Loading packages/SystemUI/unfold/src/com/android/systemui/unfold/compat/ScreenSizeFoldProvider.kt +12 −10 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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) } } } Loading packages/SystemUI/unfold/src/com/android/systemui/unfold/updates/DeviceFoldStateProvider.kt +6 −0 Original line number Diff line number Diff line Loading @@ -256,6 +256,12 @@ constructor( } } override fun markScreenAsTurnedOn() { if (!isFolded) { isUnfoldHandled = true } } override fun onScreenTurningOn() { isScreenOn = true updateHingeAngleProviderState() Loading packages/SystemUI/unfold/src/com/android/systemui/unfold/updates/screen/ScreenStatusProvider.kt +7 −0 Original line number Diff line number Diff line Loading @@ -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() } } Loading
packages/SystemUI/unfold/src/com/android/systemui/unfold/compat/ScreenSizeFoldProvider.kt +12 −10 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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) } } } Loading
packages/SystemUI/unfold/src/com/android/systemui/unfold/updates/DeviceFoldStateProvider.kt +6 −0 Original line number Diff line number Diff line Loading @@ -256,6 +256,12 @@ constructor( } } override fun markScreenAsTurnedOn() { if (!isFolded) { isUnfoldHandled = true } } override fun onScreenTurningOn() { isScreenOn = true updateHingeAngleProviderState() Loading
packages/SystemUI/unfold/src/com/android/systemui/unfold/updates/screen/ScreenStatusProvider.kt +7 −0 Original line number Diff line number Diff line Loading @@ -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() } }