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.Color;
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.util.Property;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import com.strmr.ps.R;
import defpackage.bo7;
import defpackage.m38;
import defpackage.sia;
import defpackage.sma;
import defpackage.w51;

/* JADX INFO: loaded from: classes.dex */
@m38
public class PagingIndicator extends View {
    public static final DecelerateInterpolator ac = new DecelerateInterpolator();
    public static final Property ad = new a(Float.class, "alpha");
    public static final Property ae = new b(Float.class, "diameter");
    public static final Property af = new c(Float.class, "translation_x");
    public boolean a;
    public final Rect aa;
    public final float ab;
    public final int b;
    public final int c;
    public final int d;
    public final int e;
    public final int f;
    public final int i;
    public final int j;
    public d[] k;
    public int[] l;
    public int[] m;
    public int[] n;
    public int o;
    public int p;
    public int q;
    public int r;
    public int s;
    public final Paint t;
    public final Paint u;
    public final AnimatorSet v;
    public final AnimatorSet w;
    public final AnimatorSet x;
    public Bitmap y;
    public Paint z;

    public class a extends Property<d, Float> {
        @Override // android.util.Property
        public final Float get(d dVar) {
            return Float.valueOf(dVar.a);
        }

        @Override // android.util.Property
        public final void set(d dVar, Float f) {
            d dVar2 = dVar;
            dVar2.a = f.floatValue();
            dVar2.a();
            PagingIndicator.this.invalidate();
        }
    }

    public class b extends Property<d, Float> {
        @Override // android.util.Property
        public final Float get(d dVar) {
            return Float.valueOf(dVar.e);
        }

        @Override // android.util.Property
        public final void set(d dVar, Float f) {
            d dVar2 = dVar;
            float fFloatValue = f.floatValue();
            dVar2.e = fFloatValue;
            float f2 = fFloatValue / 2.0f;
            dVar2.f = f2;
            PagingIndicator pagingIndicator = PagingIndicator.this;
            dVar2.g = f2 * pagingIndicator.ab;
            pagingIndicator.invalidate();
        }
    }

    public class c extends Property<d, Float> {
        @Override // android.util.Property
        public final Float get(d dVar) {
            return Float.valueOf(dVar.c);
        }

        @Override // android.util.Property
        public final void set(d dVar, Float f) {
            d dVar2 = dVar;
            dVar2.c = f.floatValue() * dVar2.h * dVar2.i;
            PagingIndicator.this.invalidate();
        }
    }

    public class d {
        public float a;
        public int b;
        public float c;
        public float d;
        public float e;
        public float f;
        public float g;
        public float h = 1.0f;
        public float i;

        public d() {
            this.i = PagingIndicator.this.a ? 1.0f : -1.0f;
        }

        public final void a() {
            int iRound = Math.round(this.a * 255.0f);
            PagingIndicator pagingIndicator = PagingIndicator.this;
            this.b = Color.argb(iRound, Color.red(pagingIndicator.s), Color.green(pagingIndicator.s), Color.blue(pagingIndicator.s));
        }

        public final void b() {
            this.c = 0.0f;
            this.d = 0.0f;
            PagingIndicator pagingIndicator = PagingIndicator.this;
            this.e = pagingIndicator.b;
            float f = pagingIndicator.c;
            this.f = f;
            this.g = f * pagingIndicator.ab;
            this.a = 0.0f;
            a();
        }
    }

    public PagingIndicator(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0);
        AnimatorSet animatorSet = new AnimatorSet();
        this.x = animatorSet;
        Resources resources = getResources();
        int[] iArr = bo7.n.c;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, iArr, 0, 0);
        sia.y(this, context, iArr, attributeSet, typedArrayObtainStyledAttributes, 0, 0);
        int dimensionPixelOffset = typedArrayObtainStyledAttributes.getDimensionPixelOffset(6, getResources().getDimensionPixelOffset(R.dimen.lb_page_indicator_dot_radius));
        this.c = dimensionPixelOffset;
        int i = dimensionPixelOffset * 2;
        this.b = i;
        int dimensionPixelOffset2 = typedArrayObtainStyledAttributes.getDimensionPixelOffset(2, getResources().getDimensionPixelOffset(R.dimen.lb_page_indicator_arrow_radius));
        this.f = dimensionPixelOffset2;
        int i2 = dimensionPixelOffset2 * 2;
        this.e = i2;
        this.d = typedArrayObtainStyledAttributes.getDimensionPixelOffset(5, getResources().getDimensionPixelOffset(R.dimen.lb_page_indicator_dot_gap));
        this.i = 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.t = paint;
        paint.setColor(color);
        this.s = typedArrayObtainStyledAttributes.getColor(0, getResources().getColor(R.color.lb_page_indicator_arrow_background));
        if (this.z == null && typedArrayObtainStyledAttributes.hasValue(1)) {
            setArrowColor(typedArrayObtainStyledAttributes.getColor(1, 0));
        }
        typedArrayObtainStyledAttributes.recycle();
        this.a = 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.j = dimensionPixelSize;
        Paint paint2 = new Paint(1);
        this.u = paint2;
        float dimensionPixelSize2 = resources.getDimensionPixelSize(R.dimen.lb_page_indicator_arrow_shadow_offset);
        paint2.setShadowLayer(dimensionPixelSize, dimensionPixelSize2, dimensionPixelSize2, color2);
        this.y = d();
        this.aa = new Rect(0, 0, this.y.getWidth(), this.y.getHeight());
        float f = i2;
        this.ab = this.y.getWidth() / f;
        AnimatorSet animatorSet2 = new AnimatorSet();
        this.v = animatorSet2;
        Property property = ad;
        ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat((Object) null, (Property<Object, Float>) property, 0.0f, 1.0f);
        objectAnimatorOfFloat.setDuration(167L);
        DecelerateInterpolator decelerateInterpolator = ac;
        objectAnimatorOfFloat.setInterpolator(decelerateInterpolator);
        float f2 = i;
        Property property2 = ae;
        ObjectAnimator objectAnimatorOfFloat2 = ObjectAnimator.ofFloat((Object) null, (Property<Object, Float>) property2, f2, f);
        objectAnimatorOfFloat2.setDuration(417L);
        objectAnimatorOfFloat2.setInterpolator(decelerateInterpolator);
        animatorSet2.playTogether(objectAnimatorOfFloat, objectAnimatorOfFloat2, c());
        AnimatorSet animatorSet3 = new AnimatorSet();
        this.w = animatorSet3;
        ObjectAnimator objectAnimatorOfFloat3 = ObjectAnimator.ofFloat((Object) null, (Property<Object, Float>) property, 1.0f, 0.0f);
        objectAnimatorOfFloat3.setDuration(167L);
        objectAnimatorOfFloat3.setInterpolator(decelerateInterpolator);
        ObjectAnimator objectAnimatorOfFloat4 = ObjectAnimator.ofFloat((Object) null, (Property<Object, Float>) property2, f, f2);
        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.e + this.j;
    }

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

    private int getRequiredWidth() {
        return ((this.p - 3) * this.d) + (this.i * 2) + (this.c * 2);
    }

    private void setSelectedPage(int i) {
        if (i == this.q) {
            return;
        }
        this.q = i;
        a();
    }

    public final void a() {
        int i;
        int i2 = 0;
        while (true) {
            i = this.q;
            if (i2 >= i) {
                break;
            }
            this.k[i2].b();
            d dVar = this.k[i2];
            if (i2 != this.r) {
                f = 1.0f;
            }
            dVar.h = f;
            dVar.d = this.m[i2];
            i2++;
        }
        d dVar2 = this.k[i];
        dVar2.c = 0.0f;
        dVar2.d = 0.0f;
        PagingIndicator pagingIndicator = PagingIndicator.this;
        dVar2.e = pagingIndicator.e;
        float f = pagingIndicator.f;
        dVar2.f = f;
        dVar2.g = f * pagingIndicator.ab;
        dVar2.a = 1.0f;
        dVar2.a();
        d[] dVarArr = this.k;
        int i3 = this.q;
        d dVar3 = dVarArr[i3];
        dVar3.h = this.r >= i3 ? 1.0f : -1.0f;
        dVar3.d = this.l[i3];
        while (true) {
            i3++;
            if (i3 >= this.p) {
                return;
            }
            this.k[i3].b();
            d dVar4 = this.k[i3];
            dVar4.h = 1.0f;
            dVar4.d = this.n[i3];
        }
    }

    public final void b() {
        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        int width = getWidth() - getPaddingRight();
        int requiredWidth = getRequiredWidth();
        int i = (paddingLeft + width) / 2;
        int i2 = this.p;
        int[] iArr = new int[i2];
        this.l = iArr;
        int[] iArr2 = new int[i2];
        this.m = iArr2;
        int[] iArr3 = new int[i2];
        this.n = iArr3;
        boolean z = this.a;
        int i3 = this.c;
        int i4 = this.i;
        int i5 = this.d;
        int i6 = 1;
        if (z) {
            int i7 = i - (requiredWidth / 2);
            iArr[0] = ((i7 + i3) - i5) + i4;
            iArr2[0] = i7 + i3;
            iArr3[0] = (i4 * 2) + ((i7 + i3) - (i5 * 2));
            while (i6 < this.p) {
                int[] iArr4 = this.l;
                int[] iArr5 = this.m;
                int i8 = i6 - 1;
                iArr4[i6] = iArr5[i8] + i4;
                iArr5[i6] = iArr5[i8] + i5;
                this.n[i6] = iArr4[i8] + i4;
                i6++;
            }
        } else {
            int i9 = (requiredWidth / 2) + i;
            iArr[0] = ((i9 - i3) + i5) - i4;
            iArr2[0] = i9 - i3;
            iArr3[0] = ((i5 * 2) + (i9 - i3)) - (i4 * 2);
            while (i6 < this.p) {
                int[] iArr6 = this.l;
                int[] iArr7 = this.m;
                int i10 = i6 - 1;
                iArr6[i6] = iArr7[i10] - i4;
                iArr7[i6] = iArr7[i10] - i5;
                this.n[i6] = iArr6[i10] - i4;
                i6++;
            }
        }
        this.o = paddingTop + this.f;
        a();
    }

    public final ObjectAnimator c() {
        ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat((Object) null, (Property<Object, Float>) af, (-this.i) + this.d, 0.0f);
        objectAnimatorOfFloat.setDuration(417L);
        objectAnimatorOfFloat.setInterpolator(ac);
        return objectAnimatorOfFloat;
    }

    public final Bitmap d() {
        Bitmap bitmapDecodeResource = BitmapFactory.decodeResource(getResources(), R.drawable.lb_ic_nav_arrow);
        if (this.a) {
            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 final void e(int i, boolean z) {
        if (this.q == i) {
            return;
        }
        AnimatorSet animatorSet = this.x;
        if (animatorSet.isStarted()) {
            animatorSet.end();
        }
        int i2 = this.q;
        this.r = i2;
        if (z) {
            this.w.setTarget(this.k[i2]);
            this.v.setTarget(this.k[i]);
            animatorSet.start();
        }
        setSelectedPage(i);
    }

    @sma
    public int[] getDotSelectedLeftX() {
        return this.m;
    }

    @sma
    public int[] getDotSelectedRightX() {
        return this.n;
    }

    @sma
    public int[] getDotSelectedX() {
        return this.l;
    }

    @sma
    public int getPageCount() {
        return this.p;
    }

    @Override // android.view.View
    public final void onDraw(Canvas canvas) {
        for (int i = 0; i < this.p; i++) {
            d dVar = this.k[i];
            float f = dVar.d + dVar.c;
            PagingIndicator pagingIndicator = PagingIndicator.this;
            int i2 = pagingIndicator.o;
            Paint paint = pagingIndicator.u;
            canvas.drawCircle(f, i2, dVar.f, pagingIndicator.t);
            if (dVar.a > 0.0f) {
                paint.setColor(dVar.b);
                canvas.drawCircle(f, pagingIndicator.o, dVar.f, paint);
                Bitmap bitmap = pagingIndicator.y;
                Rect rect = pagingIndicator.aa;
                float f2 = dVar.g;
                float f3 = pagingIndicator.o;
                canvas.drawBitmap(bitmap, rect, new Rect((int) (f - f2), (int) (f3 - f2), (int) (f + f2), (int) (f3 + f2)), pagingIndicator.z);
            }
        }
    }

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

    @Override // android.view.View
    public final void onRtlPropertiesChanged(int i) {
        super.onRtlPropertiesChanged(i);
        boolean z = i == 0;
        if (this.a != z) {
            this.a = z;
            this.y = d();
            d[] dVarArr = this.k;
            if (dVarArr != null) {
                for (d dVar : dVarArr) {
                    dVar.i = PagingIndicator.this.a ? 1.0f : -1.0f;
                }
            }
            b();
            invalidate();
        }
    }

    @Override // android.view.View
    public final void onSizeChanged(int i, int i2, int i3, int i4) {
        setMeasuredDimension(i, i2);
        b();
    }

    public void setArrowBackgroundColor(@w51 int i) {
        this.s = i;
    }

    public void setArrowColor(@w51 int i) {
        if (this.z == null) {
            this.z = new Paint();
        }
        this.z.setColorFilter(new PorterDuffColorFilter(i, PorterDuff.Mode.SRC_IN));
    }

    public void setDotBackgroundColor(@w51 int i) {
        this.t.setColor(i);
    }

    public void setPageCount(int i) {
        if (i <= 0) {
            throw new IllegalArgumentException("The page count should be a positive integer");
        }
        this.p = i;
        this.k = new d[i];
        for (int i2 = 0; i2 < this.p; i2++) {
            this.k[i2] = new d();
        }
        b();
        setSelectedPage(0);
    }
}
