package ῲ.ῲ.ඓ.㳳;

import android.content.Context;
import android.content.res.Resources;
import android.os.Parcelable;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import androidx.appcompat.R$dimen;
import androidx.appcompat.R$layout;
import androidx.appcompat.widget.MenuPopupWindow;
import ῲ.ᨨ.ᨨ.C1729;
import ῲ.ῲ.ඓ.㳳.AbstractC1897;

/* renamed from: ῲ.ῲ.ඓ.㳳.㗽  reason: contains not printable characters */
/* compiled from: StandardMenuPopup */
public final class View$OnKeyListenerC1919 extends AbstractC1916 implements PopupWindow.OnDismissListener, AdapterView.OnItemClickListener, AbstractC1897, View.OnKeyListener {

    /* renamed from: ᓆ  reason: contains not printable characters */
    public static final int f6491 = R$layout.abc_popup_menu_item_layout;

    /* renamed from: ʬ  reason: contains not printable characters */
    public final Context f6492;

    /* renamed from: Ԕ  reason: contains not printable characters */
    public View f6493;

    /* renamed from: Ԛ  reason: contains not printable characters */
    public int f6494 = 0;

    /* renamed from: ؿ  reason: contains not printable characters */
    public AbstractC1897.AbstractC1898 f6495;

    /* renamed from: ݜ  reason: contains not printable characters */
    public boolean f6496;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final C1924 f6497;

    /* renamed from: ᓣ  reason: contains not printable characters */
    public ViewTreeObserver f6498;

    /* renamed from: ᕣ  reason: contains not printable characters */
    public final ViewTreeObserver.OnGlobalLayoutListener f6499 = new ViewTreeObserver$OnGlobalLayoutListenerC1921();

    /* renamed from: ᨨ  reason: contains not printable characters */
    public final int f6500;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public final int f6501;

    /* renamed from: 㑃  reason: contains not printable characters */
    public final View.OnAttachStateChangeListener f6502 = new View$OnAttachStateChangeListenerC1920();

    /* renamed from: 㗗  reason: contains not printable characters */
    public View f6503;

    /* renamed from: 㗽  reason: contains not printable characters */
    public boolean f6504;

    /* renamed from: 㳳  reason: contains not printable characters */
    public final MenuPopupWindow f6505;

    /* renamed from: 㴹  reason: contains not printable characters */
    public final boolean f6506;

    /* renamed from: 㶋  reason: contains not printable characters */
    public boolean f6507;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final C1912 f6508;

    /* renamed from: 㿎  reason: contains not printable characters */
    public final int f6509;

    /* renamed from: 䀟  reason: contains not printable characters */
    public int f6510;

    /* renamed from: 䁗  reason: contains not printable characters */
    public PopupWindow.OnDismissListener f6511;

    /* renamed from: ῲ.ῲ.ඓ.㳳.㗽$ῲ  reason: contains not printable characters */
    /* compiled from: StandardMenuPopup */
    public class View$OnAttachStateChangeListenerC1920 implements View.OnAttachStateChangeListener {
        public View$OnAttachStateChangeListenerC1920() {
        }

        public void onViewAttachedToWindow(View view) {
        }

        public void onViewDetachedFromWindow(View view) {
            ViewTreeObserver viewTreeObserver = View$OnKeyListenerC1919.this.f6498;
            if (viewTreeObserver != null) {
                if (!viewTreeObserver.isAlive()) {
                    View$OnKeyListenerC1919.this.f6498 = view.getViewTreeObserver();
                }
                View$OnKeyListenerC1919 r0 = View$OnKeyListenerC1919.this;
                r0.f6498.removeGlobalOnLayoutListener(r0.f6499);
            }
            view.removeOnAttachStateChangeListener(this);
        }
    }

    /* renamed from: ῲ.ῲ.ඓ.㳳.㗽$K  reason: contains not printable characters */
    /* compiled from: StandardMenuPopup */
    public class ViewTreeObserver$OnGlobalLayoutListenerC1921 implements ViewTreeObserver.OnGlobalLayoutListener {
        public ViewTreeObserver$OnGlobalLayoutListenerC1921() {
        }

        public void onGlobalLayout() {
            if (View$OnKeyListenerC1919.this.m4960() && !View$OnKeyListenerC1919.this.f6505.m5182()) {
                View view = View$OnKeyListenerC1919.this.f6503;
                if (view == null || !view.isShown()) {
                    View$OnKeyListenerC1919.this.dismiss();
                } else {
                    View$OnKeyListenerC1919.this.f6505.show();
                }
            }
        }
    }

    public View$OnKeyListenerC1919(Context context, C1912 r5, View view, int i, int i2, boolean z) {
        this.f6492 = context;
        this.f6508 = r5;
        this.f6506 = z;
        this.f6497 = new C1924(r5, LayoutInflater.from(context), this.f6506, f6491);
        this.f6509 = i;
        this.f6500 = i2;
        Resources resources = context.getResources();
        this.f6501 = Math.max(resources.getDisplayMetrics().widthPixels / 2, resources.getDimensionPixelSize(R$dimen.abc_config_prefDialogWidth));
        this.f6493 = view;
        this.f6505 = new MenuPopupWindow(this.f6492, null, this.f6509, this.f6500);
        r5.addMenuPresenter(this, context);
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1903
    public void dismiss() {
        if (m4960()) {
            this.f6505.dismiss();
        }
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public boolean flagActionItems() {
        return false;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public void onCloseMenu(C1912 r2, boolean z) {
        if (r2 == this.f6508) {
            dismiss();
            AbstractC1897.AbstractC1898 k = this.f6495;
            if (k != null) {
                k.onCloseMenu(r2, z);
            }
        }
    }

    public void onDismiss() {
        this.f6504 = true;
        this.f6508.close();
        ViewTreeObserver viewTreeObserver = this.f6498;
        if (viewTreeObserver != null) {
            if (!viewTreeObserver.isAlive()) {
                this.f6498 = this.f6503.getViewTreeObserver();
            }
            this.f6498.removeGlobalOnLayoutListener(this.f6499);
            this.f6498 = null;
        }
        this.f6503.removeOnAttachStateChangeListener(this.f6502);
        PopupWindow.OnDismissListener onDismissListener = this.f6511;
        if (onDismissListener != null) {
            onDismissListener.onDismiss();
        }
    }

    public boolean onKey(View view, int i, KeyEvent keyEvent) {
        if (keyEvent.getAction() != 1 || i != 82) {
            return false;
        }
        dismiss();
        return true;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public void onRestoreInstanceState(Parcelable parcelable) {
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public Parcelable onSaveInstanceState() {
        return null;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public boolean onSubMenuSelected(SubMenuC1900 r10) {
        if (r10.hasVisibleItems()) {
            C1933 r0 = new C1933(this.f6492, r10, this.f6503, this.f6506, this.f6509, this.f6500);
            r0.m5000(this.f6495);
            r0.m5001(AbstractC1916.m4941(r10));
            r0.setOnDismissListener(this.f6511);
            this.f6511 = null;
            this.f6508.close(false);
            int r2 = this.f6505.m5168();
            int r3 = this.f6505.m5161();
            if ((Gravity.getAbsoluteGravity(this.f6494, C1729.m4511(this.f6493)) & 7) == 5) {
                r2 += this.f6493.getWidth();
            }
            if (r0.m5002(r2, r3)) {
                AbstractC1897.AbstractC1898 k = this.f6495;
                if (k == null) {
                    return true;
                }
                k.m4922(r10);
                return true;
            }
        }
        return false;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public void setCallback(AbstractC1897.AbstractC1898 k) {
        this.f6495 = k;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1916
    public void setOnDismissListener(PopupWindow.OnDismissListener onDismissListener) {
        this.f6511 = onDismissListener;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1903
    public void show() {
        View view;
        boolean z = true;
        if (!m4960()) {
            if (this.f6504 || (view = this.f6493) == null) {
                z = false;
            } else {
                this.f6503 = view;
                this.f6505.setOnDismissListener(this);
                this.f6505.setOnItemClickListener(this);
                this.f6505.m5179(true);
                View view2 = this.f6503;
                boolean z2 = this.f6498 == null;
                this.f6498 = view2.getViewTreeObserver();
                if (z2) {
                    this.f6498.addOnGlobalLayoutListener(this.f6499);
                }
                view2.addOnAttachStateChangeListener(this.f6502);
                this.f6505.m5170(view2);
                this.f6505.m5186(this.f6494);
                if (!this.f6496) {
                    this.f6510 = AbstractC1916.m4942(this.f6497, null, this.f6492, this.f6501);
                    this.f6496 = true;
                }
                this.f6505.m5163(this.f6510);
                this.f6505.m5190(2);
                this.f6505.m5177(m4943());
                this.f6505.show();
                ListView r0 = this.f6505.m5185();
                r0.setOnKeyListener(this);
                if (this.f6507 && this.f6508.getHeaderTitle() != null) {
                    FrameLayout frameLayout = (FrameLayout) LayoutInflater.from(this.f6492).inflate(R$layout.abc_popup_menu_header_item_layout, (ViewGroup) r0, false);
                    TextView textView = (TextView) frameLayout.findViewById(16908310);
                    if (textView != null) {
                        textView.setText(this.f6508.getHeaderTitle());
                    }
                    frameLayout.setEnabled(false);
                    r0.addHeaderView(frameLayout, null, false);
                }
                this.f6505.m5178((ListAdapter) this.f6497);
                this.f6505.show();
            }
        }
        if (!z) {
            throw new IllegalStateException("StandardMenuPopup cannot be used without an anchor");
        }
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1897
    public void updateMenuView(boolean z) {
        this.f6496 = false;
        C1924 r1 = this.f6497;
        if (r1 != null) {
            r1.notifyDataSetChanged();
        }
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1916
    /* renamed from: ʬ  reason: contains not printable characters */
    public void m4953(int i) {
        this.f6505.m5169(i);
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1916
    /* renamed from: ῲ  reason: contains not printable characters */
    public void m4954(int i) {
        this.f6505.m5176(i);
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1916
    /* renamed from: K  reason: contains not printable characters */
    public void m4958(C1912 r1) {
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1916
    /* renamed from: K  reason: contains not printable characters */
    public void m4959(boolean z) {
        this.f6497.f6551 = z;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1903
    /* renamed from: 㴹  reason: contains not printable characters */
    public ListView m4961() {
        return this.f6505.m5185();
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1916
    /* renamed from: ῲ  reason: contains not printable characters */
    public void m4955(boolean z) {
        this.f6507 = z;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1916
    /* renamed from: K  reason: contains not printable characters */
    public void m4956(int i) {
        this.f6494 = i;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1903
    /* renamed from: K  reason: contains not printable characters */
    public boolean m4960() {
        return !this.f6504 && this.f6505.m5180();
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1916
    /* renamed from: K  reason: contains not printable characters */
    public void m4957(View view) {
        this.f6493 = view;
    }
}
