Add icon to the context menu

This CL reuses cut, copy, paste, select all and share icon.
This CL adds new undo, redo icon from Material library.

Bug: 240385199
Test: Manually done
Change-Id: Ia88452de436d36a1d5f2cbf44e55a61be866f894
This commit is contained in:
Seigo Nonaka
2023-03-22 14:59:13 +09:00
parent f33cf83241
commit 200e8d2c26
6 changed files with 78 additions and 0 deletions

View File

@@ -3193,47 +3193,66 @@ public class Editor {
menuItemOrderPasteAsPlainText = 11;
}
final TypedArray a = mTextView.getContext().obtainStyledAttributes(new int[] {
// TODO: Make Undo/Redo be public attribute.
com.android.internal.R.attr.actionModeUndoDrawable,
com.android.internal.R.attr.actionModeRedoDrawable,
android.R.attr.actionModeCutDrawable,
android.R.attr.actionModeCopyDrawable,
android.R.attr.actionModePasteDrawable,
android.R.attr.actionModeSelectAllDrawable,
android.R.attr.actionModeShareDrawable,
});
menu.add(CONTEXT_MENU_GROUP_UNDO_REDO, TextView.ID_UNDO, menuItemOrderUndo,
com.android.internal.R.string.undo)
.setAlphabeticShortcut('z')
.setOnMenuItemClickListener(mOnContextMenuItemClickListener)
.setIcon(a.getDrawable(0))
.setEnabled(mTextView.canUndo());
menu.add(CONTEXT_MENU_GROUP_UNDO_REDO, TextView.ID_REDO, menuItemOrderRedo,
com.android.internal.R.string.redo)
.setAlphabeticShortcut('z', KeyEvent.META_CTRL_ON | KeyEvent.META_SHIFT_ON)
.setOnMenuItemClickListener(mOnContextMenuItemClickListener)
.setIcon(a.getDrawable(1))
.setEnabled(mTextView.canRedo());
menu.add(CONTEXT_MENU_GROUP_CLIPBOARD, TextView.ID_CUT, menuItemOrderCut,
com.android.internal.R.string.cut)
.setAlphabeticShortcut('x')
.setOnMenuItemClickListener(mOnContextMenuItemClickListener)
.setIcon(a.getDrawable(2))
.setEnabled(mTextView.canCut());
menu.add(CONTEXT_MENU_GROUP_CLIPBOARD, TextView.ID_COPY, menuItemOrderCopy,
com.android.internal.R.string.copy)
.setAlphabeticShortcut('c')
.setOnMenuItemClickListener(mOnContextMenuItemClickListener)
.setIcon(a.getDrawable(3))
.setEnabled(mTextView.canCopy());
menu.add(CONTEXT_MENU_GROUP_CLIPBOARD, TextView.ID_PASTE, menuItemOrderPaste,
com.android.internal.R.string.paste)
.setAlphabeticShortcut('v')
.setEnabled(mTextView.canPaste())
.setIcon(a.getDrawable(4))
.setOnMenuItemClickListener(mOnContextMenuItemClickListener);
menu.add(CONTEXT_MENU_GROUP_CLIPBOARD, TextView.ID_PASTE_AS_PLAIN_TEXT,
menuItemOrderPasteAsPlainText,
com.android.internal.R.string.paste_as_plain_text)
.setAlphabeticShortcut('v', KeyEvent.META_CTRL_ON | KeyEvent.META_SHIFT_ON)
.setEnabled(mTextView.canPasteAsPlainText())
.setIcon(a.getDrawable(4))
.setOnMenuItemClickListener(mOnContextMenuItemClickListener);
menu.add(CONTEXT_MENU_GROUP_CLIPBOARD, TextView.ID_SELECT_ALL,
menuItemOrderSelectAll, com.android.internal.R.string.selectAll)
.setAlphabeticShortcut('a')
.setEnabled(mTextView.canSelectAllText())
.setIcon(a.getDrawable(5))
.setOnMenuItemClickListener(mOnContextMenuItemClickListener);
menu.add(CONTEXT_MENU_GROUP_MISC, TextView.ID_SHARE, menuItemOrderShare,
com.android.internal.R.string.share)
.setEnabled(mTextView.canShare())
.setIcon(a.getDrawable(6))
.setOnMenuItemClickListener(mOnContextMenuItemClickListener);
menu.add(CONTEXT_MENU_GROUP_MISC, TextView.ID_AUTOFILL, menuItemOrderAutofill,
android.R.string.autofill)
@@ -3241,6 +3260,7 @@ public class Editor {
.setOnMenuItemClickListener(mOnContextMenuItemClickListener);
mPreserveSelection = true;
a.recycle();
// No-op for the old context menu because it doesn't have icons.
adjustIconSpacing(menu);

View File

@@ -0,0 +1,25 @@
<!--
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M9.9,19Q7.475,19 5.738,17.425Q4,15.85 4,13.5Q4,11.15 5.738,9.575Q7.475,8 9.9,8H16.2L13.6,5.4L15,4L20,9L15,14L13.6,12.6L16.2,10H9.9Q8.325,10 7.163,11Q6,12 6,13.5Q6,15 7.163,16Q8.325,17 9.9,17H17V19Z"/>
</vector>

View File

@@ -0,0 +1,25 @@
<!--
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M14.1,19H7V17H14.1Q15.675,17 16.837,16Q18,15 18,13.5Q18,12 16.837,11Q15.675,10 14.1,10H7.8L10.4,12.6L9,14L4,9L9,4L10.4,5.4L7.8,8H14.1Q16.525,8 18.263,9.575Q20,11.15 20,13.5Q20,15.85 18.263,17.425Q16.525,19 14.1,19Z"/>
</vector>

View File

@@ -918,6 +918,10 @@
<attr name="actionModeFindDrawable" format="reference" />
<!-- Drawable to use for the Web Search action button in WebView selection action modes. -->
<attr name="actionModeWebSearchDrawable" format="reference" />
<!-- Drawable to use for the Undo action button in WebView selection action modes. -->
<attr name="actionModeUndoDrawable" format="reference" />
<!-- Drawable to use for the Redo action button in WebView selection action modes. -->
<attr name="actionModeRedoDrawable" format="reference" />
<!-- PopupWindow style to use for action modes when showing as a window overlay. -->
<attr name="actionModePopupWindowStyle" format="reference" />

View File

@@ -5033,4 +5033,6 @@
<java-symbol name="materialColorSurfaceContainer" type="attr"/>
<java-symbol name="materialColorSurfaceContainer" type="attr"/>
<java-symbol type="attr" name="actionModeUndoDrawable" />
<java-symbol type="attr" name="actionModeRedoDrawable" />
</resources>

View File

@@ -358,6 +358,8 @@ please see themes_device_defaults.xml.
<item name="actionModeShareDrawable">@drawable/ic_menu_share_holo_dark</item>
<item name="actionModeFindDrawable">@drawable/ic_menu_find_holo_dark</item>
<item name="actionModeWebSearchDrawable">@drawable/ic_menu_search</item>
<item name="actionModeUndoDrawable">@drawable/ic_menu_undo_material</item>
<item name="actionModeRedoDrawable">@drawable/ic_menu_redo_material</item>
<item name="actionBarTabStyle">@style/Widget.ActionBar.TabView</item>
<item name="actionBarTabBarStyle">@style/Widget.ActionBar.TabBar</item>
<item name="actionBarTabTextStyle">@style/Widget.ActionBar.TabText</item>