discord-jadx/app/src/main/java/androidx/appcompat/view/menu/StandardMenuPopup.java
2021-06-27 22:44:35 +02:00

301 lines
12 KiB
Java

package androidx.appcompat.view.menu;
import android.content.Context;
import android.content.res.Resources;
import android.os.Parcelable;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import androidx.appcompat.R;
import androidx.appcompat.view.menu.MenuPresenter;
import androidx.appcompat.widget.MenuPopupWindow;
import androidx.core.view.ViewCompat;
public final class StandardMenuPopup extends MenuPopup implements PopupWindow.OnDismissListener, AdapterView.OnItemClickListener, MenuPresenter, View.OnKeyListener {
private static final int ITEM_LAYOUT = R.layout.abc_popup_menu_item_layout;
private final MenuAdapter mAdapter;
private View mAnchorView;
private final View.OnAttachStateChangeListener mAttachStateChangeListener = new AnonymousClass2();
private int mContentWidth;
private final Context mContext;
private int mDropDownGravity = 0;
public final ViewTreeObserver.OnGlobalLayoutListener mGlobalLayoutListener = new AnonymousClass1();
private boolean mHasContentWidth;
private final MenuBuilder mMenu;
private PopupWindow.OnDismissListener mOnDismissListener;
private final boolean mOverflowOnly;
public final MenuPopupWindow mPopup;
private final int mPopupMaxWidth;
private final int mPopupStyleAttr;
private final int mPopupStyleRes;
private MenuPresenter.Callback mPresenterCallback;
private boolean mShowTitle;
public View mShownAnchorView;
public ViewTreeObserver mTreeObserver;
private boolean mWasDismissed;
/* renamed from: androidx.appcompat.view.menu.StandardMenuPopup$1 reason: invalid class name */
public class AnonymousClass1 implements ViewTreeObserver.OnGlobalLayoutListener {
public AnonymousClass1() {
}
@Override // android.view.ViewTreeObserver.OnGlobalLayoutListener
public void onGlobalLayout() {
if (StandardMenuPopup.this.isShowing() && !StandardMenuPopup.this.mPopup.isModal()) {
View view = StandardMenuPopup.this.mShownAnchorView;
if (view == null || !view.isShown()) {
StandardMenuPopup.this.dismiss();
} else {
StandardMenuPopup.this.mPopup.show();
}
}
}
}
/* renamed from: androidx.appcompat.view.menu.StandardMenuPopup$2 reason: invalid class name */
public class AnonymousClass2 implements View.OnAttachStateChangeListener {
public AnonymousClass2() {
}
@Override // android.view.View.OnAttachStateChangeListener
public void onViewAttachedToWindow(View view) {
}
@Override // android.view.View.OnAttachStateChangeListener
public void onViewDetachedFromWindow(View view) {
ViewTreeObserver viewTreeObserver = StandardMenuPopup.this.mTreeObserver;
if (viewTreeObserver != null) {
if (!viewTreeObserver.isAlive()) {
StandardMenuPopup.this.mTreeObserver = view.getViewTreeObserver();
}
StandardMenuPopup standardMenuPopup = StandardMenuPopup.this;
standardMenuPopup.mTreeObserver.removeGlobalOnLayoutListener(standardMenuPopup.mGlobalLayoutListener);
}
view.removeOnAttachStateChangeListener(this);
}
}
public StandardMenuPopup(Context context, MenuBuilder menuBuilder, View view, int i, int i2, boolean z2) {
this.mContext = context;
this.mMenu = menuBuilder;
this.mOverflowOnly = z2;
this.mAdapter = new MenuAdapter(menuBuilder, LayoutInflater.from(context), z2, ITEM_LAYOUT);
this.mPopupStyleAttr = i;
this.mPopupStyleRes = i2;
Resources resources = context.getResources();
this.mPopupMaxWidth = Math.max(resources.getDisplayMetrics().widthPixels / 2, resources.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth));
this.mAnchorView = view;
this.mPopup = new MenuPopupWindow(context, null, i, i2);
menuBuilder.addMenuPresenter(this, context);
}
private boolean tryShow() {
View view;
if (isShowing()) {
return true;
}
if (this.mWasDismissed || (view = this.mAnchorView) == null) {
return false;
}
this.mShownAnchorView = view;
this.mPopup.setOnDismissListener(this);
this.mPopup.setOnItemClickListener(this);
this.mPopup.setModal(true);
View view2 = this.mShownAnchorView;
boolean z2 = this.mTreeObserver == null;
ViewTreeObserver viewTreeObserver = view2.getViewTreeObserver();
this.mTreeObserver = viewTreeObserver;
if (z2) {
viewTreeObserver.addOnGlobalLayoutListener(this.mGlobalLayoutListener);
}
view2.addOnAttachStateChangeListener(this.mAttachStateChangeListener);
this.mPopup.setAnchorView(view2);
this.mPopup.setDropDownGravity(this.mDropDownGravity);
if (!this.mHasContentWidth) {
this.mContentWidth = MenuPopup.measureIndividualMenuWidth(this.mAdapter, null, this.mContext, this.mPopupMaxWidth);
this.mHasContentWidth = true;
}
this.mPopup.setContentWidth(this.mContentWidth);
this.mPopup.setInputMethodMode(2);
this.mPopup.setEpicenterBounds(getEpicenterBounds());
this.mPopup.show();
ListView listView = this.mPopup.getListView();
listView.setOnKeyListener(this);
if (this.mShowTitle && this.mMenu.getHeaderTitle() != null) {
FrameLayout frameLayout = (FrameLayout) LayoutInflater.from(this.mContext).inflate(R.layout.abc_popup_menu_header_item_layout, (ViewGroup) listView, false);
TextView textView = (TextView) frameLayout.findViewById(16908310);
if (textView != null) {
textView.setText(this.mMenu.getHeaderTitle());
}
frameLayout.setEnabled(false);
listView.addHeaderView(frameLayout, null, false);
}
this.mPopup.setAdapter(this.mAdapter);
this.mPopup.show();
return true;
}
@Override // androidx.appcompat.view.menu.MenuPopup
public void addMenu(MenuBuilder menuBuilder) {
}
@Override // androidx.appcompat.view.menu.ShowableListMenu
public void dismiss() {
if (isShowing()) {
this.mPopup.dismiss();
}
}
@Override // androidx.appcompat.view.menu.MenuPresenter
public boolean flagActionItems() {
return false;
}
@Override // androidx.appcompat.view.menu.ShowableListMenu
public ListView getListView() {
return this.mPopup.getListView();
}
@Override // androidx.appcompat.view.menu.ShowableListMenu
public boolean isShowing() {
return !this.mWasDismissed && this.mPopup.isShowing();
}
@Override // androidx.appcompat.view.menu.MenuPresenter
public void onCloseMenu(MenuBuilder menuBuilder, boolean z2) {
if (menuBuilder == this.mMenu) {
dismiss();
MenuPresenter.Callback callback = this.mPresenterCallback;
if (callback != null) {
callback.onCloseMenu(menuBuilder, z2);
}
}
}
@Override // android.widget.PopupWindow.OnDismissListener
public void onDismiss() {
this.mWasDismissed = true;
this.mMenu.close();
ViewTreeObserver viewTreeObserver = this.mTreeObserver;
if (viewTreeObserver != null) {
if (!viewTreeObserver.isAlive()) {
this.mTreeObserver = this.mShownAnchorView.getViewTreeObserver();
}
this.mTreeObserver.removeGlobalOnLayoutListener(this.mGlobalLayoutListener);
this.mTreeObserver = null;
}
this.mShownAnchorView.removeOnAttachStateChangeListener(this.mAttachStateChangeListener);
PopupWindow.OnDismissListener onDismissListener = this.mOnDismissListener;
if (onDismissListener != null) {
onDismissListener.onDismiss();
}
}
@Override // android.view.View.OnKeyListener
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (keyEvent.getAction() != 1 || i != 82) {
return false;
}
dismiss();
return true;
}
@Override // androidx.appcompat.view.menu.MenuPresenter
public void onRestoreInstanceState(Parcelable parcelable) {
}
@Override // androidx.appcompat.view.menu.MenuPresenter
public Parcelable onSaveInstanceState() {
return null;
}
@Override // androidx.appcompat.view.menu.MenuPresenter
public boolean onSubMenuSelected(SubMenuBuilder subMenuBuilder) {
if (subMenuBuilder.hasVisibleItems()) {
MenuPopupHelper menuPopupHelper = new MenuPopupHelper(this.mContext, subMenuBuilder, this.mShownAnchorView, this.mOverflowOnly, this.mPopupStyleAttr, this.mPopupStyleRes);
menuPopupHelper.setPresenterCallback(this.mPresenterCallback);
menuPopupHelper.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(subMenuBuilder));
menuPopupHelper.setOnDismissListener(this.mOnDismissListener);
this.mOnDismissListener = null;
this.mMenu.close(false);
int horizontalOffset = this.mPopup.getHorizontalOffset();
int verticalOffset = this.mPopup.getVerticalOffset();
if ((Gravity.getAbsoluteGravity(this.mDropDownGravity, ViewCompat.getLayoutDirection(this.mAnchorView)) & 7) == 5) {
horizontalOffset += this.mAnchorView.getWidth();
}
if (menuPopupHelper.tryShow(horizontalOffset, verticalOffset)) {
MenuPresenter.Callback callback = this.mPresenterCallback;
if (callback == null) {
return true;
}
callback.onOpenSubMenu(subMenuBuilder);
return true;
}
}
return false;
}
@Override // androidx.appcompat.view.menu.MenuPopup
public void setAnchorView(View view) {
this.mAnchorView = view;
}
@Override // androidx.appcompat.view.menu.MenuPresenter
public void setCallback(MenuPresenter.Callback callback) {
this.mPresenterCallback = callback;
}
@Override // androidx.appcompat.view.menu.MenuPopup
public void setForceShowIcon(boolean z2) {
this.mAdapter.setForceShowIcon(z2);
}
@Override // androidx.appcompat.view.menu.MenuPopup
public void setGravity(int i) {
this.mDropDownGravity = i;
}
@Override // androidx.appcompat.view.menu.MenuPopup
public void setHorizontalOffset(int i) {
this.mPopup.setHorizontalOffset(i);
}
@Override // androidx.appcompat.view.menu.MenuPopup
public void setOnDismissListener(PopupWindow.OnDismissListener onDismissListener) {
this.mOnDismissListener = onDismissListener;
}
@Override // androidx.appcompat.view.menu.MenuPopup
public void setShowTitle(boolean z2) {
this.mShowTitle = z2;
}
@Override // androidx.appcompat.view.menu.MenuPopup
public void setVerticalOffset(int i) {
this.mPopup.setVerticalOffset(i);
}
@Override // androidx.appcompat.view.menu.ShowableListMenu
public void show() {
if (!tryShow()) {
throw new IllegalStateException("StandardMenuPopup cannot be used without an anchor");
}
}
@Override // androidx.appcompat.view.menu.MenuPresenter
public void updateMenuView(boolean z2) {
this.mHasContentWidth = false;
MenuAdapter menuAdapter = this.mAdapter;
if (menuAdapter != null) {
menuAdapter.notifyDataSetChanged();
}
}
}