android.graphics.drawable.DrawableContainer#DrawableContainerState()源码实例Demo

下面列出了android.graphics.drawable.DrawableContainer#DrawableContainerState() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: timecat   文件: ThemeUtils.java
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;
}
 
源代码2 项目: RangeSeekBar   文件: DrawableUtils.java
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;
}
 
源代码3 项目: MagicaSakura   文件: ThemeUtils.java
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;
}
 
源代码4 项目: AndroidTint   文件: EmTintManager.java
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;
}
 
/**
 * 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;
}
 
/**
 * 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;
}