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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/hosted/HostedAppMenuPropertiesDelegate.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.hosted;
6
7 import android.view.Menu;
8 import android.view.MenuItem;
9
10 import com.google.android.apps.chrome.R;
11
12 import org.chromium.chrome.browser.ChromeActivity;
13 import org.chromium.chrome.browser.Tab;
14 import org.chromium.chrome.browser.appmenu.ChromeAppMenuPropertiesDelegate;
15
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19
20 /**
21 * App menu properties delegate for {@link HostedActivity}.
22 */
23 public class HostedAppMenuPropertiesDelegate extends ChromeAppMenuPropertiesDele gate {
24 private boolean mIsCustomEntryAdded;
25 private List<String> mMenuEntries;
26 private Map<MenuItem, Integer> mItemToIndexMap = new HashMap<MenuItem, Integ er>();
27 /**
28 * Creates an {@link HostedAppMenuPropertiesDelegate} instance.
29 */
30 public HostedAppMenuPropertiesDelegate(ChromeActivity activity,
31 List<String> menuEntries) {
32 super(activity);
33 mMenuEntries = menuEntries;
34 }
35
36 @Override
37 public void prepareMenu(Menu menu) {
38 Tab currentTab = mActivity.getActivityTab();
39 if (currentTab != null) {
40 MenuItem forwardMenuItem = menu.findItem(R.id.forward_menu_id);
41 forwardMenuItem.setEnabled(currentTab.canGoForward());
42
43 mReloadMenuItem = menu.findItem(R.id.reload_menu_id);
44 mReloadMenuItem.setIcon(R.drawable.btn_reload_stop);
45 // Update the loading state of mReloadMenuItem.
46 if (currentTab.isLoading()) loadingStateChanged(true);
47
48 // Add custom menu items. Make sure they are only added once.
49 if (!mIsCustomEntryAdded) {
50 mIsCustomEntryAdded = true;
51 for (int i = 0; i < mMenuEntries.size(); i++) {
52 MenuItem item = menu.add(0, 0, 1, mMenuEntries.get(i));
53 mItemToIndexMap.put(item, i);
54 }
55 }
56 }
57 }
58
59 /**
60 * @return The index that the given menu item should appear in the result of
61 * {@link HostedIntentDataProvider#getMenuTitles()}. Returns -1 if i tem not found.
62 */
63 public int getIndexOfMenuItem(MenuItem menuItem) {
64 if (!mItemToIndexMap.containsKey(menuItem)) {
65 return -1;
66 }
67 return mItemToIndexMap.get(menuItem).intValue();
68 }
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698