199 lines
6.9 KiB
Java
199 lines
6.9 KiB
Java
package androidx.appcompat.view.menu;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Point;
|
|
import android.graphics.Rect;
|
|
import android.view.Display;
|
|
import android.view.View;
|
|
import android.view.WindowManager;
|
|
import android.widget.ListView;
|
|
import android.widget.PopupWindow;
|
|
import androidx.annotation.AttrRes;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.annotation.StyleRes;
|
|
import androidx.appcompat.R;
|
|
import androidx.appcompat.view.menu.MenuPresenter;
|
|
import androidx.core.view.GravityCompat;
|
|
import androidx.core.view.ViewCompat;
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public class MenuPopupHelper implements MenuHelper {
|
|
private static final int TOUCH_EPICENTER_SIZE_DP = 48;
|
|
private View mAnchorView;
|
|
private final Context mContext;
|
|
private int mDropDownGravity;
|
|
private boolean mForceShowIcon;
|
|
private final PopupWindow.OnDismissListener mInternalOnDismissListener;
|
|
private final MenuBuilder mMenu;
|
|
private PopupWindow.OnDismissListener mOnDismissListener;
|
|
private final boolean mOverflowOnly;
|
|
private MenuPopup mPopup;
|
|
private final int mPopupStyleAttr;
|
|
private final int mPopupStyleRes;
|
|
private MenuPresenter.Callback mPresenterCallback;
|
|
|
|
/* renamed from: androidx.appcompat.view.menu.MenuPopupHelper$1 reason: invalid class name */
|
|
public class AnonymousClass1 implements PopupWindow.OnDismissListener {
|
|
public AnonymousClass1() {
|
|
}
|
|
|
|
@Override // android.widget.PopupWindow.OnDismissListener
|
|
public void onDismiss() {
|
|
MenuPopupHelper.this.onDismiss();
|
|
}
|
|
}
|
|
|
|
public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menuBuilder) {
|
|
this(context, menuBuilder, null, false, R.attr.popupMenuStyle, 0);
|
|
}
|
|
|
|
public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menuBuilder, @NonNull View view) {
|
|
this(context, menuBuilder, view, false, R.attr.popupMenuStyle, 0);
|
|
}
|
|
|
|
public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menuBuilder, @NonNull View view, boolean z2, @AttrRes int i) {
|
|
this(context, menuBuilder, view, z2, i, 0);
|
|
}
|
|
|
|
public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menuBuilder, @NonNull View view, boolean z2, @AttrRes int i, @StyleRes int i2) {
|
|
this.mDropDownGravity = GravityCompat.START;
|
|
this.mInternalOnDismissListener = new AnonymousClass1();
|
|
this.mContext = context;
|
|
this.mMenu = menuBuilder;
|
|
this.mAnchorView = view;
|
|
this.mOverflowOnly = z2;
|
|
this.mPopupStyleAttr = i;
|
|
this.mPopupStyleRes = i2;
|
|
}
|
|
|
|
@NonNull
|
|
private MenuPopup createPopup() {
|
|
Display defaultDisplay = ((WindowManager) this.mContext.getSystemService("window")).getDefaultDisplay();
|
|
Point point = new Point();
|
|
defaultDisplay.getRealSize(point);
|
|
MenuPopup cascadingMenuPopup = Math.min(point.x, point.y) >= this.mContext.getResources().getDimensionPixelSize(R.dimen.abc_cascading_menus_min_smallest_width) ? new CascadingMenuPopup(this.mContext, this.mAnchorView, this.mPopupStyleAttr, this.mPopupStyleRes, this.mOverflowOnly) : new StandardMenuPopup(this.mContext, this.mMenu, this.mAnchorView, this.mPopupStyleAttr, this.mPopupStyleRes, this.mOverflowOnly);
|
|
cascadingMenuPopup.addMenu(this.mMenu);
|
|
cascadingMenuPopup.setOnDismissListener(this.mInternalOnDismissListener);
|
|
cascadingMenuPopup.setAnchorView(this.mAnchorView);
|
|
cascadingMenuPopup.setCallback(this.mPresenterCallback);
|
|
cascadingMenuPopup.setForceShowIcon(this.mForceShowIcon);
|
|
cascadingMenuPopup.setGravity(this.mDropDownGravity);
|
|
return cascadingMenuPopup;
|
|
}
|
|
|
|
private void showPopup(int i, int i2, boolean z2, boolean z3) {
|
|
MenuPopup popup = getPopup();
|
|
popup.setShowTitle(z3);
|
|
if (z2) {
|
|
if ((GravityCompat.getAbsoluteGravity(this.mDropDownGravity, ViewCompat.getLayoutDirection(this.mAnchorView)) & 7) == 5) {
|
|
i -= this.mAnchorView.getWidth();
|
|
}
|
|
popup.setHorizontalOffset(i);
|
|
popup.setVerticalOffset(i2);
|
|
int i3 = (int) ((this.mContext.getResources().getDisplayMetrics().density * 48.0f) / 2.0f);
|
|
popup.setEpicenterBounds(new Rect(i - i3, i2 - i3, i + i3, i2 + i3));
|
|
}
|
|
popup.show();
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.MenuHelper
|
|
public void dismiss() {
|
|
if (isShowing()) {
|
|
this.mPopup.dismiss();
|
|
}
|
|
}
|
|
|
|
public int getGravity() {
|
|
return this.mDropDownGravity;
|
|
}
|
|
|
|
public ListView getListView() {
|
|
return getPopup().getListView();
|
|
}
|
|
|
|
@NonNull
|
|
public MenuPopup getPopup() {
|
|
if (this.mPopup == null) {
|
|
this.mPopup = createPopup();
|
|
}
|
|
return this.mPopup;
|
|
}
|
|
|
|
public boolean isShowing() {
|
|
MenuPopup menuPopup = this.mPopup;
|
|
return menuPopup != null && menuPopup.isShowing();
|
|
}
|
|
|
|
public void onDismiss() {
|
|
this.mPopup = null;
|
|
PopupWindow.OnDismissListener onDismissListener = this.mOnDismissListener;
|
|
if (onDismissListener != null) {
|
|
onDismissListener.onDismiss();
|
|
}
|
|
}
|
|
|
|
public void setAnchorView(@NonNull View view) {
|
|
this.mAnchorView = view;
|
|
}
|
|
|
|
public void setForceShowIcon(boolean z2) {
|
|
this.mForceShowIcon = z2;
|
|
MenuPopup menuPopup = this.mPopup;
|
|
if (menuPopup != null) {
|
|
menuPopup.setForceShowIcon(z2);
|
|
}
|
|
}
|
|
|
|
public void setGravity(int i) {
|
|
this.mDropDownGravity = i;
|
|
}
|
|
|
|
public void setOnDismissListener(@Nullable PopupWindow.OnDismissListener onDismissListener) {
|
|
this.mOnDismissListener = onDismissListener;
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.MenuHelper
|
|
public void setPresenterCallback(@Nullable MenuPresenter.Callback callback) {
|
|
this.mPresenterCallback = callback;
|
|
MenuPopup menuPopup = this.mPopup;
|
|
if (menuPopup != null) {
|
|
menuPopup.setCallback(callback);
|
|
}
|
|
}
|
|
|
|
public void show() {
|
|
if (!tryShow()) {
|
|
throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
|
|
}
|
|
}
|
|
|
|
public void show(int i, int i2) {
|
|
if (!tryShow(i, i2)) {
|
|
throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
|
|
}
|
|
}
|
|
|
|
public boolean tryShow() {
|
|
if (isShowing()) {
|
|
return true;
|
|
}
|
|
if (this.mAnchorView == null) {
|
|
return false;
|
|
}
|
|
showPopup(0, 0, false, false);
|
|
return true;
|
|
}
|
|
|
|
public boolean tryShow(int i, int i2) {
|
|
if (isShowing()) {
|
|
return true;
|
|
}
|
|
if (this.mAnchorView == null) {
|
|
return false;
|
|
}
|
|
showPopup(i, i2, true, true);
|
|
return true;
|
|
}
|
|
}
|