what-the-bank/sources/com/google/android/material/button/MaterialButtonToggleGroup.java

478 lines
17 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.google.android.material.button;
import android.content.Context;
import android.graphics.Canvas;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.ToggleButton;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.material.button.MaterialButton;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeMap;
import o.C17052tZT;
import o.C17525xWe;
import o.CYM;
import o.DjZ;
import o.FLD;
import o.kdE;
import o.yZt;
/* loaded from: classes2.dex */
public class MaterialButtonToggleGroup extends LinearLayout {
private static final int e = C17052tZT.NHB.Widget_MaterialComponents_MaterialButtonToggleGroup;
private Set<Integer> a;
public final LinkedHashSet<RVV> b;
private Integer[] c;
boolean d;
private final List<HBt> f;
private boolean g;
private final IeS h;
private final int i;
private final Comparator<MaterialButton> j;
private boolean k;
/* loaded from: classes2.dex */
public interface RVV {
void a(int i, boolean z);
}
public MaterialButtonToggleGroup(Context context) {
this(context, null);
}
public MaterialButtonToggleGroup(Context context, AttributeSet attributeSet) {
this(context, attributeSet, C17052tZT.IeS.materialButtonToggleGroupStyle);
}
/* JADX WARN: Illegal instructions before constructor call */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public MaterialButtonToggleGroup(android.content.Context r10, android.util.AttributeSet r11, int r12) {
/*
r9 = this;
int r6 = com.google.android.material.button.MaterialButtonToggleGroup.e
android.content.Context r10 = o.hdZ.MQ_(r10, r11, r12, r6)
r9.<init>(r10, r11, r12)
java.util.ArrayList r10 = new java.util.ArrayList
r10.<init>()
r9.f = r10
com.google.android.material.button.MaterialButtonToggleGroup$IeS r10 = new com.google.android.material.button.MaterialButtonToggleGroup$IeS
r7 = 0
r10.<init>(r9, r7)
r9.h = r10
java.util.LinkedHashSet r10 = new java.util.LinkedHashSet
r10.<init>()
r9.b = r10
com.google.android.material.button.MaterialButtonToggleGroup$1 r10 = new com.google.android.material.button.MaterialButtonToggleGroup$1
r10.<init>(r9)
r9.j = r10
r9.d = r7
java.util.HashSet r10 = new java.util.HashSet
r10.<init>()
r9.a = r10
android.content.Context r10 = r9.getContext()
int[] r8 = o.C17052tZT.jNh.MaterialButtonToggleGroup
int[] r5 = new int[r7]
o.uqW.Kb_(r10, r11, r12, r6)
r0 = r10
r1 = r11
r2 = r8
r3 = r12
r4 = r6
o.uqW.Kc_(r0, r1, r2, r3, r4, r5)
android.content.res.TypedArray r10 = r10.obtainStyledAttributes(r11, r8, r12, r6)
int r11 = o.C17052tZT.jNh.MaterialButtonToggleGroup_singleSelection
boolean r11 = r10.getBoolean(r11, r7)
r9.setSingleSelection(r11)
int r11 = o.C17052tZT.jNh.MaterialButtonToggleGroup_checkedButton
r12 = -1
int r11 = r10.getResourceId(r11, r12)
r9.i = r11
int r11 = o.C17052tZT.jNh.MaterialButtonToggleGroup_selectionRequired
boolean r11 = r10.getBoolean(r11, r7)
r9.g = r11
r11 = 1
r9.setChildrenDrawingOrderEnabled(r11)
int r12 = o.C17052tZT.jNh.MaterialButtonToggleGroup_android_enabled
boolean r12 = r10.getBoolean(r12, r11)
r9.setEnabled(r12)
r10.recycle()
androidx.core.view.ViewCompat.g(r9, r11)
return
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.button.MaterialButtonToggleGroup.<init>(android.content.Context, android.util.AttributeSet, int):void");
}
@Override // android.view.View
protected void onFinishInflate() {
super.onFinishInflate();
int i = this.i;
if (i != -1) {
c(Collections.singleton(Integer.valueOf(i)));
}
}
@Override // android.view.ViewGroup
public void addView(View view, int i, ViewGroup.LayoutParams layoutParams) {
if (view instanceof MaterialButton) {
super.addView(view, i, layoutParams);
MaterialButton materialButton = (MaterialButton) view;
if (materialButton.getId() == -1) {
materialButton.setId(ViewCompat.a());
}
materialButton.setMaxLines(1);
materialButton.setEllipsize(TextUtils.TruncateAt.END);
materialButton.setCheckable(true);
materialButton.b = this.h;
DjZ djZ = materialButton.d;
if (djZ != null && !djZ.d) {
DjZ djZ2 = materialButton.d;
djZ2.s = true;
djZ2.a();
}
b(materialButton.getId(), materialButton.isChecked());
FLD c = materialButton.c();
this.f.add(new HBt(c.n, c.b, c.k, c.j));
materialButton.setEnabled(isEnabled());
ViewCompat.e(materialButton, new yZt(this) { // from class: com.google.android.material.button.MaterialButtonToggleGroup.5
private MaterialButtonToggleGroup c;
{
this.c = this;
}
@Override // o.yZt
public final void onInitializeAccessibilityNodeInfo(View view2, AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
int i2;
super.onInitializeAccessibilityNodeInfo(view2, accessibilityNodeInfoCompat);
MaterialButtonToggleGroup materialButtonToggleGroup = this.c;
if (view2 instanceof MaterialButton) {
i2 = 0;
for (int i3 = 0; i3 < materialButtonToggleGroup.getChildCount(); i3++) {
if (materialButtonToggleGroup.getChildAt(i3) == view2) {
break;
}
if ((materialButtonToggleGroup.getChildAt(i3) instanceof MaterialButton) && materialButtonToggleGroup.getChildAt(i3).getVisibility() != 8) {
i2++;
}
}
}
i2 = -1;
accessibilityNodeInfoCompat.d(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.c(0, 1, i2, 1, false, ((MaterialButton) view2).isChecked()));
}
});
}
}
@Override // android.view.ViewGroup
public void onViewRemoved(View view) {
super.onViewRemoved(view);
if (view instanceof MaterialButton) {
((MaterialButton) view).b = null;
}
int indexOfChild = indexOfChild(view);
if (indexOfChild >= 0) {
this.f.remove(indexOfChild);
}
d();
b();
}
@Override // android.widget.LinearLayout, android.view.View
protected void onMeasure(int i, int i2) {
d();
b();
super.onMeasure(i, i2);
}
@Override // android.view.View
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
AccessibilityNodeInfoCompat tU_ = AccessibilityNodeInfoCompat.tU_(accessibilityNodeInfo);
int i = 0;
for (int i2 = 0; i2 < getChildCount(); i2++) {
if ((getChildAt(i2) instanceof MaterialButton) && getChildAt(i2).getVisibility() != 8) {
i++;
}
}
tU_.e(AccessibilityNodeInfoCompat.CollectionInfoCompat.e(1, i, false, this.k ? 1 : 2));
}
public void setSingleSelection(int i) {
setSingleSelection(getResources().getBoolean(i));
}
private void d() {
int childCount = getChildCount();
int a = a();
int e2 = e();
for (int i = 0; i < childCount; i++) {
MaterialButton materialButton = (MaterialButton) getChildAt(i);
if (materialButton.getVisibility() != 8) {
FLD.RVV rvv = new FLD.RVV(materialButton.c());
c(rvv, d(i, a, e2));
materialButton.setShapeAppearanceModel(new FLD(rvv, (byte) 0));
}
}
}
private int a() {
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
if (getChildAt(i).getVisibility() != 8) {
return i;
}
}
return -1;
}
private int e() {
for (int childCount = getChildCount() - 1; childCount >= 0; childCount--) {
if (getChildAt(childCount).getVisibility() != 8) {
return childCount;
}
}
return -1;
}
private HBt d(int i, int i2, int i3) {
HBt hBt = this.f.get(i);
if (i2 == i3) {
return hBt;
}
boolean z = getOrientation() == 0;
if (i == i2) {
if (z) {
if (ViewCompat.m(this) == 1) {
kdE kde = HBt.b;
return new HBt(kde, kde, hBt.d, hBt.e);
}
kdE kde2 = hBt.c;
kdE kde3 = hBt.a;
kdE kde4 = HBt.b;
return new HBt(kde2, kde3, kde4, kde4);
}
kdE kde5 = hBt.c;
kdE kde6 = HBt.b;
return new HBt(kde5, kde6, hBt.d, kde6);
}
if (i != i3) {
return null;
}
if (z) {
if (ViewCompat.m(this) == 1) {
kdE kde7 = hBt.c;
kdE kde8 = hBt.a;
kdE kde9 = HBt.b;
return new HBt(kde7, kde8, kde9, kde9);
}
kdE kde10 = HBt.b;
return new HBt(kde10, kde10, hBt.d, hBt.e);
}
kdE kde11 = HBt.b;
return new HBt(kde11, hBt.a, kde11, hBt.e);
}
public final void b(int i, boolean z) {
if (i == -1) {
return;
}
HashSet hashSet = new HashSet(this.a);
if (z && !hashSet.contains(Integer.valueOf(i))) {
if (this.k && !hashSet.isEmpty()) {
hashSet.clear();
}
hashSet.add(Integer.valueOf(i));
} else {
if (z || !hashSet.contains(Integer.valueOf(i))) {
return;
}
if (!this.g || hashSet.size() > 1) {
hashSet.remove(Integer.valueOf(i));
}
}
c(hashSet);
}
private void c(Set<Integer> set) {
Set<Integer> set2 = this.a;
this.a = new HashSet(set);
for (int i = 0; i < getChildCount(); i++) {
int id = ((MaterialButton) getChildAt(i)).getId();
boolean contains = set.contains(Integer.valueOf(id));
View findViewById = findViewById(id);
if (findViewById instanceof MaterialButton) {
this.d = true;
((MaterialButton) findViewById).setChecked(contains);
this.d = false;
}
if (set2.contains(Integer.valueOf(id)) != set.contains(Integer.valueOf(id))) {
e(id, set.contains(Integer.valueOf(id)));
}
}
invalidate();
}
private void e(int i, boolean z) {
Iterator<RVV> it = this.b.iterator();
while (it.hasNext()) {
it.next().a(i, z);
}
}
@Override // android.view.ViewGroup
protected int getChildDrawingOrder(int i, int i2) {
Integer[] numArr = this.c;
return (numArr == null || i2 >= numArr.length) ? i2 : numArr[i2].intValue();
}
@Override // android.view.View
public void setEnabled(boolean z) {
super.setEnabled(z);
for (int i = 0; i < getChildCount(); i++) {
((MaterialButton) getChildAt(i)).setEnabled(z);
}
}
/* loaded from: classes2.dex */
class IeS implements MaterialButton.LWm {
private MaterialButtonToggleGroup a;
private IeS(MaterialButtonToggleGroup materialButtonToggleGroup) {
this.a = materialButtonToggleGroup;
}
/* synthetic */ IeS(MaterialButtonToggleGroup materialButtonToggleGroup, byte b) {
this(materialButtonToggleGroup);
}
@Override // com.google.android.material.button.MaterialButton.LWm
public final void a() {
this.a.invalidate();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class HBt {
static final kdE b = new C17525xWe(BitmapDescriptorFactory.HUE_RED);
kdE a;
kdE c;
kdE d;
kdE e;
HBt(kdE kde, kdE kde2, kdE kde3, kdE kde4) {
this.c = kde;
this.d = kde3;
this.e = kde4;
this.a = kde2;
}
}
private void b() {
LinearLayout.LayoutParams layoutParams;
int childCount = getChildCount();
int i = 0;
while (true) {
if (i >= childCount) {
i = -1;
break;
} else if (getChildAt(i).getVisibility() != 8) {
break;
} else {
i++;
}
}
if (i == -1) {
return;
}
for (int i2 = i + 1; i2 < getChildCount(); i2++) {
MaterialButton materialButton = (MaterialButton) getChildAt(i2);
int min = Math.min(materialButton.e(), ((MaterialButton) getChildAt(i2 - 1)).e());
ViewGroup.LayoutParams layoutParams2 = materialButton.getLayoutParams();
if (layoutParams2 instanceof LinearLayout.LayoutParams) {
layoutParams = (LinearLayout.LayoutParams) layoutParams2;
} else {
layoutParams = new LinearLayout.LayoutParams(layoutParams2.width, layoutParams2.height);
}
if (getOrientation() == 0) {
CYM.rz_(layoutParams, 0);
CYM.rA_(layoutParams, -min);
((ViewGroup.MarginLayoutParams) layoutParams).topMargin = 0;
} else {
((ViewGroup.MarginLayoutParams) layoutParams).bottomMargin = 0;
((ViewGroup.MarginLayoutParams) layoutParams).topMargin = -min;
CYM.rA_(layoutParams, 0);
}
materialButton.setLayoutParams(layoutParams);
}
if (getChildCount() == 0 || i == -1) {
return;
}
LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) ((MaterialButton) getChildAt(i)).getLayoutParams();
if (getOrientation() == 1) {
((ViewGroup.MarginLayoutParams) layoutParams3).topMargin = 0;
((ViewGroup.MarginLayoutParams) layoutParams3).bottomMargin = 0;
} else {
CYM.rz_(layoutParams3, 0);
CYM.rA_(layoutParams3, 0);
((ViewGroup.MarginLayoutParams) layoutParams3).leftMargin = 0;
((ViewGroup.MarginLayoutParams) layoutParams3).rightMargin = 0;
}
}
private static void c(FLD.RVV rvv, HBt hBt) {
if (hBt == null) {
rvv.f = new C17525xWe(BitmapDescriptorFactory.HUE_RED);
rvv.k = new C17525xWe(BitmapDescriptorFactory.HUE_RED);
rvv.d = new C17525xWe(BitmapDescriptorFactory.HUE_RED);
rvv.e = new C17525xWe(BitmapDescriptorFactory.HUE_RED);
return;
}
rvv.f = hBt.c;
rvv.e = hBt.a;
rvv.k = hBt.d;
rvv.d = hBt.e;
}
@Override // android.view.ViewGroup, android.view.View
protected void dispatchDraw(Canvas canvas) {
TreeMap treeMap = new TreeMap(this.j);
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
treeMap.put((MaterialButton) getChildAt(i), Integer.valueOf(i));
}
this.c = (Integer[]) treeMap.values().toArray(new Integer[0]);
super.dispatchDraw(canvas);
}
public void setSingleSelection(boolean z) {
if (this.k != z) {
this.k = z;
c(new HashSet());
}
for (int i = 0; i < getChildCount(); i++) {
((MaterialButton) getChildAt(i)).a = (this.k ? RadioButton.class : ToggleButton.class).getName();
}
}
public void setSelectionRequired(boolean z) {
this.g = z;
}
}