Merge "Merge "[Unfold animation] Add a way to markScreenAsTurnedOn" into tm-qpr-dev am: c45f351a13" into tm-qpr-dev-plus-aosp

This commit is contained in:
Automerger Merge Worker
2023-04-06 13:52:53 +00:00
committed by Android (Google) Code Review
3 changed files with 25 additions and 10 deletions

View File

@@ -25,14 +25,18 @@ import java.util.concurrent.Executor
* It could be used when no activity context is available * It could be used when no activity context is available
* TODO(b/232369816): use Jetpack WM library when non-activity contexts supported b/169740873 * 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 callbacks: MutableList<FoldCallback> = arrayListOf()
private var lastWidth: Int = 0
init {
onConfigurationChange(context.resources.configuration)
}
override fun registerCallback(callback: FoldCallback, executor: Executor) { override fun registerCallback(callback: FoldCallback, executor: Executor) {
callbacks += callback callbacks += callback
onConfigurationChange(context.resources.configuration) callback.onFoldUpdated(isFolded)
} }
override fun unregisterCallback(callback: FoldCallback) { override fun unregisterCallback(callback: FoldCallback) {
@@ -40,16 +44,14 @@ class ScreenSizeFoldProvider(private val context: Context) : FoldProvider {
} }
fun onConfigurationChange(newConfig: Configuration) { fun onConfigurationChange(newConfig: Configuration) {
if (lastWidth == newConfig.smallestScreenWidthDp) { val newIsFolded =
newConfig.smallestScreenWidthDp < INNER_SCREEN_SMALLEST_SCREEN_WIDTH_THRESHOLD_DP
if (newIsFolded == isFolded) {
return return
} }
if (newConfig.smallestScreenWidthDp > INNER_SCREEN_SMALLEST_SCREEN_WIDTH_THRESHOLD_DP) { isFolded = newIsFolded
callbacks.forEach { it.onFoldUpdated(false) } callbacks.forEach { it.onFoldUpdated(isFolded) }
} else {
callbacks.forEach { it.onFoldUpdated(true) }
}
lastWidth = newConfig.smallestScreenWidthDp
} }
} }

View File

@@ -256,6 +256,12 @@ constructor(
} }
} }
override fun markScreenAsTurnedOn() {
if (!isFolded) {
isUnfoldHandled = true
}
}
override fun onScreenTurningOn() { override fun onScreenTurningOn() {
isScreenOn = true isScreenOn = true
updateHingeAngleProviderState() updateHingeAngleProviderState()

View File

@@ -35,5 +35,12 @@ interface ScreenStatusProvider : CallbackController<ScreenListener> {
* Called when the screen is starting to be turned on. * Called when the screen is starting to be turned on.
*/ */
fun onScreenTurningOn() 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()
} }
} }