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 != null && mExpandButton.getVisi bility() != GONE) { | |
gone
2017/04/30 01:56:00
You constantly use !mUseToolbarHandle && mExpandBu
mdjones
2017/05/01 20:46:08
Removed the null checks.
| |
226 padding = mExpandButton.getMeasuredWidth() | |
227 + getResources().getDimensionPixelSize( | |
228 R.dimen.chrome_home_expand_button_extra_padding); | |
229 } | |
230 return padding; | |
231 } | |
232 | |
233 @Override | |
234 public void updateButtonVisibility() { | |
235 super.updateButtonVisibility(); | |
236 if (!mUseToolbarHandle && mExpandButton != null) { | |
237 mExpandButton.setVisibility( | |
238 urlHasFocus() || isTabSwitcherAnimationRunning() ? INVISIBLE : VISIBLE); | |
239 } | |
240 } | |
241 | |
242 @Override | |
243 protected void updateUrlExpansionAnimation() { | |
244 super.updateUrlExpansionAnimation(); | |
245 | |
246 if (!mUseToolbarHandle && mExpandButton != null) { | |
247 mExpandButton.setVisibility(mShouldHideEndToolbarButtons ? View.GONE : View.VISIBLE); | |
248 } | |
249 } | |
250 | |
251 @Override | |
210 public void onFinishInflate() { | 252 public void onFinishInflate() { |
211 super.onFinishInflate(); | 253 super.onFinishInflate(); |
212 | 254 |
255 if (mExpandButton != null) { | |
256 // Make the "expand" button square. | |
257 mExpandButton.getLayoutParams().width = mExpandButton.getHeight(); | |
258 } | |
259 | |
213 // Add extra top margin to the URL bar to compensate for the change to l ocation bar's | 260 // Add extra top margin to the URL bar to compensate for the change to l ocation bar's |
214 // vertical margin in the constructor. | 261 // vertical margin in the constructor. |
215 ((MarginLayoutParams) mLocationBar.findViewById(R.id.url_bar).getLayoutP arams()).topMargin = | 262 ((MarginLayoutParams) mLocationBar.findViewById(R.id.url_bar).getLayoutP arams()).topMargin = |
216 getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_url_ bar_top_margin); | 263 getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_url_ bar_top_margin); |
217 | 264 |
218 // Exclude the location bar from the list of browsing mode views. This p revents its | 265 // Exclude the location bar from the list of browsing mode views. This p revents its |
219 // visibility from changing during transitions. | 266 // visibility from changing during transitions. |
220 mBrowsingModeViews.remove(mLocationBar); | 267 mBrowsingModeViews.remove(mLocationBar); |
221 | 268 |
269 updateToolbarTopMargin(); | |
270 } | |
271 | |
272 /** | |
273 * Update the top margin of all the components inside the toolbar. If the to olbar handle is | |
274 * being used, extra margin is added. | |
275 */ | |
276 private void updateToolbarTopMargin() { | |
222 // Programmatically apply a top margin to all the children of the toolba r container. This | 277 // 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. | 278 // is done so the view hierarchy does not need to be changed. |
224 int topMarginForControls = getExtraTopMargin(); | 279 int topMarginForControls = getExtraTopMargin(); |
280 if (topMarginForControls == 0) return; | |
225 | 281 |
226 View topShadow = findViewById(R.id.bottom_toolbar_shadow); | 282 View topShadow = findViewById(R.id.bottom_toolbar_shadow); |
227 | 283 |
228 for (int i = 0; i < getChildCount(); i++) { | 284 for (int i = 0; i < getChildCount(); i++) { |
229 View curView = getChildAt(i); | 285 View curView = getChildAt(i); |
230 | 286 |
231 // Skip the shadow that sits at the top of the toolbar since this ne eds to sit on top | 287 // Skip the shadow that sits at the top of the toolbar since this ne eds to sit on top |
232 // of the toolbar. | 288 // of the toolbar. |
233 if (curView == topShadow) continue; | 289 if (curView == topShadow) continue; |
234 | 290 |
235 ((MarginLayoutParams) curView.getLayoutParams()).topMargin = topMarg inForControls; | 291 ((MarginLayoutParams) curView.getLayoutParams()).topMargin = topMarg inForControls; |
236 } | 292 } |
237 } | 293 } |
238 | 294 |
239 @Override | 295 @Override |
240 public void onAttachedToWindow() { | 296 public void onAttachedToWindow() { |
241 super.onAttachedToWindow(); | 297 super.onAttachedToWindow(); |
242 | 298 |
243 // The toolbar handle is part of the control container so it can draw on top of the other | 299 // The toolbar handle is part of the control container so it can draw on top of the |
gone
2017/04/30 01:56:00
why?
mdjones
2017/05/01 20:46:08
Reasons.
| |
244 // toolbar views. Get the root view and search for the handle. | 300 // other toolbar views. Get the root view and search for the handle. |
245 mToolbarHandleView = (ImageView) getRootView().findViewById(R.id.toolbar _handle); | 301 mToolbarHandleView = (ImageView) getRootView().findViewById(R.id.toolbar _handle); |
246 mToolbarHandleView.setImageDrawable(mHandleDark); | 302 mToolbarHandleView.setImageDrawable(mHandleDark); |
247 } | 303 } |
248 | 304 |
249 @Override | 305 @Override |
306 public void onNativeLibraryReady() { | |
307 super.onNativeLibraryReady(); | |
308 | |
309 mUseToolbarHandle = !FeatureUtilities.isChromeHomeExpandButtonEnabled(); | |
310 mExpandButton = (TintedImageButton) findViewById(R.id.expand_sheet_butto n); | |
311 mExpandButton.setOnClickListener(new OnClickListener() { | |
312 @Override | |
313 public void onClick(View v) { | |
314 if (mBottomSheet == null) return; | |
315 | |
316 mBottomSheet.setSheetState(BottomSheet.SHEET_STATE_HALF, true); | |
317 } | |
318 }); | |
319 | |
320 if (!mUseToolbarHandle) { | |
321 mToolbarHandleView.setVisibility(View.GONE); | |
322 | |
323 // If not using the toolbar handle, change the height of the control container to be | |
324 // the same as the top toolbar. | |
325 getRootView().findViewById(R.id.control_container).getLayoutParams() .height = | |
326 getResources().getDimensionPixelSize(R.dimen.control_contain er_height) | |
327 + getResources().getDimensionPixelSize(R.dimen.toolbar_shado w_height); | |
328 } else { | |
329 mExpandButton.setVisibility(View.VISIBLE); | |
330 mBrowsingModeViews.add(mExpandButton); | |
331 } | |
332 | |
333 updateToolbarTopMargin(); | |
334 } | |
335 | |
336 @Override | |
250 protected void updateVisualsForToolbarState() { | 337 protected void updateVisualsForToolbarState() { |
251 super.updateVisualsForToolbarState(); | 338 super.updateVisualsForToolbarState(); |
252 | 339 |
253 // TODO(mdjones): Creating a new tab from the tab switcher skips the | 340 // TODO(mdjones): Creating a new tab from the tab switcher skips the |
254 // drawTabSwitcherFadeAnimation which would otherwise make this line unn ecessary. | 341 // drawTabSwitcherFadeAnimation which would otherwise make this line unn ecessary. |
255 if (mTabSwitcherState == STATIC_TAB) mToolbarHandleView.setAlpha(1f); | 342 if (mTabSwitcherState == STATIC_TAB && mUseToolbarHandle) mToolbarHandle View.setAlpha(1f); |
256 | 343 |
257 // The tab switcher's background color should not affect the toolbar han dle; it should only | 344 // 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 | 345 // switch color based on the static tab's theme color. This is done so f ade in/out looks |
259 // correct. | 346 // correct. |
260 mToolbarHandleView.setImageDrawable(isLightTheme() ? mHandleDark : mHand leLight); | 347 if (mUseToolbarHandle) { |
gone
2017/04/30 01:56:00
You treat the toolbar handle's non-existence as an
mdjones
2017/05/01 20:46:08
The expand button waits for the native library to
| |
348 mToolbarHandleView.setImageDrawable(isLightTheme() ? mHandleDark : m HandleLight); | |
349 } else { | |
350 ColorStateList tint = mUseLightToolbarDrawables ? mLightModeTint : m DarkModeTint; | |
351 mExpandButton.setTint(tint); | |
352 } | |
261 } | 353 } |
262 | 354 |
263 @Override | 355 @Override |
264 protected void updateLocationBarBackgroundBounds(Rect out, VisualState visua lState) { | 356 protected void updateLocationBarBackgroundBounds(Rect out, VisualState visua lState) { |
265 super.updateLocationBarBackgroundBounds(out, visualState); | 357 super.updateLocationBarBackgroundBounds(out, visualState); |
266 | 358 |
267 // Allow the location bar to expand to the full height of the control co ntainer. | 359 // Allow the location bar to expand to the full height of the control co ntainer. |
268 out.top -= getExtraTopMargin() * mUrlExpansionPercent; | 360 out.top -= getExtraTopMargin() * mUrlExpansionPercent; |
269 } | 361 } |
270 | 362 |
271 @Override | 363 @Override |
272 protected boolean shouldDrawLocationBar() { | 364 protected boolean shouldDrawLocationBar() { |
273 return true; | 365 return true; |
274 } | 366 } |
275 | 367 |
276 @Override | 368 @Override |
277 protected void drawTabSwitcherFadeAnimation(boolean animationFinished, float progress) { | 369 protected void drawTabSwitcherFadeAnimation(boolean animationFinished, float progress) { |
278 mNewTabButton.setAlpha(progress); | 370 mNewTabButton.setAlpha(progress); |
279 | 371 |
280 mLocationBar.setAlpha(1f - progress); | 372 mLocationBar.setAlpha(1f - progress); |
281 mToolbarHandleView.setAlpha(1f - progress); | 373 if (mUseToolbarHandle) mToolbarHandleView.setAlpha(1f - progress); |
282 | 374 |
283 int tabSwitcherThemeColor = getToolbarColorForVisualState(VisualState.TA B_SWITCHER_NORMAL); | 375 int tabSwitcherThemeColor = getToolbarColorForVisualState(VisualState.TA B_SWITCHER_NORMAL); |
284 | 376 |
285 updateToolbarBackground(ColorUtils.getColorWithOverlay( | 377 updateToolbarBackground(ColorUtils.getColorWithOverlay( |
286 getTabThemeColor(), tabSwitcherThemeColor, progress)); | 378 getTabThemeColor(), tabSwitcherThemeColor, progress)); |
287 | 379 |
288 // Don't use transparency for accessibility mode or low-end devices sinc e the | 380 // 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. | 381 // {@link OverviewListLayout} will be used instead of the normal tab swi tcher. |
290 if (!mAccessibilityEnabled && !SysUtils.isLowEndDevice()) { | 382 if (!mAccessibilityEnabled && !SysUtils.isLowEndDevice()) { |
291 float alphaTransition = 1f - TAB_SWITCHER_TOOLBAR_ALPHA; | 383 float alphaTransition = 1f - TAB_SWITCHER_TOOLBAR_ALPHA; |
(...skipping 10 matching lines...) Expand all Loading... | |
302 @Override | 394 @Override |
303 protected void onAccessibilityStatusChanged(boolean enabled) { | 395 protected void onAccessibilityStatusChanged(boolean enabled) { |
304 super.onAccessibilityStatusChanged(enabled); | 396 super.onAccessibilityStatusChanged(enabled); |
305 mAccessibilityEnabled = enabled; | 397 mAccessibilityEnabled = enabled; |
306 } | 398 } |
307 | 399 |
308 @Override | 400 @Override |
309 protected void drawTabSwitcherAnimationOverlay(Canvas canvas, float animatio nProgress) { | 401 protected void drawTabSwitcherAnimationOverlay(Canvas canvas, float animatio nProgress) { |
310 // Intentionally overridden to block everything but the compositor scree n shot. Otherwise | 402 // 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. | 403 // the toolbar in Chrome Home does not have an animation overlay compone nt. |
312 if (mTextureCaptureMode) super.drawTabSwitcherAnimationOverlay(canvas, 0 f); | 404 if (mTextureCaptureMode) { |
405 super.drawTabSwitcherAnimationOverlay(canvas, 0f); | |
406 float previousAlpha = 0.f; | |
gone
2017/04/30 01:56:00
Where do you actually use this?
mdjones
2017/05/01 20:46:08
I don't any more. Removed.
| |
407 if (mExpandButton != null && mExpandButton.getVisibility() != View.G ONE) { | |
408 drawChild(canvas, mExpandButton, SystemClock.uptimeMillis()); | |
409 } | |
410 } | |
313 } | 411 } |
314 | 412 |
315 @Override | 413 @Override |
316 protected void resetNtpAnimationValues() { | 414 protected void resetNtpAnimationValues() { |
317 // The NTP animations don't matter if the browser is in tab switcher mod e. | 415 // The NTP animations don't matter if the browser is in tab switcher mod e. |
318 if (mTabSwitcherState != ToolbarPhone.STATIC_TAB) return; | 416 if (mTabSwitcherState != ToolbarPhone.STATIC_TAB) return; |
319 super.resetNtpAnimationValues(); | 417 super.resetNtpAnimationValues(); |
320 } | 418 } |
321 | 419 |
322 @Override | 420 @Override |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 otherToolbar.setTitleTextAppearance( | 455 otherToolbar.setTitleTextAppearance( |
358 otherToolbar.getContext(), R.style.BottomSheetContentTitle); | 456 otherToolbar.getContext(), R.style.BottomSheetContentTitle); |
359 ApiCompatibilityUtils.setPaddingRelative(otherToolbar, | 457 ApiCompatibilityUtils.setPaddingRelative(otherToolbar, |
360 ApiCompatibilityUtils.getPaddingStart(otherToolbar), | 458 ApiCompatibilityUtils.getPaddingStart(otherToolbar), |
361 otherToolbar.getPaddingTop() + extraTopMargin, | 459 otherToolbar.getPaddingTop() + extraTopMargin, |
362 ApiCompatibilityUtils.getPaddingEnd(otherToolbar), otherToolbar. getPaddingBottom()); | 460 ApiCompatibilityUtils.getPaddingEnd(otherToolbar), otherToolbar. getPaddingBottom()); |
363 | 461 |
364 otherToolbar.requestLayout(); | 462 otherToolbar.requestLayout(); |
365 } | 463 } |
366 } | 464 } |
OLD | NEW |