summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarousel.kt75
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaScenePicker.kt72
2 files changed, 112 insertions, 35 deletions
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarousel.kt b/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarousel.kt
index 581f3a5cacff..d629eec1c45a 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarousel.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarousel.kt
@@ -16,8 +16,10 @@
package com.android.systemui.media.controls.ui.composable
+import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
+import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
@@ -26,7 +28,6 @@ import androidx.compose.ui.layout.layout
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.viewinterop.AndroidView
-import androidx.core.view.contains
import com.android.compose.animation.scene.ElementKey
import com.android.compose.animation.scene.SceneScope
import com.android.systemui.media.controls.ui.controller.MediaCarouselController
@@ -36,7 +37,8 @@ import com.android.systemui.util.animation.MeasurementInput
private object MediaCarousel {
object Elements {
- internal val Content = ElementKey("MediaCarouselContent")
+ internal val Content =
+ ElementKey(debugName = "MediaCarouselContent", scenePicker = MediaScenePicker)
}
}
@@ -61,40 +63,43 @@ fun SceneScope.MediaCarousel(
mediaHost.measurementInput = MeasurementInput(layoutWidth, layoutHeight)
carouselController.setSceneContainerSize(layoutWidth, layoutHeight)
- AndroidView(
- modifier =
- modifier
- .element(MediaCarousel.Elements.Content)
- .height(mediaHeight)
- .fillMaxWidth()
- .layout { measurable, constraints ->
- val placeable = measurable.measure(constraints)
+ MovableElement(
+ key = MediaCarousel.Elements.Content,
+ modifier = modifier.height(mediaHeight).fillMaxWidth()
+ ) {
+ content {
+ AndroidView(
+ modifier =
+ Modifier.fillMaxSize().layout { measurable, constraints ->
+ val placeable = measurable.measure(constraints)
- // Notify controller to size the carousel for the current space
- mediaHost.measurementInput = MeasurementInput(placeable.width, placeable.height)
- carouselController.setSceneContainerSize(placeable.width, placeable.height)
+ // Notify controller to size the carousel for the current space
+ mediaHost.measurementInput =
+ MeasurementInput(placeable.width, placeable.height)
+ carouselController.setSceneContainerSize(placeable.width, placeable.height)
- layout(placeable.width, placeable.height) { placeable.placeRelative(0, 0) }
+ layout(placeable.width, placeable.height) { placeable.placeRelative(0, 0) }
+ },
+ factory = { context ->
+ FrameLayout(context).apply {
+ layoutParams =
+ FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ )
+ }
},
- factory = { context ->
- FrameLayout(context).apply {
- val mediaFrame = carouselController.mediaFrame
- (mediaFrame.parent as? ViewGroup)?.removeView(mediaFrame)
- addView(mediaFrame)
- layoutParams =
- FrameLayout.LayoutParams(
- FrameLayout.LayoutParams.MATCH_PARENT,
- FrameLayout.LayoutParams.MATCH_PARENT,
- )
- }
- },
- update = {
- if (it.contains(carouselController.mediaFrame)) {
- return@AndroidView
- }
- val mediaFrame = carouselController.mediaFrame
- (mediaFrame.parent as? ViewGroup)?.removeView(mediaFrame)
- it.addView(mediaFrame)
- },
- )
+ update = { it.setView(carouselController.mediaFrame) },
+ onRelease = { it.removeAllViews() }
+ )
+ }
+ }
+}
+
+private fun ViewGroup.setView(view: View) {
+ if (view.parent == this) {
+ return
+ }
+ (view.parent as? ViewGroup)?.removeView(view)
+ addView(view)
}
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaScenePicker.kt b/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaScenePicker.kt
new file mode 100644
index 000000000000..039813390f1e
--- /dev/null
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaScenePicker.kt
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.media.controls.ui.composable
+
+import com.android.compose.animation.scene.ElementKey
+import com.android.compose.animation.scene.ElementScenePicker
+import com.android.compose.animation.scene.SceneKey
+import com.android.compose.animation.scene.TransitionState
+import com.android.systemui.scene.shared.model.Scenes
+
+/** [ElementScenePicker] implementation for the media carousel object. */
+object MediaScenePicker : ElementScenePicker {
+
+ private val shadeLockscreenFraction = 0.65f
+ private val scenes =
+ setOf(
+ Scenes.Lockscreen,
+ Scenes.Shade,
+ Scenes.QuickSettings,
+ Scenes.QuickSettingsShade,
+ Scenes.Communal
+ )
+
+ override fun sceneDuringTransition(
+ element: ElementKey,
+ transition: TransitionState.Transition,
+ fromSceneZIndex: Float,
+ toSceneZIndex: Float
+ ): SceneKey? {
+ return when {
+ // TODO: 352052894 - update with the actual scene picking
+ transition.isTransitioning(from = Scenes.Lockscreen, to = Scenes.Shade) -> {
+ if (transition.progress < shadeLockscreenFraction) {
+ Scenes.Lockscreen
+ } else {
+ Scenes.Shade
+ }
+ }
+
+ // TODO: 345467290 - update with the actual scene picking
+ transition.isTransitioning(from = Scenes.Shade, to = Scenes.Lockscreen) -> {
+ if (transition.progress < 1f - shadeLockscreenFraction) {
+ Scenes.Shade
+ } else {
+ Scenes.Lockscreen
+ }
+ }
+
+ // TODO: 345467290 - update with the actual scene picking
+ transition.isTransitioningBetween(Scenes.QuickSettings, Scenes.Shade) -> {
+ Scenes.QuickSettings
+ }
+
+ // TODO: 340216785 - update with the actual scene picking
+ else -> pickSingleSceneIn(scenes, transition, element)
+ }
+ }
+}