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

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

Issue 2754313002: [Home] Record some user actions for the Chrome Home BottomSheet (Closed)
Patch Set: [Home] Record some user actions for the Chrome Home BottomSheet Created 3 years, 9 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.graphics.Bitmap; 8 import android.graphics.Bitmap;
9 import android.graphics.Canvas; 9 import android.graphics.Canvas;
10 import android.graphics.Paint; 10 import android.graphics.Paint;
11 import android.graphics.Rect; 11 import android.graphics.Rect;
12 import android.graphics.RectF; 12 import android.graphics.RectF;
13 import android.support.v7.widget.Toolbar; 13 import android.support.v7.widget.Toolbar;
14 import android.util.AttributeSet; 14 import android.util.AttributeSet;
15 import android.view.View; 15 import android.view.View;
16 import android.view.ViewGroup; 16 import android.view.ViewGroup;
17 import android.widget.ImageView; 17 import android.widget.ImageView;
18 18
19 import org.chromium.base.ApiCompatibilityUtils; 19 import org.chromium.base.ApiCompatibilityUtils;
20 import org.chromium.chrome.R; 20 import org.chromium.chrome.R;
21 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; 21 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
22 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetObserver; 22 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetObserver;
23 import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
23 24
24 /** 25 /**
25 * Phone specific toolbar that exists at the bottom of the screen. 26 * Phone specific toolbar that exists at the bottom of the screen.
26 */ 27 */
27 public class BottomToolbarPhone extends ToolbarPhone implements BottomSheetObser ver { 28 public class BottomToolbarPhone extends ToolbarPhone {
29 /**
30 * The observer used to listen to {@link BottomSheet} events.
31 */
32 private final BottomSheetObserver mBottomSheetObserver = new EmptyBottomShee tObserver() {
33 @Override
34 public void onTransitionPeekToHalf(float transitionFraction) {
35 // TODO(twellington): animate end toolbar button appearance/disappea rance.
36 if (transitionFraction >= 0.5 && !mShouldHideEndToolbarButtons) {
37 mShouldHideEndToolbarButtons = true;
38 updateUrlExpansionAnimation();
39 } else if (transitionFraction < 0.5 && mShouldHideEndToolbarButtons) {
40 mShouldHideEndToolbarButtons = false;
41 updateUrlExpansionAnimation();
42 }
43
44 boolean buttonsClickable = transitionFraction == 0.f;
45 mToggleTabStackButton.setClickable(buttonsClickable);
46 mMenuButton.setClickable(buttonsClickable);
47 }
48
49 @Override
50 public void onSheetOffsetChanged(float heightFraction) {
51 boolean isMovingDown = heightFraction < mLastHeightFraction;
52 mLastHeightFraction = heightFraction;
53
54 // The only time the omnibox should have focus is when the sheet is fully expanded. Any
55 // movement of the sheet should unfocus it.
56 if (isMovingDown && getLocationBar().isUrlBarFocused()) {
57 getLocationBar().setUrlBarFocus(false);
58 }
59 }
60 };
61
28 /** The white version of the toolbar handle; used for dark themes and incogn ito. */ 62 /** The white version of the toolbar handle; used for dark themes and incogn ito. */
29 private final Bitmap mHandleLight; 63 private final Bitmap mHandleLight;
30 64
31 /** The dark version of the toolbar handle; this is the default handle to us e. */ 65 /** The dark version of the toolbar handle; this is the default handle to us e. */
32 private final Bitmap mHandleDark; 66 private final Bitmap mHandleDark;
33 67
34 /** A handle to the bottom sheet. */ 68 /** A handle to the bottom sheet. */
35 private BottomSheet mBottomSheet; 69 private BottomSheet mBottomSheet;
36 70
37 /** 71 /**
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 114
81 mBottomSheet.setSheetState(BottomSheet.SHEET_STATE_FULL, true); 115 mBottomSheet.setSheetState(BottomSheet.SHEET_STATE_FULL, true);
82 } 116 }
83 117
84 @Override 118 @Override
85 public void setBottomSheet(BottomSheet sheet) { 119 public void setBottomSheet(BottomSheet sheet) {
86 assert mBottomSheet == null; 120 assert mBottomSheet == null;
87 121
88 mBottomSheet = sheet; 122 mBottomSheet = sheet;
89 getLocationBar().setBottomSheet(mBottomSheet); 123 getLocationBar().setBottomSheet(mBottomSheet);
90 mBottomSheet.addObserver(this); 124 mBottomSheet.addObserver(mBottomSheetObserver);
91 } 125 }
92 126
93 @Override 127 @Override
94 public boolean shouldIgnoreSwipeGesture() { 128 public boolean shouldIgnoreSwipeGesture() {
95 // Only detect swipes if the bottom sheet in the peeking state and not a nimating. 129 // Only detect swipes if the bottom sheet in the peeking state and not a nimating.
96 return mBottomSheet.getSheetState() != BottomSheet.SHEET_STATE_PEEK 130 return mBottomSheet.getSheetState() != BottomSheet.SHEET_STATE_PEEK
97 || mBottomSheet.isRunningSettleAnimation() || super.shouldIgnore SwipeGesture(); 131 || mBottomSheet.isRunningSettleAnimation() || super.shouldIgnore SwipeGesture();
98 } 132 }
99 133
100 @Override 134 @Override
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 canvas.drawRoundRect(rect, handleHeight / 2f, handleHeight / 2f, paint); 222 canvas.drawRoundRect(rect, handleHeight / 2f, handleHeight / 2f, paint);
189 223
190 return handle; 224 return handle;
191 } 225 }
192 226
193 @Override 227 @Override
194 protected boolean shouldHideEndToolbarButtons() { 228 protected boolean shouldHideEndToolbarButtons() {
195 return mShouldHideEndToolbarButtons; 229 return mShouldHideEndToolbarButtons;
196 } 230 }
197 231
198 @Override
199 public void onSheetOpened() {}
200
201 @Override
202 public void onSheetClosed() {}
203
204 @Override
205 public void onLoadUrl(String url) {}
206
207 @Override
208 public void onTransitionPeekToHalf(float transitionFraction) {
209 // TODO(twellington): animate end toolbar button appearance/disappearanc e.
210 if (transitionFraction >= 0.5 && !mShouldHideEndToolbarButtons) {
211 mShouldHideEndToolbarButtons = true;
212 updateUrlExpansionAnimation();
213 } else if (transitionFraction < 0.5 && mShouldHideEndToolbarButtons) {
214 mShouldHideEndToolbarButtons = false;
215 updateUrlExpansionAnimation();
216 }
217
218 boolean buttonsClickable = transitionFraction == 0.f;
219 mToggleTabStackButton.setClickable(buttonsClickable);
220 mMenuButton.setClickable(buttonsClickable);
221 }
222
223 @Override
224 public void onSheetOffsetChanged(float heightFraction) {
225 boolean isMovingDown = heightFraction < mLastHeightFraction;
226 mLastHeightFraction = heightFraction;
227
228 // The only time the omnibox should have focus is when the sheet is full y expanded. Any
229 // movement of the sheet should unfocus it.
230 if (isMovingDown && getLocationBar().isUrlBarFocused()) {
231 getLocationBar().setUrlBarFocus(false);
232 }
233 }
234
235 /** 232 /**
236 * Sets the height and title text appearance of the provided toolbar so that its style is 233 * Sets the height and title text appearance of the provided toolbar so that its style is
237 * consistent with BottomToolbarPhone. 234 * consistent with BottomToolbarPhone.
238 * @param otherToolbar The other {@link Toolbar} to style. 235 * @param otherToolbar The other {@link Toolbar} to style.
239 */ 236 */
240 public void setOtherToolbarStyle(Toolbar otherToolbar) { 237 public void setOtherToolbarStyle(Toolbar otherToolbar) {
241 // Android's Toolbar class typically changes its height based on device orientation. 238 // Android's Toolbar class typically changes its height based on device orientation.
242 // BottomToolbarPhone has a fixed height. Update |toolbar| to match. 239 // BottomToolbarPhone has a fixed height. Update |toolbar| to match.
243 otherToolbar.getLayoutParams().height = getHeight(); 240 otherToolbar.getLayoutParams().height = getHeight();
244 241
245 // Android Toolbar action buttons are aligned based on the minimum heigh t. 242 // Android Toolbar action buttons are aligned based on the minimum heigh t.
246 int extraTopMargin = getExtraTopMargin(); 243 int extraTopMargin = getExtraTopMargin();
247 otherToolbar.setMinimumHeight(getHeight() - extraTopMargin); 244 otherToolbar.setMinimumHeight(getHeight() - extraTopMargin);
248 245
249 otherToolbar.setTitleTextAppearance( 246 otherToolbar.setTitleTextAppearance(
250 otherToolbar.getContext(), R.style.BottomSheetContentTitle); 247 otherToolbar.getContext(), R.style.BottomSheetContentTitle);
251 ApiCompatibilityUtils.setPaddingRelative(otherToolbar, 248 ApiCompatibilityUtils.setPaddingRelative(otherToolbar,
252 ApiCompatibilityUtils.getPaddingStart(otherToolbar), 249 ApiCompatibilityUtils.getPaddingStart(otherToolbar),
253 otherToolbar.getPaddingTop() + extraTopMargin, 250 otherToolbar.getPaddingTop() + extraTopMargin,
254 ApiCompatibilityUtils.getPaddingEnd(otherToolbar), otherToolbar. getPaddingBottom()); 251 ApiCompatibilityUtils.getPaddingEnd(otherToolbar), otherToolbar. getPaddingBottom());
255 252
256 otherToolbar.requestLayout(); 253 otherToolbar.requestLayout();
257 } 254 }
258 } 255 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698