From 50a9619bb28438a872a2ba36c5cc717cf38ed00f Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 10 Apr 2024 10:24:50 +0900 Subject: Fix wrongly applied material theme for StandardMenuPopup The candidate windows has updated for Material theme but it was done only for CascadingMenuPopup. The same things need to be done for StandardMenuPopup which is mainly used for the phone devices. This CL also fixes the icon position wrongly aligned to the left of the context menu for some case. Bug: 332542108 Test: Manually tested on Pixel 8 and Pixel Tablet Change-Id: I83918055f7ee1881061e6cf2744a578a838bebe5 --- .../internal/view/menu/ListMenuItemView.java | 12 +-- .../internal/view/menu/StandardMenuPopup.java | 18 ++++- core/res/res/layout/list_menu_item_icon.xml | 2 +- .../res/layout/popup_menu_item_layout_material.xml | 91 ++++++++++++++++++++++ core/res/res/values/symbols.xml | 1 + 5 files changed, 108 insertions(+), 16 deletions(-) create mode 100644 core/res/res/layout/popup_menu_item_layout_material.xml diff --git a/core/java/com/android/internal/view/menu/ListMenuItemView.java b/core/java/com/android/internal/view/menu/ListMenuItemView.java index cb1abf13c109..bdb33c4b151c 100644 --- a/core/java/com/android/internal/view/menu/ListMenuItemView.java +++ b/core/java/com/android/internal/view/menu/ListMenuItemView.java @@ -16,12 +16,10 @@ package com.android.internal.view.menu; -import android.app.AppGlobals; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Rect; import android.graphics.drawable.Drawable; -import android.text.TextFlags; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; @@ -61,8 +59,6 @@ public class ListMenuItemView extends LinearLayout private int mMenuType; - private boolean mUseNewContextMenu; - private LayoutInflater mInflater; private boolean mForceShowIcon; @@ -89,10 +85,6 @@ public class ListMenuItemView extends LinearLayout a.recycle(); b.recycle(); - - mUseNewContextMenu = AppGlobals.getIntCoreSetting( - TextFlags.KEY_ENABLE_NEW_CONTEXT_MENU, - TextFlags.ENABLE_NEW_CONTEXT_MENU_DEFAULT ? 1 : 0) != 0; } public ListMenuItemView(Context context, AttributeSet attrs, int defStyleAttr) { @@ -289,9 +281,7 @@ public class ListMenuItemView extends LinearLayout private void insertIconView() { LayoutInflater inflater = getInflater(); - mIconView = (ImageView) inflater.inflate( - mUseNewContextMenu ? com.android.internal.R.layout.list_menu_item_fixed_size_icon : - com.android.internal.R.layout.list_menu_item_icon, + mIconView = (ImageView) inflater.inflate(com.android.internal.R.layout.list_menu_item_icon, this, false); addContentView(mIconView, 0); } diff --git a/core/java/com/android/internal/view/menu/StandardMenuPopup.java b/core/java/com/android/internal/view/menu/StandardMenuPopup.java index 1979e4fe7a90..36828f2dadca 100644 --- a/core/java/com/android/internal/view/menu/StandardMenuPopup.java +++ b/core/java/com/android/internal/view/menu/StandardMenuPopup.java @@ -16,24 +16,26 @@ package com.android.internal.view.menu; +import android.app.AppGlobals; import android.content.Context; import android.content.res.Resources; import android.os.Parcelable; +import android.text.TextFlags; import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnAttachStateChangeListener; import android.view.View.OnKeyListener; -import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.view.ViewTreeObserver; +import android.view.ViewTreeObserver.OnGlobalLayoutListener; +import android.widget.AdapterView.OnItemClickListener; import android.widget.FrameLayout; import android.widget.ListView; import android.widget.MenuPopupWindow; import android.widget.PopupWindow; -import android.widget.TextView; -import android.widget.AdapterView.OnItemClickListener; import android.widget.PopupWindow.OnDismissListener; +import android.widget.TextView; import java.util.Objects; @@ -44,6 +46,8 @@ import java.util.Objects; final class StandardMenuPopup extends MenuPopup implements OnDismissListener, OnItemClickListener, MenuPresenter, OnKeyListener { private static final int ITEM_LAYOUT = com.android.internal.R.layout.popup_menu_item_layout; + private static final int ITEM_LAYOUT_MATERIAL = + com.android.internal.R.layout.popup_menu_item_layout_material; private final Context mContext; @@ -53,6 +57,7 @@ final class StandardMenuPopup extends MenuPopup implements OnDismissListener, On private final int mPopupMaxWidth; private final int mPopupStyleAttr; private final int mPopupStyleRes; + // The popup window is final in order to couple its lifecycle to the lifecycle of the // StandardMenuPopup. private final MenuPopupWindow mPopup; @@ -114,10 +119,15 @@ final class StandardMenuPopup extends MenuPopup implements OnDismissListener, On public StandardMenuPopup(Context context, MenuBuilder menu, View anchorView, int popupStyleAttr, int popupStyleRes, boolean overflowOnly) { mContext = Objects.requireNonNull(context); + boolean useNewContextMenu = AppGlobals.getIntCoreSetting( + TextFlags.KEY_ENABLE_NEW_CONTEXT_MENU, + TextFlags.ENABLE_NEW_CONTEXT_MENU_DEFAULT ? 1 : 0) != 0; + mMenu = menu; mOverflowOnly = overflowOnly; final LayoutInflater inflater = LayoutInflater.from(context); - mAdapter = new MenuAdapter(menu, inflater, mOverflowOnly, ITEM_LAYOUT); + mAdapter = new MenuAdapter(menu, inflater, mOverflowOnly, + useNewContextMenu ? ITEM_LAYOUT_MATERIAL : ITEM_LAYOUT); mPopupStyleAttr = popupStyleAttr; mPopupStyleRes = popupStyleRes; diff --git a/core/res/res/layout/list_menu_item_icon.xml b/core/res/res/layout/list_menu_item_icon.xml index a30be6a13db6..d8514608e8dd 100644 --- a/core/res/res/layout/list_menu_item_icon.xml +++ b/core/res/res/layout/list_menu_item_icon.xml @@ -20,7 +20,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginStart="8dip" - android:layout_marginEnd="-8dip" + android:layout_marginEnd="8dip" android:layout_marginTop="8dip" android:layout_marginBottom="8dip" android:scaleType="centerInside" diff --git a/core/res/res/layout/popup_menu_item_layout_material.xml b/core/res/res/layout/popup_menu_item_layout_material.xml new file mode 100644 index 000000000000..e20ead62032c --- /dev/null +++ b/core/res/res/layout/popup_menu_item_layout_material.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index f33e2771879d..663788d948bb 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1528,6 +1528,7 @@ + -- cgit v1.2.3-59-g8ed1b