package com.google.android.material.timepicker; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.TimeInterpolator; 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.util.Pair; import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; import androidx.core.view.ViewCompat; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.material.timepicker.ClockHandView; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import o.C17052tZT; import o.C6217cMa; import o.DAZ; import org.bouncycastle.asn1.x509.DisplayText; /* loaded from: classes2.dex */ public class ClockHandView extends View { public int a; final RectF b; final int c; boolean d; public final List e; private boolean f; private final float g; private final int h; private final TimeInterpolator i; private boolean j; private float k; private float l; private double m; private boolean n; /* renamed from: o, reason: collision with root package name */ private int f6487o; private RVV p; private final ValueAnimator q; private final int r; private float s; private final Paint t; private final int y; /* loaded from: classes2.dex */ public interface RVV { void a(float f, boolean z); } /* loaded from: classes2.dex */ public interface Sts { void c(float f, boolean z); } public ClockHandView(Context context) { this(context, null); } public ClockHandView(Context context, AttributeSet attributeSet) { this(context, attributeSet, C17052tZT.IeS.materialClockStyle); } public ClockHandView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); this.q = new ValueAnimator(); this.e = new ArrayList(); Paint paint = new Paint(); this.t = paint; this.b = new RectF(); this.a = 1; TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, C17052tZT.jNh.ClockHandView, i, C17052tZT.NHB.Widget_MaterialComponents_TimePicker_Clock); this.h = DAZ.a(context, C17052tZT.IeS.motionDurationLong2, DisplayText.DISPLAY_TEXT_MAXIMUM_SIZE); this.i = DAZ.Kh_(context, C17052tZT.IeS.motionEasingEmphasizedInterpolator, C6217cMa.d); this.f6487o = obtainStyledAttributes.getDimensionPixelSize(C17052tZT.jNh.ClockHandView_materialCircleRadius, 0); this.c = obtainStyledAttributes.getDimensionPixelSize(C17052tZT.jNh.ClockHandView_selectorSize, 0); this.y = getResources().getDimensionPixelSize(C17052tZT.HBt.material_clock_hand_stroke_width); this.g = r7.getDimensionPixelSize(C17052tZT.HBt.material_clock_hand_center_dot_radius); int color = obtainStyledAttributes.getColor(C17052tZT.jNh.ClockHandView_clockHandColor, 0); paint.setAntiAlias(true); paint.setColor(color); setHandRotation(BitmapDescriptorFactory.HUE_RED); this.r = ViewConfiguration.get(context).getScaledTouchSlop(); ViewCompat.g(this, 2); obtainStyledAttributes.recycle(); } @Override // android.view.View protected void onLayout(boolean z, int i, int i2, int i3, int i4) { super.onLayout(z, i, i2, i3, i4); if (this.q.isRunning()) { return; } setHandRotation(this.s); } public void setHandRotation(float f) { setHandRotation(f, false); } public void setHandRotation(float f, boolean z) { ValueAnimator valueAnimator = this.q; if (valueAnimator != null) { valueAnimator.cancel(); } if (!z) { d(f, false); return; } float f2 = this.s; if (Math.abs(f2 - f) > 180.0f) { if (f2 > 180.0f && f < 180.0f) { f += 360.0f; } if (f2 < 180.0f && f > 180.0f) { f2 += 360.0f; } } Pair pair = new Pair(Float.valueOf(f2), Float.valueOf(f)); this.q.setFloatValues(((Float) pair.first).floatValue(), ((Float) pair.second).floatValue()); this.q.setDuration(this.h); this.q.setInterpolator(this.i); this.q.addUpdateListener(new ValueAnimator.AnimatorUpdateListener(this) { // from class: o.QSS private ClockHandView b; @Override // android.animation.ValueAnimator.AnimatorUpdateListener public final void onAnimationUpdate(ValueAnimator valueAnimator2) { this.b.d(((Float) valueAnimator2.getAnimatedValue()).floatValue(), true); } { this.b = this; } }); this.q.addListener(new AnimatorListenerAdapter(this) { // from class: com.google.android.material.timepicker.ClockHandView.4 private ClockHandView d; { this.d = this; } @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener public final void onAnimationCancel(Animator animator) { animator.end(); } }); this.q.start(); } public final void d(float f, boolean z) { float f2 = f % 360.0f; this.s = f2; this.m = Math.toRadians(f2 - 90.0f); int height = getHeight() / 2; int width = getWidth() / 2; float round = this.a == 2 ? Math.round(this.f6487o * 0.66f) : this.f6487o; float cos = width + (((float) Math.cos(this.m)) * round); float sin = height + (round * ((float) Math.sin(this.m))); RectF rectF = this.b; float f3 = this.c; rectF.set(cos - f3, sin - f3, cos + f3, sin + f3); Iterator it = this.e.iterator(); while (it.hasNext()) { it.next().c(f2, z); } invalidate(); } @Override // android.view.View protected void onDraw(Canvas canvas) { super.onDraw(canvas); int height = getHeight() / 2; int width = getWidth() / 2; float f = width; float round = this.a == 2 ? Math.round(this.f6487o * 0.66f) : this.f6487o; float cos = (float) Math.cos(this.m); float f2 = height; float sin = (float) Math.sin(this.m); this.t.setStrokeWidth(BitmapDescriptorFactory.HUE_RED); canvas.drawCircle((cos * round) + f, (round * sin) + f2, this.c, this.t); double sin2 = Math.sin(this.m); double cos2 = Math.cos(this.m); this.t.setStrokeWidth(this.y); canvas.drawLine(f, f2, width + ((int) (cos2 * r7)), height + ((int) (r7 * sin2)), this.t); canvas.drawCircle(f, f2, this.g, this.t); } public void setCircleRadius(int i) { this.f6487o = i; invalidate(); } @Override // android.view.View public boolean onTouchEvent(MotionEvent motionEvent) { boolean z; boolean z2; boolean z3; boolean z4; RVV rvv; int actionMasked = motionEvent.getActionMasked(); float x = motionEvent.getX(); float y = motionEvent.getY(); boolean z5 = false; if (actionMasked != 0) { if (actionMasked == 1 || actionMasked == 2) { int i = (int) (x - this.k); int i2 = (int) (y - this.l); this.n = (i * i) + (i2 * i2) > this.r; z2 = this.j; z = actionMasked == 1; if (this.d) { this.a = ((float) Math.hypot((double) (x - ((float) (getWidth() / 2))), (double) (y - ((float) (getHeight() / 2))))) > ((float) Math.round(((float) this.f6487o) * 0.66f)) + TypedValue.applyDimension(1, 12.0f, getContext().getResources().getDisplayMetrics()) ? 1 : 2; } z3 = false; } else { z = false; z3 = false; z2 = false; } } else { this.k = x; this.l = y; this.n = true; this.j = false; z = false; z2 = false; z3 = true; } boolean z6 = this.j; float e = e(x, y); boolean z7 = this.s != e; if (!z3 || !z7) { if (z7 || z2) { if (z && this.f) { z5 = true; } setHandRotation(e, z5); } z4 = z5 | z6; this.j = z4; if (z4 && z && (rvv = this.p) != null) { rvv.a(e(x, y), this.n); } return true; } z5 = true; z4 = z5 | z6; this.j = z4; if (z4) { rvv.a(e(x, y), this.n); } return true; } private int e(float f, float f2) { int degrees = (int) Math.toDegrees(Math.atan2(f2 - (getHeight() / 2), f - (getWidth() / 2))); int i = degrees + 90; return i < 0 ? degrees + 450 : i; } public void setOnActionUpListener(RVV rvv) { this.p = rvv; } public void setAnimateOnTouchUp(boolean z) { this.f = z; } }