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

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22480086

Change-Id: Iab32989c9f8a554813f1d14743befe4a0c5d2ed5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Automerger Merge Worker
2023-04-06 14:23:57 +00:00
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
* 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) }
}
}

View File

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

View File

@@ -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()
}
}