OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.contextmenu; | |
6 | |
7 import android.content.Context; | |
8 import android.support.annotation.StringRes; | |
9 | |
10 import org.chromium.chrome.R; | |
11 import org.chromium.chrome.browser.DefaultBrowserInfo; | |
12 import org.chromium.chrome.browser.search_engines.TemplateUrlService; | |
13 | |
14 /** | |
15 * A in class representation of chrome_context_menu.xml. | |
16 */ | |
17 public enum ContextMenuItems { | |
18 // Custom Tab Group | |
19 OPEN_IN_NEW_CHROME_TAB(R.string.contextmenu_open_in_new_chrome_tab, | |
20 R.id.contextmenu_open_in_new_chrome_tab), | |
21 OPEN_IN_CHROME_INCOGNITO_TAB(R.string.contextmenu_open_in_chrome_incognito_t ab, | |
22 R.id.contextmenu_open_in_chrome_incognito_tab), | |
23 OPEN_IN_BROWSER_ID(0, R.id.contextmenu_open_in_browser_id), | |
24 // Link Group | |
25 OPEN_IN_OTHER_WINDOW(R.string.contextmenu_open_in_other_window, | |
26 R.id.contextmenu_open_in_other_window), | |
27 OPEN_IN_NEW_TAB(R.string.contextmenu_open_in_new_tab, R.id.contextmenu_open_ in_new_tab), | |
28 OPEN_IN_INCOGNITO_TAB(R.string.contextmenu_open_in_incognito_tab, | |
29 R.id.contextmenu_open_in_incognito_tab), | |
30 COPY_LINK_ADDRESS(R.string.contextmenu_copy_link_address, R.id.contextmenu_c opy_link_address), | |
31 COPY_LINK_TEXT(R.string.contextmenu_copy_link_text, R.id.contextmenu_copy_li nk_text), | |
32 SAVE_LINK_AS(R.string.contextmenu_save_link, R.id.contextmenu_save_link_as), | |
33 // Image Group | |
34 LOAD_ORIGINAL_IMAGE(R.string.contextmenu_load_original_image, | |
35 R.id.contextmenu_load_original_image), | |
36 SAVE_IMAGE(R.string.contextmenu_save_image, R.id.contextmenu_save_image), | |
37 OPEN_IMAGE(R.string.contextmenu_open_image, R.id.contextmenu_open_image), | |
38 OPEN_IMAGE_IN_NEW_TAB(R.string.contextmenu_open_image_in_new_tab, | |
39 R.id.contextmenu_open_image_in_new_tab), | |
40 SEARCH_BY_IMAGE(R.string.contextmenu_search_web_for_image, R.id.contextmenu_ search_by_image), | |
41 SHARE_IMAGE(R.string.contextmenu_share_image, R.id.contextmenu_share_image), | |
42 // Message Group | |
43 CALL(R.string.contextmenu_call, R.id.contextmenu_call), | |
44 SEND_MESSAGE(R.string.contextmenu_send_message, R.id.contextmenu_send_messag e), | |
45 ADD_TO_CONTACTS(R.string.contextmenu_add_to_contacts, R.id.contextmenu_add_t o_contacts), | |
46 COPY(R.string.contextmenu_copy, R.id.contextmenu_copy), | |
47 // Video Group | |
48 SAVE_VIDEO(R.string.contextmenu_save_video, R.id.contextmenu_save_video), | |
49 // Other | |
50 OPEN_IN_CHROME(R.string.menu_open_in_chrome, R.id.menu_id_open_in_chrome); | |
51 | |
52 public int iconId; | |
53 public int stringId; | |
Ted C
2017/03/11 00:31:14
should these be final?
JJ
2017/03/13 20:24:29
Done.
| |
54 public int menuId; | |
55 | |
56 /** | |
57 * A representation of a Context Menu Item. Each item should have a string a nd an id associated | |
58 * with it. | |
59 * @param stringId The string that describes the action of the item. | |
60 * @param menuId The id found in ids.xml | |
61 */ | |
62 ContextMenuItems(@StringRes int stringId, int menuId) { | |
63 this.stringId = stringId; | |
64 this.menuId = menuId; | |
65 } | |
66 | |
67 /** | |
68 * Transforms the id of the item into a string. It manages special cases tha t need minor | |
69 * changes due to templating. | |
70 * @param context Requires to get the string resource related to the item. | |
71 * @return Returns a string for the menu item. | |
72 */ | |
73 String getString(Context context) { | |
74 String value; | |
Ted C
2017/03/11 00:31:14
You can skip this variable altogether. Just retur
JJ
2017/03/13 20:24:29
Slight debate on it being if/else if block or two
| |
75 if (this == ContextMenuItems.SEARCH_BY_IMAGE) { | |
76 value = context.getString(org.chromium.chrome.R.string.contextmenu_s earch_web_for_image, | |
77 TemplateUrlService.getInstance() | |
78 .getDefaultSearchEngineTemplateUrl() | |
79 .getShortName()); | |
80 } else if (this == OPEN_IN_BROWSER_ID) { | |
81 value = DefaultBrowserInfo.getTitleOpenInDefaultBrowser(false); | |
82 } else { | |
83 value = context.getString(stringId); | |
84 } | |
85 | |
86 return value; | |
87 } | |
88 } | |
OLD | NEW |