169 lines
6.3 KiB
Java
169 lines
6.3 KiB
Java
package androidx.appcompat.widget;
|
|
|
|
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.ListMenuItemView;
|
|
import androidx.appcompat.view.menu.MenuAdapter;
|
|
import androidx.appcompat.view.menu.MenuBuilder;
|
|
import androidx.appcompat.view.menu.MenuItemImpl;
|
|
import java.lang.reflect.Method;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class MenuPopupWindow extends ListPopupWindow implements MenuItemHoverListener {
|
|
private static Method K;
|
|
private MenuItemHoverListener J;
|
|
|
|
public static class MenuDropDownListView extends DropDownListView {
|
|
final int o;
|
|
final int p;
|
|
private MenuItemHoverListener q;
|
|
private MenuItem r;
|
|
|
|
public MenuDropDownListView(Context context, boolean z) {
|
|
super(context, z);
|
|
Configuration configuration = context.getResources().getConfiguration();
|
|
if (Build.VERSION.SDK_INT < 17 || 1 != configuration.getLayoutDirection()) {
|
|
this.o = 22;
|
|
this.p = 21;
|
|
} else {
|
|
this.o = 21;
|
|
this.p = 22;
|
|
}
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.DropDownListView, android.view.View
|
|
public boolean onHoverEvent(MotionEvent motionEvent) {
|
|
int i;
|
|
MenuAdapter menuAdapter;
|
|
int pointToPosition;
|
|
int i2;
|
|
if (this.q != null) {
|
|
ListAdapter adapter = getAdapter();
|
|
if (adapter instanceof HeaderViewListAdapter) {
|
|
HeaderViewListAdapter headerViewListAdapter = (HeaderViewListAdapter) adapter;
|
|
i = headerViewListAdapter.getHeadersCount();
|
|
menuAdapter = (MenuAdapter) headerViewListAdapter.getWrappedAdapter();
|
|
} else {
|
|
i = 0;
|
|
menuAdapter = (MenuAdapter) adapter;
|
|
}
|
|
MenuItemImpl menuItemImpl = null;
|
|
if (motionEvent.getAction() != 10 && (pointToPosition = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY())) != -1 && (i2 = pointToPosition - i) >= 0 && i2 < menuAdapter.getCount()) {
|
|
menuItemImpl = menuAdapter.getItem(i2);
|
|
}
|
|
MenuItem menuItem = this.r;
|
|
if (menuItem != menuItemImpl) {
|
|
MenuBuilder b = menuAdapter.b();
|
|
if (menuItem != null) {
|
|
this.q.b(b, menuItem);
|
|
}
|
|
this.r = menuItemImpl;
|
|
if (menuItemImpl != null) {
|
|
this.q.a(b, menuItemImpl);
|
|
}
|
|
}
|
|
}
|
|
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.o) {
|
|
if (listMenuItemView.isEnabled() && listMenuItemView.getItemData().hasSubMenu()) {
|
|
performItemClick(listMenuItemView, getSelectedItemPosition(), getSelectedItemId());
|
|
}
|
|
return true;
|
|
}
|
|
if (listMenuItemView == null || i != this.p) {
|
|
return super.onKeyDown(i, keyEvent);
|
|
}
|
|
setSelection(-1);
|
|
((MenuAdapter) getAdapter()).b().a(false);
|
|
return true;
|
|
}
|
|
|
|
public void setHoverListener(MenuItemHoverListener menuItemHoverListener) {
|
|
this.q = menuItemHoverListener;
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.DropDownListView, android.widget.AbsListView
|
|
public /* bridge */ /* synthetic */ void setSelector(Drawable drawable) {
|
|
super.setSelector(drawable);
|
|
}
|
|
}
|
|
|
|
static {
|
|
try {
|
|
K = PopupWindow.class.getDeclaredMethod("setTouchModal", Boolean.TYPE);
|
|
} catch (NoSuchMethodException unused) {
|
|
Log.i("MenuPopupWindow", "Could not find method setTouchModal() on PopupWindow. Oh well.");
|
|
}
|
|
}
|
|
|
|
public MenuPopupWindow(Context context, AttributeSet attributeSet, int i, int i2) {
|
|
super(context, attributeSet, i, i2);
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.ListPopupWindow
|
|
DropDownListView a(Context context, boolean z) {
|
|
MenuDropDownListView menuDropDownListView = new MenuDropDownListView(context, z);
|
|
menuDropDownListView.setHoverListener(this);
|
|
return menuDropDownListView;
|
|
}
|
|
|
|
public void b(Object obj) {
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
this.F.setExitTransition((Transition) obj);
|
|
}
|
|
}
|
|
|
|
public void c(boolean z) {
|
|
Method method = K;
|
|
if (method != null) {
|
|
try {
|
|
method.invoke(this.F, Boolean.valueOf(z));
|
|
} catch (Exception unused) {
|
|
Log.i("MenuPopupWindow", "Could not invoke setTouchModal() on PopupWindow. Oh well.");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void a(Object obj) {
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
this.F.setEnterTransition((Transition) obj);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.MenuItemHoverListener
|
|
public void b(MenuBuilder menuBuilder, MenuItem menuItem) {
|
|
MenuItemHoverListener menuItemHoverListener = this.J;
|
|
if (menuItemHoverListener != null) {
|
|
menuItemHoverListener.b(menuBuilder, menuItem);
|
|
}
|
|
}
|
|
|
|
public void a(MenuItemHoverListener menuItemHoverListener) {
|
|
this.J = menuItemHoverListener;
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.MenuItemHoverListener
|
|
public void a(MenuBuilder menuBuilder, MenuItem menuItem) {
|
|
MenuItemHoverListener menuItemHoverListener = this.J;
|
|
if (menuItemHoverListener != null) {
|
|
menuItemHoverListener.a(menuBuilder, menuItem);
|
|
}
|
|
}
|
|
}
|