mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-16 02:47:17 +01:00
239 lines
8.7 KiB
Java
239 lines
8.7 KiB
Java
package com.google.android.material.drawable;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.ColorStateList;
|
|
import android.content.res.Resources;
|
|
import android.content.res.XmlResourceParser;
|
|
import android.graphics.Outline;
|
|
import android.graphics.Path;
|
|
import android.graphics.PorterDuff;
|
|
import android.graphics.PorterDuffColorFilter;
|
|
import android.graphics.drawable.ColorDrawable;
|
|
import android.graphics.drawable.ColorStateListDrawable;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.graphics.drawable.LayerDrawable;
|
|
import android.graphics.drawable.RippleDrawable;
|
|
import android.os.Build;
|
|
import android.text.TextUtils;
|
|
import android.util.AttributeSet;
|
|
import android.util.Xml;
|
|
import androidx.annotation.ColorInt;
|
|
import androidx.annotation.DoNotInline;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.Px;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.annotation.XmlRes;
|
|
import androidx.collection.DoubleList$$ExternalSyntheticOutline0;
|
|
import androidx.core.graphics.drawable.DrawableCompat;
|
|
import java.io.IOException;
|
|
import java.util.Arrays;
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
|
|
/* loaded from: classes7.dex */
|
|
public final class DrawableUtils {
|
|
public static final int INTRINSIC_SIZE = -1;
|
|
private static final int UNSPECIFIED_HEIGHT = -1;
|
|
private static final int UNSPECIFIED_WIDTH = -1;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public static class OutlineCompatL {
|
|
private OutlineCompatL() {
|
|
}
|
|
|
|
@DoNotInline
|
|
public static void setConvexPath(@NonNull Outline outline, @NonNull Path path) {
|
|
outline.setConvexPath(path);
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@RequiresApi(30)
|
|
public static class OutlineCompatR {
|
|
private OutlineCompatR() {
|
|
}
|
|
|
|
@DoNotInline
|
|
public static void setPath(@NonNull Outline outline, @NonNull Path path) {
|
|
outline.setPath(path);
|
|
}
|
|
}
|
|
|
|
private DrawableUtils() {
|
|
}
|
|
|
|
@Nullable
|
|
public static Drawable compositeTwoLayeredDrawable(@Nullable Drawable drawable, @Nullable Drawable drawable2, @Px int i, @Px int i2) {
|
|
if (drawable == null) {
|
|
return drawable2;
|
|
}
|
|
if (drawable2 == null) {
|
|
return drawable;
|
|
}
|
|
if (i == -1) {
|
|
i = getTopLayerIntrinsicWidth(drawable, drawable2);
|
|
}
|
|
if (i2 == -1) {
|
|
i2 = getTopLayerIntrinsicHeight(drawable, drawable2);
|
|
}
|
|
if (i > drawable.getIntrinsicWidth() || i2 > drawable.getIntrinsicHeight()) {
|
|
float f = i / i2;
|
|
if (f >= drawable.getIntrinsicWidth() / drawable.getIntrinsicHeight()) {
|
|
int intrinsicWidth = drawable.getIntrinsicWidth();
|
|
i2 = (int) (intrinsicWidth / f);
|
|
i = intrinsicWidth;
|
|
} else {
|
|
i2 = drawable.getIntrinsicHeight();
|
|
i = (int) (f * i2);
|
|
}
|
|
}
|
|
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{drawable, drawable2});
|
|
layerDrawable.setLayerSize(1, i, i2);
|
|
layerDrawable.setLayerGravity(1, 17);
|
|
return layerDrawable;
|
|
}
|
|
|
|
@Nullable
|
|
public static Drawable createTintableDrawableIfNeeded(@Nullable Drawable drawable, @Nullable ColorStateList colorStateList, @Nullable PorterDuff.Mode mode) {
|
|
return createTintableMutatedDrawableIfNeeded(drawable, colorStateList, mode, false);
|
|
}
|
|
|
|
@Nullable
|
|
private static Drawable createTintableMutatedDrawableIfNeeded(@Nullable Drawable drawable, @Nullable ColorStateList colorStateList, @Nullable PorterDuff.Mode mode, boolean z) {
|
|
if (drawable == null) {
|
|
return null;
|
|
}
|
|
if (colorStateList == null) {
|
|
if (z) {
|
|
drawable.mutate();
|
|
}
|
|
return drawable;
|
|
}
|
|
Drawable mutate = DrawableCompat.wrap(drawable).mutate();
|
|
if (mode != null) {
|
|
mutate.setTintMode(mode);
|
|
}
|
|
return mutate;
|
|
}
|
|
|
|
@NonNull
|
|
public static int[] getCheckedState(@NonNull int[] iArr) {
|
|
for (int i = 0; i < iArr.length; i++) {
|
|
int i2 = iArr[i];
|
|
if (i2 == 16842912) {
|
|
return iArr;
|
|
}
|
|
if (i2 == 0) {
|
|
int[] iArr2 = (int[]) iArr.clone();
|
|
iArr2[i] = 16842912;
|
|
return iArr2;
|
|
}
|
|
}
|
|
int[] copyOf = Arrays.copyOf(iArr, iArr.length + 1);
|
|
copyOf[iArr.length] = 16842912;
|
|
return copyOf;
|
|
}
|
|
|
|
@Nullable
|
|
public static ColorStateList getColorStateListOrNull(@Nullable Drawable drawable) {
|
|
if (drawable instanceof ColorDrawable) {
|
|
return ColorStateList.valueOf(((ColorDrawable) drawable).getColor());
|
|
}
|
|
if (drawable instanceof ColorStateListDrawable) {
|
|
return ((ColorStateListDrawable) drawable).getColorStateList();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static int getTopLayerIntrinsicHeight(@NonNull Drawable drawable, @NonNull Drawable drawable2) {
|
|
int intrinsicHeight = drawable2.getIntrinsicHeight();
|
|
return intrinsicHeight != -1 ? intrinsicHeight : drawable.getIntrinsicHeight();
|
|
}
|
|
|
|
private static int getTopLayerIntrinsicWidth(@NonNull Drawable drawable, @NonNull Drawable drawable2) {
|
|
int intrinsicWidth = drawable2.getIntrinsicWidth();
|
|
return intrinsicWidth != -1 ? intrinsicWidth : drawable.getIntrinsicWidth();
|
|
}
|
|
|
|
@NonNull
|
|
public static int[] getUncheckedState(@NonNull int[] iArr) {
|
|
int[] iArr2 = new int[iArr.length];
|
|
int i = 0;
|
|
for (int i2 : iArr) {
|
|
if (i2 != 16842912) {
|
|
iArr2[i] = i2;
|
|
i++;
|
|
}
|
|
}
|
|
return iArr2;
|
|
}
|
|
|
|
@NonNull
|
|
public static AttributeSet parseDrawableXml(@NonNull Context context, @XmlRes int i, @NonNull CharSequence charSequence) {
|
|
int next;
|
|
try {
|
|
XmlResourceParser xml = context.getResources().getXml(i);
|
|
do {
|
|
next = xml.next();
|
|
if (next == 2) {
|
|
break;
|
|
}
|
|
} while (next != 1);
|
|
if (next != 2) {
|
|
throw new XmlPullParserException("No start tag found");
|
|
}
|
|
if (TextUtils.equals(xml.getName(), charSequence)) {
|
|
return Xml.asAttributeSet(xml);
|
|
}
|
|
throw new XmlPullParserException("Must have a <" + ((Object) charSequence) + "> start tag");
|
|
} catch (IOException | XmlPullParserException e) {
|
|
Resources.NotFoundException notFoundException = new Resources.NotFoundException(DoubleList$$ExternalSyntheticOutline0.m(i, new StringBuilder("Can't load badge resource ID #0x")));
|
|
notFoundException.initCause(e);
|
|
throw notFoundException;
|
|
}
|
|
}
|
|
|
|
public static void setOutlineToPath(@NonNull Outline outline, @NonNull Path path) {
|
|
if (Build.VERSION.SDK_INT >= 30) {
|
|
OutlineCompatR.setPath(outline, path);
|
|
} else {
|
|
try {
|
|
OutlineCompatL.setConvexPath(outline, path);
|
|
} catch (IllegalArgumentException unused) {
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void setRippleDrawableRadius(@Nullable RippleDrawable rippleDrawable, int i) {
|
|
rippleDrawable.setRadius(i);
|
|
}
|
|
|
|
public static void setTint(@NonNull Drawable drawable, @ColorInt int i) {
|
|
if (i != 0) {
|
|
drawable.setTint(i);
|
|
} else {
|
|
drawable.setTintList(null);
|
|
}
|
|
}
|
|
|
|
@Nullable
|
|
public static PorterDuffColorFilter updateTintFilter(@NonNull Drawable drawable, @Nullable ColorStateList colorStateList, @Nullable PorterDuff.Mode mode) {
|
|
if (colorStateList == null || mode == null) {
|
|
return null;
|
|
}
|
|
return new PorterDuffColorFilter(colorStateList.getColorForState(drawable.getState(), 0), mode);
|
|
}
|
|
|
|
@Nullable
|
|
public static Drawable createTintableMutatedDrawableIfNeeded(@Nullable Drawable drawable, @Nullable ColorStateList colorStateList, @Nullable PorterDuff.Mode mode) {
|
|
return createTintableMutatedDrawableIfNeeded(drawable, colorStateList, mode, false);
|
|
}
|
|
|
|
@Nullable
|
|
public static Drawable compositeTwoLayeredDrawable(@Nullable Drawable drawable, @Nullable Drawable drawable2) {
|
|
return compositeTwoLayeredDrawable(drawable, drawable2, -1, -1);
|
|
}
|
|
}
|