Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b498ab84 authored by Darrell Shi's avatar Darrell Shi Committed by Android (Google) Code Review
Browse files

Merge "Introduce communal scene" into main

parents 69758018 8cde9e25
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 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.scene

import dagger.Module

@Module interface CommunalSceneModule
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.scene

import com.android.systemui.communal.ui.compose.CommunalScene
import com.android.systemui.scene.shared.model.Scene
import dagger.Binds
import dagger.Module
import dagger.multibindings.IntoSet

@Module
interface CommunalSceneModule {
    @Binds @IntoSet fun communalScene(scene: CommunalScene): Scene
}
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.communal.ui.compose

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.android.compose.animation.scene.SceneScope
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.scene.shared.model.Direction
import com.android.systemui.scene.shared.model.SceneKey
import com.android.systemui.scene.shared.model.SceneModel
import com.android.systemui.scene.shared.model.UserAction
import com.android.systemui.scene.ui.composable.ComposableScene
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

/** The communal scene shows glanceable hub when the device is locked and docked. */
@SysUISingleton
class CommunalScene @Inject constructor() : ComposableScene {
    override val key = SceneKey.Communal

    override val destinationScenes: StateFlow<Map<UserAction, SceneModel>> =
        MutableStateFlow<Map<UserAction, SceneModel>>(
                mapOf(
                    UserAction.Swipe(Direction.RIGHT) to SceneModel(SceneKey.Lockscreen),
                )
            )
            .asStateFlow()

    @Composable
    override fun SceneScope.Content(modifier: Modifier) {
        Box(
            modifier = modifier.fillMaxSize().background(Color.White),
        ) {
            Text(
                modifier = Modifier.align(Alignment.Center),
                text = "Hello Communal!",
            )
        }
    }
}
+10 −2
Original line number Diff line number Diff line
@@ -68,11 +68,17 @@ constructor(

    override val destinationScenes: StateFlow<Map<UserAction, SceneModel>> =
        viewModel.upDestinationSceneKey
            .map { pageKey -> destinationScenes(up = pageKey) }
            .map { pageKey ->
                destinationScenes(up = pageKey, left = viewModel.leftDestinationSceneKey)
            }
            .stateIn(
                scope = applicationScope,
                started = SharingStarted.Eagerly,
                initialValue = destinationScenes(up = viewModel.upDestinationSceneKey.value)
                initialValue =
                    destinationScenes(
                        up = viewModel.upDestinationSceneKey.value,
                        left = viewModel.leftDestinationSceneKey,
                    )
            )

    @Composable
@@ -88,9 +94,11 @@ constructor(

    private fun destinationScenes(
        up: SceneKey?,
        left: SceneKey?,
    ): Map<UserAction, SceneModel> {
        return buildMap {
            up?.let { this[UserAction.Swipe(Direction.UP)] = SceneModel(up) }
            left?.let { this[UserAction.Swipe(Direction.LEFT)] = SceneModel(left) }
            this[UserAction.Swipe(Direction.DOWN)] = SceneModel(SceneKey.Shade)
        }
    }
+3 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import com.android.systemui.scene.ui.composable.transitions.bouncerToGoneTransit
import com.android.systemui.scene.ui.composable.transitions.goneToQuickSettingsTransition
import com.android.systemui.scene.ui.composable.transitions.goneToShadeTransition
import com.android.systemui.scene.ui.composable.transitions.lockscreenToBouncerTransition
import com.android.systemui.scene.ui.composable.transitions.lockscreenToCommunalTransition
import com.android.systemui.scene.ui.composable.transitions.lockscreenToGoneTransition
import com.android.systemui.scene.ui.composable.transitions.lockscreenToQuickSettingsTransition
import com.android.systemui.scene.ui.composable.transitions.lockscreenToShadeTransition
@@ -13,7 +14,7 @@ import com.android.systemui.scene.ui.composable.transitions.shadeToQuickSettings
/**
 * Comprehensive definition of all transitions between scenes in [SceneContainer].
 *
 * Transitions are automatically reversible, so define only one transition per scene pair. By
 * Transitions are automatically reversible, so define only one transition per scene pair. By\
 * convention, use the more common transition direction when defining the pair order, e.g.
 * Lockscreen to Bouncer rather than Bouncer to Lockscreen.
 *
@@ -27,6 +28,7 @@ val SceneContainerTransitions = transitions {
    from(Gone, to = Shade) { goneToShadeTransition() }
    from(Gone, to = QuickSettings) { goneToQuickSettingsTransition() }
    from(Lockscreen, to = Bouncer) { lockscreenToBouncerTransition() }
    from(Lockscreen, to = Communal) { lockscreenToCommunalTransition() }
    from(Lockscreen, to = Shade) { lockscreenToShadeTransition() }
    from(Lockscreen, to = QuickSettings) { lockscreenToQuickSettingsTransition() }
    from(Lockscreen, to = Gone) { lockscreenToGoneTransition() }
Loading