package com.google.android.material.timepicker;

import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import androidx.annotation.Nullable;
import com.google.android.gms.measurement.internal.c2;
import com.google.android.material.internal.w0;
import java.util.ArrayList;
import java.util.Iterator;

/* JADX INFO: loaded from: classes2.dex */
class ClockHandView extends View {
    public static final /* synthetic */ int Q = 0;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ValueAnimator f23500a;

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

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final RectF f23506g;

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public float f23508i;

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public double f23510k;

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

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

    public ClockHandView(Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, x8.c.materialClockStyle);
    }

    public final int a(int i10) {
        return i10 == 2 ? Math.round(this.f23511l * 0.66f) : this.f23511l;
    }

    public final void b(float f10) {
        this.f23500a.cancel();
        c(f10);
    }

    public final void c(float f10) {
        float f11 = f10 % 360.0f;
        this.f23508i = f11;
        this.f23510k = Math.toRadians(f11 - 90.0f);
        int height = getHeight() / 2;
        int width = getWidth() / 2;
        float fA = a(this.f23512m);
        float fCos = (((float) Math.cos(this.f23510k)) * fA) + width;
        float fSin = (fA * ((float) Math.sin(this.f23510k))) + height;
        float f12 = this.f23503d;
        this.f23506g.set(fCos - f12, fSin - f12, fCos + f12, fSin + f12);
        Iterator it = this.f23502c.iterator();
        while (it.hasNext()) {
            ClockFaceView clockFaceView = (ClockFaceView) ((f) it.next());
            if (Math.abs(clockFaceView.f23498k0 - f11) > 0.001f) {
                clockFaceView.f23498k0 = f11;
                clockFaceView.d();
            }
        }
        invalidate();
    }

    @Override // android.view.View
    public final void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int height = getHeight() / 2;
        int width = getWidth() / 2;
        float f10 = width;
        float fA = a(this.f23512m);
        float fCos = (((float) Math.cos(this.f23510k)) * fA) + f10;
        float f11 = height;
        float fSin = (fA * ((float) Math.sin(this.f23510k))) + f11;
        Paint paint = this.f23505f;
        paint.setStrokeWidth(0.0f);
        canvas.drawCircle(fCos, fSin, this.f23503d, paint);
        double dSin = Math.sin(this.f23510k);
        paint.setStrokeWidth(this.f23507h);
        canvas.drawLine(f10, f11, width + ((int) (Math.cos(this.f23510k) * d)), height + ((int) (d * dSin)), paint);
        canvas.drawCircle(f10, f11, this.f23504e, paint);
    }

    @Override // android.view.View
    public final void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        super.onLayout(z10, i10, i11, i12, i13);
        if (this.f23500a.isRunning()) {
            return;
        }
        b(this.f23508i);
    }

    @Override // android.view.View
    public final boolean onTouchEvent(MotionEvent motionEvent) {
        boolean z10;
        boolean z11;
        int actionMasked = motionEvent.getActionMasked();
        float x10 = motionEvent.getX();
        float y10 = motionEvent.getY();
        boolean z12 = false;
        if (actionMasked == 0) {
            this.f23509j = false;
            z10 = true;
            z11 = false;
        } else if (actionMasked == 1 || actionMasked == 2) {
            z11 = this.f23509j;
            if (this.f23501b) {
                this.f23512m = c2.g((float) (getWidth() / 2), (float) (getHeight() / 2), x10, y10) <= ((float) a(2)) + w0.d(getContext(), 12) ? 2 : 1;
            }
            z10 = false;
        } else {
            z11 = false;
            z10 = false;
        }
        boolean z13 = this.f23509j;
        int degrees = (int) Math.toDegrees(Math.atan2(y10 - (getHeight() / 2), x10 - (getWidth() / 2)));
        int i10 = degrees + 90;
        if (i10 < 0) {
            i10 = degrees + 450;
        }
        float f10 = i10;
        boolean z14 = this.f23508i != f10;
        if (z10 && z14) {
            z12 = true;
        } else if (z14 || z11) {
            b(f10);
            z12 = true;
        }
        this.f23509j = z13 | z12;
        return true;
    }

    public ClockHandView(Context context, @Nullable AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        ValueAnimator valueAnimator = new ValueAnimator();
        this.f23500a = valueAnimator;
        this.f23502c = new ArrayList();
        Paint paint = new Paint();
        this.f23505f = paint;
        this.f23506g = new RectF();
        this.f23512m = 1;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, x8.m.ClockHandView, i10, x8.l.Widget_MaterialComponents_TimePicker_Clock);
        com.bumptech.glide.f.o(context, x8.c.motionDurationLong2, 200);
        com.bumptech.glide.f.p(context, x8.c.motionEasingEmphasizedInterpolator, y8.a.f36865b);
        this.f23511l = typedArrayObtainStyledAttributes.getDimensionPixelSize(x8.m.ClockHandView_materialCircleRadius, 0);
        this.f23503d = typedArrayObtainStyledAttributes.getDimensionPixelSize(x8.m.ClockHandView_selectorSize, 0);
        this.f23507h = getResources().getDimensionPixelSize(x8.e.material_clock_hand_stroke_width);
        this.f23504e = r8.getDimensionPixelSize(x8.e.material_clock_hand_center_dot_radius);
        int color = typedArrayObtainStyledAttributes.getColor(x8.m.ClockHandView_clockHandColor, 0);
        paint.setAntiAlias(true);
        paint.setColor(color);
        b(0.0f);
        ViewConfiguration.get(context).getScaledTouchSlop();
        setImportantForAccessibility(2);
        typedArrayObtainStyledAttributes.recycle();
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: com.google.android.material.timepicker.d
            @Override // android.animation.ValueAnimator.AnimatorUpdateListener
            public final void onAnimationUpdate(ValueAnimator valueAnimator2) {
                int i11 = ClockHandView.Q;
                ClockHandView clockHandView = this.f23516a;
                clockHandView.getClass();
                clockHandView.c(((Float) valueAnimator2.getAnimatedValue()).floatValue());
            }
        });
        valueAnimator.addListener(new e());
    }
}
