Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuItem.java

Issue 2815453002: [Android] Show Browser Actions dialog in Chrome (Closed)
Patch Set: Update based on Ted's comments. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.contextmenu; 5 package org.chromium.chrome.browser.contextmenu;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.graphics.drawable.Drawable; 8 import android.graphics.drawable.Drawable;
9 import android.support.annotation.DrawableRes;
10 import android.support.annotation.IdRes; 9 import android.support.annotation.IdRes;
11 import android.support.annotation.StringRes;
12
13 import org.chromium.base.ApiCompatibilityUtils;
14 import org.chromium.chrome.R;
15 import org.chromium.chrome.browser.DefaultBrowserInfo;
16 import org.chromium.chrome.browser.search_engines.TemplateUrlService;
17 import org.chromium.chrome.browser.widget.TintedDrawable;
18 10
19 /** 11 /**
20 * List of all Context Menu Items available in Chrome. 12 * An interface to get information of context menu.
21 */ 13 */
22 public enum ContextMenuItem { 14 public interface ContextMenuItem {
23 // Custom Tab Group 15 /**
24 OPEN_IN_NEW_CHROME_TAB(R.drawable.context_menu_new_tab, 16 * Gets the {@link IdRes} menuId of a context menu.
25 R.string.contextmenu_open_in_new_chrome_tab, R.id.contextmenu_open_i n_new_chrome_tab), 17 * @return.
26 OPEN_IN_CHROME_INCOGNITO_TAB(R.drawable.incognito_statusbar, 18 */
27 R.string.contextmenu_open_in_chrome_incognito_tab, 19 @IdRes
28 R.id.contextmenu_open_in_chrome_incognito_tab), 20 int getMenuId();
29 OPEN_IN_BROWSER_ID(R.drawable.context_menu_new_tab, 0, R.id.contextmenu_open _in_browser_id),
30
31 // Link Group
32 OPEN_IN_OTHER_WINDOW(R.drawable.context_menu_new_tab, R.string.contextmenu_o pen_in_other_window,
33 R.id.contextmenu_open_in_other_window),
34 OPEN_IN_NEW_TAB(R.drawable.context_menu_new_tab, R.string.contextmenu_open_i n_new_tab,
35 R.id.contextmenu_open_in_new_tab),
36 OPEN_IN_INCOGNITO_TAB(R.drawable.incognito_statusbar,
37 R.string.contextmenu_open_in_incognito_tab, R.id.contextmenu_open_in _incognito_tab),
38 COPY_LINK_ADDRESS(R.drawable.ic_content_copy, R.string.contextmenu_copy_link _address,
39 R.id.contextmenu_copy_link_address),
40 COPY_LINK_TEXT(R.drawable.ic_content_copy, R.string.contextmenu_copy_link_te xt,
41 R.id.contextmenu_copy_link_text),
42 SAVE_LINK_AS(R.drawable.ic_file_download_white_24dp, R.string.contextmenu_sa ve_link,
43 R.id.contextmenu_save_link_as),
44
45 // Image Group
46 LOAD_ORIGINAL_IMAGE(R.drawable.context_menu_load_image,
47 R.string.contextmenu_load_original_image, R.id.contextmenu_load_orig inal_image),
48 SAVE_IMAGE(R.drawable.ic_file_download_white_24dp, R.string.contextmenu_save _image,
49 R.id.contextmenu_save_image),
50 OPEN_IMAGE(R.drawable.context_menu_new_tab, R.string.contextmenu_open_image,
51 R.id.contextmenu_open_image),
52 OPEN_IMAGE_IN_NEW_TAB(R.drawable.context_menu_new_tab,
53 R.string.contextmenu_open_image_in_new_tab, R.id.contextmenu_open_im age_in_new_tab),
54 SEARCH_BY_IMAGE(R.drawable.googleg, R.string.contextmenu_search_web_for_imag e,
55 R.id.contextmenu_search_by_image),
56 SHARE_IMAGE(R.drawable.ic_share_white_24dp, R.string.contextmenu_share_image ,
57 R.id.contextmenu_share_image),
58
59 // Message Group
60 CALL(R.drawable.ic_phone_googblue_36dp, R.string.contextmenu_call, R.id.cont extmenu_call),
61 SEND_MESSAGE(R.drawable.ic_email_googblue_36dp, R.string.contextmenu_send_me ssage,
62 R.id.contextmenu_send_message),
63 ADD_TO_CONTACTS(R.drawable.context_menu_add_to_contacts, R.string.contextmen u_add_to_contacts,
64 R.id.contextmenu_add_to_contacts),
65 COPY(R.drawable.ic_content_copy, R.string.contextmenu_copy, R.id.contextmenu _copy),
66
67 // Video Group
68 SAVE_VIDEO(R.drawable.ic_file_download_white_24dp, R.string.contextmenu_save _video,
69 R.id.contextmenu_save_video),
70 // Other
71 OPEN_IN_CHROME(R.drawable.context_menu_new_tab, R.string.menu_open_in_chrome ,
72 R.id.menu_id_open_in_chrome);
73
74 @DrawableRes public final int iconId;
75 @StringRes public final int stringId;
76 @IdRes public final int menuId;
77 21
78 /** 22 /**
79 * A representation of a Context Menu Item. Each item should have a string a nd an id associated 23 * Gets the title of a context menu item.
80 * with it. 24 * @param context The context required to get the title from resources.
81 * @param iconId The icon that appears in {@link TabularContextMenuUi} to re present each item. 25 * @return The title of the menu item.
82 * @param stringId The string that describes the action of the item.
83 * @param menuId The id found in ids.xml.
84 */ 26 */
85 ContextMenuItem(@DrawableRes int iconId, @StringRes int stringId, @IdRes int menuId) { 27 String getTitle(Context context);
86 this.iconId = iconId;
87 this.stringId = stringId;
88 this.menuId = menuId;
89 }
90 28
91 /** 29 /**
92 * Transforms the id of the item into a string. It manages special cases tha t need minor 30 * Gets the {@link Drawable} icon of a context menu item.
93 * changes due to templating. 31 * @param context The context required to get the icon from resources.
94 * @param context Requires to get the string resource related to the item. 32 * @return The icon of the menu item.
95 * @return Returns a string for the menu item.
96 */ 33 */
97 String getString(Context context) { 34 Drawable getDrawableAndDescription(Context context);
98 if (this == ContextMenuItem.SEARCH_BY_IMAGE) { 35 }
99 return context.getString(R.string.contextmenu_search_web_for_image,
100 TemplateUrlService.getInstance()
101 .getDefaultSearchEngineTemplateUrl()
102 .getShortName());
103 } else if (this == OPEN_IN_BROWSER_ID) {
104 return DefaultBrowserInfo.getTitleOpenInDefaultBrowser(false);
105 } else if (stringId == 0) {
106 return "";
107 }
108
109 return context.getString(stringId);
110 }
111
112 /**
113 * Returns the drawable and the content description associated with the cont ext menu. If no
114 * drawable is associated with the icon, null is returned for the drawable a nd the
115 * iconDescription.
116 */
117 Drawable getDrawableAndDescription(Context context) {
118 if (iconId == R.drawable.context_menu_new_tab
119 || iconId == R.drawable.context_menu_add_to_contacts
120 || iconId == R.drawable.context_menu_load_image) {
121 return ApiCompatibilityUtils.getDrawable(context.getResources(), ico nId);
122 } else if (iconId == 0) {
123 return null;
124 } else {
125 return TintedDrawable.constructTintedDrawable(
126 context.getResources(), iconId, R.color.light_normal_color);
127 }
128 }
129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698