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.a.b;
import c.a.f.d.g;
import c.a.f.d.l;
import c.a.g.l0;
import c.c.i.k;
import c.c.i.q;
import com.ifpdos.multiuser.R;
import java.util.Objects;
import java.util.WeakHashMap;

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

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

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

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

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

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

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

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

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

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

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

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

    private void setSubMenuArrowVisible(boolean z) {
        ImageView imageView = this.f4617h;
        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.f4615f = checkBox;
        LinearLayout linearLayout = this.f4619j;
        if (linearLayout != null) {
            linearLayout.addView(checkBox, -1);
        } else {
            addView(checkBox, -1);
        }
    }

    @Override // android.widget.AbsListView.SelectionBoundsAdjuster
    public void adjustListItemSelectionBounds(Rect rect) {
        ImageView imageView = this.f4618i;
        if (imageView == null || imageView.getVisibility() != 0) {
            return;
        }
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) this.f4618i.getLayoutParams();
        rect.top = this.f4618i.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.f4613d = radioButton;
        LinearLayout linearLayout = this.f4619j;
        if (linearLayout != null) {
            linearLayout.addView(radioButton, -1);
        } else {
            addView(radioButton, -1);
        }
    }

    @Override // c.a.f.d.l.a
    public void c(g gVar, int i2) {
        this.f4611b = gVar;
        setVisibility(gVar.isVisible() ? 0 : 8);
        setTitle(gVar.f4869e);
        setCheckable(gVar.isCheckable());
        boolean zN = gVar.n();
        gVar.e();
        d(zN);
        setIcon(gVar.getIcon());
        setEnabled(gVar.isEnabled());
        setSubMenuArrowVisible(gVar.hasSubMenu());
        setContentDescription(gVar.q);
    }

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

    @Override // c.a.f.d.l.a
    public g getItemData() {
        return this.f4611b;
    }

    @Override // android.view.View
    public void onFinishInflate() {
        super.onFinishInflate();
        Drawable drawable = this.k;
        WeakHashMap<View, q> weakHashMap = k.f5288a;
        setBackground(drawable);
        TextView textView = (TextView) findViewById(R.id.title);
        this.f4614e = textView;
        int i2 = this.l;
        if (i2 != -1) {
            textView.setTextAppearance(this.m, i2);
        }
        this.f4616g = (TextView) findViewById(R.id.shortcut);
        ImageView imageView = (ImageView) findViewById(R.id.submenuarrow);
        this.f4617h = imageView;
        if (imageView != null) {
            imageView.setImageDrawable(this.o);
        }
        this.f4618i = (ImageView) findViewById(R.id.group_divider);
        this.f4619j = (LinearLayout) findViewById(R.id.content);
    }

    @Override // android.widget.LinearLayout, android.view.View
    public void onMeasure(int i2, int i3) {
        if (this.f4612c != null && this.n) {
            ViewGroup.LayoutParams layoutParams = getLayoutParams();
            LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) this.f4612c.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.f4613d == null && this.f4615f == null) {
            return;
        }
        if (this.f4611b.h()) {
            if (this.f4613d == null) {
                b();
            }
            compoundButton = this.f4613d;
            compoundButton2 = this.f4615f;
        } else {
            if (this.f4615f == null) {
                a();
            }
            compoundButton = this.f4615f;
            compoundButton2 = this.f4613d;
        }
        if (z) {
            compoundButton.setChecked(this.f4611b.isChecked());
            if (compoundButton.getVisibility() != 0) {
                compoundButton.setVisibility(0);
            }
            if (compoundButton2 == null || compoundButton2.getVisibility() == 8) {
                return;
            }
            compoundButton2.setVisibility(8);
            return;
        }
        CheckBox checkBox = this.f4615f;
        if (checkBox != null) {
            checkBox.setVisibility(8);
        }
        RadioButton radioButton = this.f4613d;
        if (radioButton != null) {
            radioButton.setVisibility(8);
        }
    }

    public void setChecked(boolean z) {
        CompoundButton compoundButton;
        if (this.f4611b.h()) {
            if (this.f4613d == null) {
                b();
            }
            compoundButton = this.f4613d;
        } else {
            if (this.f4615f == null) {
                a();
            }
            compoundButton = this.f4615f;
        }
        compoundButton.setChecked(z);
    }

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

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

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

    public void setTitle(CharSequence charSequence) {
        int i2;
        TextView textView;
        if (charSequence != null) {
            this.f4614e.setText(charSequence);
            if (this.f4614e.getVisibility() == 0) {
                return;
            }
            textView = this.f4614e;
            i2 = 0;
        } else {
            i2 = 8;
            if (this.f4614e.getVisibility() == 8) {
                return;
            } else {
                textView = this.f4614e;
            }
        }
        textView.setVisibility(i2);
    }
}
