package androidx.core.graphics.drawable;

import X.8n2;
import X.9EH;
import X.AnonymousClass0HH;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
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.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import androidx.versionedparcelable.CustomVersionedParcelable;
import com.apiguard3.APIGuard;
import com.bef.effectsdk.BuildConfig;
import com.bytedance.covode.number.Covode;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;

public class IconCompat extends CustomVersionedParcelable {
    public static final PorterDuff.Mode LJII = PorterDuff.Mode.SRC_IN;
    public int LIZ;
    public Object LIZIZ;
    public byte[] LIZJ;
    public Parcelable LIZLLL;
    public int LJ;
    public int LJFF;
    public ColorStateList LJI;
    public PorterDuff.Mode LJIIIIZZ;
    public String LJIIIZ;

    static {
        Covode.recordClassIndex(887);
    }

    public IconCompat() {
        this.LIZ = -1;
        this.LJIIIIZZ = LJII;
    }

    private Uri LIZLLL() {
        if (this.LIZ == -1 && Build.VERSION.SDK_INT >= 23) {
            return LIZLLL((Icon) this.LIZIZ);
        }
        int i = this.LIZ;
        if (i == 4 || i == 6) {
            return Uri.parse((String) this.LIZIZ);
        }
        throw new IllegalStateException("called getUri() on ".concat(String.valueOf(this)));
    }

    private String LIZJ() {
        if (this.LIZ == -1 && Build.VERSION.SDK_INT >= 23) {
            return LIZIZ((Icon) this.LIZIZ);
        }
        if (this.LIZ == 2) {
            return ((String) this.LIZIZ).split(":", -1)[0];
        }
        throw new IllegalStateException("called getResPackage() on ".concat(String.valueOf(this)));
    }

    public final Bundle LIZIZ() {
        Bundle bundle = new Bundle();
        switch (this.LIZ) {
            case -1:
                bundle.putParcelable("obj", (Parcelable) this.LIZIZ);
                break;
            case BuildConfig.VERSION_CODE /*1*/:
            case 5:
                bundle.putParcelable("obj", (Bitmap) this.LIZIZ);
                break;
            case APIGuard.INIT_PROCEED /*2*/:
            case 4:
            case 6:
                bundle.putString("obj", (String) this.LIZIZ);
                break;
            case 3:
                bundle.putByteArray("obj", (byte[]) this.LIZIZ);
                break;
            default:
                throw new IllegalArgumentException("Invalid icon");
        }
        bundle.putInt("type", this.LIZ);
        bundle.putInt("int1", this.LJ);
        bundle.putInt("int2", this.LJFF);
        ColorStateList colorStateList = this.LJI;
        if (colorStateList != null) {
            bundle.putParcelable("tint_list", colorStateList);
        }
        PorterDuff.Mode mode = this.LJIIIIZZ;
        if (mode != LJII) {
            bundle.putString("tint_mode", mode.name());
        }
        return bundle;
    }

    public String toString() {
        String str;
        if (this.LIZ == -1) {
            return String.valueOf(this.LIZIZ);
        }
        StringBuilder sb = new StringBuilder("Icon(typ=");
        switch (this.LIZ) {
            case BuildConfig.VERSION_CODE /*1*/:
                str = "BITMAP";
                break;
            case APIGuard.INIT_PROCEED /*2*/:
                str = "RESOURCE";
                break;
            case 3:
                str = "DATA";
                break;
            case 4:
                str = "URI";
                break;
            case 5:
                str = "BITMAP_MASKABLE";
                break;
            case 6:
                str = "URI_MASKABLE";
                break;
            default:
                str = "UNKNOWN";
                break;
        }
        sb.append(str);
        switch (this.LIZ) {
            case BuildConfig.VERSION_CODE /*1*/:
            case 5:
                sb.append(" size=");
                sb.append(((Bitmap) this.LIZIZ).getWidth());
                sb.append("x");
                sb.append(((Bitmap) this.LIZIZ).getHeight());
                break;
            case APIGuard.INIT_PROCEED /*2*/:
                sb.append(" pkg=");
                sb.append(LIZJ());
                sb.append(" id=");
                sb.append(AnonymousClass0HH.LIZ("0x%08x", new Object[]{Integer.valueOf(LIZ())}));
                break;
            case 3:
                sb.append(" len=");
                sb.append(this.LJ);
                if (this.LJFF != 0) {
                    sb.append(" off=");
                    sb.append(this.LJFF);
                    break;
                }
                break;
            case 4:
            case 6:
                sb.append(" uri=");
                sb.append(this.LIZIZ);
                break;
        }
        if (this.LJI != null) {
            sb.append(" tint=");
            sb.append(this.LJI);
        }
        if (this.LJIIIIZZ != LJII) {
            sb.append(" mode=");
            sb.append(this.LJIIIIZZ);
        }
        sb.append(")");
        return sb.toString();
    }

    public final int LIZ() {
        if (this.LIZ == -1 && Build.VERSION.SDK_INT >= 23) {
            return LIZJ((Icon) this.LIZIZ);
        }
        if (this.LIZ == 2) {
            return this.LJ;
        }
        throw new IllegalStateException("called getResId() on ".concat(String.valueOf(this)));
    }

    public IconCompat(byte b) {
        this.LIZ = -1;
        this.LJIIIIZZ = LJII;
        this.LIZ = 2;
    }

    public static int LIZ(Icon icon) {
        if (Build.VERSION.SDK_INT >= 28) {
            return icon.getType();
        }
        try {
            return ((Integer) icon.getClass().getMethod("getType", new Class[0]).invoke(icon, new Object[0])).intValue();
        } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) {
            return -1;
        }
    }

    public static String LIZIZ(Icon icon) {
        if (Build.VERSION.SDK_INT >= 28) {
            return icon.getResPackage();
        }
        try {
            return (String) icon.getClass().getMethod("getResPackage", new Class[0]).invoke(icon, new Object[0]);
        } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) {
            return null;
        }
    }

    public static int LIZJ(Icon icon) {
        if (Build.VERSION.SDK_INT >= 28) {
            return icon.getResId();
        }
        try {
            return ((Integer) icon.getClass().getMethod("getResId", new Class[0]).invoke(icon, new Object[0])).intValue();
        } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) {
            return 0;
        }
    }

    /* JADX WARNING: No exception handlers in catch block: Catch:{  } */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private java.io.InputStream LJ(android.content.Context r4) {
        /*
            r3 = this;
            android.net.Uri r2 = r3.LIZLLL()
            java.lang.String r1 = r2.getScheme()
            java.lang.String r0 = "content"
            boolean r0 = r0.equals(r1)
            if (r0 != 0) goto L_0x0028
            java.lang.String r0 = "file"
            boolean r0 = r0.equals(r1)
            if (r0 == 0) goto L_0x0019
            goto L_0x0028
        L_0x0019:
            java.io.FileInputStream r2 = new java.io.FileInputStream     // Catch:{ FileNotFoundException -> 0x0031 }
            java.io.File r1 = new java.io.File     // Catch:{ FileNotFoundException -> 0x0031 }
            java.lang.Object r0 = r3.LIZIZ     // Catch:{ FileNotFoundException -> 0x0031 }
            java.lang.String r0 = (java.lang.String) r0     // Catch:{ FileNotFoundException -> 0x0031 }
            r1.<init>(r0)     // Catch:{ FileNotFoundException -> 0x0031 }
            r2.<init>(r1)     // Catch:{ FileNotFoundException -> 0x0031 }
            return r2
        L_0x0028:
            android.content.ContentResolver r0 = r4.getContentResolver()     // Catch:{  }
            java.io.InputStream r0 = r0.openInputStream(r2)     // Catch:{  }
            return r0
        L_0x0031:
            r0 = 0
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.core.graphics.drawable.IconCompat.LJ(android.content.Context):java.io.InputStream");
    }

    public static Uri LIZLLL(Icon icon) {
        if (Build.VERSION.SDK_INT >= 28) {
            return icon.getUri();
        }
        try {
            return (Uri) icon.getClass().getMethod("getUri", new Class[0]).invoke(icon, new Object[0]);
        } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) {
            return null;
        }
    }

    public final Drawable LIZIZ(Context context) {
        LIZJ(context);
        if (Build.VERSION.SDK_INT >= 23) {
            return LIZ(context).loadDrawable(context);
        }
        Drawable LIZLLL2 = LIZLLL(context);
        if (!(LIZLLL2 == null || (this.LJI == null && this.LJIIIIZZ == LJII))) {
            LIZLLL2.mutate();
            LIZLLL2.setTintList(this.LJI);
            LIZLLL2.setTintMode(this.LJIIIIZZ);
        }
        return LIZLLL2;
    }

    public static Bitmap LIZ(Bitmap bitmap) {
        int min = (int) (((float) 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 = ((float) min) * 0.5f;
        paint.setColor(-16777216);
        Shader.TileMode tileMode = Shader.TileMode.CLAMP;
        BitmapShader bitmapShader = new BitmapShader(bitmap, tileMode, tileMode);
        Matrix matrix = new Matrix();
        matrix.setTranslate((float) ((-(bitmap.getWidth() - min)) / 2), (float) ((-(bitmap.getHeight() - min)) / 2));
        bitmapShader.setLocalMatrix(matrix);
        paint.setShader(bitmapShader);
        canvas.drawCircle(f, f, 0.9166667f * f, paint);
        canvas.setBitmap((Bitmap) null);
        return createBitmap;
    }

    private void LIZJ(Context context) {
        if (this.LIZ == 2) {
            String str = (String) this.LIZIZ;
            if (str.contains(":")) {
                String str2 = str.split(":", -1)[1];
                String str3 = str2.split("/", -1)[0];
                String str4 = str2.split("/", -1)[1];
                String str5 = str.split(":", -1)[0];
                int identifier = LIZ(context, str5).getIdentifier(str4, str3, str5);
                if (this.LJ != identifier) {
                    this.LJ = identifier;
                }
            }
        }
    }

    private Drawable LIZLLL(Context context) {
        switch (this.LIZ) {
            case BuildConfig.VERSION_CODE /*1*/:
                return new BitmapDrawable(context.getResources(), (Bitmap) this.LIZIZ);
            case APIGuard.INIT_PROCEED /*2*/:
                String LIZJ2 = LIZJ();
                if (TextUtils.isEmpty(LIZJ2)) {
                    LIZJ2 = context.getPackageName();
                }
                try {
                    return LIZ(context, LIZJ2).getDrawable(this.LJ, context.getTheme());
                } catch (RuntimeException unused) {
                    break;
                }
            case 3:
                return new BitmapDrawable(context.getResources(), BitmapFactory.decodeByteArray((byte[]) this.LIZIZ, this.LJ, this.LJFF));
            case 4:
                InputStream LJ2 = LJ(context);
                if (LJ2 != null) {
                    return new BitmapDrawable(context.getResources(), BitmapFactory.decodeStream(LJ2));
                }
                break;
            case 5:
                return new BitmapDrawable(context.getResources(), LIZ((Bitmap) this.LIZIZ));
            case 6:
                InputStream LJ3 = LJ(context);
                if (LJ3 != null) {
                    if (Build.VERSION.SDK_INT >= 26) {
                        return new AdaptiveIconDrawable((Drawable) null, new BitmapDrawable(context.getResources(), BitmapFactory.decodeStream(LJ3)));
                    }
                    return new BitmapDrawable(context.getResources(), LIZ(BitmapFactory.decodeStream(LJ3)));
                }
                break;
        }
        return null;
    }

    public final Icon LIZ(Context context) {
        Icon icon;
        switch (this.LIZ) {
            case -1:
                return (Icon) this.LIZIZ;
            case BuildConfig.VERSION_CODE /*1*/:
                icon = Icon.createWithBitmap((Bitmap) this.LIZIZ);
                break;
            case APIGuard.INIT_PROCEED /*2*/:
                icon = Icon.createWithResource(LIZJ(), this.LJ);
                break;
            case 3:
                icon = Icon.createWithData((byte[]) this.LIZIZ, this.LJ, this.LJFF);
                break;
            case 4:
                icon = Icon.createWithContentUri((String) this.LIZIZ);
                break;
            case 5:
                if (Build.VERSION.SDK_INT < 26) {
                    icon = Icon.createWithBitmap(LIZ((Bitmap) this.LIZIZ));
                    break;
                } else {
                    icon = Icon.createWithAdaptiveBitmap((Bitmap) this.LIZIZ);
                    break;
                }
            case 6:
                if (context != null) {
                    InputStream LJ2 = LJ(context);
                    if (LJ2 != null) {
                        if (Build.VERSION.SDK_INT < 26) {
                            icon = Icon.createWithBitmap(LIZ(BitmapFactory.decodeStream(LJ2)));
                            break;
                        } else {
                            icon = Icon.createWithAdaptiveBitmap(BitmapFactory.decodeStream(LJ2));
                            break;
                        }
                    } else {
                        throw new IllegalStateException("Cannot load adaptive icon from uri: " + LIZLLL());
                    }
                } else {
                    throw new IllegalArgumentException("Context is required to resolve the file uri of the icon: " + LIZLLL());
                }
            default:
                throw new IllegalArgumentException("Unknown type");
        }
        ColorStateList colorStateList = this.LJI;
        if (colorStateList != null) {
            icon.setTintList(colorStateList);
        }
        PorterDuff.Mode mode = this.LJIIIIZZ;
        if (mode != LJII) {
            icon.setTintMode(mode);
        }
        return icon;
    }

    public static IconCompat LIZ(Context context, int i) {
        if (context != null) {
            return LIZ(context.getResources(), context.getPackageName(), i);
        }
        throw new IllegalArgumentException("Context must not be null.");
    }

    public static Resources LIZ(Context context, String str) {
        if ("android".equals(str)) {
            return Resources.getSystem();
        }
        PackageManager packageManager = context.getPackageManager();
        try {
            Context LIZ2 = 9EH.LJJIFFI.LIZ();
            if (8n2.LJIIIZ) {
                TextUtils.equals(str, LIZ2.getPackageName());
            }
            if (8n2.LJIIIZ) {
                TextUtils.equals(str, LIZ2.getPackageName());
            }
            ApplicationInfo applicationInfo = packageManager.getApplicationInfo(str, 8192);
            if (applicationInfo != null) {
                return packageManager.getResourcesForApplication(applicationInfo);
            }
        } catch (PackageManager.NameNotFoundException unused) {
        }
        return null;
    }

    public static IconCompat LIZ(Resources resources, String str, int i) {
        if (str == null) {
            throw new IllegalArgumentException("Package must not be null.");
        } else if (i != 0) {
            IconCompat iconCompat = new IconCompat((byte) 0);
            iconCompat.LJ = i;
            if (resources != null) {
                try {
                    iconCompat.LIZIZ = resources.getResourceName(i);
                } catch (Resources.NotFoundException unused) {
                    throw new IllegalArgumentException("Icon resource cannot be found");
                }
            } else {
                iconCompat.LIZIZ = str;
            }
            return iconCompat;
        } else {
            throw new IllegalArgumentException("Drawable resource ID must not be 0");
        }
    }
}
