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