Example usage for android.graphics.drawable Drawable invalidateSelf

List of usage examples for android.graphics.drawable Drawable invalidateSelf

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable invalidateSelf.

Prototype

public void invalidateSelf() 

Source Link

Document

Use the current Callback implementation to have this Drawable redrawn.

Usage

From source file:android.support.v7ox.widget.AppCompatDrawableManager.java

public static void tintDrawable(Drawable drawable, TintInfo tint, int[] state) {
    if (DrawableUtils.canSafelyMutateDrawable(drawable) && drawable.mutate() != drawable) {
        Log.d(TAG, "Mu d nstance as the input.");
        return;//  w ww .j ava 2s  . com
    }

    if (tint.mHasTintList || tint.mHasTintMode) {
        drawable.setColorFilter(createTintFilter(tint.mHasTintList ? tint.mTintList : null,
                tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, state));
    } else {
        drawable.clearColorFilter();
    }

    if (Build.VERSION.SDK_INT <= 23) {
        // Pre-v23 there is no guarantee that a state change will invoke an invalidation,
        // so we force it ourselves
        drawable.invalidateSelf();
    }
}

From source file:com.bilibili.magicasakura.widgets.AppCompatImageHelper.java

private boolean applySupportImageTint() {
    Drawable image = ((ImageView) mView).getDrawable();
    if (image != null && mImageTintInfo != null && mImageTintInfo.mHasTintList) {
        Drawable tintDrawable = image.mutate();
        tintDrawable = DrawableCompat.wrap(tintDrawable);
        if (mImageTintInfo.mHasTintList) {
            DrawableCompat.setTintList(tintDrawable, mImageTintInfo.mTintList);
        }//from w w  w . j ava  2  s  . com
        if (mImageTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(tintDrawable, mImageTintInfo.mTintMode);
        }
        if (tintDrawable.isStateful()) {
            tintDrawable.setState(mView.getDrawableState());
        }
        setImageDrawable(tintDrawable);
        if (image == tintDrawable) {
            tintDrawable.invalidateSelf();
        }
        return true;
    }
    return false;
}

From source file:net.fabiszewski.ulogger.MainActivity.java

/**
 * Set status led color// www  .j a va  2  s .c  om
 * @param led Led text view
 * @param color Color (red, yellow or green)
 */
private void setLedColor(TextView led, int color) {
    Drawable l;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        l = led.getCompoundDrawables()[0];
    } else {
        l = led.getCompoundDrawablesRelative()[0];
    }
    switch (color) {
    case LED_RED:
        l.setColorFilter(ContextCompat.getColor(this, R.color.colorRed), PorterDuff.Mode.SRC_ATOP);
        break;

    case LED_GREEN:
        l.setColorFilter(ContextCompat.getColor(this, R.color.colorGreen), PorterDuff.Mode.SRC_ATOP);
        break;

    case LED_YELLOW:
        l.setColorFilter(ContextCompat.getColor(this, R.color.colorYellow), PorterDuff.Mode.SRC_ATOP);
        break;
    }
    l.invalidateSelf();
}

From source file:com.guoxiaoxing.cloud.music.magicasakura.widgets.AppCompatImageHelper.java

private boolean applySupportImageTint() {
    Drawable image = ((ImageView) mView).getDrawable();
    AnimationDrawable animationDrawable = null;
    if (image instanceof AnimationDrawable) {
        Log.e("drawable", "is animationdrawable");
        animationDrawable = ((AnimationDrawable) image);
        //image = animationDrawable;
    }/*from w ww.  ja  va  2s. c  o  m*/

    if (image != null && mImageTintInfo != null && mImageTintInfo.mHasTintList) {

        if (animationDrawable != null) {
            Log.e("drawable", "is animationdrawable not null");
            Drawable tintDrawable = animationDrawable;
            Log.e("drawable", "start0");
            tintDrawable = DrawableCompat.wrap(tintDrawable);
            Log.e("drawable", "start1");
            if (mImageTintInfo.mHasTintList) {
                DrawableCompat.setTintList(tintDrawable, mImageTintInfo.mTintList);
            }
            if (mImageTintInfo.mHasTintMode) {
                DrawableCompat.setTintMode(tintDrawable, mImageTintInfo.mTintMode);
            }
            if (tintDrawable.isStateful()) {
                tintDrawable.setState(mView.getDrawableState());
            }
            tintDrawable = DrawableCompat.unwrap(tintDrawable);
            setImageDrawable(tintDrawable);
            if (image == tintDrawable) {
                Log.e("drawable", "invalidateself");
                // tintDrawable.invalidateSelf();
            }
            return true;
        } else {
            Drawable tintDrawable = image.mutate();
            tintDrawable = DrawableCompat.wrap(tintDrawable);
            if (mImageTintInfo.mHasTintList) {
                DrawableCompat.setTintList(tintDrawable, mImageTintInfo.mTintList);
            }
            if (mImageTintInfo.mHasTintMode) {
                DrawableCompat.setTintMode(tintDrawable, mImageTintInfo.mTintMode);
            }
            if (tintDrawable.isStateful()) {
                tintDrawable.setState(mView.getDrawableState());
            }
            setImageDrawable(tintDrawable);
            if (image == tintDrawable) {
                tintDrawable.invalidateSelf();
            }
            return true;
        }

    }
    return false;
}