package android.support.v7.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.support.v7.view.menu.p;
import android.support.v7.widget.t0;
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;

/* JADX INFO: loaded from: classes.dex */
public class ListMenuItemView extends LinearLayout implements p.a, AbsListView.SelectionBoundsAdjuster {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private j f837b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private ImageView f838c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private RadioButton f839d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private TextView f840e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private CheckBox f841f;
    private TextView g;
    private ImageView h;
    private ImageView i;
    private LinearLayout j;
    private Drawable k;
    private int l;
    private Context m;
    private boolean n;
    private Drawable o;
    private boolean p;
    private LayoutInflater q;
    private boolean r;

    public ListMenuItemView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, a.b.d.a.a.listMenuViewStyle);
    }

    private void a(View view) {
        c(view, -1);
    }

    private void c(View view, int i) {
        LinearLayout linearLayout = this.j;
        if (linearLayout != null) {
            linearLayout.addView(view, i);
        } else {
            addView(view, i);
        }
    }

    private void e() {
        CheckBox checkBox = (CheckBox) getInflater().inflate(a.b.d.a.g.abc_list_menu_item_checkbox, (ViewGroup) this, false);
        this.f841f = checkBox;
        a(checkBox);
    }

    private void f() {
        ImageView imageView = (ImageView) getInflater().inflate(a.b.d.a.g.abc_list_menu_item_icon, (ViewGroup) this, false);
        this.f838c = imageView;
        c(imageView, 0);
    }

    private void g() {
        RadioButton radioButton = (RadioButton) getInflater().inflate(a.b.d.a.g.abc_list_menu_item_radio, (ViewGroup) this, false);
        this.f839d = radioButton;
        a(radioButton);
    }

    private LayoutInflater getInflater() {
        if (this.q == null) {
            this.q = LayoutInflater.from(getContext());
        }
        return this.q;
    }

    private void setSubMenuArrowVisible(boolean z) {
        ImageView imageView = this.h;
        if (imageView != null) {
            imageView.setVisibility(z ? 0 : 8);
        }
    }

    @Override // android.widget.AbsListView.SelectionBoundsAdjuster
    public void adjustListItemSelectionBounds(Rect rect) {
        ImageView imageView = this.i;
        if (imageView == null || imageView.getVisibility() != 0) {
            return;
        }
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) this.i.getLayoutParams();
        rect.top += this.i.getHeight() + layoutParams.topMargin + layoutParams.bottomMargin;
    }

    @Override // android.support.v7.view.menu.p.a
    public void b(j jVar, int i) {
        this.f837b = jVar;
        setVisibility(jVar.isVisible() ? 0 : 8);
        setTitle(jVar.i(this));
        setCheckable(jVar.isCheckable());
        h(jVar.A(), jVar.g());
        setIcon(jVar.getIcon());
        setEnabled(jVar.isEnabled());
        setSubMenuArrowVisible(jVar.hasSubMenu());
        setContentDescription(jVar.getContentDescription());
    }

    @Override // android.support.v7.view.menu.p.a
    public boolean d() {
        return false;
    }

    @Override // android.support.v7.view.menu.p.a
    public j getItemData() {
        return this.f837b;
    }

    public void h(boolean z, char c2) {
        int i = (z && this.f837b.A()) ? 0 : 8;
        if (i == 0) {
            this.g.setText(this.f837b.h());
        }
        if (this.g.getVisibility() != i) {
            this.g.setVisibility(i);
        }
    }

    @Override // android.view.View
    protected void onFinishInflate() {
        super.onFinishInflate();
        a.b.c.g.p.t(this, this.k);
        TextView textView = (TextView) findViewById(a.b.d.a.f.title);
        this.f840e = textView;
        int i = this.l;
        if (i != -1) {
            textView.setTextAppearance(this.m, i);
        }
        this.g = (TextView) findViewById(a.b.d.a.f.shortcut);
        ImageView imageView = (ImageView) findViewById(a.b.d.a.f.submenuarrow);
        this.h = imageView;
        if (imageView != null) {
            imageView.setImageDrawable(this.o);
        }
        this.i = (ImageView) findViewById(a.b.d.a.f.group_divider);
        this.j = (LinearLayout) findViewById(a.b.d.a.f.content);
    }

    @Override // android.widget.LinearLayout, android.view.View
    protected void onMeasure(int i, int i2) {
        if (this.f838c != null && this.n) {
            ViewGroup.LayoutParams layoutParams = getLayoutParams();
            LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) this.f838c.getLayoutParams();
            int i3 = layoutParams.height;
            if (i3 > 0 && layoutParams2.width <= 0) {
                layoutParams2.width = i3;
            }
        }
        super.onMeasure(i, i2);
    }

    public void setCheckable(boolean z) {
        CompoundButton compoundButton;
        CompoundButton compoundButton2;
        if (!z && this.f839d == null && this.f841f == null) {
            return;
        }
        if (this.f837b.m()) {
            if (this.f839d == null) {
                g();
            }
            compoundButton = this.f839d;
            compoundButton2 = this.f841f;
        } else {
            if (this.f841f == null) {
                e();
            }
            compoundButton = this.f841f;
            compoundButton2 = this.f839d;
        }
        if (z) {
            compoundButton.setChecked(this.f837b.isChecked());
            if (compoundButton.getVisibility() != 0) {
                compoundButton.setVisibility(0);
            }
            if (compoundButton2 == null || compoundButton2.getVisibility() == 8) {
                return;
            }
            compoundButton2.setVisibility(8);
            return;
        }
        CheckBox checkBox = this.f841f;
        if (checkBox != null) {
            checkBox.setVisibility(8);
        }
        RadioButton radioButton = this.f839d;
        if (radioButton != null) {
            radioButton.setVisibility(8);
        }
    }

    public void setChecked(boolean z) {
        CompoundButton compoundButton;
        if (this.f837b.m()) {
            if (this.f839d == null) {
                g();
            }
            compoundButton = this.f839d;
        } else {
            if (this.f841f == null) {
                e();
            }
            compoundButton = this.f841f;
        }
        compoundButton.setChecked(z);
    }

    public void setForceShowIcon(boolean z) {
        this.r = z;
        this.n = z;
    }

    public void setGroupDividerEnabled(boolean z) {
        ImageView imageView = this.i;
        if (imageView != null) {
            imageView.setVisibility((this.p || !z) ? 8 : 0);
        }
    }

    public void setIcon(Drawable drawable) {
        boolean z = this.f837b.z() || this.r;
        if (z || this.n) {
            if (this.f838c == null && drawable == null && !this.n) {
                return;
            }
            if (this.f838c == null) {
                f();
            }
            if (drawable == null && !this.n) {
                this.f838c.setVisibility(8);
                return;
            }
            ImageView imageView = this.f838c;
            if (!z) {
                drawable = null;
            }
            imageView.setImageDrawable(drawable);
            if (this.f838c.getVisibility() != 0) {
                this.f838c.setVisibility(0);
            }
        }
    }

    public void setTitle(CharSequence charSequence) {
        if (charSequence == null) {
            if (this.f840e.getVisibility() != 8) {
                this.f840e.setVisibility(8);
            }
        } else {
            this.f840e.setText(charSequence);
            if (this.f840e.getVisibility() != 0) {
                this.f840e.setVisibility(0);
            }
        }
    }

    public ListMenuItemView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet);
        t0 t0VarT = t0.t(getContext(), attributeSet, a.b.d.a.j.MenuView, i, 0);
        this.k = t0VarT.f(a.b.d.a.j.MenuView_android_itemBackground);
        this.l = t0VarT.m(a.b.d.a.j.MenuView_android_itemTextAppearance, -1);
        this.n = t0VarT.a(a.b.d.a.j.MenuView_preserveIconSpacing, false);
        this.m = context;
        this.o = t0VarT.f(a.b.d.a.j.MenuView_subMenuArrow);
        TypedArray typedArrayObtainStyledAttributes = context.getTheme().obtainStyledAttributes(null, new int[]{R.attr.divider}, a.b.d.a.a.dropDownListViewStyle, 0);
        this.p = typedArrayObtainStyledAttributes.hasValue(0);
        t0VarT.u();
        typedArrayObtainStyledAttributes.recycle();
    }
}
