228 lines
8.1 KiB
Java
228 lines
8.1 KiB
Java
package com.google.android.material.internal;
|
|
|
|
import android.R;
|
|
import android.content.Context;
|
|
import android.content.res.ColorStateList;
|
|
import android.graphics.drawable.ColorDrawable;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.graphics.drawable.StateListDrawable;
|
|
import android.util.AttributeSet;
|
|
import android.util.TypedValue;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewStub;
|
|
import android.widget.CheckedTextView;
|
|
import android.widget.FrameLayout;
|
|
import androidx.appcompat.R$attr;
|
|
import androidx.appcompat.view.menu.MenuItemImpl;
|
|
import androidx.appcompat.view.menu.MenuView;
|
|
import androidx.appcompat.widget.LinearLayoutCompat;
|
|
import androidx.appcompat.widget.TooltipCompat;
|
|
import androidx.core.content.res.ResourcesCompat;
|
|
import androidx.core.graphics.drawable.DrawableCompat;
|
|
import androidx.core.view.AccessibilityDelegateCompat;
|
|
import androidx.core.view.ViewCompat;
|
|
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
|
|
import androidx.core.widget.TextViewCompat;
|
|
import com.google.android.material.R$dimen;
|
|
import com.google.android.material.R$drawable;
|
|
import com.google.android.material.R$id;
|
|
import com.google.android.material.R$layout;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class NavigationMenuItemView extends ForegroundLinearLayout implements MenuView.ItemView {
|
|
private static final int[] G = {R.attr.state_checked};
|
|
private FrameLayout A;
|
|
private MenuItemImpl B;
|
|
private ColorStateList C;
|
|
private boolean D;
|
|
private Drawable E;
|
|
private final AccessibilityDelegateCompat F;
|
|
private final int v;
|
|
private boolean x;
|
|
boolean y;
|
|
private final CheckedTextView z;
|
|
|
|
public NavigationMenuItemView(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
private void d() {
|
|
if (f()) {
|
|
this.z.setVisibility(8);
|
|
FrameLayout frameLayout = this.A;
|
|
if (frameLayout != null) {
|
|
LinearLayoutCompat.LayoutParams layoutParams = (LinearLayoutCompat.LayoutParams) frameLayout.getLayoutParams();
|
|
((ViewGroup.MarginLayoutParams) layoutParams).width = -1;
|
|
this.A.setLayoutParams(layoutParams);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
this.z.setVisibility(0);
|
|
FrameLayout frameLayout2 = this.A;
|
|
if (frameLayout2 != null) {
|
|
LinearLayoutCompat.LayoutParams layoutParams2 = (LinearLayoutCompat.LayoutParams) frameLayout2.getLayoutParams();
|
|
((ViewGroup.MarginLayoutParams) layoutParams2).width = -2;
|
|
this.A.setLayoutParams(layoutParams2);
|
|
}
|
|
}
|
|
|
|
private StateListDrawable e() {
|
|
TypedValue typedValue = new TypedValue();
|
|
if (!getContext().getTheme().resolveAttribute(R$attr.colorControlHighlight, typedValue, true)) {
|
|
return null;
|
|
}
|
|
StateListDrawable stateListDrawable = new StateListDrawable();
|
|
stateListDrawable.addState(G, new ColorDrawable(typedValue.data));
|
|
stateListDrawable.addState(ViewGroup.EMPTY_STATE_SET, new ColorDrawable(0));
|
|
return stateListDrawable;
|
|
}
|
|
|
|
private boolean f() {
|
|
return this.B.getTitle() == null && this.B.getIcon() == null && this.B.getActionView() != null;
|
|
}
|
|
|
|
private void setActionView(View view) {
|
|
if (view != null) {
|
|
if (this.A == null) {
|
|
this.A = (FrameLayout) ((ViewStub) findViewById(R$id.design_menu_item_action_area_stub)).inflate();
|
|
}
|
|
this.A.removeAllViews();
|
|
this.A.addView(view);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.MenuView.ItemView
|
|
public void a(MenuItemImpl menuItemImpl, int i) {
|
|
this.B = menuItemImpl;
|
|
setVisibility(menuItemImpl.isVisible() ? 0 : 8);
|
|
if (getBackground() == null) {
|
|
ViewCompat.a(this, e());
|
|
}
|
|
setCheckable(menuItemImpl.isCheckable());
|
|
setChecked(menuItemImpl.isChecked());
|
|
setEnabled(menuItemImpl.isEnabled());
|
|
setTitle(menuItemImpl.getTitle());
|
|
setIcon(menuItemImpl.getIcon());
|
|
setActionView(menuItemImpl.getActionView());
|
|
setContentDescription(menuItemImpl.getContentDescription());
|
|
TooltipCompat.a(this, menuItemImpl.getTooltipText());
|
|
d();
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.MenuView.ItemView
|
|
public boolean a() {
|
|
return false;
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.MenuView.ItemView
|
|
public MenuItemImpl getItemData() {
|
|
return this.B;
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
protected int[] onCreateDrawableState(int i) {
|
|
int[] onCreateDrawableState = super.onCreateDrawableState(i + 1);
|
|
MenuItemImpl menuItemImpl = this.B;
|
|
if (menuItemImpl != null && menuItemImpl.isCheckable() && this.B.isChecked()) {
|
|
ViewGroup.mergeDrawableStates(onCreateDrawableState, G);
|
|
}
|
|
return onCreateDrawableState;
|
|
}
|
|
|
|
public void setCheckable(boolean z) {
|
|
refreshDrawableState();
|
|
if (this.y != z) {
|
|
this.y = z;
|
|
this.F.a(this.z, 2048);
|
|
}
|
|
}
|
|
|
|
public void setChecked(boolean z) {
|
|
refreshDrawableState();
|
|
this.z.setChecked(z);
|
|
}
|
|
|
|
public void setHorizontalPadding(int i) {
|
|
setPadding(i, 0, i, 0);
|
|
}
|
|
|
|
public void setIcon(Drawable drawable) {
|
|
if (drawable != null) {
|
|
if (this.D) {
|
|
Drawable.ConstantState constantState = drawable.getConstantState();
|
|
if (constantState != null) {
|
|
drawable = constantState.newDrawable();
|
|
}
|
|
drawable = DrawableCompat.h(drawable).mutate();
|
|
DrawableCompat.a(drawable, this.C);
|
|
}
|
|
int i = this.v;
|
|
drawable.setBounds(0, 0, i, i);
|
|
} else if (this.x) {
|
|
if (this.E == null) {
|
|
this.E = ResourcesCompat.a(getResources(), R$drawable.navigation_empty_icon, getContext().getTheme());
|
|
Drawable drawable2 = this.E;
|
|
if (drawable2 != null) {
|
|
int i2 = this.v;
|
|
drawable2.setBounds(0, 0, i2, i2);
|
|
}
|
|
}
|
|
drawable = this.E;
|
|
}
|
|
TextViewCompat.a(this.z, drawable, null, null, null);
|
|
}
|
|
|
|
public void setIconPadding(int i) {
|
|
this.z.setCompoundDrawablePadding(i);
|
|
}
|
|
|
|
void setIconTintList(ColorStateList colorStateList) {
|
|
this.C = colorStateList;
|
|
this.D = this.C != null;
|
|
MenuItemImpl menuItemImpl = this.B;
|
|
if (menuItemImpl != null) {
|
|
setIcon(menuItemImpl.getIcon());
|
|
}
|
|
}
|
|
|
|
public void setNeedsEmptyIcon(boolean z) {
|
|
this.x = z;
|
|
}
|
|
|
|
public void setTextAppearance(int i) {
|
|
TextViewCompat.d(this.z, i);
|
|
}
|
|
|
|
public void setTextColor(ColorStateList colorStateList) {
|
|
this.z.setTextColor(colorStateList);
|
|
}
|
|
|
|
public void setTitle(CharSequence charSequence) {
|
|
this.z.setText(charSequence);
|
|
}
|
|
|
|
public NavigationMenuItemView(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, 0);
|
|
}
|
|
|
|
public NavigationMenuItemView(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
this.F = new AccessibilityDelegateCompat() { // from class: com.google.android.material.internal.NavigationMenuItemView.1
|
|
@Override // androidx.core.view.AccessibilityDelegateCompat
|
|
public void a(View view, AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
|
|
super.a(view, accessibilityNodeInfoCompat);
|
|
accessibilityNodeInfoCompat.a(NavigationMenuItemView.this.y);
|
|
}
|
|
};
|
|
setOrientation(0);
|
|
LayoutInflater.from(context).inflate(R$layout.design_navigation_menu_item, (ViewGroup) this, true);
|
|
this.v = context.getResources().getDimensionPixelSize(R$dimen.design_navigation_icon_size);
|
|
this.z = (CheckedTextView) findViewById(R$id.design_menu_item_text);
|
|
this.z.setDuplicateParentStateEnabled(true);
|
|
ViewCompat.a(this.z, this.F);
|
|
}
|
|
}
|