android.support.v7.graphics.drawable.DrawableWrapper Java Examples
The following examples show how to use
android.support.v7.graphics.drawable.DrawableWrapper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThemeUtils.java From timecat with Apache License 2.0 | 5 votes |
@SuppressLint("RestrictedApi") public static Drawable getWrapperDrawable(Drawable drawable) { if (drawable instanceof DrawableWrapper) { return ((DrawableWrapper) drawable).getWrappedDrawable(); } else if (drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) { return ((android.support.v7.graphics.drawable.DrawableWrapper) drawable).getWrappedDrawable(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && drawable instanceof android.graphics.drawable.DrawableWrapper) { return ((android.graphics.drawable.DrawableWrapper) drawable).getDrawable(); } return drawable; }
Example #2
Source File: SkinCompatDrawableUtils.java From Android-skin-support with MIT License | 5 votes |
/** * Some drawable implementations have problems with mutation. This method returns false if * there is a known issue in the given drawable's implementation. */ public static boolean canSafelyMutateDrawable(@NonNull Drawable drawable) { if (Build.VERSION.SDK_INT < 15 && drawable instanceof InsetDrawable) { return false; } else if (Build.VERSION.SDK_INT < 15 && drawable instanceof GradientDrawable) { // GradientDrawable has a bug pre-ICS which results in mutate() resulting // in loss of color return false; } else if (Build.VERSION.SDK_INT < 17 && drawable instanceof LayerDrawable) { return false; } 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 (final Drawable child : containerState.getChildren()) { if (!canSafelyMutateDrawable(child)) { return false; } } } } else if (SkinCompatVersionUtils.isV4DrawableWrapper(drawable)) { return canSafelyMutateDrawable(SkinCompatVersionUtils.getV4DrawableWrapperWrappedDrawable(drawable)); } else if (SkinCompatVersionUtils.isV4WrappedDrawable(drawable)) { return canSafelyMutateDrawable(SkinCompatVersionUtils.getV4WrappedDrawableWrappedDrawable(drawable)); } else if (drawable instanceof DrawableWrapper) { return canSafelyMutateDrawable(((DrawableWrapper) drawable).getWrappedDrawable()); } else if (drawable instanceof ScaleDrawable) { return canSafelyMutateDrawable(((ScaleDrawable) drawable).getDrawable()); } return true; }