package androidx.appcompat.widget;

import android.R;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import androidx.appcompat.widget.m0;

/* loaded from: classes.dex */
public final class j {

    /* renamed from: b, reason: collision with root package name */
    private static final PorterDuff.Mode f1087b = PorterDuff.Mode.SRC_IN;

    /* renamed from: c, reason: collision with root package name */
    private static j f1088c;

    /* renamed from: a, reason: collision with root package name */
    private m0 f1089a;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class a implements m0.c {

        /* renamed from: a, reason: collision with root package name */
        private final int[] f1090a = {h.e.R, h.e.P, h.e.f20191a};

        /* renamed from: b, reason: collision with root package name */
        private final int[] f1091b = {h.e.f20205o, h.e.B, h.e.f20210t, h.e.f20206p, h.e.f20207q, h.e.f20209s, h.e.f20208r};

        /* renamed from: c, reason: collision with root package name */
        private final int[] f1092c = {h.e.O, h.e.Q, h.e.f20201k, h.e.K, h.e.L, h.e.M, h.e.N};

        /* renamed from: d, reason: collision with root package name */
        private final int[] f1093d = {h.e.f20213w, h.e.f20199i, h.e.f20212v};

        /* renamed from: e, reason: collision with root package name */
        private final int[] f1094e = {h.e.J, h.e.S};

        /* renamed from: f, reason: collision with root package name */
        private final int[] f1095f = {h.e.f20193c, h.e.f20197g, h.e.f20194d, h.e.f20198h};

        a() {
        }

        private boolean f(int[] iArr, int i10) {
            for (int i11 : iArr) {
                if (i11 == i10) {
                    return true;
                }
            }
            return false;
        }

        private ColorStateList g(Context context) {
            return h(context, 0);
        }

        private ColorStateList h(Context context, int i10) {
            int c10 = r0.c(context, h.a.f20166t);
            return new ColorStateList(new int[][]{r0.f1162b, r0.f1165e, r0.f1163c, r0.f1169i}, new int[]{r0.b(context, h.a.f20164r), androidx.core.graphics.a.f(c10, i10), androidx.core.graphics.a.f(c10, i10), i10});
        }

        private ColorStateList i(Context context) {
            return h(context, r0.c(context, h.a.f20163q));
        }

        private ColorStateList j(Context context) {
            return h(context, r0.c(context, h.a.f20164r));
        }

        private ColorStateList k(Context context) {
            int[][] iArr = new int[3];
            int[] iArr2 = new int[3];
            int i10 = h.a.f20169w;
            ColorStateList e10 = r0.e(context, i10);
            if (e10 == null || !e10.isStateful()) {
                iArr[0] = r0.f1162b;
                iArr2[0] = r0.b(context, i10);
                iArr[1] = r0.f1166f;
                iArr2[1] = r0.c(context, h.a.f20165s);
                iArr[2] = r0.f1169i;
                iArr2[2] = r0.c(context, i10);
            } else {
                int[] iArr3 = r0.f1162b;
                iArr[0] = iArr3;
                iArr2[0] = e10.getColorForState(iArr3, 0);
                iArr[1] = r0.f1166f;
                iArr2[1] = r0.c(context, h.a.f20165s);
                iArr[2] = r0.f1169i;
                iArr2[2] = e10.getDefaultColor();
            }
            return new ColorStateList(iArr, iArr2);
        }

        private LayerDrawable l(m0 m0Var, Context context, int i10) {
            BitmapDrawable bitmapDrawable;
            BitmapDrawable bitmapDrawable2;
            BitmapDrawable bitmapDrawable3;
            int dimensionPixelSize = context.getResources().getDimensionPixelSize(i10);
            Drawable i11 = m0Var.i(context, h.e.F);
            Drawable i12 = m0Var.i(context, h.e.G);
            if ((i11 instanceof BitmapDrawable) && i11.getIntrinsicWidth() == dimensionPixelSize && i11.getIntrinsicHeight() == dimensionPixelSize) {
                bitmapDrawable = (BitmapDrawable) i11;
                bitmapDrawable2 = new BitmapDrawable(bitmapDrawable.getBitmap());
            } else {
                Bitmap createBitmap = Bitmap.createBitmap(dimensionPixelSize, dimensionPixelSize, Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(createBitmap);
                i11.setBounds(0, 0, dimensionPixelSize, dimensionPixelSize);
                i11.draw(canvas);
                bitmapDrawable = new BitmapDrawable(createBitmap);
                bitmapDrawable2 = new BitmapDrawable(createBitmap);
            }
            bitmapDrawable2.setTileModeX(Shader.TileMode.REPEAT);
            if ((i12 instanceof BitmapDrawable) && i12.getIntrinsicWidth() == dimensionPixelSize && i12.getIntrinsicHeight() == dimensionPixelSize) {
                bitmapDrawable3 = (BitmapDrawable) i12;
            } else {
                Bitmap createBitmap2 = Bitmap.createBitmap(dimensionPixelSize, dimensionPixelSize, Bitmap.Config.ARGB_8888);
                Canvas canvas2 = new Canvas(createBitmap2);
                i12.setBounds(0, 0, dimensionPixelSize, dimensionPixelSize);
                i12.draw(canvas2);
                bitmapDrawable3 = new BitmapDrawable(createBitmap2);
            }
            LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{bitmapDrawable, bitmapDrawable3, bitmapDrawable2});
            layerDrawable.setId(0, R.id.background);
            layerDrawable.setId(1, R.id.secondaryProgress);
            layerDrawable.setId(2, R.id.progress);
            return layerDrawable;
        }

        private void m(Drawable drawable, int i10, PorterDuff.Mode mode) {
            if (f0.a(drawable)) {
                drawable = drawable.mutate();
            }
            if (mode == null) {
                mode = j.f1087b;
            }
            drawable.setColorFilter(j.e(i10, mode));
        }

        /* JADX WARN: Removed duplicated region for block: B:15:0x0066 A[RETURN] */
        /* JADX WARN: Removed duplicated region for block: B:7:0x004b  */
        @Override // androidx.appcompat.widget.m0.c
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public boolean a(Context context, int i10, Drawable drawable) {
            int i11;
            boolean z10;
            int round;
            PorterDuff.Mode mode = j.f1087b;
            if (f(this.f1090a, i10)) {
                i11 = h.a.f20167u;
            } else if (f(this.f1092c, i10)) {
                i11 = h.a.f20165s;
            } else {
                if (f(this.f1093d, i10)) {
                    mode = PorterDuff.Mode.MULTIPLY;
                } else {
                    if (i10 == h.e.f20211u) {
                        z10 = true;
                        round = Math.round(40.8f);
                        i11 = 16842800;
                        if (!z10) {
                            return false;
                        }
                        if (f0.a(drawable)) {
                            drawable = drawable.mutate();
                        }
                        drawable.setColorFilter(j.e(r0.c(context, i11), mode));
                        if (round != -1) {
                            drawable.setAlpha(round);
                        }
                        return true;
                    }
                    if (i10 != h.e.f20202l) {
                        i11 = 0;
                        z10 = false;
                        round = -1;
                        if (!z10) {
                        }
                    }
                }
                i11 = 16842801;
            }
            z10 = true;
            round = -1;
            if (!z10) {
            }
        }

        @Override // androidx.appcompat.widget.m0.c
        public PorterDuff.Mode b(int i10) {
            if (i10 == h.e.H) {
                return PorterDuff.Mode.MULTIPLY;
            }
            return null;
        }

        @Override // androidx.appcompat.widget.m0.c
        public Drawable c(m0 m0Var, Context context, int i10) {
            if (i10 == h.e.f20200j) {
                return new LayerDrawable(new Drawable[]{m0Var.i(context, h.e.f20199i), m0Var.i(context, h.e.f20201k)});
            }
            if (i10 == h.e.f20215y) {
                return l(m0Var, context, h.d.f20188g);
            }
            if (i10 == h.e.f20214x) {
                return l(m0Var, context, h.d.f20189h);
            }
            if (i10 == h.e.f20216z) {
                return l(m0Var, context, h.d.f20190i);
            }
            return null;
        }

        @Override // androidx.appcompat.widget.m0.c
        public ColorStateList d(Context context, int i10) {
            if (i10 == h.e.f20203m) {
                return j.a.a(context, h.c.f20178e);
            }
            if (i10 == h.e.I) {
                return j.a.a(context, h.c.f20181h);
            }
            if (i10 == h.e.H) {
                return k(context);
            }
            if (i10 == h.e.f20196f) {
                return j(context);
            }
            if (i10 == h.e.f20192b) {
                return g(context);
            }
            if (i10 == h.e.f20195e) {
                return i(context);
            }
            if (i10 == h.e.D || i10 == h.e.E) {
                return j.a.a(context, h.c.f20180g);
            }
            if (f(this.f1091b, i10)) {
                return r0.e(context, h.a.f20167u);
            }
            if (f(this.f1094e, i10)) {
                return j.a.a(context, h.c.f20177d);
            }
            if (f(this.f1095f, i10)) {
                return j.a.a(context, h.c.f20176c);
            }
            if (i10 == h.e.A) {
                return j.a.a(context, h.c.f20179f);
            }
            return null;
        }

        @Override // androidx.appcompat.widget.m0.c
        public boolean e(Context context, int i10, Drawable drawable) {
            if (i10 == h.e.C) {
                LayerDrawable layerDrawable = (LayerDrawable) drawable;
                Drawable findDrawableByLayerId = layerDrawable.findDrawableByLayerId(R.id.background);
                int i11 = h.a.f20167u;
                m(findDrawableByLayerId, r0.c(context, i11), j.f1087b);
                m(layerDrawable.findDrawableByLayerId(R.id.secondaryProgress), r0.c(context, i11), j.f1087b);
                m(layerDrawable.findDrawableByLayerId(R.id.progress), r0.c(context, h.a.f20165s), j.f1087b);
                return true;
            }
            if (i10 != h.e.f20215y && i10 != h.e.f20214x && i10 != h.e.f20216z) {
                return false;
            }
            LayerDrawable layerDrawable2 = (LayerDrawable) drawable;
            m(layerDrawable2.findDrawableByLayerId(R.id.background), r0.b(context, h.a.f20167u), j.f1087b);
            Drawable findDrawableByLayerId2 = layerDrawable2.findDrawableByLayerId(R.id.secondaryProgress);
            int i12 = h.a.f20165s;
            m(findDrawableByLayerId2, r0.c(context, i12), j.f1087b);
            m(layerDrawable2.findDrawableByLayerId(R.id.progress), r0.c(context, i12), j.f1087b);
            return true;
        }
    }

    public static synchronized j b() {
        j jVar;
        synchronized (j.class) {
            if (f1088c == null) {
                h();
            }
            jVar = f1088c;
        }
        return jVar;
    }

    public static synchronized PorterDuffColorFilter e(int i10, PorterDuff.Mode mode) {
        PorterDuffColorFilter k10;
        synchronized (j.class) {
            k10 = m0.k(i10, mode);
        }
        return k10;
    }

    public static synchronized void h() {
        synchronized (j.class) {
            if (f1088c == null) {
                j jVar = new j();
                f1088c = jVar;
                jVar.f1089a = m0.g();
                f1088c.f1089a.t(new a());
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static void i(Drawable drawable, t0 t0Var, int[] iArr) {
        m0.v(drawable, t0Var, iArr);
    }

    public synchronized Drawable c(Context context, int i10) {
        return this.f1089a.i(context, i10);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public synchronized Drawable d(Context context, int i10, boolean z10) {
        return this.f1089a.j(context, i10, z10);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public synchronized ColorStateList f(Context context, int i10) {
        return this.f1089a.l(context, i10);
    }

    public synchronized void g(Context context) {
        this.f1089a.r(context);
    }
}
