package p037.p041.p051;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import androidx.appcompat.view.menu.ActionMenuItemView;
import androidx.appcompat.widget.ActionMenuView;
import androidx.appcompat.widget.AppCompatImageView;
import java.util.ArrayList;
import p037.p041.C1468;
import p037.p041.C1474;
import p037.p041.p042.LayoutInflaterFactory2C1494;
import p037.p041.p049.p050.AbstractC1561;
import p037.p041.p049.p050.AbstractC1584;
import p037.p041.p049.p050.C1572;
import p037.p041.p049.p050.C1576;
import p037.p041.p049.p050.C1585;
import p037.p041.p049.p050.InterfaceC1587;
import p037.p041.p049.p050.InterfaceC1589;
import p037.p041.p049.p050.InterfaceC1592;
import p037.p041.p049.p050.SubMenuC1596;
import p037.p065.p078.AbstractC1907;

/* JADX INFO: renamed from: މ.ؠ.ގ.ހ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C1601 extends AbstractC1561 {

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public C1605 f5199;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public Drawable f5200;

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public boolean f5201;

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public boolean f5202;

    /* JADX INFO: renamed from: ޏ, reason: contains not printable characters */
    public boolean f5203;

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public int f5204;

    /* JADX INFO: renamed from: ޑ, reason: contains not printable characters */
    public int f5205;

    /* JADX INFO: renamed from: ޒ, reason: contains not printable characters */
    public int f5206;

    /* JADX INFO: renamed from: ޓ, reason: contains not printable characters */
    public boolean f5207;

    /* JADX INFO: renamed from: ޔ, reason: contains not printable characters */
    public int f5208;

    /* JADX INFO: renamed from: ޕ, reason: contains not printable characters */
    public final SparseBooleanArray f5209;

    /* JADX INFO: renamed from: ޖ, reason: contains not printable characters */
    public C1607 f5210;

    /* JADX INFO: renamed from: ޗ, reason: contains not printable characters */
    public C1602 f5211;

    /* JADX INFO: renamed from: ޘ, reason: contains not printable characters */
    public RunnableC1604 f5212;

    /* JADX INFO: renamed from: ޙ, reason: contains not printable characters */
    public C1603 f5213;

    /* JADX INFO: renamed from: ޚ, reason: contains not printable characters */
    public final C1608 f5214;

    /* JADX INFO: renamed from: ޛ, reason: contains not printable characters */
    public int f5215;

    /* JADX INFO: renamed from: މ.ؠ.ގ.ހ$֏, reason: contains not printable characters */
    public class C1602 extends C1585 {
        public C1602(Context context, SubMenuC1596 subMenuC1596, View view) {
            super(context, subMenuC1596, view, false, C1468.actionOverflowMenuStyle, 0);
            if (!subMenuC1596.f5185.m3117()) {
                View view2 = C1601.this.f5199;
                this.f5152 = view2 == null ? (View) C1601.this.f5018 : view2;
            }
            m3128(C1601.this.f5214);
        }

        @Override // p037.p041.p049.p050.C1585
        /* JADX INFO: renamed from: ހ */
        public void mo3130() {
            C1601 c1601 = C1601.this;
            c1601.f5211 = null;
            c1601.f5215 = 0;
            super.mo3130();
        }
    }

    /* JADX INFO: renamed from: މ.ؠ.ގ.ހ$ؠ, reason: contains not printable characters */
    public class C1603 extends ActionMenuItemView.AbstractC0034 {
        public C1603() {
        }
    }

    /* JADX INFO: renamed from: މ.ؠ.ގ.ހ$ހ, reason: contains not printable characters */
    public class RunnableC1604 implements Runnable {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public C1607 f5218;

        public RunnableC1604(C1607 c1607) {
            this.f5218 = c1607;
        }

        @Override // java.lang.Runnable
        public void run() {
            C1572.InterfaceC1573 interfaceC1573;
            C1572 c1572 = C1601.this.f5013;
            if (c1572 != null && (interfaceC1573 = c1572.f5081) != null) {
                interfaceC1573.mo144(c1572);
            }
            View view = (View) C1601.this.f5018;
            if (view != null && view.getWindowToken() != null && this.f5218.m3131()) {
                C1601.this.f5210 = this.f5218;
            }
            C1601.this.f5212 = null;
        }
    }

    /* JADX INFO: renamed from: މ.ؠ.ގ.ހ$ށ, reason: contains not printable characters */
    public class C1605 extends AppCompatImageView implements ActionMenuView.InterfaceC0041 {

        /* JADX INFO: renamed from: މ.ؠ.ގ.ހ$ށ$֏, reason: contains not printable characters */
        public class C1606 extends AbstractViewOnTouchListenerC1655 {
            public C1606(View view, C1601 c1601) {
                super(view);
            }

            @Override // p037.p041.p051.AbstractViewOnTouchListenerC1655
            /* JADX INFO: renamed from: ؠ */
            public InterfaceC1592 mo110() {
                C1607 c1607 = C1601.this.f5210;
                if (c1607 == null) {
                    return null;
                }
                return c1607.m3126();
            }

            @Override // p037.p041.p051.AbstractViewOnTouchListenerC1655
            /* JADX INFO: renamed from: ހ */
            public boolean mo111() {
                C1601.this.m3142();
                return true;
            }

            @Override // p037.p041.p051.AbstractViewOnTouchListenerC1655
            /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
            public boolean mo3143() {
                C1601 c1601 = C1601.this;
                if (c1601.f5212 != null) {
                    return false;
                }
                c1601.m3139();
                return true;
            }
        }

        public C1605(Context context) {
            super(context, null, C1468.actionOverflowButtonStyle);
            setClickable(true);
            setFocusable(true);
            setVisibility(0);
            setEnabled(true);
            LayoutInflaterFactory2C1494.C1505.m2942((View) this, getContentDescription());
            setOnTouchListener(new C1606(this, C1601.this));
        }

        @Override // android.view.View
        public boolean performClick() {
            if (super.performClick()) {
                return true;
            }
            playSoundEffect(0);
            C1601.this.m3142();
            return true;
        }

        @Override // android.widget.ImageView
        public boolean setFrame(int i, int i2, int i3, int i4) {
            boolean frame = super.setFrame(i, i2, i3, i4);
            Drawable drawable = getDrawable();
            Drawable background = getBackground();
            if (drawable != null && background != null) {
                int width = getWidth();
                int height = getHeight();
                int iMax = Math.max(width, height) / 2;
                int paddingLeft = (width + (getPaddingLeft() - getPaddingRight())) / 2;
                int paddingTop = (height + (getPaddingTop() - getPaddingBottom())) / 2;
                background.setHotspotBounds(paddingLeft - iMax, paddingTop - iMax, paddingLeft + iMax, paddingTop + iMax);
            }
            return frame;
        }

        @Override // androidx.appcompat.widget.ActionMenuView.InterfaceC0041
        /* JADX INFO: renamed from: ؠ */
        public boolean mo105() {
            return false;
        }

        @Override // androidx.appcompat.widget.ActionMenuView.InterfaceC0041
        /* JADX INFO: renamed from: ހ */
        public boolean mo106() {
            return false;
        }
    }

    /* JADX INFO: renamed from: މ.ؠ.ގ.ހ$ނ, reason: contains not printable characters */
    public class C1607 extends C1585 {
        public C1607(Context context, C1572 c1572, View view, boolean z) {
            super(context, c1572, view, z, C1468.actionOverflowMenuStyle, 0);
            this.f5153 = 8388613;
            m3128(C1601.this.f5214);
        }

        @Override // p037.p041.p049.p050.C1585
        /* JADX INFO: renamed from: ހ */
        public void mo3130() {
            C1572 c1572 = C1601.this.f5013;
            if (c1572 != null) {
                c1572.m3093(true);
            }
            C1601.this.f5210 = null;
            super.mo3130();
        }
    }

    /* JADX INFO: renamed from: މ.ؠ.ގ.ހ$ރ, reason: contains not printable characters */
    public class C1608 implements InterfaceC1587.InterfaceC1588 {
        public C1608() {
        }

        @Override // p037.p041.p049.p050.InterfaceC1587.InterfaceC1588
        /* JADX INFO: renamed from: ֏ */
        public void mo142(C1572 c1572, boolean z) {
            if (c1572 instanceof SubMenuC1596) {
                c1572.mo3102().m3093(false);
            }
            InterfaceC1587.InterfaceC1588 interfaceC1588 = C1601.this.f5015;
            if (interfaceC1588 != null) {
                interfaceC1588.mo142(c1572, z);
            }
        }

        @Override // p037.p041.p049.p050.InterfaceC1587.InterfaceC1588
        /* JADX INFO: renamed from: ֏ */
        public boolean mo143(C1572 c1572) {
            if (c1572 == C1601.this.f5013) {
                return false;
            }
            ((SubMenuC1596) c1572).f5185.getItemId();
            InterfaceC1587.InterfaceC1588 interfaceC1588 = C1601.this.f5015;
            if (interfaceC1588 != null) {
                return interfaceC1588.mo143(c1572);
            }
            return false;
        }
    }

    public C1601(Context context) {
        super(context, C1474.abc_action_menu_layout, C1474.abc_action_menu_item_layout);
        this.f5209 = new SparseBooleanArray();
        this.f5214 = new C1608();
    }

    @Override // p037.p041.p049.p050.AbstractC1561
    /* JADX INFO: renamed from: ֏ */
    public View mo3063(C1576 c1576, View view, ViewGroup viewGroup) {
        View actionView = c1576.getActionView();
        if (actionView == null || c1576.m3115()) {
            actionView = super.mo3063(c1576, view, viewGroup);
        }
        actionView.setVisibility(c1576.f5133 ? 8 : 0);
        ActionMenuView actionMenuView = (ActionMenuView) viewGroup;
        ViewGroup.LayoutParams layoutParams = actionView.getLayoutParams();
        if (actionMenuView == null) {
            throw null;
        }
        if (!(layoutParams instanceof ActionMenuView.C0043)) {
            actionView.setLayoutParams(actionMenuView.generateLayoutParams(layoutParams));
        }
        return actionView;
    }

    @Override // p037.p041.p049.p050.InterfaceC1587
    /* JADX INFO: renamed from: ֏ */
    public void mo199(Context context, C1572 c1572) {
        this.f5012 = context;
        LayoutInflater.from(context);
        this.f5013 = c1572;
        Resources resources = context.getResources();
        if (!this.f5203) {
            this.f5202 = true;
        }
        int i = 2;
        this.f5204 = context.getResources().getDisplayMetrics().widthPixels / 2;
        Configuration configuration = context.getResources().getConfiguration();
        int i2 = configuration.screenWidthDp;
        int i3 = configuration.screenHeightDp;
        if (configuration.smallestScreenWidthDp > 600 || i2 > 600 || ((i2 > 960 && i3 > 720) || (i2 > 720 && i3 > 960))) {
            i = 5;
        } else if (i2 >= 500 || ((i2 > 640 && i3 > 480) || (i2 > 480 && i3 > 640))) {
            i = 4;
        } else if (i2 >= 360) {
            i = 3;
        }
        this.f5206 = i;
        int measuredWidth = this.f5204;
        if (this.f5202) {
            if (this.f5199 == null) {
                C1605 c1605 = new C1605(this.f5011);
                this.f5199 = c1605;
                if (this.f5201) {
                    c1605.setImageDrawable(this.f5200);
                    this.f5200 = null;
                    this.f5201 = false;
                }
                int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, 0);
                this.f5199.measure(iMakeMeasureSpec, iMakeMeasureSpec);
            }
            measuredWidth -= this.f5199.getMeasuredWidth();
        } else {
            this.f5199 = null;
        }
        this.f5205 = measuredWidth;
        this.f5208 = (int) (resources.getDisplayMetrics().density * 56.0f);
    }

    @Override // p037.p041.p049.p050.InterfaceC1587
    /* JADX INFO: renamed from: ֏ */
    public void mo200(C1572 c1572, boolean z) {
        m3138();
        InterfaceC1587.InterfaceC1588 interfaceC1588 = this.f5015;
        if (interfaceC1588 != null) {
            interfaceC1588.mo142(c1572, z);
        }
    }

    @Override // p037.p041.p049.p050.AbstractC1561, p037.p041.p049.p050.InterfaceC1587
    /* JADX INFO: renamed from: ֏ */
    public void mo202(boolean z) {
        ArrayList<C1576> arrayList;
        super.mo202(z);
        ((View) this.f5018).requestLayout();
        C1572 c1572 = this.f5013;
        boolean z2 = false;
        if (c1572 != null) {
            c1572.m3086();
            ArrayList<C1576> arrayList2 = c1572.f5085;
            int size = arrayList2.size();
            for (int i = 0; i < size; i++) {
                AbstractC1907 abstractC1907 = arrayList2.get(i).f5131;
            }
        }
        C1572 c15722 = this.f5013;
        if (c15722 != null) {
            c15722.m3086();
            arrayList = c15722.f5086;
        } else {
            arrayList = null;
        }
        if (this.f5202 && arrayList != null) {
            int size2 = arrayList.size();
            if (size2 == 1) {
                z2 = !arrayList.get(0).f5133;
            } else if (size2 > 0) {
                z2 = true;
            }
        }
        if (z2) {
            if (this.f5199 == null) {
                this.f5199 = new C1605(this.f5011);
            }
            ViewGroup viewGroup = (ViewGroup) this.f5199.getParent();
            if (viewGroup != this.f5018) {
                if (viewGroup != null) {
                    viewGroup.removeView(this.f5199);
                }
                ActionMenuView actionMenuView = (ActionMenuView) this.f5018;
                C1605 c1605 = this.f5199;
                ActionMenuView.C0043 c0043GenerateDefaultLayoutParams = actionMenuView.generateDefaultLayoutParams();
                c0043GenerateDefaultLayoutParams.f296 = true;
                actionMenuView.addView(c1605, c0043GenerateDefaultLayoutParams);
            }
        } else {
            C1605 c16052 = this.f5199;
            if (c16052 != null) {
                Object parent = c16052.getParent();
                Object obj = this.f5018;
                if (parent == obj) {
                    ((ViewGroup) obj).removeView(this.f5199);
                }
            }
        }
        ((ActionMenuView) this.f5018).setOverflowReserved(this.f5202);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public boolean m3138() {
        return m3139() | m3140();
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // p037.p041.p049.p050.AbstractC1561, p037.p041.p049.p050.InterfaceC1587
    /* JADX INFO: renamed from: ֏ */
    public boolean mo204(SubMenuC1596 subMenuC1596) {
        boolean z = false;
        if (!subMenuC1596.hasVisibleItems()) {
            return false;
        }
        SubMenuC1596 subMenuC15962 = subMenuC1596;
        while (true) {
            C1572 c1572 = subMenuC15962.f5184;
            if (c1572 == this.f5013) {
                break;
            }
            subMenuC15962 = (SubMenuC1596) c1572;
        }
        C1576 c1576 = subMenuC15962.f5185;
        ViewGroup viewGroup = (ViewGroup) this.f5018;
        View view = null;
        view = null;
        if (viewGroup != null) {
            int childCount = viewGroup.getChildCount();
            int i = 0;
            while (true) {
                if (i >= childCount) {
                    break;
                }
                View childAt = viewGroup.getChildAt(i);
                if ((childAt instanceof InterfaceC1589.InterfaceC1590) && ((InterfaceC1589.InterfaceC1590) childAt).getItemData() == c1576) {
                    view = childAt;
                    break;
                }
                i++;
            }
        }
        if (view == null) {
            return false;
        }
        subMenuC1596.f5185.getItemId();
        int size = subMenuC1596.size();
        int i2 = 0;
        while (true) {
            if (i2 >= size) {
                break;
            }
            MenuItem item = subMenuC1596.getItem(i2);
            if (item.isVisible() && item.getIcon() != null) {
                z = true;
                break;
            }
            i2++;
        }
        C1602 c1602 = new C1602(this.f5012, subMenuC1596, view);
        this.f5211 = c1602;
        c1602.f5154 = z;
        AbstractC1584 abstractC1584 = c1602.f5156;
        if (abstractC1584 != null) {
            abstractC1584.mo3072(z);
        }
        if (!this.f5211.m3131()) {
            throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
        }
        super.mo204(subMenuC1596);
        return true;
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // p037.p041.p049.p050.InterfaceC1587
    /* JADX INFO: renamed from: ؠ */
    public boolean mo205() {
        ArrayList<C1576> arrayListM3103;
        int size;
        int i;
        boolean z;
        C1572 c1572 = this.f5013;
        View view = null;
        if (c1572 != null) {
            arrayListM3103 = c1572.m3103();
            size = arrayListM3103.size();
        } else {
            arrayListM3103 = null;
            size = 0;
        }
        int i2 = this.f5206;
        int i3 = this.f5205;
        int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, 0);
        ViewGroup viewGroup = (ViewGroup) this.f5018;
        int i4 = 0;
        boolean z2 = false;
        int i5 = 0;
        int i6 = 0;
        while (true) {
            i = 2;
            z = 1;
            if (i4 >= size) {
                break;
            }
            C1576 c1576 = arrayListM3103.get(i4);
            if ((c1576.f5129 & 2) == 2) {
                i6++;
            } else if ((c1576.f5129 & 1) == 1) {
                i5++;
            } else {
                z2 = true;
            }
            if (this.f5207 && c1576.f5133) {
                i2 = 0;
            }
            i4++;
        }
        if (this.f5202 && (z2 || i5 + i6 > i2)) {
            i2--;
        }
        int i7 = i2 - i6;
        SparseBooleanArray sparseBooleanArray = this.f5209;
        sparseBooleanArray.clear();
        int i8 = 0;
        int i9 = 0;
        while (i8 < size) {
            C1576 c15762 = arrayListM3103.get(i8);
            if ((c15762.f5129 & i) == i) {
                View viewMo3063 = mo3063(c15762, view, viewGroup);
                viewMo3063.measure(iMakeMeasureSpec, iMakeMeasureSpec);
                int measuredWidth = viewMo3063.getMeasuredWidth();
                i3 -= measuredWidth;
                if (i9 == 0) {
                    i9 = measuredWidth;
                }
                int i10 = c15762.f5106;
                if (i10 != 0) {
                    sparseBooleanArray.put(i10, z);
                }
                c15762.m3114(z);
            } else if ((c15762.f5129 & z) == z) {
                int i11 = c15762.f5106;
                boolean z3 = sparseBooleanArray.get(i11);
                boolean z4 = (i7 > 0 || z3) && i3 > 0;
                if (z4) {
                    View viewMo30632 = mo3063(c15762, view, viewGroup);
                    viewMo30632.measure(iMakeMeasureSpec, iMakeMeasureSpec);
                    int measuredWidth2 = viewMo30632.getMeasuredWidth();
                    i3 -= measuredWidth2;
                    if (i9 == 0) {
                        i9 = measuredWidth2;
                    }
                    z4 &= i3 + i9 > 0;
                }
                boolean z5 = z4;
                if (z5 && i11 != 0) {
                    sparseBooleanArray.put(i11, z);
                } else if (z3) {
                    sparseBooleanArray.put(i11, false);
                    for (int i12 = 0; i12 < i8; i12++) {
                        C1576 c15763 = arrayListM3103.get(i12);
                        if (c15763.f5106 == i11) {
                            if (c15763.m3117()) {
                                i7++;
                            }
                            c15763.m3114(false);
                        }
                    }
                }
                if (z5) {
                    i7--;
                }
                c15762.m3114(z5);
            } else {
                c15762.m3114(false);
                i8++;
                view = null;
                i = 2;
                z = 1;
            }
            i8++;
            view = null;
            i = 2;
            z = 1;
        }
        return true;
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public boolean m3139() {
        Object obj;
        RunnableC1604 runnableC1604 = this.f5212;
        if (runnableC1604 != null && (obj = this.f5018) != null) {
            ((View) obj).removeCallbacks(runnableC1604);
            this.f5212 = null;
            return true;
        }
        C1607 c1607 = this.f5210;
        if (c1607 == null) {
            return false;
        }
        if (c1607.m3129()) {
            c1607.f5156.dismiss();
        }
        return true;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public boolean m3140() {
        C1602 c1602 = this.f5211;
        if (c1602 == null) {
            return false;
        }
        if (!c1602.m3129()) {
            return true;
        }
        c1602.f5156.dismiss();
        return true;
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public boolean m3141() {
        C1607 c1607 = this.f5210;
        return c1607 != null && c1607.m3129();
    }

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public boolean m3142() {
        C1572 c1572;
        if (!this.f5202 || m3141() || (c1572 = this.f5013) == null || this.f5018 == null || this.f5212 != null) {
            return false;
        }
        c1572.m3086();
        if (c1572.f5086.isEmpty()) {
            return false;
        }
        RunnableC1604 runnableC1604 = new RunnableC1604(new C1607(this.f5012, this.f5013, this.f5199, true));
        this.f5212 = runnableC1604;
        ((View) this.f5018).post(runnableC1604);
        return true;
    }
}
