167 lines
6.5 KiB
Java
167 lines
6.5 KiB
Java
package androidx.core.graphics.drawable;
|
|
|
|
import android.content.res.ColorStateList;
|
|
import android.content.res.Resources;
|
|
import android.graphics.ColorFilter;
|
|
import android.graphics.PorterDuff;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.graphics.drawable.DrawableContainer;
|
|
import android.graphics.drawable.InsetDrawable;
|
|
import android.os.Build;
|
|
import android.util.AttributeSet;
|
|
import android.util.Log;
|
|
import androidx.annotation.ColorInt;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import java.io.IOException;
|
|
import java.lang.reflect.Method;
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
/* loaded from: classes.dex */
|
|
public final class DrawableCompat {
|
|
private static final String TAG = "DrawableCompat";
|
|
private static Method sGetLayoutDirectionMethod;
|
|
private static boolean sGetLayoutDirectionMethodFetched;
|
|
private static Method sSetLayoutDirectionMethod;
|
|
private static boolean sSetLayoutDirectionMethodFetched;
|
|
|
|
private DrawableCompat() {
|
|
}
|
|
|
|
public static void applyTheme(@NonNull Drawable drawable, @NonNull Resources.Theme theme) {
|
|
drawable.applyTheme(theme);
|
|
}
|
|
|
|
public static boolean canApplyTheme(@NonNull Drawable drawable) {
|
|
return drawable.canApplyTheme();
|
|
}
|
|
|
|
public static void clearColorFilter(@NonNull Drawable drawable) {
|
|
DrawableContainer.DrawableContainerState drawableContainerState;
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
drawable.clearColorFilter();
|
|
return;
|
|
}
|
|
drawable.clearColorFilter();
|
|
if (drawable instanceof InsetDrawable) {
|
|
clearColorFilter(((InsetDrawable) drawable).getDrawable());
|
|
} else if (drawable instanceof WrappedDrawable) {
|
|
clearColorFilter(((WrappedDrawable) drawable).getWrappedDrawable());
|
|
} else if ((drawable instanceof DrawableContainer) && (drawableContainerState = (DrawableContainer.DrawableContainerState) ((DrawableContainer) drawable).getConstantState()) != null) {
|
|
int childCount = drawableContainerState.getChildCount();
|
|
for (int i = 0; i < childCount; i++) {
|
|
Drawable child = drawableContainerState.getChild(i);
|
|
if (child != null) {
|
|
clearColorFilter(child);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static int getAlpha(@NonNull Drawable drawable) {
|
|
return drawable.getAlpha();
|
|
}
|
|
|
|
public static ColorFilter getColorFilter(@NonNull Drawable drawable) {
|
|
return drawable.getColorFilter();
|
|
}
|
|
|
|
public static int getLayoutDirection(@NonNull Drawable drawable) {
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
return drawable.getLayoutDirection();
|
|
}
|
|
if (!sGetLayoutDirectionMethodFetched) {
|
|
try {
|
|
Method declaredMethod = Drawable.class.getDeclaredMethod("getLayoutDirection", new Class[0]);
|
|
sGetLayoutDirectionMethod = declaredMethod;
|
|
declaredMethod.setAccessible(true);
|
|
} catch (NoSuchMethodException e) {
|
|
Log.i(TAG, "Failed to retrieve getLayoutDirection() method", e);
|
|
}
|
|
sGetLayoutDirectionMethodFetched = true;
|
|
}
|
|
Method method = sGetLayoutDirectionMethod;
|
|
if (method != null) {
|
|
try {
|
|
return ((Integer) method.invoke(drawable, new Object[0])).intValue();
|
|
} catch (Exception e2) {
|
|
Log.i(TAG, "Failed to invoke getLayoutDirection() via reflection", e2);
|
|
sGetLayoutDirectionMethod = null;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static void inflate(@NonNull Drawable drawable, @NonNull Resources resources, @NonNull XmlPullParser xmlPullParser, @NonNull AttributeSet attributeSet, @Nullable Resources.Theme theme) throws XmlPullParserException, IOException {
|
|
drawable.inflate(resources, xmlPullParser, attributeSet, theme);
|
|
}
|
|
|
|
public static boolean isAutoMirrored(@NonNull Drawable drawable) {
|
|
return drawable.isAutoMirrored();
|
|
}
|
|
|
|
@Deprecated
|
|
public static void jumpToCurrentState(@NonNull Drawable drawable) {
|
|
drawable.jumpToCurrentState();
|
|
}
|
|
|
|
public static void setAutoMirrored(@NonNull Drawable drawable, boolean z2) {
|
|
drawable.setAutoMirrored(z2);
|
|
}
|
|
|
|
public static void setHotspot(@NonNull Drawable drawable, float f, float f2) {
|
|
drawable.setHotspot(f, f2);
|
|
}
|
|
|
|
public static void setHotspotBounds(@NonNull Drawable drawable, int i, int i2, int i3, int i4) {
|
|
drawable.setHotspotBounds(i, i2, i3, i4);
|
|
}
|
|
|
|
public static boolean setLayoutDirection(@NonNull Drawable drawable, int i) {
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
return drawable.setLayoutDirection(i);
|
|
}
|
|
if (!sSetLayoutDirectionMethodFetched) {
|
|
try {
|
|
Method declaredMethod = Drawable.class.getDeclaredMethod("setLayoutDirection", Integer.TYPE);
|
|
sSetLayoutDirectionMethod = declaredMethod;
|
|
declaredMethod.setAccessible(true);
|
|
} catch (NoSuchMethodException e) {
|
|
Log.i(TAG, "Failed to retrieve setLayoutDirection(int) method", e);
|
|
}
|
|
sSetLayoutDirectionMethodFetched = true;
|
|
}
|
|
Method method = sSetLayoutDirectionMethod;
|
|
if (method != null) {
|
|
try {
|
|
method.invoke(drawable, Integer.valueOf(i));
|
|
return true;
|
|
} catch (Exception e2) {
|
|
Log.i(TAG, "Failed to invoke setLayoutDirection(int) via reflection", e2);
|
|
sSetLayoutDirectionMethod = null;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static void setTint(@NonNull Drawable drawable, @ColorInt int i) {
|
|
drawable.setTint(i);
|
|
}
|
|
|
|
public static void setTintList(@NonNull Drawable drawable, @Nullable ColorStateList colorStateList) {
|
|
drawable.setTintList(colorStateList);
|
|
}
|
|
|
|
public static void setTintMode(@NonNull Drawable drawable, @NonNull PorterDuff.Mode mode) {
|
|
drawable.setTintMode(mode);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static <T extends Drawable> T unwrap(@NonNull Drawable drawable) {
|
|
return drawable instanceof WrappedDrawable ? (T) ((WrappedDrawable) drawable).getWrappedDrawable() : drawable;
|
|
}
|
|
|
|
public static Drawable wrap(@NonNull Drawable drawable) {
|
|
return (Build.VERSION.SDK_INT < 23 && !(drawable instanceof TintAwareDrawable)) ? new WrappedDrawableApi21(drawable) : drawable;
|
|
}
|
|
}
|