/**
* Some drawable implementations have problems with mutation. This method returns false if
* there is a known issue in the given drawable's implementation.
*/
static boolean canSafelyMutateDrawable(@NonNull 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 GradientDrawable) {
// GradientDrawable has a bug pre-ICS which results in mutate() resulting
// in loss of color
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 (!canSafelyMutateDrawable(child)) {
return false;
}
}
}
} else if (drawable instanceof android.support.v4ox.graphics.drawable.DrawableWrapper) {
return canSafelyMutateDrawable(
((android.support.v4ox.graphics.drawable.DrawableWrapper) drawable)
.getWrappedDrawable());
} else if (drawable instanceof android.support.v7ox.graphics.drawable.DrawableWrapper) {
return canSafelyMutateDrawable(
((android.support.v7ox.graphics.drawable.DrawableWrapper) drawable)
.getWrappedDrawable());
}
return true;
}
DrawableUtils.java 文件源码
java
阅读 35
收藏 0
点赞 0
评论 0
项目:permissionsModule
作者:
评论列表
文章目录