diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/StatusEvent.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/StatusEvent.kt index 6380dc0b9b46c..398f5e35e5491 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/events/StatusEvent.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/StatusEvent.kt @@ -32,6 +32,16 @@ interface StatusEvent { // Whether or not to force the status bar open and show a dot val forceVisible: Boolean val viewCreator: (context: Context) -> View + + // Update this event with values from another event. + fun updateFromEvent(other: StatusEvent?) { + // no op by default + } + + // Whether or not this event should update its value from the provided. False by default + fun shouldUpdateFromEvent(other: StatusEvent?): Boolean { + return false + } } class BatteryEvent : StatusEvent { @@ -53,15 +63,30 @@ class PrivacyEvent : StatusEvent { override val priority = 100 override val forceVisible = true var privacyItems: List = listOf() + private var privacyChip: OngoingPrivacyChip? = null override val viewCreator: (context: Context) -> View = { context -> val v = LayoutInflater.from(context) .inflate(R.layout.ongoing_privacy_chip, null) as OngoingPrivacyChip v.privacyList = privacyItems + privacyChip = v v } override fun toString(): String { return javaClass.simpleName } + + override fun shouldUpdateFromEvent(other: StatusEvent?): Boolean { + return other is PrivacyEvent && other.privacyItems != privacyItems + } + + override fun updateFromEvent(other: StatusEvent?) { + if (other !is PrivacyEvent) { + return + } + + privacyItems = other.privacyItems + privacyChip?.privacyList = other.privacyItems + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemEventCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemEventCoordinator.kt index b4818233aea37..bde085e4e0b88 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemEventCoordinator.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemEventCoordinator.kt @@ -92,9 +92,6 @@ class SystemEventCoordinator @Inject constructor( var currentPrivacyItems = listOf() override fun onPrivacyItemsChanged(privacyItems: List) { - if (privacyItems.isNotEmpty() && currentPrivacyItems.containsAll(privacyItems)) { - return - } currentPrivacyItems = privacyItems notifyListeners() } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationScheduler.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationScheduler.kt index 40049373610cb..8da7fda242c7b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationScheduler.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationScheduler.kt @@ -98,7 +98,8 @@ class SystemStatusAnimationScheduler @Inject constructor( // Don't deal with threading for now (no need let's be honest) Assert.isMainThread() - if (event.priority > scheduledEvent?.priority ?: -1) { + if (event.priority > scheduledEvent?.priority ?: -1 || + scheduledEvent?.shouldUpdateFromEvent(event) == true) { if (DEBUG) { Log.d(TAG, "scheduling event $event") } @@ -134,7 +135,20 @@ class SystemStatusAnimationScheduler @Inject constructor( * Clear the scheduled event (if any) and schedule a new one */ private fun scheduleEvent(event: StatusEvent) { - scheduledEvent = event + if (animationState == ANIMATING_OUT || + (animationState == SHOWING_PERSISTENT_DOT && event.forceVisible)) { + // do not schedule an event or change the current one + return + } + + // If we are showing the chip, possibly update the current event, rather than replacing + if (scheduledEvent?.shouldUpdateFromEvent(event) == true) { + scheduledEvent?.updateFromEvent(event) + return + } else { + scheduledEvent = event + } + if (scheduledEvent!!.forceVisible) { hasPersistentDot = true } @@ -170,7 +184,13 @@ class SystemStatusAnimationScheduler @Inject constructor( val chipAnimator = ValueAnimator.ofFloat(1f, 0f) chipAnimator.duration = CHIP_ANIM_LENGTH - chipAnimator.addListener(ChipAnimatorAdapter(IDLE, scheduledEvent!!.viewCreator)) + val endState = if (hasPersistentDot) { + SHOWING_PERSISTENT_DOT + } else { + IDLE + } + chipAnimator.addListener( + ChipAnimatorAdapter(endState, scheduledEvent!!.viewCreator)) chipAnimator.addUpdateListener(chipUpdateListener) val aSet2 = AnimatorSet() @@ -207,6 +227,10 @@ class SystemStatusAnimationScheduler @Inject constructor( it.onHidePersistentDot() } + if (animationState == SHOWING_PERSISTENT_DOT) { + animationState = IDLE + } + if (anims.isNotEmpty()) { val aSet = AnimatorSet() aSet.playTogether(anims) @@ -330,6 +354,8 @@ const val ANIMATING_IN = 1 const val RUNNING_CHIP_ANIM = 2 /** Chip is animating away and system is animating back */ const val ANIMATING_OUT = 3 +/** Chip has animated away, and the persistent dot is showing */ +const val SHOWING_PERSISTENT_DOT = 4 private const val TAG = "SystemStatusAnimationScheduler" private const val DELAY: Long = 100