Example usage for android.view View invalidate

List of usage examples for android.view View invalidate

Introduction

In this page you can find the example usage for android.view View invalidate.

Prototype

public void invalidate() 

Source Link

Document

Invalidate the whole view.

Usage

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void applyBackground(final View view, final int color) {
    if (view == null)
        return;//w ww  .  j a  v a 2  s . c o  m
    try {
        final Drawable bg = view.getBackground();
        if (bg == null)
            return;
        final Drawable mutated = bg.mutate();
        if (mutated == null)
            return;
        mutated.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        view.invalidate();
    } catch (final Exception e) {
        e.printStackTrace();
    }
}

From source file:com.matthewtamlin.sliding_intro_screen_library.transformers.MultiViewParallaxTransformer.java

@Override
public void transformPage(final View page, final float position) {
    // The status of the transformation
    final boolean pageIsSelected = (position == 0f);
    final boolean pageIsScrolling = (-1f < position && position < 1f);

    if (pageIsSelected) {
        page.invalidate(); // Make sure page displays correctly
    } else if (pageIsScrolling) {
        // For every resource ID which has been nominated for a parallax factor
        for (final Integer id : parallaxFactors.keySet()) {
            // Check to see if the current page has a View with that resource ID
            final View viewToTransform = getViewToTransform(page, id);

            // If the parallax factor is applicable, apply the parallax effect
            if (viewToTransform != null) {
                final float parallaxFactor = parallaxFactors.get(id);

                // The displacement which is automatically applied by the transformer superclass
                final float nominalDisplacement = (page.getWidth() / 2) * position;

                // Subtract 1 from the parallax factor because the View is already moved the
                // nominal displacement by the transformer superclass
                final float modifiedDisplacement = nominalDisplacement * (parallaxFactor - 1);

                // Apply the extra displacement using the X translation method
                viewToTransform.setTranslationX(modifiedDisplacement);
            }/*  w  w w .j ava  2 s  . c  o  m*/
        }
    }
}

From source file:org.getlantern.firetweet.util.ThemeUtils.java

public static void applyBackground(final View view, final int color) {
    if (view == null)
        return;//from   www . j ava 2  s .com
    try {
        final Drawable bg = view.getBackground();
        if (bg == null)
            return;
        final Drawable mutated = bg.mutate();
        if (mutated == null)
            return;
        mutated.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        view.invalidate();
    } catch (final Exception e) {
        Crashlytics.logException(e);
        e.printStackTrace();
    }
}

From source file:danonino.danonino_the_game.Core.Activities.Menu.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    //set to full screen
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_menu);
    this.continuePlaying = false;
    MusicManager.start(getApplicationContext(), MusicManager.MUSIC_MENU);
    ShardsContainer.load(getBaseContext());

    this.startBtn = (ImageButton) findViewById(R.id.start_btn);
    this.settingsBtn = (Button) findViewById(R.id.settings_btn);
    this.layout = (RelativeLayout) findViewById(R.id.layout);

    Drawable bg = ContextCompat.getDrawable(getApplicationContext(), R.drawable.menubackground);
    this.layout.setBackground(bg);
    Drawable setbg = ContextCompat.getDrawable(getApplicationContext(), R.drawable.settingicon);
    this.settingsBtn.setBackground(setbg);
    Drawable playbg = ContextCompat.getDrawable(getApplicationContext(), R.drawable.woodenlabel);
    this.startBtn.setBackground(playbg);

    this.startBtn.setOnTouchListener(new View.OnTouchListener() {
        @Override/*from  w ww.  j a  va  2s. co m*/
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN: {
                ImageButton view = (ImageButton) v;
                view.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                v.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP:
                Intent i = new Intent(getBaseContext(), Game.class);
                startActivity(i);

            case MotionEvent.ACTION_CANCEL: {
                ImageButton view = (ImageButton) v;
                view.getBackground().clearColorFilter();
                view.invalidate();
                break;
            }
            }
            return true;
        }
    });

    this.settingsBtn.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN: {
                Button view = (Button) v;
                view.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                v.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP:
                continuePlaying = true;
                Intent i = new Intent(getBaseContext(), Settings.class);
                startActivity(i);

            case MotionEvent.ACTION_CANCEL: {
                Button view = (Button) v;
                view.getBackground().clearColorFilter();
                view.invalidate();
                break;
            }
            }
            return true;
        }
    });

}

From source file:com.example.nikhil.wikipediasearch.ImageAdapter.java

public View getView(int position, View view, ViewGroup parent) {
    if (view == null) {
        view = new ImageView(parent.getContext());
        view.setPadding(6, 2, 6, 2);//from   ww w.  j  a  v  a  2 s . co  m
        //view.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN);
        view.setBackgroundColor(ContextCompat.getColor(parent.getContext(), R.color.Color_1));

        view.invalidate();
    }

    int width = parent.getContext().getResources().getDisplayMetrics().widthPixels;
    if (URLS[position] != null) {
        Picasso.with(parent.getContext()).load(URLS[position]).noFade().resize(width / 4, width / 4)
                .centerCrop().error(R.drawable.no_image).placeholder(R.drawable.loading_image)
                .into((ImageView) view);
    }

    view.setTag(position);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                int pos = (int) v.getTag();
                zoomImageFromThumb(v, pos);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    return view;
}

From source file:com.groksolutions.grok.mobile.GrokActivity.java

/**
 * Capture the screen and return the URI of the image
 *///from  w ww . ja va2s.  c o m
private Uri takeScreenCapture(boolean isRetryOk) {
    String fileName = "GROK_" + new SimpleDateFormat("yyyyMMddhhmm'.jpg'", Locale.US).format(new Date());

    File screenShot = new File(getCacheDir(), fileName);

    // create bitmap screen capture
    View v1 = getWindow().getDecorView().getRootView();
    v1.setDrawingCacheEnabled(true);
    v1.invalidate();
    v1.buildDrawingCache(true);
    Bitmap bitmap = null;
    FileOutputStream fOut = null;

    try {
        bitmap = Bitmap.createBitmap(v1.getDrawingCache(true));
        v1.setDrawingCacheEnabled(false);
        fOut = new FileOutputStream(screenShot);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 75, fOut);

    } catch (FileNotFoundException e) {
        Log.e(TAG, "Screen shot file not found", e);
    } catch (OutOfMemoryError e) {
        Log.e(TAG, "Out of Memory Error creating screenshot", e);
        // retry one time on out of memory
        if (isRetryOk) {
            return takeScreenCapture(false);
        }
        return writeTextFileToSend("screenshot.txt", "Out of Memory: Failed to generate screenshot");
    } finally {
        // recycle the bitmap on the heap to free up space and help prevent
        // out of memory errors
        if (bitmap != null) {
            bitmap.recycle();
            bitmap = null;
        }
        System.gc();
        try {
            if (fOut != null) {
                fOut.flush();
                fOut.close();
            }
        } catch (IOException e) {
            Log.e(TAG, "Error saving the screenshot file", e);
        }
    }

    return Uri.parse("content://" + getApplication().getPackageName() + "/" + fileName);
}

From source file:com.numenta.htmit.mobile.HTMITActivity.java

/**
 * Capture the screen and return the URI of the image
 *//*w w w. ja  v a 2  s  .c  o  m*/
private Uri takeScreenCapture(boolean isRetryOk) {
    String fileName = "HTMIT_" + new SimpleDateFormat("yyyyMMddhhmm'.jpg'", Locale.US).format(new Date());

    File screenShot = new File(getCacheDir(), fileName);

    // create bitmap screen capture
    View v1 = getWindow().getDecorView().getRootView();
    v1.setDrawingCacheEnabled(true);
    v1.invalidate();
    v1.buildDrawingCache(true);
    Bitmap bitmap = null;
    FileOutputStream fOut = null;

    try {
        bitmap = Bitmap.createBitmap(v1.getDrawingCache(true));
        v1.setDrawingCacheEnabled(false);
        fOut = new FileOutputStream(screenShot);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 75, fOut);

    } catch (FileNotFoundException e) {
        Log.e(TAG, "Screen shot file not found", e);
    } catch (OutOfMemoryError e) {
        Log.e(TAG, "Out of Memory Error creating screenshot", e);
        // retry one time on out of memory
        if (isRetryOk) {
            return takeScreenCapture(false);
        }
        return writeTextFileToSend("screenshot.txt", "Out of Memory: Failed to generate screenshot");
    } finally {
        // recycle the bitmap on the heap to free up space and help prevent
        // out of memory errors
        if (bitmap != null) {
            bitmap.recycle();
            bitmap = null;
        }
        System.gc();
        try {
            if (fOut != null) {
                fOut.flush();
                fOut.close();
            }
        } catch (IOException e) {
            Log.e(TAG, "Error saving the screenshot file", e);
        }
    }

    return Uri.parse("content://" + getApplication().getPackageName() + "/" + fileName);
}

From source file:com.YOMPsolutions.YOMP.mobile.YOMPActivity.java

/**
 * Capture the screen and return the URI of the image
 *///from  www. ja va2s  . c  o  m
private Uri takeScreenCapture(boolean isRetryOk) {
    String fileName = "YOMP_" + new SimpleDateFormat("yyyyMMddhhmm'.jpg'", Locale.US).format(new Date());

    File screenShot = new File(getCacheDir(), fileName);

    // create bitmap screen capture
    View v1 = getWindow().getDecorView().getRootView();
    v1.setDrawingCacheEnabled(true);
    v1.invalidate();
    v1.buildDrawingCache(true);
    Bitmap bitmap = null;
    FileOutputStream fOut = null;

    try {
        bitmap = Bitmap.createBitmap(v1.getDrawingCache(true));
        v1.setDrawingCacheEnabled(false);
        fOut = new FileOutputStream(screenShot);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 75, fOut);

    } catch (FileNotFoundException e) {
        Log.e(TAG, "Screen shot file not found", e);
    } catch (OutOfMemoryError e) {
        Log.e(TAG, "Out of Memory Error creating screenshot", e);
        // retry one time on out of memory
        if (isRetryOk) {
            return takeScreenCapture(false);
        }
        return writeTextFileToSend("screenshot.txt", "Out of Memory: Failed to generate screenshot");
    } finally {
        // recycle the bitmap on the heap to free up space and help prevent
        // out of memory errors
        if (bitmap != null) {
            bitmap.recycle();
            bitmap = null;
        }
        System.gc();
        try {
            if (fOut != null) {
                fOut.flush();
                fOut.close();
            }
        } catch (IOException e) {
            Log.e(TAG, "Error saving the screenshot file", e);
        }
    }

    return Uri.parse("content://" + getApplication().getPackageName() + "/" + fileName);
}

From source file:li.klass.fhem.fragments.core.DeviceListFragment.java

@Override
@SuppressWarnings("unchecked")
public void update(boolean doUpdate) {

    View view = getView();
    if (view == null)
        return;// w  w  w  .j  a  v a  2  s  .  c o m

    if (doUpdate) {
        getActivity().sendBroadcast(new Intent(Actions.SHOW_EXECUTING_DIALOG));
        view.invalidate();
    }

    Log.i(DeviceListFragment.class.getName(), "request device list update (doUpdate=" + doUpdate + ")");

    Intent intent = new Intent(getUpdateAction()).setClass(getActivity(), getUpdateActionIntentTargetClass())
            .putExtra(DO_REFRESH, doUpdate).putExtra(RESULT_RECEIVER, new FhemResultReceiver() {
                protected void onReceiveResult(int resultCode, Bundle resultData) {
                    View view = getView();
                    if (view == null)
                        return;

                    if (resultCode == ResultCodes.SUCCESS && resultData.containsKey(DEVICE_LIST)) {
                        getActivity().sendBroadcast(new Intent(Actions.DISMISS_EXECUTING_DIALOG));

                        RoomDeviceList deviceList = (RoomDeviceList) resultData.getSerializable(DEVICE_LIST);
                        long lastUpdate = resultData.getLong(LAST_UPDATE);

                        getAdapter().updateData(deviceList, lastUpdate);

                        if (deviceList != null && deviceList.isEmptyOrOnlyContainsDoNotShowDevices()) {
                            showEmptyView();
                        } else {
                            hideEmptyView();
                        }
                    }

                    View dummyConnectionNotification = view.findViewById(R.id.dummyConnectionNotification);
                    if (!dataConnectionSwitch.getCurrentProvider(getActivity()).getClass()
                            .isAssignableFrom(DummyDataConnection.class)) {
                        dummyConnectionNotification.setVisibility(View.GONE);
                    } else {
                        dummyConnectionNotification.setVisibility(View.VISIBLE);
                    }
                }
            });
    fillIntent(intent);

    FragmentActivity activity = getActivity();
    if (activity != null) {
        activity.startService(intent);
    }
}

From source file:com.numenta.taurus.TaurusBaseActivity.java

/**
 * Capture the screen and return the URI of the image
 *//*w  w  w . j a  va 2  s.co m*/
private Uri takeScreenCapture(boolean isRetryOk) {
    String fileName = "FILE_" + new SimpleDateFormat("yyyyMMddhhmm'.jpg'", Locale.US).format(new Date());

    File screenShot = new File(getCacheDir(), fileName);

    // create bitmap screen capture
    View v1 = getWindow().getDecorView().getRootView();
    v1.setDrawingCacheEnabled(true);
    v1.invalidate();
    v1.buildDrawingCache(true);
    Bitmap bitmap = null;
    FileOutputStream fOut = null;

    try {
        bitmap = Bitmap.createBitmap(v1.getDrawingCache(true));
        v1.setDrawingCacheEnabled(false);
        fOut = new FileOutputStream(screenShot);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 75, fOut);

    } catch (FileNotFoundException e) {
        Log.e(TAG, "Screen shot file not found", e);
    } catch (OutOfMemoryError e) {
        Log.e(TAG, "Out of Memory Error creating screenshot", e);
        // retry one time on out of memory
        if (isRetryOk) {
            return takeScreenCapture(false);
        }
        return writeTextFileToSend("screenshot.txt", "Out of Memory: Failed to generate screenshot");
    } finally {
        // recycle the bitmap on the heap to free up space and help prevent
        // out of memory errors
        if (bitmap != null) {
            bitmap.recycle();
            //noinspection UnusedAssignment
            bitmap = null;
        }
        System.gc();
        try {
            if (fOut != null) {
                fOut.flush();
                fOut.close();
            }
        } catch (IOException e) {
            Log.e(TAG, "Error saving the screenshot file", e);
        }
    }

    return Uri.parse("content://" + getApplication().getPackageName() + "/" + fileName);
}