package defpackage;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import ar.tvplayer.tv.R;

/* renamed from: ˈᵺː, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class ViewOnKeyListenerC1115 extends AbstractC4053 implements PopupWindow.OnDismissListener, View.OnKeyListener {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public final int f4806;

    /* renamed from: ˁˑᵰ, reason: contains not printable characters */
    public boolean f4807;

    /* renamed from: ˑᵝﹳᵜ, reason: contains not printable characters */
    public boolean f4809;

    /* renamed from: ᐧﾞ, reason: contains not printable characters */
    public InterfaceC2316 f4811;

    /* renamed from: ᵙᵢᵨᵳ, reason: contains not printable characters */
    public int f4812;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final C2804 f4813;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final int f4815;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final Context f4816;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final boolean f4817;

    /* renamed from: ᵧـˌᵎ, reason: contains not printable characters */
    public View f4818;

    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public PopupWindow.OnDismissListener f4819;

    /* renamed from: ᵶʔᵢˊ, reason: contains not printable characters */
    public ViewTreeObserver f4820;

    /* renamed from: ᵺʙ, reason: contains not printable characters */
    public View f4821;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public final C0247 f4822;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final MenuC2418 f4823;

    /* renamed from: ﾞⁱ, reason: contains not printable characters */
    public boolean f4824;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public final ViewTreeObserverOnGlobalLayoutListenerC3682 f4810 = new ViewTreeObserverOnGlobalLayoutListenerC3682(3, this);

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public final ViewOnAttachStateChangeListenerC5360 f4808 = new ViewOnAttachStateChangeListenerC5360(2, this);

    /* renamed from: ᵡᵘˎʽ, reason: contains not printable characters */
    public int f4814 = 0;

    public ViewOnKeyListenerC1115(Context context, MenuC2418 menuC2418, View view, int i, boolean z) {
        this.f4816 = context;
        this.f4823 = menuC2418;
        this.f4817 = z;
        this.f4822 = new C0247(menuC2418, LayoutInflater.from(context), z, R.layout._11_res_0x7f0e0013);
        this.f4806 = i;
        Resources resources = context.getResources();
        this.f4815 = Math.max(resources.getDisplayMetrics().widthPixels / 2, resources.getDimensionPixelSize(R.dimen._11_res_0x7f070017));
        this.f4818 = view;
        this.f4813 = new C2804(context, null, i, 0);
        menuC2418.m6194(this, context);
    }

    @Override // defpackage.InterfaceC0221
    public final void dismiss() {
        if (mo1523()) {
            this.f4813.dismiss();
        }
    }

    @Override // android.widget.PopupWindow.OnDismissListener
    public final void onDismiss() {
        this.f4807 = true;
        this.f4823.m6185(true);
        ViewTreeObserver viewTreeObserver = this.f4820;
        if (viewTreeObserver != null) {
            if (!viewTreeObserver.isAlive()) {
                this.f4820 = this.f4821.getViewTreeObserver();
            }
            this.f4820.removeGlobalOnLayoutListener(this.f4810);
            this.f4820 = null;
        }
        this.f4821.removeOnAttachStateChangeListener(this.f4808);
        PopupWindow.OnDismissListener onDismissListener = this.f4819;
        if (onDismissListener != null) {
            onDismissListener.onDismiss();
        }
    }

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

    @Override // defpackage.InterfaceC5245
    /* renamed from: ˇʼʤˎ */
    public final void mo3443(MenuC2418 menuC2418, boolean z) {
        if (menuC2418 != this.f4823) {
            return;
        }
        dismiss();
        InterfaceC2316 interfaceC2316 = this.f4811;
        if (interfaceC2316 != null) {
            interfaceC2316.mo5172(menuC2418, z);
        }
    }

    @Override // defpackage.AbstractC4053
    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final void mo3542(int i) {
        this.f4814 = i;
    }

    @Override // defpackage.AbstractC4053
    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public final void mo3543(MenuC2418 menuC2418) {
    }

    @Override // defpackage.InterfaceC5245
    /* renamed from: ˎˏʜʾ */
    public final void mo3445(InterfaceC2316 interfaceC2316) {
        this.f4811 = interfaceC2316;
    }

    @Override // defpackage.InterfaceC0221
    /* renamed from: ˏˋٴ */
    public final void mo1522() {
        View view;
        if (mo1523()) {
            return;
        }
        if (this.f4807 || (view = this.f4818) == null) {
            ᵹˉᵞ.ᵳٴᵶ("StandardMenuPopup cannot be used without an anchor");
            return;
        }
        this.f4821 = view;
        C2804 c2804 = this.f4813;
        C1496 c1496 = c2804.f14680;
        C1496 c14962 = c2804.f14680;
        c1496.setOnDismissListener(this);
        c2804.f14662 = this;
        c2804.f14665 = true;
        c14962.setFocusable(true);
        View view2 = this.f4821;
        boolean z = this.f4820 == null;
        ViewTreeObserver viewTreeObserver = view2.getViewTreeObserver();
        this.f4820 = viewTreeObserver;
        if (z) {
            viewTreeObserver.addOnGlobalLayoutListener(this.f4810);
        }
        view2.addOnAttachStateChangeListener(this.f4808);
        c2804.f14681 = view2;
        c2804.f14677 = this.f4814;
        boolean z2 = this.f4824;
        Context context = this.f4816;
        C0247 c0247 = this.f4822;
        if (!z2) {
            this.f4812 = AbstractC4053.m8915(c0247, context, this.f4815);
            this.f4824 = true;
        }
        c2804.m8576(this.f4812);
        c14962.setInputMethodMode(2);
        Rect rect = this.f15213;
        c2804.f14671 = rect != null ? new Rect(rect) : null;
        c2804.mo1522();
        C1073 c1073 = c2804.f14684;
        c1073.setOnKeyListener(this);
        if (this.f4809) {
            MenuC2418 menuC2418 = this.f4823;
            if (menuC2418.f9435 != null) {
                FrameLayout frameLayout = (FrameLayout) LayoutInflater.from(context).inflate(R.layout._11_res_0x7f0e0012, (ViewGroup) c1073, false);
                TextView textView = (TextView) frameLayout.findViewById(android.R.id.title);
                if (textView != null) {
                    textView.setText(menuC2418.f9435);
                }
                frameLayout.setEnabled(false);
                c1073.addHeaderView(frameLayout, null, false);
            }
        }
        c2804.mo2474(c0247);
        c2804.mo1522();
    }

    @Override // defpackage.InterfaceC5245
    /* renamed from: ˏᵙ */
    public final boolean mo3447() {
        return false;
    }

    @Override // defpackage.InterfaceC5245
    /* renamed from: ᵝᵵᵺ */
    public final void mo3448() {
        this.f4824 = false;
        C0247 c0247 = this.f4822;
        if (c0247 != null) {
            c0247.notifyDataSetChanged();
        }
    }

    @Override // defpackage.AbstractC4053
    /* renamed from: ᵞʡ, reason: contains not printable characters */
    public final void mo3544(boolean z) {
        this.f4809 = z;
    }

    @Override // defpackage.AbstractC4053
    /* renamed from: ᵡʠ, reason: contains not printable characters */
    public final void mo3545(int i) {
        this.f4813.f14674 = i;
    }

    @Override // defpackage.InterfaceC0221
    /* renamed from: ᵥᵯˎ */
    public final boolean mo1523() {
        return !this.f4807 && this.f4813.f14680.isShowing();
    }

    @Override // defpackage.AbstractC4053
    /* renamed from: ᵨᵳʝ, reason: contains not printable characters */
    public final void mo3546(int i) {
        this.f4813.m8571(i);
    }

    @Override // defpackage.AbstractC4053
    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public final void mo3547(View view) {
        this.f4818 = view;
    }

    @Override // defpackage.AbstractC4053
    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public final void mo3548(boolean z) {
        this.f4822.f1790 = z;
    }

    @Override // defpackage.InterfaceC5245
    /* renamed from: ᵴᵳ */
    public final boolean mo3450(SubMenuC0664 subMenuC0664) throws Resources.NotFoundException {
        boolean z;
        if (subMenuC0664.hasVisibleItems()) {
            C3835 c3835 = new C3835(this.f4816, subMenuC0664, this.f4821, this.f4817, this.f4806, 0);
            InterfaceC2316 interfaceC2316 = this.f4811;
            c3835.f14264 = interfaceC2316;
            AbstractC4053 abstractC4053 = c3835.f14259;
            if (abstractC4053 != null) {
                abstractC4053.mo3445(interfaceC2316);
            }
            int size = subMenuC0664.f9424.size();
            int i = 0;
            while (true) {
                if (i >= size) {
                    z = false;
                    break;
                }
                MenuItem item = subMenuC0664.getItem(i);
                if (item.isVisible() && item.getIcon() != null) {
                    z = true;
                    break;
                }
                i++;
            }
            c3835.f14256 = z;
            AbstractC4053 abstractC40532 = c3835.f14259;
            if (abstractC40532 != null) {
                abstractC40532.mo3548(z);
            }
            c3835.f14262 = this.f4819;
            this.f4819 = null;
            this.f4823.m6185(false);
            C2804 c2804 = this.f4813;
            int width = c2804.f14674;
            int iM8574 = c2804.m8574();
            if ((Gravity.getAbsoluteGravity(this.f4814, this.f4818.getLayoutDirection()) & 7) == 5) {
                width += this.f4818.getWidth();
            }
            if (!c3835.m8477()) {
                if (c3835.f14255 != null) {
                    c3835.m8478(width, iM8574, true, true);
                }
            }
            InterfaceC2316 interfaceC23162 = this.f4811;
            if (interfaceC23162 != null) {
                interfaceC23162.mo5174(subMenuC0664);
            }
            return true;
        }
        return false;
    }

    @Override // defpackage.InterfaceC0221
    /* renamed from: ᵶᵷᵕ */
    public final C1073 mo1524() {
        return this.f4813.f14684;
    }

    @Override // defpackage.AbstractC4053
    /* renamed from: ᵸʓᵠ, reason: contains not printable characters */
    public final void mo3549(PopupWindow.OnDismissListener onDismissListener) {
        this.f4819 = onDismissListener;
    }
}
