package androidx.leanback.widget;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import com.debridstream.tv.R;

/* JADX INFO: loaded from: classes.dex */
public class PagingIndicator extends View {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public static final z f11841A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public static final z f11842B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public static final z f11843C;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public static final DecelerateInterpolator f11844z = new DecelerateInterpolator();

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final int f11852k;
    public A[] l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public int[] f11853m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public int[] f11854n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public int[] f11855o;

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

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

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

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

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

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final Paint f11861u;

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

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

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

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

    static {
        Class<Float> cls = Float.class;
        f11841A = new z("alpha", 0, cls);
        f11842B = new z("diameter", 1, cls);
        f11843C = new z("translation_x", 2, cls);
    }

    public PagingIndicator(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0);
        AnimatorSet animatorSet = new AnimatorSet();
        Resources resources = getResources();
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, Z1.a.f9142b, 0, 0);
        int dimensionPixelOffset = typedArrayObtainStyledAttributes.getDimensionPixelOffset(6, getResources().getDimensionPixelOffset(R.dimen.lb_page_indicator_dot_radius));
        this.f11847c = dimensionPixelOffset;
        int i6 = dimensionPixelOffset * 2;
        this.f11846b = i6;
        int dimensionPixelOffset2 = typedArrayObtainStyledAttributes.getDimensionPixelOffset(2, getResources().getDimensionPixelOffset(R.dimen.lb_page_indicator_arrow_radius));
        this.f11850f = dimensionPixelOffset2;
        int i7 = dimensionPixelOffset2 * 2;
        this.f11849e = i7;
        this.f11848d = typedArrayObtainStyledAttributes.getDimensionPixelOffset(5, getResources().getDimensionPixelOffset(R.dimen.lb_page_indicator_dot_gap));
        this.f11851j = typedArrayObtainStyledAttributes.getDimensionPixelOffset(4, getResources().getDimensionPixelOffset(R.dimen.lb_page_indicator_arrow_gap));
        int color = typedArrayObtainStyledAttributes.getColor(3, getResources().getColor(R.color.lb_page_indicator_dot));
        Paint paint = new Paint(1);
        this.f11860t = paint;
        paint.setColor(color);
        this.f11859s = typedArrayObtainStyledAttributes.getColor(0, getResources().getColor(R.color.lb_page_indicator_arrow_background));
        if (this.f11863w == null && typedArrayObtainStyledAttributes.hasValue(1)) {
            setArrowColor(typedArrayObtainStyledAttributes.getColor(1, 0));
        }
        typedArrayObtainStyledAttributes.recycle();
        this.f11845a = resources.getConfiguration().getLayoutDirection() == 0;
        int color2 = resources.getColor(R.color.lb_page_indicator_arrow_shadow);
        int dimensionPixelSize = resources.getDimensionPixelSize(R.dimen.lb_page_indicator_arrow_shadow_radius);
        this.f11852k = dimensionPixelSize;
        Paint paint2 = new Paint(1);
        this.f11861u = paint2;
        float dimensionPixelSize2 = resources.getDimensionPixelSize(R.dimen.lb_page_indicator_arrow_shadow_offset);
        paint2.setShadowLayer(dimensionPixelSize, dimensionPixelSize2, dimensionPixelSize2, color2);
        this.f11862v = d();
        this.f11864x = new Rect(0, 0, this.f11862v.getWidth(), this.f11862v.getHeight());
        float f6 = i7;
        this.f11865y = this.f11862v.getWidth() / f6;
        AnimatorSet animatorSet2 = new AnimatorSet();
        z zVar = f11841A;
        ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat((Object) null, zVar, 0.0f, 1.0f);
        objectAnimatorOfFloat.setDuration(167L);
        DecelerateInterpolator decelerateInterpolator = f11844z;
        objectAnimatorOfFloat.setInterpolator(decelerateInterpolator);
        float f7 = i6;
        z zVar2 = f11842B;
        ObjectAnimator objectAnimatorOfFloat2 = ObjectAnimator.ofFloat((Object) null, zVar2, f7, f6);
        objectAnimatorOfFloat2.setDuration(417L);
        objectAnimatorOfFloat2.setInterpolator(decelerateInterpolator);
        animatorSet2.playTogether(objectAnimatorOfFloat, objectAnimatorOfFloat2, c());
        AnimatorSet animatorSet3 = new AnimatorSet();
        ObjectAnimator objectAnimatorOfFloat3 = ObjectAnimator.ofFloat((Object) null, zVar, 1.0f, 0.0f);
        objectAnimatorOfFloat3.setDuration(167L);
        objectAnimatorOfFloat3.setInterpolator(decelerateInterpolator);
        ObjectAnimator objectAnimatorOfFloat4 = ObjectAnimator.ofFloat((Object) null, zVar2, f6, f7);
        objectAnimatorOfFloat4.setDuration(417L);
        objectAnimatorOfFloat4.setInterpolator(decelerateInterpolator);
        animatorSet3.playTogether(objectAnimatorOfFloat3, objectAnimatorOfFloat4, c());
        animatorSet.playTogether(animatorSet2, animatorSet3);
        setLayerType(1, null);
    }

    private int getDesiredHeight() {
        return getPaddingBottom() + getPaddingTop() + this.f11849e + this.f11852k;
    }

    private int getDesiredWidth() {
        return getPaddingRight() + getPaddingLeft() + getRequiredWidth();
    }

    private int getRequiredWidth() {
        return ((this.f11857q - 3) * this.f11848d) + (this.f11851j * 2) + (this.f11847c * 2);
    }

    private void setSelectedPage(int i6) {
        if (i6 == this.f11858r) {
            return;
        }
        this.f11858r = i6;
        a();
    }

    public final void a() {
        int i6;
        int i7 = 0;
        while (true) {
            i6 = this.f11858r;
            if (i7 >= i6) {
                break;
            }
            this.l[i7].b();
            A a6 = this.l[i7];
            if (i7 != 0) {
                f = 1.0f;
            }
            a6.f11788h = f;
            a6.f11784d = this.f11854n[i7];
            i7++;
        }
        A a7 = this.l[i6];
        a7.f11783c = 0.0f;
        a7.f11784d = 0.0f;
        PagingIndicator pagingIndicator = a7.f11790j;
        a7.f11785e = pagingIndicator.f11849e;
        float f6 = pagingIndicator.f11850f;
        a7.f11786f = f6;
        a7.f11787g = f6 * pagingIndicator.f11865y;
        a7.f11781a = 1.0f;
        a7.a();
        A[] aArr = this.l;
        int i8 = this.f11858r;
        A a8 = aArr[i8];
        a8.f11788h = i8 <= 0 ? 1.0f : -1.0f;
        a8.f11784d = this.f11853m[i8];
        while (true) {
            i8++;
            if (i8 >= this.f11857q) {
                return;
            }
            this.l[i8].b();
            A a9 = this.l[i8];
            a9.f11788h = 1.0f;
            a9.f11784d = this.f11855o[i8];
        }
    }

    public final void b() {
        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        int width = getWidth() - getPaddingRight();
        int requiredWidth = getRequiredWidth();
        int i6 = (paddingLeft + width) / 2;
        int i7 = this.f11857q;
        int[] iArr = new int[i7];
        this.f11853m = iArr;
        int[] iArr2 = new int[i7];
        this.f11854n = iArr2;
        int[] iArr3 = new int[i7];
        this.f11855o = iArr3;
        boolean z6 = this.f11845a;
        int i8 = this.f11847c;
        int i9 = this.f11851j;
        int i10 = this.f11848d;
        int i11 = 1;
        if (z6) {
            int i12 = i6 - (requiredWidth / 2);
            iArr[0] = ((i12 + i8) - i10) + i9;
            iArr2[0] = i12 + i8;
            iArr3[0] = (i9 * 2) + ((i12 + i8) - (i10 * 2));
            while (i11 < this.f11857q) {
                int[] iArr4 = this.f11853m;
                int[] iArr5 = this.f11854n;
                int i13 = i11 - 1;
                iArr4[i11] = iArr5[i13] + i9;
                iArr5[i11] = iArr5[i13] + i10;
                this.f11855o[i11] = iArr4[i13] + i9;
                i11++;
            }
        } else {
            int i14 = (requiredWidth / 2) + i6;
            iArr[0] = ((i14 - i8) + i10) - i9;
            iArr2[0] = i14 - i8;
            iArr3[0] = ((i10 * 2) + (i14 - i8)) - (i9 * 2);
            while (i11 < this.f11857q) {
                int[] iArr6 = this.f11853m;
                int[] iArr7 = this.f11854n;
                int i15 = i11 - 1;
                iArr6[i11] = iArr7[i15] - i9;
                iArr7[i11] = iArr7[i15] - i10;
                this.f11855o[i11] = iArr6[i15] - i9;
                i11++;
            }
        }
        this.f11856p = paddingTop + this.f11850f;
        a();
    }

    public final ObjectAnimator c() {
        ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat((Object) null, f11843C, (-this.f11851j) + this.f11848d, 0.0f);
        objectAnimatorOfFloat.setDuration(417L);
        objectAnimatorOfFloat.setInterpolator(f11844z);
        return objectAnimatorOfFloat;
    }

    public final Bitmap d() {
        Bitmap bitmapDecodeResource = BitmapFactory.decodeResource(getResources(), R.drawable.lb_ic_nav_arrow);
        if (this.f11845a) {
            return bitmapDecodeResource;
        }
        Matrix matrix = new Matrix();
        matrix.preScale(-1.0f, 1.0f);
        return Bitmap.createBitmap(bitmapDecodeResource, 0, 0, bitmapDecodeResource.getWidth(), bitmapDecodeResource.getHeight(), matrix, false);
    }

    public int[] getDotSelectedLeftX() {
        return this.f11854n;
    }

    public int[] getDotSelectedRightX() {
        return this.f11855o;
    }

    public int[] getDotSelectedX() {
        return this.f11853m;
    }

    public int getPageCount() {
        return this.f11857q;
    }

    @Override // android.view.View
    public final void onDraw(Canvas canvas) {
        for (int i6 = 0; i6 < this.f11857q; i6++) {
            A a6 = this.l[i6];
            float f6 = a6.f11784d + a6.f11783c;
            PagingIndicator pagingIndicator = a6.f11790j;
            canvas.drawCircle(f6, pagingIndicator.f11856p, a6.f11786f, pagingIndicator.f11860t);
            if (a6.f11781a > 0.0f) {
                Paint paint = pagingIndicator.f11861u;
                paint.setColor(a6.f11782b);
                canvas.drawCircle(f6, pagingIndicator.f11856p, a6.f11786f, paint);
                Bitmap bitmap = pagingIndicator.f11862v;
                float f7 = a6.f11787g;
                float f8 = pagingIndicator.f11856p;
                canvas.drawBitmap(bitmap, pagingIndicator.f11864x, new Rect((int) (f6 - f7), (int) (f8 - f7), (int) (f6 + f7), (int) (f8 + f7)), pagingIndicator.f11863w);
            }
        }
    }

    @Override // android.view.View
    public final void onMeasure(int i6, int i7) {
        int desiredHeight = getDesiredHeight();
        int mode = View.MeasureSpec.getMode(i7);
        if (mode == Integer.MIN_VALUE) {
            desiredHeight = Math.min(desiredHeight, View.MeasureSpec.getSize(i7));
        } else if (mode == 1073741824) {
            desiredHeight = View.MeasureSpec.getSize(i7);
        }
        int desiredWidth = getDesiredWidth();
        int mode2 = View.MeasureSpec.getMode(i6);
        if (mode2 == Integer.MIN_VALUE) {
            desiredWidth = Math.min(desiredWidth, View.MeasureSpec.getSize(i6));
        } else if (mode2 == 1073741824) {
            desiredWidth = View.MeasureSpec.getSize(i6);
        }
        setMeasuredDimension(desiredWidth, desiredHeight);
    }

    @Override // android.view.View
    public final void onRtlPropertiesChanged(int i6) {
        super.onRtlPropertiesChanged(i6);
        boolean z6 = i6 == 0;
        if (this.f11845a != z6) {
            this.f11845a = z6;
            this.f11862v = d();
            A[] aArr = this.l;
            if (aArr != null) {
                for (A a6 : aArr) {
                    a6.f11789i = a6.f11790j.f11845a ? 1.0f : -1.0f;
                }
            }
            b();
            invalidate();
        }
    }

    @Override // android.view.View
    public final void onSizeChanged(int i6, int i7, int i8, int i9) {
        setMeasuredDimension(i6, i7);
        b();
    }

    public void setArrowBackgroundColor(int i6) {
        this.f11859s = i6;
    }

    public void setArrowColor(int i6) {
        if (this.f11863w == null) {
            this.f11863w = new Paint();
        }
        this.f11863w.setColorFilter(new PorterDuffColorFilter(i6, PorterDuff.Mode.SRC_IN));
    }

    public void setDotBackgroundColor(int i6) {
        this.f11860t.setColor(i6);
    }

    public void setPageCount(int i6) {
        if (i6 <= 0) {
            throw new IllegalArgumentException("The page count should be a positive integer");
        }
        this.f11857q = i6;
        this.l = new A[i6];
        for (int i7 = 0; i7 < this.f11857q; i7++) {
            this.l[i7] = new A(this);
        }
        b();
        setSelectedPage(0);
    }
}
