package o;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.HeaderViewListAdapter;
import android.widget.ListAdapter;
import androidx.appcompat.view.menu.ListMenuItemView;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class ZO extends C0097Dt {
    public LO A;
    public final int x;
    public final int y;
    public KO z;

    public ZO(Context context, boolean z) {
        super(context, z);
        if (1 == context.getResources().getConfiguration().getLayoutDirection()) {
            this.x = 21;
            this.y = 22;
        } else {
            this.x = 22;
            this.y = 21;
        }
    }

    @Override // o.C0097Dt, android.view.View
    public final boolean onHoverEvent(MotionEvent motionEvent) {
        C3089zO c3089zO;
        int headersCount;
        int iPointToPosition;
        int i;
        if (this.z != null) {
            ListAdapter adapter = getAdapter();
            if (adapter instanceof HeaderViewListAdapter) {
                HeaderViewListAdapter headerViewListAdapter = (HeaderViewListAdapter) adapter;
                headersCount = headerViewListAdapter.getHeadersCount();
                c3089zO = (C3089zO) headerViewListAdapter.getWrappedAdapter();
            } else {
                c3089zO = (C3089zO) adapter;
                headersCount = 0;
            }
            LO loB = (motionEvent.getAction() == 10 || (iPointToPosition = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY())) == -1 || (i = iPointToPosition - headersCount) < 0 || i >= c3089zO.getCount()) ? null : c3089zO.getItem(i);
            LO lo = this.A;
            if (lo != loB) {
                CO co = c3089zO.a;
                if (lo != null) {
                    this.z.d(co, lo);
                }
                this.A = loB;
                if (loB != null) {
                    this.z.f(co, loB);
                }
            }
        }
        return super.onHoverEvent(motionEvent);
    }

    @Override // android.widget.ListView, android.widget.AbsListView, android.view.View, android.view.KeyEvent.Callback
    public final boolean onKeyDown(int i, KeyEvent keyEvent) {
        ListMenuItemView listMenuItemView = (ListMenuItemView) getSelectedView();
        if (listMenuItemView != null && i == this.x) {
            if (listMenuItemView.isEnabled() && listMenuItemView.getItemData().hasSubMenu()) {
                performItemClick(listMenuItemView, getSelectedItemPosition(), getSelectedItemId());
            }
            return true;
        }
        if (listMenuItemView == null || i != this.y) {
            return super.onKeyDown(i, keyEvent);
        }
        setSelection(-1);
        ListAdapter adapter = getAdapter();
        (adapter instanceof HeaderViewListAdapter ? (C3089zO) ((HeaderViewListAdapter) adapter).getWrappedAdapter() : (C3089zO) adapter).a.c(false);
        return true;
    }

    public void setHoverListener(KO ko) {
        this.z = ko;
    }

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