mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-14 18:07:16 +01:00
319 lines
12 KiB
Java
319 lines
12 KiB
Java
package com.google.android.material.button;
|
|
|
|
import android.content.Context;
|
|
import android.text.TextUtils;
|
|
import android.util.AttributeSet;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
import android.widget.RadioButton;
|
|
import android.widget.ToggleButton;
|
|
import androidx.annotation.BoolRes;
|
|
import androidx.annotation.IdRes;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.biometric.ErrorUtils$$ExternalSyntheticOutline0;
|
|
import androidx.core.view.AccessibilityDelegateCompat;
|
|
import androidx.core.view.ViewCompat;
|
|
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
|
|
import com.google.android.material.R;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashSet;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes7.dex */
|
|
public class MaterialButtonToggleGroup extends MaterialButtonGroup {
|
|
private static final int DEF_STYLE_RES = R.style.Widget_MaterialComponents_MaterialButtonToggleGroup;
|
|
private static final String LOG_TAG = "MButtonToggleGroup";
|
|
private Set<Integer> checkedIds;
|
|
|
|
@IdRes
|
|
private final int defaultCheckId;
|
|
private final LinkedHashSet<OnButtonCheckedListener> onButtonCheckedListeners;
|
|
private boolean selectionRequired;
|
|
private boolean singleSelection;
|
|
private boolean skipCheckedStateTracker;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public interface OnButtonCheckedListener {
|
|
void onButtonChecked(MaterialButtonToggleGroup materialButtonToggleGroup, @IdRes int i, boolean z);
|
|
}
|
|
|
|
/* 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(@androidx.annotation.NonNull android.content.Context r7, @androidx.annotation.Nullable android.util.AttributeSet r8, int r9) {
|
|
/*
|
|
r6 = this;
|
|
int r4 = com.google.android.material.button.MaterialButtonToggleGroup.DEF_STYLE_RES
|
|
android.content.Context r7 = com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap(r7, r8, r9, r4)
|
|
r6.<init>(r7, r8, r9)
|
|
java.util.LinkedHashSet r7 = new java.util.LinkedHashSet
|
|
r7.<init>()
|
|
r6.onButtonCheckedListeners = r7
|
|
r7 = 0
|
|
r6.skipCheckedStateTracker = r7
|
|
java.util.HashSet r0 = new java.util.HashSet
|
|
r0.<init>()
|
|
r6.checkedIds = r0
|
|
android.content.Context r0 = r6.getContext()
|
|
int[] r2 = com.google.android.material.R.styleable.MaterialButtonToggleGroup
|
|
int[] r5 = new int[r7]
|
|
r1 = r8
|
|
r3 = r9
|
|
android.content.res.TypedArray r8 = com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(r0, r1, r2, r3, r4, r5)
|
|
int r9 = com.google.android.material.R.styleable.MaterialButtonToggleGroup_singleSelection
|
|
boolean r9 = r8.getBoolean(r9, r7)
|
|
r6.setSingleSelection(r9)
|
|
int r9 = com.google.android.material.R.styleable.MaterialButtonToggleGroup_checkedButton
|
|
r0 = -1
|
|
int r9 = r8.getResourceId(r9, r0)
|
|
r6.defaultCheckId = r9
|
|
int r9 = com.google.android.material.R.styleable.MaterialButtonToggleGroup_selectionRequired
|
|
boolean r7 = r8.getBoolean(r9, r7)
|
|
r6.selectionRequired = r7
|
|
com.google.android.material.shape.StateListCornerSize r7 = r6.innerCornerSize
|
|
if (r7 != 0) goto L52
|
|
com.google.android.material.shape.AbsoluteCornerSize r7 = new com.google.android.material.shape.AbsoluteCornerSize
|
|
r9 = 0
|
|
r7.<init>(r9)
|
|
com.google.android.material.shape.StateListCornerSize r7 = com.google.android.material.shape.StateListCornerSize.create(r7)
|
|
r6.innerCornerSize = r7
|
|
L52:
|
|
int r7 = com.google.android.material.R.styleable.MaterialButtonToggleGroup_android_enabled
|
|
r9 = 1
|
|
boolean r7 = r8.getBoolean(r7, r9)
|
|
r6.setEnabled(r7)
|
|
r8.recycle()
|
|
r6.setImportantForAccessibility(r9)
|
|
return
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.button.MaterialButtonToggleGroup.<init>(android.content.Context, android.util.AttributeSet, int):void");
|
|
}
|
|
|
|
private void checkInternal(@IdRes int i, boolean z) {
|
|
if (i == -1) {
|
|
ErrorUtils$$ExternalSyntheticOutline0.m(i, "Button ID is not valid: ", LOG_TAG);
|
|
return;
|
|
}
|
|
HashSet hashSet = new HashSet(this.checkedIds);
|
|
if (z && !hashSet.contains(Integer.valueOf(i))) {
|
|
if (this.singleSelection && !hashSet.isEmpty()) {
|
|
hashSet.clear();
|
|
}
|
|
hashSet.add(Integer.valueOf(i));
|
|
} else {
|
|
if (z || !hashSet.contains(Integer.valueOf(i))) {
|
|
return;
|
|
}
|
|
if (!this.selectionRequired || hashSet.size() > 1) {
|
|
hashSet.remove(Integer.valueOf(i));
|
|
}
|
|
}
|
|
updateCheckedIds(hashSet);
|
|
}
|
|
|
|
private void dispatchOnButtonChecked(@IdRes int i, boolean z) {
|
|
Iterator<OnButtonCheckedListener> it2 = this.onButtonCheckedListeners.iterator();
|
|
while (it2.hasNext()) {
|
|
it2.next().onButtonChecked(this, i, z);
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
private String getChildrenA11yClassName() {
|
|
return (this.singleSelection ? RadioButton.class : ToggleButton.class).getName();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public int getIndexWithinVisibleButtons(@Nullable View view) {
|
|
if (!(view instanceof MaterialButton)) {
|
|
return -1;
|
|
}
|
|
int i = 0;
|
|
for (int i2 = 0; i2 < getChildCount(); i2++) {
|
|
if (getChildAt(i2) == view) {
|
|
return i;
|
|
}
|
|
if ((getChildAt(i2) instanceof MaterialButton) && isChildVisible(i2)) {
|
|
i++;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
private int getVisibleButtonCount() {
|
|
int i = 0;
|
|
for (int i2 = 0; i2 < getChildCount(); i2++) {
|
|
if ((getChildAt(i2) instanceof MaterialButton) && isChildVisible(i2)) {
|
|
i++;
|
|
}
|
|
}
|
|
return i;
|
|
}
|
|
|
|
private boolean isChildVisible(int i) {
|
|
return getChildAt(i).getVisibility() != 8;
|
|
}
|
|
|
|
private void setCheckedStateForView(@IdRes int i, boolean z) {
|
|
View findViewById = findViewById(i);
|
|
if (findViewById instanceof MaterialButton) {
|
|
this.skipCheckedStateTracker = true;
|
|
((MaterialButton) findViewById).setChecked(z);
|
|
this.skipCheckedStateTracker = false;
|
|
}
|
|
}
|
|
|
|
private void setupButtonChild(@NonNull MaterialButton materialButton) {
|
|
materialButton.setMaxLines(1);
|
|
materialButton.setEllipsize(TextUtils.TruncateAt.END);
|
|
materialButton.setCheckable(true);
|
|
materialButton.setA11yClassName(getChildrenA11yClassName());
|
|
}
|
|
|
|
private void updateCheckedIds(Set<Integer> set) {
|
|
Set<Integer> set2 = this.checkedIds;
|
|
this.checkedIds = new HashSet(set);
|
|
for (int i = 0; i < getChildCount(); i++) {
|
|
int id = getChildButton(i).getId();
|
|
setCheckedStateForView(id, set.contains(Integer.valueOf(id)));
|
|
if (set2.contains(Integer.valueOf(id)) != set.contains(Integer.valueOf(id))) {
|
|
dispatchOnButtonChecked(id, set.contains(Integer.valueOf(id)));
|
|
}
|
|
}
|
|
invalidate();
|
|
}
|
|
|
|
private void updateChildrenA11yClassName() {
|
|
String childrenA11yClassName = getChildrenA11yClassName();
|
|
for (int i = 0; i < getChildCount(); i++) {
|
|
getChildButton(i).setA11yClassName(childrenA11yClassName);
|
|
}
|
|
}
|
|
|
|
public void addOnButtonCheckedListener(@NonNull OnButtonCheckedListener onButtonCheckedListener) {
|
|
this.onButtonCheckedListeners.add(onButtonCheckedListener);
|
|
}
|
|
|
|
@Override // com.google.android.material.button.MaterialButtonGroup, android.view.ViewGroup
|
|
public void addView(@NonNull View view, int i, @NonNull ViewGroup.LayoutParams layoutParams) {
|
|
if (!(view instanceof MaterialButton)) {
|
|
Log.e(LOG_TAG, "Child views must be of type MaterialButton.");
|
|
return;
|
|
}
|
|
super.addView(view, i, layoutParams);
|
|
MaterialButton materialButton = (MaterialButton) view;
|
|
setupButtonChild(materialButton);
|
|
checkInternal(materialButton.getId(), materialButton.isChecked());
|
|
ViewCompat.setAccessibilityDelegate(materialButton, new AccessibilityDelegateCompat() { // from class: com.google.android.material.button.MaterialButtonToggleGroup.1
|
|
@Override // androidx.core.view.AccessibilityDelegateCompat
|
|
public void onInitializeAccessibilityNodeInfo(View view2, @NonNull AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
|
|
super.onInitializeAccessibilityNodeInfo(view2, accessibilityNodeInfoCompat);
|
|
accessibilityNodeInfoCompat.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(0, 1, MaterialButtonToggleGroup.this.getIndexWithinVisibleButtons(view2), 1, false, ((MaterialButton) view2).isChecked()));
|
|
}
|
|
});
|
|
}
|
|
|
|
public void check(@IdRes int i) {
|
|
checkInternal(i, true);
|
|
}
|
|
|
|
public void clearChecked() {
|
|
updateCheckedIds(new HashSet());
|
|
}
|
|
|
|
public void clearOnButtonCheckedListeners() {
|
|
this.onButtonCheckedListeners.clear();
|
|
}
|
|
|
|
@IdRes
|
|
public int getCheckedButtonId() {
|
|
if (!this.singleSelection || this.checkedIds.isEmpty()) {
|
|
return -1;
|
|
}
|
|
return this.checkedIds.iterator().next().intValue();
|
|
}
|
|
|
|
@NonNull
|
|
public List<Integer> getCheckedButtonIds() {
|
|
ArrayList arrayList = new ArrayList();
|
|
for (int i = 0; i < getChildCount(); i++) {
|
|
int id = getChildButton(i).getId();
|
|
if (this.checkedIds.contains(Integer.valueOf(id))) {
|
|
arrayList.add(Integer.valueOf(id));
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
public boolean isSelectionRequired() {
|
|
return this.selectionRequired;
|
|
}
|
|
|
|
public boolean isSingleSelection() {
|
|
return this.singleSelection;
|
|
}
|
|
|
|
public void onButtonCheckedStateChanged(@NonNull MaterialButton materialButton, boolean z) {
|
|
if (this.skipCheckedStateTracker) {
|
|
return;
|
|
}
|
|
checkInternal(materialButton.getId(), z);
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onFinishInflate() {
|
|
super.onFinishInflate();
|
|
int i = this.defaultCheckId;
|
|
if (i != -1) {
|
|
updateCheckedIds(Collections.singleton(Integer.valueOf(i)));
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo accessibilityNodeInfo) {
|
|
super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
|
|
AccessibilityNodeInfoCompat.wrap(accessibilityNodeInfo).setCollectionInfo(AccessibilityNodeInfoCompat.CollectionInfoCompat.obtain(1, getVisibleButtonCount(), false, isSingleSelection() ? 1 : 2));
|
|
}
|
|
|
|
public void removeOnButtonCheckedListener(@NonNull OnButtonCheckedListener onButtonCheckedListener) {
|
|
this.onButtonCheckedListeners.remove(onButtonCheckedListener);
|
|
}
|
|
|
|
public void setSelectionRequired(boolean z) {
|
|
this.selectionRequired = z;
|
|
}
|
|
|
|
public void setSingleSelection(boolean z) {
|
|
if (this.singleSelection != z) {
|
|
this.singleSelection = z;
|
|
clearChecked();
|
|
}
|
|
updateChildrenA11yClassName();
|
|
}
|
|
|
|
public void uncheck(@IdRes int i) {
|
|
checkInternal(i, false);
|
|
}
|
|
|
|
public void setSingleSelection(@BoolRes int i) {
|
|
setSingleSelection(getResources().getBoolean(i));
|
|
}
|
|
|
|
public MaterialButtonToggleGroup(@NonNull Context context, @Nullable AttributeSet attributeSet) {
|
|
this(context, attributeSet, R.attr.materialButtonToggleGroupStyle);
|
|
}
|
|
|
|
public MaterialButtonToggleGroup(@NonNull Context context) {
|
|
this(context, null);
|
|
}
|
|
}
|