Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 17 | package com.android.systemui.statusbar.phone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 19 | import static com.android.systemui.ScreenDecorations.DisplayCutoutView.boundsFromDirection; |
| 20 | |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 21 | import android.annotation.Nullable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.Context; |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 23 | import android.content.res.Configuration; |
| 24 | import android.graphics.Rect; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.util.AttributeSet; |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 26 | import android.util.EventLog; |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 27 | import android.util.Pair; |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 28 | import android.view.DisplayCutout; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 29 | import android.view.Gravity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.view.MotionEvent; |
| 31 | import android.view.View; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 32 | import android.view.ViewGroup; |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 33 | import android.view.WindowInsets; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 34 | import android.view.accessibility.AccessibilityEvent; |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 35 | import android.widget.LinearLayout; |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 36 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 37 | import com.android.systemui.Dependency; |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 38 | import com.android.systemui.EventLogTags; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 39 | import com.android.systemui.R; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 40 | import com.android.systemui.plugins.DarkIconDispatcher; |
| 41 | import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 42 | import com.android.systemui.statusbar.CommandQueue; |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 43 | |
| 44 | import java.util.Objects; |
Joe Onorato | 79de0c5 | 2010-05-26 17:03:26 -0400 | [diff] [blame] | 45 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 46 | public class PhoneStatusBarView extends PanelBar { |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 47 | private static final String TAG = "PhoneStatusBarView"; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 48 | private static final boolean DEBUG = StatusBar.DEBUG; |
Christoph Studer | 934025e | 2014-11-25 12:53:55 +0100 | [diff] [blame] | 49 | private static final boolean DEBUG_GESTURES = false; |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 50 | private static final int NO_VALUE = Integer.MIN_VALUE; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 51 | private final CommandQueue mCommandQueue; |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 52 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 53 | StatusBar mBar; |
Daniel Sandler | 5a8aefa | 2012-09-25 01:21:12 -0400 | [diff] [blame] | 54 | |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 55 | boolean mIsFullyOpenedPanel = false; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 56 | private ScrimController mScrimController; |
Selim Cinek | 3d395c6 | 2015-06-16 19:37:37 -0700 | [diff] [blame] | 57 | private float mMinFraction; |
Selim Cinek | 80c2abe | 2015-06-17 15:37:30 -0700 | [diff] [blame] | 58 | private Runnable mHideExpandedRunnable = new Runnable() { |
| 59 | @Override |
| 60 | public void run() { |
Selim Cinek | 529c532 | 2016-04-06 20:03:45 -0700 | [diff] [blame] | 61 | if (mPanelFraction == 0.0f) { |
| 62 | mBar.makeExpandedInvisible(); |
| 63 | } |
Selim Cinek | 80c2abe | 2015-06-17 15:37:30 -0700 | [diff] [blame] | 64 | } |
| 65 | }; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 66 | private DarkReceiver mBattery; |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 67 | private int mLastOrientation; |
Evan Laird | cda685d | 2018-01-22 18:25:17 -0500 | [diff] [blame] | 68 | @Nullable |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 69 | private View mCenterIconSpace; |
| 70 | @Nullable |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 71 | private View mCutoutSpace; |
| 72 | @Nullable |
| 73 | private DisplayCutout mDisplayCutout; |
Fabian Kozynski | 786974f | 2019-07-25 12:44:06 -0400 | [diff] [blame] | 74 | |
Evan Laird | 17a96ba | 2018-05-23 18:21:56 -0400 | [diff] [blame] | 75 | /** |
| 76 | * Draw this many pixels into the left/right side of the cutout to optimally use the space |
| 77 | */ |
| 78 | private int mCutoutSideNudge = 0; |
Selim Cinek | d21232e | 2019-06-20 14:15:59 -0700 | [diff] [blame] | 79 | private boolean mHeadsUpVisible; |
Joe Onorato | 119a401 | 2010-06-30 14:49:51 -0400 | [diff] [blame] | 80 | |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 81 | private int mRoundedCornerPadding = 0; |
| 82 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 83 | public PhoneStatusBarView(Context context, AttributeSet attrs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | super(context, attrs); |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 85 | mCommandQueue = Dependency.get(CommandQueue.class); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 86 | } |
| 87 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 88 | public void setBar(StatusBar bar) { |
Daniel Sandler | efb0faf | 2012-10-10 14:15:34 -0700 | [diff] [blame] | 89 | mBar = bar; |
| 90 | } |
| 91 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 92 | public void setScrimController(ScrimController scrimController) { |
| 93 | mScrimController = scrimController; |
| 94 | } |
| 95 | |
Daniel Sandler | efb0faf | 2012-10-10 14:15:34 -0700 | [diff] [blame] | 96 | @Override |
Jorim Jaggi | acea100 | 2014-05-10 01:30:10 +0200 | [diff] [blame] | 97 | public void onFinishInflate() { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 98 | mBattery = findViewById(R.id.battery); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 99 | mCutoutSpace = findViewById(R.id.cutout_space_view); |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 100 | mCenterIconSpace = findViewById(R.id.centered_icon_area); |
Evan Laird | 17a96ba | 2018-05-23 18:21:56 -0400 | [diff] [blame] | 101 | |
| 102 | updateResources(); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
| 106 | protected void onAttachedToWindow() { |
| 107 | super.onAttachedToWindow(); |
| 108 | // Always have Battery meters in the status bar observe the dark/light modes. |
| 109 | Dependency.get(DarkIconDispatcher.class).addDarkReceiver(mBattery); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 110 | if (updateOrientationAndCutout(getResources().getConfiguration().orientation)) { |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 111 | updateLayoutForCutout(); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 112 | } |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | @Override |
| 116 | protected void onDetachedFromWindow() { |
| 117 | super.onDetachedFromWindow(); |
| 118 | Dependency.get(DarkIconDispatcher.class).removeDarkReceiver(mBattery); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 119 | mDisplayCutout = null; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | protected void onConfigurationChanged(Configuration newConfig) { |
| 124 | super.onConfigurationChanged(newConfig); |
| 125 | |
| 126 | // May trigger cutout space layout-ing |
| 127 | if (updateOrientationAndCutout(newConfig.orientation)) { |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 128 | updateLayoutForCutout(); |
| 129 | requestLayout(); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 133 | @Override |
| 134 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
| 135 | if (updateOrientationAndCutout(mLastOrientation)) { |
| 136 | updateLayoutForCutout(); |
| 137 | requestLayout(); |
| 138 | } |
| 139 | return super.onApplyWindowInsets(insets); |
| 140 | } |
| 141 | |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 142 | /** |
| 143 | * |
| 144 | * @param newOrientation may pass NO_VALUE for no change |
| 145 | * @return boolean indicating if we need to update the cutout location / margins |
| 146 | */ |
| 147 | private boolean updateOrientationAndCutout(int newOrientation) { |
| 148 | boolean changed = false; |
| 149 | if (newOrientation != NO_VALUE) { |
| 150 | if (mLastOrientation != newOrientation) { |
| 151 | changed = true; |
| 152 | mLastOrientation = newOrientation; |
| 153 | } |
| 154 | } |
| 155 | |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 156 | if (!Objects.equals(getRootWindowInsets().getDisplayCutout(), mDisplayCutout)) { |
| 157 | changed = true; |
| 158 | mDisplayCutout = getRootWindowInsets().getDisplayCutout(); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | return changed; |
Daniel Sandler | efb0faf | 2012-10-10 14:15:34 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Daniel Sandler | 1c1edaa | 2012-08-14 11:14:45 -0400 | [diff] [blame] | 164 | @Override |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 165 | public boolean panelEnabled() { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 166 | return mCommandQueue.panelsEnabled(); |
Daniel Sandler | 1e8feef | 2012-08-16 11:37:41 -0400 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | @Override |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 170 | public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) { |
Alan Viverette | 5b04675 | 2015-01-08 11:13:06 -0800 | [diff] [blame] | 171 | if (super.onRequestSendAccessibilityEventInternal(child, event)) { |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 172 | // The status bar is very small so augment the view that the user is touching |
| 173 | // with the content of the status bar a whole. This way an accessibility service |
| 174 | // may announce the current item as well as the entire content if appropriate. |
| 175 | AccessibilityEvent record = AccessibilityEvent.obtain(); |
| 176 | onInitializeAccessibilityEvent(record); |
| 177 | dispatchPopulateAccessibilityEvent(record); |
| 178 | event.appendRecord(record); |
| 179 | return true; |
| 180 | } |
| 181 | return false; |
| 182 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 183 | |
| 184 | @Override |
| 185 | public void onPanelPeeked() { |
| 186 | super.onPanelPeeked(); |
Jorim Jaggi | fa505a7 | 2014-04-28 20:04:11 +0200 | [diff] [blame] | 187 | mBar.makeExpandedVisible(false); |
Daniel Sandler | 67eab79 | 2012-10-02 17:08:23 -0400 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | @Override |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 191 | public void onPanelCollapsed() { |
| 192 | super.onPanelCollapsed(); |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 193 | // Close the status bar in the next frame so we can show the end of the animation. |
Jorim Jaggi | 45e2d8f | 2017-05-16 14:23:19 +0200 | [diff] [blame] | 194 | post(mHideExpandedRunnable); |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 195 | mIsFullyOpenedPanel = false; |
Daniel Sandler | 8e72c9e | 2012-08-15 00:09:26 -0400 | [diff] [blame] | 196 | } |
| 197 | |
Selim Cinek | 80c2abe | 2015-06-17 15:37:30 -0700 | [diff] [blame] | 198 | public void removePendingHideExpandedRunnables() { |
Jorim Jaggi | 45e2d8f | 2017-05-16 14:23:19 +0200 | [diff] [blame] | 199 | removeCallbacks(mHideExpandedRunnable); |
Selim Cinek | 80c2abe | 2015-06-17 15:37:30 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Daniel Sandler | 8e72c9e | 2012-08-15 00:09:26 -0400 | [diff] [blame] | 202 | @Override |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 203 | public void onPanelFullyOpened() { |
| 204 | super.onPanelFullyOpened(); |
| 205 | if (!mIsFullyOpenedPanel) { |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 206 | mPanel.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 207 | } |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 208 | mIsFullyOpenedPanel = true; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | @Override |
| 212 | public boolean onTouchEvent(MotionEvent event) { |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 213 | boolean barConsumedEvent = mBar.interceptTouchEvent(event); |
| 214 | |
| 215 | if (DEBUG_GESTURES) { |
| 216 | if (event.getActionMasked() != MotionEvent.ACTION_MOVE) { |
| 217 | EventLog.writeEvent(EventLogTags.SYSUI_PANELBAR_TOUCH, |
| 218 | event.getActionMasked(), (int) event.getX(), (int) event.getY(), |
| 219 | barConsumedEvent ? 1 : 0); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | return barConsumedEvent || super.onTouchEvent(event); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | @Override |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 227 | public void onTrackingStarted() { |
| 228 | super.onTrackingStarted(); |
Jorim Jaggi | e70d31f | 2014-04-24 22:08:30 +0200 | [diff] [blame] | 229 | mBar.onTrackingStarted(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 230 | mScrimController.onTrackingStarted(); |
Selim Cinek | 529c532 | 2016-04-06 20:03:45 -0700 | [diff] [blame] | 231 | removePendingHideExpandedRunnables(); |
Jorim Jaggi | e70d31f | 2014-04-24 22:08:30 +0200 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | @Override |
Selim Cinek | dbbcfbe | 2014-10-24 17:52:35 +0200 | [diff] [blame] | 235 | public void onClosingFinished() { |
| 236 | super.onClosingFinished(); |
| 237 | mBar.onClosingFinished(); |
| 238 | } |
| 239 | |
| 240 | @Override |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 241 | public void onTrackingStopped(boolean expand) { |
| 242 | super.onTrackingStopped(expand); |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 243 | mBar.onTrackingStopped(expand); |
| 244 | } |
| 245 | |
| 246 | @Override |
| 247 | public void onExpandingFinished() { |
| 248 | super.onExpandingFinished(); |
| 249 | mScrimController.onExpandingFinished(); |
Jorim Jaggi | e70d31f | 2014-04-24 22:08:30 +0200 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | @Override |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 253 | public boolean onInterceptTouchEvent(MotionEvent event) { |
| 254 | return mBar.interceptTouchEvent(event) || super.onInterceptTouchEvent(event); |
| 255 | } |
| 256 | |
| 257 | @Override |
Selim Cinek | 3d395c6 | 2015-06-16 19:37:37 -0700 | [diff] [blame] | 258 | public void panelScrimMinFractionChanged(float minFraction) { |
| 259 | if (mMinFraction != minFraction) { |
| 260 | mMinFraction = minFraction; |
| 261 | updateScrimFraction(); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | @Override |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 266 | public void panelExpansionChanged(float frac, boolean expanded) { |
| 267 | super.panelExpansionChanged(frac, expanded); |
Selim Cinek | 3d395c6 | 2015-06-16 19:37:37 -0700 | [diff] [blame] | 268 | updateScrimFraction(); |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 269 | if ((frac == 0 || frac == 1) && mBar.getNavigationBarView() != null) { |
Winson Chung | 5b6a1fe | 2019-07-26 16:38:08 -0700 | [diff] [blame] | 270 | mBar.getNavigationBarView().onStatusBarPanelStateChanged(); |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 271 | } |
Selim Cinek | 3d395c6 | 2015-06-16 19:37:37 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | private void updateScrimFraction() { |
Selim Cinek | ae76b4c | 2017-03-07 16:49:43 -0800 | [diff] [blame] | 275 | float scrimFraction = mPanelFraction; |
| 276 | if (mMinFraction < 1.0f) { |
| 277 | scrimFraction = Math.max((mPanelFraction - mMinFraction) / (1.0f - mMinFraction), |
| 278 | 0); |
| 279 | } |
Selim Cinek | 3d395c6 | 2015-06-16 19:37:37 -0700 | [diff] [blame] | 280 | mScrimController.setPanelExpansion(scrimFraction); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 281 | } |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 282 | |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 283 | public void updateResources() { |
Evan Laird | 17a96ba | 2018-05-23 18:21:56 -0400 | [diff] [blame] | 284 | mCutoutSideNudge = getResources().getDimensionPixelSize( |
| 285 | R.dimen.display_cutout_margin_consumption); |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 286 | mRoundedCornerPadding = getResources().getDimensionPixelSize( |
| 287 | R.dimen.rounded_corner_content_padding); |
Evan Laird | 17a96ba | 2018-05-23 18:21:56 -0400 | [diff] [blame] | 288 | |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 289 | updateStatusBarHeight(); |
| 290 | } |
| 291 | |
| 292 | private void updateStatusBarHeight() { |
| 293 | final int waterfallTopInset = |
| 294 | mDisplayCutout == null ? 0 : mDisplayCutout.getWaterfallInsets().top; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 295 | ViewGroup.LayoutParams layoutParams = getLayoutParams(); |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 296 | layoutParams.height = |
| 297 | getResources().getDimensionPixelSize(R.dimen.status_bar_height) - waterfallTopInset; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 298 | setLayoutParams(layoutParams); |
| 299 | } |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 300 | |
| 301 | private void updateLayoutForCutout() { |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 302 | updateStatusBarHeight(); |
| 303 | Pair<Integer, Integer> cornerCutoutMargins = |
| 304 | StatusBarWindowView.cornerCutoutMargins(mDisplayCutout, getDisplay()); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 305 | updateCutoutLocation(cornerCutoutMargins); |
| 306 | updateSafeInsets(cornerCutoutMargins); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 307 | } |
| 308 | |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 309 | private void updateCutoutLocation(Pair<Integer, Integer> cornerCutoutMargins) { |
Evan Laird | cda685d | 2018-01-22 18:25:17 -0500 | [diff] [blame] | 310 | // Not all layouts have a cutout (e.g., Car) |
| 311 | if (mCutoutSpace == null) { |
| 312 | return; |
| 313 | } |
| 314 | |
shawnlin | 63dfae2 | 2020-02-16 17:15:07 +0800 | [diff] [blame] | 315 | if (mDisplayCutout == null || mDisplayCutout.isEmpty() || cornerCutoutMargins != null) { |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 316 | mCenterIconSpace.setVisibility(View.VISIBLE); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 317 | mCutoutSpace.setVisibility(View.GONE); |
| 318 | return; |
| 319 | } |
| 320 | |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 321 | mCenterIconSpace.setVisibility(View.GONE); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 322 | mCutoutSpace.setVisibility(View.VISIBLE); |
| 323 | LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mCutoutSpace.getLayoutParams(); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 324 | |
| 325 | Rect bounds = new Rect(); |
| 326 | boundsFromDirection(mDisplayCutout, Gravity.TOP, bounds); |
| 327 | |
Evan Laird | 17a96ba | 2018-05-23 18:21:56 -0400 | [diff] [blame] | 328 | bounds.left = bounds.left + mCutoutSideNudge; |
| 329 | bounds.right = bounds.right - mCutoutSideNudge; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 330 | lp.width = bounds.width(); |
| 331 | lp.height = bounds.height(); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 332 | } |
| 333 | |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 334 | private void updateSafeInsets(Pair<Integer, Integer> cornerCutoutMargins) { |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 335 | // Depending on our rotation, we may have to work around a cutout in the middle of the view, |
| 336 | // or letterboxing from the right or left sides. |
| 337 | |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 338 | Pair<Integer, Integer> padding = |
| 339 | StatusBarWindowView.paddingNeededForCutoutAndRoundedCorner( |
| 340 | mDisplayCutout, cornerCutoutMargins, mRoundedCornerPadding); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 341 | |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 342 | setPadding(padding.first, getPaddingTop(), padding.second, getPaddingBottom()); |
Evan Laird | 058c8ae | 2018-01-12 14:26:10 -0500 | [diff] [blame] | 343 | } |
Selim Cinek | d21232e | 2019-06-20 14:15:59 -0700 | [diff] [blame] | 344 | |
| 345 | public void setHeadsUpVisible(boolean headsUpVisible) { |
| 346 | mHeadsUpVisible = headsUpVisible; |
| 347 | updateVisibility(); |
| 348 | } |
| 349 | |
| 350 | @Override |
| 351 | protected boolean shouldPanelBeVisible() { |
| 352 | return mHeadsUpVisible || super.shouldPanelBeVisible(); |
| 353 | } |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 354 | } |