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.view.menu.j;
import androidx.appcompat.view.menu.p;
import androidx.appcompat.widget.g0;
import androidx.appcompat.widget.v0;
import androidx.core.widget.i;
import c.f.l.t;

/* JADX INFO: loaded from: classes.dex */
public class NavigationMenuItemView extends c implements p.a {
    private static final int[] J = {R.attr.state_checked};
    private boolean A;
    boolean B;
    private final CheckedTextView C;
    private FrameLayout D;
    private j E;
    private ColorStateList F;
    private boolean G;
    private Drawable H;
    private final c.f.l.a I;
    private final int z;

    class a extends c.f.l.a {
        a() {
        }

        @Override // c.f.l.a
        public void g(View view, c.f.l.c0.d dVar) {
            super.g(view, dVar);
            dVar.J(NavigationMenuItemView.this.B);
        }
    }

    public NavigationMenuItemView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    private void B() {
        if (D()) {
            this.C.setVisibility(8);
            FrameLayout frameLayout = this.D;
            if (frameLayout != null) {
                g0.a aVar = (g0.a) frameLayout.getLayoutParams();
                ((ViewGroup.MarginLayoutParams) aVar).width = -1;
                this.D.setLayoutParams(aVar);
                return;
            }
            return;
        }
        this.C.setVisibility(0);
        FrameLayout frameLayout2 = this.D;
        if (frameLayout2 != null) {
            g0.a aVar2 = (g0.a) frameLayout2.getLayoutParams();
            ((ViewGroup.MarginLayoutParams) aVar2).width = -2;
            this.D.setLayoutParams(aVar2);
        }
    }

    private StateListDrawable C() {
        TypedValue typedValue = new TypedValue();
        if (!getContext().getTheme().resolveAttribute(c.a.a.colorControlHighlight, typedValue, true)) {
            return null;
        }
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(J, new ColorDrawable(typedValue.data));
        stateListDrawable.addState(ViewGroup.EMPTY_STATE_SET, new ColorDrawable(0));
        return stateListDrawable;
    }

    private boolean D() {
        return this.E.getTitle() == null && this.E.getIcon() == null && this.E.getActionView() != null;
    }

    private void setActionView(View view) {
        if (view != null) {
            if (this.D == null) {
                this.D = (FrameLayout) ((ViewStub) findViewById(d.c.a.a.e.design_menu_item_action_area_stub)).inflate();
            }
            this.D.removeAllViews();
            this.D.addView(view);
        }
    }

    @Override // androidx.appcompat.view.menu.p.a
    public boolean d() {
        return false;
    }

    @Override // androidx.appcompat.view.menu.p.a
    public void e(j jVar, int i2) {
        this.E = jVar;
        setVisibility(jVar.isVisible() ? 0 : 8);
        if (getBackground() == null) {
            t.X(this, C());
        }
        setCheckable(jVar.isCheckable());
        setChecked(jVar.isChecked());
        setEnabled(jVar.isEnabled());
        setTitle(jVar.getTitle());
        setIcon(jVar.getIcon());
        setActionView(jVar.getActionView());
        setContentDescription(jVar.getContentDescription());
        v0.a(this, jVar.getTooltipText());
        B();
    }

    @Override // androidx.appcompat.view.menu.p.a
    public j getItemData() {
        return this.E;
    }

    @Override // android.view.ViewGroup, android.view.View
    protected int[] onCreateDrawableState(int i2) {
        int[] iArrOnCreateDrawableState = super.onCreateDrawableState(i2 + 1);
        j jVar = this.E;
        if (jVar != null && jVar.isCheckable() && this.E.isChecked()) {
            ViewGroup.mergeDrawableStates(iArrOnCreateDrawableState, J);
        }
        return iArrOnCreateDrawableState;
    }

    public void setCheckable(boolean z) {
        refreshDrawableState();
        if (this.B != z) {
            this.B = z;
            this.I.l(this.C, 2048);
        }
    }

    public void setChecked(boolean z) {
        refreshDrawableState();
        this.C.setChecked(z);
    }

    public void setHorizontalPadding(int i2) {
        setPadding(i2, 0, i2, 0);
    }

    public void setIcon(Drawable drawable) {
        if (drawable != null) {
            if (this.G) {
                Drawable.ConstantState constantState = drawable.getConstantState();
                if (constantState != null) {
                    drawable = constantState.newDrawable();
                }
                drawable = androidx.core.graphics.drawable.a.q(drawable).mutate();
                androidx.core.graphics.drawable.a.o(drawable, this.F);
            }
            int i2 = this.z;
            drawable.setBounds(0, 0, i2, i2);
        } else if (this.A) {
            if (this.H == null) {
                Drawable drawableA = c.f.d.c.f.a(getResources(), d.c.a.a.d.navigation_empty_icon, getContext().getTheme());
                this.H = drawableA;
                if (drawableA != null) {
                    int i3 = this.z;
                    drawableA.setBounds(0, 0, i3, i3);
                }
            }
            drawable = this.H;
        }
        i.f(this.C, drawable, null, null, null);
    }

    public void setIconPadding(int i2) {
        this.C.setCompoundDrawablePadding(i2);
    }

    void setIconTintList(ColorStateList colorStateList) {
        this.F = colorStateList;
        this.G = colorStateList != null;
        j jVar = this.E;
        if (jVar != null) {
            setIcon(jVar.getIcon());
        }
    }

    public void setNeedsEmptyIcon(boolean z) {
        this.A = z;
    }

    public void setTextAppearance(int i2) {
        i.k(this.C, i2);
    }

    public void setTextColor(ColorStateList colorStateList) {
        this.C.setTextColor(colorStateList);
    }

    public void setTitle(CharSequence charSequence) {
        this.C.setText(charSequence);
    }

    public NavigationMenuItemView(Context context, AttributeSet attributeSet, int i2) {
        super(context, attributeSet, i2);
        this.I = new a();
        setOrientation(0);
        LayoutInflater.from(context).inflate(d.c.a.a.g.design_navigation_menu_item, (ViewGroup) this, true);
        this.z = context.getResources().getDimensionPixelSize(d.c.a.a.c.design_navigation_icon_size);
        CheckedTextView checkedTextView = (CheckedTextView) findViewById(d.c.a.a.e.design_menu_item_text);
        this.C = checkedTextView;
        checkedTextView.setDuplicateParentStateEnabled(true);
        t.W(this.C, this.I);
    }
}
