Merge "[Unfold animation] Add a way to markScreenAsTurnedOn" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c45f351a13
@@ -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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -256,6 +256,12 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun markScreenAsTurnedOn() {
|
||||||
|
if (!isFolded) {
|
||||||
|
isUnfoldHandled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onScreenTurningOn() {
|
override fun onScreenTurningOn() {
|
||||||
isScreenOn = true
|
isScreenOn = true
|
||||||
updateHingeAngleProviderState()
|
updateHingeAngleProviderState()
|
||||||
|
|||||||
@@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user