Chromium Code Reviews| 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.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.toolbar_h andle_color); | |
| 60 mHandleDark = generateHandleBitmap(defaultHandleColor); | |
| 61 | |
| 62 int lightHandleColor = ApiCompatibilityUtils.getColor( | |
| 63 getResources(), R.color.toolbar_handle_color_incognito); | |
| 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 Loading... | |
| 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. | |
| 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 // The toolbar shadow adds extra height to the toolbar; compensate for t hat now. | |
| 146 ((MarginLayoutParams) mToolbarHandleView.getLayoutParams()).topMargin += | |
| 147 getResources().getDimensionPixelSize(R.dimen.toolbar_shadow_heig ht); | |
|
Theresa
2017/03/13 23:08:42
Can toolbar_handle_margin_top be its current value
mdjones
2017/03/13 23:43:39
Unfortunately no, the margin from the top of the t
Theresa
2017/03/14 00:01:44
This is setting the margin on the handle, which us
mdjones
2017/03/14 16:25:28
Ah yes, you're right. I got one of the other dimen
| |
| 148 } | |
| 149 | |
| 150 @Override | |
| 151 protected void updateVisualsForToolbarState() { | |
| 152 super.updateVisualsForToolbarState(); | |
| 153 | |
| 154 // The handle should not show in tab switcher mode. | |
| 155 mToolbarHandleView.setVisibility( | |
| 156 mTabSwitcherState != ToolbarPhone.STATIC_TAB ? View.INVISIBLE : View.VISIBLE); | |
| 157 mToolbarHandleView.setImageBitmap(mUseLightToolbarDrawables ? mHandleLig ht : mHandleDark); | |
|
Theresa
2017/03/13 23:08:42
We'll also likely need to change the pull handle b
mdjones
2017/03/13 23:43:39
When we need that functionality, we can add a meth
| |
| 158 } | |
| 159 | |
| 160 @Override | |
| 161 protected void updateLocationBarBackgroundBounds(Rect out, VisualState visua lState) { | |
| 162 super.updateLocationBarBackgroundBounds(out, visualState); | |
| 163 | |
| 164 // Allow the location bar to expand to the full height of the control co ntainer. | |
| 165 out.top -= getExtraTopMargin() * mUrlExpansionPercent; | |
| 166 } | |
| 167 | |
| 168 /** | |
| 169 * Generate the bitmap used as the handle on the toolbar. This indicates tha t the toolbar can | |
| 170 * be pulled up. | |
| 171 * @return The handle as a bitmap. | |
| 172 */ | |
| 173 private Bitmap generateHandleBitmap(int handleColor) { | |
| 174 int handleWidth = getResources().getDimensionPixelSize(R.dimen.toolbar_h andle_width); | |
| 175 int handleHeight = getResources().getDimensionPixelSize(R.dimen.toolbar_ handle_height); | |
| 176 | |
| 177 Bitmap handle = Bitmap.createBitmap(handleWidth, handleHeight, Bitmap.Co nfig.ARGB_8888); | |
| 178 | |
| 179 Canvas canvas = new Canvas(handle); | |
| 180 | |
| 181 // Clear the canvas to be completely transparent. | |
| 182 canvas.drawARGB(0, 0, 0, 0); | |
| 183 | |
| 184 Paint paint = new Paint(); | |
| 185 paint.setColor(handleColor); | |
| 186 paint.setAntiAlias(true); | |
| 187 | |
| 188 RectF rect = new RectF(0, 0, handleWidth, handleHeight); | |
| 189 | |
| 190 // Use height / 2 for the corner radius so the handle always takes the s hape of a pill. | |
| 191 canvas.drawRoundRect(rect, handleHeight / 2, handleHeight / 2, paint); | |
| 192 | |
| 193 return handle; | |
| 194 } | |
| 195 | |
| 83 @Override | 196 @Override |
| 84 protected boolean shouldHideEndToolbarButtons() { | 197 protected boolean shouldHideEndToolbarButtons() { |
| 85 return mShouldHideEndToolbarButtons; | 198 return mShouldHideEndToolbarButtons; |
| 86 } | 199 } |
| 87 | 200 |
| 88 @Override | 201 @Override |
| 89 public void onSheetOpened() {} | 202 public void onSheetOpened() {} |
| 90 | 203 |
| 91 @Override | 204 @Override |
| 92 public void onSheetClosed() {} | 205 public void onSheetClosed() {} |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 115 boolean isMovingDown = heightFraction < mLastHeightFraction; | 228 boolean isMovingDown = heightFraction < mLastHeightFraction; |
| 116 mLastHeightFraction = heightFraction; | 229 mLastHeightFraction = heightFraction; |
| 117 | 230 |
| 118 // The only time the omnibox should have focus is when the sheet is full y expanded. Any | 231 // 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. | 232 // movement of the sheet should unfocus it. |
| 120 if (isMovingDown && getLocationBar().isUrlBarFocused()) { | 233 if (isMovingDown && getLocationBar().isUrlBarFocused()) { |
| 121 getLocationBar().setUrlBarFocus(false); | 234 getLocationBar().setUrlBarFocus(false); |
| 122 } | 235 } |
| 123 } | 236 } |
| 124 } | 237 } |
| OLD | NEW |