package t3;

import M.J;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.SystemClock;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.ProgressBar;
import com.martsnew.tv.R;
import h3.AbstractC1031a;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import n4.u0;

/* JADX INFO: renamed from: t3.d, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC1541d extends ProgressBar {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final C1540c f16963A;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final C1551n f16964q;

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

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final boolean f16966s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final int f16967t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public C1538a f16968u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public boolean f16969v;

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

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final RunnableC1539b f16971x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final RunnableC1539b f16972y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final C1540c f16973z;

    public AbstractC1541d(Context context, AttributeSet attributeSet) {
        super(A3.a.a(context, attributeSet, R.attr.linearProgressIndicatorStyle, R.style.Widget_MaterialComponents_ProgressIndicator), attributeSet, R.attr.linearProgressIndicatorStyle);
        this.f16969v = false;
        this.f16970w = 4;
        this.f16971x = new RunnableC1539b(this, 0);
        this.f16972y = new RunnableC1539b(this, 1);
        this.f16973z = new C1540c(this, 0);
        this.f16963A = new C1540c(this, 1);
        Context context2 = getContext();
        C1551n c1551n = new C1551n();
        c1551n.f17017c = new int[0];
        int dimensionPixelSize = context2.getResources().getDimensionPixelSize(R.dimen.mtrl_progress_track_thickness);
        int[] iArr = AbstractC1031a.f13395a;
        s3.k.a(context2, attributeSet, R.attr.linearProgressIndicatorStyle, R.style.Widget_MaterialComponents_LinearProgressIndicator);
        s3.k.b(context2, attributeSet, iArr, R.attr.linearProgressIndicatorStyle, R.style.Widget_MaterialComponents_LinearProgressIndicator, new int[0]);
        TypedArray typedArrayObtainStyledAttributes = context2.obtainStyledAttributes(attributeSet, iArr, R.attr.linearProgressIndicatorStyle, R.style.Widget_MaterialComponents_LinearProgressIndicator);
        c1551n.f17015a = s7.d.s(context2, typedArrayObtainStyledAttributes, 8, dimensionPixelSize);
        c1551n.f17016b = Math.min(s7.d.s(context2, typedArrayObtainStyledAttributes, 7, 0), c1551n.f17015a / 2);
        c1551n.f17019e = typedArrayObtainStyledAttributes.getInt(4, 0);
        c1551n.f17020f = typedArrayObtainStyledAttributes.getInt(1, 0);
        if (!typedArrayObtainStyledAttributes.hasValue(2)) {
            TypedValue typedValueW = u0.w(context2, R.attr.colorPrimary);
            c1551n.f17017c = new int[]{typedValueW != null ? typedValueW.data : -1};
        } else if (typedArrayObtainStyledAttributes.peekValue(2).type != 1) {
            c1551n.f17017c = new int[]{typedArrayObtainStyledAttributes.getColor(2, -1)};
        } else {
            int[] intArray = context2.getResources().getIntArray(typedArrayObtainStyledAttributes.getResourceId(2, -1));
            c1551n.f17017c = intArray;
            if (intArray.length == 0) {
                throw new IllegalArgumentException("indicatorColors cannot be empty when indicatorColor is not used.");
            }
        }
        if (typedArrayObtainStyledAttributes.hasValue(6)) {
            c1551n.f17018d = typedArrayObtainStyledAttributes.getColor(6, -1);
        } else {
            c1551n.f17018d = c1551n.f17017c[0];
            TypedArray typedArrayObtainStyledAttributes2 = context2.getTheme().obtainStyledAttributes(new int[]{android.R.attr.disabledAlpha});
            float f3 = typedArrayObtainStyledAttributes2.getFloat(0, 0.2f);
            typedArrayObtainStyledAttributes2.recycle();
            c1551n.f17018d = W2.g.h(c1551n.f17018d, (int) (f3 * 255.0f));
        }
        typedArrayObtainStyledAttributes.recycle();
        int[] iArr2 = AbstractC1031a.f13404k;
        s3.k.a(context2, attributeSet, R.attr.linearProgressIndicatorStyle, R.style.Widget_MaterialComponents_LinearProgressIndicator);
        s3.k.b(context2, attributeSet, iArr2, R.attr.linearProgressIndicatorStyle, R.style.Widget_MaterialComponents_LinearProgressIndicator, new int[0]);
        TypedArray typedArrayObtainStyledAttributes3 = context2.obtainStyledAttributes(attributeSet, iArr2, R.attr.linearProgressIndicatorStyle, R.style.Widget_MaterialComponents_LinearProgressIndicator);
        c1551n.f17021g = typedArrayObtainStyledAttributes3.getInt(0, 1);
        c1551n.f17022h = typedArrayObtainStyledAttributes3.getInt(1, 0);
        typedArrayObtainStyledAttributes3.recycle();
        c1551n.a();
        c1551n.i = c1551n.f17022h == 1;
        this.f16964q = c1551n;
        s3.k.a(context2, attributeSet, R.attr.linearProgressIndicatorStyle, R.style.Widget_MaterialComponents_LinearProgressIndicator);
        s3.k.b(context2, attributeSet, iArr, R.attr.linearProgressIndicatorStyle, R.style.Widget_MaterialComponents_LinearProgressIndicator, new int[0]);
        TypedArray typedArrayObtainStyledAttributes4 = context2.obtainStyledAttributes(attributeSet, iArr, R.attr.linearProgressIndicatorStyle, R.style.Widget_MaterialComponents_LinearProgressIndicator);
        typedArrayObtainStyledAttributes4.getInt(5, -1);
        this.f16967t = Math.min(typedArrayObtainStyledAttributes4.getInt(3, -1), 1000);
        typedArrayObtainStyledAttributes4.recycle();
        this.f16968u = new C1538a();
        this.f16966s = true;
    }

    private AbstractC1546i getCurrentDrawingDelegate() {
        if (isIndeterminate()) {
            if (getIndeterminateDrawable() == null) {
                return null;
            }
            return getIndeterminateDrawable().f16994B;
        }
        if (getProgressDrawable() == null) {
            return null;
        }
        return getProgressDrawable().f16975B;
    }

    public void a(int i) {
        if (!isIndeterminate()) {
            super.setProgress(i);
            if (getProgressDrawable() != null) {
                getProgressDrawable().jumpToCurrentState();
                return;
            }
            return;
        }
        if (getProgressDrawable() != null) {
            this.f16965r = i;
            this.f16969v = true;
            if (getIndeterminateDrawable().isVisible()) {
                C1538a c1538a = this.f16968u;
                ContentResolver contentResolver = getContext().getContentResolver();
                c1538a.getClass();
                if (Settings.Global.getFloat(contentResolver, "animator_duration_scale", 1.0f) != 0.0f) {
                    getIndeterminateDrawable().f16995C.j();
                    return;
                }
            }
            getIndeterminateDrawable();
            this.f16973z.a();
        }
    }

    public final boolean b() {
        Field field = J.f4065a;
        if (!isAttachedToWindow() || getWindowVisibility() != 0) {
            return false;
        }
        View view = this;
        while (view.getVisibility() == 0) {
            Object parent = view.getParent();
            if (parent == null) {
                return getWindowVisibility() == 0;
            }
            if (!(parent instanceof View)) {
                return true;
            }
            view = (View) parent;
        }
        return false;
    }

    @Override // android.widget.ProgressBar
    public Drawable getCurrentDrawable() {
        return isIndeterminate() ? getIndeterminateDrawable() : getProgressDrawable();
    }

    public int getHideAnimationBehavior() {
        return this.f16964q.f17020f;
    }

    public int[] getIndicatorColor() {
        return this.f16964q.f17017c;
    }

    public int getShowAnimationBehavior() {
        return this.f16964q.f17019e;
    }

    public int getTrackColor() {
        return this.f16964q.f17018d;
    }

    public int getTrackCornerRadius() {
        return this.f16964q.f17016b;
    }

    public int getTrackThickness() {
        return this.f16964q.f17015a;
    }

    @Override // android.view.View
    public final void invalidate() {
        super.invalidate();
        if (getCurrentDrawable() != null) {
            getCurrentDrawable().invalidateSelf();
        }
    }

    @Override // android.widget.ProgressBar, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (getProgressDrawable() != null && getIndeterminateDrawable() != null) {
            getIndeterminateDrawable().f16995C.i(this.f16973z);
        }
        C1543f progressDrawable = getProgressDrawable();
        C1540c c1540c = this.f16963A;
        if (progressDrawable != null) {
            C1543f progressDrawable2 = getProgressDrawable();
            if (progressDrawable2.f16987v == null) {
                progressDrawable2.f16987v = new ArrayList();
            }
            if (!progressDrawable2.f16987v.contains(c1540c)) {
                progressDrawable2.f16987v.add(c1540c);
            }
        }
        if (getIndeterminateDrawable() != null) {
            C1547j indeterminateDrawable = getIndeterminateDrawable();
            if (indeterminateDrawable.f16987v == null) {
                indeterminateDrawable.f16987v = new ArrayList();
            }
            if (!indeterminateDrawable.f16987v.contains(c1540c)) {
                indeterminateDrawable.f16987v.add(c1540c);
            }
        }
        if (b()) {
            if (this.f16967t > 0) {
                SystemClock.uptimeMillis();
            }
            setVisibility(0);
        }
    }

    @Override // android.widget.ProgressBar, android.view.View
    public final void onDetachedFromWindow() {
        removeCallbacks(this.f16972y);
        removeCallbacks(this.f16971x);
        ((AbstractC1545h) getCurrentDrawable()).c(false, false, false);
        C1547j indeterminateDrawable = getIndeterminateDrawable();
        C1540c c1540c = this.f16963A;
        if (indeterminateDrawable != null) {
            getIndeterminateDrawable().e(c1540c);
            getIndeterminateDrawable().f16995C.l();
        }
        if (getProgressDrawable() != null) {
            getProgressDrawable().e(c1540c);
        }
        super.onDetachedFromWindow();
    }

    @Override // android.widget.ProgressBar, android.view.View
    public final synchronized void onDraw(Canvas canvas) {
        try {
            int iSave = canvas.save();
            if (getPaddingLeft() != 0 || getPaddingTop() != 0) {
                canvas.translate(getPaddingLeft(), getPaddingTop());
            }
            if (getPaddingRight() != 0 || getPaddingBottom() != 0) {
                canvas.clipRect(0, 0, getWidth() - (getPaddingLeft() + getPaddingRight()), getHeight() - (getPaddingTop() + getPaddingBottom()));
            }
            getCurrentDrawable().draw(canvas);
            canvas.restoreToCount(iSave);
        } catch (Throwable th) {
            throw th;
        }
    }

    @Override // android.widget.ProgressBar, android.view.View
    public final synchronized void onMeasure(int i, int i5) {
        try {
            super.onMeasure(i, i5);
            AbstractC1546i currentDrawingDelegate = getCurrentDrawingDelegate();
            if (currentDrawingDelegate == null) {
                return;
            }
            int i8 = ((C1548k) currentDrawingDelegate).f16992a.f17015a;
            setMeasuredDimension(getMeasuredWidth(), i8 < 0 ? getMeasuredHeight() : i8 + getPaddingTop() + getPaddingBottom());
        } catch (Throwable th) {
            throw th;
        }
    }

    @Override // android.view.View
    public final void onVisibilityChanged(View view, int i) {
        super.onVisibilityChanged(view, i);
        boolean z8 = i == 0;
        if (this.f16966s) {
            ((AbstractC1545h) getCurrentDrawable()).c(b(), false, z8);
        }
    }

    @Override // android.view.View
    public final void onWindowVisibilityChanged(int i) {
        super.onWindowVisibilityChanged(i);
        if (this.f16966s) {
            ((AbstractC1545h) getCurrentDrawable()).c(b(), false, false);
        }
    }

    public void setAnimatorDurationScaleProvider(C1538a c1538a) {
        this.f16968u = c1538a;
        if (getProgressDrawable() != null) {
            getProgressDrawable().f16984s = c1538a;
        }
        if (getIndeterminateDrawable() != null) {
            getIndeterminateDrawable().f16984s = c1538a;
        }
    }

    public void setHideAnimationBehavior(int i) {
        this.f16964q.f17020f = i;
        invalidate();
    }

    @Override // android.widget.ProgressBar
    public synchronized void setIndeterminate(boolean z8) {
        try {
            if (z8 == isIndeterminate()) {
                return;
            }
            if (b() && z8) {
                throw new IllegalStateException("Cannot switch to indeterminate mode while the progress indicator is visible.");
            }
            AbstractC1545h abstractC1545h = (AbstractC1545h) getCurrentDrawable();
            if (abstractC1545h != null) {
                abstractC1545h.c(false, false, false);
            }
            super.setIndeterminate(z8);
            AbstractC1545h abstractC1545h2 = (AbstractC1545h) getCurrentDrawable();
            if (abstractC1545h2 != null) {
                abstractC1545h2.c(b(), false, false);
            }
            this.f16969v = false;
        } catch (Throwable th) {
            throw th;
        }
    }

    @Override // android.widget.ProgressBar
    public void setIndeterminateDrawable(Drawable drawable) {
        if (drawable == null) {
            super.setIndeterminateDrawable(null);
        } else {
            if (!(drawable instanceof C1547j)) {
                throw new IllegalArgumentException("Cannot set framework drawable as indeterminate drawable.");
            }
            ((AbstractC1545h) drawable).c(false, false, false);
            super.setIndeterminateDrawable(drawable);
        }
    }

    public void setIndicatorColor(int... iArr) {
        if (iArr.length == 0) {
            TypedValue typedValueW = u0.w(getContext(), R.attr.colorPrimary);
            iArr = new int[]{typedValueW != null ? typedValueW.data : -1};
        }
        if (Arrays.equals(getIndicatorColor(), iArr)) {
            return;
        }
        this.f16964q.f17017c = iArr;
        getIndeterminateDrawable().f16995C.e();
        invalidate();
    }

    @Override // android.widget.ProgressBar
    public synchronized void setProgress(int i) {
        if (isIndeterminate()) {
            return;
        }
        a(i);
    }

    @Override // android.widget.ProgressBar
    public void setProgressDrawable(Drawable drawable) {
        if (drawable == null) {
            super.setProgressDrawable(null);
        } else {
            if (!(drawable instanceof C1543f)) {
                throw new IllegalArgumentException("Cannot set framework drawable as progress drawable.");
            }
            C1543f c1543f = (C1543f) drawable;
            c1543f.c(false, false, false);
            super.setProgressDrawable(c1543f);
            c1543f.setLevel((int) ((getProgress() / getMax()) * 10000.0f));
        }
    }

    public void setShowAnimationBehavior(int i) {
        this.f16964q.f17019e = i;
        invalidate();
    }

    public void setTrackColor(int i) {
        C1551n c1551n = this.f16964q;
        if (c1551n.f17018d != i) {
            c1551n.f17018d = i;
            invalidate();
        }
    }

    public void setTrackCornerRadius(int i) {
        C1551n c1551n = this.f16964q;
        if (c1551n.f17016b != i) {
            c1551n.f17016b = Math.min(i, c1551n.f17015a / 2);
        }
    }

    public void setTrackThickness(int i) {
        C1551n c1551n = this.f16964q;
        if (c1551n.f17015a != i) {
            c1551n.f17015a = i;
            requestLayout();
        }
    }

    public void setVisibilityAfterHide(int i) {
        if (i != 0 && i != 4 && i != 8) {
            throw new IllegalArgumentException("The component's visibility must be one of VISIBLE, INVISIBLE, and GONE defined in View.");
        }
        this.f16970w = i;
    }

    @Override // android.widget.ProgressBar
    public C1547j getIndeterminateDrawable() {
        return (C1547j) super.getIndeterminateDrawable();
    }

    @Override // android.widget.ProgressBar
    public C1543f getProgressDrawable() {
        return (C1543f) super.getProgressDrawable();
    }
}
