1 /* 2 * Copyright (C) 2014 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 17 package com.android.systemui.statusbar.notification.stack; 18 19 import static com.android.systemui.statusbar.notification.NotificationUtils.logKey; 20 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.content.Context; 24 import android.util.MathUtils; 25 26 import androidx.annotation.VisibleForTesting; 27 28 import com.android.systemui.Dumpable; 29 import com.android.systemui.dagger.SysUISingleton; 30 import com.android.systemui.dump.DumpManager; 31 import com.android.systemui.res.R; 32 import com.android.systemui.scene.shared.flag.SceneContainerFlag; 33 import com.android.systemui.shade.ShadeDisplayAware; 34 import com.android.systemui.shade.transition.LargeScreenShadeInterpolator; 35 import com.android.systemui.statusbar.NotificationShelf; 36 import com.android.systemui.statusbar.StatusBarState; 37 import com.android.systemui.statusbar.notification.collection.NotificationEntry; 38 import com.android.systemui.statusbar.notification.data.repository.HeadsUpRepository; 39 import com.android.systemui.statusbar.notification.headsup.AvalancheController; 40 import com.android.systemui.statusbar.notification.headsup.NotificationsHunSharedAnimationValues; 41 import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; 42 import com.android.systemui.statusbar.notification.row.ExpandableView; 43 import com.android.systemui.statusbar.notification.shared.NotificationBundleUi; 44 import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.BypassController; 45 import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.SectionProvider; 46 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; 47 48 import java.io.PrintWriter; 49 50 import javax.inject.Inject; 51 52 /** 53 * Global state to track all input states for 54 * {@link com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm}. 55 */ 56 @SysUISingleton 57 public class AmbientState implements Dumpable { 58 59 private static final float MAX_PULSE_HEIGHT = 100000f; 60 private static final boolean NOTIFICATIONS_HAVE_SHADOWS = false; 61 62 private final SectionProvider mSectionProvider; 63 private final BypassController mBypassController; 64 private final LargeScreenShadeInterpolator mLargeScreenShadeInterpolator; 65 private final AvalancheController mAvalancheController; 66 private final HeadsUpRepository mHeadsUpRepository; 67 68 /** 69 * Used to read bouncer states. 70 */ 71 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; 72 private float mStackTop; 73 private float mStackCutoff; 74 private float mHeadsUpTop; 75 private float mHeadsUpBottom; 76 private int mScrollY; 77 private float mOverScrollTopAmount; 78 private float mOverScrollBottomAmount; 79 private boolean mDozing; 80 private boolean mHideSensitive; 81 private float mStackTranslation; 82 private int mLayoutHeight; 83 private int mTopPadding; 84 private boolean mShadeExpanded; 85 private float mMaxHeadsUpTranslation; 86 private boolean mClearAllInProgress; 87 private int mLayoutMinHeight; 88 private int mLayoutMaxHeight; 89 private NotificationShelf mShelf; 90 private int mZDistanceBetweenElements; 91 private int mBaseZHeight; 92 private int mContentHeight; 93 private ExpandableView mLastVisibleBackgroundChild; 94 private float mCurrentScrollVelocity; 95 private int mStatusBarState; 96 private boolean mShowingStackOnLockscreen; 97 private float mLockscreenStackFadeInProgress; 98 private float mExpandingVelocity; 99 private boolean mPanelTracking; 100 private boolean mExpansionChanging; 101 private boolean mIsSmallScreen; 102 private boolean mPulsing; 103 private float mHideAmount; 104 private float mPulseHeight = MAX_PULSE_HEIGHT; 105 106 /** 107 * The ExpandableNotificationRow that is pulsing, or the one that was pulsing 108 * when the device started to transition from AOD to LockScreen. 109 */ 110 private ExpandableNotificationRow mPulsingRow; 111 112 /** Fraction of lockscreen to shade animation (on lockscreen swipe down). */ 113 private float mFractionToShade; 114 115 /** 116 * @param fractionToShade Fraction of lockscreen to shade transition 117 */ setFractionToShade(float fractionToShade)118 public void setFractionToShade(float fractionToShade) { 119 mFractionToShade = fractionToShade; 120 } 121 122 /** 123 * @return fractionToShade Fraction of lockscreen to shade transition 124 */ getFractionToShade()125 public float getFractionToShade() { 126 return mFractionToShade; 127 } 128 129 /** How we much we are sleeping. 1f fully dozing (AOD), 0f fully awake (for all other states) */ 130 private float mDozeAmount = 0.0f; 131 132 private Runnable mOnPulseHeightChangedListener; 133 private ExpandableNotificationRow mTrackedHeadsUpRow; 134 private float mAppearFraction; 135 private float mOverExpansion; 136 private int mStackTopMargin; 137 private boolean mUseSplitShade; 138 139 /** Distance of top of notifications panel from top of screen. */ 140 private float mStackY = 0; 141 142 /** Height of notifications panel interpolated by the expansion fraction. */ 143 private float mStackHeight = 0; 144 145 /** Fraction of shade expansion. */ 146 private float mExpansionFraction; 147 148 /** Fraction of QS expansion. 0 when in shade, 1 when in QS. */ 149 private float mQsExpansionFraction; 150 151 /** Height of the notifications panel when expansion completes. */ 152 private float mStackEndHeight; 153 154 /** Whether we are swiping up. */ 155 private boolean mIsSwipingUp; 156 157 /** Whether we are flinging the shade open or closed. */ 158 private boolean mIsFlinging; 159 160 /** 161 * Whether we need to do a fling down after swiping up on lockscreen. 162 * True right after we swipe up on lockscreen and have not finished the fling down that follows. 163 * False when we stop flinging or leave lockscreen. 164 */ 165 private boolean mIsFlingRequiredAfterLockScreenSwipeUp = false; 166 167 /** 168 * Whether the shade is currently closing. 169 */ 170 private boolean mIsClosing; 171 172 @VisibleForTesting isFlingRequiredAfterLockScreenSwipeUp()173 public boolean isFlingRequiredAfterLockScreenSwipeUp() { 174 return mIsFlingRequiredAfterLockScreenSwipeUp; 175 } 176 177 @VisibleForTesting setFlingRequiredAfterLockScreenSwipeUp(boolean value)178 public void setFlingRequiredAfterLockScreenSwipeUp(boolean value) { 179 mIsFlingRequiredAfterLockScreenSwipeUp = value; 180 } 181 182 /** 183 * @return Height of the available space for the notification content, when the shade 184 * expansion completes. 185 */ getStackEndHeight()186 public float getStackEndHeight() { 187 return mStackEndHeight; 188 } 189 190 /** 191 * @see #getStackEndHeight() 192 */ setStackEndHeight(float stackEndHeight)193 public void setStackEndHeight(float stackEndHeight) { 194 mStackEndHeight = stackEndHeight; 195 } 196 197 /** 198 * @param stackY Distance of top of notifications panel from top of screen. 199 */ setStackY(float stackY)200 public void setStackY(float stackY) { 201 SceneContainerFlag.assertInLegacyMode(); 202 mStackY = stackY; 203 } 204 205 /** 206 * @return Distance of top of notifications panel from top of screen. 207 */ getStackY()208 public float getStackY() { 209 SceneContainerFlag.assertInLegacyMode(); 210 return mStackY; 211 } 212 213 /** 214 * @param expansionFraction Fraction of shade expansion. 215 */ setExpansionFraction(float expansionFraction)216 public void setExpansionFraction(float expansionFraction) { 217 mExpansionFraction = expansionFraction; 218 } 219 220 /** 221 * @param expansionFraction Fraction of QS expansion. 222 */ setQsExpansionFraction(float expansionFraction)223 public void setQsExpansionFraction(float expansionFraction) { 224 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return; 225 mQsExpansionFraction = expansionFraction; 226 } 227 228 /** 229 * @param isSwipingUp Whether we are swiping up. 230 */ setSwipingUp(boolean isSwipingUp)231 public void setSwipingUp(boolean isSwipingUp) { 232 SceneContainerFlag.assertInLegacyMode(); 233 if (!isSwipingUp && mIsSwipingUp) { 234 // Just stopped swiping up. 235 mIsFlingRequiredAfterLockScreenSwipeUp = true; 236 } 237 mIsSwipingUp = isSwipingUp; 238 } 239 240 /** 241 * @return Whether we are swiping up. 242 */ isSwipingUp()243 public boolean isSwipingUp() { 244 return mIsSwipingUp; 245 } 246 247 /** 248 * @param isFlinging Whether we are flinging the shade open or closed. 249 */ setFlinging(boolean isFlinging)250 public void setFlinging(boolean isFlinging) { 251 SceneContainerFlag.assertInLegacyMode(); 252 if (isOnKeyguard() && !isFlinging && mIsFlinging) { 253 // Just stopped flinging. 254 mIsFlingRequiredAfterLockScreenSwipeUp = false; 255 } 256 mIsFlinging = isFlinging; 257 } 258 259 /** 260 * @param useSplitShade True if we are showing split shade. 261 */ setUseSplitShade(boolean useSplitShade)262 public void setUseSplitShade(boolean useSplitShade) { 263 mUseSplitShade = useSplitShade; 264 } 265 266 /** 267 * @return True if we are showing split shade. 268 */ getUseSplitShade()269 public boolean getUseSplitShade() { 270 return mUseSplitShade; 271 } 272 273 /** 274 * @return Fraction of shade expansion. 275 */ getExpansionFraction()276 public float getExpansionFraction() { 277 return mExpansionFraction; 278 } 279 280 /** 281 * @return Fraction of QS expansion. 282 */ getQsExpansionFraction()283 public float getQsExpansionFraction() { 284 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return 0f; 285 return mQsExpansionFraction; 286 } 287 288 /** 289 * @return Height of the notification content returned by {@link #getStackEndHeight()}, but 290 * interpolated by the shade expansion fraction. 291 */ getInterpolatedStackHeight()292 public float getInterpolatedStackHeight() { 293 return mStackHeight; 294 } 295 296 /** 297 * @see #getInterpolatedStackHeight() 298 */ setInterpolatedStackHeight(float stackHeight)299 public void setInterpolatedStackHeight(float stackHeight) { 300 mStackHeight = stackHeight; 301 } 302 303 @Inject AmbientState( @onNull @hadeDisplayAware Context context, @NonNull DumpManager dumpManager, @NonNull SectionProvider sectionProvider, @NonNull BypassController bypassController, @Nullable StatusBarKeyguardViewManager statusBarKeyguardViewManager, @NonNull LargeScreenShadeInterpolator largeScreenShadeInterpolator, @NonNull HeadsUpRepository headsUpRepository, AvalancheController avalancheController )304 public AmbientState( 305 @NonNull @ShadeDisplayAware Context context, 306 @NonNull DumpManager dumpManager, 307 @NonNull SectionProvider sectionProvider, 308 @NonNull BypassController bypassController, 309 @Nullable StatusBarKeyguardViewManager statusBarKeyguardViewManager, 310 @NonNull LargeScreenShadeInterpolator largeScreenShadeInterpolator, 311 @NonNull HeadsUpRepository headsUpRepository, 312 AvalancheController avalancheController 313 ) { 314 mSectionProvider = sectionProvider; 315 mBypassController = bypassController; 316 mStatusBarKeyguardViewManager = statusBarKeyguardViewManager; 317 mLargeScreenShadeInterpolator = largeScreenShadeInterpolator; 318 mAvalancheController = avalancheController; 319 mHeadsUpRepository = headsUpRepository; 320 reload(context); 321 dumpManager.registerDumpable(this); 322 } 323 324 /** 325 * Reload the dimens e.g. if the density changed. 326 */ reload(Context context)327 public void reload(Context context) { 328 mZDistanceBetweenElements = getZDistanceBetweenElements(context); 329 mBaseZHeight = getBaseHeight(mZDistanceBetweenElements); 330 } 331 getAvalancheShowingHunKey()332 String getAvalancheShowingHunKey() { 333 // If we don't have a previous showing hun, we don't consider the showing hun as avalanche 334 if (isNullAvalancheKey(getAvalanchePreviousHunKey())) return ""; 335 return mAvalancheController.getShowingHunKey(); 336 } 337 getAvalanchePreviousHunKey()338 String getAvalanchePreviousHunKey() { 339 return mAvalancheController.getPreviousHunKey(); 340 } 341 isNullAvalancheKey(String key)342 boolean isNullAvalancheKey(String key) { 343 if (key == null || key.isEmpty()) return true; 344 return key.equals("HeadsUpEntry null") || key.equals("HeadsUpEntry.mEntry null"); 345 } 346 setOverExpansion(float overExpansion)347 void setOverExpansion(float overExpansion) { 348 mOverExpansion = overExpansion; 349 } 350 getOverExpansion()351 public float getOverExpansion() { 352 return mOverExpansion; 353 } 354 getZDistanceBetweenElements(Context context)355 private static int getZDistanceBetweenElements(Context context) { 356 return Math.max(1, context.getResources() 357 .getDimensionPixelSize(R.dimen.z_distance_between_notifications)); 358 } 359 getBaseHeight(int zdistanceBetweenElements)360 private static int getBaseHeight(int zdistanceBetweenElements) { 361 return NOTIFICATIONS_HAVE_SHADOWS ? 4 * zdistanceBetweenElements : 0; 362 } 363 364 /** 365 * @return the launch height for notifications that are launched 366 */ getNotificationLaunchHeight(Context context)367 public static int getNotificationLaunchHeight(Context context) { 368 int zDistance = getZDistanceBetweenElements(context); 369 return NOTIFICATIONS_HAVE_SHADOWS ? 2 * getBaseHeight(zDistance) : 4 * zDistance; 370 } 371 372 /** 373 * @return the basic Z height on which notifications remain. 374 */ getBaseZHeight()375 public int getBaseZHeight() { 376 return mBaseZHeight; 377 } 378 379 /** 380 * @return the distance in Z between two overlaying notifications. 381 */ getZDistanceBetweenElements()382 public int getZDistanceBetweenElements() { 383 return mZDistanceBetweenElements; 384 } 385 386 /** Y coordinate in view pixels of the top of the notification stack */ getStackTop()387 public float getStackTop() { 388 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return 0f; 389 return mStackTop; 390 } 391 392 /** @see #getStackTop() */ setStackTop(float mStackTop)393 public void setStackTop(float mStackTop) { 394 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return; 395 this.mStackTop = mStackTop; 396 } 397 398 /** 399 * Y coordinate in view pixels above which the bottom of the notification stack / shelf / footer 400 * must be. 401 */ getStackCutoff()402 public float getStackCutoff() { 403 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return 0f; 404 return mStackCutoff; 405 } 406 407 /** @see #getStackCutoff() */ setStackCutoff(float stackCutoff)408 public void setStackCutoff(float stackCutoff) { 409 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return; 410 this.mStackCutoff = stackCutoff; 411 } 412 413 /** y coordinate of the top position of a pinned HUN */ getHeadsUpTop()414 public float getHeadsUpTop() { 415 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return 0f; 416 return mHeadsUpTop; 417 } 418 419 /** @see #getHeadsUpTop() */ setHeadsUpTop(float mHeadsUpTop)420 public void setHeadsUpTop(float mHeadsUpTop) { 421 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return; 422 this.mHeadsUpTop = mHeadsUpTop; 423 } 424 425 /** the bottom-most y position where we can draw pinned HUNs */ getHeadsUpBottom()426 public float getHeadsUpBottom() { 427 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return 0f; 428 NotificationsHunSharedAnimationValues.assertInLegacyMode(); 429 return mHeadsUpBottom; 430 } 431 432 /** @see #getHeadsUpBottom() */ setHeadsUpBottom(float headsUpBottom)433 public void setHeadsUpBottom(float headsUpBottom) { 434 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return; 435 mHeadsUpBottom = headsUpBottom; 436 } 437 getScrollY()438 public int getScrollY() { 439 return mScrollY; 440 } 441 442 /** 443 * Set the new Scroll Y position. 444 */ setScrollY(int scrollY)445 public void setScrollY(int scrollY) { 446 // Because we're dealing with an overscroller, scrollY could sometimes become smaller than 447 // 0. However this is only for internal purposes and the scroll position when read 448 // should never be smaller than 0, otherwise it can lead to flickers. 449 this.mScrollY = Math.max(scrollY, 0); 450 } 451 452 /** While dozing, we draw as little as possible, assuming a black background */ setDozing(boolean dozing)453 public void setDozing(boolean dozing) { 454 mDozing = dozing; 455 } 456 457 /** Hide ratio of the status bar **/ setHideAmount(float hidemount)458 public void setHideAmount(float hidemount) { 459 if (hidemount == 1.0f && mHideAmount != hidemount) { 460 // Whenever we are fully hidden, let's reset the pulseHeight again 461 setPulseHeight(MAX_PULSE_HEIGHT); 462 } 463 mHideAmount = hidemount; 464 } 465 466 /** Returns the hide ratio of the status bar */ getHideAmount()467 public float getHideAmount() { 468 return mHideAmount; 469 } 470 setHideSensitive(boolean hideSensitive)471 public void setHideSensitive(boolean hideSensitive) { 472 mHideSensitive = hideSensitive; 473 } 474 isDozing()475 public boolean isDozing() { 476 return mDozing; 477 } 478 isHideSensitive()479 public boolean isHideSensitive() { 480 return mHideSensitive; 481 } 482 setOverScrollAmount(float amount, boolean onTop)483 public void setOverScrollAmount(float amount, boolean onTop) { 484 if (onTop) { 485 mOverScrollTopAmount = amount; 486 } else { 487 mOverScrollBottomAmount = amount; 488 } 489 } 490 491 /** 492 * Is bypass currently enabled? 493 */ isBypassEnabled()494 public boolean isBypassEnabled() { 495 return mBypassController.isBypassEnabled(); 496 } 497 getOverScrollAmount(boolean top)498 public float getOverScrollAmount(boolean top) { 499 return top ? mOverScrollTopAmount : mOverScrollBottomAmount; 500 } 501 getSectionProvider()502 public SectionProvider getSectionProvider() { 503 return mSectionProvider; 504 } 505 getStackTranslation()506 public float getStackTranslation() { 507 return mStackTranslation; 508 } 509 setStackTranslation(float stackTranslation)510 public void setStackTranslation(float stackTranslation) { 511 mStackTranslation = stackTranslation; 512 } 513 setLayoutHeight(int layoutHeight)514 public void setLayoutHeight(int layoutHeight) { 515 mLayoutHeight = layoutHeight; 516 } 517 setLayoutMaxHeight(int maxLayoutHeight)518 public void setLayoutMaxHeight(int maxLayoutHeight) { 519 mLayoutMaxHeight = maxLayoutHeight; 520 } 521 getLayoutMaxHeight()522 public int getLayoutMaxHeight() { 523 return mLayoutMaxHeight; 524 } 525 getTopPadding()526 public int getTopPadding() { 527 SceneContainerFlag.assertInLegacyMode(); 528 return mTopPadding; 529 } 530 setTopPadding(int topPadding)531 public void setTopPadding(int topPadding) { 532 SceneContainerFlag.assertInLegacyMode(); 533 mTopPadding = topPadding; 534 } 535 getInnerHeight()536 public int getInnerHeight() { 537 return getInnerHeight(false /* ignorePulseHeight */); 538 } 539 540 /** 541 * @param ignorePulseHeight ignore the pulse height for this request 542 * @return the inner height of the algorithm. 543 */ getInnerHeight(boolean ignorePulseHeight)544 public int getInnerHeight(boolean ignorePulseHeight) { 545 if (mDozeAmount == 1.0f && !isPulseExpanding()) { 546 return mShelf.getHeight(); 547 } 548 int height; 549 if (SceneContainerFlag.isEnabled()) { 550 // TODO(b/192348384): This is probably incorrect as mContentHeight is not up to date. 551 // Consider removing usages of getInnerHeight in flexiglass if possible. 552 height = (int) Math.min(mLayoutHeight, mContentHeight) - mTopPadding; 553 } else { 554 height = (int) Math.max(mLayoutMinHeight, 555 Math.min(mLayoutHeight, mContentHeight) - mTopPadding); 556 } 557 if (ignorePulseHeight) { 558 return height; 559 } 560 float pulseHeight = Math.min(mPulseHeight, (float) height); 561 return (int) MathUtils.lerp(height, pulseHeight, mDozeAmount); 562 } 563 isPulseExpanding()564 public boolean isPulseExpanding() { 565 return mPulseHeight != MAX_PULSE_HEIGHT && mDozeAmount != 0.0f && mHideAmount != 1.0f; 566 } 567 isShadeExpanded()568 public boolean isShadeExpanded() { 569 return mShadeExpanded; 570 } 571 setShadeExpanded(boolean shadeExpanded)572 public void setShadeExpanded(boolean shadeExpanded) { 573 mShadeExpanded = shadeExpanded; 574 } 575 setMaxHeadsUpTranslation(float maxHeadsUpTranslation)576 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) { 577 mMaxHeadsUpTranslation = maxHeadsUpTranslation; 578 } 579 getMaxHeadsUpTranslation()580 public float getMaxHeadsUpTranslation() { 581 return mMaxHeadsUpTranslation; 582 } 583 setClearAllInProgress(boolean clearAllInProgress)584 public void setClearAllInProgress(boolean clearAllInProgress) { 585 mClearAllInProgress = clearAllInProgress; 586 } 587 isClearAllInProgress()588 public boolean isClearAllInProgress() { 589 return mClearAllInProgress; 590 } 591 setLayoutMinHeight(int layoutMinHeight)592 public void setLayoutMinHeight(int layoutMinHeight) { 593 SceneContainerFlag.assertInLegacyMode(); 594 mLayoutMinHeight = layoutMinHeight; 595 } 596 setShelf(NotificationShelf shelf)597 public void setShelf(NotificationShelf shelf) { 598 mShelf = shelf; 599 } 600 601 @Nullable getShelf()602 public NotificationShelf getShelf() { 603 return mShelf; 604 } 605 setContentHeight(int contentHeight)606 public void setContentHeight(int contentHeight) { 607 SceneContainerFlag.assertInLegacyMode(); 608 mContentHeight = contentHeight; 609 } 610 getContentHeight()611 public float getContentHeight() { 612 SceneContainerFlag.assertInLegacyMode(); 613 return mContentHeight; 614 } 615 616 /** 617 * Sets the last visible view of the host layout, that has a background, i.e the very last 618 * view in the shade, without the clear all button. 619 */ setLastVisibleBackgroundChild( ExpandableView lastVisibleBackgroundChild)620 public void setLastVisibleBackgroundChild( 621 ExpandableView lastVisibleBackgroundChild) { 622 mLastVisibleBackgroundChild = lastVisibleBackgroundChild; 623 } 624 getLastVisibleBackgroundChild()625 public ExpandableView getLastVisibleBackgroundChild() { 626 return mLastVisibleBackgroundChild; 627 } 628 setCurrentScrollVelocity(float currentScrollVelocity)629 public void setCurrentScrollVelocity(float currentScrollVelocity) { 630 mCurrentScrollVelocity = currentScrollVelocity; 631 } 632 getCurrentScrollVelocity()633 public float getCurrentScrollVelocity() { 634 return mCurrentScrollVelocity; 635 } 636 isOnKeyguard()637 public boolean isOnKeyguard() { 638 return mStatusBarState == StatusBarState.KEYGUARD; 639 } 640 isShowingStackOnLockscreen()641 public boolean isShowingStackOnLockscreen() { 642 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return false; 643 return mShowingStackOnLockscreen; 644 } 645 setShowingStackOnLockscreen(boolean showingStackOnLockscreen)646 public void setShowingStackOnLockscreen(boolean showingStackOnLockscreen) { 647 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return; 648 mShowingStackOnLockscreen = showingStackOnLockscreen; 649 } 650 getLockscreenStackFadeInProgress()651 public float getLockscreenStackFadeInProgress() { 652 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return 0f; 653 return mLockscreenStackFadeInProgress; 654 } 655 setLockscreenStackFadeInProgress(float lockscreenStackFadeInProgress)656 public void setLockscreenStackFadeInProgress(float lockscreenStackFadeInProgress) { 657 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return; 658 mLockscreenStackFadeInProgress = lockscreenStackFadeInProgress; 659 } 660 setStatusBarState(int statusBarState)661 public void setStatusBarState(int statusBarState) { 662 if (mStatusBarState != StatusBarState.KEYGUARD) { 663 mIsFlingRequiredAfterLockScreenSwipeUp = false; 664 } 665 mStatusBarState = statusBarState; 666 } 667 setExpandingVelocity(float expandingVelocity)668 public void setExpandingVelocity(float expandingVelocity) { 669 mExpandingVelocity = expandingVelocity; 670 } 671 setExpansionChanging(boolean expansionChanging)672 public void setExpansionChanging(boolean expansionChanging) { 673 mExpansionChanging = expansionChanging; 674 } 675 isExpansionChanging()676 public boolean isExpansionChanging() { 677 return mExpansionChanging; 678 } 679 getExpandingVelocity()680 public float getExpandingVelocity() { 681 return mExpandingVelocity; 682 } 683 setPanelTracking(boolean panelTracking)684 public void setPanelTracking(boolean panelTracking) { 685 mPanelTracking = panelTracking; 686 } 687 setPulsing(boolean hasPulsing)688 public void setPulsing(boolean hasPulsing) { 689 mPulsing = hasPulsing; 690 } 691 692 /** 693 * @return if we're pulsing in general 694 */ isPulsing()695 public boolean isPulsing() { 696 return mPulsing; 697 } 698 isPulsing(String entryKey)699 public boolean isPulsing(String entryKey) { 700 boolean isHeadsUp = mHeadsUpRepository.isHeadsUpEntry(entryKey); 701 return mPulsing && isHeadsUp; 702 } 703 isPulsing(NotificationEntry entry)704 public boolean isPulsing(NotificationEntry entry) { 705 boolean isHeadsUp = entry.isHeadsUpEntry(); 706 return mPulsing && isHeadsUp; 707 } 708 setPulsingRow(ExpandableNotificationRow row)709 public void setPulsingRow(ExpandableNotificationRow row) { 710 mPulsingRow = row; 711 } 712 713 /** 714 * @param row The row to check 715 * @return true if row is the pulsing row when the device started to transition from AOD to lock 716 * screen 717 */ isPulsingRow(ExpandableView row)718 public boolean isPulsingRow(ExpandableView row) { 719 return mPulsingRow == row; 720 } 721 isPanelTracking()722 public boolean isPanelTracking() { 723 return mPanelTracking; 724 } 725 isSmallScreen()726 public boolean isSmallScreen() { 727 return mIsSmallScreen; 728 } 729 setSmallScreen(boolean smallScreen)730 public void setSmallScreen(boolean smallScreen) { 731 mIsSmallScreen = smallScreen; 732 } 733 734 /** 735 * @return Whether we need to do a fling down after swiping up on lockscreen. 736 */ isFlingingAfterSwipeUpOnLockscreen()737 public boolean isFlingingAfterSwipeUpOnLockscreen() { 738 SceneContainerFlag.assertInLegacyMode(); 739 return mIsFlinging && mIsFlingRequiredAfterLockScreenSwipeUp; 740 } 741 742 /** 743 * @return whether a view is dozing and not pulsing right now 744 */ isDozingAndNotPulsing(ExpandableView view)745 public boolean isDozingAndNotPulsing(ExpandableView view) { 746 if (view instanceof ExpandableNotificationRow) { 747 return isDozingAndNotPulsing((ExpandableNotificationRow) view); 748 } 749 return false; 750 } 751 752 /** 753 * @return whether a row is dozing and not pulsing right now 754 */ isDozingAndNotPulsing(ExpandableNotificationRow row)755 public boolean isDozingAndNotPulsing(ExpandableNotificationRow row) { 756 boolean isPulsing = NotificationBundleUi.isEnabled() 757 ? isPulsing(row.getKey()) 758 : isPulsing(row.getEntryLegacy()); 759 return isDozing() && !isPulsing; 760 } 761 762 /** 763 * @return {@code true } when shade is completely hidden: in AOD, ambient display or when 764 * bypassing. 765 */ isFullyHidden()766 public boolean isFullyHidden() { 767 return mHideAmount == 1; 768 } 769 isHiddenAtAll()770 public boolean isHiddenAtAll() { 771 return mHideAmount != 0; 772 } 773 setPulseHeight(float height)774 public void setPulseHeight(float height) { 775 if (height != mPulseHeight) { 776 mPulseHeight = height; 777 if (mOnPulseHeightChangedListener != null) { 778 mOnPulseHeightChangedListener.run(); 779 } 780 } 781 } 782 getPulseHeight()783 public float getPulseHeight() { 784 if (mPulseHeight == MAX_PULSE_HEIGHT) { 785 // If we're not pulse expanding, the height should be 0 786 return 0; 787 } 788 return mPulseHeight; 789 } 790 setDozeAmount(float dozeAmount)791 public void setDozeAmount(float dozeAmount) { 792 if (dozeAmount != mDozeAmount) { 793 mDozeAmount = dozeAmount; 794 if (dozeAmount == 0.0f || dozeAmount == 1.0f) { 795 // We woke all the way up, let's reset the pulse height 796 setPulseHeight(MAX_PULSE_HEIGHT); 797 } 798 } 799 } 800 getDozeAmount()801 public float getDozeAmount() { 802 return mDozeAmount; 803 } 804 805 /** 806 * Is the device fully awake, which is different from not tark at all when there are pulsing 807 * notifications. 808 */ isFullyAwake()809 public boolean isFullyAwake() { 810 return mDozeAmount == 0.0f; 811 } 812 setOnPulseHeightChangedListener(Runnable onPulseHeightChangedListener)813 public void setOnPulseHeightChangedListener(Runnable onPulseHeightChangedListener) { 814 mOnPulseHeightChangedListener = onPulseHeightChangedListener; 815 } 816 setTrackedHeadsUpRow(ExpandableNotificationRow row)817 public void setTrackedHeadsUpRow(ExpandableNotificationRow row) { 818 mTrackedHeadsUpRow = row; 819 } 820 821 /** 822 * Returns the currently tracked heads up row, if there is one and it is currently above the 823 * shelf (still appearing). 824 */ getTrackedHeadsUpRow()825 public ExpandableNotificationRow getTrackedHeadsUpRow() { 826 if (mTrackedHeadsUpRow == null || !mTrackedHeadsUpRow.isAboveShelf()) { 827 return null; 828 } 829 return mTrackedHeadsUpRow; 830 } 831 setAppearFraction(float appearFraction)832 public void setAppearFraction(float appearFraction) { 833 mAppearFraction = appearFraction; 834 } 835 getAppearFraction()836 public float getAppearFraction() { 837 return mAppearFraction; 838 } 839 setStackTopMargin(int stackTopMargin)840 public void setStackTopMargin(int stackTopMargin) { 841 mStackTopMargin = stackTopMargin; 842 } 843 getStackTopMargin()844 public int getStackTopMargin() { 845 return mStackTopMargin; 846 } 847 848 /** 849 * Check to see if we are about to show bouncer. 850 * 851 * @return if bouncer expansion is between 0 and 1. 852 */ isBouncerInTransit()853 public boolean isBouncerInTransit() { 854 return mStatusBarKeyguardViewManager != null 855 && mStatusBarKeyguardViewManager.isPrimaryBouncerInTransit(); 856 } 857 858 /** 859 * @param isClosing Whether the shade is currently closing. 860 */ setIsClosing(boolean isClosing)861 public void setIsClosing(boolean isClosing) { 862 mIsClosing = isClosing; 863 } 864 865 /** 866 * @return Whether the shade is currently closing. 867 */ isClosing()868 public boolean isClosing() { 869 return mIsClosing; 870 } 871 getLargeScreenShadeInterpolator()872 public LargeScreenShadeInterpolator getLargeScreenShadeInterpolator() { 873 return mLargeScreenShadeInterpolator; 874 } 875 876 @Override dump(PrintWriter pw, String[] args)877 public void dump(PrintWriter pw, String[] args) { 878 pw.println("mStackTop=" + mStackTop); 879 pw.println("mStackCutoff=" + mStackCutoff); 880 pw.println("mHeadsUpTop=" + mHeadsUpTop); 881 pw.println("mHeadsUpBottom=" + mHeadsUpBottom); 882 pw.println("mTopPadding=" + mTopPadding); 883 pw.println("mStackTopMargin=" + mStackTopMargin); 884 pw.println("mStackTranslation=" + mStackTranslation); 885 pw.println("mLayoutMinHeight=" + mLayoutMinHeight); 886 pw.println("mLayoutMaxHeight=" + mLayoutMaxHeight); 887 pw.println("mLayoutHeight=" + mLayoutHeight); 888 pw.println("mContentHeight=" + mContentHeight); 889 pw.println("mHideSensitive=" + mHideSensitive); 890 pw.println("mShadeExpanded=" + mShadeExpanded); 891 pw.println("mClearAllInProgress=" + mClearAllInProgress); 892 pw.println("mStatusBarState=" + StatusBarState.toString(mStatusBarState)); 893 pw.println("mExpansionChanging=" + mExpansionChanging); 894 pw.println("mPanelFullWidth=" + mIsSmallScreen); 895 pw.println("mPulsing=" + mPulsing); 896 pw.println("mPulseHeight=" + mPulseHeight); 897 pw.println("mTrackedHeadsUpRow.key=" + logKey(mTrackedHeadsUpRow)); 898 pw.println("mMaxHeadsUpTranslation=" + mMaxHeadsUpTranslation); 899 pw.println("mDozeAmount=" + mDozeAmount); 900 pw.println("mDozing=" + mDozing); 901 pw.println("mFractionToShade=" + mFractionToShade); 902 pw.println("mHideAmount=" + mHideAmount); 903 pw.println("mAppearFraction=" + mAppearFraction); 904 pw.println("mExpansionFraction=" + mExpansionFraction); 905 pw.println("mQsExpansionFraction=" + mQsExpansionFraction); 906 pw.println("mExpandingVelocity=" + mExpandingVelocity); 907 pw.println("mOverScrollTopAmount=" + mOverScrollTopAmount); 908 pw.println("mOverScrollBottomAmount=" + mOverScrollBottomAmount); 909 pw.println("mOverExpansion=" + mOverExpansion); 910 pw.println("mStackHeight=" + mStackHeight); 911 pw.println("mStackEndHeight=" + mStackEndHeight); 912 pw.println("mStackY=" + mStackY); 913 pw.println("mScrollY=" + mScrollY); 914 pw.println("mCurrentScrollVelocity=" + mCurrentScrollVelocity); 915 pw.println("mIsSwipingUp=" + mIsSwipingUp); 916 pw.println("mPanelTracking=" + mPanelTracking); 917 pw.println("mIsFlinging=" + mIsFlinging); 918 pw.println("mIsFlingRequiredAfterLockScreenSwipeUp=" 919 + mIsFlingRequiredAfterLockScreenSwipeUp); 920 pw.println("mZDistanceBetweenElements=" + mZDistanceBetweenElements); 921 pw.println("mBaseZHeight=" + mBaseZHeight); 922 pw.println("mIsClosing=" + mIsClosing); 923 } 924 } 925