本文整理汇总了Java中android.graphics.drawable.DrawableContainer.DrawableContainerState方法的典型用法代码示例。如果您正苦于以下问题:Java DrawableContainer.DrawableContainerState方法的具体用法?Java DrawableContainer.DrawableContainerState怎么用?Java DrawableContainer.DrawableContainerState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.DrawableContainer
的用法示例。
在下文中一共展示了DrawableContainer.DrawableContainerState方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: containsNinePatch
import android.graphics.drawable.DrawableContainer; //导入方法依赖的package包/类
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 getBaseApplication 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: containsNinePatch
import android.graphics.drawable.DrawableContainer; //导入方法依赖的package包/类
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;
}
示例3: onCreateViewHolder
import android.graphics.drawable.DrawableContainer; //导入方法依赖的package包/类
/**
* Inflates the view and creates the ViewHolder
*
* @param parent Get the context from it
* @param viewType Ignored
* @return The created ViewHolder
*/
@Override
public ButtonViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.multiplechoice_button, parent, false);
// Clone drawable to allow modifications
ToggleButton button = (ToggleButton) v.findViewById(R.id.toggleButton);
StateListDrawable drawable = (StateListDrawable) button.getBackground();
drawable = (StateListDrawable) drawable.mutate();
button.setBackgroundDrawable(drawable.getConstantState().newDrawable());
drawable = (StateListDrawable) button.getBackground();
// Deep Clone (necessary for API Version 15 apparently)
DrawableContainer.DrawableContainerState drawableContainerState = (DrawableContainer.DrawableContainerState) drawable.getConstantState();
for (int i = 0; i < drawableContainerState.getChildren().length; i++) {
if (drawableContainerState.getChildren()[i] != null) {
drawableContainerState.getChildren()[i] = drawableContainerState.getChildren()[i].getConstantState().newDrawable().mutate();
}
}
return new ButtonViewHolder(v);
}
示例4: shouldMutateBackground
import android.graphics.drawable.DrawableContainer; //导入方法依赖的package包/类
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;
}
示例5: canSafelyMutateDrawable
import android.graphics.drawable.DrawableContainer; //导入方法依赖的package包/类
/**
* 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 its 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 android.support.v4.graphics.drawable.DrawableWrapper) {
return canSafelyMutateDrawable(
((android.support.v4.graphics.drawable.DrawableWrapper) drawable)
.getWrappedDrawable());
} /*else if (drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) {
return canSafelyMutateDrawable(
((android.support.v7.graphics.drawable.DrawableWrapper) drawable)
.getWrappedDrawable());
}*/ else if (drawable instanceof ScaleDrawable) {
return canSafelyMutateDrawable(((ScaleDrawable) drawable).getDrawable());
}
return true;
}
示例6: canSafelyMutateDrawable
import android.graphics.drawable.DrawableContainer; //导入方法依赖的package包/类
/**
* 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 (drawable instanceof android.support.v4.graphics.drawable.DrawableWrapper) {
return canSafelyMutateDrawable(
((android.support.v4.graphics.drawable.DrawableWrapper) drawable)
.getWrappedDrawable());
} else if (drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) {
return canSafelyMutateDrawable(
((android.support.v7.graphics.drawable.DrawableWrapper) drawable)
.getWrappedDrawable());
} else if (drawable instanceof ScaleDrawable) {
return canSafelyMutateDrawable(((ScaleDrawable) drawable).getDrawable());
}
return true;
}
示例7: canSafelyMutateDrawable
import android.graphics.drawable.DrawableContainer; //导入方法依赖的package包/类
/**
* 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;
}
示例8: shouldMutateBackground
import android.graphics.drawable.DrawableContainer; //导入方法依赖的package包/类
private static boolean shouldMutateBackground(Drawable paramDrawable)
{
if (Build.VERSION.SDK_INT >= 16) {}
for (;;)
{
return true;
if ((paramDrawable instanceof LayerDrawable))
{
if (Build.VERSION.SDK_INT < 16) {
return false;
}
}
else if ((paramDrawable instanceof InsetDrawable))
{
if (Build.VERSION.SDK_INT < 14) {
return false;
}
}
else if ((paramDrawable instanceof DrawableContainer))
{
Drawable.ConstantState localConstantState = paramDrawable.getConstantState();
if ((localConstantState instanceof DrawableContainer.DrawableContainerState))
{
Drawable[] arrayOfDrawable = ((DrawableContainer.DrawableContainerState)localConstantState).getChildren();
int i = arrayOfDrawable.length;
for (int j = 0; j < i; j++) {
if (!shouldMutateBackground(arrayOfDrawable[j])) {
return false;
}
}
}
}
}
}
示例9: forceStateChangeOnChildrenCompat
import android.graphics.drawable.DrawableContainer; //导入方法依赖的package包/类
private static void forceStateChangeOnChildrenCompat(Drawable drawable) {
Drawable.ConstantState drawableState = drawable.getConstantState();
if (drawableState instanceof DrawableContainer.DrawableContainerState) {
DrawableContainer.DrawableContainerState drawableContainerState =
(DrawableContainer.DrawableContainerState) drawableState;
Drawable[] children = drawableContainerState.getChildren();
if (children != null) {
for (Drawable child : children) {
forceStateChange(child, true);
}
}
}
}
示例10: forceStateChangeOnChildren
import android.graphics.drawable.DrawableContainer; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
private static void forceStateChangeOnChildren(Drawable drawable) {
Drawable.ConstantState drawableState = drawable.getConstantState();
if (drawableState instanceof DrawableContainer.DrawableContainerState) {
DrawableContainer.DrawableContainerState drawableContainerState =
(DrawableContainer.DrawableContainerState) drawableState;
for (int i = 0; i < drawableContainerState.getChildCount(); i++) {
Drawable child = drawableContainerState.getChild(i);
forceStateChange(child, true);
}
}
}
示例11: ClassDescStateListDrawable
import android.graphics.drawable.DrawableContainer; //导入方法依赖的package包/类
public ClassDescStateListDrawable(ClassDescDrawableMgr classMgr, ClassDescElementDrawableContainer parent)
{
super(classMgr, "selector", parent);
this.methodGetStateListState = new MethodContainer<DrawableContainer.DrawableContainerState>(StateListDrawable.class,"getStateListState");
this.methodGetStateListStateIsConstantSize =
new MethodContainer<Void>(DrawableContainer.class.getName() + "$DrawableContainerState","setConstantSize",boolean.class);
}
示例12: initialize
import android.graphics.drawable.DrawableContainer; //导入方法依赖的package包/类
public void initialize(Context context, AttributeSet attrs) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
this.setBackground(getResources().getDrawable(R.drawable.toggle_background, null));
} else {
this.setBackground(getResources().getDrawable(R.drawable.toggle_background));
}
StateListDrawable stateListDrawable = (StateListDrawable) this.getBackground();
DrawableContainer.DrawableContainerState dcs = (DrawableContainer.DrawableContainerState) stateListDrawable.getConstantState();
Drawable[] drawableItems = dcs.getChildren();
GradientDrawable unChecked = (GradientDrawable) drawableItems[0];
GradientDrawable checked = (GradientDrawable) drawableItems[1];
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomToggleButton);
// getting all the attributes values set from the typed array i.e from user
int toggleOnColor = typedArray.getColor(R.styleable.CustomToggleButton_checkedColor, Color.parseColor("#FF4081"));
int toggleOffColor = typedArray.getColor(R.styleable.CustomToggleButton_uncheckedColor, Color.parseColor("#FF4081"));
float borderWidth = typedArray.getDimension(R.styleable.CustomToggleButton_borderWidth, 4.0f);
float radius = typedArray.getDimension(R.styleable.CustomToggleButton_radius, 15.0f);
int checkedTextColor = typedArray.getColor(R.styleable.CustomToggleButton_checkedTextColor, getResources().getColor(R.color.CheckedTextColor));
int uncheckedTextColor = typedArray.getColor(R.styleable.CustomToggleButton_uncheckedTextColor, getResources().getColor(R.color.uncheckedTextColor));
Log.d(TAG, "initialize: " + borderWidth);
ColorStateList colorStateList = new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_checked},
new int[]{-android.R.attr.state_checked}
},
new int[]{
checkedTextColor,
uncheckedTextColor
}
);
this.setTextColor(colorStateList);
checked.setStroke(Math.round(borderWidth), toggleOnColor);
checked.setColor(toggleOnColor);
checked.setCornerRadius(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, getResources().getDisplayMetrics()));
unChecked.setStroke(Math.round(borderWidth), toggleOffColor);
unChecked.setCornerRadius(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, getResources().getDisplayMetrics()));
}