OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.customtabs; | 5 package org.chromium.chrome.browser.customtabs; |
6 | 6 |
7 import android.view.Menu; | 7 import android.view.Menu; |
8 import android.view.MenuItem; | 8 import android.view.MenuItem; |
9 | 9 |
10 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
11 import org.chromium.chrome.R; | 11 import org.chromium.chrome.R; |
12 import org.chromium.chrome.browser.ChromeActivity; | 12 import org.chromium.chrome.browser.ChromeActivity; |
13 import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; | 13 import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; |
14 import org.chromium.chrome.browser.tab.Tab; | 14 import org.chromium.chrome.browser.tab.Tab; |
15 | 15 |
16 import java.util.HashMap; | 16 import java.util.HashMap; |
17 import java.util.List; | 17 import java.util.List; |
18 import java.util.Map; | 18 import java.util.Map; |
19 | 19 |
20 /** | 20 /** |
21 * App menu properties delegate for {@link CustomTabActivity}. | 21 * App menu properties delegate for {@link CustomTabActivity}. |
22 */ | 22 */ |
23 public class CustomTabAppMenuPropertiesDelegate extends AppMenuPropertiesDelegat
e { | 23 public class CustomTabAppMenuPropertiesDelegate extends AppMenuPropertiesDelegat
e { |
24 private boolean mIsCustomEntryAdded; | 24 private boolean mIsCustomEntryAdded; |
| 25 private boolean mShowShare; |
25 private List<String> mMenuEntries; | 26 private List<String> mMenuEntries; |
26 private Map<MenuItem, Integer> mItemToIndexMap = new HashMap<MenuItem, Integ
er>(); | 27 private Map<MenuItem, Integer> mItemToIndexMap = new HashMap<MenuItem, Integ
er>(); |
27 /** | 28 /** |
28 * Creates an {@link CustomTabAppMenuPropertiesDelegate} instance. | 29 * Creates an {@link CustomTabAppMenuPropertiesDelegate} instance. |
29 */ | 30 */ |
30 public CustomTabAppMenuPropertiesDelegate(ChromeActivity activity, List<Stri
ng> menuEntries) { | 31 public CustomTabAppMenuPropertiesDelegate(ChromeActivity activity, List<Stri
ng> menuEntries, |
| 32 boolean showShare) { |
31 super(activity); | 33 super(activity); |
32 mMenuEntries = menuEntries; | 34 mMenuEntries = menuEntries; |
| 35 mShowShare = showShare; |
33 } | 36 } |
34 | 37 |
35 @Override | 38 @Override |
36 public void prepareMenu(Menu menu) { | 39 public void prepareMenu(Menu menu) { |
37 Tab currentTab = mActivity.getActivityTab(); | 40 Tab currentTab = mActivity.getActivityTab(); |
38 if (currentTab != null) { | 41 if (currentTab != null) { |
39 MenuItem forwardMenuItem = menu.findItem(R.id.forward_menu_id); | 42 MenuItem forwardMenuItem = menu.findItem(R.id.forward_menu_id); |
40 forwardMenuItem.setEnabled(currentTab.canGoForward()); | 43 forwardMenuItem.setEnabled(currentTab.canGoForward()); |
41 | 44 |
42 mReloadMenuItem = menu.findItem(R.id.reload_menu_id); | 45 mReloadMenuItem = menu.findItem(R.id.reload_menu_id); |
43 mReloadMenuItem.setIcon(R.drawable.btn_reload_stop); | 46 mReloadMenuItem.setIcon(R.drawable.btn_reload_stop); |
44 loadingStateChanged(currentTab.isLoading()); | 47 loadingStateChanged(currentTab.isLoading()); |
45 | 48 |
| 49 MenuItem shareItem = menu.findItem(R.id.share_menu_id); |
| 50 shareItem.setVisible(mShowShare); |
| 51 shareItem.setEnabled(mShowShare); |
| 52 |
46 MenuItem openInChromeItem = menu.findItem(R.id.open_in_chrome_id); | 53 MenuItem openInChromeItem = menu.findItem(R.id.open_in_chrome_id); |
47 openInChromeItem.setTitle(mActivity.getString(R.string.menu_open_in_
product, | 54 openInChromeItem.setTitle(mActivity.getString(R.string.menu_open_in_
product, |
48 mActivity.getString(R.string.app_name))); | 55 mActivity.getString(R.string.app_name))); |
49 | 56 |
50 // Add custom menu items. Make sure they are only added once. | 57 // Add custom menu items. Make sure they are only added once. |
51 if (!mIsCustomEntryAdded) { | 58 if (!mIsCustomEntryAdded) { |
52 mIsCustomEntryAdded = true; | 59 mIsCustomEntryAdded = true; |
53 for (int i = 0; i < mMenuEntries.size(); i++) { | 60 for (int i = 0; i < mMenuEntries.size(); i++) { |
54 MenuItem item = menu.add(0, 0, 1, mMenuEntries.get(i)); | 61 MenuItem item = menu.add(0, 0, 1, mMenuEntries.get(i)); |
55 mItemToIndexMap.put(item, i); | 62 mItemToIndexMap.put(item, i); |
(...skipping 23 matching lines...) Expand all Loading... |
79 * the same title, a random one will be returned. This method is for testing
purpose _only_. | 86 * the same title, a random one will be returned. This method is for testing
purpose _only_. |
80 */ | 87 */ |
81 @VisibleForTesting | 88 @VisibleForTesting |
82 MenuItem getMenuItemForTitle(String title) { | 89 MenuItem getMenuItemForTitle(String title) { |
83 for (MenuItem item : mItemToIndexMap.keySet()) { | 90 for (MenuItem item : mItemToIndexMap.keySet()) { |
84 if (item.getTitle().equals(title)) return item; | 91 if (item.getTitle().equals(title)) return item; |
85 } | 92 } |
86 return null; | 93 return null; |
87 } | 94 } |
88 } | 95 } |
OLD | NEW |