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

Commit 847a875f authored by Nick Chameyev's avatar Nick Chameyev
Browse files

[Unfold animation] Add a way to markScreenAsTurnedOn

This might be needed in the environment
where screen turning on/off events are not
available.

Bug: 277009748
Test: presubmit
Change-Id: I6933d615cfa16a3c670378f9512647083a152a8b
parent 5351ad5b
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -25,14 +25,18 @@ import java.util.concurrent.Executor
 * It could be used when no activity context is available
 * TODO(b/232369816): use Jetpack WM library when non-activity contexts supported b/169740873
 */
class ScreenSizeFoldProvider(private val context: Context) : FoldProvider {
class ScreenSizeFoldProvider(context: Context) : FoldProvider {

    private var isFolded: Boolean = false
    private var callbacks: MutableList<FoldCallback> = arrayListOf()
    private var lastWidth: Int = 0

    init {
        onConfigurationChange(context.resources.configuration)
    }

    override fun registerCallback(callback: FoldCallback, executor: Executor) {
        callbacks += callback
        onConfigurationChange(context.resources.configuration)
        callback.onFoldUpdated(isFolded)
    }

    override fun unregisterCallback(callback: FoldCallback) {
@@ -40,16 +44,14 @@ class ScreenSizeFoldProvider(private val context: Context) : FoldProvider {
    }

    fun onConfigurationChange(newConfig: Configuration) {
        if (lastWidth == newConfig.smallestScreenWidthDp) {
        val newIsFolded =
                newConfig.smallestScreenWidthDp < INNER_SCREEN_SMALLEST_SCREEN_WIDTH_THRESHOLD_DP
        if (newIsFolded == isFolded) {
            return
        }

        if (newConfig.smallestScreenWidthDp > INNER_SCREEN_SMALLEST_SCREEN_WIDTH_THRESHOLD_DP) {
            callbacks.forEach { it.onFoldUpdated(false) }
        } else {
            callbacks.forEach { it.onFoldUpdated(true) }
        }
        lastWidth = newConfig.smallestScreenWidthDp
        isFolded = newIsFolded
        callbacks.forEach { it.onFoldUpdated(isFolded) }
    }
}

+6 −0
Original line number Diff line number Diff line
@@ -256,6 +256,12 @@ constructor(
            }
        }

        override fun markScreenAsTurnedOn() {
            if (!isFolded) {
                isUnfoldHandled = true
            }
        }

        override fun onScreenTurningOn() {
            isScreenOn = true
            updateHingeAngleProviderState()
+7 −0
Original line number Diff line number Diff line
@@ -35,5 +35,12 @@ interface ScreenStatusProvider : CallbackController<ScreenListener> {
         * Called when the screen is starting to be turned on.
         */
        fun onScreenTurningOn()

        /**
         * Called when the screen is already turned on but it happened before the creation
         * of the unfold progress provider, so we won't play the actual animation but we treat
         * the current state of the screen as 'turned on'
         */
        fun markScreenAsTurnedOn()
    }
}