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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/toolbar/BottomToolbarPhone.java

Issue 2853583002: 🏠 Add expand button and flag to enable it (Closed)
Patch Set: rebase Created 3 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.toolbar; 5 package org.chromium.chrome.browser.toolbar;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.res.ColorStateList;
8 import android.graphics.Canvas; 9 import android.graphics.Canvas;
9 import android.graphics.Rect; 10 import android.graphics.Rect;
10 import android.graphics.drawable.Drawable; 11 import android.graphics.drawable.Drawable;
11 import android.os.Build; 12 import android.os.Build;
13 import android.os.SystemClock;
12 import android.support.v7.widget.Toolbar; 14 import android.support.v7.widget.Toolbar;
13 import android.util.AttributeSet; 15 import android.util.AttributeSet;
14 import android.view.View; 16 import android.view.View;
15 import android.view.ViewGroup; 17 import android.view.ViewGroup;
16 import android.widget.ImageView; 18 import android.widget.ImageView;
17 19
18 import org.chromium.base.ApiCompatibilityUtils; 20 import org.chromium.base.ApiCompatibilityUtils;
19 import org.chromium.chrome.R; 21 import org.chromium.chrome.R;
20 import org.chromium.chrome.browser.device.DeviceClassManager; 22 import org.chromium.chrome.browser.device.DeviceClassManager;
21 import org.chromium.chrome.browser.util.ColorUtils; 23 import org.chromium.chrome.browser.util.ColorUtils;
24 import org.chromium.chrome.browser.util.FeatureUtilities;
25 import org.chromium.chrome.browser.widget.TintedImageButton;
22 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; 26 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
23 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetMetrics; 27 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetMetrics;
24 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetObserver; 28 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetObserver;
25 import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver; 29 import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
26 30
27 /** 31 /**
28 * Phone specific toolbar that exists at the bottom of the screen. 32 * Phone specific toolbar that exists at the bottom of the screen.
29 */ 33 */
30 public class BottomToolbarPhone extends ToolbarPhone { 34 public class BottomToolbarPhone extends ToolbarPhone {
31 /** 35 /**
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 85
82 /** The white version of the toolbar handle; used for dark themes and incogn ito. */ 86 /** The white version of the toolbar handle; used for dark themes and incogn ito. */
83 private final Drawable mHandleLight; 87 private final Drawable mHandleLight;
84 88
85 /** The dark version of the toolbar handle; this is the default handle to us e. */ 89 /** The dark version of the toolbar handle; this is the default handle to us e. */
86 private final Drawable mHandleDark; 90 private final Drawable mHandleDark;
87 91
88 /** A handle to the bottom sheet. */ 92 /** A handle to the bottom sheet. */
89 private BottomSheet mBottomSheet; 93 private BottomSheet mBottomSheet;
90 94
95 /** A handle to the expand button that Chrome Home may or may not use. */
96 private TintedImageButton mExpandButton;
97
91 /** 98 /**
92 * Whether the end toolbar buttons should be hidden regardless of whether th e URL bar is 99 * Whether the end toolbar buttons should be hidden regardless of whether th e URL bar is
93 * focused. 100 * focused.
94 */ 101 */
95 private boolean mShouldHideEndToolbarButtons; 102 private boolean mShouldHideEndToolbarButtons;
96 103
97 /** 104 /**
98 * This tracks the height fraction of the bottom bar to determine if it is m oving up or down. 105 * This tracks the height fraction of the bottom bar to determine if it is m oving up or down.
99 */ 106 */
100 private float mLastHeightFraction; 107 private float mLastHeightFraction;
101 108
102 /** The toolbar handle view that indicates the toolbar can be pulled upward. */ 109 /** The toolbar handle view that indicates the toolbar can be pulled upward. */
103 private ImageView mToolbarHandleView; 110 private ImageView mToolbarHandleView;
104 111
112 /** Whether or not the toolbar handle should be used. */
113 private boolean mUseToolbarHandle;
114
105 /** 115 /**
106 * Constructs a BottomToolbarPhone object. 116 * Constructs a BottomToolbarPhone object.
107 * @param context The Context in which this View object is created. 117 * @param context The Context in which this View object is created.
108 * @param attrs The AttributeSet that was specified with this View. 118 * @param attrs The AttributeSet that was specified with this View.
109 */ 119 */
110 public BottomToolbarPhone(Context context, AttributeSet attrs) { 120 public BottomToolbarPhone(Context context, AttributeSet attrs) {
111 super(context, attrs); 121 super(context, attrs);
112 122
113 mHandleDark = ApiCompatibilityUtils.getDrawable( 123 mHandleDark = ApiCompatibilityUtils.getDrawable(
114 context.getResources(), R.drawable.toolbar_handle_dark); 124 context.getResources(), R.drawable.toolbar_handle_dark);
115 mHandleLight = ApiCompatibilityUtils.getDrawable( 125 mHandleLight = ApiCompatibilityUtils.getDrawable(
116 context.getResources(), R.drawable.toolbar_handle_light); 126 context.getResources(), R.drawable.toolbar_handle_light);
117 mLocationBarVerticalMargin = 127 mLocationBarVerticalMargin =
118 getResources().getDimensionPixelOffset(R.dimen.bottom_location_b ar_vertical_margin); 128 getResources().getDimensionPixelOffset(R.dimen.bottom_location_b ar_vertical_margin);
129 mUseToolbarHandle = true;
119 } 130 }
120 131
121 /** 132 /**
122 * Set the color of the pull handle used by the toolbar. 133 * Set the color of the pull handle used by the toolbar.
123 * @param useLightDrawable If the handle color should be light. 134 * @param useLightDrawable If the handle color should be light.
124 */ 135 */
125 public void updateHandleTint(boolean useLightDrawable) { 136 public void updateHandleTint(boolean useLightDrawable) {
137 if (!mUseToolbarHandle) return;
126 mToolbarHandleView.setImageDrawable(useLightDrawable ? mHandleLight : mH andleDark); 138 mToolbarHandleView.setImageDrawable(useLightDrawable ? mHandleLight : mH andleDark);
127 } 139 }
128 140
129 /** 141 /**
130 * @return Whether or not the toolbar is currently using a light theme color . 142 * @return Whether or not the toolbar is currently using a light theme color .
131 */ 143 */
132 public boolean isLightTheme() { 144 public boolean isLightTheme() {
133 return !ColorUtils.shouldUseLightForegroundOnBackground(getTabThemeColor ()); 145 return !ColorUtils.shouldUseLightForegroundOnBackground(getTabThemeColor ());
134 } 146 }
135 147
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 ViewGroup coordinator = (ViewGroup) getRootView().findViewById(R.id.coor dinator); 212 ViewGroup coordinator = (ViewGroup) getRootView().findViewById(R.id.coor dinator);
201 coordinator.addView(mProgressBar); 213 coordinator.addView(mProgressBar);
202 mProgressBar.setProgressBarContainer(coordinator); 214 mProgressBar.setProgressBarContainer(coordinator);
203 } 215 }
204 216
205 /** 217 /**
206 * @return The extra top margin that should be applied to the browser contro ls views to 218 * @return The extra top margin that should be applied to the browser contro ls views to
207 * correctly offset them from the handle that sits above them. 219 * correctly offset them from the handle that sits above them.
208 */ 220 */
209 private int getExtraTopMargin() { 221 private int getExtraTopMargin() {
222 if (!mUseToolbarHandle) return 0;
210 return getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_top_m argin); 223 return getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_top_m argin);
211 } 224 }
212 225
213 @Override 226 @Override
227 protected int getBoundsAfterAccountingForLeftButton() {
228 int padding = super.getBoundsAfterAccountingForLeftButton();
229 if (!mUseToolbarHandle && mExpandButton.getVisibility() != GONE) {
230 padding = mExpandButton.getMeasuredWidth();
231 }
232 return padding;
233 }
234
235 @Override
236 public void updateButtonVisibility() {
237 super.updateButtonVisibility();
238 if (!mUseToolbarHandle) {
239 mExpandButton.setVisibility(
240 urlHasFocus() || isTabSwitcherAnimationRunning() ? INVISIBLE : VISIBLE);
241 }
242 }
243
244 @Override
245 protected void updateUrlExpansionAnimation() {
246 super.updateUrlExpansionAnimation();
247
248 if (!mUseToolbarHandle) {
249 mExpandButton.setVisibility(mShouldHideEndToolbarButtons ? View.GONE : View.VISIBLE);
250 }
251 }
252
253 @Override
214 public void onFinishInflate() { 254 public void onFinishInflate() {
215 super.onFinishInflate(); 255 super.onFinishInflate();
216 256
257 mExpandButton = (TintedImageButton) findViewById(R.id.expand_sheet_butto n);
258
217 // Add extra top margin to the URL bar to compensate for the change to l ocation bar's 259 // Add extra top margin to the URL bar to compensate for the change to l ocation bar's
218 // vertical margin in the constructor. 260 // vertical margin in the constructor.
219 ((MarginLayoutParams) mLocationBar.findViewById(R.id.url_bar).getLayoutP arams()).topMargin = 261 ((MarginLayoutParams) mLocationBar.findViewById(R.id.url_bar).getLayoutP arams()).topMargin =
220 getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_url_ bar_top_margin); 262 getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_url_ bar_top_margin);
221 263
222 // Exclude the location bar from the list of browsing mode views. This p revents its 264 // Exclude the location bar from the list of browsing mode views. This p revents its
223 // visibility from changing during transitions. 265 // visibility from changing during transitions.
224 mBrowsingModeViews.remove(mLocationBar); 266 mBrowsingModeViews.remove(mLocationBar);
225 267
268 updateToolbarTopMargin();
269 }
270
271 /**
272 * Update the top margin of all the components inside the toolbar. If the to olbar handle is
273 * being used, extra margin is added.
274 */
275 private void updateToolbarTopMargin() {
226 // Programmatically apply a top margin to all the children of the toolba r container. This 276 // Programmatically apply a top margin to all the children of the toolba r container. This
227 // is done so the view hierarchy does not need to be changed. 277 // is done so the view hierarchy does not need to be changed.
228 int topMarginForControls = getExtraTopMargin(); 278 int topMarginForControls = getExtraTopMargin();
229 279
230 View topShadow = findViewById(R.id.bottom_toolbar_shadow); 280 View topShadow = findViewById(R.id.bottom_toolbar_shadow);
231 281
232 for (int i = 0; i < getChildCount(); i++) { 282 for (int i = 0; i < getChildCount(); i++) {
233 View curView = getChildAt(i); 283 View curView = getChildAt(i);
234 284
235 // Skip the shadow that sits at the top of the toolbar since this ne eds to sit on top 285 // Skip the shadow that sits at the top of the toolbar since this ne eds to sit on top
236 // of the toolbar. 286 // of the toolbar.
237 if (curView == topShadow) continue; 287 if (curView == topShadow) continue;
238 288
239 ((MarginLayoutParams) curView.getLayoutParams()).topMargin = topMarg inForControls; 289 ((MarginLayoutParams) curView.getLayoutParams()).topMargin = topMarg inForControls;
240 } 290 }
241 } 291 }
242 292
243 @Override 293 @Override
244 public void onAttachedToWindow() { 294 public void onAttachedToWindow() {
245 super.onAttachedToWindow(); 295 super.onAttachedToWindow();
246 296
247 // The toolbar handle is part of the control container so it can draw on top of the other 297 // The toolbar handle is part of the control container so it can draw on top of the
248 // toolbar views. Get the root view and search for the handle. 298 // other toolbar views, this way there is only a single handle instead o f each having its
299 // own. Get the root view and search for the handle.
249 mToolbarHandleView = (ImageView) getRootView().findViewById(R.id.toolbar _handle); 300 mToolbarHandleView = (ImageView) getRootView().findViewById(R.id.toolbar _handle);
250 mToolbarHandleView.setImageDrawable(mHandleDark); 301 mToolbarHandleView.setImageDrawable(mHandleDark);
251 } 302 }
252 303
253 @Override 304 @Override
305 public void onNativeLibraryReady() {
306 super.onNativeLibraryReady();
307
308 mUseToolbarHandle = !FeatureUtilities.isChromeHomeExpandButtonEnabled();
309
310 if (!mUseToolbarHandle) initExpandButton();
311 }
312
313 /**
314 * Initialize the "expand" button if it is being used.
315 */
316 private void initExpandButton() {
317 mLocationBarVerticalMargin =
318 getResources().getDimensionPixelOffset(R.dimen.location_bar_vert ical_margin);
319
320 mToolbarHandleView.setVisibility(View.GONE);
321
322 mExpandButton.setOnClickListener(new OnClickListener() {
323 @Override
324 public void onClick(View v) {
325 if (mBottomSheet != null) mBottomSheet.onExpandButtonPressed();
326 }
327 });
328
329 mExpandButton.setVisibility(View.VISIBLE);
330 mBrowsingModeViews.add(mExpandButton);
331
332 updateToolbarTopMargin();
333 }
334
335 @Override
254 protected void updateVisualsForToolbarState() { 336 protected void updateVisualsForToolbarState() {
255 super.updateVisualsForToolbarState(); 337 super.updateVisualsForToolbarState();
256 338
257 // TODO(mdjones): Creating a new tab from the tab switcher skips the 339 // TODO(mdjones): Creating a new tab from the tab switcher skips the
258 // drawTabSwitcherFadeAnimation which would otherwise make this line unn ecessary. 340 // drawTabSwitcherFadeAnimation which would otherwise make this line unn ecessary.
259 if (mTabSwitcherState == STATIC_TAB) mToolbarHandleView.setAlpha(1f); 341 if (mTabSwitcherState == STATIC_TAB && mUseToolbarHandle) mToolbarHandle View.setAlpha(1f);
260 342
261 // The tab switcher's background color should not affect the toolbar han dle; it should only 343 // The tab switcher's background color should not affect the toolbar han dle; it should only
262 // switch color based on the static tab's theme color. This is done so f ade in/out looks 344 // switch color based on the static tab's theme color. This is done so f ade in/out looks
263 // correct. 345 // correct.
264 mToolbarHandleView.setImageDrawable(isLightTheme() ? mHandleDark : mHand leLight); 346 if (mUseToolbarHandle) {
347 mToolbarHandleView.setImageDrawable(isLightTheme() ? mHandleDark : m HandleLight);
348 } else {
349 ColorStateList tint = mUseLightToolbarDrawables ? mLightModeTint : m DarkModeTint;
350 mExpandButton.setTint(tint);
351 }
265 } 352 }
266 353
267 @Override 354 @Override
268 protected void updateLocationBarBackgroundBounds(Rect out, VisualState visua lState) { 355 protected void updateLocationBarBackgroundBounds(Rect out, VisualState visua lState) {
269 super.updateLocationBarBackgroundBounds(out, visualState); 356 super.updateLocationBarBackgroundBounds(out, visualState);
270 357
271 // Allow the location bar to expand to the full height of the control co ntainer. 358 // Allow the location bar to expand to the full height of the control co ntainer.
272 out.top -= getExtraTopMargin() * mUrlExpansionPercent; 359 out.top -= getExtraTopMargin() * mUrlExpansionPercent;
273 } 360 }
274 361
275 @Override 362 @Override
276 protected boolean shouldDrawLocationBar() { 363 protected boolean shouldDrawLocationBar() {
277 return true; 364 return true;
278 } 365 }
279 366
280 @Override 367 @Override
281 protected void drawTabSwitcherFadeAnimation(boolean animationFinished, float progress) { 368 protected void drawTabSwitcherFadeAnimation(boolean animationFinished, float progress) {
282 mNewTabButton.setAlpha(progress); 369 mNewTabButton.setAlpha(progress);
283 370
284 mLocationBar.setAlpha(1f - progress); 371 mLocationBar.setAlpha(1f - progress);
285 mToolbarHandleView.setAlpha(1f - progress); 372 if (mUseToolbarHandle) mToolbarHandleView.setAlpha(1f - progress);
286 373
287 int tabSwitcherThemeColor = getToolbarColorForVisualState(VisualState.TA B_SWITCHER_NORMAL); 374 int tabSwitcherThemeColor = getToolbarColorForVisualState(VisualState.TA B_SWITCHER_NORMAL);
288 375
289 updateToolbarBackground(ColorUtils.getColorWithOverlay( 376 updateToolbarBackground(ColorUtils.getColorWithOverlay(
290 getTabThemeColor(), tabSwitcherThemeColor, progress)); 377 getTabThemeColor(), tabSwitcherThemeColor, progress));
291 378
292 // Don't use transparency for accessibility mode or low-end devices sinc e the 379 // Don't use transparency for accessibility mode or low-end devices sinc e the
293 // {@link OverviewListLayout} will be used instead of the normal tab swi tcher. 380 // {@link OverviewListLayout} will be used instead of the normal tab swi tcher.
294 if (!DeviceClassManager.enableAccessibilityLayout()) { 381 if (!DeviceClassManager.enableAccessibilityLayout()) {
295 float alphaTransition = 1f - TAB_SWITCHER_TOOLBAR_ALPHA; 382 float alphaTransition = 1f - TAB_SWITCHER_TOOLBAR_ALPHA;
296 mToolbarBackground.setAlpha((int) ((1f - (alphaTransition * progress )) * 255)); 383 mToolbarBackground.setAlpha((int) ((1f - (alphaTransition * progress )) * 255));
297 } 384 }
298 } 385 }
299 386
300 @Override 387 @Override
301 public void finishAnimations() { 388 public void finishAnimations() {
302 super.finishAnimations(); 389 super.finishAnimations();
303 drawTabSwitcherFadeAnimation(true, mTabSwitcherModePercent); 390 drawTabSwitcherFadeAnimation(true, mTabSwitcherModePercent);
304 } 391 }
305 392
306 @Override 393 @Override
307 protected void drawTabSwitcherAnimationOverlay(Canvas canvas, float animatio nProgress) { 394 protected void drawTabSwitcherAnimationOverlay(Canvas canvas, float animatio nProgress) {
308 // Intentionally overridden to block everything but the compositor scree n shot. Otherwise 395 // Intentionally overridden to block everything but the compositor scree n shot. Otherwise
309 // the toolbar in Chrome Home does not have an animation overlay compone nt. 396 // the toolbar in Chrome Home does not have an animation overlay compone nt.
310 if (mTextureCaptureMode) super.drawTabSwitcherAnimationOverlay(canvas, 0 f); 397 if (mTextureCaptureMode) {
398 super.drawTabSwitcherAnimationOverlay(canvas, 0f);
399 if (!mUseToolbarHandle && mExpandButton.getVisibility() != View.GONE ) {
400 drawChild(canvas, mExpandButton, SystemClock.uptimeMillis());
401 }
402 }
311 } 403 }
312 404
313 @Override 405 @Override
314 protected void resetNtpAnimationValues() { 406 protected void resetNtpAnimationValues() {
315 // The NTP animations don't matter if the browser is in tab switcher mod e. 407 // The NTP animations don't matter if the browser is in tab switcher mod e.
316 if (mTabSwitcherState != ToolbarPhone.STATIC_TAB) return; 408 if (mTabSwitcherState != ToolbarPhone.STATIC_TAB) return;
317 super.resetNtpAnimationValues(); 409 super.resetNtpAnimationValues();
318 } 410 }
319 411
320 @Override 412 @Override
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 otherToolbar.setTitleTextAppearance( 447 otherToolbar.setTitleTextAppearance(
356 otherToolbar.getContext(), R.style.BottomSheetContentTitle); 448 otherToolbar.getContext(), R.style.BottomSheetContentTitle);
357 ApiCompatibilityUtils.setPaddingRelative(otherToolbar, 449 ApiCompatibilityUtils.setPaddingRelative(otherToolbar,
358 ApiCompatibilityUtils.getPaddingStart(otherToolbar), 450 ApiCompatibilityUtils.getPaddingStart(otherToolbar),
359 otherToolbar.getPaddingTop() + extraTopMargin, 451 otherToolbar.getPaddingTop() + extraTopMargin,
360 ApiCompatibilityUtils.getPaddingEnd(otherToolbar), otherToolbar. getPaddingBottom()); 452 ApiCompatibilityUtils.getPaddingEnd(otherToolbar), otherToolbar. getPaddingBottom());
361 453
362 otherToolbar.requestLayout(); 454 otherToolbar.requestLayout();
363 } 455 }
364 } 456 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698