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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuPropertiesDelegate.java

Issue 2821223004: [Home] Show the app menu icons as a footer (Closed)
Patch Set: Changes from tedchoc@ review 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 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.appmenu; 5 package org.chromium.chrome.browser.appmenu;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.pm.ResolveInfo; 8 import android.content.pm.ResolveInfo;
9 import android.graphics.PorterDuff; 9 import android.graphics.PorterDuff;
10 import android.graphics.drawable.Drawable; 10 import android.graphics.drawable.Drawable;
11 import android.os.SystemClock; 11 import android.os.SystemClock;
12 import android.support.annotation.Nullable;
12 import android.view.Menu; 13 import android.view.Menu;
13 import android.view.MenuItem; 14 import android.view.MenuItem;
15 import android.view.View;
14 16
15 import org.chromium.base.ApiCompatibilityUtils; 17 import org.chromium.base.ApiCompatibilityUtils;
16 import org.chromium.base.CommandLine; 18 import org.chromium.base.CommandLine;
17 import org.chromium.base.ContextUtils; 19 import org.chromium.base.ContextUtils;
18 import org.chromium.base.metrics.RecordHistogram; 20 import org.chromium.base.metrics.RecordHistogram;
19 import org.chromium.chrome.R; 21 import org.chromium.chrome.R;
20 import org.chromium.chrome.browser.ChromeActivity; 22 import org.chromium.chrome.browser.ChromeActivity;
21 import org.chromium.chrome.browser.ChromeSwitches; 23 import org.chromium.chrome.browser.ChromeSwitches;
22 import org.chromium.chrome.browser.ShortcutHelper; 24 import org.chromium.chrome.browser.ShortcutHelper;
23 import org.chromium.chrome.browser.UrlConstants; 25 import org.chromium.chrome.browser.UrlConstants;
(...skipping 13 matching lines...) Expand all
37 39
38 import java.util.concurrent.TimeUnit; 40 import java.util.concurrent.TimeUnit;
39 41
40 /** 42 /**
41 * App Menu helper that handles hiding and showing menu items based on activity state. 43 * App Menu helper that handles hiding and showing menu items based on activity state.
42 */ 44 */
43 public class AppMenuPropertiesDelegate { 45 public class AppMenuPropertiesDelegate {
44 // Indices for different levels in drawable.btn_reload_stop. 46 // Indices for different levels in drawable.btn_reload_stop.
45 // Used only when preparing menu and refresh reload button in menu when tab 47 // Used only when preparing menu and refresh reload button in menu when tab
46 // page load status changes. 48 // page load status changes.
47 private static final int RELOAD_BUTTON_LEVEL_RELOAD = 0; 49 static final int RELOAD_BUTTON_LEVEL_RELOAD = 0;
48 private static final int RELOAD_BUTTON_LEVEL_STOP_LOADING = 1; 50 static final int RELOAD_BUTTON_LEVEL_STOP_LOADING = 1;
49 51
50 protected MenuItem mReloadMenuItem; 52 protected MenuItem mReloadMenuItem;
51 53
52 protected final ChromeActivity mActivity; 54 protected final ChromeActivity mActivity;
53 55
54 protected BookmarkBridge mBookmarkBridge; 56 protected BookmarkBridge mBookmarkBridge;
55 57
58 @Nullable
59 private AppMenuIconRowFooter mAppMenuIconRowFooter;
60
56 public AppMenuPropertiesDelegate(ChromeActivity activity) { 61 public AppMenuPropertiesDelegate(ChromeActivity activity) {
57 mActivity = activity; 62 mActivity = activity;
58 } 63 }
59 64
60 /** 65 /**
61 * @return Whether the App Menu should be shown. 66 * @return Whether the App Menu should be shown.
62 */ 67 */
63 public boolean shouldShowAppMenu() { 68 public boolean shouldShowAppMenu() {
64 return mActivity.shouldShowAppMenu(); 69 return mActivity.shouldShowAppMenu();
65 } 70 }
(...skipping 29 matching lines...) Expand all
95 menu.setGroupVisible(R.id.PAGE_MENU, isPageMenu); 100 menu.setGroupVisible(R.id.PAGE_MENU, isPageMenu);
96 menu.setGroupVisible(R.id.OVERVIEW_MODE_MENU, isOverviewMenu); 101 menu.setGroupVisible(R.id.OVERVIEW_MODE_MENU, isOverviewMenu);
97 menu.setGroupVisible(R.id.TABLET_EMPTY_MODE_MENU, isTabletEmptyModeMenu) ; 102 menu.setGroupVisible(R.id.TABLET_EMPTY_MODE_MENU, isTabletEmptyModeMenu) ;
98 103
99 if (isPageMenu && currentTab != null) { 104 if (isPageMenu && currentTab != null) {
100 String url = currentTab.getUrl(); 105 String url = currentTab.getUrl();
101 boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREF IX) 106 boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREF IX)
102 || url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX); 107 || url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX);
103 boolean isFileScheme = url.startsWith(UrlConstants.FILE_URL_PREFIX); 108 boolean isFileScheme = url.startsWith(UrlConstants.FILE_URL_PREFIX);
104 boolean isContentScheme = url.startsWith(UrlConstants.CONTENT_URL_PR EFIX); 109 boolean isContentScheme = url.startsWith(UrlConstants.CONTENT_URL_PR EFIX);
105 boolean shouldShowIconRow = !mActivity.isTablet() 110
106 || mActivity.getWindow().getDecorView().getWidth() 111 // If the BottomSheet is not null, the icon row will be displayed us ing
107 < DeviceFormFactor.getMinimumTabletWidthPx(mActivity ); 112 // AppMenuIconRowFooter as a prompt view.
113 boolean shouldShowIconRow = mActivity.getBottomSheet() == null
114 && (!mActivity.isTablet()
115 || mActivity.getWindow().getDecorView().getWidth( )
116 < DeviceFormFactor.getMinimumTabletWidthP x(mActivity));
108 117
109 // Update the icon row items (shown in narrow form factors). 118 // Update the icon row items (shown in narrow form factors).
110 menu.findItem(R.id.icon_row_menu_id).setVisible(shouldShowIconRow); 119 menu.findItem(R.id.icon_row_menu_id).setVisible(shouldShowIconRow);
111 if (shouldShowIconRow) { 120 if (shouldShowIconRow) {
112 // Disable the "Forward" menu item if there is no page to go to. 121 // Disable the "Forward" menu item if there is no page to go to.
113 MenuItem forwardMenuItem = menu.findItem(R.id.forward_menu_id); 122 MenuItem forwardMenuItem = menu.findItem(R.id.forward_menu_id);
114 forwardMenuItem.setEnabled(currentTab.canGoForward()); 123 forwardMenuItem.setEnabled(currentTab.canGoForward());
115 124
116 mReloadMenuItem = menu.findItem(R.id.reload_menu_id); 125 mReloadMenuItem = menu.findItem(R.id.reload_menu_id);
117 mReloadMenuItem.setIcon(R.drawable.btn_reload_stop); 126 mReloadMenuItem.setIcon(R.drawable.btn_reload_stop);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // main_menu.xml contains multiple items with the same id in different g roups 224 // main_menu.xml contains multiple items with the same id in different g roups
216 // e.g.: new_incognito_tab_menu_id. 225 // e.g.: new_incognito_tab_menu_id.
217 disableEnableMenuItem(menu, R.id.new_incognito_tab_menu_id, 226 disableEnableMenuItem(menu, R.id.new_incognito_tab_menu_id,
218 true, 227 true,
219 PrefServiceBridge.getInstance().isIncognitoModeEnabled(), 228 PrefServiceBridge.getInstance().isIncognitoModeEnabled(),
220 PrefServiceBridge.getInstance().isIncognitoModeManaged()); 229 PrefServiceBridge.getInstance().isIncognitoModeManaged());
221 mActivity.prepareMenu(menu); 230 mActivity.prepareMenu(menu);
222 } 231 }
223 232
224 /** 233 /**
234 * Called after the menu has been shown to finish initializing views.
235 * @param menu The {@link AppMenu} that was shown.
236 */
237 public void onShow(final AppMenu menu) {
238 View promptView = menu.getPromptView();
239 if (!(promptView instanceof AppMenuIconRowFooter)) {
240 mAppMenuIconRowFooter = null;
241 return;
242 }
243
244 mAppMenuIconRowFooter = (AppMenuIconRowFooter) promptView;
245 mAppMenuIconRowFooter.initialize(mActivity, menu, mBookmarkBridge);
246 }
247
248 /**
225 * Sets the visibility and labels of the "Add to Home screen" and "Open WebA PK" menu items. 249 * Sets the visibility and labels of the "Add to Home screen" and "Open WebA PK" menu items.
226 */ 250 */
227 protected void prepareAddToHomescreenMenuItem( 251 protected void prepareAddToHomescreenMenuItem(
228 Menu menu, Tab currentTab, boolean canShowHomeScreenMenuItem) { 252 Menu menu, Tab currentTab, boolean canShowHomeScreenMenuItem) {
229 // Record whether or not we have finished installability checks for this page when we're 253 // Record whether or not we have finished installability checks for this page when we're
230 // preparing the menu to be displayed. This will let us determine if it is feasible to 254 // preparing the menu to be displayed. This will let us determine if it is feasible to
231 // change the add to homescreen menu item based on whether a site is a P WA. 255 // change the add to homescreen menu item based on whether a site is a P WA.
232 currentTab.getAppBannerManager().recordMenuOpen(); 256 currentTab.getAppBannerManager().recordMenuOpen();
233 257
234 MenuItem homescreenItem = menu.findItem(R.id.add_to_homescreen_id); 258 MenuItem homescreenItem = menu.findItem(R.id.add_to_homescreen_id);
(...skipping 29 matching lines...) Expand all
264 /** 288 /**
265 * Notify the delegate that the load state changed. 289 * Notify the delegate that the load state changed.
266 * @param isLoading Whether the page is currently loading. 290 * @param isLoading Whether the page is currently loading.
267 */ 291 */
268 public void loadingStateChanged(boolean isLoading) { 292 public void loadingStateChanged(boolean isLoading) {
269 if (mReloadMenuItem != null) { 293 if (mReloadMenuItem != null) {
270 mReloadMenuItem.getIcon().setLevel(isLoading 294 mReloadMenuItem.getIcon().setLevel(isLoading
271 ? RELOAD_BUTTON_LEVEL_STOP_LOADING : RELOAD_BUTTON_LEVEL_REL OAD); 295 ? RELOAD_BUTTON_LEVEL_STOP_LOADING : RELOAD_BUTTON_LEVEL_REL OAD);
272 mReloadMenuItem.setTitle(isLoading 296 mReloadMenuItem.setTitle(isLoading
273 ? R.string.accessibility_btn_stop_loading : R.string.accessi bility_btn_refresh); 297 ? R.string.accessibility_btn_stop_loading : R.string.accessi bility_btn_refresh);
298 } else if (mAppMenuIconRowFooter != null) {
299 mAppMenuIconRowFooter.loadingStateChanged(isLoading);
274 } 300 }
275 } 301 }
276 302
277 /** 303 /**
278 * Notify the delegate that menu was dismissed. 304 * Notify the delegate that menu was dismissed.
279 */ 305 */
280 public void onMenuDismissed() { 306 public void onMenuDismissed() {
281 mReloadMenuItem = null; 307 mReloadMenuItem = null;
282 } 308 }
283 309
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 String url = currentTab.getUrl(); 380 String url = currentTab.getUrl();
355 boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX) 381 boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX)
356 || url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX); 382 || url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX);
357 requstMenuItem.setVisible(!isChromeScheme || currentTab.isNativePage()); 383 requstMenuItem.setVisible(!isChromeScheme || currentTab.isNativePage());
358 requstMenuItem.setChecked(currentTab.getUseDesktopUserAgent()); 384 requstMenuItem.setChecked(currentTab.getUseDesktopUserAgent());
359 requstMenuItem.setTitleCondensed(requstMenuItem.isChecked() 385 requstMenuItem.setTitleCondensed(requstMenuItem.isChecked()
360 ? mActivity.getString(R.string.menu_request_desktop_site_on) 386 ? mActivity.getString(R.string.menu_request_desktop_site_on)
361 : mActivity.getString(R.string.menu_request_desktop_site_off)); 387 : mActivity.getString(R.string.menu_request_desktop_site_off));
362 } 388 }
363 } 389 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuIconRowFooter.java ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698