Commit f02a51fb authored by Pavel Yatsuk's avatar Pavel Yatsuk Committed by Commit Bot

[Touchless] Add icons to touchless context menu.

Touchless context menus should include icons for individual items. To
support this I added a method to TouchlessContextMenuManager to map from
item id to resource id of corresponding item. I've also added following
VectorDrawable resources:
- ic_remove_circle_outline_24dp
- ic_help_outline_24dp

Here are screenshots:
- screen/pyyNGb0jLpX
- screen/GDwXF9z7mvr

BUG=937445
R=dewittj@chromium.org

Change-Id: Ic46f4335f8a219bc6d2cc389b62457a9042415d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1586261
Commit-Queue: Pavel Yatsuk <pavely@chromium.org>
Reviewed-by: default avatarJustin DeWitt <dewittj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654682}
parent 0f84e6d8
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
tools:ignore="NewApi">
<path
android:fillColor="@color/default_icon_color"
android:fillType="evenOdd"
android:pathData="M11,18h2v-2h-2v2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM12,6c-2.21,0 -4,1.79 -4,4h2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,2 -3,1.75 -3,5h2c0,-2.25 3,-2.5 3,-5 0,-2.21 -1.79,-4 -4,-4z"/>
</vector>
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
tools:ignore="NewApi">
<path
android:fillColor="@color/default_icon_color"
android:fillType="evenOdd"
android:pathData="M7,11v2h10v-2L7,11zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
</vector>
......@@ -5,7 +5,7 @@
package org.chromium.chrome.browser.touchless;
import android.content.Context;
import android.support.annotation.StringRes;
import android.support.annotation.DrawableRes;
import android.view.View;
import android.view.View.OnClickListener;
......@@ -13,6 +13,7 @@ import org.chromium.chrome.browser.native_page.ContextMenuManager;
import org.chromium.chrome.browser.native_page.NativePageNavigationDelegate;
import org.chromium.chrome.browser.touchless.dialog.TouchlessDialogProperties;
import org.chromium.chrome.browser.touchless.dialog.TouchlessDialogProperties.DialogListItemProperties;
import org.chromium.chrome.touchless.R;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogProperties;
import org.chromium.ui.modelutil.PropertyModel;
......@@ -49,8 +50,8 @@ public class TouchlessContextMenuManager extends ContextMenuManager {
// Each menu item is assigned its own instance of TouchlessItemClickListener where
// itemId of this item is maintained.
PropertyModel menuItem = buildMenuItem(context, getResourceIdForMenuItem(itemId),
new TouchlessItemClickListener(delegate, itemId));
PropertyModel menuItem = buildMenuItem(
context, itemId, new TouchlessItemClickListener(delegate, itemId));
menuItems.add(menuItem);
}
if (menuItems.size() == 0) return;
......@@ -92,9 +93,11 @@ public class TouchlessContextMenuManager extends ContextMenuManager {
* resources by PropertyModel.Builder.
*/
private PropertyModel buildMenuItem(
Context context, @StringRes int itemTextId, OnClickListener listener) {
Context context, @ContextMenuItemId int itemId, OnClickListener listener) {
return new PropertyModel.Builder(DialogListItemProperties.ALL_KEYS)
.with(DialogListItemProperties.TEXT, context.getResources(), itemTextId)
.with(DialogListItemProperties.TEXT, context.getResources(),
getResourceIdForMenuItem(itemId))
.with(DialogListItemProperties.ICON, context, getIconIdForMenuItem(itemId))
.with(DialogListItemProperties.CLICK_LISTENER, listener)
.build();
}
......@@ -126,6 +129,20 @@ public class TouchlessContextMenuManager extends ContextMenuManager {
return builder.build();
}
/**
* Returns resource id of an icon to be displayed for menu item with given item id.
*/
private @DrawableRes int getIconIdForMenuItem(@ContextMenuItemId int itemId) {
switch (itemId) {
case ContextMenuItemId.REMOVE:
return R.drawable.ic_remove_circle_outline_24dp;
case ContextMenuItemId.LEARN_MORE:
return R.drawable.ic_help_outline_24dp;
default:
return 0;
}
}
private void closeTouchlessContextMenu() {
mModalDialogManager.dismissDialog(mTouchlessMenuModel, 0);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment