Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
14 changes: 8 additions & 6 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
8 changes: 5 additions & 3 deletions domain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions domain/src/main/kotlin/com/luncher/domain/appearance/AppName.kt
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -74,6 +76,22 @@ sealed interface AppearanceOption<T> {
appearance.copy(tileStyle = appearance.tileStyle.copy(corners = value))
}

/** How the focused tile stands out: framed, or lifted with a shadow. */
data object FocusStyle : AppearanceOption<Focus> {
override val values: List<Focus> = 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<Name> {
override val values: List<Name> = 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<Boolean> {
override val values: List<Boolean> = listOf(true, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ fun appearanceOptions(): AppearanceOptions =
AppearanceOption.HorizontalAlignment,
AppearanceOption.FullBottomRow,
AppearanceOption.CornerRadius,
AppearanceOption.FocusStyle,
AppearanceOption.AppName,
),
),
AppearanceGroup(
Expand Down
10 changes: 10 additions & 0 deletions domain/src/main/kotlin/com/luncher/domain/appearance/FocusStyle.kt
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
12 changes: 9 additions & 3 deletions domain/src/main/kotlin/com/luncher/domain/layout/TileGrid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 16 additions & 2 deletions domain/src/main/kotlin/com/luncher/domain/layout/TileLayouts.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class AppearanceOptionsTest {
AppearanceOption.HorizontalAlignment,
AppearanceOption.FullBottomRow,
AppearanceOption.CornerRadius,
AppearanceOption.FocusStyle,
AppearanceOption.AppName,
),
catalog.groups[0].options,
)
Expand Down
35 changes: 35 additions & 0 deletions domain/src/test/kotlin/com/luncher/domain/layout/TileGridTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
Loading