package com.google.android.material.timepicker;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
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.util.Pair;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import com.ifpdos.udi.service.core.pc.R;
import d.h.j.y;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final /* synthetic */ int f1182f = 0;
    public int A;

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

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

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

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

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

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final List<c> f1188r;

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

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

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

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

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

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

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

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

    public class a implements ValueAnimator.AnimatorUpdateListener {
        public a() {
        }

        @Override // android.animation.ValueAnimator.AnimatorUpdateListener
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float fFloatValue = ((Float) valueAnimator.getAnimatedValue()).floatValue();
            ClockHandView clockHandView = ClockHandView.this;
            int i2 = ClockHandView.f1182f;
            clockHandView.c(fFloatValue, true);
        }
    }

    public class b extends AnimatorListenerAdapter {
        public b(ClockHandView clockHandView) {
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationCancel(Animator animator) {
            animator.end();
        }
    }

    public interface c {
        void a(float f2, boolean z2);
    }

    public ClockHandView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, R.attr.materialClockStyle);
        this.f1188r = new ArrayList();
        Paint paint = new Paint();
        this.f1191u = paint;
        this.f1192v = new RectF();
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, g.e.a.a.b.f3541f, R.attr.materialClockStyle, R.style.Widget_MaterialComponents_TimePicker_Clock);
        this.A = typedArrayObtainStyledAttributes.getDimensionPixelSize(1, 0);
        this.f1189s = typedArrayObtainStyledAttributes.getDimensionPixelSize(2, 0);
        this.f1193w = getResources().getDimensionPixelSize(R.dimen.material_clock_hand_stroke_width);
        this.f1190t = r4.getDimensionPixelSize(R.dimen.material_clock_hand_center_dot_radius);
        int color = typedArrayObtainStyledAttributes.getColor(0, 0);
        paint.setAntiAlias(true);
        paint.setColor(color);
        b(0.0f, false);
        this.f1187q = ViewConfiguration.get(context).getScaledTouchSlop();
        AtomicInteger atomicInteger = y.a;
        y.c.s(this, 2);
        typedArrayObtainStyledAttributes.recycle();
    }

    public final int a(float f2, float f3) {
        int degrees = ((int) Math.toDegrees(Math.atan2(f3 - (getHeight() / 2), f2 - (getWidth() / 2)))) + 90;
        return degrees < 0 ? degrees + 360 : degrees;
    }

    public void b(float f2, boolean z2) {
        ValueAnimator valueAnimator = this.f1183m;
        if (valueAnimator != null) {
            valueAnimator.cancel();
        }
        if (!z2) {
            c(f2, false);
            return;
        }
        float f3 = this.f1194x;
        if (Math.abs(f3 - f2) > 180.0f) {
            if (f3 > 180.0f && f2 < 180.0f) {
                f2 += 360.0f;
            }
            if (f3 < 180.0f && f2 > 180.0f) {
                f3 += 360.0f;
            }
        }
        Pair pair = new Pair(Float.valueOf(f3), Float.valueOf(f2));
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(((Float) pair.first).floatValue(), ((Float) pair.second).floatValue());
        this.f1183m = valueAnimatorOfFloat;
        valueAnimatorOfFloat.setDuration(200L);
        this.f1183m.addUpdateListener(new a());
        this.f1183m.addListener(new b(this));
        this.f1183m.start();
    }

    public final void c(float f2, boolean z2) {
        float f3 = f2 % 360.0f;
        this.f1194x = f3;
        this.f1196z = Math.toRadians(f3 - 90.0f);
        int height = getHeight() / 2;
        float fCos = (this.A * ((float) Math.cos(this.f1196z))) + (getWidth() / 2);
        float fSin = (this.A * ((float) Math.sin(this.f1196z))) + height;
        RectF rectF = this.f1192v;
        int i2 = this.f1189s;
        rectF.set(fCos - i2, fSin - i2, fCos + i2, fSin + i2);
        Iterator<c> it = this.f1188r.iterator();
        while (it.hasNext()) {
            it.next().a(f3, z2);
        }
        invalidate();
    }

    @Override // android.view.View
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int height = getHeight() / 2;
        float width = getWidth() / 2;
        float fCos = (this.A * ((float) Math.cos(this.f1196z))) + width;
        float f2 = height;
        float fSin = (this.A * ((float) Math.sin(this.f1196z))) + f2;
        this.f1191u.setStrokeWidth(0.0f);
        canvas.drawCircle(fCos, fSin, this.f1189s, this.f1191u);
        double dSin = Math.sin(this.f1196z);
        double dCos = Math.cos(this.f1196z);
        this.f1191u.setStrokeWidth(this.f1193w);
        canvas.drawLine(width, f2, r1 + ((int) (dCos * d)), height + ((int) (d * dSin)), this.f1191u);
        canvas.drawCircle(width, f2, this.f1190t, this.f1191u);
    }

    @Override // android.view.View
    public void onLayout(boolean z2, int i2, int i3, int i4, int i5) {
        super.onLayout(z2, i2, i3, i4, i5);
        b(this.f1194x, false);
    }

    @Override // android.view.View
    @SuppressLint({"ClickableViewAccessibility"})
    public boolean onTouchEvent(MotionEvent motionEvent) {
        boolean z2;
        boolean z3;
        int actionMasked = motionEvent.getActionMasked();
        float x2 = motionEvent.getX();
        float y2 = motionEvent.getY();
        boolean z4 = false;
        if (actionMasked == 0) {
            this.f1184n = x2;
            this.f1185o = y2;
            this.f1186p = true;
            this.f1195y = false;
            z2 = false;
            z3 = true;
        } else if (actionMasked == 1 || actionMasked == 2) {
            int i2 = (int) (x2 - this.f1184n);
            int i3 = (int) (y2 - this.f1185o);
            this.f1186p = (i3 * i3) + (i2 * i2) > this.f1187q;
            z2 = this.f1195y;
            if (actionMasked == 1) {
            }
            z3 = false;
        } else {
            z2 = false;
            z3 = false;
        }
        boolean z5 = this.f1195y;
        float fA = a(x2, y2);
        boolean z6 = this.f1194x != fA;
        if (z3 && z6) {
            z4 = true;
        } else if (z6 || z2) {
            b(fA, false);
            z4 = true;
        }
        this.f1195y = z5 | z4;
        return true;
    }
}
