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
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
android:resource="@xml/clip_paths" />
</provider>

<!-- The overlay's resolved colors, read-only, for apps that match the theme (docs/SHARED_THEME.md). -->
<provider
android:name=".system.ThemeProvider"
android:authorities="${applicationId}.theme"
android:exported="true" />


<activity
android:name=".MainActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import jr.brian.commandpannel.ui.theme.TccUiLook
*/
object CustomLookStore {
const val KEY = "custom_looks"
private const val LOOK_KEY = "overlay_look"
const val LOOK_KEY = "overlay_look"

fun all(prefs: SharedPreferences): List<CustomLook> = CustomLookJson.decodeList(prefs.getString(KEY, null))

Expand Down
145 changes: 145 additions & 0 deletions app/src/main/java/jr/brian/commandpannel/system/SharedLookPalette.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package jr.brian.commandpannel.system

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.graphics.lerp
import jr.brian.commandpannel.ui.theme.TccColors
import jr.brian.commandpannel.ui.theme.TccUiLook
import jr.brian.commandpannel.ui.theme.clampContrast
import jr.brian.commandpannel.ui.theme.resolveLookColors

private const val SECONDARY_INK_FADE = 0.25f
private const val TERTIARY_INK_FADE = 0.45f

// A client can't draw a look's frames, bevels or shadows, so its surfaces need a visible step of their own.
internal const val SHARED_SURFACE_STEP = 1.06f
internal const val SHARED_SURFACE_HIGH_STEP = 1.12f

/** The roles a built-in look paints itself, taken from the fills its card renderer uses. */
private class LookRoles(
val background: Color,
val surface: Color,
/** Drawn at [highAmount] over the surface for `surface_high`, the way the look tints a focused card. */
val highTint: Color,
val highAmount: Float,
val accent: Color,
/** The look's single text color, for looks that draw text in one ink. `null` keeps the palette's text. */
val ink: Color? = null,
val danger: Color? = null,
)

/**
* The palette to publish for built-in [look]. Only the shared theme uses this: the overlay and companion keep resolving
* their own colors. Renderer-only looks return [colors] unchanged. With [ledAccent] on, the LED color stays the accent.
*/
internal fun publishedLookPalette(colors: TccColors, look: TccUiLook, ledAccent: Boolean): TccColors {
val roles = lookRoles(colors, look) ?: return colors
val background = roles.background.opaque()
val surface = roles.surface.opaque().clampContrast(background, SHARED_SURFACE_STEP)
val surfaceHigh = roles.highTint.opaque().copy(alpha = roles.highAmount).compositeOver(surface)
.clampContrast(surface, SHARED_SURFACE_HIGH_STEP)
val ink = roles.ink?.opaque()
return colors.copy(
primaryBackground = background,
panelBackground = surface,
panelBackgroundSelect = surfaceHigh,
primary = ink ?: colors.primary.opaque(),
secondary = ink?.let { lerp(it, surface, SECONDARY_INK_FADE) } ?: colors.secondary.opaque(),
tertiary = ink?.let { lerp(it, surface, TERTIARY_INK_FADE) } ?: colors.tertiary.opaque(),
accent = (if (ledAccent) colors.accent else roles.accent).opaque(),
error = (roles.danger ?: colors.error).opaque(),
)
}

private fun lookRoles(colors: TccColors, look: TccUiLook): LookRoles? {
val lc = resolveLookColors(colors, look)
val bg = colors.primaryBackground
return when (look) {
TccUiLook.SOFT_CONSOLE -> LookRoles(
background = lc.softSurface,
surface = lc.softSurface,
highTint = lc.softAccent,
highAmount = 0.06f,
accent = lc.softAccent,
)
TccUiLook.SOFT_CONSOLE_OLED -> LookRoles(
background = if (colors.isDark) Color.Black else lc.softSurface,
surface = lc.softSurface,
highTint = lc.softAccent,
highAmount = 0.06f,
accent = lc.softAccent,
)
// Composited, because lcdPanel's Oklab mix rounds to pure black on the pure-black palette.
TccUiLook.SEGMENT_LCD -> LookRoles(
background = bg,
surface = lc.lcdInk.opaque().copy(alpha = 0.08f).compositeOver(bg.opaque()),
highTint = lc.lcdInk,
highAmount = 0.10f,
accent = lc.lcdInk,
ink = lc.lcdInk,
)
TccUiLook.BLOOM -> LookRoles(
background = bg,
surface = lc.bloomContainer,
highTint = lc.bloomContainerHigh,
highAmount = 1f,
accent = lc.bloomOnContainer,
)
TccUiLook.NEON_ARCADE -> LookRoles(
background = bg,
surface = lc.neonPanel,
highTint = lc.neonTube,
highAmount = 0.10f,
accent = lc.neonTube,
)
TccUiLook.TERMINAL -> LookRoles(
background = bg,
surface = bg,
highTint = lc.terminalInk,
highAmount = 0.08f,
accent = lc.terminalInk,
ink = lc.terminalInk,
)
TccUiLook.COCKPIT -> LookRoles(
background = bg,
surface = lc.cockpitPanel,
highTint = lc.ledOn,
highAmount = 0.06f,
accent = lc.ledOn,
danger = lc.dangerZone,
)
TccUiLook.INDUSTRIAL -> LookRoles(
background = bg,
surface = lc.metalFill,
highTint = lc.hazard,
highAmount = 0.08f,
accent = lc.hazard,
)
TccUiLook.COMIC_PANEL -> LookRoles(
background = bg,
surface = lc.comicPaper,
highTint = colors.accent,
highAmount = 0.10f,
accent = colors.accent,
ink = lc.comicInk,
)
TccUiLook.E_INK -> LookRoles(
background = lc.einkPaper,
surface = lc.einkPaper,
highTint = lc.einkInk,
highAmount = 0.06f,
accent = lc.einkInk,
ink = lc.einkInk,
)
TccUiLook.AUTO,
TccUiLook.AURORA_GLASS,
TccUiLook.AURORA_BLUR,
TccUiLook.CARTRIDGE,
TccUiLook.TACTICAL_HUD,
TccUiLook.STICKER_BOOK,
TccUiLook.JELLY,
TccUiLook.Y2K_CHROME -> null
}
}

private fun Color.opaque(): Color = copy(alpha = 1f)
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package jr.brian.commandpannel.system

/**
* The shared theme contract, version 1: how another app reads the overlay's resolved colors from [ThemeProvider].
* The full spec is `docs/SHARED_THEME.md` in the Command Panel repo.
*
* Constants only, with no Android or Command Panel imports, so a client can copy this file as is (keeping or changing
* the `package` line). Version 1 is frozen: never add, remove, rename or reorder a column. Any change to the row means
* a new [VERSION].
*/
object SharedThemeContract {

/** The contract version this file describes, also returned in [COLUMN_VERSION]. */
const val VERSION = 1

/** The provider's authority is the Command Panel package plus this suffix. */
const val AUTHORITY_SUFFIX = ".theme"

/** The one readable path: `content://<package>.theme/palette`. Returns one row. */
const val PATH = "palette"

/** The only package a release client may trust. */
const val RELEASE_PACKAGE = "jr.brian.commandpannel"

/** For debug clients only. A release client must never read from or trust this package. */
const val DEBUG_PACKAGE = "jr.brian.commandpannel.debug"

/** SHA-256 of Command Panel's release signing certificate (lowercase hex, no separators). Debug builds differ. */
const val RELEASE_CERT_SHA256 = "8ebd8e6ff20a29019a857fe25a98532649d66bf3fd778a64150db8085d988927"

// ---- columns, all integers ----

const val COLUMN_VERSION = "version"

/** 1 for a dark palette, 0 for a light one. */
const val COLUMN_IS_DARK = "is_dark"

// Colors, as ARGB ints.
const val COLUMN_BG = "bg"
const val COLUMN_RAIL = "rail"
const val COLUMN_SURFACE = "surface"
const val COLUMN_SURFACE_HIGH = "surface_high"
const val COLUMN_BORDER = "border"
const val COLUMN_ACCENT = "accent"
const val COLUMN_ACCENT_SOFT = "accent_soft"
const val COLUMN_ACCENT_FOCUSED = "accent_focused"
const val COLUMN_ON_ACCENT = "on_accent"
const val COLUMN_TEXT_PRIMARY = "text_primary"
const val COLUMN_TEXT_SECONDARY = "text_secondary"
const val COLUMN_TEXT_TERTIARY = "text_tertiary"
const val COLUMN_DANGER = "danger"
const val COLUMN_SUCCESS = "success"

/** Every column, in the order a query without a projection returns them. */
val COLUMNS = listOf(
COLUMN_VERSION, COLUMN_IS_DARK,
COLUMN_BG, COLUMN_RAIL, COLUMN_SURFACE, COLUMN_SURFACE_HIGH, COLUMN_BORDER,
COLUMN_ACCENT, COLUMN_ACCENT_SOFT, COLUMN_ACCENT_FOCUSED, COLUMN_ON_ACCENT,
COLUMN_TEXT_PRIMARY, COLUMN_TEXT_SECONDARY, COLUMN_TEXT_TERTIARY,
COLUMN_DANGER, COLUMN_SUCCESS,
)
}
Loading
Loading