summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/BounceableInfo.kt60
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/QuickQuickSettings.kt10
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/CommonTile.kt19
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/EditTile.kt352
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/InfiniteGridLayout.kt11
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/Tile.kt184
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionState.kt8
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/Selection.kt147
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/model/TileGridCell.kt16
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/BounceableTileViewModel.kt38
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditTileViewModel.kt14
12 files changed, 513 insertions, 350 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/BounceableInfo.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/BounceableInfo.kt
new file mode 100644
index 000000000000..b9994d7bb821
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/BounceableInfo.kt
@@ -0,0 +1,60 @@
+/*
+ * 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.qs.panels.ui.compose
+
+import com.android.compose.animation.Bounceable
+import com.android.systemui.qs.panels.shared.model.SizedTile
+import com.android.systemui.qs.panels.ui.model.GridCell
+import com.android.systemui.qs.panels.ui.model.TileGridCell
+import com.android.systemui.qs.panels.ui.viewmodel.BounceableTileViewModel
+import com.android.systemui.qs.panels.ui.viewmodel.TileViewModel
+
+data class BounceableInfo(
+ val bounceable: BounceableTileViewModel,
+ val previousTile: Bounceable?,
+ val nextTile: Bounceable?,
+ val bounceEnd: Boolean,
+)
+
+fun List<Pair<GridCell, BounceableTileViewModel>>.bounceableInfo(
+ index: Int,
+ columns: Int,
+): BounceableInfo {
+ val cell = this[index].first as TileGridCell
+ // Only look for neighbor bounceables if they are on the same row
+ val onLastColumn = cell.onLastColumn(cell.column, columns)
+ val previousTile = getOrNull(index - 1)?.takeIf { cell.column != 0 }
+ val nextTile = getOrNull(index + 1)?.takeIf { !onLastColumn }
+ return BounceableInfo(this[index].second, previousTile?.second, nextTile?.second, !onLastColumn)
+}
+
+fun List<BounceableTileViewModel>.bounceableInfo(
+ sizedTile: SizedTile<TileViewModel>,
+ index: Int,
+ column: Int,
+ columns: Int,
+): BounceableInfo {
+ // Only look for neighbor bounceables if they are on the same row
+ val onLastColumn = sizedTile.onLastColumn(column, columns)
+ val previousTile = getOrNull(index - 1)?.takeIf { column != 0 }
+ val nextTile = getOrNull(index + 1)?.takeIf { !onLastColumn }
+ return BounceableInfo(this[index], previousTile, nextTile, !onLastColumn)
+}
+
+private fun <T> SizedTile<T>.onLastColumn(column: Int, columns: Int): Boolean {
+ return column == columns - width
+}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt
index 770fd785723a..74fa0fef21d7 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt
@@ -116,9 +116,9 @@ class EditTileListState(tiles: List<SizedTile<EditTileViewModel>>, private val c
regenerateGrid()
_tiles.add(insertionIndex.coerceIn(0, _tiles.size), cell)
} else {
- // Add the tile with a temporary row which will get reassigned when
+ // Add the tile with a temporary row/col which will get reassigned when
// regenerating spacers
- _tiles.add(insertionIndex.coerceIn(0, _tiles.size), TileGridCell(draggedTile, 0))
+ _tiles.add(insertionIndex.coerceIn(0, _tiles.size), TileGridCell(draggedTile, 0, 0))
}
regenerateGrid()
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/QuickQuickSettings.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/QuickQuickSettings.kt
index a645b51404e7..f36f45c7942d 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/QuickQuickSettings.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/QuickQuickSettings.kt
@@ -20,6 +20,8 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.util.fastMap
@@ -29,6 +31,7 @@ import com.android.systemui.compose.modifiers.sysuiResTag
import com.android.systemui.grid.ui.compose.VerticalSpannedGrid
import com.android.systemui.qs.composefragment.ui.GridAnchor
import com.android.systemui.qs.panels.ui.compose.infinitegrid.Tile
+import com.android.systemui.qs.panels.ui.viewmodel.BounceableTileViewModel
import com.android.systemui.qs.panels.ui.viewmodel.QuickQuickSettingsViewModel
import com.android.systemui.qs.shared.ui.ElementKeys.toElementKey
import com.android.systemui.res.R
@@ -41,7 +44,9 @@ fun SceneScope.QuickQuickSettings(
val sizedTiles by
viewModel.tileViewModels.collectAsStateWithLifecycle(initialValue = emptyList())
val tiles = sizedTiles.fastMap { it.tile }
+ val bounceables = remember(sizedTiles) { List(sizedTiles.size) { BounceableTileViewModel() } }
val squishiness by viewModel.squishinessViewModel.squishiness.collectAsStateWithLifecycle()
+ val scope = rememberCoroutineScope()
DisposableEffect(tiles) {
val token = Any()
@@ -49,6 +54,7 @@ fun SceneScope.QuickQuickSettings(
onDispose { tiles.forEach { it.stopListening(token) } }
}
val columns by viewModel.columns.collectAsStateWithLifecycle()
+ var cellIndex = 0
Box(modifier = modifier) {
GridAnchor()
VerticalSpannedGrid(
@@ -59,11 +65,15 @@ fun SceneScope.QuickQuickSettings(
modifier = Modifier.sysuiResTag("qqs_tile_layout"),
) { spanIndex ->
val it = sizedTiles[spanIndex]
+ val column = cellIndex % columns
+ cellIndex += it.width
Tile(
tile = it.tile,
iconOnly = it.isIcon,
modifier = Modifier.element(it.tile.spec.toElementKey(spanIndex)),
squishiness = { squishiness },
+ coroutineScope = scope,
+ bounceableInfo = bounceables.bounceableInfo(it, spanIndex, column, columns),
)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/CommonTile.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/CommonTile.kt
index 9ec5a82a18d7..71fa0ac30fb7 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/CommonTile.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/CommonTile.kt
@@ -31,6 +31,7 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@@ -54,6 +55,7 @@ import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.semantics.toggleableState
+import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.android.compose.modifiers.background
import com.android.compose.modifiers.thenIf
@@ -64,7 +66,6 @@ import com.android.systemui.compose.modifiers.sysuiResTag
import com.android.systemui.qs.panels.ui.compose.infinitegrid.CommonTileDefaults.longPressLabel
import com.android.systemui.qs.panels.ui.viewmodel.AccessibilityUiState
import com.android.systemui.res.R
-import kotlinx.coroutines.delay
private const val TEST_TAG_TOGGLE = "qs_tile_toggle_target"
@@ -138,13 +139,20 @@ fun LargeTileLabels(
accessibilityUiState: AccessibilityUiState? = null,
) {
Column(verticalArrangement = Arrangement.Center, modifier = modifier.fillMaxHeight()) {
- Text(label, color = colors.label, modifier = Modifier.tileMarquee())
+ Text(
+ label,
+ style = MaterialTheme.typography.labelLarge,
+ color = colors.label,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
if (!TextUtils.isEmpty(secondaryLabel)) {
Text(
secondaryLabel ?: "",
color = colors.secondaryLabel,
+ style = MaterialTheme.typography.bodyMedium,
modifier =
- Modifier.tileMarquee().thenIf(
+ Modifier.thenIf(
accessibilityUiState?.stateDescription?.contains(secondaryLabel ?: "") ==
true
) {
@@ -182,10 +190,7 @@ fun SmallTileContent(
rememberAnimatedVectorPainter(animatedImageVector = image, atEnd = true)
} else {
var atEnd by remember(icon.res) { mutableStateOf(false) }
- LaunchedEffect(key1 = icon.res) {
- delay(350)
- atEnd = true
- }
+ LaunchedEffect(key1 = icon.res) { atEnd = true }
rememberAnimatedVectorPainter(animatedImageVector = image, atEnd = atEnd)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/EditTile.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/EditTile.kt
index 45c1e48840ee..5c2a2bd2b78c 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/EditTile.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/EditTile.kt
@@ -22,13 +22,13 @@ import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloatAsState
-import androidx.compose.animation.core.animateIntAsState
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.LocalOverscrollConfiguration
import androidx.compose.foundation.background
import androidx.compose.foundation.border
+import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Arrangement.spacedBy
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
@@ -46,7 +46,6 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.grid.GridCells
-import androidx.compose.foundation.lazy.grid.LazyGridItemScope
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.foundation.rememberScrollState
@@ -66,19 +65,17 @@ import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.BiasAlignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
-import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
-import androidx.compose.ui.graphics.drawscope.Stroke
-import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.layout.positionInRoot
@@ -98,23 +95,26 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.util.fastMap
-import androidx.compose.ui.zIndex
+import com.android.compose.animation.bounceable
import com.android.compose.modifiers.background
import com.android.compose.modifiers.height
import com.android.systemui.common.ui.compose.load
import com.android.systemui.qs.panels.shared.model.SizedTile
import com.android.systemui.qs.panels.shared.model.SizedTileImpl
+import com.android.systemui.qs.panels.ui.compose.BounceableInfo
import com.android.systemui.qs.panels.ui.compose.DragAndDropState
import com.android.systemui.qs.panels.ui.compose.EditTileListState
+import com.android.systemui.qs.panels.ui.compose.bounceableInfo
import com.android.systemui.qs.panels.ui.compose.dragAndDropRemoveZone
import com.android.systemui.qs.panels.ui.compose.dragAndDropTileList
import com.android.systemui.qs.panels.ui.compose.dragAndDropTileSource
import com.android.systemui.qs.panels.ui.compose.infinitegrid.CommonTileDefaults.InactiveCornerRadius
import com.android.systemui.qs.panels.ui.compose.infinitegrid.CommonTileDefaults.TileArrangementPadding
+import com.android.systemui.qs.panels.ui.compose.infinitegrid.CommonTileDefaults.TileHeight
import com.android.systemui.qs.panels.ui.compose.infinitegrid.CommonTileDefaults.ToggleTargetSize
import com.android.systemui.qs.panels.ui.compose.infinitegrid.EditModeTileDefaults.CurrentTilesGridPadding
import com.android.systemui.qs.panels.ui.compose.selection.MutableSelectionState
-import com.android.systemui.qs.panels.ui.compose.selection.ResizingHandle
+import com.android.systemui.qs.panels.ui.compose.selection.ResizableTileContainer
import com.android.systemui.qs.panels.ui.compose.selection.TileWidths
import com.android.systemui.qs.panels.ui.compose.selection.clearSelectionTile
import com.android.systemui.qs.panels.ui.compose.selection.rememberSelectionState
@@ -122,11 +122,14 @@ import com.android.systemui.qs.panels.ui.compose.selection.selectableTile
import com.android.systemui.qs.panels.ui.model.GridCell
import com.android.systemui.qs.panels.ui.model.SpacerGridCell
import com.android.systemui.qs.panels.ui.model.TileGridCell
+import com.android.systemui.qs.panels.ui.viewmodel.BounceableTileViewModel
import com.android.systemui.qs.panels.ui.viewmodel.EditTileViewModel
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.qs.shared.model.groupAndSort
import com.android.systemui.res.R
+import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
object TileType
@@ -241,15 +244,20 @@ private fun CurrentTilesGrid(
onSetTiles: (List<TileSpec>) -> Unit,
) {
val currentListState by rememberUpdatedState(listState)
- val tileHeight = CommonTileDefaults.TileHeight
val totalRows = listState.tiles.lastOrNull()?.row ?: 0
val totalHeight by
animateDpAsState(
- gridHeight(totalRows + 1, tileHeight, TileArrangementPadding, CurrentTilesGridPadding),
+ gridHeight(totalRows + 1, TileHeight, TileArrangementPadding, CurrentTilesGridPadding),
label = "QSEditCurrentTilesGridHeight",
)
val gridState = rememberLazyGridState()
var gridContentOffset by remember { mutableStateOf(Offset(0f, 0f)) }
+ val coroutineScope = rememberCoroutineScope()
+
+ val cells =
+ remember(listState.tiles) {
+ listState.tiles.fastMap { Pair(it, BounceableTileViewModel()) }
+ }
TileLazyGrid(
state = gridState,
@@ -272,7 +280,7 @@ private fun CurrentTilesGrid(
}
.testTag(CURRENT_TILES_GRID_TEST_TAG),
) {
- EditTiles(listState.tiles, listState, selectionState) { spec ->
+ EditTiles(cells, columns, listState, selectionState, coroutineScope) { spec ->
// Toggle the current size of the tile
currentListState.isIcon(spec)?.let { onResize(spec, !it) }
}
@@ -286,10 +294,10 @@ private fun AvailableTileGrid(
columns: Int,
dragAndDropState: DragAndDropState,
) {
- // Available tiles aren't visible during drag and drop, so the row isn't needed
+ // Available tiles aren't visible during drag and drop, so the row/col isn't needed
val groupedTiles =
remember(tiles.fastMap { it.tile.category }, tiles.fastMap { it.tile.label }) {
- groupAndSort(tiles.fastMap { TileGridCell(it, 0) })
+ groupAndSort(tiles.fastMap { TileGridCell(it, 0, 0) })
}
val labelColors = EditModeTileDefaults.editTileColors()
@@ -349,24 +357,26 @@ private fun GridCell.key(index: Int, dragAndDropState: DragAndDropState): Any {
/**
* Adds a list of [GridCell] to the lazy grid
*
- * @param cells the list of [GridCell]
+ * @param cells the pairs of [GridCell] to [BounceableTileViewModel]
* @param dragAndDropState the [DragAndDropState] for this grid
* @param selectionState the [MutableSelectionState] for this grid
* @param onToggleSize the callback when a tile's size is toggled
*/
fun LazyGridScope.EditTiles(
- cells: List<GridCell>,
+ cells: List<Pair<GridCell, BounceableTileViewModel>>,
+ columns: Int,
dragAndDropState: DragAndDropState,
selectionState: MutableSelectionState,
+ coroutineScope: CoroutineScope,
onToggleSize: (spec: TileSpec) -> Unit,
) {
items(
count = cells.size,
- key = { cells[it].key(it, dragAndDropState) },
- span = { cells[it].span },
+ key = { cells[it].first.key(it, dragAndDropState) },
+ span = { cells[it].first.span },
contentType = { TileType },
) { index ->
- when (val cell = cells[index]) {
+ when (val cell = cells[index].first) {
is TileGridCell ->
if (dragAndDropState.isMoving(cell.tile.tileSpec)) {
// If the tile is being moved, replace it with a visible spacer
@@ -385,6 +395,9 @@ fun LazyGridScope.EditTiles(
dragAndDropState = dragAndDropState,
selectionState = selectionState,
onToggleSize = onToggleSize,
+ coroutineScope = coroutineScope,
+ bounceableInfo = cells.bounceableInfo(index, columns),
+ modifier = Modifier.animateItem(),
)
}
is SpacerGridCell -> SpacerGridCell()
@@ -393,12 +406,15 @@ fun LazyGridScope.EditTiles(
}
@Composable
-private fun LazyGridItemScope.TileGridCell(
+private fun TileGridCell(
cell: TileGridCell,
index: Int,
dragAndDropState: DragAndDropState,
selectionState: MutableSelectionState,
onToggleSize: (spec: TileSpec) -> Unit,
+ coroutineScope: CoroutineScope,
+ bounceableInfo: BounceableInfo,
+ modifier: Modifier = Modifier,
) {
val stateDescription = stringResource(id = R.string.accessibility_qs_edit_position, index + 1)
var selected by remember { mutableStateOf(false) }
@@ -407,6 +423,9 @@ private fun LazyGridItemScope.TileGridCell(
targetValue = if (selected) 1f else 0f,
label = "QSEditTileSelectionAlpha",
)
+ val selectionColor = MaterialTheme.colorScheme.primary
+ val colors = EditModeTileDefaults.editTileColors()
+ val currentBounceableInfo by rememberUpdatedState(bounceableInfo)
LaunchedEffect(selectionState.selection?.tileSpec) {
selectionState.selection?.let {
@@ -420,152 +439,61 @@ private fun LazyGridItemScope.TileGridCell(
selected = selectionState.selection?.tileSpec == cell.tile.tileSpec
}
- val modifier =
- Modifier.animateItem()
- .semantics(mergeDescendants = true) {
- this.stateDescription = stateDescription
- contentDescription = cell.tile.label.text
- customActions =
- listOf(
- // TODO(b/367748260): Add final accessibility actions
- CustomAccessibilityAction("Toggle size") {
- onToggleSize(cell.tile.tileSpec)
- true
- }
- )
- }
- .height(CommonTileDefaults.TileHeight)
- .fillMaxWidth()
-
- val content =
- @Composable {
- EditTile(
- tileViewModel = cell.tile,
- iconOnly = cell.isIcon,
- selectionAlpha = { selectionAlpha },
- modifier =
- Modifier.fillMaxSize()
- .selectableTile(cell.tile.tileSpec, selectionState)
- .dragAndDropTileSource(
- SizedTileImpl(cell.tile, cell.width),
- dragAndDropState,
- selectionState::unSelect,
- ),
- )
- }
-
- if (selected) {
- SelectedTile(
- isIcon = cell.isIcon,
- selectionAlpha = { selectionAlpha },
- selectionState = selectionState,
- modifier = modifier.zIndex(2f), // 2f to display this tile over neighbors when dragged
- content = content,
- )
- } else {
- UnselectedTile(
- selectionAlpha = { selectionAlpha },
- selectionState = selectionState,
- modifier = modifier,
- content = content,
- )
- }
-}
-
-@Composable
-private fun SelectedTile(
- isIcon: Boolean,
- selectionAlpha: () -> Float,
- selectionState: MutableSelectionState,
- modifier: Modifier = Modifier,
- content: @Composable () -> Unit,
-) {
// Current base, min and max width of this tile
var tileWidths: TileWidths? by remember { mutableStateOf(null) }
-
- // Animated diff between the current width and the resized width of the tile. We can't use
- // animateContentSize here as the tile is sometimes unbounded.
- val remainingOffset by
- animateIntAsState(
- selectionState.resizingState?.let { tileWidths?.base?.minus(it.width) ?: 0 } ?: 0,
- label = "QSEditTileWidthOffset",
- )
-
val padding = with(LocalDensity.current) { TileArrangementPadding.roundToPx() }
- Box(
- modifier.onSizeChanged {
- val min = if (isIcon) it.width else (it.width - padding) / 2
- val max = if (isIcon) (it.width * 2) + padding else it.width
- tileWidths = TileWidths(it.width, min, max)
- }
+
+ ResizableTileContainer(
+ selected = selected,
+ selectionState = selectionState,
+ selectionAlpha = { selectionAlpha },
+ selectionColor = selectionColor,
+ tileWidths = { tileWidths },
+ modifier =
+ modifier
+ .height(TileHeight)
+ .fillMaxWidth()
+ .onSizeChanged {
+ // Grab the size before the bounceable to get the idle width
+ val min = if (cell.isIcon) it.width else (it.width - padding) / 2
+ val max = if (cell.isIcon) (it.width * 2) + padding else it.width
+ tileWidths = TileWidths(it.width, min, max)
+ }
+ .bounceable(
+ bounceable = currentBounceableInfo.bounceable,
+ previousBounceable = currentBounceableInfo.previousTile,
+ nextBounceable = currentBounceableInfo.nextTile,
+ orientation = Orientation.Horizontal,
+ bounceEnd = currentBounceableInfo.bounceEnd,
+ ),
) {
- val handle =
- @Composable {
- ResizingHandle(
- enabled = true,
- selectionState = selectionState,
- transition = selectionAlpha,
- tileWidths = { tileWidths },
+ Box(
+ modifier
+ .fillMaxSize()
+ .semantics(mergeDescendants = true) {
+ this.stateDescription = stateDescription
+ contentDescription = cell.tile.label.text
+ customActions =
+ listOf(
+ // TODO(b/367748260): Add final accessibility actions
+ CustomAccessibilityAction("Toggle size") {
+ onToggleSize(cell.tile.tileSpec)
+ true
+ }
+ )
+ }
+ .selectableTile(cell.tile.tileSpec, selectionState) {
+ coroutineScope.launch { currentBounceableInfo.bounceable.animateBounce() }
+ }
+ .dragAndDropTileSource(
+ SizedTileImpl(cell.tile, cell.width),
+ dragAndDropState,
+ selectionState::unSelect,
)
- }
-
- Layout(contents = listOf(content, handle)) {
- (contentMeasurables, handleMeasurables),
- constraints ->
- // Grab the width from the resizing state if a resize is in progress, otherwise fill the
- // max width
- val width =
- selectionState.resizingState?.width ?: (constraints.maxWidth - remainingOffset)
- val contentPlaceable =
- contentMeasurables.first().measure(constraints.copy(maxWidth = width))
- val handlePlaceable = handleMeasurables.first().measure(constraints)
-
- // Place the dot vertically centered on the right edge
- val handleX = contentPlaceable.width - (handlePlaceable.width / 2)
- val handleY = (contentPlaceable.height / 2) - (handlePlaceable.height / 2)
-
- layout(constraints.maxWidth, constraints.maxHeight) {
- contentPlaceable.place(0, 0)
- handlePlaceable.place(handleX, handleY)
- }
- }
- }
-}
-
-@Composable
-private fun UnselectedTile(
- selectionAlpha: () -> Float,
- selectionState: MutableSelectionState,
- modifier: Modifier = Modifier,
- content: @Composable () -> Unit,
-) {
- val handle =
- @Composable {
- ResizingHandle(
- enabled = false,
- selectionState = selectionState,
- transition = selectionAlpha,
- )
- }
-
- Box(modifier) {
- Layout(contents = listOf(content, handle)) {
- (contentMeasurables, handleMeasurables),
- constraints ->
- val contentPlaceable =
- contentMeasurables
- .first()
- .measure(constraints.copy(maxWidth = constraints.maxWidth))
- val handlePlaceable = handleMeasurables.first().measure(constraints)
-
- // Place the dot vertically centered on the right edge
- val handleX = contentPlaceable.width - (handlePlaceable.width / 2)
- val handleY = (contentPlaceable.height / 2) - (handlePlaceable.height / 2)
-
- layout(constraints.maxWidth, constraints.maxHeight) {
- contentPlaceable.place(0, 0)
- handlePlaceable.place(handleX, handleY)
- }
+ .tileBackground(colors.background)
+ .tilePadding()
+ ) {
+ EditTile(tile = cell.tile, iconOnly = cell.isIcon)
}
}
}
@@ -588,19 +516,19 @@ private fun AvailableTileGridCell(
verticalArrangement = spacedBy(CommonTileDefaults.TilePadding, Alignment.Top),
modifier = modifier,
) {
- EditTileContainer(
- colors = colors,
- modifier =
- Modifier.fillMaxWidth()
- .height(CommonTileDefaults.TileHeight)
- .clearSelectionTile(selectionState)
- .semantics(mergeDescendants = true) {
- onClick(onClickActionName) { false }
- this.stateDescription = stateDescription
- }
- .dragAndDropTileSource(SizedTileImpl(cell.tile, cell.width), dragAndDropState) {
- selectionState.unSelect()
- },
+ Box(
+ Modifier.fillMaxWidth()
+ .height(TileHeight)
+ .clearSelectionTile(selectionState)
+ .semantics(mergeDescendants = true) {
+ onClick(onClickActionName) { false }
+ this.stateDescription = stateDescription
+ }
+ .dragAndDropTileSource(SizedTileImpl(cell.tile, cell.width), dragAndDropState) {
+ selectionState.unSelect()
+ }
+ .tileBackground(colors.background)
+ .tilePadding()
) {
// Icon
SmallTileContent(
@@ -626,16 +554,14 @@ private fun AvailableTileGridCell(
@Composable
private fun SpacerGridCell(modifier: Modifier = Modifier) {
// By default, spacers are invisible and exist purely to catch drag movements
- Box(modifier.height(CommonTileDefaults.TileHeight).fillMaxWidth())
+ Box(modifier.height(TileHeight).fillMaxWidth())
}
@Composable
-fun EditTile(
- tileViewModel: EditTileViewModel,
+fun BoxScope.EditTile(
+ tile: EditTileViewModel,
iconOnly: Boolean,
- modifier: Modifier = Modifier,
colors: TileColors = EditModeTileDefaults.editTileColors(),
- selectionAlpha: () -> Float = { 1f },
) {
// Animated horizontal alignment from center (0f) to start (-1f)
val alignmentValue by
@@ -646,68 +572,36 @@ fun EditTile(
val alignment by remember {
derivedStateOf { BiasAlignment(horizontalBias = alignmentValue, verticalBias = 0f) }
}
+ // Icon
+ Box(Modifier.size(ToggleTargetSize).align(alignment)) {
+ SmallTileContent(
+ icon = tile.icon,
+ color = colors.icon,
+ animateToEnd = true,
+ modifier = Modifier.align(Alignment.Center),
+ )
+ }
- EditTileContainer(colors = colors, selectionAlpha = selectionAlpha, modifier = modifier) {
- // Icon
- Box(Modifier.size(ToggleTargetSize).align(alignment)) {
- SmallTileContent(
- icon = tileViewModel.icon,
- color = colors.icon,
- animateToEnd = true,
- modifier = Modifier.align(Alignment.Center),
- )
- }
-
- // Labels, positioned after the icon
- AnimatedVisibility(visible = !iconOnly, enter = fadeIn(), exit = fadeOut()) {
- LargeTileLabels(
- label = tileViewModel.label.text,
- secondaryLabel = tileViewModel.appName?.text,
- colors = colors,
- modifier = Modifier.padding(start = ToggleTargetSize + TileArrangementPadding),
- )
- }
+ // Labels, positioned after the icon
+ AnimatedVisibility(visible = !iconOnly, enter = fadeIn(), exit = fadeOut()) {
+ LargeTileLabels(
+ label = tile.label.text,
+ secondaryLabel = tile.appName?.text,
+ colors = colors,
+ modifier = Modifier.padding(start = ToggleTargetSize + TileArrangementPadding),
+ )
}
}
-@Composable
-private fun EditTileContainer(
- colors: TileColors,
- modifier: Modifier = Modifier,
- selectionAlpha: () -> Float = { 0f },
- selectionColor: Color = MaterialTheme.colorScheme.primary,
- content: @Composable BoxScope.() -> Unit = {},
-) {
- Box(
- Modifier.wrapContentSize().drawWithContent {
- drawContent()
- drawRoundRect(
- SolidColor(selectionColor),
- cornerRadius = CornerRadius(InactiveCornerRadius.toPx()),
- style = Stroke(EditModeTileDefaults.SelectedBorderWidth.toPx()),
- alpha = selectionAlpha(),
- )
- }
- ) {
- Box(
- modifier =
- modifier
- .drawBehind {
- drawRoundRect(
- SolidColor(colors.background),
- cornerRadius = CornerRadius(InactiveCornerRadius.toPx()),
- )
- }
- .tilePadding(),
- content = content,
- )
+private fun Modifier.tileBackground(color: Color): Modifier {
+ return drawBehind {
+ drawRoundRect(SolidColor(color), cornerRadius = CornerRadius(InactiveCornerRadius.toPx()))
}
}
private object EditModeTileDefaults {
const val PLACEHOLDER_ALPHA = .3f
val EditGridHeaderHeight = 60.dp
- val SelectedBorderWidth = 2.dp
val CurrentTilesGridPadding = 8.dp
@Composable
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/InfiniteGridLayout.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/InfiniteGridLayout.kt
index 6920e498bdde..e5c213519415 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/InfiniteGridLayout.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/InfiniteGridLayout.kt
@@ -20,6 +20,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.util.fastMap
@@ -29,7 +30,9 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.grid.ui.compose.VerticalSpannedGrid
import com.android.systemui.qs.panels.shared.model.SizedTileImpl
import com.android.systemui.qs.panels.ui.compose.PaginatableGridLayout
+import com.android.systemui.qs.panels.ui.compose.bounceableInfo
import com.android.systemui.qs.panels.ui.compose.rememberEditListState
+import com.android.systemui.qs.panels.ui.viewmodel.BounceableTileViewModel
import com.android.systemui.qs.panels.ui.viewmodel.EditTileViewModel
import com.android.systemui.qs.panels.ui.viewmodel.IconTilesViewModel
import com.android.systemui.qs.panels.ui.viewmodel.QSColumnsViewModel
@@ -62,7 +65,11 @@ constructor(
}
val columns by gridSizeViewModel.columns.collectAsStateWithLifecycle()
val sizedTiles = tiles.map { SizedTileImpl(it, it.spec.width()) }
+ val bounceables =
+ remember(sizedTiles) { List(sizedTiles.size) { BounceableTileViewModel() } }
val squishiness by squishinessViewModel.squishiness.collectAsStateWithLifecycle()
+ val scope = rememberCoroutineScope()
+ var cellIndex = 0
VerticalSpannedGrid(
columns = columns,
@@ -71,11 +78,15 @@ constructor(
spans = sizedTiles.fastMap { it.width },
) { spanIndex ->
val it = sizedTiles[spanIndex]
+ val column = cellIndex % columns
+ cellIndex += it.width
Tile(
tile = it.tile,
iconOnly = iconTilesViewModel.isIconTile(it.tile.spec),
modifier = Modifier.element(it.tile.spec.toElementKey(spanIndex)),
squishiness = { squishiness },
+ coroutineScope = scope,
+ bounceableInfo = bounceables.bounceableInfo(it, spanIndex, column, columns),
)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/Tile.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/Tile.kt
index 4bd5b2d68c4c..52d526123430 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/Tile.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/Tile.kt
@@ -23,8 +23,8 @@ import android.service.quicksettings.Tile.STATE_ACTIVE
import android.service.quicksettings.Tile.STATE_INACTIVE
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.ExperimentalFoundationApi
-import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.combinedClickable
+import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Arrangement.spacedBy
import androidx.compose.foundation.layout.Box
@@ -44,6 +44,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
@@ -61,11 +62,13 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.compose.animation.Expandable
+import com.android.compose.animation.bounceable
import com.android.compose.modifiers.thenIf
import com.android.systemui.animation.Expandable
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.compose.modifiers.sysuiResTag
import com.android.systemui.plugins.qs.QSTile
+import com.android.systemui.qs.panels.ui.compose.BounceableInfo
import com.android.systemui.qs.panels.ui.compose.infinitegrid.CommonTileDefaults.InactiveCornerRadius
import com.android.systemui.qs.panels.ui.compose.infinitegrid.CommonTileDefaults.longPressLabel
import com.android.systemui.qs.panels.ui.viewmodel.TileUiState
@@ -74,6 +77,8 @@ import com.android.systemui.qs.panels.ui.viewmodel.toUiState
import com.android.systemui.qs.tileimpl.QSTileImpl
import com.android.systemui.res.R
import java.util.function.Supplier
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.launch
private const val TEST_TAG_SMALL = "qs_tile_small"
private const val TEST_TAG_LARGE = "qs_tile_large"
@@ -102,9 +107,12 @@ fun Tile(
tile: TileViewModel,
iconOnly: Boolean,
squishiness: () -> Float,
+ coroutineScope: CoroutineScope,
+ bounceableInfo: BounceableInfo,
modifier: Modifier = Modifier,
) {
val state by tile.state.collectAsStateWithLifecycle(tile.currentState)
+ val currentBounceableInfo by rememberUpdatedState(bounceableInfo)
val resources = resources()
val uiState = remember(state, resources) { state.toUiState(resources) }
val colors = TileDefaults.getColorForState(uiState)
@@ -112,7 +120,7 @@ fun Tile(
// TODO(b/361789146): Draw the shapes instead of clipping
val tileShape = TileDefaults.animateTileShape(uiState.state)
- TileContainer(
+ TileExpandable(
color =
if (iconOnly || !uiState.handlesSecondaryClick) {
colors.iconBackground
@@ -120,93 +128,101 @@ fun Tile(
colors.background
},
shape = tileShape,
- iconOnly = iconOnly,
- onClick = tile::onClick,
- onLongClick = tile::onLongClick,
- uiState = uiState,
squishiness = squishiness,
- modifier = modifier,
+ modifier =
+ modifier
+ .fillMaxWidth()
+ .bounceable(
+ bounceable = currentBounceableInfo.bounceable,
+ previousBounceable = currentBounceableInfo.previousTile,
+ nextBounceable = currentBounceableInfo.nextTile,
+ orientation = Orientation.Horizontal,
+ bounceEnd = currentBounceableInfo.bounceEnd,
+ ),
) { expandable ->
- val icon = getTileIcon(icon = uiState.icon)
- if (iconOnly) {
- SmallTileContent(
- icon = icon,
- color = colors.icon,
- modifier = Modifier.align(Alignment.Center),
- )
- } else {
- val iconShape = TileDefaults.animateIconShape(uiState.state)
- LargeTileContent(
- label = uiState.label,
- secondaryLabel = uiState.secondaryLabel,
- icon = icon,
- colors = colors,
- iconShape = iconShape,
- toggleClickSupported = state.handlesSecondaryClick,
- onClick = {
- if (state.handlesSecondaryClick) {
- tile.onSecondaryClick()
- }
- },
- onLongClick = { tile.onLongClick(expandable) },
- accessibilityUiState = uiState.accessibilityUiState,
- squishiness = squishiness,
- )
+ TileContainer(
+ onClick = {
+ tile.onClick(expandable)
+ if (uiState.accessibilityUiState.toggleableState != null) {
+ coroutineScope.launch { currentBounceableInfo.bounceable.animateBounce() }
+ }
+ },
+ onLongClick = { tile.onLongClick(expandable) },
+ uiState = uiState,
+ iconOnly = iconOnly,
+ ) {
+ val icon = getTileIcon(icon = uiState.icon)
+ if (iconOnly) {
+ SmallTileContent(
+ icon = icon,
+ color = colors.icon,
+ modifier = Modifier.align(Alignment.Center),
+ )
+ } else {
+ val iconShape = TileDefaults.animateIconShape(uiState.state)
+ LargeTileContent(
+ label = uiState.label,
+ secondaryLabel = uiState.secondaryLabel,
+ icon = icon,
+ colors = colors,
+ iconShape = iconShape,
+ toggleClickSupported = state.handlesSecondaryClick,
+ onClick = {
+ if (state.handlesSecondaryClick) {
+ tile.onSecondaryClick()
+ }
+ },
+ onLongClick = { tile.onLongClick(expandable) },
+ accessibilityUiState = uiState.accessibilityUiState,
+ squishiness = squishiness,
+ )
+ }
}
}
}
@Composable
-private fun TileContainer(
+private fun TileExpandable(
color: Color,
shape: Shape,
- iconOnly: Boolean,
- uiState: TileUiState,
squishiness: () -> Float,
modifier: Modifier = Modifier,
- onClick: (Expandable) -> Unit = {},
- onLongClick: (Expandable) -> Unit = {},
- content: @Composable BoxScope.(Expandable) -> Unit,
+ content: @Composable (Expandable) -> Unit,
) {
Expandable(
color = color,
shape = shape,
modifier = modifier.clip(shape).verticalSquish(squishiness),
) {
- val longPressLabel = longPressLabel()
- Box(
- modifier =
- Modifier.height(CommonTileDefaults.TileHeight)
- .fillMaxWidth()
- .combinedClickable(
- onClick = { onClick(it) },
- onLongClick = { onLongClick(it) },
- onClickLabel = uiState.accessibilityUiState.clickLabel,
- onLongClickLabel = longPressLabel,
- )
- .semantics {
- role = uiState.accessibilityUiState.accessibilityRole
- if (uiState.accessibilityUiState.accessibilityRole == Role.Switch) {
- uiState.accessibilityUiState.toggleableState?.let {
- toggleableState = it
- }
- }
- stateDescription = uiState.accessibilityUiState.stateDescription
- }
- .sysuiResTag(if (iconOnly) TEST_TAG_SMALL else TEST_TAG_LARGE)
- .thenIf(iconOnly) {
- Modifier.semantics {
- contentDescription = uiState.accessibilityUiState.contentDescription
- }
- }
- .tilePadding()
- ) {
- content(it)
- }
+ content(it)
}
}
@Composable
+fun TileContainer(
+ onClick: () -> Unit,
+ onLongClick: () -> Unit,
+ uiState: TileUiState,
+ iconOnly: Boolean,
+ content: @Composable BoxScope.() -> Unit,
+) {
+ Box(
+ modifier =
+ Modifier.height(CommonTileDefaults.TileHeight)
+ .fillMaxWidth()
+ .tileCombinedClickable(
+ onClick = onClick,
+ onLongClick = onLongClick,
+ uiState = uiState,
+ iconOnly = iconOnly,
+ )
+ .sysuiResTag(if (iconOnly) TEST_TAG_SMALL else TEST_TAG_LARGE)
+ .tilePadding(),
+ content = content,
+ )
+}
+
+@Composable
private fun getTileIcon(icon: Supplier<QSTile.Icon?>): Icon {
val context = LocalContext.current
return icon.get()?.let {
@@ -222,14 +238,38 @@ fun tileHorizontalArrangement(): Arrangement.Horizontal {
return spacedBy(space = CommonTileDefaults.TileArrangementPadding, alignment = Alignment.Start)
}
-fun Modifier.tileMarquee(): Modifier {
- return basicMarquee(iterations = 1, initialDelayMillis = 200)
-}
-
fun Modifier.tilePadding(): Modifier {
return padding(CommonTileDefaults.TilePadding)
}
+@Composable
+fun Modifier.tileCombinedClickable(
+ onClick: () -> Unit,
+ onLongClick: () -> Unit,
+ uiState: TileUiState,
+ iconOnly: Boolean,
+): Modifier {
+ val longPressLabel = longPressLabel()
+ return combinedClickable(
+ onClick = onClick,
+ onLongClick = onLongClick,
+ onClickLabel = uiState.accessibilityUiState.clickLabel,
+ onLongClickLabel = longPressLabel,
+ )
+ .semantics {
+ role = uiState.accessibilityUiState.accessibilityRole
+ if (uiState.accessibilityUiState.accessibilityRole == Role.Switch) {
+ uiState.accessibilityUiState.toggleableState?.let { toggleableState = it }
+ }
+ stateDescription = uiState.accessibilityUiState.stateDescription
+ }
+ .thenIf(iconOnly) {
+ Modifier.semantics {
+ contentDescription = uiState.accessibilityUiState.contentDescription
+ }
+ }
+}
+
data class TileColors(
val background: Color,
val iconBackground: Color,
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionState.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionState.kt
index 441d96289d86..1d36aee4eb85 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionState.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionState.kt
@@ -89,8 +89,11 @@ class MutableSelectionState(
* Listens for click events to select/unselect the given [TileSpec]. Use this on current tiles as
* they can be selected.
*/
-@Composable
-fun Modifier.selectableTile(tileSpec: TileSpec, selectionState: MutableSelectionState): Modifier {
+fun Modifier.selectableTile(
+ tileSpec: TileSpec,
+ selectionState: MutableSelectionState,
+ onClick: () -> Unit = {},
+): Modifier {
return pointerInput(Unit) {
detectTapGestures(
onTap = {
@@ -99,6 +102,7 @@ fun Modifier.selectableTile(tileSpec: TileSpec, selectionState: MutableSelection
} else {
selectionState.select(tileSpec, manual = true)
}
+ onClick()
}
)
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/Selection.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/Selection.kt
index e0f0b6aa8919..9f13a3788f53 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/Selection.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/Selection.kt
@@ -16,63 +16,117 @@
package com.android.systemui.qs.panels.ui.compose.selection
+import androidx.compose.animation.core.animateIntAsState
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.systemGestureExclusion
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.drawWithContent
+import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.SolidColor
+import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.layout.layout
+import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.toSize
+import androidx.compose.ui.zIndex
+import com.android.compose.modifiers.thenIf
+import com.android.systemui.qs.panels.ui.compose.infinitegrid.CommonTileDefaults.InactiveCornerRadius
import com.android.systemui.qs.panels.ui.compose.selection.SelectionDefaults.ResizingDotSize
+import com.android.systemui.qs.panels.ui.compose.selection.SelectionDefaults.SelectedBorderWidth
/**
- * Dot handling resizing drag events. Use this on the selected tile to resize it
+ * Places a dot to handle resizing drag events. Use this on tiles to resize.
*
- * @param enabled whether resizing drag events should be handled
+ * The dot is placed vertically centered on the right border. The [content] will have a border when
+ * selected.
+ *
+ * @param selected whether resizing drag events should be handled
* @param selectionState the [MutableSelectionState] on the grid
- * @param transition the animated value for the dot, used for its alpha and scale
+ * @param selectionAlpha the animated value for the dot and border alpha
+ * @param selectionColor the [Color] of the dot and border
* @param tileWidths the [TileWidths] of the selected tile
- * @param onResize the callback when the drag passes the resizing threshold
*/
@Composable
-fun ResizingHandle(
+fun ResizableTileContainer(
+ selected: Boolean,
+ selectionState: MutableSelectionState,
+ selectionAlpha: () -> Float,
+ selectionColor: Color,
+ tileWidths: () -> TileWidths?,
+ modifier: Modifier = Modifier,
+ content: @Composable BoxScope.() -> Unit = {},
+) {
+ Box(
+ modifier
+ .resizable(selected, selectionState, tileWidths)
+ .selectionBorder(selectionColor, selectionAlpha)
+ ) {
+ content()
+ ResizingHandle(
+ enabled = selected,
+ selectionState = selectionState,
+ transition = selectionAlpha,
+ tileWidths = tileWidths,
+ modifier =
+ // Higher zIndex to make sure the handle is drawn above the content
+ Modifier.zIndex(2f),
+ )
+ }
+}
+
+@Composable
+private fun ResizingHandle(
enabled: Boolean,
selectionState: MutableSelectionState,
transition: () -> Float,
- tileWidths: () -> TileWidths? = { null },
+ tileWidths: () -> TileWidths?,
+ modifier: Modifier = Modifier,
) {
- if (enabled) {
- // Manually creating the touch target around the resizing dot to ensure that the next tile
- // does
- // not receive the touch input accidentally.
- val minTouchTargetSize = LocalMinimumInteractiveComponentSize.current
- Box(
- Modifier.size(minTouchTargetSize)
- .systemGestureExclusion { Rect(Offset.Zero, it.size.toSize()) }
- .pointerInput(Unit) {
- detectHorizontalDragGestures(
- onHorizontalDrag = { _, offset -> selectionState.onResizingDrag(offset) },
- onDragStart = {
- tileWidths()?.let { selectionState.onResizingDragStart(it) }
- },
- onDragEnd = selectionState::onResizingDragEnd,
- onDragCancel = selectionState::onResizingDragEnd,
+ // Manually creating the touch target around the resizing dot to ensure that the next tile
+ // does not receive the touch input accidentally.
+ val minTouchTargetSize = LocalMinimumInteractiveComponentSize.current
+ Box(
+ modifier
+ .layout { measurable, constraints ->
+ val size = minTouchTargetSize.roundToPx()
+ val placeable = measurable.measure(Constraints(size, size, size, size))
+ layout(placeable.width, placeable.height) {
+ placeable.place(
+ x = constraints.maxWidth - placeable.width / 2,
+ y = constraints.maxHeight / 2 - placeable.height / 2,
)
}
- ) {
- ResizingDot(transition = transition, modifier = Modifier.align(Alignment.Center))
- }
- } else {
- ResizingDot(transition = transition)
+ }
+ .thenIf(enabled) {
+ Modifier.systemGestureExclusion { Rect(Offset.Zero, it.size.toSize()) }
+ .pointerInput(Unit) {
+ detectHorizontalDragGestures(
+ onHorizontalDrag = { _, offset ->
+ selectionState.onResizingDrag(offset)
+ },
+ onDragStart = {
+ tileWidths()?.let { selectionState.onResizingDragStart(it) }
+ },
+ onDragEnd = selectionState::onResizingDragEnd,
+ onDragCancel = selectionState::onResizingDragEnd,
+ )
+ }
+ }
+ ) {
+ ResizingDot(transition = transition, modifier = Modifier.align(Alignment.Center))
}
}
@@ -88,6 +142,45 @@ private fun ResizingDot(
}
}
+private fun Modifier.selectionBorder(
+ selectionColor: Color,
+ selectionAlpha: () -> Float = { 0f },
+): Modifier {
+ return drawWithContent {
+ drawContent()
+ drawRoundRect(
+ SolidColor(selectionColor),
+ cornerRadius = CornerRadius(InactiveCornerRadius.toPx()),
+ style = Stroke(SelectedBorderWidth.toPx()),
+ alpha = selectionAlpha(),
+ )
+ }
+}
+
+@Composable
+private fun Modifier.resizable(
+ selected: Boolean,
+ selectionState: MutableSelectionState,
+ tileWidths: () -> TileWidths?,
+): Modifier {
+ if (!selected) return zIndex(1f)
+
+ // Animated diff between the current width and the resized width of the tile. We can't use
+ // animateContentSize here as the tile is sometimes unbounded.
+ val remainingOffset by
+ animateIntAsState(
+ selectionState.resizingState?.let { tileWidths()?.base?.minus(it.width) ?: 0 } ?: 0,
+ label = "QSEditTileWidthOffset",
+ )
+ return zIndex(2f).layout { measurable, constraints ->
+ // Grab the width from the resizing state if a resize is in progress
+ val width = selectionState.resizingState?.width ?: (constraints.maxWidth - remainingOffset)
+ val placeable = measurable.measure(constraints.copy(minWidth = width, maxWidth = width))
+ layout(constraints.maxWidth, placeable.height) { placeable.place(0, 0) }
+ }
+}
+
private object SelectionDefaults {
val ResizingDotSize = 16.dp
+ val SelectedBorderWidth = 2.dp
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/model/TileGridCell.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/model/TileGridCell.kt
index b1841c4c5ffa..c0441f8a38a1 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/model/TileGridCell.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/model/TileGridCell.kt
@@ -31,8 +31,8 @@ sealed interface GridCell {
}
/**
- * Represents a [EditTileViewModel] from a grid associated with a tile format and the row it's
- * positioned at
+ * Represents a [EditTileViewModel] from a grid associated with a tile format and the row and column
+ * it's positioned at
*/
@Immutable
data class TileGridCell(
@@ -41,13 +41,15 @@ data class TileGridCell(
override val width: Int,
override val span: GridItemSpan = GridItemSpan(width),
override val s: String = "${tile.tileSpec.spec}-$row-$width",
+ val column: Int,
) : GridCell, SizedTile<EditTileViewModel>, CategoryAndName by tile {
val key: String = "${tile.tileSpec.spec}-$row"
constructor(
sizedTile: SizedTile<EditTileViewModel>,
row: Int,
- ) : this(tile = sizedTile.tile, row = row, width = sizedTile.width)
+ column: Int,
+ ) : this(tile = sizedTile.tile, row = row, column = column, width = sizedTile.width)
}
/** Represents an empty space used to fill incomplete rows. Will always display as a 1x1 tile */
@@ -73,7 +75,13 @@ fun List<SizedTile<EditTileViewModel>>.toGridCells(
return splitInRowsSequence(this, columns)
.flatMapIndexed { rowIndex, sizedTiles ->
val correctedRowIndex = rowIndex + startingRow
- val row: List<GridCell> = sizedTiles.map { TileGridCell(it, correctedRowIndex) }
+ var column = 0
+ val row: List<GridCell> =
+ sizedTiles.map {
+ TileGridCell(it, correctedRowIndex, column).also { cell ->
+ column += cell.width
+ }
+ }
// Fill the incomplete rows with spacers
val numSpacers = columns - sizedTiles.sumOf { it.width }
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/BounceableTileViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/BounceableTileViewModel.kt
new file mode 100644
index 000000000000..506b05256880
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/BounceableTileViewModel.kt
@@ -0,0 +1,38 @@
+/*
+ * 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.qs.panels.ui.viewmodel
+
+import androidx.compose.animation.core.Animatable
+import androidx.compose.animation.core.VectorConverter
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.dp
+import com.android.compose.animation.Bounceable
+
+class BounceableTileViewModel : Bounceable {
+ private val animatableBounce = Animatable(0.dp, Dp.VectorConverter)
+ override val bounce: Dp
+ get() = animatableBounce.value
+
+ suspend fun animateBounce() {
+ animatableBounce.animateTo(BounceSize)
+ animatableBounce.animateTo(0.dp)
+ }
+
+ private companion object {
+ val BounceSize = 8.dp
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditTileViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditTileViewModel.kt
index ee12736f6db4..be6ce5c5b4f4 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditTileViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditTileViewModel.kt
@@ -43,13 +43,13 @@ data class UnloadedEditTileViewModel(
) {
fun load(context: Context): EditTileViewModel {
return EditTileViewModel(
- tileSpec,
- icon,
- label.toAnnotatedString(context) ?: AnnotatedString(tileSpec.spec),
- appName?.toAnnotatedString(context),
- isCurrent,
- availableEditActions,
- category,
+ tileSpec = tileSpec,
+ icon = icon,
+ label = label.toAnnotatedString(context) ?: AnnotatedString(tileSpec.spec),
+ appName = appName?.toAnnotatedString(context),
+ isCurrent = isCurrent,
+ availableEditActions = availableEditActions,
+ category = category,
)
}
}