package com.google.android.material.timepicker;

import M.J;
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 com.martsnew.tv.R;
import h3.AbstractC1031a;
import java.lang.reflect.Field;
import java.util.ArrayList;

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

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

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

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

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

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

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

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

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

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

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

    public ClockHandView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, R.attr.materialClockStyle);
        this.f10403q = new ArrayList();
        Paint paint = new Paint();
        this.f10406t = paint;
        this.f10407u = new RectF();
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, AbstractC1031a.f13400f, R.attr.materialClockStyle, R.style.Widget_MaterialComponents_TimePicker_Clock);
        this.f10412z = typedArrayObtainStyledAttributes.getDimensionPixelSize(1, 0);
        this.f10404r = typedArrayObtainStyledAttributes.getDimensionPixelSize(2, 0);
        this.f10408v = getResources().getDimensionPixelSize(R.dimen.material_clock_hand_stroke_width);
        this.f10405s = r4.getDimensionPixelSize(R.dimen.material_clock_hand_center_dot_radius);
        int color = typedArrayObtainStyledAttributes.getColor(0, 0);
        paint.setAntiAlias(true);
        paint.setColor(color);
        a(0.0f);
        ViewConfiguration.get(context).getScaledTouchSlop();
        Field field = J.f4065a;
        setImportantForAccessibility(2);
        typedArrayObtainStyledAttributes.recycle();
    }

    public final void a(float f3) {
        float f7 = f3 % 360.0f;
        this.f10409w = f7;
        this.f10411y = Math.toRadians(f7 - 90.0f);
        int height = getHeight() / 2;
        float fCos = (this.f10412z * ((float) Math.cos(this.f10411y))) + (getWidth() / 2);
        float fSin = (this.f10412z * ((float) Math.sin(this.f10411y))) + height;
        float f8 = this.f10404r;
        this.f10407u.set(fCos - f8, fSin - f8, fCos + f8, fSin + f8);
        ArrayList arrayList = this.f10403q;
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj = arrayList.get(i);
            i++;
            ClockFaceView clockFaceView = (ClockFaceView) ((d) obj);
            if (Math.abs(clockFaceView.f10401U - f7) > 0.001f) {
                clockFaceView.f10401U = f7;
                clockFaceView.g();
            }
        }
        invalidate();
    }

    @Override // android.view.View
    public final void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int height = getHeight() / 2;
        float width = getWidth() / 2;
        float fCos = (this.f10412z * ((float) Math.cos(this.f10411y))) + width;
        float f3 = height;
        float fSin = (this.f10412z * ((float) Math.sin(this.f10411y))) + f3;
        Paint paint = this.f10406t;
        paint.setStrokeWidth(0.0f);
        canvas.drawCircle(fCos, fSin, this.f10404r, paint);
        double dSin = Math.sin(this.f10411y);
        double dCos = Math.cos(this.f10411y);
        paint.setStrokeWidth(this.f10408v);
        canvas.drawLine(width, f3, r1 + ((int) (dCos * d)), height + ((int) (d * dSin)), paint);
        canvas.drawCircle(width, f3, this.f10405s, paint);
    }

    @Override // android.view.View
    public final void onLayout(boolean z8, int i, int i5, int i8, int i9) {
        super.onLayout(z8, i, i5, i8, i9);
        a(this.f10409w);
    }

    @Override // android.view.View
    public final boolean onTouchEvent(MotionEvent motionEvent) {
        boolean z8;
        boolean z9;
        int actionMasked = motionEvent.getActionMasked();
        float x8 = motionEvent.getX();
        float y8 = motionEvent.getY();
        boolean z10 = false;
        if (actionMasked == 0) {
            this.f10410x = false;
            z8 = true;
            z9 = false;
        } else if (actionMasked == 1 || actionMasked == 2) {
            z9 = this.f10410x;
            z8 = false;
        } else {
            z9 = false;
            z8 = false;
        }
        boolean z11 = this.f10410x;
        int degrees = (int) Math.toDegrees(Math.atan2(y8 - (getHeight() / 2), x8 - (getWidth() / 2)));
        int i = degrees + 90;
        if (i < 0) {
            i = degrees + 450;
        }
        float f3 = i;
        boolean z12 = this.f10409w != f3;
        if (z8 && z12) {
            z10 = true;
        } else if (z12 || z9) {
            a(f3);
            z10 = true;
        }
        this.f10410x = z11 | z10;
        return true;
    }
}
