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

Commit 63796b55 authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Fix wrongly applied material theme for StandardMenuPopup (2nd attempt)

The second attempt contains followings
- Add feature flag for fixing this issue.
- Tweak the layout for not to be misaligned in some case.

Original comment from the first attempt:

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
Bug: 334822606
Test: Manually tested with Pixel 8 and Pixel Table on following conditions
- Google Map send feedback menu
- Copy menu on settings in Android version page
- Regular EditText
Change-Id: I181fb046e74033c94657c5455e8b70ea6efa159e
parent a55d0834
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -61,4 +61,11 @@ public class ClientFlags {
    public static boolean icuBidiMigration() {
        return TextFlags.isFeatureEnabled(Flags.FLAG_ICU_BIDI_MIGRATION);
    }

    /**
     * @see Flags#fixMisalignedContextMenu()
     */
    public static boolean fixMisalignedContextMenu() {
        return TextFlags.isFeatureEnabled(Flags.FLAG_FIX_MISALIGNED_CONTEXT_MENU);
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public final class TextFlags {
            Flags.FLAG_USE_BOUNDS_FOR_WIDTH,
            Flags.FLAG_FIX_LINE_HEIGHT_FOR_LOCALE,
            Flags.FLAG_ICU_BIDI_MIGRATION,
            Flags.FLAG_FIX_MISALIGNED_CONTEXT_MENU,
    };

    /**
@@ -73,6 +74,7 @@ public final class TextFlags {
            Flags.useBoundsForWidth(),
            Flags.fixLineHeightForLocale(),
            Flags.icuBidiMigration(),
            Flags.fixMisalignedContextMenu(),
    };

    /**
+10 −0
Original line number Diff line number Diff line
@@ -170,3 +170,13 @@ flag {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "fix_misaligned_context_menu"
  namespace: "text"
  description: "Fix the context menu misalignment and incosistent icon size."
  bug: "332542108"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
+3 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.ClientFlags;
import android.text.TextFlags;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@@ -290,7 +291,8 @@ 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 :
                mUseNewContextMenu && !ClientFlags.fixMisalignedContextMenu()
                        ? com.android.internal.R.layout.list_menu_item_fixed_size_icon :
                        com.android.internal.R.layout.list_menu_item_icon,
                this, false);
        addContentView(mIconView, 0);
+16 −4
Original line number Diff line number Diff line
@@ -16,24 +16,27 @@

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.ClientFlags;
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 +47,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 +58,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 +120,16 @@ 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,
                ClientFlags.fixMisalignedContextMenu() && useNewContextMenu
                        ? ITEM_LAYOUT_MATERIAL : ITEM_LAYOUT);
        mPopupStyleAttr = popupStyleAttr;
        mPopupStyleRes = popupStyleRes;

Loading