Adds UserSwitcher screen to Compose Gallery app
Bug: 246002091 Test: This is a test for the parent CL Change-Id: Ia1e4c360a072c79d8f57bfdb473d55463b27a3e4
This commit is contained in:
BIN
packages/SystemUI/compose/gallery/res/drawable/kitten1.jpeg
Normal file
BIN
packages/SystemUI/compose/gallery/res/drawable/kitten1.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
BIN
packages/SystemUI/compose/gallery/res/drawable/kitten2.jpeg
Normal file
BIN
packages/SystemUI/compose/gallery/res/drawable/kitten2.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.8 KiB |
BIN
packages/SystemUI/compose/gallery/res/drawable/kitten3.jpeg
Normal file
BIN
packages/SystemUI/compose/gallery/res/drawable/kitten3.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.1 KiB |
BIN
packages/SystemUI/compose/gallery/res/drawable/kitten4.jpeg
Normal file
BIN
packages/SystemUI/compose/gallery/res/drawable/kitten4.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
BIN
packages/SystemUI/compose/gallery/res/drawable/kitten5.jpeg
Normal file
BIN
packages/SystemUI/compose/gallery/res/drawable/kitten5.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
BIN
packages/SystemUI/compose/gallery/res/drawable/kitten6.jpeg
Normal file
BIN
packages/SystemUI/compose/gallery/res/drawable/kitten6.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
@@ -28,25 +28,25 @@ import com.android.systemui.compose.theme.SystemUITheme
|
||||
|
||||
/** The gallery app screens. */
|
||||
object GalleryAppScreens {
|
||||
val Typography = ChildScreen("typography") { TypographyScreen() }
|
||||
val MaterialColors = ChildScreen("material_colors") { MaterialColorsScreen() }
|
||||
val AndroidColors = ChildScreen("android_colors") { AndroidColorsScreen() }
|
||||
val Buttons = ChildScreen("buttons") { ButtonsScreen() }
|
||||
val ExampleFeature = ChildScreen("example_feature") { ExampleFeatureScreen() }
|
||||
private val Typography = ChildScreen("typography") { TypographyScreen() }
|
||||
private val MaterialColors = ChildScreen("material_colors") { MaterialColorsScreen() }
|
||||
private val AndroidColors = ChildScreen("android_colors") { AndroidColorsScreen() }
|
||||
private val Buttons = ChildScreen("buttons") { ButtonsScreen() }
|
||||
private val ExampleFeature = ChildScreen("example_feature") { ExampleFeatureScreen() }
|
||||
|
||||
val PeopleEmpty =
|
||||
private val PeopleEmpty =
|
||||
ChildScreen("people_empty") { navController ->
|
||||
EmptyPeopleScreen(onResult = { navController.popBackStack() })
|
||||
}
|
||||
val PeopleFew =
|
||||
private val PeopleFew =
|
||||
ChildScreen("people_few") { navController ->
|
||||
FewPeopleScreen(onResult = { navController.popBackStack() })
|
||||
}
|
||||
val PeopleFull =
|
||||
private val PeopleFull =
|
||||
ChildScreen("people_full") { navController ->
|
||||
FullPeopleScreen(onResult = { navController.popBackStack() })
|
||||
}
|
||||
val People =
|
||||
private val People =
|
||||
ParentScreen(
|
||||
"people",
|
||||
mapOf(
|
||||
@@ -55,6 +55,52 @@ object GalleryAppScreens {
|
||||
"Full" to PeopleFull,
|
||||
)
|
||||
)
|
||||
private val UserSwitcherSingleUser =
|
||||
ChildScreen("user_switcher_single") { navController ->
|
||||
UserSwitcherScreen(
|
||||
userCount = 1,
|
||||
onFinished = navController::popBackStack,
|
||||
)
|
||||
}
|
||||
private val UserSwitcherThreeUsers =
|
||||
ChildScreen("user_switcher_three") { navController ->
|
||||
UserSwitcherScreen(
|
||||
userCount = 3,
|
||||
onFinished = navController::popBackStack,
|
||||
)
|
||||
}
|
||||
private val UserSwitcherFourUsers =
|
||||
ChildScreen("user_switcher_four") { navController ->
|
||||
UserSwitcherScreen(
|
||||
userCount = 4,
|
||||
onFinished = navController::popBackStack,
|
||||
)
|
||||
}
|
||||
private val UserSwitcherFiveUsers =
|
||||
ChildScreen("user_switcher_five") { navController ->
|
||||
UserSwitcherScreen(
|
||||
userCount = 5,
|
||||
onFinished = navController::popBackStack,
|
||||
)
|
||||
}
|
||||
private val UserSwitcherSixUsers =
|
||||
ChildScreen("user_switcher_six") { navController ->
|
||||
UserSwitcherScreen(
|
||||
userCount = 6,
|
||||
onFinished = navController::popBackStack,
|
||||
)
|
||||
}
|
||||
private val UserSwitcher =
|
||||
ParentScreen(
|
||||
"user_switcher",
|
||||
mapOf(
|
||||
"Single" to UserSwitcherSingleUser,
|
||||
"Three" to UserSwitcherThreeUsers,
|
||||
"Four" to UserSwitcherFourUsers,
|
||||
"Five" to UserSwitcherFiveUsers,
|
||||
"Six" to UserSwitcherSixUsers,
|
||||
)
|
||||
)
|
||||
|
||||
val Home =
|
||||
ParentScreen(
|
||||
@@ -66,6 +112,7 @@ object GalleryAppScreens {
|
||||
"Example feature" to ExampleFeature,
|
||||
"Buttons" to Buttons,
|
||||
"People" to People,
|
||||
"User Switcher" to UserSwitcher,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.compose.gallery
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.android.systemui.user.Fakes.fakeUserSwitcherViewModel
|
||||
import com.android.systemui.user.ui.compose.UserSwitcherScreen
|
||||
|
||||
@Composable
|
||||
fun UserSwitcherScreen(
|
||||
userCount: Int,
|
||||
onFinished: () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current.applicationContext
|
||||
UserSwitcherScreen(
|
||||
viewModel = fakeUserSwitcherViewModel(context, userCount = userCount),
|
||||
onFinished = onFinished,
|
||||
)
|
||||
}
|
||||
@@ -58,12 +58,29 @@ object Fakes {
|
||||
(0 until userCount).map { index ->
|
||||
UserModel(
|
||||
id = index,
|
||||
name = Text.Loaded("user_$index"),
|
||||
name =
|
||||
Text.Loaded(
|
||||
when (index % 6) {
|
||||
0 -> "Ross Geller"
|
||||
1 -> "Phoebe Buffay"
|
||||
2 -> "Monica Geller"
|
||||
3 -> "Rachel Greene"
|
||||
4 -> "Chandler Bing"
|
||||
else -> "Joey Tribbiani"
|
||||
}
|
||||
),
|
||||
image =
|
||||
checkNotNull(
|
||||
AppCompatResources.getDrawable(
|
||||
context,
|
||||
R.drawable.ic_avatar_guest_user
|
||||
when (index % 6) {
|
||||
0 -> R.drawable.kitten1
|
||||
1 -> R.drawable.kitten2
|
||||
2 -> R.drawable.kitten3
|
||||
3 -> R.drawable.kitten4
|
||||
4 -> R.drawable.kitten5
|
||||
else -> R.drawable.kitten6
|
||||
},
|
||||
)
|
||||
),
|
||||
isSelected = index == 0,
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.common.ui.drawable
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Path
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.DrawableWrapper
|
||||
import kotlin.math.min
|
||||
|
||||
/** Renders the wrapped [Drawable] as a circle. */
|
||||
class CircularDrawable(
|
||||
drawable: Drawable,
|
||||
) : DrawableWrapper(drawable) {
|
||||
private val path: Path by lazy { Path() }
|
||||
|
||||
override fun onBoundsChange(bounds: Rect) {
|
||||
super.onBoundsChange(bounds)
|
||||
updateClipPath()
|
||||
}
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
canvas.save()
|
||||
canvas.clipPath(path)
|
||||
drawable?.draw(canvas)
|
||||
canvas.restore()
|
||||
}
|
||||
|
||||
private fun updateClipPath() {
|
||||
path.reset()
|
||||
path.addCircle(
|
||||
bounds.centerX().toFloat(),
|
||||
bounds.centerY().toFloat(),
|
||||
min(bounds.width(), bounds.height()) / 2f,
|
||||
Path.Direction.CW
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,10 @@ object UserSwitcherViewBinder {
|
||||
viewModel.users.collect { users ->
|
||||
val viewPool =
|
||||
view.children.filter { it.tag == USER_VIEW_TAG }.toMutableList()
|
||||
viewPool.forEach { view.removeView(it) }
|
||||
viewPool.forEach {
|
||||
view.removeView(it)
|
||||
flowWidget.removeView(it)
|
||||
}
|
||||
users.forEach { userViewModel ->
|
||||
val userView =
|
||||
if (viewPool.isNotEmpty()) {
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.android.systemui.user.ui.viewmodel
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.android.systemui.R
|
||||
import com.android.systemui.common.ui.drawable.CircularDrawable
|
||||
import com.android.systemui.power.domain.interactor.PowerInteractor
|
||||
import com.android.systemui.user.domain.interactor.UserInteractor
|
||||
import com.android.systemui.user.legacyhelper.ui.LegacyUserUiHelper
|
||||
@@ -130,7 +131,7 @@ private constructor(
|
||||
return UserViewModel(
|
||||
viewKey = model.id,
|
||||
name = model.name,
|
||||
image = model.image,
|
||||
image = CircularDrawable(model.image),
|
||||
isSelectionMarkerVisible = model.isSelected,
|
||||
alpha =
|
||||
if (model.isSelectable) {
|
||||
|
||||
Reference in New Issue
Block a user