diff --git a/README.md b/README.md index bdd7562b..7785c657 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ It's made with performance in mind, to run smoothly even on old and weak Android - [x] Reorder your apps - [x] Hide the apps you don't use (quickly accessible from the hidden shelf) - [x] Customize the tile shape, from square to pill-shaped +- [x] Lift the focused tile with a soft shadow instead of a frame, and show its app's name below it - [x] Set your own pictures as wallpaper, with dim and blur options **On the way** diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index b4df9cdd..5bd3cf0c 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -230,12 +230,14 @@ Adding an aspect, e.g. the focus frame's color: | Its label and its values' labels, in every translation | `:feature:settings` | the exhaustive `when` doesn't compile; lint ([`TRANSLATIONS.md`](TRANSLATIONS.md)) | | Its effect on the home screen, and on the preview where it shows | `:feature:home`, `:feature:settings` | a test that sets each option of the catalog to a value other than its default, and fails if the home screen, or the preview, draws the same | -Today `Appearance` has four parts: `TileGeometry` (the tiles' size, spacing and alignment), -`TileStyle` (their corners), `TopBarAppearance` (whether the time and the -date show, the clock's side, and the time's side of the date) and `Background` (the wallpaper: a -picture of the picture library, or none, and how it's drawn). The catalog's options, the vertical -and the horizontal alignment, a full bottom row, the corner radius, the time and the date shown or -hidden, the clock's side and the time's side, are changed in the settings' appearance editor +Today `Appearance` has four parts: `TileGeometry` (the tiles' size, spacing and alignment, and +whether the focused tile's name shows below it, which the rows leave room for), `TileStyle` (their +corners, and how the focused one stands out: framed or lifted), `TopBarAppearance` (whether the +time and the date show, the clock's side, and the time's side of the date) and `Background` (the +wallpaper: a picture of the picture library, or none, and how it's drawn). The catalog's options, +the vertical and the horizontal alignment, a full bottom row, the corner radius, the focus style, +the app name, the time and the date shown or hidden, the clock's side and the time's side, are +changed in the settings' appearance editor ([`feature/settings/README.md`](../feature/settings/README.md#appearance)); the wallpaper's fit, position, dim and blur in the background editor it opens (below). The wallpaper's picture isn't an option, since its values are the library's pictures, not a list known in `:domain`. diff --git a/domain/README.md b/domain/README.md index e39dc047..5a7ae78f 100644 --- a/domain/README.md +++ b/domain/README.md @@ -25,10 +25,12 @@ domain/src/ │ │ └── Banner.kt model and rule: which image a tile shows (the app's banner or its icon) │ ├── appearance/ │ │ ├── Appearance.kt model: how the home screen looks, as far as the user can change it, in parts (docs/ARCHITECTURE.md#appearance) -│ │ ├── TileGeometry.kt model: where tiles go and how big they are, in dp; their alignment +│ │ ├── TileGeometry.kt model: where tiles go and how big they are, in dp; their alignment; whether the focused tile's name shows below it +│ │ ├── AppName.kt model: an app's name below its tile, never or below the focused one │ │ ├── VerticalAlignment.kt model: the rows at the top, centered or at the bottom of the height │ │ ├── HorizontalAlignment.kt model: a row that isn't full at the left, centered or at the right -│ │ ├── TileStyle.kt model: how each tile is drawn (its corners) +│ │ ├── TileStyle.kt model: how each tile is drawn (its corners, how the focused one stands out) +│ │ ├── FocusStyle.kt model: the focused tile framed, or lifted with a shadow │ │ ├── Corners.kt model and rule: a corner radius or round ends, in pixels for a tile's height │ │ ├── TopBarAppearance.kt model: whether the time and the date show, the clock's side of the top bar, the time's side of the date │ │ ├── Background.kt model and rule: the wallpaper, a picture of the library or none, and how it's drawn; only values its context offers; another picture chosen as it is @@ -70,7 +72,7 @@ domain/src/ │ ├── TileLayout.kt how an arrangement of tiles reports sizes and positions │ ├── TileMoves.kt how it says where a tile the user moves goes, and which tile is nearest across │ ├── Direction.kt model: a D-pad arrow -│ ├── TileGrid.kt rule: the grid (rows of tiles as wide as a width; the short row first or last, at the left, centered or at the right; at the top, centered or at the bottom of a height), and moves in it +│ ├── TileGrid.kt rule: the grid (rows of tiles as wide as a width; the short row first or last, at the left, centered or at the right; at the top, centered or at the bottom of a height; room below each row for the focused tile's name), and moves in it │ ├── TileFocus.kt rule: where each arrow takes the focus among the tiles: along the row, the nearest tile up or down, and back the way it came │ ├── TileLayouts.kt rule: the layouts for a TileGeometry, in pixels at a density; picks the arrangement and placement │ ├── ShelfLayout.kt rule: the shown apps' tiles above a shelf of the hidden ones, while arranging diff --git a/domain/src/main/kotlin/com/luncher/domain/appearance/AppName.kt b/domain/src/main/kotlin/com/luncher/domain/appearance/AppName.kt new file mode 100644 index 00000000..f3321622 --- /dev/null +++ b/domain/src/main/kotlin/com/luncher/domain/appearance/AppName.kt @@ -0,0 +1,10 @@ +package com.luncher.domain.appearance + +/** When an app's name shows on the home screen, centered below its tile. */ +enum class AppName { + /** Never: the banner says which app it is. */ + OFF, + + /** Below the focused tile only, coming and going with the focus. */ + WHEN_FOCUSED, +} diff --git a/domain/src/main/kotlin/com/luncher/domain/appearance/AppearanceOption.kt b/domain/src/main/kotlin/com/luncher/domain/appearance/AppearanceOption.kt index 994535ba..ce802303 100644 --- a/domain/src/main/kotlin/com/luncher/domain/appearance/AppearanceOption.kt +++ b/domain/src/main/kotlin/com/luncher/domain/appearance/AppearanceOption.kt @@ -4,6 +4,8 @@ import com.luncher.domain.pictures.Blur import com.luncher.domain.pictures.Fit import com.luncher.domain.pictures.PictureCut import com.luncher.domain.pictures.PicturePosition +import com.luncher.domain.appearance.AppName as Name +import com.luncher.domain.appearance.FocusStyle as Focus import com.luncher.domain.appearance.HorizontalAlignment as Horizontal import com.luncher.domain.appearance.VerticalAlignment as Vertical @@ -74,6 +76,22 @@ sealed interface AppearanceOption { appearance.copy(tileStyle = appearance.tileStyle.copy(corners = value)) } + /** How the focused tile stands out: framed, or lifted with a shadow. */ + data object FocusStyle : AppearanceOption { + override val values: List = Focus.entries + override fun get(appearance: Appearance) = appearance.tileStyle.focus + override fun set(appearance: Appearance, value: Focus) = + appearance.copy(tileStyle = appearance.tileStyle.copy(focus = value)) + } + + /** Whether the focused tile's app name shows below it. */ + data object AppName : AppearanceOption { + override val values: List = Name.entries + override fun get(appearance: Appearance) = appearance.tileGeometry.appName + override fun set(appearance: Appearance, value: Name) = + appearance.copy(tileGeometry = appearance.tileGeometry.copy(appName = value)) + } + /** Whether the top bar shows the time. */ data object ShowTime : AppearanceOption { override val values: List = listOf(true, false) diff --git a/domain/src/main/kotlin/com/luncher/domain/appearance/AppearanceOptions.kt b/domain/src/main/kotlin/com/luncher/domain/appearance/AppearanceOptions.kt index f50f6539..a26e232f 100644 --- a/domain/src/main/kotlin/com/luncher/domain/appearance/AppearanceOptions.kt +++ b/domain/src/main/kotlin/com/luncher/domain/appearance/AppearanceOptions.kt @@ -34,6 +34,8 @@ fun appearanceOptions(): AppearanceOptions = AppearanceOption.HorizontalAlignment, AppearanceOption.FullBottomRow, AppearanceOption.CornerRadius, + AppearanceOption.FocusStyle, + AppearanceOption.AppName, ), ), AppearanceGroup( diff --git a/domain/src/main/kotlin/com/luncher/domain/appearance/FocusStyle.kt b/domain/src/main/kotlin/com/luncher/domain/appearance/FocusStyle.kt new file mode 100644 index 00000000..b9d18c99 --- /dev/null +++ b/domain/src/main/kotlin/com/luncher/domain/appearance/FocusStyle.kt @@ -0,0 +1,10 @@ +package com.luncher.domain.appearance + +/** How the focused tile stands out from the others. */ +enum class FocusStyle { + /** A frame in the accent color around it, and a slight zoom. */ + FRAME, + + /** No frame: a bigger zoom, and a soft shadow under it, as if it were lifted off the screen. */ + LIFT, +} diff --git a/domain/src/main/kotlin/com/luncher/domain/appearance/TileGeometry.kt b/domain/src/main/kotlin/com/luncher/domain/appearance/TileGeometry.kt index 74313c44..d6ab1938 100644 --- a/domain/src/main/kotlin/com/luncher/domain/appearance/TileGeometry.kt +++ b/domain/src/main/kotlin/com/luncher/domain/appearance/TileGeometry.kt @@ -23,4 +23,10 @@ data class TileGeometry( * the last, so the bottom row is always full. Nothing changes with the rows at the top. */ val fullBottomRow: Boolean = true, + /** + * When an app's name shows below its tile. Shown below the focused one, the rows are further + * apart to leave it room, and the last row has the room below it too, so a name never covers + * a tile ([com.luncher.domain.layout.TileLayouts.nameRoom]). + */ + val appName: AppName = AppName.OFF, ) diff --git a/domain/src/main/kotlin/com/luncher/domain/appearance/TileStyle.kt b/domain/src/main/kotlin/com/luncher/domain/appearance/TileStyle.kt index 1202a868..c9602d86 100644 --- a/domain/src/main/kotlin/com/luncher/domain/appearance/TileStyle.kt +++ b/domain/src/main/kotlin/com/luncher/domain/appearance/TileStyle.kt @@ -5,6 +5,8 @@ package com.luncher.domain.appearance * have. */ data class TileStyle( - /** The tiles' corners, and their focus frame's. */ + /** The tiles' corners, and their focus frame's and shadow's. */ val corners: Corners = Corners.Radius(12), + /** How the focused tile stands out: a frame, or lifted. */ + val focus: FocusStyle = FocusStyle.FRAME, ) diff --git a/domain/src/main/kotlin/com/luncher/domain/layout/TileGrid.kt b/domain/src/main/kotlin/com/luncher/domain/layout/TileGrid.kt index f7eef8ef..97d90304 100644 --- a/domain/src/main/kotlin/com/luncher/domain/layout/TileGrid.kt +++ b/domain/src/main/kotlin/com/luncher/domain/layout/TileGrid.kt @@ -10,7 +10,8 @@ import kotlin.math.roundToInt * top to bottom. The tiles share the [width] they get between them, [gap] apart, with the banner's * 16:9 shape; what's left over after rounding goes to equal margins on both sides, so the grid is * centered. The row that isn't full is the last one, or the first with [shortRowFirst], and goes - * where [rowAlignment] says: at the left, centered, or at the right. The rows go where + * where [rowAlignment] says: at the left, centered, or at the right. Below each row, the last one + * too, is [nameHeight] of room for the focused tile's name, none by default. The rows go where * [verticalAlignment] says in the [height] they get, if they fit it; otherwise they start at the * top, and rows below the space scroll vertically. * @@ -28,11 +29,13 @@ class TileGrid( private val shortRowFirst: Boolean = false, height: Int = 0, verticalAlignment: VerticalAlignment = VerticalAlignment.TOP, + nameHeight: Int = 0, ) : TileLayout, TileMoves { init { require(columns >= 1) { "columns must be at least 1: $columns" } require(tileCount >= 0) { "tileCount must not be negative: $tileCount" } + require(nameHeight >= 0) { "nameHeight must not be negative: $nameHeight" } } override val tileWidth: Int = ((width - gap * (columns - 1)) / columns).coerceAtLeast(0) @@ -41,7 +44,10 @@ class TileGrid( private val margin: Int = ((width - tileWidth * columns - gap * (columns - 1)) / 2).coerceAtLeast(0) private val rows: Int = rows(tileCount) - private val rowsHeight: Int = if (rows == 0) 0 else rows * tileHeight + (rows - 1) * gap + /** A row's tiles and the room for a name below them. */ + private val rowHeight: Int = tileHeight + nameHeight + + private val rowsHeight: Int = if (rows == 0) 0 else rows * rowHeight + (rows - 1) * gap /** Above the first row: room left at the top when the rows are centered or at the bottom. */ private val offset: Int = verticalAlignment.offset(rowsHeight, height) @@ -51,7 +57,7 @@ class TileGrid( override fun left(index: Int): Int = margin + slot(index) * (tileWidth + gap) / 2 - override fun top(index: Int): Int = offset + row(index, tileCount) * (tileHeight + gap) + override fun top(index: Int): Int = offset + row(index, tileCount) * (rowHeight + gap) override fun indexToward(index: Int, direction: Direction): Int? { val row = row(index, tileCount) diff --git a/domain/src/main/kotlin/com/luncher/domain/layout/TileLayouts.kt b/domain/src/main/kotlin/com/luncher/domain/layout/TileLayouts.kt index 2e57f95e..ea6c79d1 100644 --- a/domain/src/main/kotlin/com/luncher/domain/layout/TileLayouts.kt +++ b/domain/src/main/kotlin/com/luncher/domain/layout/TileLayouts.kt @@ -1,5 +1,6 @@ package com.luncher.domain.layout +import com.luncher.domain.appearance.AppName import com.luncher.domain.appearance.TileGeometry import com.luncher.domain.appearance.VerticalAlignment import kotlin.math.roundToInt @@ -8,12 +9,25 @@ import kotlin.math.roundToInt * The layouts of the home screen's tiles for a [TileGeometry], at [pixelsPerDp]: the one place that * turns the geometry's dp into pixels and picks the arrangement, so where a tile is shown and * where the user moves it agree, and anything else that shows tiles, at its own density, agrees too. + * + * [nameHeight] is how much room, in pixels, the focused tile's name takes below the tile, zoomed + * as the tile is: the view that draws the name measures its text, as the domain can't. The rows + * leave it that room only while the geometry shows the name ([AppName.WHEN_FOCUSED]). */ -class TileLayouts(geometry: TileGeometry, pixelsPerDp: Float) { +class TileLayouts(geometry: TileGeometry, pixelsPerDp: Float, nameHeight: Int = 0) { /** Between tiles, in pixels. */ val gap: Int = (geometry.gapDp * pixelsPerDp).roundToInt() + /** + * Below each row, the last one too, the room for the focused tile's name, in pixels: none + * while names don't show. A view scrolling a tile into sight shows this much below it too. + */ + val nameRoom: Int = when (geometry.appName) { + AppName.OFF -> 0 + AppName.WHEN_FOCUSED -> nameHeight + } + private val tileWidth: Int = (geometry.tileWidthDp * pixelsPerDp).roundToInt() private val vertical = geometry.verticalAlignment private val horizontal = geometry.horizontalAlignment @@ -46,6 +60,6 @@ class TileLayouts(geometry: TileGeometry, pixelsPerDp: Float) { private fun grid(tileCount: Int, width: Int, height: Int, vertical: VerticalAlignment) = TileGrid( tileCount, TileGrid.columnsFor(width, tileWidth, gap), width, gap, - horizontal, shortRowFirst, height, vertical, + horizontal, shortRowFirst, height, vertical, nameRoom, ) } diff --git a/domain/src/test/kotlin/com/luncher/domain/appearance/AppearanceOptionTest.kt b/domain/src/test/kotlin/com/luncher/domain/appearance/AppearanceOptionTest.kt index bd348fa8..09827cb8 100644 --- a/domain/src/test/kotlin/com/luncher/domain/appearance/AppearanceOptionTest.kt +++ b/domain/src/test/kotlin/com/luncher/domain/appearance/AppearanceOptionTest.kt @@ -74,6 +74,8 @@ class AppearanceOptionTest { assertEquals(HorizontalAlignment.CENTER, AppearanceOption.HorizontalAlignment.default) assertEquals(true, AppearanceOption.FullBottomRow.default) assertEquals(Corners.Radius(12), AppearanceOption.CornerRadius.default) + assertEquals(FocusStyle.FRAME, AppearanceOption.FocusStyle.default) + assertEquals(AppName.OFF, AppearanceOption.AppName.default) assertEquals(Side.LEFT, AppearanceOption.ClockSide.default) assertEquals(Side.LEFT, AppearanceOption.TimeSide.default) assertEquals(true, AppearanceOption.ShowTime.default) @@ -101,6 +103,25 @@ class AppearanceOptionTest { ) } + // Lifted and a name below are new looks, never the default: the home screen looks as before. + @Test + fun `the focus style and the app name step from today's look to the new one`() { + assertEquals(listOf(FocusStyle.FRAME, FocusStyle.LIFT), AppearanceOption.FocusStyle.values) + assertEquals(listOf(AppName.OFF, AppName.WHEN_FOCUSED), AppearanceOption.AppName.values) + } + + // The focus style only redraws the tiles; the name needs room between the rows, a new layout. + @Test + fun `the focus style changes the tiles' style, the app name their geometry`() { + val lifted = AppearanceOption.FocusStyle.set(Appearance(), FocusStyle.LIFT) + val named = AppearanceOption.AppName.set(Appearance(), AppName.WHEN_FOCUSED) + + assertEquals(TileStyle(focus = FocusStyle.LIFT), lifted.tileStyle) + assertEquals(TileGeometry(), lifted.tileGeometry) + assertEquals(TileGeometry(appName = AppName.WHEN_FOCUSED), named.tileGeometry) + assertEquals(TileStyle(), named.tileStyle) + } + @Test fun `steps to the next and the previous value`() { val radius = AppearanceOption.CornerRadius diff --git a/domain/src/test/kotlin/com/luncher/domain/appearance/AppearanceOptionsTest.kt b/domain/src/test/kotlin/com/luncher/domain/appearance/AppearanceOptionsTest.kt index 1aef2103..8fc84040 100644 --- a/domain/src/test/kotlin/com/luncher/domain/appearance/AppearanceOptionsTest.kt +++ b/domain/src/test/kotlin/com/luncher/domain/appearance/AppearanceOptionsTest.kt @@ -22,6 +22,8 @@ class AppearanceOptionsTest { AppearanceOption.HorizontalAlignment, AppearanceOption.FullBottomRow, AppearanceOption.CornerRadius, + AppearanceOption.FocusStyle, + AppearanceOption.AppName, ), catalog.groups[0].options, ) diff --git a/domain/src/test/kotlin/com/luncher/domain/layout/TileGridTest.kt b/domain/src/test/kotlin/com/luncher/domain/layout/TileGridTest.kt index 468dbd77..c5531b30 100644 --- a/domain/src/test/kotlin/com/luncher/domain/layout/TileGridTest.kt +++ b/domain/src/test/kotlin/com/luncher/domain/layout/TileGridTest.kt @@ -49,6 +49,41 @@ class TileGridTest { assertEquals(0, grid(tiles = 0).contentHeight) } + // Two rows, 25 px apart, each with 30 px below its tiles for the focused tile's name. + @Test + fun `leaves room for a name below each row, the last one too`() { + val grid = TileGrid(7, columns = 5, width = 1000, gap = 25, nameHeight = 30) + + assertEquals(101, grid.tileHeight) // the tiles keep their size + assertEquals(listOf(0, 205), (5..6).map(grid::left)) + assertEquals(101 + 30 + 25, grid.top(5)) + assertEquals(2 * (101 + 30) + 25, grid.contentHeight) + } + + @Test + fun `at the bottom, a name below the last row still fits the height`() { + val grid = TileGrid(7, columns = 5, width = 1000, gap = 25, height = 600, verticalAlignment = VerticalAlignment.BOTTOM, nameHeight = 30) + + assertEquals(600 - 30, grid.top(5) + grid.tileHeight) + assertEquals(600, grid.contentHeight) + } + + // Moves depend on the order and the columns only: the room for names changes none. + @Test + fun `the room for names changes no move`() { + val grid = TileGrid(7, columns = 5, width = 1000, gap = 25, nameHeight = 30) + + for (index in 0 until 7) { + for (direction in Direction.entries) assertEquals(grid(tiles = 7).indexToward(index, direction), grid.indexToward(index, direction)) + assertEquals(grid(tiles = 7).slot(index), grid.slot(index)) + } + } + + @Test(expected = IllegalArgumentException::class) + fun `needs a room for names that isn't negative`() { + TileGrid(7, columns = 5, width = 1000, gap = 25, nameHeight = -1) + } + @Test fun `a space too narrow for the tiles gives empty tiles instead of failing`() { val grid = grid(tiles = 3, width = 50) diff --git a/domain/src/test/kotlin/com/luncher/domain/layout/TileLayoutsTest.kt b/domain/src/test/kotlin/com/luncher/domain/layout/TileLayoutsTest.kt index c8a4d1f6..d78d286e 100644 --- a/domain/src/test/kotlin/com/luncher/domain/layout/TileLayoutsTest.kt +++ b/domain/src/test/kotlin/com/luncher/domain/layout/TileLayoutsTest.kt @@ -1,5 +1,6 @@ package com.luncher.domain.layout +import com.luncher.domain.appearance.AppName import com.luncher.domain.appearance.TileGeometry import com.luncher.domain.appearance.HorizontalAlignment import com.luncher.domain.appearance.VerticalAlignment @@ -193,5 +194,32 @@ class TileLayoutsTest { assertEquals(layouts.tiles(5, width, height).left(0), at(top, left).shelf(5, 0, width, height, 20).labelLeft(50)) } + @Test + fun `leaves room for the focused tile's name only while names show`() { + val names = TileLayouts(topLeft.copy(appName = AppName.WHEN_FOCUSED), pixelsPerDp = 1f, nameHeight = 30) + val none = TileLayouts(topLeft, pixelsPerDp = 1f, nameHeight = 30) + + assertEquals(30, names.nameRoom) + assertEquals(0, none.nameRoom) + val tiles = names.tiles(tileCount = 7, width, height) + assertEquals(tiles.tileHeight + 30 + names.gap, tiles.top(5)) + assertEquals(none.tiles(tileCount = 7, width, height).top(5) + 30, tiles.top(5)) + } + + // The name of a tile in the last shown row stays clear of the shelf's label, and the moves + // and the focus are those without names. + @Test + fun `while names show, arranging leaves them room too, and moves the same`() { + val names = TileLayouts(TileGeometry(appName = AppName.WHEN_FOCUSED), pixelsPerDp = 1f, nameHeight = 30) + + val shelf = names.shelf(shownCount = 5, hiddenCount = 2, width, height = 0, labelHeight = 20) + + assertEquals(shelf.top(0) + shelf.tileHeight + 30 + names.gap, shelf.labelTop) + val moves = names.moves(tileCount = 7, width) + val without = layouts().moves(tileCount = 7, width) + for (index in 0 until 7) assertEquals(without.indexToward(index, Direction.DOWN), moves.indexToward(index, Direction.DOWN)) + assertEquals(layouts().focus(tileCount = 7, width).toward(1, Direction.DOWN), names.focus(tileCount = 7, width).toward(1, Direction.DOWN)) + } + private fun layouts() = TileLayouts(TileGeometry(), pixelsPerDp = 1f) } diff --git a/feature/home/README.md b/feature/home/README.md index 7831824a..ea0dbbd6 100644 --- a/feature/home/README.md +++ b/feature/home/README.md @@ -25,11 +25,11 @@ feature/home/ │ │ ├── ClockView.kt the top bar's time and date, following the Clock port │ │ ├── OutlinedTextView.kt a text on the wallpaper, with :ui's WallpaperOutline around it │ │ ├── AppTilesView.kt places the tiles where the domain's TileLayout says; scrolls - │ │ ├── AppTileView.kt one app: its image, focus frame and zoom; held or hidden while arranging - │ │ ├── TilePaints.kt what every tile draws with: frames, dimming, the corners + │ │ ├── AppTileView.kt one app: its image, focus frame and zoom, or lift and shadow; its name; held or hidden while arranging + │ │ ├── TilePaints.kt what every tile draws with: frames, dimming, the name, the corners, the focus style, the shadow's outline │ │ ├── HomeWallpaper.kt the wallpaper, the window's background, as the process's Wallpaper says; a window while it's drawn again │ │ └── ArrangeMode.kt arrange mode: keys to the domain's ArrangeSession, the shelf, the top bar's title and hint - │ └── res/ the focused tile's zoom (animator/), the settings gear and its focus + │ └── res/ the focused tile's zoom, or zoom and lift (animator/), the settings gear and its focus │ disc, home_activity.xml, home_* dimensions and strings, and their │ translations in values-el/ and values-ar/ (docs/TRANSLATIONS.md) └── test/ @@ -74,14 +74,14 @@ one job, so a new arrangement, image source or top bar item changes one of them: | Part | Job | |---|---| | `homeApps` (`:domain`) | which apps show, in which order, and which are hidden: the installed apps matched to the stored `AppArrangement` ([Hidden apps](../settings/README.md#hidden-apps)) | -| `Appearance` (`:domain`) | how the home screen looks, as the user set it in the [appearance editor](../settings/README.md#appearance), in parts: `TileGeometry` (the tiles' width, the gap between them, their vertical and horizontal alignment), `TileStyle` (their corners: a radius, 12 dp by default, or round ends), `TopBarAppearance` (whether the time and the date show, the clock's side, the time's side of the date), `Background` (the wallpaper: a picture of the picture library, or none, its fit, position, dim and blur). [Below](#appearance): how each part is applied. | +| `Appearance` (`:domain`) | how the home screen looks, as the user set it in the [appearance editor](../settings/README.md#appearance), in parts: `TileGeometry` (the tiles' width, the gap between them, their vertical and horizontal alignment, whether the focused tile's name shows), `TileStyle` (their corners: a radius, 12 dp by default, or round ends; the focus style: a frame by default, or lifted), `TopBarAppearance` (whether the time and the date show, the clock's side, the time's side of the date), `Background` (the wallpaper: a picture of the picture library, or none, its fit, position, dim and blur). [Below](#appearance): how each part is applied. | | `AppearanceSettings` (`:domain`), `PreferencesAppearanceSettings` (`:platform`) | the stored appearance, and when it changes | | `TileLayout`, `TileLayouts` (`:domain`) | where each tile goes and how big it is; `TileGrid` is the only one so far, with as many columns as fit tiles of about the geometry's width (`TileGrid.columnsFor`), so tiles keep their size next to the top bar's text on any screen. `TileLayouts` is the only place that picks the arrangement, for the tiles' places and for moves in arrange mode alike. | | `TileFocus` (`:domain`) | where each arrow takes the focus among the tiles ([below](#focus)) | | `AppTilesView` | lays tiles out where the `TileLayout` says, moves the focus where the `TileFocus` says, and scrolls to the focused one; holds the `TilePaints` its tiles share | | `bannerFor` (`:domain`) | which image a tile shows | | `AppImages` (`:domain`), `CachedBannerImages` and `BannerImages` (`:platform`) | draws that image into a bitmap of the tile's size, or reads the one an earlier start drew | -| `AppTileView` | draws that bitmap, the focus frame and zoom, with the corners `TilePaints` gives; in arrange mode, a white frame and a bigger zoom when held, dimmed when hidden | +| `AppTileView` | draws that bitmap, the focus frame and zoom, or the lift ([below](#appearance)), with the corners `TilePaints` gives, and the focused app's name below it if the geometry says; in arrange mode, a white frame and the largest zoom when held, dimmed when hidden | | `Clock` (`:domain`) | what time it is, in which time zone and hour format, and when that changes | | `AndroidClock` (`:platform`) | reads those from Android, and watches the time broadcasts only while something listens | | `ClockView` | formats a reading in the device's language; the time and the date side by side, in the order the top bar gives, either or both hidden | @@ -135,7 +135,8 @@ What keeps it light: Android, not looked for: nothing runs between them, and a burst of them (an app store's updates) reads the list once. - **Nothing allocated per key press in Luncher's code.** `TileFocus` keeps its last move in place; - the zoom is a state animator created with each tile; scrolling reuses one `Scroller`. + the zoom (and the lift) is a state animator created with each tile, as is the name's fade; + scrolling reuses one `Scroller`. Android 5 still allocates inside its animators each time they start, about 2 KB a focus move. - **Layout passes only when the tiles change.** Focus, zoom and scrolling redraw without measuring or laying out again. The clock's text changes once a minute, which lays out the top @@ -154,8 +155,8 @@ screen reads an equal appearance. What a change costs depends on the part: | Part | Goes to | A change costs | |---|---|---| -| `TileGeometry` | `AppTilesView.tileGeometry` | a new layout from `TileLayouts` (it's an input of the layout, with the width, the height, the number of tiles and `shownCount`), and a layout pass; new banner bitmaps only for tiles whose size changes, so a new placement draws none | -| `TileStyle` | `AppTilesView.tileStyle` | the radius in the `TilePaints` all tiles share, and a redraw: no layout pass, no new bitmaps | +| `TileGeometry` | `AppTilesView.tileGeometry` | a new layout from `TileLayouts` (it's an input of the layout, with the width, the height, the number of tiles and `shownCount`), and a layout pass; new banner bitmaps only for tiles whose size changes, so a new placement, or the name shown, draws none | +| `TileStyle` | `AppTilesView.tileStyle` | the radius and the focus style in the `TilePaints` all tiles share, and a redraw; a new focus style also gives each tile the state animator of that style: no layout pass, no new bitmaps | | `TopBarAppearance` | `TopBarView.appearance` | the bar's items moved (focus on the gear stays), and a layout pass of the bar only | | `Background` | `HomeWallpaper.show` | the window's background: the picture kept at the screen's size, or drawn again in the background while a window says so ([below](#the-wallpaper)); nothing else is laid out or drawn anew | @@ -179,6 +180,28 @@ half the tile's height, which is what round ends are, so they're half circles on radius draws the same bitmaps, so no banner is drawn again. Drawing allocates nothing, with or without rounded corners. +The focused tile stands out in one of two styles (`TileStyle.focus`). **Frame**, the default: the +accent-colored frame and a zoom of 1.1 (`home_tile_focus.xml`). **Lift**: no frame, a zoom of 1.15, +and the tile rises toward the viewer (`translationZ`, `home_tile_lift`, in `home_tile_lift.xml`), so +Android's renderer casts its shadow from its outline, a rounded rectangle with the tiles' corners +(`TilePaints.tileOutline`). The shadow is the GPU's, as for any raised view since Android 5: no +blurred bitmap, no software layer, nothing drawn per frame in Luncher's code; `AppTilesView` doesn't +clip its tiles, so it shows past the tile. A held tile keeps its white frame and its zoom of 1.15 in +both styles; a lifted one only focused is as big, so there the white frame tells the two apart. + +With the app name shown (`TileGeometry.appName`, Off by default), the focused tile draws its app's +name centered below it, in the primary text color, cut with "…" to the tile's width, outlined as +everything on the wallpaper is ([The top bar](#the-top-bar)), fading in and out with the focus in +the zoom's time, and dimmed with a hidden app's tile in [arrange mode](#arrange-mode). It's drawn +with the tile, past its bottom edge, so it zooms and lifts with it; its text is cut once per tile +size, and the fade is an animator made with the tile, so a focus move only starts it. The rows leave +it room: `TilePaints.nameHeight`, the gap and a line of text at the largest zoom a tile gets, +measured by `:ui`'s `TileName` (which the [appearance editor's +preview](../settings/README.md#appearance) measures with too), is the room `TileLayouts` keeps below +each row, the last one too, so a name never covers the next row, and the rows at the bottom end that +much higher. Scrolling to a focused tile shows its name too. The room doesn't change where the focus +or a moved app goes. + ### The wallpaper The `Background` part's picture is the window's background (`HomeWallpaper`), behind the top bar @@ -241,7 +264,7 @@ shows where hiding is. | While… | Arrows | OK | Back | |---|---|---|---| -| holding an app (white frame, bigger zoom) | move it | put it down | put it down, end the mode | +| holding an app (white frame, the largest zoom) | move it | put it down | put it down, end the mode | | not holding one | move the focus | pick up the focused app, shown or hidden | end the mode | Left and Right move the held app one place along the order, wrapping rows; Up and Down one row, to diff --git a/feature/home/src/main/java/com/luncher/launcher/home/AppTileView.kt b/feature/home/src/main/java/com/luncher/launcher/home/AppTileView.kt index 562f6860..1bfd315f 100644 --- a/feature/home/src/main/java/com/luncher/launcher/home/AppTileView.kt +++ b/feature/home/src/main/java/com/luncher/launcher/home/AppTileView.kt @@ -1,36 +1,48 @@ package com.luncher.launcher.home import android.animation.AnimatorInflater +import android.animation.ValueAnimator import android.annotation.SuppressLint import android.content.Context import android.graphics.Bitmap import android.graphics.BitmapShader import android.graphics.Canvas +import android.graphics.Color import android.graphics.Paint import android.graphics.Rect import android.graphics.RectF import android.graphics.Shader +import android.text.TextUtils import android.view.View +import com.luncher.domain.appearance.FocusStyle import com.luncher.domain.apps.AppImages import com.luncher.domain.apps.InstalledApp import com.luncher.domain.apps.bannerFor /** - * One app on the home screen: its banner, and a frame and a slight zoom while it has focus. - * The image is drawn at the tile's size whenever that size changes (the number of columns, for - * example), so drawing the tile is a single bitmap copy. With rounded corners ([TilePaints]), the - * same bitmap fills a rounded rectangle through a shader made with it, and the frame follows the + * One app on the home screen: its banner, and while it has focus, as [TilePaints.focusStyle] says, + * a frame and a slight zoom, or no frame, a bigger zoom and a shadow, as if lifted. The image is + * drawn at the tile's size whenever that size changes (the number of columns, for example), so + * drawing the tile is a single bitmap copy. With rounded corners ([TilePaints]), the same bitmap + * fills a rounded rectangle through a shader made with it, and the frame and the shadow follow the * corners: a new radius only redraws, with the image as it is. * - * While the user arranges apps, a [held] tile has a white frame and a bigger zoom, apart from one - * that's only focused, and a [hidden] app's tile is dimmed. + * The shadow is Android's own, cast by the tile's outline as it rises (its translationZ, in the + * state animator), drawn by the GPU: nothing is blurred or allocated for it. With + * [TilePaints.showsNames], the focused tile's app name shows centered below it, cut to the + * tile's width, fading in and out with the focus; drawn with the tile, outside its bounds, which + * [AppTilesView] doesn't clip, so it zooms with it. + * + * While the user arranges apps, a [held] tile has a white frame and the largest zoom, apart from + * one that's only focused (lifted, that one is as big: the frame tells them apart), and a + * [hidden] app's tile is dimmed, its name too. */ @SuppressLint("ViewConstructor") // Created in code only, never from XML. internal class AppTileView( context: Context, val app: InstalledApp, private val images: AppImages, - /** Shared by every tile: the frames, the dimming and the corner radius. */ + /** Shared by every tile: the frames, the dimming, the name's paint, the corners and the focus style. */ private val paints: TilePaints, ) : View(context) { @@ -43,6 +55,22 @@ internal class AppTileView( private val bounds = RectF() private val frameBounds = RectF() + /** The app's name as it fits the tile's width, and where it starts: set with each new size. */ + private var name = "" + private var nameLeft = 0f + + /** + * The name's fade, with the focus: forward as it comes, back as it goes. Made once, so a key + * press only starts it. + */ + private val nameFade = ValueAnimator.ofFloat(0f, 1f).apply { + duration = resources.getInteger(android.R.integer.config_shortAnimTime).toLong() + addUpdateListener { invalidate() } + } + + /** The focus style the state animator is for; null before the first. */ + private var focusStyle: FocusStyle? = null + /** The user holds this tile, to move it. */ var held = false set(value) { @@ -50,7 +78,7 @@ internal class AppTileView( field = value val zoom = when { value -> HELD_ZOOM - isFocused -> FOCUSED_ZOOM // as the focus animator leaves it (home_tile_focus.xml) + isFocused -> focusedZoom() // as the focus animator leaves it else -> 1f } animate().scaleX(zoom).scaleY(zoom) @@ -71,7 +99,25 @@ internal class AppTileView( isFocusableInTouchMode = true isClickable = true contentDescription = app.label - stateListAnimator = AnimatorInflater.loadStateListAnimator(context, R.animator.home_tile_focus) + outlineProvider = paints.tileOutline + restyle() + } + + /** + * Takes the style [paints] have now: a new focus style swaps the state animator, which zooms + * and lifts the tile, and puts it at once where the new one has it; new corners give the + * shadow a new outline. Then redraws. + */ + fun restyle() { + val style = paints.focusStyle + if (style != focusStyle) { + focusStyle = style + translationZ = 0f // the frame's animator doesn't lift, so it wouldn't bring the tile down + stateListAnimator = AnimatorInflater.loadStateListAnimator(context, focusAnimator(style)) + jumpDrawablesToCurrentState() + } + invalidateOutline() + invalidate() } override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { @@ -81,6 +127,9 @@ internal class AppTileView( bounds.set(0f, 0f, w.toFloat(), h.toFloat()) val inset = paints.focusFrame.strokeWidth / 2 frameBounds.set(inset, inset, w - inset, h - inset) + name = TextUtils.ellipsize(app.label, paints.namePaint, w.toFloat(), TextUtils.TruncateAt.END).toString() + nameLeft = (w - paints.namePaint.measureText(name)) / 2 + invalidateOutline() } override fun onDraw(canvas: Canvas) { @@ -94,21 +143,71 @@ internal class AppTileView( canvas.drawRoundRect(bounds, radius, radius, imagePaint) } } - if (isFocused || held) { - val frame = if (held) paints.heldFrame else paints.focusFrame + val frame = when { + held -> paints.heldFrame + isFocused && paints.focusStyle == FocusStyle.FRAME -> paints.focusFrame + else -> null + } + if (frame != null) { // The line's middle runs half its width inside the edge, its corners as much tighter. val frameRadius = (radius - frame.strokeWidth / 2).coerceAtLeast(0f) canvas.drawRoundRect(frameBounds, frameRadius, frameRadius, frame) } + if (paints.showsNames) drawName(canvas) + } + + /** + * The app's name below the tile, as faded in as the focus has it, with its outline; a hidden + * app's as dimmed as its tile. + */ + private fun drawName(canvas: Canvas) { + val shown = when { + nameFade.isRunning -> nameFade.animatedFraction + isFocused -> 1f + else -> 0f + } + if (shown <= 0f) return + val paint = paints.namePaint + val outline = paints.nameOutline + val alpha = (shown * if (hidden) TilePaints.HIDDEN_ALPHA else TilePaints.OPAQUE).toInt() + val baseline = (height + paints.nameGap - paints.nameAscent).toFloat() + outline.under(paint) { + paint.alpha = Color.alpha(outline.color) * alpha / TilePaints.OPAQUE + canvas.drawText(name, nameLeft, baseline, paint) + } + paint.alpha = alpha + canvas.drawText(name, nameLeft, baseline, paint) + paint.alpha = TilePaints.OPAQUE } override fun onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect?) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect) + if (paints.showsNames) { + // Back the way it came if it's still fading, else in from nothing or out from whole. + if (nameFade.isRunning || !gainFocus) nameFade.reverse() else nameFade.start() + } invalidate() } - private companion object { - const val FOCUSED_ZOOM = 1.1f + private fun focusedZoom() = when (paints.focusStyle) { + FocusStyle.FRAME -> FRAME_ZOOM + FocusStyle.LIFT -> LIFT_ZOOM + } + + private fun focusAnimator(style: FocusStyle) = when (style) { + FocusStyle.FRAME -> R.animator.home_tile_focus + FocusStyle.LIFT -> R.animator.home_tile_lift + } + + companion object { + /** The focused tile's zoom, framed (home_tile_focus.xml) and lifted (home_tile_lift.xml). */ + const val FRAME_ZOOM = 1.1f + const val LIFT_ZOOM = 1.15f + + /** A held tile's zoom, while the user arranges apps. */ const val HELD_ZOOM = 1.15f + + /** The most a tile grows, framed, lifted or held. */ + const val LARGEST_ZOOM = HELD_ZOOM } } diff --git a/feature/home/src/main/java/com/luncher/launcher/home/AppTilesView.kt b/feature/home/src/main/java/com/luncher/launcher/home/AppTilesView.kt index 57878c3f..cf2a2b3e 100644 --- a/feature/home/src/main/java/com/luncher/launcher/home/AppTilesView.kt +++ b/feature/home/src/main/java/com/luncher/launcher/home/AppTilesView.kt @@ -12,6 +12,7 @@ import android.util.AttributeSet import android.view.View import android.view.ViewGroup import android.widget.Scroller +import com.luncher.domain.appearance.AppName import com.luncher.domain.appearance.TileGeometry import com.luncher.domain.appearance.TileStyle import com.luncher.domain.layout.Direction @@ -34,6 +35,10 @@ import com.luncher.launcher.ui.R as UiR * While the user arranges apps ([shownCount] set), the tiles after the shown ones are the hidden * apps, on a shelf below a label ([ShelfLayout]); with none, an empty slot shows where hiding is. * + * While names show, the focused tile draws its app's name below itself, in the room the layout + * leaves below each row; this view doesn't clip its tiles (clipChildren, in home_activity.xml), + * so the name and a zoomed or lifted tile's shadow show past a tile's bounds. + * * D-pad focus goes where the layout's [TileFocus] says, a rule of :domain: Android's own search * would go to the nearest view that way anywhere, past the end of a row to another row or to the * top bar, and pick one of two tiles as near by itself. Only Up out of the first row is left to @@ -45,33 +50,37 @@ internal class AppTilesView(context: Context, attrs: AttributeSet?) : ViewGroup( private val pixelsPerDp = resources.displayMetrics.density private val scroller = Scroller(context) + /** What every tile draws with: give it to each new tile. */ + val paints = TilePaints(context) + /** * Where the tiles go and how big they are, from the home screen's appearance. Its default is - * the home screen without settings. + * the home screen without settings. Whether the focused tile's name shows is part of it: the + * rows leave the name room ([TilePaints.nameHeight]), so it changes the layout. */ var tileGeometry: TileGeometry = TileGeometry() set(value) { if (field == value) return field = value - layouts = TileLayouts(value, pixelsPerDp) + layouts = TileLayouts(value, pixelsPerDp, paints.nameHeight) + paints.showsNames = value.appName == AppName.WHEN_FOCUSED + for (i in 0 until childCount) getChildAt(i).invalidate() requestLayout() } - private var layouts = TileLayouts(tileGeometry, pixelsPerDp) - - /** What every tile draws with: give it to each new tile. */ - val paints = TilePaints(context) + private var layouts = TileLayouts(tileGeometry, pixelsPerDp, paints.nameHeight) /** * How the tiles are drawn, from the home screen's appearance: a new one changes [paints] and - * redraws the tiles, with the places and images they have. + * restyles the tiles, with the places and images they have. */ var tileStyle: TileStyle = TileStyle() set(value) { if (field == value) return field = value paints.corners = value.corners - for (i in 0 until childCount) getChildAt(i).invalidate() + paints.focusStyle = value.focus + for (i in 0 until childCount) (getChildAt(i) as AppTileView).restyle() } /** @@ -216,8 +225,9 @@ internal class AppTilesView(context: Context, attrs: AttributeSet?) : ViewGroup( private fun targetScrollX(child: View, from: Int) = scrollToShow(child.left - paddingLeft, child.right + paddingRight, from, width, maxScrollX()) + // The focused tile's name too, below it, while names show. private fun targetScrollY(child: View, from: Int) = - scrollToShow(child.top - paddingTop, child.bottom + paddingBottom, from, height, maxScrollY()) + scrollToShow(child.top - paddingTop, child.bottom + layouts.nameRoom + paddingBottom, from, height, maxScrollY()) /** The scroll position nearest to [from] that shows [start] to [end] within [size], if it fits. */ private fun scrollToShow(start: Int, end: Int, from: Int, size: Int, max: Int): Int { diff --git a/feature/home/src/main/java/com/luncher/launcher/home/TilePaints.kt b/feature/home/src/main/java/com/luncher/launcher/home/TilePaints.kt index c285f0c1..8af1dc99 100644 --- a/feature/home/src/main/java/com/luncher/launcher/home/TilePaints.kt +++ b/feature/home/src/main/java/com/luncher/launcher/home/TilePaints.kt @@ -1,15 +1,25 @@ package com.luncher.launcher.home import android.content.Context +import android.graphics.Outline import android.graphics.Paint +import android.text.TextPaint +import android.view.View +import android.view.ViewOutlineProvider +import com.luncher.domain.appearance.AppName import com.luncher.domain.appearance.Corners +import com.luncher.domain.appearance.FocusStyle +import com.luncher.domain.appearance.TileGeometry import com.luncher.domain.appearance.TileStyle +import com.luncher.launcher.ui.TileName +import com.luncher.launcher.ui.WallpaperOutline import com.luncher.launcher.ui.color import com.luncher.launcher.ui.R as UiR /** * What every tile draws with besides its own image: the focus frame, the held frame, the dimming - * of a hidden app, and the corners from the home screen's [TileStyle]. + * of a hidden app, the focused app's name, the corners and the focus style from the home screen's + * [TileStyle], and the outline a lifted tile's shadow takes. * [AppTilesView] holds the one set its tiles share, so a style change updates it once and redraws, * without touching each tile's own state. */ @@ -27,6 +37,46 @@ internal class TilePaints(context: Context) { /** The tiles' corners, from the home screen's style. */ var corners: Corners = TileStyle().corners + /** How the focused tile stands out, from the home screen's style. */ + var focusStyle: FocusStyle = TileStyle().focus + + /** + * Whether the focused tile shows its app's name below it, from the home screen's geometry. It + * starts as the default geometry has it, as [AppTilesView]'s does: the view sets it only when + * its geometry changes, so a different start would leave the rows room for names never drawn. + */ + var showsNames = TileGeometry().appName == AppName.WHEN_FOCUSED + + /** + * The app's name below its tile, as :ui's [TileName] has it, so the appearance editor's preview + * leaves it the same room; on the wallpaper, with [nameOutline]'s edge, as the top bar's texts. + */ + private val name = TileName(context) + val namePaint: TextPaint = name.paint + val nameOutline = WallpaperOutline(context) + + /** The name's ascent, and the gap between a tile's bottom edge and the name's top, before the zoom. */ + val nameAscent: Int = name.ascent + val nameGap: Int = name.gap + + /** + * How far below a tile its name reaches, the gap included, at the most a tile is zoomed + * ([AppTileView.LARGEST_ZOOM]): the room the rows leave below each tile while names show + * ([com.luncher.domain.layout.TileLayouts]). What the zoom adds above the name, the gap + * between the rows already has room for. + */ + val nameHeight: Int = name.room(AppTileView.LARGEST_ZOOM) + + /** + * The shape a lifted tile's shadow takes: the tile's, with its corners. Shared by every tile; + * Android asks it again when a tile's size changes, or the tile asks with a new radius. + */ + val tileOutline = object : ViewOutlineProvider() { + override fun getOutline(view: View, outline: Outline) { + outline.setRoundRect(0, 0, view.width, view.height, cornerRadius(view.height)) + } + } + private val pixelsPerDp = context.resources.displayMetrics.density /** The radius of the corners of a tile [tileHeight] pixels high; 0 draws it square. */ diff --git a/feature/home/src/main/res/animator/home_tile_lift.xml b/feature/home/src/main/res/animator/home_tile_lift.xml new file mode 100644 index 00000000..b240db26 --- /dev/null +++ b/feature/home/src/main/res/animator/home_tile_lift.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + diff --git a/feature/home/src/main/res/values/dimens.xml b/feature/home/src/main/res/values/dimens.xml index 2ee5a8c9..8e55ff8a 100644 --- a/feature/home/src/main/res/values/dimens.xml +++ b/feature/home/src/main/res/values/dimens.xml @@ -6,6 +6,8 @@ 24dp 3dp + + 12dp 32sp 18sp diff --git a/feature/home/src/test/java/com/luncher/launcher/home/HomeAppearanceTest.kt b/feature/home/src/test/java/com/luncher/launcher/home/HomeAppearanceTest.kt index 2bc964ee..2a770fa0 100644 --- a/feature/home/src/test/java/com/luncher/launcher/home/HomeAppearanceTest.kt +++ b/feature/home/src/test/java/com/luncher/launcher/home/HomeAppearanceTest.kt @@ -2,11 +2,16 @@ package com.luncher.launcher.home import android.graphics.Bitmap import android.graphics.Canvas +import android.graphics.Outline +import android.graphics.Paint +import android.graphics.Rect import android.os.Looper import android.view.View +import com.luncher.domain.appearance.AppName import com.luncher.domain.appearance.Appearance import com.luncher.domain.appearance.Corners import com.luncher.domain.appearance.FakeAppearanceSettings +import com.luncher.domain.appearance.FocusStyle import com.luncher.domain.appearance.HorizontalAlignment import com.luncher.domain.appearance.Side import com.luncher.domain.appearance.TileGeometry @@ -149,6 +154,155 @@ class HomeAppearanceTest { assertEquals(tile.height / 2f, activity.grid().paints.cornerRadius(tile.height)) } + @Test + fun `lifts the focused tile without a frame as the appearance says, the others staying down`() { + appearance.appearance = Appearance(tileStyle = TileStyle(focus = FocusStyle.LIFT)) + + val activity = start().get() + idle() // the focus animator's frames + + val tiles = activity.tiles() + val lift = activity.resources.getDimension(R.dimen.home_tile_lift) + assertEquals(lift, tiles[0].translationZ) + assertEquals(AppTileView.LIFT_ZOOM, tiles[0].scaleX) + assertEquals(0f, tiles[1].translationZ) + assertEquals(1f, tiles[1].scaleX) + assertSame(activity.grid().paints.tileOutline, tiles[0].outlineProvider) + } + + // The view sets the paints' names only when its geometry changes: before that, they must agree. + @Test + fun `the tiles show names as their first geometry says, before any change`() { + val tiles = AppTilesView(RuntimeEnvironment.getApplication(), null) + + assertEquals(tiles.tileGeometry.appName == AppName.WHEN_FOCUSED, tiles.paints.showsNames) + } + + // While arranging, a hidden app's tile on the shelf is dimmed: its name with it. + @Test + fun `a hidden app's name is drawn as dimmed as its tile`() { + appearance.appearance = Appearance(tileGeometry = TileGeometry(appName = AppName.WHEN_FOCUSED)) + val tile = start().get().tiles()[1] + tile.requestFocus() + shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(1)) // the name's fade + + assertEquals(TilePaints.OPAQUE, nameAlpha(tile)) + tile.hidden = true + assertEquals(TilePaints.HIDDEN_ALPHA, nameAlpha(tile)) + } + + /** The alpha [tile] draws its name with: the last text it draws, its outline before it. */ + private fun nameAlpha(tile: AppTileView): Int { + var alpha = -1 + val canvas = object : Canvas(Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)) { + override fun drawText(text: String, x: Float, y: Float, paint: Paint) { + alpha = paint.alpha + } + } + tile.draw(canvas) + return alpha + } + + // The shadow is cast by the outline: the tile's shape, its round ends too. + @Test + fun `the lifted tile's shadow has the tiles' corners`() { + appearance.appearance = Appearance(tileStyle = TileStyle(Corners.Pill, FocusStyle.LIFT)) + + val activity = start().get() + + val tile = activity.tiles().first() + val outline = Outline() + tile.outlineProvider.getOutline(tile, outline) + assertEquals(tile.height / 2f, outline.radius) + val bounds = Rect() + assertTrue(outline.getRect(bounds)) + assertEquals(Rect(0, 0, tile.width, tile.height), bounds) + } + + // A new focus style only swaps the tiles' animators: the tile is framed and down again at once. + @Test + fun `a new focus style lays nothing out again, and puts the focused tile down`() { + appearance.appearance = Appearance(tileStyle = TileStyle(focus = FocusStyle.LIFT)) + val activity = start().get() + idle() + + appearance.write(Appearance()) + + val tile = activity.tiles().first() + assertFalse(activity.grid().isLayoutRequested) + assertEquals(FocusStyle.FRAME, activity.grid().paints.focusStyle) + assertEquals(0f, tile.translationZ) + assertEquals(AppTileView.FRAME_ZOOM, tile.scaleX) + } + + // The held tile keeps its white frame and its zoom, lifted too, so it stands out from one only focused. + @Test + fun `lifted, a held tile still has its zoom`() { + appearance.appearance = Appearance(tileStyle = TileStyle(focus = FocusStyle.LIFT)) + val activity = start().get() + val tile = activity.tiles().first() + + tile.performLongClick() + shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(1)) + + assertTrue(tile.held) + assertEquals(AppTileView.HELD_ZOOM, tile.scaleX) + } + + @Test + fun `with the app names shown, the rows leave room below each for the focused tile's name`() { + val withNames = Appearance(topLeftTiles.copy(appName = AppName.WHEN_FOCUSED)) + appearance.appearance = Appearance(topLeftTiles) + val activity = start().get() + idle() + val tiles = activity.tiles() + val rowsApart = tiles[5].top - tiles[0].top + + appearance.write(withNames) + idle() + + val paints = activity.grid().paints + assertTrue(paints.showsNames) + assertTrue("${paints.nameHeight} px for a name", paints.nameHeight > 0) + assertEquals(rowsApart + paints.nameHeight, tiles[5].top - tiles[0].top) + assertSame(tiles[0], tiles[0].focusSearch(View.FOCUS_LEFT)) // the moves the same + assertSame(tiles[5], tiles[0].focusSearch(View.FOCUS_DOWN)) + } + + // At the bottom, the last row is the room for a name higher, so the name stays on the screen. + @Test + fun `with the app names shown at the bottom, the last row leaves room for its name below it`() { + appearance.appearance = Appearance(TileGeometry(verticalAlignment = VerticalAlignment.BOTTOM, appName = AppName.WHEN_FOCUSED)) + + val activity = start().get() + + val grid = activity.grid() + assertEquals(grid.height - grid.paddingBottom - grid.paints.nameHeight, activity.tiles().last().bottom) + } + + // Rows that don't fit scroll: a tile focused at the bottom scrolls up until its name shows too. + @Test + fun `focusing a tile at the bottom scrolls its name into sight`() { + val application = RuntimeEnvironment.getApplication() as HomeTestApplication + application.graph = object : TestHomeGraph(application) { + override val installedApps = FakeInstalledApps((1..25).map { app("app%02d".format(it)) }) + override val appearanceSettings = FakeAppearanceSettings(Appearance(topLeftTiles.copy(appName = AppName.WHEN_FOCUSED))) + } + val activity = start().get() + idle() + val grid = activity.grid() + val last = activity.tiles().last() + + last.requestFocus() + // A layout pass scrolls to the focused tile at once, where the focus move's scroll is + // animated by drawn frames, which Robolectric doesn't draw. + grid.requestLayout() + idle() + + assertTrue(grid.scrollY > 0) + assertEquals(grid.height - grid.paddingBottom, last.bottom + grid.paints.nameHeight - grid.scrollY) + } + @Test fun `arranges the top bar as the appearance says`() { appearance.appearance = Appearance(topBar = TopBarAppearance(clockSide = Side.RIGHT, timeSide = Side.RIGHT)) @@ -263,6 +417,13 @@ class HomeAppearanceTest { assertEquals(0, appearance.listenerCount) } + // The focused tile lifted, its name below it: neither allocates either. + @Test + @GraphicsMode(GraphicsMode.Mode.NATIVE) + fun `drawing the tiles allocates nothing lifted, with the focused tile's name`() { + drawingTheTilesAllocatesNothing(Appearance(TileGeometry(appName = AppName.WHEN_FOCUSED), TileStyle(Corners.Radius(16), FocusStyle.LIFT))) + } + // Rule 5 (docs/ARCHITECTURE.md): drawing allocates nothing, with rounded corners too. Counts // what this thread allocates drawing the tiles, the focused one's frame included, after a new // style, which itself may allocate (a key that changes a stored value). Native graphics, since @@ -270,9 +431,15 @@ class HomeAppearanceTest { @Test @GraphicsMode(GraphicsMode.Mode.NATIVE) fun `drawing the tiles allocates nothing after a new tile style`() { + drawingTheTilesAllocatesNothing(Appearance(tileStyle = TileStyle(Corners.Radius(16)))) + } + + /** Draws the tiles many times after [changed] is written, and fails if a draw allocates. */ + private fun drawingTheTilesAllocatesNothing(changed: Appearance) { val activity = start().get() idle() - appearance.write(Appearance(tileStyle = TileStyle(Corners.Radius(16)))) + appearance.write(changed) + shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(1)) // a new layout, the animators val grid = activity.grid() val canvas = Canvas(Bitmap.createBitmap(grid.width, grid.height, Bitmap.Config.ARGB_8888)) val threads = ManagementFactory.getThreadMXBean() as com.sun.management.ThreadMXBean diff --git a/feature/home/src/test/java/com/luncher/launcher/home/HomeLayoutTest.kt b/feature/home/src/test/java/com/luncher/launcher/home/HomeLayoutTest.kt index c96dec76..eae6f74a 100644 --- a/feature/home/src/test/java/com/luncher/launcher/home/HomeLayoutTest.kt +++ b/feature/home/src/test/java/com/luncher/launcher/home/HomeLayoutTest.kt @@ -8,10 +8,12 @@ import android.view.KeyEvent import android.view.View import android.view.ViewConfiguration import android.widget.TextView +import com.luncher.domain.appearance.AppName import com.luncher.domain.appearance.Appearance import com.luncher.domain.appearance.Background import com.luncher.domain.appearance.Corners import com.luncher.domain.appearance.FakeAppearanceSettings +import com.luncher.domain.appearance.FocusStyle import com.luncher.domain.appearance.HorizontalAlignment import com.luncher.domain.appearance.Side import com.luncher.domain.appearance.TileGeometry @@ -154,6 +156,14 @@ class HomeLayoutTest(private val screen: TvScreen) { for (a in tiles) for (b in tiles - a) { assertApart(screen, "${a.app.label} zoomed and ${b.app.label}", bounds(a, HELD_ZOOM), bounds(b)) } + // Its name below it, as far as it can reach zoomed, clear of the others too. + val paints = findViewById(R.id.home_apps).paints + if (!paints.showsNames) return + for (a in tiles) { + val zoomed = bounds(a, HELD_ZOOM) + val name = RectF(zoomed.left, zoomed.bottom, zoomed.right, zoomed.bottom + paints.nameHeight) + for (b in tiles - a) assertApart(screen, "${a.app.label}'s name and ${b.app.label}", name, bounds(b)) + } } @Test @@ -182,6 +192,21 @@ class HomeLayoutTest(private val screen: TvScreen) { `the home screen fits`() } + // The focused tile lifted, its name below it: the rows further apart. + @Test + fun `the home screen fits with the focused tile lifted and its name shown`() { + appearance.appearance = Appearance(TileGeometry(appName = AppName.WHEN_FOCUSED), TileStyle(focus = FocusStyle.LIFT)) + + `the home screen fits`() + } + + @Test + fun `arrange mode fits with the focused tile's name shown`() { + appearance.appearance = Appearance(TileGeometry(appName = AppName.WHEN_FOCUSED), TileStyle(focus = FocusStyle.LIFT)) + + `arrange mode fits`() + } + @Test fun `arrange mode fits`() { val activity = start() diff --git a/feature/home/src/test/java/com/luncher/launcher/home/HomeScreenshotTest.kt b/feature/home/src/test/java/com/luncher/launcher/home/HomeScreenshotTest.kt index b5eb718e..dac62ea8 100644 --- a/feature/home/src/test/java/com/luncher/launcher/home/HomeScreenshotTest.kt +++ b/feature/home/src/test/java/com/luncher/launcher/home/HomeScreenshotTest.kt @@ -13,10 +13,12 @@ import android.view.View import com.github.takahirom.roborazzi.ExperimentalRoborazziApi import com.github.takahirom.roborazzi.captureRoboImage import com.github.takahirom.roborazzi.captureScreenRoboImage +import com.luncher.domain.appearance.AppName import com.luncher.domain.appearance.Appearance import com.luncher.domain.appearance.Background import com.luncher.domain.appearance.Corners import com.luncher.domain.appearance.FakeAppearanceSettings +import com.luncher.domain.appearance.FocusStyle import com.luncher.domain.appearance.HorizontalAlignment import com.luncher.domain.appearance.Side import com.luncher.domain.appearance.TileGeometry @@ -204,6 +206,35 @@ class HomeScreenshotTest { start(appearance = appearance).window.decorView.captureRoboImage("src/test/screenshots/home/home_screen_appearance.png") } + // The tvOS-like look: the focused tile lifted, without a frame, its shadow under it, and its + // app's name below it, the rows further apart. + @Test + fun homeScreenLiftedWithTheAppName() { + val appearance = Appearance(TileGeometry(appName = AppName.WHEN_FOCUSED), TileStyle(focus = FocusStyle.LIFT)) + + start(appearance = appearance).window.decorView.captureRoboImage("src/test/screenshots/home/home_screen_lifted_name.png") + } + + // The same with the long name focused: cut to the tile's width. + @Test + fun homeScreenWithALongAppName() { + val activity = start(appearance = Appearance(TileGeometry(appName = AppName.WHEN_FOCUSED))) + val tiles = activity.findViewById(R.id.home_apps) + tiles.getChildAt(tiles.childCount - 1).requestFocus() + shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(1)) // the zoom and the name's fade + + activity.window.decorView.captureRoboImage("src/test/screenshots/home/home_screen_long_name.png") + } + + // Holding Music, lifted: the held tile's white frame tells it from one only focused. + @Test + fun arrangingLifted() { + val activity = start(hidden = listOf("weather"), appearance = Appearance(TileGeometry(appName = AppName.WHEN_FOCUSED), TileStyle(focus = FocusStyle.LIFT))) + activity.arrange("Music") + + activity.window.decorView.captureRoboImage("src/test/screenshots/home/home_arranging_lifted.png") + } + // The date hidden: the time alone, the tiles where they are with both. @Test fun homeScreenWithoutTheDate() { diff --git a/feature/home/src/test/screenshots/home/home_arranging_lifted.png b/feature/home/src/test/screenshots/home/home_arranging_lifted.png new file mode 100644 index 00000000..c35b62df Binary files /dev/null and b/feature/home/src/test/screenshots/home/home_arranging_lifted.png differ diff --git a/feature/home/src/test/screenshots/home/home_screen_lifted_name.png b/feature/home/src/test/screenshots/home/home_screen_lifted_name.png new file mode 100644 index 00000000..1427f829 Binary files /dev/null and b/feature/home/src/test/screenshots/home/home_screen_lifted_name.png differ diff --git a/feature/home/src/test/screenshots/home/home_screen_long_name.png b/feature/home/src/test/screenshots/home/home_screen_long_name.png new file mode 100644 index 00000000..aa05b785 Binary files /dev/null and b/feature/home/src/test/screenshots/home/home_screen_long_name.png differ diff --git a/feature/settings/README.md b/feature/settings/README.md index f40c99c5..8bf61cd0 100644 --- a/feature/settings/README.md +++ b/feature/settings/README.md @@ -175,19 +175,22 @@ they scroll when they're taller than the screen. **The preview** draws outlined tiles filled with white at 20 % (`settings_preview_tile`, in place of the banners) on the home screen's background (the wallpaper's picture, drawn at the sample screen's -size in the background's style, or the plain color), the first one framed and zoomed as focused, and -plain blocks for the time, the date and the settings gear: no names, images or text. It's a made-up -sample, not the user's apps: a screen 960 dp wide, of the TV's shape (`screenSize`, which the -wallpaper is drawn at: 540 dp tall on a 16:9 TV), so a picture is cut as on the home screen, with -seven tiles, a full row and a short one, so that every option's values look different. The width -stays on every shape, so a row holds as many tiles. It lays them out with `TileLayouts` and -`topBarLayout` at its own density (its pixels per sample dp), so every dp value scales with it and -it can't disagree with the home screen. What's on the wallpaper has the home screen's edge -(`WallpaperOutline`, [`feature/home/README.md`](../home/README.md#the-top-bar)), so the illustration -reads on a white picture too: the blocks and the tiles' outlines, at the sample's scale but a pixel -at least (there the tiles' fill doesn't show, their outlines do); not the focus frame, as on the -home screen. A new shape gets it too: `AppearancePreviewViewTest` fails for a light shape without -it. It isn't focusable. +size in the background's style, or the plain color), the first one zoomed as focused, framed or +lifted (a few dark, offset rounded rectangles stand for the shadow), and plain blocks for the time, +the date, the settings gear and, while the app name shows, the focused tile's name: no images or +text. It's a made-up sample, not the user's apps: a screen 960 dp wide, of the TV's shape +(`screenSize`, which the wallpaper is drawn at: 540 dp tall on a 16:9 TV), so a picture is cut as on +the home screen, with seven tiles, a full row and a short one, so that every option's values look +different. The width stays on every shape, so a row holds as many tiles. It lays them out with +`TileLayouts` and `topBarLayout` at its own density (its pixels per sample dp), so every dp value +scales with it and it can't disagree with the home screen. The room the rows leave the focused +tile's name is measured as the home screen's (`:ui`'s `TileName`, at the largest zoom), so it +follows the device's font size and the language's font there too. What's on the wallpaper has the +home screen's edge (`WallpaperOutline`, [`feature/home/README.md`](../home/README.md#the-top-bar)), +so the illustration reads on a white picture too: the blocks and the tiles' outlines, at the +sample's scale but a pixel at least (there the tiles' fill doesn't show, their outlines do); not the +focus frame, as on the home screen. A new shape gets it too: `AppearancePreviewViewTest` fails for a +light shape without it. It isn't focusable. To add an option: [`ARCHITECTURE.md`](../../docs/ARCHITECTURE.md#appearance), "Adding an aspect"; its labels go in `optionLabel` and `optionValue` (`OptionLabels.kt`), in every translation. diff --git a/feature/settings/src/main/java/com/luncher/launcher/settings/AppearancePreviewView.kt b/feature/settings/src/main/java/com/luncher/launcher/settings/AppearancePreviewView.kt index 0ac158c5..39e55608 100644 --- a/feature/settings/src/main/java/com/luncher/launcher/settings/AppearancePreviewView.kt +++ b/feature/settings/src/main/java/com/luncher/launcher/settings/AppearancePreviewView.kt @@ -3,7 +3,9 @@ package com.luncher.launcher.settings import android.content.Context import android.graphics.Bitmap import android.graphics.Canvas +import android.graphics.Color import android.graphics.Paint +import android.graphics.Path import android.graphics.RectF import android.os.Handler import android.os.Looper @@ -11,6 +13,7 @@ import android.util.AttributeSet import android.view.View import com.luncher.domain.appearance.Appearance import com.luncher.domain.appearance.Background +import com.luncher.domain.appearance.FocusStyle import com.luncher.domain.jobs.JobPriority import com.luncher.domain.jobs.Jobs import com.luncher.domain.jobs.LatestRequest @@ -21,6 +24,7 @@ import com.luncher.domain.pictures.PictureImages import com.luncher.domain.wallpaper.Wallpaper import com.luncher.domain.wallpaper.WallpaperDrawing import com.luncher.domain.wallpaper.wallpaperDrawing +import com.luncher.launcher.ui.TileName import com.luncher.launcher.ui.WallpaperOutline import com.luncher.launcher.ui.color import com.luncher.launcher.ui.screenSize @@ -34,8 +38,10 @@ import kotlin.math.roundToInt * images or text. Not the real home screen: a made-up one, [SCREEN_WIDTH] dp wide and of the * TV's shape ([screenSize], as the wallpaper is drawn: 540 dp tall on a 16:9 TV), with [TILES] * tiles, chosen so every option's values look different: a full row and a short one, so left and - * right differ, and the first tile focused, so the focus frame shows. The width stays, so a row - * holds as many tiles on every shape. + * right differ, and the first tile focused, so the focus style shows: framed, or lifted with a + * shadow (a few dark, offset round rectangles around it, not a blur), and with the app name shown, a block + * below it, in the room the rows leave it. The width stays, so a row holds as many tiles on every + * shape. * * It's laid out by the same rules as the home screen, [TileLayouts] and [topBarLayout], at its own * density (its pixels per sample dp), so every dp value scales with it, and it can't disagree with @@ -48,8 +54,9 @@ import kotlin.math.roundToInt * Either is kept, and not drawn again, while the background and the size stay the same. * * What's on the wallpaper has the home screen's edge ([WallpaperOutline]), so the illustration - * reads on a white picture as the home screen does: the blocks and the tiles' outlines, at the - * sample's scale, a pixel at least; not the focus frame, which the home screen's has none of. + * reads on a white picture as the home screen does: the blocks (the name's too) and the tiles' + * outlines, at the sample's scale, a pixel at least; not the focus frame, which the home screen's + * has none of. */ internal class AppearancePreviewView(context: Context, attrs: AttributeSet?) : View(context, attrs) { @@ -146,6 +153,21 @@ internal class AppearancePreviewView(context: Context, attrs: AttributeSet?) : V private val tiles = Array(TILES) { RectF() } private var tileHeight = 0 private var tileRadius = 0f + + /** The focused tile's zoom and whether it's lifted, from the style. */ + private var focusZoom = FRAME_ZOOM + private var lifted = false + + /** + * A lifted tile's shadow, layer by layer, each wider and lower, less the tile: the tiles' fill + * is see-through, and the shadow under it would darken the tile it lifts. Made anew with the + * tiles' places and corners, in place. + */ + private val shadows = Array(SHADOW_LAYERS) { Path().apply { fillType = Path.FillType.EVEN_ODD } } + private val shadow = RectF() + + /** The app name's block, below the focused tile. */ + private val name = RectF() private val time = RectF() private val date = RectF() private val gear = RectF() @@ -155,9 +177,25 @@ internal class AppearancePreviewView(context: Context, attrs: AttributeSet?) : V private val tileFillPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = context.color(R.color.settings_preview_tile) } private val tilePaint = stroke(context.color(UiR.color.text_secondary)) private val focusPaint = stroke(context.color(UiR.color.accent)) + private val shadowPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = Color.argb(SHADOW_ALPHA, 0, 0, 0) } private val primaryPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = context.color(UiR.color.text_primary) } private val secondaryPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = context.color(UiR.color.text_secondary) } private val outline = WallpaperOutline(context) + + /** + * The room below each row for the focused tile's name, and the gap above its block, in dp: + * measured as the home screen measures them (:ui's [TileName]), at the largest zoom the sample + * draws, the home screen's largest too. So the rows here are as far apart as there, with the + * device's font size and the language's font. + */ + private val nameRoom: Float + private val nameGap: Float + + init { + val tileName = TileName(context) + nameRoom = tileName.roomDp(LIFT_ZOOM) + nameGap = tileName.gapDp + } private val blockOutlinePaint = stroke(outline.color).apply { strokeJoin = Paint.Join.ROUND } private val tileOutlinePaint = stroke(outline.color) @@ -203,12 +241,16 @@ internal class AppearancePreviewView(context: Context, attrs: AttributeSet?) : V canvas.drawRoundRect(tiles[i], tileRadius, tileRadius, tileFillPaint) canvas.drawRoundRect(tiles[i], tileRadius, tileRadius, tilePaint) } - // Zoomed, as the home screen's focused tile. + // Zoomed, as the home screen's focused tile, its name with it. val focused = tiles[FOCUSED] canvas.save() - canvas.scale(FOCUSED_ZOOM, FOCUSED_ZOOM, focused.centerX(), focused.centerY()) + canvas.scale(focusZoom, focusZoom, focused.centerX(), focused.centerY()) + if (lifted) { + for (layer in shadows) canvas.drawPath(layer, shadowPaint) + } canvas.drawRoundRect(focused, tileRadius, tileRadius, tileFillPaint) - canvas.drawRoundRect(focused, tileRadius, tileRadius, focusPaint) + if (!lifted) canvas.drawRoundRect(focused, tileRadius, tileRadius, focusPaint) + drawBlock(canvas, name, primaryPaint) canvas.restore() } @@ -221,8 +263,8 @@ internal class AppearancePreviewView(context: Context, attrs: AttributeSet?) : V private fun placeTiles() { if (scale == 0f) return - val grid = TileLayouts(appearance.tileGeometry, scale) - .tiles(TILES, (TILES_WIDTH * scale).roundToInt(), (tilesHeight * scale).roundToInt()) + val layouts = TileLayouts(appearance.tileGeometry, scale, nameHeight = (nameRoom * scale).roundToInt()) + val grid = layouts.tiles(TILES, (TILES_WIDTH * scale).roundToInt(), (tilesHeight * scale).roundToInt()) tileHeight = grid.tileHeight val left = screen.left + PADDING_HORIZONTAL * scale val top = screen.top + TILES_TOP * scale @@ -231,10 +273,31 @@ internal class AppearancePreviewView(context: Context, attrs: AttributeSet?) : V val y = top + grid.top(i) tiles[i].set(x, y, x + grid.tileWidth, y + grid.tileHeight) } + val focused = tiles[FOCUSED] + if (layouts.nameRoom > 0) { + val nameLeft = focused.centerX() - NAME_WIDTH * scale / 2 + val nameTop = focused.bottom + nameGap * scale + name.set(nameLeft, nameTop, nameLeft + NAME_WIDTH * scale, nameTop + NAME_HEIGHT * scale) + } else { + name.setEmpty() + } } private fun styleTiles() { - tileRadius = appearance.tileStyle.corners.pixels(tileHeight, scale) + val style = appearance.tileStyle + tileRadius = style.corners.pixels(tileHeight, scale) + lifted = style.focus == FocusStyle.LIFT + focusZoom = if (lifted) LIFT_ZOOM else FRAME_ZOOM + val focused = tiles[FOCUSED] + for (i in shadows.indices) { + val spread = (i + 1) * SHADOW_SPREAD * scale + shadow.set(focused) + shadow.inset(-spread, -spread) + shadow.offset(0f, (i + 1) * SHADOW_DROP * scale) + shadows[i].reset() + shadows[i].addRoundRect(shadow, tileRadius + spread, tileRadius + spread, Path.Direction.CW) + shadows[i].addRoundRect(focused, tileRadius, tileRadius, Path.Direction.CW) + } } /** @@ -319,7 +382,17 @@ internal class AppearancePreviewView(context: Context, attrs: AttributeSet?) : V const val TILES_WIDTH = SCREEN_WIDTH - 2 * PADDING_HORIZONTAL const val TILES = 7 const val FOCUSED = 0 - const val FOCUSED_ZOOM = 1.1f + /** The focused tile's zoom, framed or lifted (feature/home's AppTileView); lifted is the largest. */ + const val FRAME_ZOOM = 1.1f + const val LIFT_ZOOM = 1.15f + /** A lifted tile's shadow: its layers, how much wider and lower each is than the last, and each one's darkness. */ + const val SHADOW_LAYERS = 3 + const val SHADOW_SPREAD = 2 + const val SHADOW_DROP = 3 + const val SHADOW_ALPHA = 40 + /** The name's block, as wide as a short name. */ + const val NAME_WIDTH = 64 + const val NAME_HEIGHT = 12 /** The tiles' outline, and the focused one's frame. */ const val OUTLINE = 2 const val FRAME = 3 diff --git a/feature/settings/src/main/java/com/luncher/launcher/settings/OptionLabels.kt b/feature/settings/src/main/java/com/luncher/launcher/settings/OptionLabels.kt index c4395427..2b696f59 100644 --- a/feature/settings/src/main/java/com/luncher/launcher/settings/OptionLabels.kt +++ b/feature/settings/src/main/java/com/luncher/launcher/settings/OptionLabels.kt @@ -1,10 +1,12 @@ package com.luncher.launcher.settings import android.content.Context +import com.luncher.domain.appearance.AppName import com.luncher.domain.appearance.Appearance import com.luncher.domain.appearance.AppearanceOption import com.luncher.domain.appearance.AppearanceTopic import com.luncher.domain.appearance.Corners +import com.luncher.domain.appearance.FocusStyle import com.luncher.domain.appearance.HorizontalAlignment import com.luncher.domain.appearance.Side import com.luncher.domain.appearance.VerticalAlignment @@ -27,6 +29,8 @@ internal fun optionLabel(option: AppearanceOption<*>): Int = when (option) { AppearanceOption.HorizontalAlignment -> R.string.settings_appearance_horizontal_alignment AppearanceOption.FullBottomRow -> R.string.settings_appearance_full_bottom_row AppearanceOption.CornerRadius -> R.string.settings_appearance_corner_radius + AppearanceOption.FocusStyle -> R.string.settings_appearance_focus_style + AppearanceOption.AppName -> R.string.settings_appearance_app_name AppearanceOption.ShowTime -> R.string.settings_appearance_time AppearanceOption.ShowDate -> R.string.settings_appearance_date AppearanceOption.ClockSide -> R.string.settings_appearance_clock_side @@ -46,6 +50,8 @@ internal fun Context.optionValue(option: AppearanceOption<*>, appearance: Appear is Corners.Radius -> getString(R.string.settings_appearance_radius_dp, corners.dp) Corners.Pill -> getString(R.string.settings_appearance_pill) } + AppearanceOption.FocusStyle -> getString(focus(AppearanceOption.FocusStyle.get(appearance))) + AppearanceOption.AppName -> getString(appName(AppearanceOption.AppName.get(appearance))) AppearanceOption.ShowTime -> getString(shown(AppearanceOption.ShowTime.get(appearance))) AppearanceOption.ShowDate -> getString(shown(AppearanceOption.ShowDate.get(appearance))) AppearanceOption.ClockSide -> getString(side(AppearanceOption.ClockSide.get(appearance))) @@ -56,6 +62,16 @@ internal fun Context.optionValue(option: AppearanceOption<*>, appearance: Appear AppearanceOption.BackgroundBlur -> getString(blur(AppearanceOption.BackgroundBlur.get(appearance))) } +private fun focus(style: FocusStyle): Int = when (style) { + FocusStyle.FRAME -> R.string.settings_appearance_frame + FocusStyle.LIFT -> R.string.settings_appearance_lift +} + +private fun appName(name: AppName): Int = when (name) { + AppName.OFF -> R.string.settings_appearance_off + AppName.WHEN_FOCUSED -> R.string.settings_appearance_when_focused +} + private fun fit(fit: Fit): Int = when (fit) { Fit.FILL -> R.string.settings_appearance_fill Fit.STRETCH -> R.string.settings_appearance_stretch diff --git a/feature/settings/src/main/res/values-ar/strings.xml b/feature/settings/src/main/res/values-ar/strings.xml index 4861141a..abeb1593 100644 --- a/feature/settings/src/main/res/values-ar/strings.xml +++ b/feature/settings/src/main/res/values-ar/strings.xml @@ -17,6 +17,11 @@ استدارة الزوايا %1$d dp كبسولة + نمط التحديد + إطار + رفع + اسم التطبيق + عند التحديد الوقت التاريخ ظاهر diff --git a/feature/settings/src/main/res/values-el/strings.xml b/feature/settings/src/main/res/values-el/strings.xml index 7abd88e3..7f06b21d 100644 --- a/feature/settings/src/main/res/values-el/strings.xml +++ b/feature/settings/src/main/res/values-el/strings.xml @@ -17,6 +17,11 @@ Στρογγύλεμα γωνιών %1$d dp Κάψουλα + Στυλ επιλογής + Πλαίσιο + Ανύψωση + Όνομα εφαρμογής + Επιλεγμένης Ώρα Ημερομηνία Εμφανής diff --git a/feature/settings/src/main/res/values/strings.xml b/feature/settings/src/main/res/values/strings.xml index d8b2d1cd..2a2deab8 100644 --- a/feature/settings/src/main/res/values/strings.xml +++ b/feature/settings/src/main/res/values/strings.xml @@ -39,6 +39,17 @@ Pill + + Focus style + Frame + Lift + + App name + When focused Time diff --git a/feature/settings/src/test/java/com/luncher/launcher/settings/AppearanceActivityTest.kt b/feature/settings/src/test/java/com/luncher/launcher/settings/AppearanceActivityTest.kt index 11c27eac..f46b0709 100644 --- a/feature/settings/src/test/java/com/luncher/launcher/settings/AppearanceActivityTest.kt +++ b/feature/settings/src/test/java/com/luncher/launcher/settings/AppearanceActivityTest.kt @@ -5,8 +5,10 @@ import android.view.KeyEvent import android.view.View import android.widget.LinearLayout import android.widget.TextView +import com.luncher.domain.appearance.AppName import com.luncher.domain.appearance.Appearance import com.luncher.domain.appearance.Corners +import com.luncher.domain.appearance.FocusStyle import com.luncher.domain.appearance.HorizontalAlignment import com.luncher.domain.appearance.FakeAppearanceSettings import com.luncher.domain.appearance.Side @@ -145,7 +147,8 @@ class AppearanceActivityTest { assertEquals( listOf( "Tiles open", "Vertical alignment: Bottom", "Horizontal alignment: Center", "Full bottom row: On", - "Corner radius: 12 dp", "Time and date", "Background: None", "Reset to defaults", + "Corner radius: 12 dp", "Focus style: Frame", "App name: Off", "Time and date", "Background: None", + "Reset to defaults", ), activity.lines(), ) @@ -227,6 +230,22 @@ class AppearanceActivityTest { assertTrue(activity.row("Corner radius").isFocused) } + // The tvOS-like look, a step away each: the focused tile lifted, its name below it. + @Test + fun `the focus style steps to Lift, and the app name to When focused`() { + val activity = start() + activity.focus("Tiles", "Focus style") + + activity.press(KeyEvent.KEYCODE_DPAD_RIGHT) + assertEquals("Lift", activity.value("Focus style")) + assertTrue(activity.row("App name").requestFocus()) + activity.press(KeyEvent.KEYCODE_DPAD_RIGHT) + assertEquals("When focused", activity.value("App name")) + + assertEquals(Appearance(TileGeometry(appName = AppName.WHEN_FOCUSED), TileStyle(focus = FocusStyle.LIFT)), settings.appearance) + assertEquals(settings.appearance, activity.findViewById(R.id.settings_appearance_preview).appearance) + } + @Test fun `the horizontal alignment steps from left through center to right`() { settings.appearance = Appearance(TileGeometry(horizontalAlignment = HorizontalAlignment.LEFT)) diff --git a/feature/settings/src/test/java/com/luncher/launcher/settings/AppearancePreviewViewTest.kt b/feature/settings/src/test/java/com/luncher/launcher/settings/AppearancePreviewViewTest.kt index bd493115..90258e3f 100644 --- a/feature/settings/src/test/java/com/luncher/launcher/settings/AppearancePreviewViewTest.kt +++ b/feature/settings/src/test/java/com/luncher/launcher/settings/AppearancePreviewViewTest.kt @@ -1,10 +1,12 @@ package com.luncher.launcher.settings +import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Color import android.graphics.Rect import android.view.View +import com.luncher.domain.appearance.AppName import com.luncher.domain.appearance.Appearance import com.luncher.domain.appearance.Background import com.luncher.domain.appearance.Corners @@ -48,7 +50,9 @@ class AppearancePreviewViewTest { private val images = FakePictureImages(::sampleWallpaper) - private val preview = AppearancePreviewView(RuntimeEnvironment.getApplication(), null).apply { + private val preview = preview(RuntimeEnvironment.getApplication()) + + private fun preview(context: android.content.Context) = AppearancePreviewView(context, null).apply { measure(exactly(WIDTH), exactly(HEIGHT)) layout(0, 0, WIDTH, HEIGHT) showWallpapers(home, images, jobs) @@ -60,11 +64,11 @@ class AppearancePreviewViewTest { private fun exactly(size: Int) = View.MeasureSpec.makeMeasureSpec(size, View.MeasureSpec.EXACTLY) - private fun draw(appearance: Appearance): Bitmap { - preview.appearance = appearance + private fun draw(appearance: Appearance, view: AppearancePreviewView = preview): Bitmap { + view.appearance = appearance jobs.runAll() // its wallpaper, drawn in the background shadowOf(Looper.getMainLooper()).idle() // and shown - return Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888).also { preview.draw(Canvas(it)) } + return Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888).also { view.draw(Canvas(it)) } } /** The bytes this thread allocates running [block], on average over many runs, after as many to warm up. */ @@ -84,6 +88,20 @@ class AppearancePreviewViewTest { } } + // The room the rows leave for the focused tile's name is measured as the home screen's is + // (:ui's TileName), so it grows with the device's font size as there. Nothing else in the + // sample is text, so without the name the font size changes nothing. + @Test + fun `the room for the app name follows the font size, as on the home screen`() { + val application = RuntimeEnvironment.getApplication() + val larger = Configuration(application.resources.configuration).apply { fontScale = 1.3f } + val largerText = preview(application.createConfigurationContext(larger)) + val names = Appearance(TileGeometry(appName = AppName.WHEN_FOCUSED)) + + assertFalse("the same room at 1.3", draw(names).sameAs(draw(names, largerText))) + assertTrue(draw(Appearance()).sameAs(draw(Appearance(), largerText))) + } + // Rule 5 (docs/ARCHITECTURE.md): drawing allocates nothing. @Test fun `drawing allocates nothing`() { diff --git a/feature/settings/src/test/screenshots/settings/preview/appname_when_focused.png b/feature/settings/src/test/screenshots/settings/preview/appname_when_focused.png new file mode 100644 index 00000000..b2ac22fe Binary files /dev/null and b/feature/settings/src/test/screenshots/settings/preview/appname_when_focused.png differ diff --git a/feature/settings/src/test/screenshots/settings/preview/focusstyle_lift.png b/feature/settings/src/test/screenshots/settings/preview/focusstyle_lift.png new file mode 100644 index 00000000..b793d206 Binary files /dev/null and b/feature/settings/src/test/screenshots/settings/preview/focusstyle_lift.png differ diff --git a/feature/settings/src/test/screenshots/settings/settings_appearance_arabic.png b/feature/settings/src/test/screenshots/settings/settings_appearance_arabic.png index 4194271a..17236e70 100644 Binary files a/feature/settings/src/test/screenshots/settings/settings_appearance_arabic.png and b/feature/settings/src/test/screenshots/settings/settings_appearance_arabic.png differ diff --git a/feature/settings/src/test/screenshots/settings/settings_appearance_changed.png b/feature/settings/src/test/screenshots/settings/settings_appearance_changed.png index 715a6b11..2948c722 100644 Binary files a/feature/settings/src/test/screenshots/settings/settings_appearance_changed.png and b/feature/settings/src/test/screenshots/settings/settings_appearance_changed.png differ diff --git a/feature/settings/src/test/screenshots/settings/settings_appearance_small_screen.png b/feature/settings/src/test/screenshots/settings/settings_appearance_small_screen.png index 80834875..ac41c1d4 100644 Binary files a/feature/settings/src/test/screenshots/settings/settings_appearance_small_screen.png and b/feature/settings/src/test/screenshots/settings/settings_appearance_small_screen.png differ diff --git a/platform/src/main/java/com/luncher/launcher/appearance/PreferencesAppearanceSettings.kt b/platform/src/main/java/com/luncher/launcher/appearance/PreferencesAppearanceSettings.kt index 85cc970f..8f11bd11 100644 --- a/platform/src/main/java/com/luncher/launcher/appearance/PreferencesAppearanceSettings.kt +++ b/platform/src/main/java/com/luncher/launcher/appearance/PreferencesAppearanceSettings.kt @@ -76,6 +76,8 @@ class PreferencesAppearanceSettings(context: Context) : AppearanceSettings { AppearanceOption.HorizontalAlignment -> "tile_horizontal_alignment" AppearanceOption.FullBottomRow -> "tile_full_bottom_row" AppearanceOption.CornerRadius -> "tile_corner_radius" + AppearanceOption.FocusStyle -> "tile_focus_style" + AppearanceOption.AppName -> "tile_app_name" AppearanceOption.ClockSide -> "clock_side" AppearanceOption.TimeSide -> "time_side" AppearanceOption.ShowTime -> "show_time" diff --git a/platform/src/test/java/com/luncher/launcher/appearance/PreferencesAppearanceSettingsTest.kt b/platform/src/test/java/com/luncher/launcher/appearance/PreferencesAppearanceSettingsTest.kt index 22aea956..76018395 100644 --- a/platform/src/test/java/com/luncher/launcher/appearance/PreferencesAppearanceSettingsTest.kt +++ b/platform/src/test/java/com/luncher/launcher/appearance/PreferencesAppearanceSettingsTest.kt @@ -2,9 +2,11 @@ package com.luncher.launcher.appearance import android.content.Context import android.content.SharedPreferences +import com.luncher.domain.appearance.AppName import com.luncher.domain.appearance.Appearance import com.luncher.domain.appearance.AppearanceOption import com.luncher.domain.appearance.Corners +import com.luncher.domain.appearance.FocusStyle import com.luncher.domain.appearance.HorizontalAlignment import com.luncher.domain.appearance.Side import com.luncher.domain.appearance.TileGeometry @@ -37,8 +39,9 @@ class PreferencesAppearanceSettingsTest { verticalAlignment = VerticalAlignment.CENTER, horizontalAlignment = HorizontalAlignment.RIGHT, fullBottomRow = false, + appName = AppName.WHEN_FOCUSED, ), - TileStyle(Corners.Radius(16)), + TileStyle(Corners.Radius(16), FocusStyle.LIFT), TopBarAppearance(clockSide = Side.RIGHT, timeSide = Side.RIGHT, showTime = true, showDate = false), Background(PictureId("0123456789abcdef0123456789abcdef"), Fit.STRETCH, PicturePosition.LEFT, 40, Blur.LIGHT), ) @@ -50,6 +53,8 @@ class PreferencesAppearanceSettingsTest { "tile_horizontal_alignment" to "RIGHT", "tile_full_bottom_row" to "false", "tile_corner_radius" to "16", + "tile_focus_style" to "LIFT", + "tile_app_name" to "WHEN_FOCUSED", "clock_side" to "RIGHT", "time_side" to "RIGHT", "show_time" to "true", @@ -113,6 +118,19 @@ class PreferencesAppearanceSettingsTest { assertEquals(none, PreferencesAppearanceSettings(context).read()) } + // The focus style and the app name were added after the other options: an older version stored + // neither, and the tiles keep the look they had. + @Test + fun `stored before the focus style and the app name, frames the focused tile without a name`() { + store(stored - "tile_focus_style" - "tile_app_name") + + val before = changed.copy( + tileGeometry = changed.tileGeometry.copy(appName = AppName.OFF), + tileStyle = changed.tileStyle.copy(focus = FocusStyle.FRAME), + ) + assertEquals(before, PreferencesAppearanceSettings(context).read()) + } + // The background was added after the other options: an older version stored none of it. @Test fun `stored before the background, has none`() { @@ -150,6 +168,8 @@ class PreferencesAppearanceSettingsTest { Triple("tile_horizontal_alignment", "center", AppearanceOption.HorizontalAlignment), // names are exact Triple("tile_full_bottom_row", "maybe", AppearanceOption.FullBottomRow), Triple("tile_corner_radius", "5", AppearanceOption.CornerRadius), + Triple("tile_focus_style", "GLOW", AppearanceOption.FocusStyle), + Triple("tile_app_name", "ALWAYS", AppearanceOption.AppName), Triple("clock_side", "right", AppearanceOption.ClockSide), // names are exact Triple("time_side", "1", AppearanceOption.TimeSide), // a position, never stored Triple("show_date", "hidden", AppearanceOption.ShowDate), diff --git a/ui/README.md b/ui/README.md index 94d27b41..d4ad16d2 100644 --- a/ui/README.md +++ b/ui/README.md @@ -23,6 +23,8 @@ ui/ │ │ │ the previews' shape │ │ ├── ShortestShowing.kt how long a wait has shown, so it shows half a second at least: WorkingDialog's, │ │ │ and the share window's wheel + │ │ ├── TileName.kt the app name below the focused tile: its paint, its gap, the room it takes + │ │ │ below a tile; the home screen's, and the room the appearance preview leaves │ │ ├── WallpaperOutline.kt the dark edge around what's drawn on the wallpaper, on the home screen │ │ │ and in the previews of it │ │ └── WorkingDialog.kt a floating panel with a spinning wheel and a message, taking every key, @@ -35,7 +37,8 @@ ui/ │ └── values/ │ ├── colors.xml background, accent, primary and secondary text, a panel and its focused entry, │ │ the wallpaper outline - │ ├── dimens.xml a panel's corners, an entry's frame, WorkingDialog's sizes, the wallpaper outline's width + │ ├── dimens.xml a panel's corners, an entry's frame, WorkingDialog's sizes, the wallpaper outline's width, + │ │ the tile name's text size and gap │ └── themes.xml Theme.Luncher, the app's and the home screen's theme; Theme.Luncher.Working └── testFixtures/java/com/luncher/launcher/testing/ ├── TvDevice.kt the TV screens the JVM tests run on (TV_1080P, TV_SCREENS) diff --git a/ui/src/main/java/com/luncher/launcher/ui/TileName.kt b/ui/src/main/java/com/luncher/launcher/ui/TileName.kt new file mode 100644 index 00000000..394d9ece --- /dev/null +++ b/ui/src/main/java/com/luncher/launcher/ui/TileName.kt @@ -0,0 +1,49 @@ +package com.luncher.launcher.ui + +import android.content.Context +import android.graphics.Paint +import android.text.TextPaint +import kotlin.math.ceil + +/** + * The app's name below the focused tile: its paint, the gap above it, and how far below a tile it + * reaches. The home screen draws it with this (feature/home's TilePaints), and the appearance + * editor's preview leaves it the same room, at its own scale, so the two can't drift apart: both + * measure the text, so the room follows the device's font size and the language's font. + */ +class TileName(context: Context) { + + /** The name's text, in the primary text color. */ + val paint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply { + color = context.color(R.color.text_primary) + textSize = context.resources.getDimension(R.dimen.tile_name_text) + } + + /** Between a tile's bottom edge and the name's top, before the tile's zoom, in pixels. */ + val gap: Int = context.resources.getDimensionPixelSize(R.dimen.tile_name_gap) + + /** The name's ascent, read once: each read of the font's metrics allocates. */ + val ascent: Int + + private val lineHeight: Int + + private val pixelsPerDp = context.resources.displayMetrics.density + + init { + val metrics = paint.fontMetricsInt + ascent = metrics.ascent + lineHeight = metrics.descent - metrics.ascent + } + + /** + * How far below a tile the name reaches, the gap included, with the tile zoomed by [zoom]: the + * name is drawn with the tile, so it's zoomed as the tile is. In whole pixels. + */ + fun room(zoom: Float): Int = ceil(zoom * (gap + lineHeight)).toInt() + + /** [room] in dp, for a drawing at a scale of its own (a preview's sample dp). */ + fun roomDp(zoom: Float): Float = room(zoom) / pixelsPerDp + + /** [gap] in dp, for a drawing at a scale of its own. */ + val gapDp: Float = gap / pixelsPerDp +} diff --git a/ui/src/main/res/values/dimens.xml b/ui/src/main/res/values/dimens.xml index cdf71e2b..951b962a 100644 --- a/ui/src/main/res/values/dimens.xml +++ b/ui/src/main/res/values/dimens.xml @@ -19,4 +19,9 @@ (WallpaperOutline). The home screen's gear (feature/home's home_settings.xml) draws twice this, in its own units. --> 0.75dp + + 16sp + 8dp