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