Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50a9619b authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

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
parent a69c13a5
Loading
Loading
Loading
Loading
+1 −11
Original line number Diff line number Diff line
@@ -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);
    }
+14 −4
Original line number Diff line number Diff line
@@ -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;

+1 −1
Original line number Diff line number Diff line
@@ -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"
+91 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2024 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.

     Forked from the popup_menu_item_layout.xml for material support. When you edit this file, you
     may also need to update that file.
-->

<com.android.internal.view.menu.ListMenuItemView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minWidth="196dip"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/group_divider"
        android:layout_width="match_parent"
        android:layout_height="1dip"
        android:layout_marginTop="4dip"
        android:layout_marginBottom="4dip"
        android:background="@drawable/list_divider_material" />

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="?attr/dropdownListPreferredItemHeight"
        android:paddingEnd="16dip"
        android:duplicateParentState="true" >

        <!-- Icon will be inserted here. -->

        <!-- The title and summary have some gap between them,
        and this 'group' should be centered vertically. -->
        <RelativeLayout
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:duplicateParentState="true">

            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_alignParentStart="true"
                android:textAppearance="?attr/textAppearanceLargePopupMenu"
                android:singleLine="true"
                android:duplicateParentState="true"
                android:ellipsize="marquee"
                android:fadingEdge="horizontal"
                android:textAlignment="viewStart" />

            <TextView
                android:id="@+id/shortcut"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/title"
                android:layout_alignParentStart="true"
                android:textAppearance="?attr/textAppearanceSmallPopupMenu"
                android:singleLine="true"
                android:duplicateParentState="true"
                android:textAlignment="viewStart" />

        </RelativeLayout>

        <ImageView
            android:id="@+id/submenuarrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginStart="8dp"
            android:scaleType="center"
            android:visibility="gone" />

        <!-- Checkbox, and/or radio button will be inserted here. -->

    </LinearLayout>

</com.android.internal.view.menu.ListMenuItemView>
+1 −0
Original line number Diff line number Diff line
@@ -1528,6 +1528,7 @@
  <java-symbol type="layout" name="number_picker" />
  <java-symbol type="layout" name="permissions_package_list_item" />
  <java-symbol type="layout" name="popup_menu_item_layout" />
  <java-symbol type="layout" name="popup_menu_item_layout_material" />
  <java-symbol type="layout" name="popup_menu_header_item_layout" />
  <java-symbol type="layout" name="remote_views_adapter_default_loading_view" />
  <java-symbol type="layout" name="search_bar" />