what-the-bank/sources/com/google/android/material/timepicker/ClockFaceView.java

265 lines
11 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.google.android.material.timepicker;
import android.R;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.RadialGradient;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.TextView;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.material.timepicker.ClockHandView;
import java.util.Arrays;
import o.AgY;
import o.C14739fyr;
import o.C17052tZT;
import o.yZt;
/* loaded from: classes2.dex */
public class ClockFaceView extends RadialViewGroup implements ClockHandView.Sts {
final SparseArray<TextView> a;
private final int b;
final int c;
final Rect d;
public final ClockHandView e;
private final int f;
private float g;
private final float[] h;
private final int[] i;
private final int j;
private final ColorStateList k;
private String[] l;
private final yZt m;
private final RectF n;
/* renamed from: o, reason: collision with root package name */
private final Rect f6486o;
public ClockFaceView(Context context) {
this(context, null);
}
public ClockFaceView(Context context, AttributeSet attributeSet) {
this(context, attributeSet, C17052tZT.IeS.materialClockStyle);
}
public ClockFaceView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
this.d = new Rect();
this.n = new RectF();
this.f6486o = new Rect();
this.a = new SparseArray<>();
this.h = new float[]{BitmapDescriptorFactory.HUE_RED, 0.9f, 1.0f};
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, C17052tZT.jNh.ClockFaceView, i, C17052tZT.NHB.Widget_MaterialComponents_TimePicker_Clock);
Resources resources = getResources();
ColorStateList Ku_ = C14739fyr.Ku_(context, obtainStyledAttributes, C17052tZT.jNh.ClockFaceView_clockNumberTextColor);
this.k = Ku_;
LayoutInflater.from(context).inflate(C17052tZT.tOB.material_clockface_view, (ViewGroup) this, true);
ClockHandView clockHandView = (ClockHandView) findViewById(C17052tZT.ZqN.material_clock_hand);
this.e = clockHandView;
this.c = resources.getDimensionPixelSize(C17052tZT.HBt.material_clock_hand_padding);
int colorForState = Ku_.getColorForState(new int[]{R.attr.state_selected}, Ku_.getDefaultColor());
this.i = new int[]{colorForState, colorForState, Ku_.getDefaultColor()};
clockHandView.e.add(this);
int defaultColor = AgY.dS_(context, C17052tZT.Sts.material_timepicker_clockface).getDefaultColor();
ColorStateList Ku_2 = C14739fyr.Ku_(context, obtainStyledAttributes, C17052tZT.jNh.ClockFaceView_clockFaceBackgroundColor);
setBackgroundColor(Ku_2 != null ? Ku_2.getDefaultColor() : defaultColor);
getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(this) { // from class: com.google.android.material.timepicker.ClockFaceView.2
private ClockFaceView e;
{
this.e = this;
}
@Override // android.view.ViewTreeObserver.OnPreDrawListener
public final boolean onPreDraw() {
if (!this.e.isShown()) {
return true;
}
this.e.getViewTreeObserver().removeOnPreDrawListener(this);
int height = this.e.getHeight() / 2;
int i2 = this.e.e.c;
this.e.setRadius((height - i2) - this.e.c);
return true;
}
});
setFocusable(true);
obtainStyledAttributes.recycle();
this.m = new yZt(this) { // from class: com.google.android.material.timepicker.ClockFaceView.3
private ClockFaceView c;
{
this.c = this;
}
@Override // o.yZt
public final void onInitializeAccessibilityNodeInfo(View view, AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
super.onInitializeAccessibilityNodeInfo(view, accessibilityNodeInfoCompat);
int intValue = ((Integer) view.getTag(C17052tZT.ZqN.material_value_index)).intValue();
if (intValue > 0) {
accessibilityNodeInfoCompat.c(this.c.a.get(intValue - 1));
}
accessibilityNodeInfoCompat.d(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.c(0, 1, intValue, 1, false, view.isSelected()));
accessibilityNodeInfoCompat.d(true);
accessibilityNodeInfoCompat.e(AccessibilityNodeInfoCompat.AccessibilityActionCompat.e);
}
@Override // o.yZt
public final boolean performAccessibilityAction(View view, int i2, Bundle bundle) {
if (i2 == 16) {
long uptimeMillis = SystemClock.uptimeMillis();
view.getHitRect(this.c.d);
float centerX = this.c.d.centerX();
float centerY = this.c.d.centerY();
this.c.e.onTouchEvent(MotionEvent.obtain(uptimeMillis, uptimeMillis, 0, centerX, centerY, 0));
this.c.e.onTouchEvent(MotionEvent.obtain(uptimeMillis, uptimeMillis, 1, centerX, centerY, 0));
return true;
}
return super.performAccessibilityAction(view, i2, bundle);
}
};
String[] strArr = new String[12];
Arrays.fill(strArr, "");
setValues(strArr, 0);
this.j = resources.getDimensionPixelSize(C17052tZT.HBt.material_time_picker_minimum_screen_height);
this.f = resources.getDimensionPixelSize(C17052tZT.HBt.material_time_picker_minimum_screen_width);
this.b = resources.getDimensionPixelSize(C17052tZT.HBt.material_clock_size);
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.android.material.timepicker.RadialViewGroup
public final void e() {
super.e();
for (int i = 0; i < this.a.size(); i++) {
this.a.get(i).setVisibility(0);
}
}
@Override // android.view.View
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
AccessibilityNodeInfoCompat.tU_(accessibilityNodeInfo).e(AccessibilityNodeInfoCompat.CollectionInfoCompat.e(1, this.l.length, false, 1));
}
@Override // com.google.android.material.timepicker.RadialViewGroup
public void setRadius(int i) {
if (i != b()) {
super.setRadius(i);
this.e.setCircleRadius(b());
}
}
@Override // androidx.constraintlayout.widget.ConstraintLayout, android.view.ViewGroup, android.view.View
public void onLayout(boolean z, int i, int i2, int i3, int i4) {
super.onLayout(z, i, i2, i3, i4);
h();
}
public void setHandRotation(float f) {
this.e.setHandRotation(f);
h();
}
@Override // com.google.android.material.timepicker.ClockHandView.Sts
public final void c(float f, boolean z) {
if (Math.abs(this.g - f) > 0.001f) {
this.g = f;
h();
}
}
@Override // androidx.constraintlayout.widget.ConstraintLayout, android.view.View
public void onMeasure(int i, int i2) {
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
int max = (int) (this.b / Math.max(Math.max(this.j / displayMetrics.heightPixels, this.f / displayMetrics.widthPixels), 1.0f));
int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(max, 1073741824);
setMeasuredDimension(max, max);
super.onMeasure(makeMeasureSpec, makeMeasureSpec);
}
private void h() {
RectF rectF = this.e.b;
float f = Float.MAX_VALUE;
TextView textView = null;
for (int i = 0; i < this.a.size(); i++) {
TextView textView2 = this.a.get(i);
if (textView2 != null) {
textView2.getHitRect(this.d);
this.n.set(this.d);
this.n.union(rectF);
float width = this.n.width() * this.n.height();
if (width < f) {
textView = textView2;
f = width;
}
}
}
for (int i2 = 0; i2 < this.a.size(); i2++) {
TextView textView3 = this.a.get(i2);
if (textView3 != null) {
textView3.setSelected(textView3 == textView);
textView3.getHitRect(this.d);
this.n.set(this.d);
textView3.getLineBounds(0, this.f6486o);
this.n.inset(this.f6486o.left, this.f6486o.top);
textView3.getPaint().setShader(!RectF.intersects(rectF, this.n) ? null : new RadialGradient(rectF.centerX() - this.n.left, rectF.centerY() - this.n.top, rectF.width() * 0.5f, this.i, this.h, Shader.TileMode.CLAMP));
textView3.invalidate();
}
}
}
public void setValues(String[] strArr, int i) {
this.l = strArr;
LayoutInflater from = LayoutInflater.from(getContext());
int size = this.a.size();
boolean z = false;
for (int i2 = 0; i2 < Math.max(this.l.length, size); i2++) {
TextView textView = this.a.get(i2);
if (i2 >= this.l.length) {
removeView(textView);
this.a.remove(i2);
} else {
if (textView == null) {
textView = (TextView) from.inflate(C17052tZT.tOB.material_clockface_textview, (ViewGroup) this, false);
this.a.put(i2, textView);
addView(textView);
}
textView.setText(this.l[i2]);
textView.setTag(C17052tZT.ZqN.material_value_index, Integer.valueOf(i2));
int i3 = (i2 / 12) + 1;
textView.setTag(C17052tZT.ZqN.material_clock_level, Integer.valueOf(i3));
if (i3 > 1) {
z = true;
}
ViewCompat.e(textView, this.m);
textView.setTextColor(this.k);
if (i != 0) {
textView.setContentDescription(getResources().getString(i, this.l[i2]));
}
}
}
ClockHandView clockHandView = this.e;
if (clockHandView.d && !z) {
clockHandView.a = 1;
}
clockHandView.d = z;
clockHandView.invalidate();
}
}