List of usage examples for android.support.v4.graphics.drawable DrawableCompat setTintMode
public static void setTintMode(Drawable drawable, Mode mode)
From source file:com.max.library.view.v7.AppCompatDrawableManager.java
public Drawable getDrawable(@NonNull Context context, @DrawableRes int resId, boolean failIfNotKnown) { // Let the InflateDelegates have a go first if (mDelegates != null) { for (int i = 0, count = mDelegates.size(); i < count; i++) { final InflateDelegate delegate = mDelegates.get(i); final Drawable result = delegate.onInflateDrawable(context, resId); if (result != null) { return result; }// w w w . j a va 2 s .c om } } // The delegates failed so we'll carry on Drawable drawable = ContextCompat.getDrawable(context, resId); if (drawable != null) { if (Build.VERSION.SDK_INT >= 8) { // Mutate can cause NPEs on 2.1 drawable = drawable.mutate(); } final ColorStateList tintList = getTintList(context, resId); if (tintList != null) { // First wrap the Drawable and set the tint list drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTintList(drawable, tintList); // If there is a blending mode specified for the drawable, use it final PorterDuff.Mode tintMode = getTintMode(resId); if (tintMode != null) { DrawableCompat.setTintMode(drawable, tintMode); } } else if (resId == R.drawable.abc_cab_background_top_material) { return new LayerDrawable( new Drawable[] { getDrawable(context, R.drawable.abc_cab_background_internal_bg), getDrawable(context, R.drawable.abc_cab_background_top_mtrl_alpha) }); } else if (resId == com.max.library.R.drawable.abc_seekbar_track_material) { LayerDrawable ld = (LayerDrawable) drawable; setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.background), getThemeAttrColor(context, R.attr.colorControlNormal), DEFAULT_MODE); setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.secondaryProgress), getThemeAttrColor(context, R.attr.colorControlNormal), DEFAULT_MODE); setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.progress), getThemeAttrColor(context, R.attr.colorControlActivated), DEFAULT_MODE); } else { final boolean tinted = tintDrawableUsingColorFilter(context, resId, drawable); if (!tinted && failIfNotKnown) { // If we didn't tint using a ColorFilter, and we're set to fail if we don't // know the id, return null drawable = null; } } } return drawable; }
From source file:com.albedinsky.android.support.ui.graphics.drawable.DrawableWrapper.java
/** */ @Override public void setTintMode(PorterDuff.Mode tintMode) { DrawableCompat.setTintMode(mDrawable, tintMode); }
From source file:info.bartowski.easteregg.LLand.java
private void reset() { L("reset");/*from ww w .j a v a 2 s . c om*/ final Drawable sky = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, SKIES[mTimeOfDay]); sky.setDither(true); setBackground(sky); mFlipped = frand() > 0.5f; setScaleX(mFlipped ? -1 : 1); setScore(0); int i = getChildCount(); while (i-- > 0) { final View v = getChildAt(i); if (v instanceof GameView) { removeViewAt(i); } } mObstaclesInPlay.clear(); mWidth = getWidth(); mHeight = getHeight(); boolean showingSun = (mTimeOfDay == DAY || mTimeOfDay == SUNSET) && frand() > 0.25; if (showingSun) { final Star sun = new Star(getContext()); sun.setBackground(Utility.getCompatDrawable(getContext(), R.drawable.sun)); final int w = getResources().getDimensionPixelSize(R.dimen.lland_sun_size); sun.setTranslationX(frand(w, mWidth - w)); if (mTimeOfDay == DAY) { sun.setTranslationY(frand(w, (mHeight * 0.66f))); DrawableCompat.setTint(sun.getBackground(), 0); } else { sun.setTranslationY(frand(mHeight * 0.66f, mHeight - w)); DrawableCompat.setTintMode(sun.getBackground(), PorterDuff.Mode.SRC_ATOP); DrawableCompat.setTint(sun.getBackground(), 0xC0FF8000); } addView(sun, new LayoutParams(w, w)); } if (!showingSun) { final boolean dark = mTimeOfDay == NIGHT || mTimeOfDay == TWILIGHT; final float ff = frand(); if ((dark && ff < 0.75f) || ff < 0.5f) { final Star moon = new Star(getContext()); moon.setBackground(Utility.getCompatDrawable(getContext(), R.drawable.moon)); moon.getBackground().setAlpha(dark ? 255 : 128); moon.setScaleX(frand() > 0.5 ? -1 : 1); moon.setRotation(moon.getScaleX() * frand(5, 30)); final int w = getResources().getDimensionPixelSize(R.dimen.lland_sun_size); moon.setTranslationX(frand(w, mWidth - w)); moon.setTranslationY(frand(w, mHeight - w)); addView(moon, new LayoutParams(w, w)); } } final int mh = mHeight / 6; final boolean cloudless = frand() < 0.25; final int N = 20; for (i = 0; i < N; i++) { final float r1 = frand(); final Scenery s; if (HAVE_STARS && r1 < 0.3 && mTimeOfDay != DAY) { s = new Star(getContext()); } else if (r1 < 0.6 && !cloudless) { s = new Cloud(getContext()); } else { s = new Building(getContext()); s.z = (float) i / N; ViewCompat.setTranslationZ(s, PARAMS.SCENERY_Z * (1 + s.z)); s.v = 0.85f * s.z; // buildings move proportional to their distance hsv[0] = 175; hsv[1] = 0.25f; hsv[2] = 1 * s.z; s.setBackgroundColor(Color.HSVToColor(hsv)); s.h = irand(PARAMS.BUILDING_HEIGHT_MIN, mh); } final LayoutParams lp = new LayoutParams(s.w, s.h); if (s instanceof Building) { lp.gravity = Gravity.BOTTOM; } else { lp.gravity = Gravity.TOP; final float r = frand(); if (s instanceof Star) { lp.topMargin = (int) (r * r * mHeight); } else { lp.topMargin = (int) (1 - r * r * mHeight / 2) + mHeight / 2; } } addView(s, lp); s.setTranslationX(frand(-lp.width, mWidth + lp.width)); } mDroid = new Player(getContext()); mDroid.setX(mWidth / 2); mDroid.setY(mHeight / 2); addView(mDroid, new LayoutParams(PARAMS.PLAYER_SIZE, PARAMS.PLAYER_SIZE)); mAnim = new TimeAnimator(); mAnim.setTimeListener(new TimeAnimator.TimeListener() { @Override public void onTimeUpdate(TimeAnimator timeAnimator, long t, long dt) { step(t, dt); } }); }
From source file:com.albedinsky.android.ui.graphics.drawable.DrawableWrapper.java
/** */ @Override public void setTintMode(@NonNull PorterDuff.Mode tintMode) { DrawableCompat.setTintMode(mDrawable, tintMode); }
From source file:android.support.graphics.drawable.AnimatedVectorDrawableCompat.java
public void setTintMode(PorterDuff.Mode tintMode) { if (mDelegateDrawable != null) { DrawableCompat.setTintMode(mDelegateDrawable, tintMode); return;// w w w . ja va 2s .com } mAnimatedVectorState.mVectorDrawable.setTintMode(tintMode); }
From source file:android.support.v7.widget.AppCompatDrawableManager.java
private Drawable tintDrawable(@NonNull Context context, @DrawableRes int resId, boolean failIfNotKnown, @NonNull Drawable drawable) {//from w ww . j a va 2s . c o m final ColorStateList tintList = getTintList(context, resId); if (tintList != null) { // First mutate the Drawable, then wrap it and set the tint list if (DrawableUtils.canSafelyMutateDrawable(drawable)) { drawable = drawable.mutate(); } drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTintList(drawable, tintList); // If there is a blending mode specified for the drawable, use it final PorterDuff.Mode tintMode = getTintMode(resId); if (tintMode != null) { DrawableCompat.setTintMode(drawable, tintMode); } } else if (resId == R.drawable.abc_seekbar_track_material) { LayerDrawable ld = (LayerDrawable) drawable; setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.background), getThemeAttrColor(context, R.attr.colorControlNormal), DEFAULT_MODE); setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.secondaryProgress), getThemeAttrColor(context, R.attr.colorControlNormal), DEFAULT_MODE); setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.progress), getThemeAttrColor(context, R.attr.colorControlActivated), DEFAULT_MODE); } else if (resId == R.drawable.abc_ratingbar_material || resId == R.drawable.abc_ratingbar_indicator_material || resId == R.drawable.abc_ratingbar_small_material) { LayerDrawable ld = (LayerDrawable) drawable; setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.background), getDisabledThemeAttrColor(context, R.attr.colorControlNormal), DEFAULT_MODE); setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.secondaryProgress), getThemeAttrColor(context, R.attr.colorControlActivated), DEFAULT_MODE); setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.progress), getThemeAttrColor(context, R.attr.colorControlActivated), DEFAULT_MODE); } else { final boolean tinted = tintDrawableUsingColorFilter(context, resId, drawable); if (!tinted && failIfNotKnown) { // If we didn't tint using a ColorFilter, and we're set to fail if we don't // know the id, return null drawable = null; } } return drawable; }
From source file:android.support.graphics.drawable.VectorDrawableCompat.java
public void setTintMode(Mode tintMode) { if (mDelegateDrawable != null) { DrawableCompat.setTintMode(mDelegateDrawable, tintMode); return;//from ww w .ja v a2 s . c om } final VectorDrawableCompatState state = mVectorState; if (state.mTintMode != tintMode) { state.mTintMode = tintMode; mTintFilter = updateTintFilter(mTintFilter, state.mTint, tintMode); invalidateSelf(); } }
From source file:org.mariotaku.multivalueswitch.library.MultiValueSwitch.java
private void applyTrackTint() { if (mTrackDrawable != null && (mHasTrackTint || mHasTrackTintMode)) { mTrackDrawable = mTrackDrawable.mutate(); if (mHasTrackTint) { DrawableCompat.setTintList(mTrackDrawable, mTrackTintList); }//from w ww .j ava2 s. c o m if (mHasTrackTintMode) { DrawableCompat.setTintMode(mTrackDrawable, mTrackTintMode); } // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (mTrackDrawable.isStateful()) { mTrackDrawable.setState(getDrawableState()); } } }
From source file:info.bartowski.easteregg.MLand.java
public void reset() { L("reset");//ww w . j a v a 2 s . com final Drawable sky = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, SKIES[mTimeOfDay]); sky.setDither(true); setBackground(sky); mFlipped = frand() > 0.5f; setScaleX(mFlipped ? -1 : 1); int i = getChildCount(); while (i-- > 0) { final View v = getChildAt(i); if (v instanceof GameView) { removeViewAt(i); } } mObstaclesInPlay.clear(); mCurrentPipeId = 0; mWidth = getWidth(); mHeight = getHeight(); boolean showingSun = (mTimeOfDay == DAY || mTimeOfDay == SUNSET) && frand() > 0.25; if (showingSun) { final Star sun = new Star(getContext()); sun.setBackground(Utility.getCompatDrawable(getContext(), R.drawable.sun)); final int w = getResources().getDimensionPixelSize(R.dimen.mland_sun_size); sun.setTranslationX(frand(w, mWidth - w)); if (mTimeOfDay == DAY) { sun.setTranslationY(frand(w, (mHeight * 0.66f))); DrawableCompat.setTint(sun.getBackground(), 0); } else { sun.setTranslationY(frand(mHeight * 0.66f, mHeight - w)); DrawableCompat.setTintMode(sun.getBackground(), PorterDuff.Mode.SRC_ATOP); DrawableCompat.setTint(sun.getBackground(), 0xC0FF8000); } addView(sun, new LayoutParams(w, w)); } if (!showingSun) { final boolean dark = mTimeOfDay == NIGHT || mTimeOfDay == TWILIGHT; final float ff = frand(); if ((dark && ff < 0.75f) || ff < 0.5f) { final Star moon = new Star(getContext()); moon.setBackground(Utility.getCompatDrawable(getContext(), R.drawable.moon)); moon.getBackground().setAlpha(dark ? 255 : 128); moon.setScaleX(frand() > 0.5 ? -1 : 1); moon.setRotation(moon.getScaleX() * frand(5, 30)); final int w = getResources().getDimensionPixelSize(R.dimen.mland_sun_size); moon.setTranslationX(frand(w, mWidth - w)); moon.setTranslationY(frand(w, mHeight - w)); addView(moon, new LayoutParams(w, w)); } } final int mh = mHeight / 6; final boolean cloudless = frand() < 0.25; final int N = 20; for (i = 0; i < N; i++) { final float r1 = frand(); final Scenery s; if (HAVE_STARS && r1 < 0.3 && mTimeOfDay != DAY) { s = new Star(getContext()); } else if (r1 < 0.6 && !cloudless) { s = new Cloud(getContext()); } else { switch (mScene) { case SCENE_ZRH: s = new Mountain(getContext()); break; case SCENE_TX: s = new Cactus(getContext()); break; case SCENE_CITY: default: s = new Building(getContext()); break; } s.z = (float) i / N; // no more shadows for these things //s.setTranslationZ(PARAMS.SCENERY_Z * (1+s.z)); s.v = 0.85f * s.z; // buildings move proportional to their distance if (mScene == SCENE_CITY) { s.setBackgroundColor(Color.GRAY); s.h = irand(PARAMS.BUILDING_HEIGHT_MIN, mh); } final int c = (int) (255f * s.z); final Drawable bg = s.getBackground(); if (bg != null) bg.setColorFilter(Color.rgb(c, c, c), PorterDuff.Mode.MULTIPLY); } final LayoutParams lp = new LayoutParams(s.w, s.h); if (s instanceof Building) { lp.gravity = Gravity.BOTTOM; } else { lp.gravity = Gravity.TOP; final float r = frand(); if (s instanceof Star) { lp.topMargin = (int) (r * r * mHeight); } else { lp.topMargin = (int) (1 - r * r * mHeight / 2) + mHeight / 2; } } addView(s, lp); s.setTranslationX(frand(-lp.width, mWidth + lp.width)); } for (Player p : mPlayers) { addView(p); // put it back! p.reset(); } realignPlayers(); if (mAnim != null) { mAnim.cancel(); } mAnim = new TimeAnimator(); mAnim.setTimeListener(new TimeAnimator.TimeListener() { @Override public void onTimeUpdate(TimeAnimator timeAnimator, long t, long dt) { step(t, dt); } }); }
From source file:org.mariotaku.multivalueswitch.library.MultiValueSwitch.java
private void applyThumbTint() { if (mThumbDrawable != null && (mHasThumbTint || mHasThumbTintMode)) { mThumbDrawable = mThumbDrawable.mutate(); if (mHasThumbTint) { DrawableCompat.setTintList(mThumbDrawable, mThumbTintList); }/* w w w .j a va 2 s .com*/ if (mHasThumbTintMode) { DrawableCompat.setTintMode(mThumbDrawable, mThumbTintMode); } // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (mThumbDrawable.isStateful()) { mThumbDrawable.setState(getDrawableState()); } } }