List of usage examples for android.graphics.drawable Drawable getConstantState
public @Nullable ConstantState getConstantState()
From source file:com.example.domiter.fileexplorer.dialog.BaseDialogFragment.java
/** * Overrides tint set with tintDrawable(). *//*from w w w. ja v a 2s . c om*/ private Drawable lightenDrawable(Drawable drawable) { if (drawable == null) { return null; } Drawable newDrawable = drawable.getConstantState().newDrawable().mutate(); newDrawable .setColorFilter(new LightingColorFilter(Color.rgb(255, 255, 255), Color.argb(200, 255, 255, 255))); return newDrawable; }
From source file:com.appeaser.sublimenavigationviewlibrary.SublimeBaseItemView.java
private Drawable prepareIcon(Drawable icon) { icon = DrawableCompat.wrap(icon.getConstantState().newDrawable()).mutate(); icon.setBounds(0, 0, mIconSize, mIconSize); DrawableCompat.setTintList(icon, mIconTintList); return icon;//w ww.jav a2 s .c o m }
From source file:com.max.library.view.v7.AppCompatDrawableManager.java
private static boolean shouldMutateBackground(Drawable drawable) { if (drawable instanceof LayerDrawable) { return Build.VERSION.SDK_INT >= 16; } else if (drawable instanceof InsetDrawable) { return Build.VERSION.SDK_INT >= 14; } else if (drawable instanceof StateListDrawable) { // StateListDrawable has a bug in mutate() on API 7 return Build.VERSION.SDK_INT >= 8; } else if (drawable instanceof DrawableContainer) { // If we have a DrawableContainer, let's traverse it's child array final Drawable.ConstantState state = drawable.getConstantState(); if (state instanceof DrawableContainer.DrawableContainerState) { final DrawableContainer.DrawableContainerState containerState = (DrawableContainer.DrawableContainerState) state; for (Drawable child : containerState.getChildren()) { if (!shouldMutateBackground(child)) { return false; }//from w w w . j ava 2 s . c om } } } return true; }
From source file:android.support.design.internal.BottomNavigationItemView.java
@Override public void setIcon(Drawable icon) { if (icon != null) { Drawable.ConstantState state = icon.getConstantState(); icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate(); DrawableCompat.setTintList(icon, mIconTint); }// w w w . j a v a2s .com mIcon.setImageDrawable(icon); }
From source file:android.support.design.internal.NavigationMenuItemView.java
@Override public void setIcon(Drawable icon) { if (icon != null) { if (mHasIconTintList) { Drawable.ConstantState state = icon.getConstantState(); icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate(); DrawableCompat.setTintList(icon, mIconTintList); }// w w w . ja v a2 s . c o m icon.setBounds(0, 0, mIconSize, mIconSize); } else if (mNeedsEmptyIcon) { if (mEmptyDrawable == null) { mEmptyDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.navigation_empty_icon, getContext().getTheme()); if (mEmptyDrawable != null) { mEmptyDrawable.setBounds(0, 0, mIconSize, mIconSize); } } icon = mEmptyDrawable; } TextViewCompat.setCompoundDrawablesRelative(mTextView, icon, null, null, null); }
From source file:com.stepstone.stepper.internal.widget.StepTab.java
/** * Inflates an animated vector drawable. On Lollipop+ this uses the native {@link android.graphics.drawable.AnimatedVectorDrawable} * and below it inflates the drawable as a {@link AnimatedVectorDrawableCompat}. * * @param animatedVectorDrawableResId resource ID for the animated vector * @return animated vector drawable//from w ww. jav a2 s .c o m */ public Drawable createAnimatedVectorDrawable(@DrawableRes int animatedVectorDrawableResId) { Context context = getContext(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Drawable drawable = context.getDrawable(animatedVectorDrawableResId); return drawable.getConstantState().newDrawable(context.getResources()); } else { return AnimatedVectorDrawableCompat.create(context, animatedVectorDrawableResId); } }
From source file:com.bilibili.magicasakura.utils.TintManager.java
private boolean addCachedDrawable(final int key, @NonNull final Drawable drawable) { if (drawable instanceof FilterableStateListDrawable) { return false; }//from w ww . j av a 2 s . c om final Drawable.ConstantState cs = drawable.getConstantState(); if (cs != null) { synchronized (mDrawableCacheLock) { if (mCacheDrawables == null) { mCacheDrawables = new SparseArray<>(); } mCacheDrawables.put(key, new WeakReference<>(cs)); } return true; } return false; }
From source file:com.ruesga.rview.drawer.DrawerNavigationMenuItemView.java
@Override public void setIcon(Drawable icon) { if (icon != null) { if (mShouldTintedIcon && mHasIconTintList) { Drawable.ConstantState state = icon.getConstantState(); icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate(); DrawableCompat.setTintList(icon, mIconTintList); }/*w w w. j av a 2 s. c o m*/ icon.setBounds(0, 0, mIconSize, mIconSize); } else if (mNeedsEmptyIcon) { if (mEmptyDrawable == null) { mEmptyDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.navigation_empty_icon, getContext().getTheme()); if (mEmptyDrawable != null) { mEmptyDrawable.setBounds(0, 0, mIconSize, mIconSize); } } icon = mEmptyDrawable; } mIcon.setImageDrawable(icon); }
From source file:com.facebook.litho.reference.DrawableResourcesCache.java
public @Nullable Drawable get(int resId, Resources resources, @Nullable Resources.Theme theme) { SimplePoolWithCount<Drawable> drawablesPool = mDrawableCache.get(resId); if (drawablesPool == null) { drawablesPool = new SimplePoolWithCount<>(DRAWABLES_POOL_MAX_ITEMS); mDrawableCache.put(resId, drawablesPool); }/*from w w w .java 2 s . c o m*/ Drawable drawable = drawablesPool.acquire(); if (drawable == null) { drawable = ResourcesCompat.getDrawable(resources, resId, theme); } // We never want this pool to remain empty otherwise we would risk to resolve a new drawable // when get is called again. So if the pool is about to drain we just put a new Drawable in it // to keep it warm. if (drawable != null && drawablesPool.getPoolSize() == 0) { drawablesPool.release(drawable.getConstantState().newDrawable()); } return drawable; }
From source file:com.morlunk.mumbleclient.channel.ChannelListAdapter.java
/** * Updates the user's state icon with a nice animation. * @param user The user to update.//from www.j av a 2 s . c om * @param view The view containing this adapter. */ public void animateUserStateUpdate(IUser user, RecyclerView view) { long itemId = user.getSession() | USER_ID_MASK; UserViewHolder uvh = (UserViewHolder) view.findViewHolderForItemId(itemId); if (uvh != null) { Drawable newState = getTalkStateDrawable(user); Drawable oldState = uvh.mUserTalkHighlight.getDrawable().getCurrent(); if (!newState.getConstantState().equals(oldState.getConstantState())) { // "Flip" in new talking state. FlipDrawable drawable = new FlipDrawable(oldState, newState); uvh.mUserTalkHighlight.setImageDrawable(drawable); drawable.start(FLIP_DURATION); } } }