Java Code Examples for android.graphics.drawable.DrawableContainer#DrawableContainerState
The following examples show how to use
android.graphics.drawable.DrawableContainer#DrawableContainerState .
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 | 6 votes |
public static boolean containsNinePatch(Drawable drawable) { drawable = getWrapperDrawable(drawable); if (drawable instanceof NinePatchDrawable || drawable instanceof InsetDrawable || drawable instanceof LayerDrawable) { return true; } else if (drawable instanceof StateListDrawable) { final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState()); //can't get containState from drawable which is containing DrawableWrapperDonut //https://code.google.com/p/android/issues/detail?id=169920 if (containerState == null) { return true; } for (Drawable dr : containerState.getChildren()) { dr = getWrapperDrawable(dr); if (dr instanceof NinePatchDrawable || dr instanceof InsetDrawable || dr instanceof LayerDrawable) { return true; } } } return false; }
Example 2
Source File: DrawableUtils.java From RangeSeekBar with MIT License | 6 votes |
public static boolean canSafelyMutateDrawable(@NonNull Drawable drawable) { 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 (drawable instanceof DrawableWrapper) { return canSafelyMutateDrawable( Objects.requireNonNull(((DrawableWrapper) drawable).getDrawable())); } else if (drawable instanceof ScaleDrawable) { return canSafelyMutateDrawable(Objects.requireNonNull(((ScaleDrawable) drawable).getDrawable())); } return true; }
Example 3
Source File: ThemeUtils.java From MagicaSakura with Apache License 2.0 | 6 votes |
public static boolean containsNinePatch(Drawable drawable) { drawable = getWrapperDrawable(drawable); if (drawable instanceof NinePatchDrawable || drawable instanceof InsetDrawable || drawable instanceof LayerDrawable) { return true; } else if (drawable instanceof StateListDrawable) { final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState()); //can't get containState from drawable which is containing DrawableWrapperDonut //https://code.google.com/p/android/issues/detail?id=169920 if (containerState == null) { return true; } for (Drawable dr : containerState.getChildren()) { dr = getWrapperDrawable(dr); if (dr instanceof NinePatchDrawable || dr instanceof InsetDrawable || dr instanceof LayerDrawable) { return true; } } } return false; }
Example 4
Source File: EmTintManager.java From AndroidTint with Apache License 2.0 | 6 votes |
private static boolean shouldMutateBackground(Drawable drawable) { if (Build.VERSION.SDK_INT >= 16) { // For SDK 16+, we should be fine mutating the drawable return true; } 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 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; } } } } return true; }
Example 5
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 (SkinCompatVersionUtils.isV7DrawableWrapper(drawable)) { return canSafelyMutateDrawable(SkinCompatVersionUtils.getV7DrawableWrapperWrappedDrawable(drawable)); } else if (drawable instanceof ScaleDrawable) { Drawable scaleDrawable = ((ScaleDrawable) drawable).getDrawable(); if (scaleDrawable != null) { return canSafelyMutateDrawable(scaleDrawable); } } return true; }
Example 6
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; }