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 * List of all Context Menu Items available in Chrome. |
| 16 */ |
| 17 public enum ContextMenuItem { |
| 18 // Custom Tab Group |
| 19 OPEN_IN_NEW_CHROME_TAB(R.string.contextmenu_open_in_new_chrome_tab, |
| 20 R.id.context_menu_open_in_new_chrome_tab), |
| 21 OPEN_IN_CHROME_INCOGNITO_TAB(R.string.contextmenu_open_in_chrome_incognito_t
ab, |
| 22 R.id.context_menu_open_in_chrome_incognito_tab), |
| 23 OPEN_IN_BROWSER_ID(0, R.id.context_menu_open_in_browser_id), |
| 24 // Link Group |
| 25 OPEN_IN_OTHER_WINDOW(R.string.contextmenu_open_in_other_window, |
| 26 R.id.context_menu_open_in_other_window), |
| 27 OPEN_IN_NEW_TAB(R.string.contextmenu_open_in_new_tab, R.id.context_menu_open
_in_new_tab), |
| 28 OPEN_IN_INCOGNITO_TAB(R.string.contextmenu_open_in_incognito_tab, |
| 29 R.id.context_menu_open_in_incognito_tab), |
| 30 COPY_LINK_ADDRESS(R.string.contextmenu_copy_link_address, R.id.context_menu_
copy_link_address), |
| 31 COPY_LINK_TEXT(R.string.contextmenu_copy_link_text, R.id.context_menu_copy_l
ink_text), |
| 32 SAVE_LINK_AS(R.string.contextmenu_save_link, R.id.context_menu_save_link_as)
, |
| 33 // Image Group |
| 34 LOAD_ORIGINAL_IMAGE(R.string.contextmenu_load_original_image, |
| 35 R.id.context_menu_load_original_image), |
| 36 SAVE_IMAGE(R.string.contextmenu_save_image, R.id.context_menu_save_image), |
| 37 OPEN_IMAGE(R.string.contextmenu_open_image, R.id.context_menu_open_image), |
| 38 OPEN_IMAGE_IN_NEW_TAB(R.string.contextmenu_open_image_in_new_tab, |
| 39 R.id.context_menu_open_image_in_new_tab), |
| 40 SEARCH_BY_IMAGE(R.string.contextmenu_search_web_for_image, R.id.context_menu
_search_by_image), |
| 41 SHARE_IMAGE(R.string.contextmenu_share_image, R.id.context_menu_share_image)
, |
| 42 // Message Group |
| 43 CALL(R.string.contextmenu_call, R.id.context_menu_call), |
| 44 SEND_MESSAGE(R.string.contextmenu_send_message, R.id.context_menu_send_messa
ge), |
| 45 ADD_TO_CONTACTS(R.string.contextmenu_add_to_contacts, R.id.context_menu_add_
to_contacts), |
| 46 COPY(R.string.contextmenu_copy, R.id.context_menu_copy), |
| 47 // Video Group |
| 48 SAVE_VIDEO(R.string.contextmenu_save_video, R.id.context_menu_save_video), |
| 49 // Other |
| 50 OPEN_IN_CHROME(R.string.menu_open_in_chrome, R.id.menu_id_open_in_chrome); |
| 51 |
| 52 public final int stringId; |
| 53 public final int menuId; |
| 54 |
| 55 /** |
| 56 * A representation of a Context Menu Item. Each item should have a string a
nd an id associated |
| 57 * with it. |
| 58 * @param stringId The string that describes the action of the item. |
| 59 * @param menuId The id found in ids.xml |
| 60 */ |
| 61 ContextMenuItem(@StringRes int stringId, int menuId) { |
| 62 this.stringId = stringId; |
| 63 this.menuId = menuId; |
| 64 } |
| 65 |
| 66 /** |
| 67 * Transforms the id of the item into a string. It manages special cases tha
t need minor |
| 68 * changes due to templating. |
| 69 * @param context Requires to get the string resource related to the item. |
| 70 * @return Returns a string for the menu item. |
| 71 */ |
| 72 String getString(Context context) { |
| 73 if (this == ContextMenuItem.SEARCH_BY_IMAGE) { |
| 74 return context.getString(R.string.contextmenu_search_web_for_image, |
| 75 TemplateUrlService.getInstance() |
| 76 .getDefaultSearchEngineTemplateUrl() |
| 77 .getShortName()); |
| 78 } else if (this == OPEN_IN_BROWSER_ID) { |
| 79 return DefaultBrowserInfo.getTitleOpenInDefaultBrowser(false); |
| 80 } |
| 81 |
| 82 return context.getString(stringId); |
| 83 } |
| 84 } |
OLD | NEW |