OLD | NEW |
---|---|
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.base.SysUtils; | 21 import org.chromium.base.SysUtils; |
20 import org.chromium.chrome.R; | 22 import org.chromium.chrome.R; |
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 Loading... | |
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 |
105 /** Whether accessibility is enabled. */ | 112 /** Whether accessibility is enabled. */ |
106 private boolean mAccessibilityEnabled; | 113 private boolean mAccessibilityEnabled; |
107 | 114 |
115 /** Whether or not the toolbar handle should be used. */ | |
116 private boolean mUseToolbarHandle; | |
117 | |
108 /** | 118 /** |
109 * Constructs a BottomToolbarPhone object. | 119 * Constructs a BottomToolbarPhone object. |
110 * @param context The Context in which this View object is created. | 120 * @param context The Context in which this View object is created. |
111 * @param attrs The AttributeSet that was specified with this View. | 121 * @param attrs The AttributeSet that was specified with this View. |
112 */ | 122 */ |
113 public BottomToolbarPhone(Context context, AttributeSet attrs) { | 123 public BottomToolbarPhone(Context context, AttributeSet attrs) { |
114 super(context, attrs); | 124 super(context, attrs); |
115 | 125 |
116 mHandleDark = ApiCompatibilityUtils.getDrawable( | 126 mHandleDark = ApiCompatibilityUtils.getDrawable( |
117 context.getResources(), R.drawable.toolbar_handle_dark); | 127 context.getResources(), R.drawable.toolbar_handle_dark); |
118 mHandleLight = ApiCompatibilityUtils.getDrawable( | 128 mHandleLight = ApiCompatibilityUtils.getDrawable( |
119 context.getResources(), R.drawable.toolbar_handle_light); | 129 context.getResources(), R.drawable.toolbar_handle_light); |
120 mLocationBarVerticalMargin = | 130 mLocationBarVerticalMargin = |
121 getResources().getDimensionPixelOffset(R.dimen.bottom_location_b ar_vertical_margin); | 131 getResources().getDimensionPixelOffset(R.dimen.bottom_location_b ar_vertical_margin); |
132 mUseToolbarHandle = true; | |
122 } | 133 } |
123 | 134 |
124 /** | 135 /** |
125 * Set the color of the pull handle used by the toolbar. | 136 * Set the color of the pull handle used by the toolbar. |
126 * @param useLightDrawable If the handle color should be light. | 137 * @param useLightDrawable If the handle color should be light. |
127 */ | 138 */ |
128 public void updateHandleTint(boolean useLightDrawable) { | 139 public void updateHandleTint(boolean useLightDrawable) { |
140 if (!mUseToolbarHandle) return; | |
129 mToolbarHandleView.setImageDrawable(useLightDrawable ? mHandleLight : mH andleDark); | 141 mToolbarHandleView.setImageDrawable(useLightDrawable ? mHandleLight : mH andleDark); |
130 } | 142 } |
131 | 143 |
132 /** | 144 /** |
133 * @return Whether or not the toolbar is currently using a light theme color . | 145 * @return Whether or not the toolbar is currently using a light theme color . |
134 */ | 146 */ |
135 public boolean isLightTheme() { | 147 public boolean isLightTheme() { |
136 return !ColorUtils.shouldUseLightForegroundOnBackground(getTabThemeColor ()); | 148 return !ColorUtils.shouldUseLightForegroundOnBackground(getTabThemeColor ()); |
137 } | 149 } |
138 | 150 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 ViewGroup coordinator = (ViewGroup) getRootView().findViewById(R.id.coor dinator); | 208 ViewGroup coordinator = (ViewGroup) getRootView().findViewById(R.id.coor dinator); |
197 coordinator.addView(mProgressBar); | 209 coordinator.addView(mProgressBar); |
198 mProgressBar.setProgressBarContainer(coordinator); | 210 mProgressBar.setProgressBarContainer(coordinator); |
199 } | 211 } |
200 | 212 |
201 /** | 213 /** |
202 * @return The extra top margin that should be applied to the browser contro ls views to | 214 * @return The extra top margin that should be applied to the browser contro ls views to |
203 * correctly offset them from the handle that sits above them. | 215 * correctly offset them from the handle that sits above them. |
204 */ | 216 */ |
205 private int getExtraTopMargin() { | 217 private int getExtraTopMargin() { |
218 if (!mUseToolbarHandle) return 0; | |
206 return getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_top_m argin); | 219 return getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_top_m argin); |
207 } | 220 } |
208 | 221 |
209 @Override | 222 @Override |
223 protected int getBoundsAfterAccountingForLeftButton() { | |
224 int padding = super.getBoundsAfterAccountingForLeftButton(); | |
225 if (!mUseToolbarHandle && mExpandButton.getVisibility() != GONE) { | |
226 padding = mExpandButton.getMeasuredWidth(); | |
227 } | |
228 return padding; | |
229 } | |
230 | |
231 @Override | |
232 public void updateButtonVisibility() { | |
233 super.updateButtonVisibility(); | |
234 if (!mUseToolbarHandle) { | |
235 mExpandButton.setVisibility( | |
236 urlHasFocus() || isTabSwitcherAnimationRunning() ? INVISIBLE : VISIBLE); | |
237 } | |
238 } | |
239 | |
240 @Override | |
241 protected void updateUrlExpansionAnimation() { | |
242 super.updateUrlExpansionAnimation(); | |
243 | |
244 if (!mUseToolbarHandle) { | |
245 mExpandButton.setVisibility(mShouldHideEndToolbarButtons ? View.GONE : View.VISIBLE); | |
246 } | |
247 } | |
248 | |
249 @Override | |
210 public void onFinishInflate() { | 250 public void onFinishInflate() { |
211 super.onFinishInflate(); | 251 super.onFinishInflate(); |
212 | 252 |
253 mExpandButton = (TintedImageButton) findViewById(R.id.expand_sheet_butto n); | |
254 | |
213 // Add extra top margin to the URL bar to compensate for the change to l ocation bar's | 255 // Add extra top margin to the URL bar to compensate for the change to l ocation bar's |
214 // vertical margin in the constructor. | 256 // vertical margin in the constructor. |
215 ((MarginLayoutParams) mLocationBar.findViewById(R.id.url_bar).getLayoutP arams()).topMargin = | 257 ((MarginLayoutParams) mLocationBar.findViewById(R.id.url_bar).getLayoutP arams()).topMargin = |
216 getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_url_ bar_top_margin); | 258 getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_url_ bar_top_margin); |
217 | 259 |
218 // Exclude the location bar from the list of browsing mode views. This p revents its | 260 // Exclude the location bar from the list of browsing mode views. This p revents its |
219 // visibility from changing during transitions. | 261 // visibility from changing during transitions. |
220 mBrowsingModeViews.remove(mLocationBar); | 262 mBrowsingModeViews.remove(mLocationBar); |
221 | 263 |
264 updateToolbarTopMargin(); | |
265 } | |
266 | |
267 /** | |
268 * Update the top margin of all the components inside the toolbar. If the to olbar handle is | |
269 * being used, extra margin is added. | |
270 */ | |
271 private void updateToolbarTopMargin() { | |
222 // Programmatically apply a top margin to all the children of the toolba r container. This | 272 // Programmatically apply a top margin to all the children of the toolba r container. This |
223 // is done so the view hierarchy does not need to be changed. | 273 // is done so the view hierarchy does not need to be changed. |
224 int topMarginForControls = getExtraTopMargin(); | 274 int topMarginForControls = getExtraTopMargin(); |
225 | 275 |
226 View topShadow = findViewById(R.id.bottom_toolbar_shadow); | 276 View topShadow = findViewById(R.id.bottom_toolbar_shadow); |
227 | 277 |
228 for (int i = 0; i < getChildCount(); i++) { | 278 for (int i = 0; i < getChildCount(); i++) { |
229 View curView = getChildAt(i); | 279 View curView = getChildAt(i); |
230 | 280 |
231 // Skip the shadow that sits at the top of the toolbar since this ne eds to sit on top | 281 // Skip the shadow that sits at the top of the toolbar since this ne eds to sit on top |
232 // of the toolbar. | 282 // of the toolbar. |
233 if (curView == topShadow) continue; | 283 if (curView == topShadow) continue; |
234 | 284 |
235 ((MarginLayoutParams) curView.getLayoutParams()).topMargin = topMarg inForControls; | 285 ((MarginLayoutParams) curView.getLayoutParams()).topMargin = topMarg inForControls; |
236 } | 286 } |
237 } | 287 } |
238 | 288 |
239 @Override | 289 @Override |
240 public void onAttachedToWindow() { | 290 public void onAttachedToWindow() { |
241 super.onAttachedToWindow(); | 291 super.onAttachedToWindow(); |
242 | 292 |
243 // The toolbar handle is part of the control container so it can draw on top of the other | 293 // The toolbar handle is part of the control container so it can draw on top of the |
244 // toolbar views. Get the root view and search for the handle. | 294 // other toolbar views, this way there is only a single handle instead o f each having its |
295 // own. Get the root view and search for the handle. | |
245 mToolbarHandleView = (ImageView) getRootView().findViewById(R.id.toolbar _handle); | 296 mToolbarHandleView = (ImageView) getRootView().findViewById(R.id.toolbar _handle); |
246 mToolbarHandleView.setImageDrawable(mHandleDark); | 297 mToolbarHandleView.setImageDrawable(mHandleDark); |
247 } | 298 } |
248 | 299 |
249 @Override | 300 @Override |
301 public void onNativeLibraryReady() { | |
302 super.onNativeLibraryReady(); | |
303 | |
304 mUseToolbarHandle = !FeatureUtilities.isChromeHomeExpandButtonEnabled(); | |
305 | |
306 if (!mUseToolbarHandle) initExpandButton(); | |
307 } | |
308 | |
309 /** | |
310 * Initialize the "expand" button if it is being used. | |
311 */ | |
312 private void initExpandButton() { | |
313 mLocationBarVerticalMargin = | |
314 getResources().getDimensionPixelOffset(R.dimen.location_bar_vert ical_margin); | |
315 | |
316 mToolbarHandleView.setVisibility(View.GONE); | |
317 | |
318 mExpandButton.setOnClickListener(new OnClickListener() { | |
319 @Override | |
320 public void onClick(View v) { | |
321 if (mBottomSheet == null) return; | |
322 mBottomSheet.onExpandButtonPressed(); | |
gone
2017/05/02 17:25:07
if (mBottomSheet != null) mBottomSheet.onExpandBut
mdjones
2017/05/02 18:46:10
Done.
| |
323 } | |
324 }); | |
325 | |
326 mExpandButton.setVisibility(View.VISIBLE); | |
327 mBrowsingModeViews.add(mExpandButton); | |
328 | |
329 updateToolbarTopMargin(); | |
330 } | |
331 | |
332 @Override | |
250 protected void updateVisualsForToolbarState() { | 333 protected void updateVisualsForToolbarState() { |
251 super.updateVisualsForToolbarState(); | 334 super.updateVisualsForToolbarState(); |
252 | 335 |
253 // TODO(mdjones): Creating a new tab from the tab switcher skips the | 336 // TODO(mdjones): Creating a new tab from the tab switcher skips the |
254 // drawTabSwitcherFadeAnimation which would otherwise make this line unn ecessary. | 337 // drawTabSwitcherFadeAnimation which would otherwise make this line unn ecessary. |
255 if (mTabSwitcherState == STATIC_TAB) mToolbarHandleView.setAlpha(1f); | 338 if (mTabSwitcherState == STATIC_TAB && mUseToolbarHandle) mToolbarHandle View.setAlpha(1f); |
256 | 339 |
257 // The tab switcher's background color should not affect the toolbar han dle; it should only | 340 // The tab switcher's background color should not affect the toolbar han dle; it should only |
258 // switch color based on the static tab's theme color. This is done so f ade in/out looks | 341 // switch color based on the static tab's theme color. This is done so f ade in/out looks |
259 // correct. | 342 // correct. |
260 mToolbarHandleView.setImageDrawable(isLightTheme() ? mHandleDark : mHand leLight); | 343 if (mUseToolbarHandle) { |
344 mToolbarHandleView.setImageDrawable(isLightTheme() ? mHandleDark : m HandleLight); | |
345 } else { | |
346 ColorStateList tint = mUseLightToolbarDrawables ? mLightModeTint : m DarkModeTint; | |
347 mExpandButton.setTint(tint); | |
348 } | |
261 } | 349 } |
262 | 350 |
263 @Override | 351 @Override |
264 protected void updateLocationBarBackgroundBounds(Rect out, VisualState visua lState) { | 352 protected void updateLocationBarBackgroundBounds(Rect out, VisualState visua lState) { |
265 super.updateLocationBarBackgroundBounds(out, visualState); | 353 super.updateLocationBarBackgroundBounds(out, visualState); |
266 | 354 |
267 // Allow the location bar to expand to the full height of the control co ntainer. | 355 // Allow the location bar to expand to the full height of the control co ntainer. |
268 out.top -= getExtraTopMargin() * mUrlExpansionPercent; | 356 out.top -= getExtraTopMargin() * mUrlExpansionPercent; |
269 } | 357 } |
270 | 358 |
271 @Override | 359 @Override |
272 protected boolean shouldDrawLocationBar() { | 360 protected boolean shouldDrawLocationBar() { |
273 return true; | 361 return true; |
274 } | 362 } |
275 | 363 |
276 @Override | 364 @Override |
277 protected void drawTabSwitcherFadeAnimation(boolean animationFinished, float progress) { | 365 protected void drawTabSwitcherFadeAnimation(boolean animationFinished, float progress) { |
278 mNewTabButton.setAlpha(progress); | 366 mNewTabButton.setAlpha(progress); |
279 | 367 |
280 mLocationBar.setAlpha(1f - progress); | 368 mLocationBar.setAlpha(1f - progress); |
281 mToolbarHandleView.setAlpha(1f - progress); | 369 if (mUseToolbarHandle) mToolbarHandleView.setAlpha(1f - progress); |
282 | 370 |
283 int tabSwitcherThemeColor = getToolbarColorForVisualState(VisualState.TA B_SWITCHER_NORMAL); | 371 int tabSwitcherThemeColor = getToolbarColorForVisualState(VisualState.TA B_SWITCHER_NORMAL); |
284 | 372 |
285 updateToolbarBackground(ColorUtils.getColorWithOverlay( | 373 updateToolbarBackground(ColorUtils.getColorWithOverlay( |
286 getTabThemeColor(), tabSwitcherThemeColor, progress)); | 374 getTabThemeColor(), tabSwitcherThemeColor, progress)); |
287 | 375 |
288 // Don't use transparency for accessibility mode or low-end devices sinc e the | 376 // Don't use transparency for accessibility mode or low-end devices sinc e the |
289 // {@link OverviewListLayout} will be used instead of the normal tab swi tcher. | 377 // {@link OverviewListLayout} will be used instead of the normal tab swi tcher. |
290 if (!mAccessibilityEnabled && !SysUtils.isLowEndDevice()) { | 378 if (!mAccessibilityEnabled && !SysUtils.isLowEndDevice()) { |
291 float alphaTransition = 1f - TAB_SWITCHER_TOOLBAR_ALPHA; | 379 float alphaTransition = 1f - TAB_SWITCHER_TOOLBAR_ALPHA; |
(...skipping 10 matching lines...) Expand all Loading... | |
302 @Override | 390 @Override |
303 protected void onAccessibilityStatusChanged(boolean enabled) { | 391 protected void onAccessibilityStatusChanged(boolean enabled) { |
304 super.onAccessibilityStatusChanged(enabled); | 392 super.onAccessibilityStatusChanged(enabled); |
305 mAccessibilityEnabled = enabled; | 393 mAccessibilityEnabled = enabled; |
306 } | 394 } |
307 | 395 |
308 @Override | 396 @Override |
309 protected void drawTabSwitcherAnimationOverlay(Canvas canvas, float animatio nProgress) { | 397 protected void drawTabSwitcherAnimationOverlay(Canvas canvas, float animatio nProgress) { |
310 // Intentionally overridden to block everything but the compositor scree n shot. Otherwise | 398 // Intentionally overridden to block everything but the compositor scree n shot. Otherwise |
311 // the toolbar in Chrome Home does not have an animation overlay compone nt. | 399 // the toolbar in Chrome Home does not have an animation overlay compone nt. |
312 if (mTextureCaptureMode) super.drawTabSwitcherAnimationOverlay(canvas, 0 f); | 400 if (mTextureCaptureMode) { |
401 super.drawTabSwitcherAnimationOverlay(canvas, 0f); | |
402 if (!mUseToolbarHandle && mExpandButton.getVisibility() != View.GONE ) { | |
403 drawChild(canvas, mExpandButton, SystemClock.uptimeMillis()); | |
404 } | |
405 } | |
313 } | 406 } |
314 | 407 |
315 @Override | 408 @Override |
316 protected void resetNtpAnimationValues() { | 409 protected void resetNtpAnimationValues() { |
317 // The NTP animations don't matter if the browser is in tab switcher mod e. | 410 // The NTP animations don't matter if the browser is in tab switcher mod e. |
318 if (mTabSwitcherState != ToolbarPhone.STATIC_TAB) return; | 411 if (mTabSwitcherState != ToolbarPhone.STATIC_TAB) return; |
319 super.resetNtpAnimationValues(); | 412 super.resetNtpAnimationValues(); |
320 } | 413 } |
321 | 414 |
322 @Override | 415 @Override |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 otherToolbar.setTitleTextAppearance( | 450 otherToolbar.setTitleTextAppearance( |
358 otherToolbar.getContext(), R.style.BottomSheetContentTitle); | 451 otherToolbar.getContext(), R.style.BottomSheetContentTitle); |
359 ApiCompatibilityUtils.setPaddingRelative(otherToolbar, | 452 ApiCompatibilityUtils.setPaddingRelative(otherToolbar, |
360 ApiCompatibilityUtils.getPaddingStart(otherToolbar), | 453 ApiCompatibilityUtils.getPaddingStart(otherToolbar), |
361 otherToolbar.getPaddingTop() + extraTopMargin, | 454 otherToolbar.getPaddingTop() + extraTopMargin, |
362 ApiCompatibilityUtils.getPaddingEnd(otherToolbar), otherToolbar. getPaddingBottom()); | 455 ApiCompatibilityUtils.getPaddingEnd(otherToolbar), otherToolbar. getPaddingBottom()); |
363 | 456 |
364 otherToolbar.requestLayout(); | 457 otherToolbar.requestLayout(); |
365 } | 458 } |
366 } | 459 } |
OLD | NEW |