package androidx.core.graphics.drawable;

import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Bitmap;
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.util.Log;
import androidx.versionedparcelable.CustomVersionedParcelable;
import java.lang.reflect.InvocationTargetException;
import p138.p139.p143.p144.C2803;

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

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public static final PorterDuff.Mode f591 = PorterDuff.Mode.SRC_IN;

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public int f592;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public Object f593;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public byte[] f594;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public Parcelable f595;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public int f596;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public int f597;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public ColorStateList f598;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public PorterDuff.Mode f599;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public String f600;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public String f601;

    public IconCompat() {
        this.f592 = -1;
        this.f594 = null;
        this.f595 = null;
        this.f596 = 0;
        this.f597 = 0;
        this.f598 = null;
        this.f599 = f591;
        this.f600 = null;
    }

    public IconCompat(int i) {
        this.f592 = -1;
        this.f594 = null;
        this.f595 = null;
        this.f596 = 0;
        this.f597 = 0;
        this.f598 = null;
        this.f599 = f591;
        this.f600 = null;
        this.f592 = i;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static Bitmap m227(Bitmap bitmap, boolean z) {
        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 f = iMin;
        float f2 = 0.5f * f;
        float f3 = 0.9166667f * f2;
        if (z) {
            float f4 = 0.010416667f * f;
            paint.setColor(0);
            paint.setShadowLayer(f4, 0.0f, f * 0.020833334f, 1023410176);
            canvas.drawCircle(f2, f2, f3, paint);
            paint.setShadowLayer(f4, 0.0f, 0.0f, 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() - iMin)) / 2, (-(bitmap.getHeight() - iMin)) / 2);
        bitmapShader.setLocalMatrix(matrix);
        paint.setShader(bitmapShader);
        canvas.drawCircle(f2, f2, f3, paint);
        canvas.setBitmap(null);
        return bitmapCreateBitmap;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static IconCompat m228(Resources resources, String str, int i) {
        if (str == null) {
            throw new IllegalArgumentException("Package must not be null.");
        }
        if (i == 0) {
            throw new IllegalArgumentException("Drawable resource ID must not be 0");
        }
        IconCompat iconCompat = new IconCompat(2);
        iconCompat.f596 = i;
        if (resources != null) {
            try {
                iconCompat.f593 = resources.getResourceName(i);
            } catch (Resources.NotFoundException unused) {
                throw new IllegalArgumentException("Icon resource cannot be found");
            }
        } else {
            iconCompat.f593 = "";
        }
        iconCompat.f601 = str;
        return iconCompat;
    }

    public String toString() {
        String str;
        if (this.f592 == -1) {
            return String.valueOf(this.f593);
        }
        StringBuilder sb = new StringBuilder("Icon(typ=");
        switch (this.f592) {
            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.f592) {
            case 1:
            case 5:
                sb.append(" size=");
                sb.append(((Bitmap) this.f593).getWidth());
                sb.append("x");
                sb.append(((Bitmap) this.f593).getHeight());
                break;
            case 2:
                sb.append(" pkg=");
                sb.append(this.f601);
                sb.append(" id=");
                sb.append(String.format("0x%08x", Integer.valueOf(m229())));
                break;
            case 3:
                sb.append(" len=");
                sb.append(this.f596);
                if (this.f597 != 0) {
                    sb.append(" off=");
                    sb.append(this.f597);
                }
                break;
            case 4:
            case 6:
                sb.append(" uri=");
                sb.append(this.f593);
                break;
        }
        if (this.f598 != null) {
            sb.append(" tint=");
            sb.append(this.f598);
        }
        if (this.f599 != f591) {
            sb.append(" mode=");
            sb.append(this.f599);
        }
        sb.append(")");
        return sb.toString();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public int m229() {
        int i;
        if (this.f592 != -1 || (i = Build.VERSION.SDK_INT) < 23) {
            if (this.f592 == 2) {
                return this.f596;
            }
            throw new IllegalStateException("called getResId() on " + this);
        }
        Icon icon = (Icon) this.f593;
        if (i >= 28) {
            return icon.getResId();
        }
        try {
            return ((Integer) icon.getClass().getMethod("getResId", new Class[0]).invoke(icon, new Object[0])).intValue();
        } catch (IllegalAccessException e) {
            Log.e("IconCompat", "Unable to get icon resource", e);
            return 0;
        } catch (NoSuchMethodException e2) {
            Log.e("IconCompat", "Unable to get icon resource", e2);
            return 0;
        } catch (InvocationTargetException e3) {
            Log.e("IconCompat", "Unable to get icon resource", e3);
            return 0;
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public Uri m230() {
        int i;
        if (this.f592 != -1 || (i = Build.VERSION.SDK_INT) < 23) {
            int i2 = this.f592;
            if (i2 == 4 || i2 == 6) {
                return Uri.parse((String) this.f593);
            }
            throw new IllegalStateException("called getUri() on " + this);
        }
        Icon icon = (Icon) this.f593;
        if (i >= 28) {
            return icon.getUri();
        }
        try {
            return (Uri) icon.getClass().getMethod("getUri", new Class[0]).invoke(icon, new Object[0]);
        } catch (IllegalAccessException e) {
            Log.e("IconCompat", "Unable to get icon uri", e);
            return null;
        } catch (NoSuchMethodException e2) {
            Log.e("IconCompat", "Unable to get icon uri", e2);
            return null;
        } catch (InvocationTargetException e3) {
            Log.e("IconCompat", "Unable to get icon uri", e3);
            return null;
        }
    }

    @Deprecated
    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public Icon m231() {
        Icon iconCreateWithBitmap;
        int i;
        int i2 = this.f592;
        String resPackage = null;
        switch (i2) {
            case -1:
                return (Icon) this.f593;
            case 0:
            default:
                throw new IllegalArgumentException("Unknown type");
            case 1:
                iconCreateWithBitmap = Icon.createWithBitmap((Bitmap) this.f593);
                break;
            case 2:
                if (i2 == -1 && (i = Build.VERSION.SDK_INT) >= 23) {
                    Icon icon = (Icon) this.f593;
                    if (i >= 28) {
                        resPackage = icon.getResPackage();
                    } else {
                        try {
                            resPackage = (String) icon.getClass().getMethod("getResPackage", new Class[0]).invoke(icon, new Object[0]);
                        } catch (IllegalAccessException e) {
                            Log.e("IconCompat", "Unable to get icon package", e);
                        } catch (NoSuchMethodException e2) {
                            Log.e("IconCompat", "Unable to get icon package", e2);
                        } catch (InvocationTargetException e3) {
                            Log.e("IconCompat", "Unable to get icon package", e3);
                        }
                    }
                } else {
                    if (this.f592 != 2) {
                        throw new IllegalStateException("called getResPackage() on " + this);
                    }
                    resPackage = this.f601;
                }
                iconCreateWithBitmap = Icon.createWithResource(resPackage, this.f596);
                break;
            case 3:
                iconCreateWithBitmap = Icon.createWithData((byte[]) this.f593, this.f596, this.f597);
                break;
            case 4:
                iconCreateWithBitmap = Icon.createWithContentUri((String) this.f593);
                break;
            case 5:
                iconCreateWithBitmap = Build.VERSION.SDK_INT < 26 ? Icon.createWithBitmap(m227((Bitmap) this.f593, false)) : Icon.createWithAdaptiveBitmap((Bitmap) this.f593);
                break;
            case 6:
                StringBuilder sbM4889 = C2803.m4889("Context is required to resolve the file uri of the icon: ");
                sbM4889.append(m230());
                throw new IllegalArgumentException(sbM4889.toString());
        }
        ColorStateList colorStateList = this.f598;
        if (colorStateList != null) {
            iconCreateWithBitmap.setTintList(colorStateList);
        }
        PorterDuff.Mode mode = this.f599;
        if (mode == f591) {
            return iconCreateWithBitmap;
        }
        iconCreateWithBitmap.setTintMode(mode);
        return iconCreateWithBitmap;
    }
}
