767 lines
30 KiB
Java
767 lines
30 KiB
Java
package androidx.appcompat.widget;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Context;
|
|
import android.content.res.Configuration;
|
|
import android.content.res.Resources;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.os.Parcel;
|
|
import android.os.Parcelable;
|
|
import android.util.SparseBooleanArray;
|
|
import android.view.MenuItem;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.appcompat.R;
|
|
import androidx.appcompat.view.ActionBarPolicy;
|
|
import androidx.appcompat.view.menu.ActionMenuItemView;
|
|
import androidx.appcompat.view.menu.BaseMenuPresenter;
|
|
import androidx.appcompat.view.menu.MenuBuilder;
|
|
import androidx.appcompat.view.menu.MenuItemImpl;
|
|
import androidx.appcompat.view.menu.MenuPopupHelper;
|
|
import androidx.appcompat.view.menu.MenuPresenter;
|
|
import androidx.appcompat.view.menu.MenuView;
|
|
import androidx.appcompat.view.menu.ShowableListMenu;
|
|
import androidx.appcompat.view.menu.SubMenuBuilder;
|
|
import androidx.appcompat.widget.ActionMenuView;
|
|
import androidx.core.graphics.drawable.DrawableCompat;
|
|
import androidx.core.view.ActionProvider;
|
|
import androidx.core.view.GravityCompat;
|
|
import java.util.ArrayList;
|
|
public class ActionMenuPresenter extends BaseMenuPresenter implements ActionProvider.SubUiVisibilityListener {
|
|
private static final String TAG = "ActionMenuPresenter";
|
|
private final SparseBooleanArray mActionButtonGroups = new SparseBooleanArray();
|
|
public ActionButtonSubmenu mActionButtonPopup;
|
|
private int mActionItemWidthLimit;
|
|
private boolean mExpandedActionViewsExclusive;
|
|
private int mMaxItems;
|
|
private boolean mMaxItemsSet;
|
|
private int mMinCellSize;
|
|
public int mOpenSubMenuId;
|
|
public OverflowMenuButton mOverflowButton;
|
|
public OverflowPopup mOverflowPopup;
|
|
private Drawable mPendingOverflowIcon;
|
|
private boolean mPendingOverflowIconSet;
|
|
private ActionMenuPopupCallback mPopupCallback;
|
|
public final PopupPresenterCallback mPopupPresenterCallback = new PopupPresenterCallback();
|
|
public OpenOverflowRunnable mPostedOpenRunnable;
|
|
private boolean mReserveOverflow;
|
|
private boolean mReserveOverflowSet;
|
|
private boolean mStrictWidthLimit;
|
|
private int mWidthLimit;
|
|
private boolean mWidthLimitSet;
|
|
|
|
public class ActionButtonSubmenu extends MenuPopupHelper {
|
|
public ActionButtonSubmenu(Context context, SubMenuBuilder subMenuBuilder, View view) {
|
|
super(context, subMenuBuilder, view, false, R.attr.actionOverflowMenuStyle);
|
|
if (!((MenuItemImpl) subMenuBuilder.getItem()).isActionButton()) {
|
|
View view2 = ActionMenuPresenter.this.mOverflowButton;
|
|
setAnchorView(view2 == null ? (View) ActionMenuPresenter.access$200(ActionMenuPresenter.this) : view2);
|
|
}
|
|
setPresenterCallback(ActionMenuPresenter.this.mPopupPresenterCallback);
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.MenuPopupHelper
|
|
public void onDismiss() {
|
|
ActionMenuPresenter actionMenuPresenter = ActionMenuPresenter.this;
|
|
actionMenuPresenter.mActionButtonPopup = null;
|
|
actionMenuPresenter.mOpenSubMenuId = 0;
|
|
super.onDismiss();
|
|
}
|
|
}
|
|
|
|
public class ActionMenuPopupCallback extends ActionMenuItemView.PopupCallback {
|
|
public ActionMenuPopupCallback() {
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.ActionMenuItemView.PopupCallback
|
|
public ShowableListMenu getPopup() {
|
|
ActionButtonSubmenu actionButtonSubmenu = ActionMenuPresenter.this.mActionButtonPopup;
|
|
if (actionButtonSubmenu != null) {
|
|
return actionButtonSubmenu.getPopup();
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public class OpenOverflowRunnable implements Runnable {
|
|
private OverflowPopup mPopup;
|
|
|
|
public OpenOverflowRunnable(OverflowPopup overflowPopup) {
|
|
this.mPopup = overflowPopup;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
if (ActionMenuPresenter.access$400(ActionMenuPresenter.this) != null) {
|
|
ActionMenuPresenter.access$500(ActionMenuPresenter.this).changeMenuMode();
|
|
}
|
|
View view = (View) ActionMenuPresenter.access$600(ActionMenuPresenter.this);
|
|
if (!(view == null || view.getWindowToken() == null || !this.mPopup.tryShow())) {
|
|
ActionMenuPresenter.this.mOverflowPopup = this.mPopup;
|
|
}
|
|
ActionMenuPresenter.this.mPostedOpenRunnable = null;
|
|
}
|
|
}
|
|
|
|
public class OverflowMenuButton extends AppCompatImageView implements ActionMenuView.ActionMenuChildView {
|
|
|
|
/* renamed from: androidx.appcompat.widget.ActionMenuPresenter$OverflowMenuButton$1 reason: invalid class name */
|
|
public class AnonymousClass1 extends ForwardingListener {
|
|
public final /* synthetic */ ActionMenuPresenter val$this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public AnonymousClass1(View view, ActionMenuPresenter actionMenuPresenter) {
|
|
super(view);
|
|
this.val$this$0 = actionMenuPresenter;
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.ForwardingListener
|
|
public ShowableListMenu getPopup() {
|
|
OverflowPopup overflowPopup = ActionMenuPresenter.this.mOverflowPopup;
|
|
if (overflowPopup == null) {
|
|
return null;
|
|
}
|
|
return overflowPopup.getPopup();
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.ForwardingListener
|
|
public boolean onForwardingStarted() {
|
|
ActionMenuPresenter.this.showOverflowMenu();
|
|
return true;
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.ForwardingListener
|
|
public boolean onForwardingStopped() {
|
|
ActionMenuPresenter actionMenuPresenter = ActionMenuPresenter.this;
|
|
if (actionMenuPresenter.mPostedOpenRunnable != null) {
|
|
return false;
|
|
}
|
|
actionMenuPresenter.hideOverflowMenu();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public OverflowMenuButton(Context context) {
|
|
super(context, null, R.attr.actionOverflowButtonStyle);
|
|
setClickable(true);
|
|
setFocusable(true);
|
|
setVisibility(0);
|
|
setEnabled(true);
|
|
TooltipCompat.setTooltipText(this, getContentDescription());
|
|
setOnTouchListener(new AnonymousClass1(this, ActionMenuPresenter.this));
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.ActionMenuView.ActionMenuChildView
|
|
public boolean needsDividerAfter() {
|
|
return false;
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.ActionMenuView.ActionMenuChildView
|
|
public boolean needsDividerBefore() {
|
|
return false;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public boolean performClick() {
|
|
if (super.performClick()) {
|
|
return true;
|
|
}
|
|
playSoundEffect(0);
|
|
ActionMenuPresenter.this.showOverflowMenu();
|
|
return true;
|
|
}
|
|
|
|
@Override // android.widget.ImageView
|
|
public boolean setFrame(int i, int i2, int i3, int i4) {
|
|
boolean frame = super.setFrame(i, i2, i3, i4);
|
|
Drawable drawable = getDrawable();
|
|
Drawable background = getBackground();
|
|
if (!(drawable == null || background == null)) {
|
|
int width = getWidth();
|
|
int height = getHeight();
|
|
int max = Math.max(width, height) / 2;
|
|
int paddingLeft = (width + (getPaddingLeft() - getPaddingRight())) / 2;
|
|
int paddingTop = (height + (getPaddingTop() - getPaddingBottom())) / 2;
|
|
DrawableCompat.setHotspotBounds(background, paddingLeft - max, paddingTop - max, paddingLeft + max, paddingTop + max);
|
|
}
|
|
return frame;
|
|
}
|
|
}
|
|
|
|
public class OverflowPopup extends MenuPopupHelper {
|
|
public OverflowPopup(Context context, MenuBuilder menuBuilder, View view, boolean z2) {
|
|
super(context, menuBuilder, view, z2, R.attr.actionOverflowMenuStyle);
|
|
setGravity(GravityCompat.END);
|
|
setPresenterCallback(ActionMenuPresenter.this.mPopupPresenterCallback);
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.MenuPopupHelper
|
|
public void onDismiss() {
|
|
if (ActionMenuPresenter.access$000(ActionMenuPresenter.this) != null) {
|
|
ActionMenuPresenter.access$100(ActionMenuPresenter.this).close();
|
|
}
|
|
ActionMenuPresenter.this.mOverflowPopup = null;
|
|
super.onDismiss();
|
|
}
|
|
}
|
|
|
|
public class PopupPresenterCallback implements MenuPresenter.Callback {
|
|
public PopupPresenterCallback() {
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.MenuPresenter.Callback
|
|
public void onCloseMenu(@NonNull MenuBuilder menuBuilder, boolean z2) {
|
|
if (menuBuilder instanceof SubMenuBuilder) {
|
|
menuBuilder.getRootMenu().close(false);
|
|
}
|
|
MenuPresenter.Callback callback = ActionMenuPresenter.this.getCallback();
|
|
if (callback != null) {
|
|
callback.onCloseMenu(menuBuilder, z2);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.MenuPresenter.Callback
|
|
public boolean onOpenSubMenu(@NonNull MenuBuilder menuBuilder) {
|
|
if (menuBuilder == ActionMenuPresenter.access$300(ActionMenuPresenter.this)) {
|
|
return false;
|
|
}
|
|
ActionMenuPresenter.this.mOpenSubMenuId = ((SubMenuBuilder) menuBuilder).getItem().getItemId();
|
|
MenuPresenter.Callback callback = ActionMenuPresenter.this.getCallback();
|
|
if (callback != null) {
|
|
return callback.onOpenSubMenu(menuBuilder);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@SuppressLint({"BanParcelableUsage"})
|
|
public static class SavedState implements Parcelable {
|
|
public static final Parcelable.Creator<SavedState> CREATOR = new AnonymousClass1();
|
|
public int openSubMenuId;
|
|
|
|
/* renamed from: androidx.appcompat.widget.ActionMenuPresenter$SavedState$1 reason: invalid class name */
|
|
public class AnonymousClass1 implements Parcelable.Creator<SavedState> {
|
|
@Override // android.os.Parcelable.Creator
|
|
public SavedState createFromParcel(Parcel parcel) {
|
|
return new SavedState(parcel);
|
|
}
|
|
|
|
@Override // android.os.Parcelable.Creator
|
|
public SavedState[] newArray(int i) {
|
|
return new SavedState[i];
|
|
}
|
|
}
|
|
|
|
public SavedState() {
|
|
}
|
|
|
|
public SavedState(Parcel parcel) {
|
|
this.openSubMenuId = parcel.readInt();
|
|
}
|
|
|
|
@Override // android.os.Parcelable
|
|
public int describeContents() {
|
|
return 0;
|
|
}
|
|
|
|
@Override // android.os.Parcelable
|
|
public void writeToParcel(Parcel parcel, int i) {
|
|
parcel.writeInt(this.openSubMenuId);
|
|
}
|
|
}
|
|
|
|
public ActionMenuPresenter(Context context) {
|
|
super(context, R.layout.abc_action_menu_layout, R.layout.abc_action_menu_item_layout);
|
|
}
|
|
|
|
public static /* synthetic */ MenuBuilder access$000(ActionMenuPresenter actionMenuPresenter) {
|
|
return actionMenuPresenter.mMenu;
|
|
}
|
|
|
|
public static /* synthetic */ MenuBuilder access$100(ActionMenuPresenter actionMenuPresenter) {
|
|
return actionMenuPresenter.mMenu;
|
|
}
|
|
|
|
public static /* synthetic */ MenuView access$200(ActionMenuPresenter actionMenuPresenter) {
|
|
return actionMenuPresenter.mMenuView;
|
|
}
|
|
|
|
public static /* synthetic */ MenuBuilder access$300(ActionMenuPresenter actionMenuPresenter) {
|
|
return actionMenuPresenter.mMenu;
|
|
}
|
|
|
|
public static /* synthetic */ MenuBuilder access$400(ActionMenuPresenter actionMenuPresenter) {
|
|
return actionMenuPresenter.mMenu;
|
|
}
|
|
|
|
public static /* synthetic */ MenuBuilder access$500(ActionMenuPresenter actionMenuPresenter) {
|
|
return actionMenuPresenter.mMenu;
|
|
}
|
|
|
|
public static /* synthetic */ MenuView access$600(ActionMenuPresenter actionMenuPresenter) {
|
|
return actionMenuPresenter.mMenuView;
|
|
}
|
|
|
|
private View findViewForItem(MenuItem menuItem) {
|
|
ViewGroup viewGroup = (ViewGroup) this.mMenuView;
|
|
if (viewGroup == null) {
|
|
return null;
|
|
}
|
|
int childCount = viewGroup.getChildCount();
|
|
for (int i = 0; i < childCount; i++) {
|
|
View childAt = viewGroup.getChildAt(i);
|
|
if ((childAt instanceof MenuView.ItemView) && ((MenuView.ItemView) childAt).getItemData() == menuItem) {
|
|
return childAt;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.BaseMenuPresenter
|
|
public void bindItemView(MenuItemImpl menuItemImpl, MenuView.ItemView itemView) {
|
|
itemView.initialize(menuItemImpl, 0);
|
|
ActionMenuItemView actionMenuItemView = (ActionMenuItemView) itemView;
|
|
actionMenuItemView.setItemInvoker((ActionMenuView) this.mMenuView);
|
|
if (this.mPopupCallback == null) {
|
|
this.mPopupCallback = new ActionMenuPopupCallback();
|
|
}
|
|
actionMenuItemView.setPopupCallback(this.mPopupCallback);
|
|
}
|
|
|
|
public boolean dismissPopupMenus() {
|
|
return hideOverflowMenu() | hideSubMenus();
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.BaseMenuPresenter
|
|
public boolean filterLeftoverView(ViewGroup viewGroup, int i) {
|
|
if (viewGroup.getChildAt(i) == this.mOverflowButton) {
|
|
return false;
|
|
}
|
|
return super.filterLeftoverView(viewGroup, i);
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.BaseMenuPresenter, androidx.appcompat.view.menu.MenuPresenter
|
|
public boolean flagActionItems() {
|
|
int i;
|
|
ArrayList<MenuItemImpl> arrayList;
|
|
int i2;
|
|
int i3;
|
|
int i4;
|
|
ActionMenuPresenter actionMenuPresenter = this;
|
|
MenuBuilder menuBuilder = actionMenuPresenter.mMenu;
|
|
View view = null;
|
|
int i5 = 0;
|
|
if (menuBuilder != null) {
|
|
arrayList = menuBuilder.getVisibleItems();
|
|
i = arrayList.size();
|
|
} else {
|
|
arrayList = null;
|
|
i = 0;
|
|
}
|
|
int i6 = actionMenuPresenter.mMaxItems;
|
|
int i7 = actionMenuPresenter.mActionItemWidthLimit;
|
|
int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, 0);
|
|
ViewGroup viewGroup = (ViewGroup) actionMenuPresenter.mMenuView;
|
|
boolean z2 = false;
|
|
int i8 = 0;
|
|
int i9 = 0;
|
|
for (int i10 = 0; i10 < i; i10++) {
|
|
MenuItemImpl menuItemImpl = arrayList.get(i10);
|
|
if (menuItemImpl.requiresActionButton()) {
|
|
i8++;
|
|
} else if (menuItemImpl.requestsActionButton()) {
|
|
i9++;
|
|
} else {
|
|
z2 = true;
|
|
}
|
|
if (actionMenuPresenter.mExpandedActionViewsExclusive && menuItemImpl.isActionViewExpanded()) {
|
|
i6 = 0;
|
|
}
|
|
}
|
|
if (actionMenuPresenter.mReserveOverflow && (z2 || i9 + i8 > i6)) {
|
|
i6--;
|
|
}
|
|
int i11 = i6 - i8;
|
|
SparseBooleanArray sparseBooleanArray = actionMenuPresenter.mActionButtonGroups;
|
|
sparseBooleanArray.clear();
|
|
if (actionMenuPresenter.mStrictWidthLimit) {
|
|
int i12 = actionMenuPresenter.mMinCellSize;
|
|
i3 = i7 / i12;
|
|
i2 = ((i7 % i12) / i3) + i12;
|
|
} else {
|
|
i3 = 0;
|
|
i2 = 0;
|
|
}
|
|
int i13 = 0;
|
|
int i14 = 0;
|
|
while (i13 < i) {
|
|
MenuItemImpl menuItemImpl2 = arrayList.get(i13);
|
|
if (menuItemImpl2.requiresActionButton()) {
|
|
View itemView = actionMenuPresenter.getItemView(menuItemImpl2, view, viewGroup);
|
|
if (actionMenuPresenter.mStrictWidthLimit) {
|
|
i3 -= ActionMenuView.measureChildForCells(itemView, i2, i3, makeMeasureSpec, i5);
|
|
} else {
|
|
itemView.measure(makeMeasureSpec, makeMeasureSpec);
|
|
}
|
|
int measuredWidth = itemView.getMeasuredWidth();
|
|
i7 -= measuredWidth;
|
|
if (i14 == 0) {
|
|
i14 = measuredWidth;
|
|
}
|
|
int groupId = menuItemImpl2.getGroupId();
|
|
if (groupId != 0) {
|
|
sparseBooleanArray.put(groupId, true);
|
|
}
|
|
menuItemImpl2.setIsActionButton(true);
|
|
i4 = i;
|
|
} else if (menuItemImpl2.requestsActionButton()) {
|
|
int groupId2 = menuItemImpl2.getGroupId();
|
|
boolean z3 = sparseBooleanArray.get(groupId2);
|
|
boolean z4 = (i11 > 0 || z3) && i7 > 0 && (!actionMenuPresenter.mStrictWidthLimit || i3 > 0);
|
|
boolean z5 = z4;
|
|
i4 = i;
|
|
if (z4) {
|
|
View itemView2 = actionMenuPresenter.getItemView(menuItemImpl2, null, viewGroup);
|
|
if (actionMenuPresenter.mStrictWidthLimit) {
|
|
int measureChildForCells = ActionMenuView.measureChildForCells(itemView2, i2, i3, makeMeasureSpec, 0);
|
|
i3 -= measureChildForCells;
|
|
if (measureChildForCells == 0) {
|
|
z5 = false;
|
|
}
|
|
} else {
|
|
itemView2.measure(makeMeasureSpec, makeMeasureSpec);
|
|
}
|
|
int measuredWidth2 = itemView2.getMeasuredWidth();
|
|
i7 -= measuredWidth2;
|
|
if (i14 == 0) {
|
|
i14 = measuredWidth2;
|
|
}
|
|
z4 = z5 & (!actionMenuPresenter.mStrictWidthLimit ? i7 + i14 > 0 : i7 >= 0);
|
|
}
|
|
if (z4 && groupId2 != 0) {
|
|
sparseBooleanArray.put(groupId2, true);
|
|
} else if (z3) {
|
|
sparseBooleanArray.put(groupId2, false);
|
|
for (int i15 = 0; i15 < i13; i15++) {
|
|
MenuItemImpl menuItemImpl3 = arrayList.get(i15);
|
|
if (menuItemImpl3.getGroupId() == groupId2) {
|
|
if (menuItemImpl3.isActionButton()) {
|
|
i11++;
|
|
}
|
|
menuItemImpl3.setIsActionButton(false);
|
|
}
|
|
}
|
|
}
|
|
if (z4) {
|
|
i11--;
|
|
}
|
|
menuItemImpl2.setIsActionButton(z4);
|
|
} else {
|
|
i4 = i;
|
|
menuItemImpl2.setIsActionButton(false);
|
|
i13++;
|
|
view = null;
|
|
actionMenuPresenter = this;
|
|
i = i4;
|
|
i5 = 0;
|
|
}
|
|
i13++;
|
|
view = null;
|
|
actionMenuPresenter = this;
|
|
i = i4;
|
|
i5 = 0;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.BaseMenuPresenter
|
|
public View getItemView(MenuItemImpl menuItemImpl, View view, ViewGroup viewGroup) {
|
|
View actionView = menuItemImpl.getActionView();
|
|
if (actionView == null || menuItemImpl.hasCollapsibleActionView()) {
|
|
actionView = super.getItemView(menuItemImpl, view, viewGroup);
|
|
}
|
|
actionView.setVisibility(menuItemImpl.isActionViewExpanded() ? 8 : 0);
|
|
ActionMenuView actionMenuView = (ActionMenuView) viewGroup;
|
|
ViewGroup.LayoutParams layoutParams = actionView.getLayoutParams();
|
|
if (!actionMenuView.checkLayoutParams(layoutParams)) {
|
|
actionView.setLayoutParams(actionMenuView.generateLayoutParams(layoutParams));
|
|
}
|
|
return actionView;
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.BaseMenuPresenter, androidx.appcompat.view.menu.MenuPresenter
|
|
public MenuView getMenuView(ViewGroup viewGroup) {
|
|
MenuView menuView = this.mMenuView;
|
|
MenuView menuView2 = super.getMenuView(viewGroup);
|
|
if (menuView != menuView2) {
|
|
((ActionMenuView) menuView2).setPresenter(this);
|
|
}
|
|
return menuView2;
|
|
}
|
|
|
|
public Drawable getOverflowIcon() {
|
|
OverflowMenuButton overflowMenuButton = this.mOverflowButton;
|
|
if (overflowMenuButton != null) {
|
|
return overflowMenuButton.getDrawable();
|
|
}
|
|
if (this.mPendingOverflowIconSet) {
|
|
return this.mPendingOverflowIcon;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public boolean hideOverflowMenu() {
|
|
MenuView menuView;
|
|
OpenOverflowRunnable openOverflowRunnable = this.mPostedOpenRunnable;
|
|
if (openOverflowRunnable == null || (menuView = this.mMenuView) == null) {
|
|
OverflowPopup overflowPopup = this.mOverflowPopup;
|
|
if (overflowPopup == null) {
|
|
return false;
|
|
}
|
|
overflowPopup.dismiss();
|
|
return true;
|
|
}
|
|
((View) menuView).removeCallbacks(openOverflowRunnable);
|
|
this.mPostedOpenRunnable = null;
|
|
return true;
|
|
}
|
|
|
|
public boolean hideSubMenus() {
|
|
ActionButtonSubmenu actionButtonSubmenu = this.mActionButtonPopup;
|
|
if (actionButtonSubmenu == null) {
|
|
return false;
|
|
}
|
|
actionButtonSubmenu.dismiss();
|
|
return true;
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.BaseMenuPresenter, androidx.appcompat.view.menu.MenuPresenter
|
|
public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menuBuilder) {
|
|
super.initForMenu(context, menuBuilder);
|
|
Resources resources = context.getResources();
|
|
ActionBarPolicy actionBarPolicy = ActionBarPolicy.get(context);
|
|
if (!this.mReserveOverflowSet) {
|
|
this.mReserveOverflow = actionBarPolicy.showsOverflowMenuButton();
|
|
}
|
|
if (!this.mWidthLimitSet) {
|
|
this.mWidthLimit = actionBarPolicy.getEmbeddedMenuWidthLimit();
|
|
}
|
|
if (!this.mMaxItemsSet) {
|
|
this.mMaxItems = actionBarPolicy.getMaxActionButtons();
|
|
}
|
|
int i = this.mWidthLimit;
|
|
if (this.mReserveOverflow) {
|
|
if (this.mOverflowButton == null) {
|
|
OverflowMenuButton overflowMenuButton = new OverflowMenuButton(this.mSystemContext);
|
|
this.mOverflowButton = overflowMenuButton;
|
|
if (this.mPendingOverflowIconSet) {
|
|
overflowMenuButton.setImageDrawable(this.mPendingOverflowIcon);
|
|
this.mPendingOverflowIcon = null;
|
|
this.mPendingOverflowIconSet = false;
|
|
}
|
|
int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, 0);
|
|
this.mOverflowButton.measure(makeMeasureSpec, makeMeasureSpec);
|
|
}
|
|
i -= this.mOverflowButton.getMeasuredWidth();
|
|
} else {
|
|
this.mOverflowButton = null;
|
|
}
|
|
this.mActionItemWidthLimit = i;
|
|
this.mMinCellSize = (int) (resources.getDisplayMetrics().density * 56.0f);
|
|
}
|
|
|
|
public boolean isOverflowMenuShowPending() {
|
|
return this.mPostedOpenRunnable != null || isOverflowMenuShowing();
|
|
}
|
|
|
|
public boolean isOverflowMenuShowing() {
|
|
OverflowPopup overflowPopup = this.mOverflowPopup;
|
|
return overflowPopup != null && overflowPopup.isShowing();
|
|
}
|
|
|
|
public boolean isOverflowReserved() {
|
|
return this.mReserveOverflow;
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.BaseMenuPresenter, androidx.appcompat.view.menu.MenuPresenter
|
|
public void onCloseMenu(MenuBuilder menuBuilder, boolean z2) {
|
|
dismissPopupMenus();
|
|
super.onCloseMenu(menuBuilder, z2);
|
|
}
|
|
|
|
public void onConfigurationChanged(Configuration configuration) {
|
|
if (!this.mMaxItemsSet) {
|
|
this.mMaxItems = ActionBarPolicy.get(this.mContext).getMaxActionButtons();
|
|
}
|
|
MenuBuilder menuBuilder = this.mMenu;
|
|
if (menuBuilder != null) {
|
|
menuBuilder.onItemsChanged(true);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.MenuPresenter
|
|
public void onRestoreInstanceState(Parcelable parcelable) {
|
|
int i;
|
|
MenuItem findItem;
|
|
if ((parcelable instanceof SavedState) && (i = ((SavedState) parcelable).openSubMenuId) > 0 && (findItem = this.mMenu.findItem(i)) != null) {
|
|
onSubMenuSelected((SubMenuBuilder) findItem.getSubMenu());
|
|
}
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.MenuPresenter
|
|
public Parcelable onSaveInstanceState() {
|
|
SavedState savedState = new SavedState();
|
|
savedState.openSubMenuId = this.mOpenSubMenuId;
|
|
return savedState;
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.BaseMenuPresenter, androidx.appcompat.view.menu.MenuPresenter
|
|
public boolean onSubMenuSelected(SubMenuBuilder subMenuBuilder) {
|
|
boolean z2 = false;
|
|
if (!subMenuBuilder.hasVisibleItems()) {
|
|
return false;
|
|
}
|
|
SubMenuBuilder subMenuBuilder2 = subMenuBuilder;
|
|
while (subMenuBuilder2.getParentMenu() != this.mMenu) {
|
|
subMenuBuilder2 = (SubMenuBuilder) subMenuBuilder2.getParentMenu();
|
|
}
|
|
View findViewForItem = findViewForItem(subMenuBuilder2.getItem());
|
|
if (findViewForItem == null) {
|
|
return false;
|
|
}
|
|
this.mOpenSubMenuId = subMenuBuilder.getItem().getItemId();
|
|
int size = subMenuBuilder.size();
|
|
int i = 0;
|
|
while (true) {
|
|
if (i >= size) {
|
|
break;
|
|
}
|
|
MenuItem item = subMenuBuilder.getItem(i);
|
|
if (item.isVisible() && item.getIcon() != null) {
|
|
z2 = true;
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
ActionButtonSubmenu actionButtonSubmenu = new ActionButtonSubmenu(this.mContext, subMenuBuilder, findViewForItem);
|
|
this.mActionButtonPopup = actionButtonSubmenu;
|
|
actionButtonSubmenu.setForceShowIcon(z2);
|
|
this.mActionButtonPopup.show();
|
|
super.onSubMenuSelected(subMenuBuilder);
|
|
return true;
|
|
}
|
|
|
|
@Override // androidx.core.view.ActionProvider.SubUiVisibilityListener
|
|
public void onSubUiVisibilityChanged(boolean z2) {
|
|
if (z2) {
|
|
super.onSubMenuSelected(null);
|
|
return;
|
|
}
|
|
MenuBuilder menuBuilder = this.mMenu;
|
|
if (menuBuilder != null) {
|
|
menuBuilder.close(false);
|
|
}
|
|
}
|
|
|
|
public void setExpandedActionViewsExclusive(boolean z2) {
|
|
this.mExpandedActionViewsExclusive = z2;
|
|
}
|
|
|
|
public void setItemLimit(int i) {
|
|
this.mMaxItems = i;
|
|
this.mMaxItemsSet = true;
|
|
}
|
|
|
|
public void setMenuView(ActionMenuView actionMenuView) {
|
|
this.mMenuView = actionMenuView;
|
|
actionMenuView.initialize(this.mMenu);
|
|
}
|
|
|
|
public void setOverflowIcon(Drawable drawable) {
|
|
OverflowMenuButton overflowMenuButton = this.mOverflowButton;
|
|
if (overflowMenuButton != null) {
|
|
overflowMenuButton.setImageDrawable(drawable);
|
|
return;
|
|
}
|
|
this.mPendingOverflowIconSet = true;
|
|
this.mPendingOverflowIcon = drawable;
|
|
}
|
|
|
|
public void setReserveOverflow(boolean z2) {
|
|
this.mReserveOverflow = z2;
|
|
this.mReserveOverflowSet = true;
|
|
}
|
|
|
|
public void setWidthLimit(int i, boolean z2) {
|
|
this.mWidthLimit = i;
|
|
this.mStrictWidthLimit = z2;
|
|
this.mWidthLimitSet = true;
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.BaseMenuPresenter
|
|
public boolean shouldIncludeItem(int i, MenuItemImpl menuItemImpl) {
|
|
return menuItemImpl.isActionButton();
|
|
}
|
|
|
|
public boolean showOverflowMenu() {
|
|
MenuBuilder menuBuilder;
|
|
if (!this.mReserveOverflow || isOverflowMenuShowing() || (menuBuilder = this.mMenu) == null || this.mMenuView == null || this.mPostedOpenRunnable != null || menuBuilder.getNonActionItems().isEmpty()) {
|
|
return false;
|
|
}
|
|
OpenOverflowRunnable openOverflowRunnable = new OpenOverflowRunnable(new OverflowPopup(this.mContext, this.mMenu, this.mOverflowButton, true));
|
|
this.mPostedOpenRunnable = openOverflowRunnable;
|
|
((View) this.mMenuView).post(openOverflowRunnable);
|
|
return true;
|
|
}
|
|
|
|
@Override // androidx.appcompat.view.menu.BaseMenuPresenter, androidx.appcompat.view.menu.MenuPresenter
|
|
public void updateMenuView(boolean z2) {
|
|
MenuView menuView;
|
|
super.updateMenuView(z2);
|
|
((View) this.mMenuView).requestLayout();
|
|
MenuBuilder menuBuilder = this.mMenu;
|
|
boolean z3 = false;
|
|
if (menuBuilder != null) {
|
|
ArrayList<MenuItemImpl> actionItems = menuBuilder.getActionItems();
|
|
int size = actionItems.size();
|
|
for (int i = 0; i < size; i++) {
|
|
ActionProvider supportActionProvider = actionItems.get(i).getSupportActionProvider();
|
|
if (supportActionProvider != null) {
|
|
supportActionProvider.setSubUiVisibilityListener(this);
|
|
}
|
|
}
|
|
}
|
|
MenuBuilder menuBuilder2 = this.mMenu;
|
|
ArrayList<MenuItemImpl> nonActionItems = menuBuilder2 != null ? menuBuilder2.getNonActionItems() : null;
|
|
if (this.mReserveOverflow && nonActionItems != null) {
|
|
int size2 = nonActionItems.size();
|
|
if (size2 == 1) {
|
|
z3 = !nonActionItems.get(0).isActionViewExpanded();
|
|
} else if (size2 > 0) {
|
|
z3 = true;
|
|
}
|
|
}
|
|
if (z3) {
|
|
if (this.mOverflowButton == null) {
|
|
this.mOverflowButton = new OverflowMenuButton(this.mSystemContext);
|
|
}
|
|
ViewGroup viewGroup = (ViewGroup) this.mOverflowButton.getParent();
|
|
if (viewGroup != this.mMenuView) {
|
|
if (viewGroup != null) {
|
|
viewGroup.removeView(this.mOverflowButton);
|
|
}
|
|
ActionMenuView actionMenuView = (ActionMenuView) this.mMenuView;
|
|
actionMenuView.addView(this.mOverflowButton, actionMenuView.generateOverflowButtonLayoutParams());
|
|
}
|
|
} else {
|
|
OverflowMenuButton overflowMenuButton = this.mOverflowButton;
|
|
if (overflowMenuButton != null && overflowMenuButton.getParent() == (menuView = this.mMenuView)) {
|
|
((ViewGroup) menuView).removeView(this.mOverflowButton);
|
|
}
|
|
}
|
|
((ActionMenuView) this.mMenuView).setOverflowReserved(this.mReserveOverflow);
|
|
}
|
|
}
|