package androidx.core.graphics.drawable;

import A1.c;
import L4.a;
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.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
import androidx.versionedparcelable.CustomVersionedParcelable;
import com.revenuecat.purchases.common.Constants;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/* JADX INFO: loaded from: classes.dex */
public class IconCompat extends CustomVersionedParcelable {

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static final PorterDuff.Mode f11290k = PorterDuff.Mode.SRC_IN;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f11291a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public Object f11292b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public byte[] f11293c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Parcelable f11294d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f11295e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f11296f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public ColorStateList f11297g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public PorterDuff.Mode f11298h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public String f11299i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public String f11300j;

    public IconCompat() {
        this.f11291a = -1;
        this.f11293c = null;
        this.f11294d = null;
        this.f11295e = 0;
        this.f11296f = 0;
        this.f11297g = null;
        this.f11298h = f11290k;
        this.f11299i = null;
    }

    public static IconCompat a(Bundle bundle) {
        int i6 = bundle.getInt("type");
        IconCompat iconCompat = new IconCompat(i6);
        iconCompat.f11295e = bundle.getInt("int1");
        iconCompat.f11296f = bundle.getInt("int2");
        iconCompat.f11300j = bundle.getString("string1");
        if (bundle.containsKey("tint_list")) {
            iconCompat.f11297g = (ColorStateList) bundle.getParcelable("tint_list");
        }
        if (bundle.containsKey("tint_mode")) {
            iconCompat.f11298h = PorterDuff.Mode.valueOf(bundle.getString("tint_mode"));
        }
        switch (i6) {
            case -1:
            case 1:
            case 5:
                iconCompat.f11292b = bundle.getParcelable("obj");
                return iconCompat;
            case 0:
            default:
                Log.w("IconCompat", "Unknown type " + i6);
                return null;
            case 2:
            case 4:
            case 6:
                iconCompat.f11292b = bundle.getString("obj");
                return iconCompat;
            case 3:
                iconCompat.f11292b = bundle.getByteArray("obj");
                return iconCompat;
        }
    }

    public static IconCompat b(Icon icon) {
        icon.getClass();
        int iS = a.S(icon);
        if (iS == 2) {
            return d(null, a.Q(icon), a.P(icon));
        }
        if (iS == 4) {
            Uri uriT = a.T(icon);
            uriT.getClass();
            String string = uriT.toString();
            string.getClass();
            IconCompat iconCompat = new IconCompat(4);
            iconCompat.f11292b = string;
            return iconCompat;
        }
        if (iS != 6) {
            IconCompat iconCompat2 = new IconCompat(-1);
            iconCompat2.f11292b = icon;
            return iconCompat2;
        }
        Uri uriT2 = a.T(icon);
        uriT2.getClass();
        String string2 = uriT2.toString();
        string2.getClass();
        IconCompat iconCompat3 = new IconCompat(6);
        iconCompat3.f11292b = string2;
        return iconCompat3;
    }

    public static Bitmap c(Bitmap bitmap, boolean z6) {
        int iMin = (int) (Math.min(bitmap.getWidth(), bitmap.getHeight()) * 0.6666667f);
        Bitmap bitmapCreateBitmap = Bitmap.createBitmap(iMin, iMin, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmapCreateBitmap);
        Paint paint = new Paint(3);
        float f6 = iMin;
        float f7 = 0.5f * f6;
        float f8 = 0.9166667f * f7;
        if (z6) {
            float f9 = 0.010416667f * f6;
            paint.setColor(0);
            paint.setShadowLayer(f9, 0.0f, f6 * 0.020833334f, 1023410176);
            canvas.drawCircle(f7, f7, f8, paint);
            paint.setShadowLayer(f9, 0.0f, 0.0f, 503316480);
            canvas.drawCircle(f7, f7, f8, 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() - iMin)) / 2.0f, (-(bitmap.getHeight() - iMin)) / 2.0f);
        bitmapShader.setLocalMatrix(matrix);
        paint.setShader(bitmapShader);
        canvas.drawCircle(f7, f7, f8, paint);
        canvas.setBitmap(null);
        return bitmapCreateBitmap;
    }

    public static IconCompat d(Resources resources, String str, int i6) {
        str.getClass();
        if (i6 == 0) {
            throw new IllegalArgumentException("Drawable resource ID must not be 0");
        }
        IconCompat iconCompat = new IconCompat(2);
        iconCompat.f11295e = i6;
        if (resources != null) {
            try {
                iconCompat.f11292b = resources.getResourceName(i6);
            } catch (Resources.NotFoundException unused) {
                throw new IllegalArgumentException("Icon resource cannot be found");
            }
        } else {
            iconCompat.f11292b = str;
        }
        iconCompat.f11300j = str;
        return iconCompat;
    }

    public final int e() {
        int i6 = this.f11291a;
        if (i6 == -1) {
            return a.P(this.f11292b);
        }
        if (i6 == 2) {
            return this.f11295e;
        }
        throw new IllegalStateException("called getResId() on " + this);
    }

    public final String f() {
        int i6 = this.f11291a;
        if (i6 == -1) {
            return a.Q(this.f11292b);
        }
        if (i6 == 2) {
            String str = this.f11300j;
            return (str == null || TextUtils.isEmpty(str)) ? ((String) this.f11292b).split(Constants.SUBS_ID_BASE_PLAN_ID_SEPARATOR, -1)[0] : this.f11300j;
        }
        throw new IllegalStateException("called getResPackage() on " + this);
    }

    public final Uri g() {
        int i6 = this.f11291a;
        if (i6 == -1) {
            return a.T(this.f11292b);
        }
        if (i6 == 4 || i6 == 6) {
            return Uri.parse((String) this.f11292b);
        }
        throw new IllegalStateException("called getUri() on " + this);
    }

    /* JADX WARN: Removed duplicated region for block: B:25:0x007d  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x0096  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Icon h(Context context) {
        Icon iconCreateWithBitmap;
        InputStream inputStreamOpenInputStream;
        int i6 = Build.VERSION.SDK_INT;
        switch (this.f11291a) {
            case -1:
                return (Icon) this.f11292b;
            case 0:
            default:
                throw new IllegalArgumentException("Unknown type");
            case 1:
                iconCreateWithBitmap = Icon.createWithBitmap((Bitmap) this.f11292b);
                break;
            case 2:
                iconCreateWithBitmap = Icon.createWithResource(f(), this.f11295e);
                break;
            case 3:
                iconCreateWithBitmap = Icon.createWithData((byte[]) this.f11292b, this.f11295e, this.f11296f);
                break;
            case 4:
                iconCreateWithBitmap = Icon.createWithContentUri((String) this.f11292b);
                break;
            case 5:
                iconCreateWithBitmap = i6 < 26 ? Icon.createWithBitmap(c((Bitmap) this.f11292b, false)) : A1.a.a((Bitmap) this.f11292b);
                break;
            case 6:
                if (i6 >= 30) {
                    iconCreateWithBitmap = c.b(g());
                } else {
                    if (context == null) {
                        throw new IllegalArgumentException("Context is required to resolve the file uri of the icon: " + g());
                    }
                    Uri uriG = g();
                    String scheme = uriG.getScheme();
                    if ("content".equals(scheme) || "file".equals(scheme)) {
                        try {
                            inputStreamOpenInputStream = context.getContentResolver().openInputStream(uriG);
                        } catch (Exception e6) {
                            Log.w("IconCompat", "Unable to load image from URI: " + uriG, e6);
                            inputStreamOpenInputStream = null;
                        }
                        if (inputStreamOpenInputStream != null) {
                            throw new IllegalStateException("Cannot load adaptive icon from uri: " + g());
                        }
                        if (i6 < 26) {
                            iconCreateWithBitmap = Icon.createWithBitmap(c(BitmapFactory.decodeStream(inputStreamOpenInputStream), false));
                        } else {
                            iconCreateWithBitmap = A1.a.a(BitmapFactory.decodeStream(inputStreamOpenInputStream));
                        }
                        break;
                    } else {
                        try {
                            inputStreamOpenInputStream = new FileInputStream(new File((String) this.f11292b));
                        } catch (FileNotFoundException e7) {
                            Log.w("IconCompat", "Unable to load image from path: " + uriG, e7);
                            inputStreamOpenInputStream = null;
                        }
                        if (inputStreamOpenInputStream != null) {
                        }
                    }
                }
                break;
        }
        ColorStateList colorStateList = this.f11297g;
        if (colorStateList != null) {
            iconCreateWithBitmap.setTintList(colorStateList);
        }
        PorterDuff.Mode mode = this.f11298h;
        if (mode != f11290k) {
            iconCreateWithBitmap.setTintMode(mode);
        }
        return iconCreateWithBitmap;
    }

    public final String toString() {
        String str;
        if (this.f11291a == -1) {
            return String.valueOf(this.f11292b);
        }
        StringBuilder sb = new StringBuilder("Icon(typ=");
        switch (this.f11291a) {
            case 1:
                str = "BITMAP";
                break;
            case 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.f11291a) {
            case 1:
            case 5:
                sb.append(" size=");
                sb.append(((Bitmap) this.f11292b).getWidth());
                sb.append("x");
                sb.append(((Bitmap) this.f11292b).getHeight());
                break;
            case 2:
                sb.append(" pkg=");
                sb.append(this.f11300j);
                sb.append(" id=");
                sb.append(String.format("0x%08x", Integer.valueOf(e())));
                break;
            case 3:
                sb.append(" len=");
                sb.append(this.f11295e);
                if (this.f11296f != 0) {
                    sb.append(" off=");
                    sb.append(this.f11296f);
                }
                break;
            case 4:
            case 6:
                sb.append(" uri=");
                sb.append(this.f11292b);
                break;
        }
        if (this.f11297g != null) {
            sb.append(" tint=");
            sb.append(this.f11297g);
        }
        if (this.f11298h != f11290k) {
            sb.append(" mode=");
            sb.append(this.f11298h);
        }
        sb.append(")");
        return sb.toString();
    }

    public IconCompat(int i6) {
        this.f11293c = null;
        this.f11294d = null;
        this.f11295e = 0;
        this.f11296f = 0;
        this.f11297g = null;
        this.f11298h = f11290k;
        this.f11299i = null;
        this.f11291a = i6;
    }
}
