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

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

Issue 2744763005: 🏠 Add pull-handle to bottom toolbar (Closed)
Patch Set: address comments 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;
9 import android.graphics.Canvas;
10 import android.graphics.Paint;
11 import android.graphics.Rect;
12 import android.graphics.RectF;
8 import android.util.AttributeSet; 13 import android.util.AttributeSet;
14 import android.view.View;
9 import android.view.ViewGroup; 15 import android.view.ViewGroup;
16 import android.widget.ImageView;
10 17
18 import org.chromium.base.ApiCompatibilityUtils;
11 import org.chromium.chrome.R; 19 import org.chromium.chrome.R;
12 import org.chromium.chrome.browser.widget.BottomSheet; 20 import org.chromium.chrome.browser.widget.BottomSheet;
13 import org.chromium.chrome.browser.widget.BottomSheetObserver; 21 import org.chromium.chrome.browser.widget.BottomSheetObserver;
14 22
15 /** 23 /**
16 * Phone specific toolbar that exists at the bottom of the screen. 24 * Phone specific toolbar that exists at the bottom of the screen.
17 */ 25 */
18 public class BottomToolbarPhone extends ToolbarPhone implements BottomSheetObser ver { 26 public class BottomToolbarPhone extends ToolbarPhone implements BottomSheetObser ver {
27 /** The white version of the toolbar handle; used for dark themes and incogn ito. */
28 private final Bitmap mHandleLight;
29
30 /** The dark version of the toolbar handle; this is the default handle to us e. */
31 private final Bitmap mHandleDark;
32
19 /** A handle to the bottom sheet. */ 33 /** A handle to the bottom sheet. */
20 private BottomSheet mBottomSheet; 34 private BottomSheet mBottomSheet;
21 35
22 /** 36 /**
23 * Whether the end toolbar buttons should be hidden regardless of whether th e URL bar is 37 * Whether the end toolbar buttons should be hidden regardless of whether th e URL bar is
24 * focused. 38 * focused.
25 */ 39 */
26 private boolean mShouldHideEndToolbarButtons; 40 private boolean mShouldHideEndToolbarButtons;
27 41
28 /** 42 /**
29 * This tracks the height fraction of the bottom bar to determine if it is m oving up or down. 43 * This tracks the height fraction of the bottom bar to determine if it is m oving up or down.
30 */ 44 */
31 private float mLastHeightFraction; 45 private float mLastHeightFraction;
32 46
47 /** The toolbar handle view that indicates the toolbar can be pulled upward. */
48 private ImageView mToolbarHandleView;
49
33 /** 50 /**
34 * Constructs a BottomToolbarPhone object. 51 * Constructs a BottomToolbarPhone object.
35 * @param context The Context in which this View object is created. 52 * @param context The Context in which this View object is created.
36 * @param attrs The AttributeSet that was specified with this View. 53 * @param attrs The AttributeSet that was specified with this View.
37 */ 54 */
38 public BottomToolbarPhone(Context context, AttributeSet attrs) { 55 public BottomToolbarPhone(Context context, AttributeSet attrs) {
39 super(context, attrs); 56 super(context, attrs);
57
58 int defaultHandleColor =
59 ApiCompatibilityUtils.getColor(getResources(), R.color.google_gr ey_500);
60 mHandleDark = generateHandleBitmap(defaultHandleColor);
61
62 int lightHandleColor =
63 ApiCompatibilityUtils.getColor(getResources(), R.color.semi_opaq ue_white);
64 mHandleLight = generateHandleBitmap(lightHandleColor);
40 } 65 }
41 66
42 @Override 67 @Override
43 protected int getProgressBarTopMargin() { 68 protected int getProgressBarTopMargin() {
44 // In the case where the toolbar is at the bottom of the screen, the pro gress bar should 69 // In the case where the toolbar is at the bottom of the screen, the pro gress bar should
45 // be at the top of the screen. 70 // be at the top of the screen.
46 return 0; 71 return 0;
47 } 72 }
48 73
49 @Override 74 @Override
(...skipping 23 matching lines...) Expand all
73 98
74 @Override 99 @Override
75 protected void addProgressBarToHierarchy() { 100 protected void addProgressBarToHierarchy() {
76 if (mProgressBar == null) return; 101 if (mProgressBar == null) return;
77 102
78 ViewGroup coordinator = (ViewGroup) getRootView().findViewById(R.id.coor dinator); 103 ViewGroup coordinator = (ViewGroup) getRootView().findViewById(R.id.coor dinator);
79 coordinator.addView(mProgressBar); 104 coordinator.addView(mProgressBar);
80 mProgressBar.setProgressBarContainer(coordinator); 105 mProgressBar.setProgressBarContainer(coordinator);
81 } 106 }
82 107
108 /**
109 * @return The extra top margin that should be applied to the browser contro ls views to
110 * correctly offset them from the handle that sits above them.
111 */
112 private int getExtraTopMargin() {
113 return getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_top_m argin);
114 }
115
116 @Override
117 public void onFinishInflate() {
118 super.onFinishInflate();
119
120 // Programmatically apply a top margin to all the children of the toolba r container. This
121 // is done so the view hierarchy does not need to be changed.
122 int topMarginForControls = getExtraTopMargin();
123
124 View topShadow = findViewById(R.id.bottom_toolbar_shadow);
125
126 for (int i = 0; i < getChildCount(); i++) {
127 View curView = getChildAt(i);
128
129 // Skip the shadow that sits at the top of the toolbar.
gone 2017/03/14 22:38:40 Add why.
mdjones 2017/03/15 17:26:12 Done.
130 if (curView == topShadow) continue;
131
132 ((MarginLayoutParams) curView.getLayoutParams()).topMargin = topMarg inForControls;
133 }
134 }
135
136 @Override
137 public void onAttachedToWindow() {
138 super.onAttachedToWindow();
139
140 // The toolbar handle is part of the control container so it can draw on top of the other
141 // toolbar views. Get the root view and search for the handle.
142 mToolbarHandleView = (ImageView) getRootView().findViewById(R.id.toolbar _handle);
143 mToolbarHandleView.setImageBitmap(mHandleDark);
144 }
145
146 @Override
147 protected void updateVisualsForToolbarState() {
148 super.updateVisualsForToolbarState();
149
150 // The handle should not show in tab switcher mode.
151 mToolbarHandleView.setVisibility(
152 mTabSwitcherState != ToolbarPhone.STATIC_TAB ? View.INVISIBLE : View.VISIBLE);
153 mToolbarHandleView.setImageBitmap(mUseLightToolbarDrawables ? mHandleLig ht : mHandleDark);
154 }
155
156 @Override
157 protected void updateLocationBarBackgroundBounds(Rect out, VisualState visua lState) {
158 super.updateLocationBarBackgroundBounds(out, visualState);
159
160 // Allow the location bar to expand to the full height of the control co ntainer.
161 out.top -= getExtraTopMargin() * mUrlExpansionPercent;
162 }
163
164 /**
165 * Generate the bitmap used as the handle on the toolbar. This indicates tha t the toolbar can
166 * be pulled up.
167 * @return The handle as a bitmap.
168 */
169 private Bitmap generateHandleBitmap(int handleColor) {
170 int handleWidth = getResources().getDimensionPixelSize(R.dimen.toolbar_h andle_width);
171 int handleHeight = getResources().getDimensionPixelSize(R.dimen.toolbar_ handle_height);
172
173 Bitmap handle = Bitmap.createBitmap(handleWidth, handleHeight, Bitmap.Co nfig.ARGB_8888);
174
gone 2017/03/14 22:38:40 I guess you really like newlines, but please remov
mdjones 2017/03/15 17:26:12 Done.
175 Canvas canvas = new Canvas(handle);
176
177 // Clear the canvas to be completely transparent.
178 canvas.drawARGB(0, 0, 0, 0);
179
180 Paint paint = new Paint();
181 paint.setColor(handleColor);
182 paint.setAntiAlias(true);
183
184 RectF rect = new RectF(0, 0, handleWidth, handleHeight);
185
186 // Use height / 2 for the corner radius so the handle always takes the s hape of a pill.
187 canvas.drawRoundRect(rect, handleHeight / 2, handleHeight / 2, paint);
188
189 return handle;
190 }
191
83 @Override 192 @Override
84 protected boolean shouldHideEndToolbarButtons() { 193 protected boolean shouldHideEndToolbarButtons() {
85 return mShouldHideEndToolbarButtons; 194 return mShouldHideEndToolbarButtons;
86 } 195 }
87 196
88 @Override 197 @Override
89 public void onSheetOpened() {} 198 public void onSheetOpened() {}
90 199
91 @Override 200 @Override
92 public void onSheetClosed() {} 201 public void onSheetClosed() {}
(...skipping 22 matching lines...) Expand all
115 boolean isMovingDown = heightFraction < mLastHeightFraction; 224 boolean isMovingDown = heightFraction < mLastHeightFraction;
116 mLastHeightFraction = heightFraction; 225 mLastHeightFraction = heightFraction;
117 226
118 // The only time the omnibox should have focus is when the sheet is full y expanded. Any 227 // The only time the omnibox should have focus is when the sheet is full y expanded. Any
119 // movement of the sheet should unfocus it. 228 // movement of the sheet should unfocus it.
120 if (isMovingDown && getLocationBar().isUrlBarFocused()) { 229 if (isMovingDown && getLocationBar().isUrlBarFocused()) {
121 getLocationBar().setUrlBarFocus(false); 230 getLocationBar().setUrlBarFocus(false);
122 } 231 }
123 } 232 }
124 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698