package androidx.appcompat.view.menu;

import android.content.Context;
import android.content.res.Resources;
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.ViewConfiguration;
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 c.b.b;
import c.b.e.i.i;
import c.b.e.i.n;
import c.b.f.d1;
import c.f.j.a0;
import c.f.j.i0;
import com.ifpdos.debugmenu.R;
import java.util.Objects;
import java.util.WeakHashMap;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public i f103b;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public ImageView f104e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public RadioButton f105f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public TextView f106g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public CheckBox f107h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public TextView f108i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public ImageView f109j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public ImageView f110k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public LinearLayout f111l;
    public Drawable m;
    public int n;
    public Context o;
    public boolean p;
    public Drawable q;
    public boolean r;
    public LayoutInflater s;
    public boolean t;

    public ListMenuItemView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        d1 d1VarO = d1.o(getContext(), attributeSet, b.r, R.attr.listMenuViewStyle, 0);
        this.m = d1VarO.e(5);
        this.n = d1VarO.j(1, -1);
        this.p = d1VarO.a(7, false);
        this.o = context;
        this.q = d1VarO.e(8);
        TypedArray typedArrayObtainStyledAttributes = context.getTheme().obtainStyledAttributes(null, new int[]{android.R.attr.divider}, R.attr.dropDownListViewStyle, 0);
        this.r = typedArrayObtainStyledAttributes.hasValue(0);
        d1VarO.f806b.recycle();
        typedArrayObtainStyledAttributes.recycle();
    }

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

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

    public final void a() {
        CheckBox checkBox = (CheckBox) getInflater().inflate(R.layout.abc_list_menu_item_checkbox, (ViewGroup) this, false);
        this.f107h = checkBox;
        LinearLayout linearLayout = this.f111l;
        if (linearLayout != null) {
            linearLayout.addView(checkBox, -1);
        } else {
            addView(checkBox, -1);
        }
    }

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

    public final void b() {
        RadioButton radioButton = (RadioButton) getInflater().inflate(R.layout.abc_list_menu_item_radio, (ViewGroup) this, false);
        this.f105f = radioButton;
        LinearLayout linearLayout = this.f111l;
        if (linearLayout != null) {
            linearLayout.addView(radioButton, -1);
        } else {
            addView(radioButton, -1);
        }
    }

    @Override // c.b.e.i.n.a
    public void c(i iVar, int i2) {
        this.f103b = iVar;
        setVisibility(iVar.isVisible() ? 0 : 8);
        setTitle(iVar.f729e);
        setCheckable(iVar.isCheckable());
        boolean zM = iVar.m();
        iVar.e();
        d(zM);
        setIcon(iVar.getIcon());
        setEnabled(iVar.isEnabled());
        setSubMenuArrowVisible(iVar.hasSubMenu());
        setContentDescription(iVar.q);
    }

    public void d(boolean z) {
        String string;
        int i2 = (z && this.f103b.m()) ? 0 : 8;
        if (i2 == 0) {
            TextView textView = this.f108i;
            i iVar = this.f103b;
            char cE = iVar.e();
            if (cE == 0) {
                string = "";
            } else {
                Resources resources = iVar.n.f712b.getResources();
                StringBuilder sb = new StringBuilder();
                if (ViewConfiguration.get(iVar.n.f712b).hasPermanentMenuKey()) {
                    sb.append(resources.getString(R.string.abc_prepend_shortcut_label));
                }
                int i3 = iVar.n.n() ? iVar.f735k : iVar.f733i;
                i.c(sb, i3, 65536, resources.getString(R.string.abc_menu_meta_shortcut_label));
                i.c(sb, i3, 4096, resources.getString(R.string.abc_menu_ctrl_shortcut_label));
                i.c(sb, i3, 2, resources.getString(R.string.abc_menu_alt_shortcut_label));
                i.c(sb, i3, 1, resources.getString(R.string.abc_menu_shift_shortcut_label));
                i.c(sb, i3, 4, resources.getString(R.string.abc_menu_sym_shortcut_label));
                i.c(sb, i3, 8, resources.getString(R.string.abc_menu_function_shortcut_label));
                if (cE == '\b') {
                    sb.append(resources.getString(R.string.abc_menu_delete_shortcut_label));
                } else if (cE == '\n') {
                    sb.append(resources.getString(R.string.abc_menu_enter_shortcut_label));
                } else if (cE != ' ') {
                    sb.append(cE);
                } else {
                    sb.append(resources.getString(R.string.abc_menu_space_shortcut_label));
                }
                string = sb.toString();
            }
            textView.setText(string);
        }
        if (this.f108i.getVisibility() != i2) {
            this.f108i.setVisibility(i2);
        }
    }

    @Override // c.b.e.i.n.a
    public i getItemData() {
        return this.f103b;
    }

    @Override // android.view.View
    public void onFinishInflate() {
        super.onFinishInflate();
        Drawable drawable = this.m;
        WeakHashMap<View, i0> weakHashMap = a0.a;
        a0.d.q(this, drawable);
        TextView textView = (TextView) findViewById(R.id.title);
        this.f106g = textView;
        int i2 = this.n;
        if (i2 != -1) {
            textView.setTextAppearance(this.o, i2);
        }
        this.f108i = (TextView) findViewById(R.id.shortcut);
        ImageView imageView = (ImageView) findViewById(R.id.submenuarrow);
        this.f109j = imageView;
        if (imageView != null) {
            imageView.setImageDrawable(this.q);
        }
        this.f110k = (ImageView) findViewById(R.id.group_divider);
        this.f111l = (LinearLayout) findViewById(R.id.content);
    }

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

    public void setCheckable(boolean z) {
        CompoundButton compoundButton;
        CompoundButton compoundButton2;
        if (!z && this.f105f == null && this.f107h == null) {
            return;
        }
        if (this.f103b.h()) {
            if (this.f105f == null) {
                b();
            }
            compoundButton = this.f105f;
            compoundButton2 = this.f107h;
        } else {
            if (this.f107h == null) {
                a();
            }
            compoundButton = this.f107h;
            compoundButton2 = this.f105f;
        }
        if (z) {
            compoundButton.setChecked(this.f103b.isChecked());
            if (compoundButton.getVisibility() != 0) {
                compoundButton.setVisibility(0);
            }
            if (compoundButton2 == null || compoundButton2.getVisibility() == 8) {
                return;
            }
            compoundButton2.setVisibility(8);
            return;
        }
        CheckBox checkBox = this.f107h;
        if (checkBox != null) {
            checkBox.setVisibility(8);
        }
        RadioButton radioButton = this.f105f;
        if (radioButton != null) {
            radioButton.setVisibility(8);
        }
    }

    public void setChecked(boolean z) {
        CompoundButton compoundButton;
        if (this.f103b.h()) {
            if (this.f105f == null) {
                b();
            }
            compoundButton = this.f105f;
        } else {
            if (this.f107h == null) {
                a();
            }
            compoundButton = this.f107h;
        }
        compoundButton.setChecked(z);
    }

    public void setForceShowIcon(boolean z) {
        this.t = z;
        this.p = z;
    }

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

    public void setIcon(Drawable drawable) {
        Objects.requireNonNull(this.f103b.n);
        boolean z = this.t;
        if (z || this.p) {
            ImageView imageView = this.f104e;
            if (imageView == null && drawable == null && !this.p) {
                return;
            }
            if (imageView == null) {
                ImageView imageView2 = (ImageView) getInflater().inflate(R.layout.abc_list_menu_item_icon, (ViewGroup) this, false);
                this.f104e = imageView2;
                LinearLayout linearLayout = this.f111l;
                if (linearLayout != null) {
                    linearLayout.addView(imageView2, 0);
                } else {
                    addView(imageView2, 0);
                }
            }
            if (drawable == null && !this.p) {
                this.f104e.setVisibility(8);
                return;
            }
            ImageView imageView3 = this.f104e;
            if (!z) {
                drawable = null;
            }
            imageView3.setImageDrawable(drawable);
            if (this.f104e.getVisibility() != 0) {
                this.f104e.setVisibility(0);
            }
        }
    }

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