package androidx.core.graphics.drawable; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.Shader; import android.graphics.drawable.Icon; import android.net.Uri; import android.os.Build; import android.os.Parcelable; import android.text.TextUtils; import androidx.versionedparcelable.CustomVersionedParcelable; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.huawei.hms.framework.network.grs.GrsBaseInfo; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.nio.charset.Charset; import o.ZEY; /* loaded from: classes.dex */ public class IconCompat extends CustomVersionedParcelable { static final PorterDuff.Mode a = PorterDuff.Mode.SRC_IN; public int b; public byte[] c; Object d; public int e; public String f; public Parcelable g; public ColorStateList h; PorterDuff.Mode i; public String j; /* renamed from: o, reason: collision with root package name */ public int f6386o; public static IconCompat pZ_(Resources resources, String str, int i) { ZEY.d(str); if (i == 0) { throw new IllegalArgumentException("Drawable resource ID must not be 0"); } IconCompat iconCompat = new IconCompat(2); iconCompat.e = i; if (resources != null) { try { iconCompat.d = resources.getResourceName(i); } catch (Resources.NotFoundException unused) { throw new IllegalArgumentException("Icon resource cannot be found"); } } else { iconCompat.d = str; } iconCompat.f = str; return iconCompat; } public static IconCompat pY_(Bitmap bitmap) { ZEY.d(bitmap); IconCompat iconCompat = new IconCompat(1); iconCompat.d = bitmap; return iconCompat; } public IconCompat() { this.f6386o = -1; this.c = null; this.g = null; this.e = 0; this.b = 0; this.h = null; this.i = a; this.j = null; } IconCompat(int i) { this.c = null; this.g = null; this.e = 0; this.b = 0; this.h = null; this.i = a; this.j = null; this.f6386o = i; } public int c() { int i = this.f6386o; return i == -1 ? HBt.b(this.d) : i; } public String a() { int i = this.f6386o; if (i == -1) { return HBt.e(this.d); } if (i != 2) { throw new IllegalStateException("called getResPackage() on ".concat(String.valueOf(this))); } String str = this.f; return (str == null || TextUtils.isEmpty(str)) ? ((String) this.d).split(":", -1)[0] : this.f; } public int e() { int i = this.f6386o; if (i == -1) { return HBt.c(this.d); } if (i == 2) { return this.e; } throw new IllegalStateException("called getResId() on ".concat(String.valueOf(this))); } public Bitmap qa_() { int i = this.f6386o; if (i == -1) { Object obj = this.d; if (obj instanceof Bitmap) { return (Bitmap) obj; } return null; } if (i == 1) { return (Bitmap) this.d; } if (i == 5) { return pX_((Bitmap) this.d, true); } throw new IllegalStateException("called getBitmap() on ".concat(String.valueOf(this))); } public Uri qb_() { int i = this.f6386o; if (i == -1) { return HBt.qe_(this.d); } if (i != 4 && i != 6) { throw new IllegalStateException("called getUri() on ".concat(String.valueOf(this))); } return Uri.parse((String) this.d); } @Deprecated public Icon qc_() { return qd_(null); } public Icon qd_(Context context) { return HBt.qf_(this, context); } public InputStream a(Context context) { Uri qb_ = qb_(); String scheme = qb_.getScheme(); if ("content".equals(scheme) || "file".equals(scheme)) { return context.getContentResolver().openInputStream(qb_); } try { return new FileInputStream(new File((String) this.d)); } catch (FileNotFoundException | Exception unused) { return null; } } public String toString() { if (this.f6386o == -1) { return String.valueOf(this.d); } StringBuilder sb = new StringBuilder("Icon(typ="); sb.append(a(this.f6386o)); switch (this.f6386o) { case 1: case 5: sb.append(" size="); sb.append(((Bitmap) this.d).getWidth()); sb.append("x"); sb.append(((Bitmap) this.d).getHeight()); break; case 2: sb.append(" pkg="); sb.append(this.f); sb.append(" id="); sb.append(String.format("0x%08x", Integer.valueOf(e()))); break; case 3: sb.append(" len="); sb.append(this.e); if (this.b != 0) { sb.append(" off="); sb.append(this.b); break; } break; case 4: case 6: sb.append(" uri="); sb.append(this.d); break; } if (this.h != null) { sb.append(" tint="); sb.append(this.h); } if (this.i != a) { sb.append(" mode="); sb.append(this.i); } sb.append(")"); return sb.toString(); } @Override // androidx.versionedparcelable.CustomVersionedParcelable public void c(boolean z) { this.j = this.i.name(); switch (this.f6386o) { case -1: if (z) { throw new IllegalArgumentException("Can't serialize Icon created with IconCompat#createFromIcon"); } this.g = (Parcelable) this.d; return; case 0: default: return; case 1: case 5: if (z) { Bitmap bitmap = (Bitmap) this.d; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 90, byteArrayOutputStream); this.c = byteArrayOutputStream.toByteArray(); return; } this.g = (Parcelable) this.d; return; case 2: this.c = ((String) this.d).getBytes(Charset.forName("UTF-16")); return; case 3: this.c = (byte[]) this.d; return; case 4: case 6: this.c = this.d.toString().getBytes(Charset.forName("UTF-16")); return; } } @Override // androidx.versionedparcelable.CustomVersionedParcelable public void g() { this.i = PorterDuff.Mode.valueOf(this.j); switch (this.f6386o) { case -1: Parcelable parcelable = this.g; if (parcelable == null) { throw new IllegalArgumentException("Invalid icon"); } this.d = parcelable; return; case 0: default: return; case 1: case 5: Parcelable parcelable2 = this.g; if (parcelable2 != null) { this.d = parcelable2; return; } byte[] bArr = this.c; this.d = bArr; this.f6386o = 3; this.e = 0; this.b = bArr.length; return; case 2: case 4: case 6: String str = new String(this.c, Charset.forName("UTF-16")); this.d = str; if (this.f6386o == 2 && this.f == null) { this.f = str.split(":", -1)[0]; return; } return; case 3: this.d = this.c; return; } } static Bitmap pX_(Bitmap bitmap, boolean z) { int min = (int) (Math.min(bitmap.getWidth(), bitmap.getHeight()) * 0.6666667f); Bitmap createBitmap = Bitmap.createBitmap(min, min, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(createBitmap); Paint paint = new Paint(3); float f = min; float f2 = 0.5f * f; float f3 = 0.9166667f * f2; if (z) { float f4 = 0.010416667f * f; paint.setColor(0); paint.setShadowLayer(f4, BitmapDescriptorFactory.HUE_RED, f * 0.020833334f, 1023410176); canvas.drawCircle(f2, f2, f3, paint); paint.setShadowLayer(f4, BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, 503316480); canvas.drawCircle(f2, f2, f3, paint); paint.clearShadowLayer(); } paint.setColor(-16777216); Shader.TileMode tileMode = Shader.TileMode.CLAMP; BitmapShader bitmapShader = new BitmapShader(bitmap, tileMode, tileMode); Matrix matrix = new Matrix(); matrix.setTranslate((-(bitmap.getWidth() - min)) / 2.0f, (-(bitmap.getHeight() - min)) / 2.0f); bitmapShader.setLocalMatrix(matrix); paint.setShader(bitmapShader); canvas.drawCircle(f2, f2, f3, paint); canvas.setBitmap(null); return createBitmap; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static class IeS { static String c(Object obj) { return ((Icon) obj).getResPackage(); } static int b(Object obj) { return ((Icon) obj).getType(); } static int e(Object obj) { return ((Icon) obj).getResId(); } static Uri qh_(Object obj) { return ((Icon) obj).getUri(); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static class Sts { static Icon qg_(Bitmap bitmap) { return Icon.createWithAdaptiveBitmap(bitmap); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static class LWm { static Icon qi_(Uri uri) { return Icon.createWithAdaptiveBitmapContentUri(uri); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static class HBt { static int b(Object obj) { if (Build.VERSION.SDK_INT >= 28) { return IeS.b(obj); } try { return ((Integer) obj.getClass().getMethod("getType", new Class[0]).invoke(obj, new Object[0])).intValue(); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) { return -1; } } static String e(Object obj) { if (Build.VERSION.SDK_INT >= 28) { return IeS.c(obj); } try { return (String) obj.getClass().getMethod("getResPackage", new Class[0]).invoke(obj, new Object[0]); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) { return null; } } static int c(Object obj) { if (Build.VERSION.SDK_INT >= 28) { return IeS.e(obj); } try { return ((Integer) obj.getClass().getMethod("getResId", new Class[0]).invoke(obj, new Object[0])).intValue(); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) { return 0; } } static Uri qe_(Object obj) { if (Build.VERSION.SDK_INT >= 28) { return IeS.qh_(obj); } try { return (Uri) obj.getClass().getMethod("getUri", new Class[0]).invoke(obj, new Object[0]); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) { return null; } } static Icon qf_(IconCompat iconCompat, Context context) { Icon createWithBitmap; switch (iconCompat.f6386o) { case -1: return (Icon) iconCompat.d; case 0: default: throw new IllegalArgumentException("Unknown type"); case 1: createWithBitmap = Icon.createWithBitmap((Bitmap) iconCompat.d); break; case 2: createWithBitmap = Icon.createWithResource(iconCompat.a(), iconCompat.e); break; case 3: createWithBitmap = Icon.createWithData((byte[]) iconCompat.d, iconCompat.e, iconCompat.b); break; case 4: createWithBitmap = Icon.createWithContentUri((String) iconCompat.d); break; case 5: createWithBitmap = Sts.qg_((Bitmap) iconCompat.d); break; case 6: if (Build.VERSION.SDK_INT >= 30) { createWithBitmap = LWm.qi_(iconCompat.qb_()); break; } else { if (context == null) { StringBuilder sb = new StringBuilder("Context is required to resolve the file uri of the icon: "); sb.append(iconCompat.qb_()); throw new IllegalArgumentException(sb.toString()); } InputStream a = iconCompat.a(context); if (a == null) { StringBuilder sb2 = new StringBuilder("Cannot load adaptive icon from uri: "); sb2.append(iconCompat.qb_()); throw new IllegalStateException(sb2.toString()); } createWithBitmap = Sts.qg_(BitmapFactory.decodeStream(a)); break; } } if (iconCompat.h != null) { createWithBitmap.setTintList(iconCompat.h); } if (iconCompat.i != IconCompat.a) { createWithBitmap.setTintMode(iconCompat.i); } return createWithBitmap; } } private static String a(int i) { switch (i) { case 1: return "BITMAP"; case 2: return "RESOURCE"; case 3: return "DATA"; case 4: return "URI"; case 5: return "BITMAP_MASKABLE"; case 6: return "URI_MASKABLE"; default: return GrsBaseInfo.CountryCodeSource.UNKNOWN; } } }