jimu-decompiled/sources/androidx/appcompat/view/menu/ListMenuItemView.java
2025-05-13 19:24:51 +02:00

286 lines
8.9 KiB
Java

package androidx.appcompat.view.menu;
import android.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import androidx.appcompat.R$attr;
import androidx.appcompat.R$id;
import androidx.appcompat.R$layout;
import androidx.appcompat.R$styleable;
import androidx.appcompat.view.menu.MenuView;
import androidx.appcompat.widget.TintTypedArray;
import androidx.core.view.ViewCompat;
/* loaded from: classes.dex */
public class ListMenuItemView extends LinearLayout implements MenuView.ItemView, AbsListView.SelectionBoundsAdjuster {
private MenuItemImpl a;
private ImageView b;
private RadioButton c;
private TextView d;
private CheckBox e;
private TextView f;
private ImageView g;
private ImageView h;
private LinearLayout i;
private Drawable j;
private int k;
private Context l;
private boolean m;
private Drawable n;
private boolean o;
private LayoutInflater p;
private boolean q;
public ListMenuItemView(Context context, AttributeSet attributeSet) {
this(context, attributeSet, R$attr.listMenuViewStyle);
}
private void b() {
this.e = (CheckBox) getInflater().inflate(R$layout.abc_list_menu_item_checkbox, (ViewGroup) this, false);
a(this.e);
}
private void c() {
this.b = (ImageView) getInflater().inflate(R$layout.abc_list_menu_item_icon, (ViewGroup) this, false);
a(this.b, 0);
}
private void d() {
this.c = (RadioButton) getInflater().inflate(R$layout.abc_list_menu_item_radio, (ViewGroup) this, false);
a(this.c);
}
private LayoutInflater getInflater() {
if (this.p == null) {
this.p = LayoutInflater.from(getContext());
}
return this.p;
}
private void setSubMenuArrowVisible(boolean z) {
ImageView imageView = this.g;
if (imageView != null) {
imageView.setVisibility(z ? 0 : 8);
}
}
@Override // androidx.appcompat.view.menu.MenuView.ItemView
public void a(MenuItemImpl menuItemImpl, int i) {
this.a = menuItemImpl;
setVisibility(menuItemImpl.isVisible() ? 0 : 8);
setTitle(menuItemImpl.a(this));
setCheckable(menuItemImpl.isCheckable());
a(menuItemImpl.m(), menuItemImpl.d());
setIcon(menuItemImpl.getIcon());
setEnabled(menuItemImpl.isEnabled());
setSubMenuArrowVisible(menuItemImpl.hasSubMenu());
setContentDescription(menuItemImpl.getContentDescription());
}
@Override // androidx.appcompat.view.menu.MenuView.ItemView
public boolean a() {
return false;
}
@Override // android.widget.AbsListView.SelectionBoundsAdjuster
public void adjustListItemSelectionBounds(Rect rect) {
ImageView imageView = this.h;
if (imageView == null || imageView.getVisibility() != 0) {
return;
}
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) this.h.getLayoutParams();
rect.top += this.h.getHeight() + layoutParams.topMargin + layoutParams.bottomMargin;
}
@Override // androidx.appcompat.view.menu.MenuView.ItemView
public MenuItemImpl getItemData() {
return this.a;
}
@Override // android.view.View
protected void onFinishInflate() {
super.onFinishInflate();
ViewCompat.a(this, this.j);
this.d = (TextView) findViewById(R$id.title);
int i = this.k;
if (i != -1) {
this.d.setTextAppearance(this.l, i);
}
this.f = (TextView) findViewById(R$id.shortcut);
this.g = (ImageView) findViewById(R$id.submenuarrow);
ImageView imageView = this.g;
if (imageView != null) {
imageView.setImageDrawable(this.n);
}
this.h = (ImageView) findViewById(R$id.group_divider);
this.i = (LinearLayout) findViewById(R$id.content);
}
@Override // android.widget.LinearLayout, android.view.View
protected void onMeasure(int i, int i2) {
if (this.b != null && this.m) {
ViewGroup.LayoutParams layoutParams = getLayoutParams();
LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) this.b.getLayoutParams();
if (layoutParams.height > 0 && layoutParams2.width <= 0) {
layoutParams2.width = layoutParams.height;
}
}
super.onMeasure(i, i2);
}
public void setCheckable(boolean z) {
CompoundButton compoundButton;
CompoundButton compoundButton2;
if (!z && this.c == null && this.e == null) {
return;
}
if (this.a.i()) {
if (this.c == null) {
d();
}
compoundButton = this.c;
compoundButton2 = this.e;
} else {
if (this.e == null) {
b();
}
compoundButton = this.e;
compoundButton2 = this.c;
}
if (z) {
compoundButton.setChecked(this.a.isChecked());
if (compoundButton.getVisibility() != 0) {
compoundButton.setVisibility(0);
}
if (compoundButton2 == null || compoundButton2.getVisibility() == 8) {
return;
}
compoundButton2.setVisibility(8);
return;
}
CheckBox checkBox = this.e;
if (checkBox != null) {
checkBox.setVisibility(8);
}
RadioButton radioButton = this.c;
if (radioButton != null) {
radioButton.setVisibility(8);
}
}
public void setChecked(boolean z) {
CompoundButton compoundButton;
if (this.a.i()) {
if (this.c == null) {
d();
}
compoundButton = this.c;
} else {
if (this.e == null) {
b();
}
compoundButton = this.e;
}
compoundButton.setChecked(z);
}
public void setForceShowIcon(boolean z) {
this.q = z;
this.m = z;
}
public void setGroupDividerEnabled(boolean z) {
ImageView imageView = this.h;
if (imageView != null) {
imageView.setVisibility((this.o || !z) ? 8 : 0);
}
}
public void setIcon(Drawable drawable) {
boolean z = this.a.l() || this.q;
if (z || this.m) {
if (this.b == null && drawable == null && !this.m) {
return;
}
if (this.b == null) {
c();
}
if (drawable == null && !this.m) {
this.b.setVisibility(8);
return;
}
ImageView imageView = this.b;
if (!z) {
drawable = null;
}
imageView.setImageDrawable(drawable);
if (this.b.getVisibility() != 0) {
this.b.setVisibility(0);
}
}
}
public void setTitle(CharSequence charSequence) {
if (charSequence == null) {
if (this.d.getVisibility() != 8) {
this.d.setVisibility(8);
}
} else {
this.d.setText(charSequence);
if (this.d.getVisibility() != 0) {
this.d.setVisibility(0);
}
}
}
public ListMenuItemView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet);
TintTypedArray a = TintTypedArray.a(getContext(), attributeSet, R$styleable.MenuView, i, 0);
this.j = a.b(R$styleable.MenuView_android_itemBackground);
this.k = a.g(R$styleable.MenuView_android_itemTextAppearance, -1);
this.m = a.a(R$styleable.MenuView_preserveIconSpacing, false);
this.l = context;
this.n = a.b(R$styleable.MenuView_subMenuArrow);
TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(null, new int[]{R.attr.divider}, R$attr.dropDownListViewStyle, 0);
this.o = obtainStyledAttributes.hasValue(0);
a.a();
obtainStyledAttributes.recycle();
}
private void a(View view) {
a(view, -1);
}
private void a(View view, int i) {
LinearLayout linearLayout = this.i;
if (linearLayout != null) {
linearLayout.addView(view, i);
} else {
addView(view, i);
}
}
public void a(boolean z, char c) {
int i = (z && this.a.m()) ? 0 : 8;
if (i == 0) {
this.f.setText(this.a.e());
}
if (this.f.getVisibility() != i) {
this.f.setVisibility(i);
}
}
}