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

Commit 74ed70bb authored by Seigo Nonaka's avatar Seigo Nonaka Committed by Automerger Merge Worker
Browse files

Merge "Redesign the ContextMenu to meet matrial spec" into udc-dev am: 578a00a9

parents 616a9a61 578a00a9
Loading
Loading
Loading
Loading
+10 −3
Original line number Original line Diff line number Diff line
@@ -5,12 +5,14 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.StyleRes;
import android.annotation.StyleRes;
import android.app.AppGlobals;
import android.content.Context;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Handler;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.SystemClock;
import android.os.SystemClock;
import android.text.TextFlags;
import android.view.Gravity;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
@@ -46,8 +48,6 @@ import java.util.List;
 */
 */
final class CascadingMenuPopup extends MenuPopup implements MenuPresenter, OnKeyListener,
final class CascadingMenuPopup extends MenuPopup implements MenuPresenter, OnKeyListener,
        PopupWindow.OnDismissListener {
        PopupWindow.OnDismissListener {
    private static final int ITEM_LAYOUT = com.android.internal.R.layout.cascading_menu_item_layout;

    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({HORIZ_POSITION_LEFT, HORIZ_POSITION_RIGHT})
    @IntDef({HORIZ_POSITION_LEFT, HORIZ_POSITION_RIGHT})
    public @interface HorizPosition {}
    public @interface HorizPosition {}
@@ -190,6 +190,7 @@ final class CascadingMenuPopup extends MenuPopup implements MenuPresenter, OnKey
    private Callback mPresenterCallback;
    private Callback mPresenterCallback;
    private ViewTreeObserver mTreeObserver;
    private ViewTreeObserver mTreeObserver;
    private PopupWindow.OnDismissListener mOnDismissListener;
    private PopupWindow.OnDismissListener mOnDismissListener;
    private final int mItemLayout;


    /** Whether popup menus should disable exit animations when closing. */
    /** Whether popup menus should disable exit animations when closing. */
    private boolean mShouldCloseImmediately;
    private boolean mShouldCloseImmediately;
@@ -215,6 +216,12 @@ final class CascadingMenuPopup extends MenuPopup implements MenuPresenter, OnKey
                res.getDimensionPixelSize(com.android.internal.R.dimen.config_prefDialogWidth));
                res.getDimensionPixelSize(com.android.internal.R.dimen.config_prefDialogWidth));


        mSubMenuHoverHandler = new Handler();
        mSubMenuHoverHandler = new Handler();

        mItemLayout = AppGlobals.getIntCoreSetting(
                TextFlags.KEY_ENABLE_NEW_CONTEXT_MENU,
                TextFlags.ENABLE_NEW_CONTEXT_MENU_DEFAULT ? 1 : 0) != 0
                ? com.android.internal.R.layout.cascading_menu_item_layout_material
                : com.android.internal.R.layout.cascading_menu_item_layout;
    }
    }


    @Override
    @Override
@@ -348,7 +355,7 @@ final class CascadingMenuPopup extends MenuPopup implements MenuPresenter, OnKey
     */
     */
    private void showMenu(@NonNull MenuBuilder menu) {
    private void showMenu(@NonNull MenuBuilder menu) {
        final LayoutInflater inflater = LayoutInflater.from(mContext);
        final LayoutInflater inflater = LayoutInflater.from(mContext);
        final MenuAdapter adapter = new MenuAdapter(menu, inflater, mOverflowOnly, ITEM_LAYOUT);
        final MenuAdapter adapter = new MenuAdapter(menu, inflater, mOverflowOnly, mItemLayout);


        // Apply "force show icon" setting. There are 3 cases:
        // Apply "force show icon" setting. There are 3 cases:
        // (1) This is the top level menu and icon spacing is forced. Add spacing.
        // (1) This is the top level menu and icon spacing is forced. Add spacing.
+11 −3
Original line number Original line Diff line number Diff line
@@ -16,12 +16,12 @@


package com.android.internal.view.menu;
package com.android.internal.view.menu;


import com.android.internal.R;
import android.app.AppGlobals;

import android.content.Context;
import android.content.Context;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.text.TextFlags;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View;
@@ -61,6 +61,8 @@ public class ListMenuItemView extends LinearLayout


    private int mMenuType;
    private int mMenuType;


    private boolean mUseNewContextMenu;

    private LayoutInflater mInflater;
    private LayoutInflater mInflater;


    private boolean mForceShowIcon;
    private boolean mForceShowIcon;
@@ -87,6 +89,10 @@ public class ListMenuItemView extends LinearLayout


        a.recycle();
        a.recycle();
        b.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) {
    public ListMenuItemView(Context context, AttributeSet attrs, int defStyleAttr) {
@@ -283,7 +289,9 @@ public class ListMenuItemView extends LinearLayout


    private void insertIconView() {
    private void insertIconView() {
        LayoutInflater inflater = getInflater();
        LayoutInflater inflater = getInflater();
        mIconView = (ImageView) inflater.inflate(com.android.internal.R.layout.list_menu_item_icon,
        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,
                this, false);
                this, false);
        addContentView(mIconView, 0);
        addContentView(mIconView, 0);
    }
    }
+84 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2023 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.
-->

<!-- Keep in sync with popup_menu_item_layout.xml (which only differs in the title and shortcut
    position). -->
<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="112dip"
    android:maxWidth="280dip"
    android:orientation="vertical" >

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

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="48dip"
        android:layout_marginStart="12dip"
        android:layout_marginEnd="12dip"
        android:duplicateParentState="true" >

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

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginStart="6dip"
            android:textAppearance="?attr/textAppearanceLargePopupMenu"
            android:singleLine="true"
            android:duplicateParentState="true"
            android:textAlignment="viewStart" />

        <Space
            android:layout_width="0dip"
            android:layout_height="1dip"
            android:layout_weight="1"/>

        <TextView
            android:id="@+id/shortcut"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginStart="16dip"
            android:textAppearance="?attr/textAppearanceSmallPopupMenu"
            android:singleLine="true"
            android:duplicateParentState="true"
            android:textAlignment="viewEnd" />

        <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>
+28 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2023 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.
-->

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/icon"
    android:layout_width="24dp"
    android:layout_height="24dp"
    android:layout_gravity="center_vertical"
    android:layout_marginStart="0dip"
    android:layout_marginEnd="6dip"
    android:layout_marginTop="0dip"
    android:layout_marginBottom="0dip"
    android:scaleType="centerInside"
    android:duplicateParentState="true" />
+2 −0
Original line number Original line Diff line number Diff line
@@ -1476,6 +1476,7 @@
  <java-symbol type="layout" name="action_mode_close_item" />
  <java-symbol type="layout" name="action_mode_close_item" />
  <java-symbol type="layout" name="alert_dialog" />
  <java-symbol type="layout" name="alert_dialog" />
  <java-symbol type="layout" name="cascading_menu_item_layout" />
  <java-symbol type="layout" name="cascading_menu_item_layout" />
  <java-symbol type="layout" name="cascading_menu_item_layout_material" />
  <java-symbol type="layout" name="choose_account" />
  <java-symbol type="layout" name="choose_account" />
  <java-symbol type="layout" name="choose_account_row" />
  <java-symbol type="layout" name="choose_account_row" />
  <java-symbol type="layout" name="choose_account_type" />
  <java-symbol type="layout" name="choose_account_type" />
@@ -1525,6 +1526,7 @@
  <java-symbol type="layout" name="list_content_simple" />
  <java-symbol type="layout" name="list_content_simple" />
  <java-symbol type="layout" name="list_menu_item_checkbox" />
  <java-symbol type="layout" name="list_menu_item_checkbox" />
  <java-symbol type="layout" name="list_menu_item_icon" />
  <java-symbol type="layout" name="list_menu_item_icon" />
  <java-symbol type="layout" name="list_menu_item_fixed_size_icon" />
  <java-symbol type="layout" name="list_menu_item_layout" />
  <java-symbol type="layout" name="list_menu_item_layout" />
  <java-symbol type="layout" name="list_menu_item_radio" />
  <java-symbol type="layout" name="list_menu_item_radio" />
  <java-symbol type="layout" name="locale_picker_item" />
  <java-symbol type="layout" name="locale_picker_item" />