Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99f0414a authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[Chipbar] Cleanup: Group the display-related variables into one object.

Bug: 245610654
Test: manual: verify TTT chips still work
Test: atest SystemUITests
Change-Id: I9b43b5260275951dce0f788c1bb7e8891ad9add6
parent cd5a7d1a
Loading
Loading
Loading
Loading
+0 −2
Original line number Original line Diff line number Diff line
@@ -142,8 +142,6 @@ class MediaTttChipControllerReceiver @Inject constructor(
    }
    }


    override fun updateView(newInfo: ChipReceiverInfo, currentView: ViewGroup) {
    override fun updateView(newInfo: ChipReceiverInfo, currentView: ViewGroup) {
        super.updateView(newInfo, currentView)

        val iconInfo = MediaTttUtils.getIconInfoFromPackageName(
        val iconInfo = MediaTttUtils.getIconInfoFromPackageName(
            context, newInfo.routeInfo.clientPackageName, logger
            context, newInfo.routeInfo.clientPackageName, logger
        )
        )
+2 −4
Original line number Original line Diff line number Diff line
@@ -132,8 +132,6 @@ open class MediaTttChipControllerSender @Inject constructor(
        newInfo: ChipSenderInfo,
        newInfo: ChipSenderInfo,
        currentView: ViewGroup
        currentView: ViewGroup
    ) {
    ) {
        super.updateView(newInfo, currentView)

        val chipState = newInfo.state
        val chipState = newInfo.state


        // Detect falsing touches on the chip.
        // Detect falsing touches on the chip.
@@ -210,10 +208,10 @@ open class MediaTttChipControllerSender @Inject constructor(
        //   animateChipOut matches the animateChipIn.
        //   animateChipOut matches the animateChipIn.
    }
    }


    override fun shouldIgnoreViewRemoval(removalReason: String): Boolean {
    override fun shouldIgnoreViewRemoval(info: ChipSenderInfo, removalReason: String): Boolean {
        // Don't remove the chip if we're in progress or succeeded, since the user should still be
        // Don't remove the chip if we're in progress or succeeded, since the user should still be
        // able to see the status of the transfer. (But do remove it if it's finally timed out.)
        // able to see the status of the transfer. (But do remove it if it's finally timed out.)
        val transferStatus = info?.state?.transferStatus
        val transferStatus = info.state.transferStatus
        if (
        if (
            (transferStatus == TransferStatus.IN_PROGRESS ||
            (transferStatus == TransferStatus.IN_PROGRESS ||
                transferStatus == TransferStatus.SUCCEEDED) &&
                transferStatus == TransferStatus.SUCCEEDED) &&
+30 −34
Original line number Original line Diff line number Diff line
@@ -32,7 +32,6 @@ import android.view.accessibility.AccessibilityManager
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_CONTROLS
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_CONTROLS
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_ICONS
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_ICONS
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_TEXT
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_TEXT
import androidx.annotation.CallSuper
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.util.concurrency.DelayableExecutor
import com.android.systemui.util.concurrency.DelayableExecutor
@@ -87,17 +86,8 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
     */
     */
    internal abstract val windowLayoutParams: WindowManager.LayoutParams
    internal abstract val windowLayoutParams: WindowManager.LayoutParams


    /** The view currently being displayed. Null if the view is not being displayed. */
    /** A container for all the display-related objects. Null if the view is not being displayed. */
    private var view: ViewGroup? = null
    private var displayInfo: DisplayInfo? = null

    /** The view controller for [view]. Null if the view is not being displayed. */
    private var viewController: TouchableRegionViewController? = null

    /** The info currently being displayed. Null if the view is not being displayed. */
    internal var info: T? = null

    // TODO(b/245610654): We should probably group [view], [viewController], and [info] together
    //   into one object since they're either all null or all non-null.


    /** A [Runnable] that, when run, will cancel the pending timeout of the view. */
    /** A [Runnable] that, when run, will cancel the pending timeout of the view. */
    private var cancelViewTimeout: Runnable? = null
    private var cancelViewTimeout: Runnable? = null
@@ -109,10 +99,11 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
     * display the correct information in the view.
     * display the correct information in the view.
     */
     */
    fun displayView(newInfo: T) {
    fun displayView(newInfo: T) {
        val currentView = view
        val currentDisplayInfo = displayInfo


        if (currentView != null) {
        if (currentDisplayInfo != null) {
            updateView(newInfo, currentView)
            currentDisplayInfo.info = newInfo
            updateView(currentDisplayInfo.info, currentDisplayInfo.view)
        } else {
        } else {
            // The view is new, so set up all our callbacks and inflate the view
            // The view is new, so set up all our callbacks and inflate the view
            configurationController.addCallback(displayScaleListener)
            configurationController.addCallback(displayScaleListener)
@@ -149,24 +140,24 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
        val newView = LayoutInflater
        val newView = LayoutInflater
                .from(context)
                .from(context)
                .inflate(viewLayoutRes, null) as ViewGroup
                .inflate(viewLayoutRes, null) as ViewGroup
        view = newView

        val newViewController = TouchableRegionViewController(newView, this::getTouchableRegion)
        val newViewController = TouchableRegionViewController(newView, this::getTouchableRegion)
        newViewController.init()
        newViewController.init()
        viewController = newViewController


        updateView(newInfo, newView)
        // We don't need to hold on to the view controller since we never set anything additional
        // on it -- it will be automatically cleaned up when the view is detached.
        val newDisplayInfo = DisplayInfo(newView, newInfo)
        displayInfo = newDisplayInfo
        updateView(newDisplayInfo.info, newDisplayInfo.view)
        windowManager.addView(newView, windowLayoutParams)
        windowManager.addView(newView, windowLayoutParams)
        animateViewIn(newView)
        animateViewIn(newView)
    }
    }


    /** Removes then re-inflates the view. */
    /** Removes then re-inflates the view. */
    private fun reinflateView() {
    private fun reinflateView() {
        val currentInfo = info
        val currentViewInfo = displayInfo ?: return
        if (view == null || currentInfo == null) { return }


        windowManager.removeView(view)
        windowManager.removeView(currentViewInfo.view)
        inflateAndUpdateView(currentInfo)
        inflateAndUpdateView(currentViewInfo.info)
    }
    }


    private val displayScaleListener = object : ConfigurationController.ConfigurationListener {
    private val displayScaleListener = object : ConfigurationController.ConfigurationListener {
@@ -182,21 +173,20 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
     *     change, etc.)
     *     change, etc.)
     */
     */
    fun removeView(removalReason: String) {
    fun removeView(removalReason: String) {
        if (shouldIgnoreViewRemoval(removalReason)) {
        val currentDisplayInfo = displayInfo ?: return
        if (shouldIgnoreViewRemoval(currentDisplayInfo.info, removalReason)) {
            return
            return
        }
        }
        val currentView = view ?: return


        val currentView = currentDisplayInfo.view
        animateViewOut(currentView) { windowManager.removeView(currentView) }
        animateViewOut(currentView) { windowManager.removeView(currentView) }


        logger.logChipRemoval(removalReason)
        logger.logChipRemoval(removalReason)
        configurationController.removeCallback(displayScaleListener)
        configurationController.removeCallback(displayScaleListener)
        // Re-set the view to null immediately (instead as part of the animation end runnable) so
        // Re-set to null immediately (instead as part of the animation end runnable) so
        // that if a new view event comes in while this view is animating out, we still display the
        // that if a new view event comes in while this view is animating out, we still display the
        // new view appropriately.
        // new view appropriately.
        view = null
        displayInfo = null
        viewController = null
        info = null
        // No need to time the view out since it's already gone
        // No need to time the view out since it's already gone
        cancelViewTimeout?.run()
        cancelViewTimeout?.run()
    }
    }
@@ -206,15 +196,12 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
     *
     *
     * Allows subclasses to keep the view visible for longer in certain circumstances.
     * Allows subclasses to keep the view visible for longer in certain circumstances.
     */
     */
    open fun shouldIgnoreViewRemoval(removalReason: String): Boolean = false
    open fun shouldIgnoreViewRemoval(info: T, removalReason: String): Boolean = false


    /**
    /**
     * A method implemented by subclasses to update [currentView] based on [newInfo].
     * A method implemented by subclasses to update [currentView] based on [newInfo].
     */
     */
    @CallSuper
    abstract fun updateView(newInfo: T, currentView: ViewGroup)
    open fun updateView(newInfo: T, currentView: ViewGroup) {
        info = newInfo
    }


    /**
    /**
     * Fills [outRect] with the touchable region of this view. This will be used by WindowManager
     * Fills [outRect] with the touchable region of this view. This will be used by WindowManager
@@ -237,6 +224,15 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
    internal open fun animateViewOut(view: ViewGroup, onAnimationEnd: Runnable) {
    internal open fun animateViewOut(view: ViewGroup, onAnimationEnd: Runnable) {
        onAnimationEnd.run()
        onAnimationEnd.run()
    }
    }

    /** A container for all the display-related state objects. */
    private inner class DisplayInfo(
        /** The view currently being displayed. */
        val view: ViewGroup,

        /** The info currently being displayed. */
        var info: T,
    )
}
}


object TemporaryDisplayRemovalReason {
object TemporaryDisplayRemovalReason {
+1 −2
Original line number Original line Diff line number Diff line
@@ -261,11 +261,10 @@ class TemporaryViewDisplayControllerTest : SysuiTestCase() {


        override val windowLayoutParams = commonWindowLayoutParams
        override val windowLayoutParams = commonWindowLayoutParams
        override fun updateView(newInfo: ViewInfo, currentView: ViewGroup) {
        override fun updateView(newInfo: ViewInfo, currentView: ViewGroup) {
            super.updateView(newInfo, currentView)
            mostRecentViewInfo = newInfo
            mostRecentViewInfo = newInfo
        }
        }


        override fun shouldIgnoreViewRemoval(removalReason: String): Boolean {
        override fun shouldIgnoreViewRemoval(info: ViewInfo, removalReason: String): Boolean {
            return shouldIgnoreViewRemoval
            return shouldIgnoreViewRemoval
        }
        }