package p028j;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.transition.Transition;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.widget.HeaderViewListAdapter;
import android.widget.ListAdapter;
import android.widget.PopupWindow;
import androidx.appcompat.view.menu.C0102d;
import androidx.appcompat.view.menu.C0103e;
import androidx.appcompat.view.menu.C0107g;
import androidx.appcompat.view.menu.ListMenuItemView;
import java.lang.reflect.Method;

/* renamed from: j.t2 */
/* loaded from: classes.dex */
public class C1214t2 extends C1147m2 implements InterfaceC1186q2 {

    /* renamed from: N */
    public static Method f2922N;

    /* renamed from: M */
    public InterfaceC1186q2 f2923M;

    /* renamed from: j.t2$a */
    /* loaded from: classes.dex */
    public static class C1215a {
        /* renamed from: a */
        public static void m1851a(PopupWindow popupWindow, Transition transition) {
            popupWindow.setEnterTransition(transition);
        }

        /* renamed from: b */
        public static void m1850b(PopupWindow popupWindow, Transition transition) {
            popupWindow.setExitTransition(transition);
        }
    }

    /* renamed from: j.t2$b */
    /* loaded from: classes.dex */
    public static class C1216b {
        /* renamed from: a */
        public static void m1849a(PopupWindow popupWindow, boolean z) {
            popupWindow.setTouchModal(z);
        }
    }

    /* renamed from: j.t2$c */
    /* loaded from: classes.dex */
    public static class C1217c extends C1127k2 {

        /* renamed from: q */
        public final int f2924q;

        /* renamed from: r */
        public final int f2925r;

        /* renamed from: s */
        public InterfaceC1186q2 f2926s;

        /* renamed from: t */
        public MenuItem f2927t;

        /* renamed from: j.t2$c$a */
        /* loaded from: classes.dex */
        public static class C1218a {
            /* renamed from: a */
            public static int m1846a(Configuration configuration) {
                int layoutDirection;
                layoutDirection = configuration.getLayoutDirection();
                return layoutDirection;
            }
        }

        public C1217c(Context context, boolean z) {
            super(context, z);
            Configuration configuration = context.getResources().getConfiguration();
            if (Build.VERSION.SDK_INT < 17 || 1 != C1218a.m1846a(configuration)) {
                this.f2924q = 22;
                this.f2925r = 21;
                return;
            }
            this.f2924q = 21;
            this.f2925r = 22;
        }

        @Override // p028j.C1127k2
        /* renamed from: d */
        public /* bridge */ /* synthetic */ int mo1848d(int i, int i2, int i3, int i4, int i5) {
            return super.mo1848d(i, i2, i3, i4, i5);
        }

        @Override // p028j.C1127k2
        /* renamed from: e */
        public /* bridge */ /* synthetic */ boolean mo1847e(MotionEvent motionEvent, int i) {
            return super.mo1847e(motionEvent, i);
        }

        @Override // p028j.C1127k2, android.view.ViewGroup, android.view.View
        public /* bridge */ /* synthetic */ boolean hasFocus() {
            return super.hasFocus();
        }

        @Override // p028j.C1127k2, android.view.View
        public /* bridge */ /* synthetic */ boolean hasWindowFocus() {
            return super.hasWindowFocus();
        }

        @Override // p028j.C1127k2, android.view.View
        public /* bridge */ /* synthetic */ boolean isFocused() {
            return super.isFocused();
        }

        @Override // p028j.C1127k2, android.view.View
        public /* bridge */ /* synthetic */ boolean isInTouchMode() {
            return super.isInTouchMode();
        }

        @Override // p028j.C1127k2, android.view.View
        public boolean onHoverEvent(MotionEvent motionEvent) {
            C0102d c0102d;
            int i;
            int pointToPosition;
            int i2;
            if (this.f2926s != null) {
                ListAdapter adapter = getAdapter();
                if (adapter instanceof HeaderViewListAdapter) {
                    HeaderViewListAdapter headerViewListAdapter = (HeaderViewListAdapter) adapter;
                    i = headerViewListAdapter.getHeadersCount();
                    c0102d = (C0102d) headerViewListAdapter.getWrappedAdapter();
                } else {
                    c0102d = (C0102d) adapter;
                    i = 0;
                }
                C0107g item = (motionEvent.getAction() == 10 || (pointToPosition = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY())) == -1 || (i2 = pointToPosition - i) < 0 || i2 >= c0102d.getCount()) ? null : c0102d.getItem(i2);
                MenuItem menuItem = this.f2927t;
                if (menuItem != item) {
                    C0103e m4915b = c0102d.m4915b();
                    if (menuItem != null) {
                        this.f2926s.mo1853h(m4915b, menuItem);
                    }
                    this.f2927t = item;
                    if (item != null) {
                        this.f2926s.mo1854e(m4915b, item);
                    }
                }
            }
            return super.onHoverEvent(motionEvent);
        }

        @Override // android.widget.ListView, android.widget.AbsListView, android.view.View, android.view.KeyEvent.Callback
        public boolean onKeyDown(int i, KeyEvent keyEvent) {
            ListMenuItemView listMenuItemView = (ListMenuItemView) getSelectedView();
            if (listMenuItemView != null && i == this.f2924q) {
                if (listMenuItemView.isEnabled() && listMenuItemView.getItemData().hasSubMenu()) {
                    performItemClick(listMenuItemView, getSelectedItemPosition(), getSelectedItemId());
                }
                return true;
            } else if (listMenuItemView == null || i != this.f2925r) {
                return super.onKeyDown(i, keyEvent);
            } else {
                setSelection(-1);
                ListAdapter adapter = getAdapter();
                if (adapter instanceof HeaderViewListAdapter) {
                    adapter = ((HeaderViewListAdapter) adapter).getWrappedAdapter();
                }
                ((C0102d) adapter).m4915b().m4883e(false);
                return true;
            }
        }

        @Override // p028j.C1127k2, android.widget.AbsListView, android.view.View
        public /* bridge */ /* synthetic */ boolean onTouchEvent(MotionEvent motionEvent) {
            return super.onTouchEvent(motionEvent);
        }

        public void setHoverListener(InterfaceC1186q2 interfaceC1186q2) {
            this.f2926s = interfaceC1186q2;
        }

        @Override // p028j.C1127k2, android.widget.AbsListView
        public /* bridge */ /* synthetic */ void setSelector(Drawable drawable) {
            super.setSelector(drawable);
        }
    }

    static {
        try {
            if (Build.VERSION.SDK_INT <= 28) {
                f2922N = PopupWindow.class.getDeclaredMethod("setTouchModal", Boolean.TYPE);
            }
        } catch (NoSuchMethodException unused) {
            Log.i("MenuPopupWindow", "Could not find method setTouchModal() on PopupWindow. Oh well.");
        }
    }

    public C1214t2(Context context, AttributeSet attributeSet, int i, int i2) {
        super(context, attributeSet, i, i2);
    }

    /* renamed from: N */
    public void m1858N(Object obj) {
        if (Build.VERSION.SDK_INT >= 23) {
            C1215a.m1851a(this.f2790I, (Transition) obj);
        }
    }

    /* renamed from: O */
    public void m1857O(Object obj) {
        if (Build.VERSION.SDK_INT >= 23) {
            C1215a.m1850b(this.f2790I, (Transition) obj);
        }
    }

    /* renamed from: P */
    public void m1856P(InterfaceC1186q2 interfaceC1186q2) {
        this.f2923M = interfaceC1186q2;
    }

    /* renamed from: Q */
    public void m1855Q(boolean z) {
        if (Build.VERSION.SDK_INT > 28) {
            C1216b.m1849a(this.f2790I, z);
            return;
        }
        Method method = f2922N;
        if (method != null) {
            try {
                method.invoke(this.f2790I, Boolean.valueOf(z));
            } catch (Exception unused) {
                Log.i("MenuPopupWindow", "Could not invoke setTouchModal() on PopupWindow. Oh well.");
            }
        }
    }

    @Override // p028j.InterfaceC1186q2
    /* renamed from: e */
    public void mo1854e(C0103e c0103e, MenuItem menuItem) {
        InterfaceC1186q2 interfaceC1186q2 = this.f2923M;
        if (interfaceC1186q2 != null) {
            interfaceC1186q2.mo1854e(c0103e, menuItem);
        }
    }

    @Override // p028j.InterfaceC1186q2
    /* renamed from: h */
    public void mo1853h(C0103e c0103e, MenuItem menuItem) {
        InterfaceC1186q2 interfaceC1186q2 = this.f2923M;
        if (interfaceC1186q2 != null) {
            interfaceC1186q2.mo1853h(c0103e, menuItem);
        }
    }

    @Override // p028j.C1147m2
    /* renamed from: s */
    public C1127k2 mo1852s(Context context, boolean z) {
        C1217c c1217c = new C1217c(context, z);
        c1217c.setHoverListener(this);
        return c1217c;
    }
}