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 b.b.b;
import b.b.f.i.i;
import b.b.f.i.n;
import b.b.g.z0;
import b.f.j.s;
import com.cvte.vman.BuildConfig;
import com.cvte.vman.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: a, reason: collision with root package name */
    public i f49a;

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

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

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

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

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

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

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

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

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

    @Override // b.b.f.i.n.a
    public void c(i iVar, int i) {
        this.f49a = iVar;
        setVisibility(iVar.isVisible() ? 0 : 8);
        setTitle(iVar.f395e);
        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) {
        int i;
        String string;
        int i2 = (z && this.f49a.m()) ? 0 : 8;
        if (i2 == 0) {
            TextView textView = this.f54f;
            i iVar = this.f49a;
            char cE = iVar.e();
            if (cE == 0) {
                string = BuildConfig.FLAVOR;
            } else {
                Resources resources = iVar.n.f383b.getResources();
                StringBuilder sb = new StringBuilder();
                if (ViewConfiguration.get(iVar.n.f383b).hasPermanentMenuKey()) {
                    sb.append(resources.getString(R.string.abc_prepend_shortcut_label));
                }
                int i3 = iVar.n.n() ? iVar.k : iVar.i;
                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') {
                    i = R.string.abc_menu_delete_shortcut_label;
                } else if (cE == '\n') {
                    i = R.string.abc_menu_enter_shortcut_label;
                } else if (cE != ' ') {
                    sb.append(cE);
                    string = sb.toString();
                } else {
                    i = R.string.abc_menu_space_shortcut_label;
                }
                sb.append(resources.getString(i));
                string = sb.toString();
            }
            textView.setText(string);
        }
        if (this.f54f.getVisibility() != i2) {
            this.f54f.setVisibility(i2);
        }
    }

    @Override // b.b.f.i.n.a
    public i getItemData() {
        return this.f49a;
    }

    @Override // android.view.View
    public void onFinishInflate() {
        super.onFinishInflate();
        Drawable drawable = this.j;
        WeakHashMap<View, s> weakHashMap = b.f.j.n.f1007a;
        setBackground(drawable);
        TextView textView = (TextView) findViewById(R.id.title);
        this.f52d = textView;
        int i = this.k;
        if (i != -1) {
            textView.setTextAppearance(this.l, i);
        }
        this.f54f = (TextView) findViewById(R.id.shortcut);
        ImageView imageView = (ImageView) findViewById(R.id.submenuarrow);
        this.g = imageView;
        if (imageView != null) {
            imageView.setImageDrawable(this.n);
        }
        this.h = (ImageView) findViewById(R.id.group_divider);
        this.i = (LinearLayout) findViewById(R.id.content);
    }

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

    public void setChecked(boolean z) {
        CompoundButton compoundButton;
        if (this.f49a.h()) {
            if (this.f51c == null) {
                b();
            }
            compoundButton = this.f51c;
        } else {
            if (this.f53e == null) {
                a();
            }
            compoundButton = this.f53e;
        }
        compoundButton.setChecked(z);
    }

    public void setForceShowIcon(boolean z) {
        this.q = z;
        this.m = z;
    }

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

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

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