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.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 com.ifpdos.udi.service.core.pc.R;
import d.b.b;
import d.b.f.i.i;
import d.b.f.i.n;
import d.b.g.z0;
import d.h.j.y;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public LinearLayout f453t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public Drawable f454u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public int f455v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public Context f456w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public boolean f457x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public Drawable f458y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public boolean f459z;

    public ListMenuItemView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        z0 z0VarQ = z0.q(getContext(), attributeSet, b.f1544q, R.attr.listMenuViewStyle, 0);
        this.f454u = z0VarQ.g(5);
        this.f455v = z0VarQ.l(1, -1);
        this.f457x = z0VarQ.a(7, false);
        this.f456w = context;
        this.f458y = z0VarQ.g(8);
        TypedArray typedArrayObtainStyledAttributes = context.getTheme().obtainStyledAttributes(null, new int[]{android.R.attr.divider}, R.attr.dropDownListViewStyle, 0);
        this.f459z = typedArrayObtainStyledAttributes.hasValue(0);
        z0VarQ.f2138b.recycle();
        typedArrayObtainStyledAttributes.recycle();
    }

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

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

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

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

    public void c(boolean z2) {
        int i2;
        String string;
        int i3 = (z2 && this.f445f.m()) ? 0 : 8;
        if (i3 == 0) {
            TextView textView = this.f450q;
            i iVar = this.f445f;
            char cE = iVar.e();
            if (cE == 0) {
                string = "";
            } else {
                Resources resources = iVar.f1826n.f1787b.getResources();
                StringBuilder sb = new StringBuilder();
                if (ViewConfiguration.get(iVar.f1826n.f1787b).hasPermanentMenuKey()) {
                    sb.append(resources.getString(R.string.abc_prepend_shortcut_label));
                }
                int i4 = iVar.f1826n.n() ? iVar.f1823k : iVar.f1821i;
                i.c(sb, i4, 65536, resources.getString(R.string.abc_menu_meta_shortcut_label));
                i.c(sb, i4, 4096, resources.getString(R.string.abc_menu_ctrl_shortcut_label));
                i.c(sb, i4, 2, resources.getString(R.string.abc_menu_alt_shortcut_label));
                i.c(sb, i4, 1, resources.getString(R.string.abc_menu_shift_shortcut_label));
                i.c(sb, i4, 4, resources.getString(R.string.abc_menu_sym_shortcut_label));
                i.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.f450q.getVisibility() != i3) {
            this.f450q.setVisibility(i3);
        }
    }

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

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

    @Override // android.view.View
    public void onFinishInflate() {
        super.onFinishInflate();
        Drawable drawable = this.f454u;
        AtomicInteger atomicInteger = y.a;
        y.c.q(this, drawable);
        TextView textView = (TextView) findViewById(R.id.title);
        this.f448o = textView;
        int i2 = this.f455v;
        if (i2 != -1) {
            textView.setTextAppearance(this.f456w, i2);
        }
        this.f450q = (TextView) findViewById(R.id.shortcut);
        ImageView imageView = (ImageView) findViewById(R.id.submenuarrow);
        this.f451r = imageView;
        if (imageView != null) {
            imageView.setImageDrawable(this.f458y);
        }
        this.f452s = (ImageView) findViewById(R.id.group_divider);
        this.f453t = (LinearLayout) findViewById(R.id.content);
    }

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

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

    public void setChecked(boolean z2) {
        CompoundButton compoundButton;
        if (this.f445f.h()) {
            if (this.f447n == null) {
                b();
            }
            compoundButton = this.f447n;
        } else {
            if (this.f449p == null) {
                a();
            }
            compoundButton = this.f449p;
        }
        compoundButton.setChecked(z2);
    }

    public void setForceShowIcon(boolean z2) {
        this.B = z2;
        this.f457x = z2;
    }

    public void setGroupDividerEnabled(boolean z2) {
        ImageView imageView = this.f452s;
        if (imageView != null) {
            imageView.setVisibility((this.f459z || !z2) ? 8 : 0);
        }
    }

    public void setIcon(Drawable drawable) {
        Objects.requireNonNull(this.f445f.f1826n);
        boolean z2 = this.B;
        if (z2 || this.f457x) {
            ImageView imageView = this.f446m;
            if (imageView == null && drawable == null && !this.f457x) {
                return;
            }
            if (imageView == null) {
                ImageView imageView2 = (ImageView) getInflater().inflate(R.layout.abc_list_menu_item_icon, (ViewGroup) this, false);
                this.f446m = imageView2;
                LinearLayout linearLayout = this.f453t;
                if (linearLayout != null) {
                    linearLayout.addView(imageView2, 0);
                } else {
                    addView(imageView2, 0);
                }
            }
            if (drawable == null && !this.f457x) {
                this.f446m.setVisibility(8);
                return;
            }
            ImageView imageView3 = this.f446m;
            if (!z2) {
                drawable = null;
            }
            imageView3.setImageDrawable(drawable);
            if (this.f446m.getVisibility() != 0) {
                this.f446m.setVisibility(0);
            }
        }
    }

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