本文整理汇总了Java中android.graphics.drawable.DrawableContainer类的典型用法代码示例。如果您正苦于以下问题:Java DrawableContainer类的具体用法?Java DrawableContainer怎么用?Java DrawableContainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DrawableContainer类属于android.graphics.drawable包,在下文中一共展示了DrawableContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: setContainerConstantStateV9
import android.graphics.drawable.DrawableContainer; //导入依赖的package包/类
private static boolean setContainerConstantStateV9(DrawableContainer drawable, ConstantState constantState) {
if (!sSetConstantStateMethodFetched) {
try {
sSetConstantStateMethod = DrawableContainer.class.getDeclaredMethod("setConstantState", new Class[]{DrawableContainerState.class});
sSetConstantStateMethod.setAccessible(true);
} catch (NoSuchMethodException e) {
Log.e(LOG_TAG, "Could not fetch setConstantState(). Oh well.");
}
sSetConstantStateMethodFetched = true;
}
if (sSetConstantStateMethod != null) {
try {
sSetConstantStateMethod.invoke(drawable, new Object[]{constantState});
return true;
} catch (Exception e2) {
Log.e(LOG_TAG, "Could not invoke setConstantState(). Oh well.");
}
}
return false;
}
示例3: setContainerConstantStateV7
import android.graphics.drawable.DrawableContainer; //导入依赖的package包/类
private static boolean setContainerConstantStateV7(DrawableContainer drawable, ConstantState constantState) {
if (!sDrawableContainerStateFieldFetched) {
try {
sDrawableContainerStateField = DrawableContainer.class.getDeclaredField("mDrawableContainerStateField");
sDrawableContainerStateField.setAccessible(true);
} catch (NoSuchFieldException e) {
Log.e(LOG_TAG, "Could not fetch mDrawableContainerStateField. Oh well.");
}
sDrawableContainerStateFieldFetched = true;
}
if (sDrawableContainerStateField != null) {
try {
sDrawableContainerStateField.set(drawable, constantState);
return true;
} catch (Exception e2) {
Log.e(LOG_TAG, "Could not set mDrawableContainerStateField. Oh well.");
}
}
return false;
}
示例4: 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;
}
示例5: 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);
}
示例6: 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;
}
示例7: wrapForTinting
import android.graphics.drawable.DrawableContainer; //导入依赖的package包/类
public static Drawable wrapForTinting(Drawable drawable)
{
Object obj;
label0:
{
if (!(drawable instanceof GradientDrawable))
{
obj = drawable;
if (!(drawable instanceof DrawableContainer))
{
break label0;
}
}
obj = new DrawableWrapperLollipop(drawable);
}
return ((Drawable) (obj));
}
示例8: isEquals
import android.graphics.drawable.DrawableContainer; //导入依赖的package包/类
/**
* Check if two Drawables are equal. A regular check for a Drawable equals
* just checks for the instance reference, while this check is doing a
* deeper equals when dealing with {@link DrawableContainer} instances. In
* these cases, the method will run equals on each of the child drawables in
* the container (order is importance as well).
*
* @param d1
* @param d2
* @return <code>true</code> if the drawables are equal, <code>false</code>
* otherwise.
*/
public static boolean isEquals(Drawable d1, Drawable d2) {
if (d1 == d2) {
return true;
}
if (d1 == null || d2 == null) {
return false;
}
if (d1 instanceof DrawableContainer && d2 instanceof DrawableContainer) {
// Try to match the content of those containers
DrawableContainerState containerState1 = (DrawableContainerState) ((DrawableContainer) d1)
.getConstantState();
DrawableContainerState containerState2 = (DrawableContainerState) ((DrawableContainer) d2)
.getConstantState();
return Arrays.equals(containerState1.getChildren(), containerState2.getChildren());
}
return d1.equals(d2);
}
示例9: 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;
}
示例10: ensureBackgroundDrawableStateWorkaround
import android.graphics.drawable.DrawableContainer; //导入依赖的package包/类
private void ensureBackgroundDrawableStateWorkaround() {
final int sdk = Build.VERSION.SDK_INT;
if (sdk != 21 && sdk != 22) {
// The workaround is only required on API 21-22
return;
}
final Drawable bg = mEditText.getBackground();
if (bg == null) {
return;
}
if (!mHasReconstructedEditTextBackground) {
// This is gross. There is an issue in the platform which affects container Drawables
// where the first drawable retrieved from resources will propagate any changes
// (like color filter) to all instances from the cache. We'll try to workaround it...
final Drawable newBg = bg.getConstantState().newDrawable();
if (bg instanceof DrawableContainer) {
// If we have a Drawable container, we can try and set it's constant state via
// reflection from the new Drawable
mHasReconstructedEditTextBackground =
com.commonsware.cwac.crossport.design.widget.DrawableUtils.setContainerConstantState(
(DrawableContainer) bg, newBg.getConstantState());
}
if (!mHasReconstructedEditTextBackground) {
// If we reach here then we just need to set a brand new instance of the Drawable
// as the background. This has the unfortunate side-effect of wiping out any
// user set padding, but I'd hope that use of custom padding on an EditText
// is limited.
ViewCompat.setBackground(mEditText, newBg);
mHasReconstructedEditTextBackground = true;
}
}
}
示例11: isCompatTintEnabled
import android.graphics.drawable.DrawableContainer; //导入依赖的package包/类
protected boolean isCompatTintEnabled() {
if (VERSION.SDK_INT != 21) {
return false;
}
Drawable drawable = this.mDrawable;
if ((drawable instanceof GradientDrawable) || (drawable instanceof DrawableContainer) || (drawable instanceof InsetDrawable)) {
return true;
}
return false;
}
示例12: ensureBackgroundDrawableStateWorkaround
import android.graphics.drawable.DrawableContainer; //导入依赖的package包/类
private void ensureBackgroundDrawableStateWorkaround() {
Drawable bg = this.mEditText.getBackground();
if (bg != null && !this.mHasReconstructedEditTextBackground) {
Drawable newBg = bg.getConstantState().newDrawable();
if (bg instanceof DrawableContainer) {
this.mHasReconstructedEditTextBackground = DrawableUtils.setContainerConstantState((DrawableContainer) bg, newBg.getConstantState());
}
if (!this.mHasReconstructedEditTextBackground) {
this.mEditText.setBackgroundDrawable(newBg);
this.mHasReconstructedEditTextBackground = true;
}
}
}
示例13: 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;
}
示例14: m2634b
import android.graphics.drawable.DrawableContainer; //导入依赖的package包/类
public static boolean m2634b(Drawable drawable) {
if (drawable instanceof LayerDrawable) {
return VERSION.SDK_INT >= 16;
} else if (drawable instanceof InsetDrawable) {
return VERSION.SDK_INT >= 14;
} else {
if (drawable instanceof StateListDrawable) {
return VERSION.SDK_INT >= 8;
} else {
if (drawable instanceof GradientDrawable) {
return VERSION.SDK_INT >= 14;
} else {
if (!(drawable instanceof DrawableContainer)) {
return drawable instanceof C0063q ? m2634b(((C0063q) drawable).m469a()) : drawable instanceof C0244a ? m2634b(((C0244a) drawable).m1984a()) : drawable instanceof ScaleDrawable ? m2634b(((ScaleDrawable) drawable).getDrawable()) : true;
} else {
ConstantState constantState = drawable.getConstantState();
if (!(constantState instanceof DrawableContainerState)) {
return true;
}
for (Drawable b : ((DrawableContainerState) constantState).getChildren()) {
if (!m2634b(b)) {
return false;
}
}
return true;
}
}
}
}
}
示例15: m487c
import android.graphics.drawable.DrawableContainer; //导入依赖的package包/类
protected boolean m487c() {
if (VERSION.SDK_INT != 21) {
return false;
}
Drawable drawable = this.c;
return (drawable instanceof GradientDrawable) || (drawable instanceof DrawableContainer) || (drawable instanceof InsetDrawable);
}