Loading packages/SystemUI/communal/layout/src/com/android/systemui/communal/layout/ui/compose/CommunalGridLayout.kt +9 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.communal.layout.ui.compose import android.util.SizeF import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row Loading Loading @@ -54,7 +55,14 @@ fun CommunalGridLayout( Row( modifier = Modifier.height(layoutConfig.cardHeight(cardInfo.size)), ) { cardInfo.card.Content(Modifier.fillMaxSize()) cardInfo.card.Content( modifier = Modifier.fillMaxSize(), size = SizeF( layoutConfig.cardWidth.value, layoutConfig.cardHeight(cardInfo.size).value, ), ) } } } Loading packages/SystemUI/communal/layout/src/com/android/systemui/communal/layout/ui/compose/config/CommunalGridLayoutCard.kt +5 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.communal.layout.ui.compose.config import android.util.SizeF import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier Loading @@ -26,8 +27,11 @@ abstract class CommunalGridLayoutCard { * * To host non-Compose views, see * https://developer.android.com/jetpack/compose/migrate/interoperability-apis/views-in-compose. * * @param size The size given to the card. Content of the card should fill all this space, given * that margins and paddings have been taken care of by the layout. */ @Composable abstract fun Content(modifier: Modifier) @Composable abstract fun Content(modifier: Modifier, size: SizeF) /** * Sizes supported by the card. Loading packages/SystemUI/communal/layout/tests/src/com/android/systemui/communal/layout/CommunalLayoutEngineTest.kt +2 −1 Original line number Diff line number Diff line package com.android.systemui.communal.layout import android.util.SizeF import androidx.compose.material3.Card import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier Loading Loading @@ -91,7 +92,7 @@ class CommunalLayoutEngineTest { override val supportedSizes = listOf(size) @Composable override fun Content(modifier: Modifier) { override fun Content(modifier: Modifier, size: SizeF) { Card(modifier = modifier, content = {}) } } Loading packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +38 −2 Original line number Diff line number Diff line package com.android.systemui.communal.ui.compose import android.appwidget.AppWidgetHostView import android.os.Bundle import android.util.SizeF import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize Loading @@ -12,9 +15,12 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.integerResource import androidx.compose.ui.viewinterop.AndroidView import com.android.systemui.communal.layout.ui.compose.CommunalGridLayout import com.android.systemui.communal.layout.ui.compose.config.CommunalGridLayoutCard import com.android.systemui.communal.layout.ui.compose.config.CommunalGridLayoutConfig import com.android.systemui.communal.shared.model.CommunalContentSize import com.android.systemui.communal.ui.model.CommunalContentUiModel import com.android.systemui.communal.ui.viewmodel.CommunalViewModel import com.android.systemui.res.R Loading @@ -24,6 +30,7 @@ fun CommunalHub( viewModel: CommunalViewModel, ) { val showTutorial by viewModel.showTutorialContent.collectAsState(initial = false) val widgetContent by viewModel.widgetContent.collectAsState(initial = emptyList()) Box( modifier = modifier.fillMaxSize().background(Color.White), ) { Loading @@ -36,7 +43,7 @@ fun CommunalHub( gridHeight = dimensionResource(R.dimen.communal_grid_height), gridColumnsPerCard = integerResource(R.integer.communal_grid_columns_per_card), ), communalCards = if (showTutorial) tutorialContent else emptyList(), communalCards = if (showTutorial) tutorialContent else widgetContent.map(::contentCard), ) } } Loading @@ -58,8 +65,37 @@ private fun tutorialCard(size: CommunalGridLayoutCard.Size): CommunalGridLayoutC override val supportedSizes = listOf(size) @Composable override fun Content(modifier: Modifier) { override fun Content(modifier: Modifier, size: SizeF) { Card(modifier = modifier, content = {}) } } } private fun contentCard(model: CommunalContentUiModel): CommunalGridLayoutCard { return object : CommunalGridLayoutCard() { override val supportedSizes = listOf(convertToCardSize(model.size)) override val priority = model.priority @Composable override fun Content(modifier: Modifier, size: SizeF) { AndroidView( modifier = modifier, factory = { model.view.apply { if (this is AppWidgetHostView) { updateAppWidgetSize(Bundle(), listOf(size)) } } }, ) } } } private fun convertToCardSize(size: CommunalContentSize): CommunalGridLayoutCard.Size { return when (size) { CommunalContentSize.FULL -> CommunalGridLayoutCard.Size.FULL CommunalContentSize.HALF -> CommunalGridLayoutCard.Size.HALF CommunalContentSize.THIRD -> CommunalGridLayoutCard.Size.THIRD } } packages/SystemUI/src/com/android/systemui/communal/data/model/CommunalWidgetMetadata.kt +1 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.systemui.communal.data.model import com.android.systemui.communal.shared.CommunalContentSize import com.android.systemui.communal.shared.model.CommunalContentSize /** Metadata for the default widgets */ data class CommunalWidgetMetadata( Loading Loading
packages/SystemUI/communal/layout/src/com/android/systemui/communal/layout/ui/compose/CommunalGridLayout.kt +9 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.communal.layout.ui.compose import android.util.SizeF import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row Loading Loading @@ -54,7 +55,14 @@ fun CommunalGridLayout( Row( modifier = Modifier.height(layoutConfig.cardHeight(cardInfo.size)), ) { cardInfo.card.Content(Modifier.fillMaxSize()) cardInfo.card.Content( modifier = Modifier.fillMaxSize(), size = SizeF( layoutConfig.cardWidth.value, layoutConfig.cardHeight(cardInfo.size).value, ), ) } } } Loading
packages/SystemUI/communal/layout/src/com/android/systemui/communal/layout/ui/compose/config/CommunalGridLayoutCard.kt +5 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.communal.layout.ui.compose.config import android.util.SizeF import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier Loading @@ -26,8 +27,11 @@ abstract class CommunalGridLayoutCard { * * To host non-Compose views, see * https://developer.android.com/jetpack/compose/migrate/interoperability-apis/views-in-compose. * * @param size The size given to the card. Content of the card should fill all this space, given * that margins and paddings have been taken care of by the layout. */ @Composable abstract fun Content(modifier: Modifier) @Composable abstract fun Content(modifier: Modifier, size: SizeF) /** * Sizes supported by the card. Loading
packages/SystemUI/communal/layout/tests/src/com/android/systemui/communal/layout/CommunalLayoutEngineTest.kt +2 −1 Original line number Diff line number Diff line package com.android.systemui.communal.layout import android.util.SizeF import androidx.compose.material3.Card import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier Loading Loading @@ -91,7 +92,7 @@ class CommunalLayoutEngineTest { override val supportedSizes = listOf(size) @Composable override fun Content(modifier: Modifier) { override fun Content(modifier: Modifier, size: SizeF) { Card(modifier = modifier, content = {}) } } Loading
packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +38 −2 Original line number Diff line number Diff line package com.android.systemui.communal.ui.compose import android.appwidget.AppWidgetHostView import android.os.Bundle import android.util.SizeF import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize Loading @@ -12,9 +15,12 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.integerResource import androidx.compose.ui.viewinterop.AndroidView import com.android.systemui.communal.layout.ui.compose.CommunalGridLayout import com.android.systemui.communal.layout.ui.compose.config.CommunalGridLayoutCard import com.android.systemui.communal.layout.ui.compose.config.CommunalGridLayoutConfig import com.android.systemui.communal.shared.model.CommunalContentSize import com.android.systemui.communal.ui.model.CommunalContentUiModel import com.android.systemui.communal.ui.viewmodel.CommunalViewModel import com.android.systemui.res.R Loading @@ -24,6 +30,7 @@ fun CommunalHub( viewModel: CommunalViewModel, ) { val showTutorial by viewModel.showTutorialContent.collectAsState(initial = false) val widgetContent by viewModel.widgetContent.collectAsState(initial = emptyList()) Box( modifier = modifier.fillMaxSize().background(Color.White), ) { Loading @@ -36,7 +43,7 @@ fun CommunalHub( gridHeight = dimensionResource(R.dimen.communal_grid_height), gridColumnsPerCard = integerResource(R.integer.communal_grid_columns_per_card), ), communalCards = if (showTutorial) tutorialContent else emptyList(), communalCards = if (showTutorial) tutorialContent else widgetContent.map(::contentCard), ) } } Loading @@ -58,8 +65,37 @@ private fun tutorialCard(size: CommunalGridLayoutCard.Size): CommunalGridLayoutC override val supportedSizes = listOf(size) @Composable override fun Content(modifier: Modifier) { override fun Content(modifier: Modifier, size: SizeF) { Card(modifier = modifier, content = {}) } } } private fun contentCard(model: CommunalContentUiModel): CommunalGridLayoutCard { return object : CommunalGridLayoutCard() { override val supportedSizes = listOf(convertToCardSize(model.size)) override val priority = model.priority @Composable override fun Content(modifier: Modifier, size: SizeF) { AndroidView( modifier = modifier, factory = { model.view.apply { if (this is AppWidgetHostView) { updateAppWidgetSize(Bundle(), listOf(size)) } } }, ) } } } private fun convertToCardSize(size: CommunalContentSize): CommunalGridLayoutCard.Size { return when (size) { CommunalContentSize.FULL -> CommunalGridLayoutCard.Size.FULL CommunalContentSize.HALF -> CommunalGridLayoutCard.Size.HALF CommunalContentSize.THIRD -> CommunalGridLayoutCard.Size.THIRD } }
packages/SystemUI/src/com/android/systemui/communal/data/model/CommunalWidgetMetadata.kt +1 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.systemui.communal.data.model import com.android.systemui.communal.shared.CommunalContentSize import com.android.systemui.communal.shared.model.CommunalContentSize /** Metadata for the default widgets */ data class CommunalWidgetMetadata( Loading