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
4 changes: 4 additions & 0 deletions docs/WEAR_OS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ versions by @cubetes): one design on every wrist. The rules live in `WatchLogic.
up next, plus the waiting count) and **complication** (sets done as a ring, else the streak;
"↑3" as its title while sets wait).
- **Language**: the app's, not the watch's (the phone sends it), in all 24 of the app's languages.
- **Always On** on a screen that can burn in: the whole screen moves up to 3 dp once a minute,
round a 3 × 3 grid (`BurnIn`).
- **TalkBack**: a number box (weight, reps, seconds) and the weigh-in read their name and value
apart, and offer More and Less in TalkBack's actions, like the Apple Watch's adjustable numbers.
- **The rest from the phone**: a rest started on the phone runs on the watch as well. The watch
follows only a *new* rest end from the phone, so a snapshot with the same end can't undo a ±15
or a Skip pressed on the watch (`RestMath.follows`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.offset
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.lifecycle.lifecycleScope
import androidx.wear.ambient.AmbientLifecycleObserver
import androidx.wear.compose.material3.AppScaffold
Expand Down Expand Up @@ -36,10 +42,18 @@ class MainActivity : ComponentActivity() {
WorkoutService.sync(this)
}

private var burnIn = false
private val minute = mutableIntStateOf(0)

private val ambient = AmbientLifecycleObserver(this, object : AmbientLifecycleObserver.AmbientLifecycleCallback {
override fun onEnterAmbient(ambientDetails: AmbientLifecycleObserver.AmbientDetails) { WearStore.ambient.value = true }
override fun onExitAmbient() { WearStore.ambient.value = false }
override fun onUpdateAmbient() {}
override fun onEnterAmbient(ambientDetails: AmbientLifecycleObserver.AmbientDetails) {
burnIn = ambientDetails.burnInProtectionRequired
minute.intValue = 0
WearStore.ambient.value = true
}
override fun onExitAmbient() { WearStore.ambient.value = false; minute.intValue = 0 }
// Once a minute in Always On: a screen that can burn in moves a little (BurnIn).
override fun onUpdateAmbient() { if (burnIn) minute.intValue++ }
})

override fun attachBaseContext(base: Context) {
Expand All @@ -59,8 +73,10 @@ class MainActivity : ComponentActivity() {
val s by WearStore.state.collectAsState()
val dim by WearStore.ambient.collectAsState()
OpenGymTheme(accent = Accent.of(s.settings), ambient = dim, reduceMotion = reduceMotion.value, round = round) {
AppScaffold(timeText = { OgTimeText() }) {
WearApp(onWorkoutShown = { onWorkout() })
Box(Modifier.offset { BurnIn.offset(minute.intValue).let { (x, y) -> IntOffset(x.dp.roundToPx(), y.dp.roundToPx()) } }) {
AppScaffold(timeText = { OgTimeText() }) {
WearApp(onWorkoutShown = { onWorkout() })
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,20 @@ object Stills {
fun shows(have: Boolean, showClip: Boolean?, ambient: Boolean) = have && showClip != false && !ambient
}

/**
* Always On on a screen that can burn in (AmbientDetails.burnInProtectionRequired): the whole
* screen moves a few dp each minute (onUpdateAmbient), round a 3 × 3 grid, so no pixel stays lit.
*/
object BurnIn {
const val DP = 3

/** The offset in dp for the n-th minute in Always On: (0, 0) first, then the grid's other eight. */
fun offset(n: Int): Pair<Int, Int> {
val i = Math.floorMod(n + 4, 9)
return ((i % 3) - 1) * DP to ((i / 3) - 1) * DP
}
}

/**
* The rest's buzz with the screen off: the watch's processor sleeps between heart-rate batches, and
* a timer that only counts while it is awake comes late. So the app holds it awake for the rest (or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.rotary.onRotaryScrollEvent
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.CustomAccessibilityAction
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.customActions
import androidx.compose.ui.semantics.onClick
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -178,7 +181,7 @@ private fun IconLabel(label: String, icon: G?, color: Color, iconSize: Dp, weigh

/**
* A one-line label at `size`, made smaller just enough to fit when it would not (never under
* 10 sp), instead of ending in "…": minimumScaleFactor on the Apple Watch.
* 12 sp), instead of ending in "…": minimumScaleFactor on the Apple Watch.
*/
@Composable
fun FitText(text: String, color: Color, size: TextUnit, weight: FontWeight = FontWeight.Normal, align: TextAlign = TextAlign.Center) {
Expand All @@ -188,7 +191,7 @@ fun FitText(text: String, color: Color, size: TextUnit, weight: FontWeight = Fon
val full = remember(text, style, measurer) { measurer.measure(text, style, maxLines = 1, softWrap = false).size.width }
val max = constraints.maxWidth
// 5 % under the exact fit: rounding glyph widths must not tip it into "…".
val fit = if (full <= max || full == 0) size else (size.value * max / full * 0.95f).coerceAtLeast(10f).sp
val fit = if (full <= max || full == 0) size else (size.value * max / full * 0.95f).coerceAtLeast(12f).sp
Text(text, style = style.copy(fontSize = fit), maxLines = 1, softWrap = false, overflow = TextOverflow.Ellipsis)
}
}
Expand Down Expand Up @@ -266,7 +269,7 @@ fun ArrowButton(left: Boolean, enabled: Boolean, onClick: () -> Unit) {
@Composable
fun Tag(text: String, color: Color) {
Box(Modifier.clip(CircleShape).background(color.copy(alpha = 0.18f)).padding(horizontal = 6.dp, vertical = 1.dp)) {
Text(text.uppercase(), color = color, fontSize = 10.sp, fontWeight = FontWeight.Bold, maxLines = 1)
Text(text.uppercase(), color = color, fontSize = 12.sp, fontWeight = FontWeight.Bold, maxLines = 1)
}
}

Expand All @@ -275,36 +278,69 @@ fun Quiet(text: String, size: TextUnit = 12.sp, modifier: Modifier = Modifier, l
color: Color = Og.Label2) =
Text(text, modifier = modifier, color = color, fontSize = size, textAlign = align, maxLines = lines, overflow = TextOverflow.Ellipsis)

/** A number you can turn: big in a soft box, its unit small beside it, its name under it; outlined in the accent while the crown turns it. */
/**
* A number you can turn, in Apple Workout's style (#1107): its name small and in capitals on top, the
* number big under it, both in `tint` (the accent; orange on a warm-up) on a dark tint of it, and an
* outline in the same colour while the crown turns it. The number grows with the box's height and
* shrinks to fit its width rather than end in "…".
*/
@Composable
fun NumberBox(value: String, unit: String?, label: String, selected: Boolean, modifier: Modifier = Modifier,
tint: Color = Og.Text, big: Boolean = true, showLabel: Boolean = true, onClick: () -> Unit) {
val a = LocalAccent.current
tint: Color = LocalAccent.current.accent, showLabel: Boolean = true, onAdjust: ((Int) -> Unit)? = null,
onClick: () -> Unit) {
val adjust = adjustActions(onAdjust)
val dim = LocalAmbient.current
val shape = RoundedCornerShape(12.dp)
Column(
val ink = tint.copy(alpha = if (dim) 0.7f else 1f)
BoxWithConstraints(
modifier
.heightIn(min = Og.Tap)
.clip(shape)
.background(if (dim) Color.Transparent else Og.Surface)
.border(if (selected) 2.dp else if (dim) 1.dp else 0.dp, if (selected) a.accent else Og.Surface2, shape)
.background(if (dim) Color.Transparent else tint.copy(alpha = 0.16f))
.then(when {
selected -> Modifier.border(2.dp, tint, shape)
dim -> Modifier.border(1.dp, Og.Surface2, shape)
else -> Modifier
})
.combinedClickable(role = Role.Button, onClick = onClick)
.padding(horizontal = 4.dp, vertical = 3.dp)
.semantics { contentDescription = "$label, $value ${unit ?: ""}" },
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
.semantics {
contentDescription = label
stateDescription = if (unit != null) "$value $unit" else value
if (adjust != null) customActions = adjust
},
contentAlignment = Alignment.Center,
) {
Row(verticalAlignment = Alignment.Bottom) {
Text(value, style = Og.Number, fontSize = if (big) 28.sp else 22.sp, color = tint.copy(alpha = if (dim) 0.7f else 1f), maxLines = 1)
if (unit != null) Text(" $unit", color = Og.Label2, fontSize = 11.sp, modifier = Modifier.padding(bottom = 4.dp), maxLines = 1)
}
if (showLabel) Row(verticalAlignment = Alignment.CenterVertically) {
if (selected) { Glyph(G.CROWN, a.accent, 8.dp); Box(Modifier.width(2.dp)) }
Text(label, color = Og.Label2, fontSize = 10.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
// The number is 0.42 of the box's height (40 sp at most), and shrinks to fit its width:
// digits ~0.62 of the size wide, the unit ~7 dp a letter, 8 dp of padding.
// Its line (~1.3 of the size) must fit under the label; a box too short for both drops the label
// (still read by TalkBack) rather than shrink the number (40 mm emulator: the "g" of "kg" was cut).
val fs = LocalDensity.current.fontScale
val room = maxWidth.value - 8f - (unit?.let { (it.length + 1) * 7f * fs } ?: 0f)
val withLabel = showLabel && (maxHeight.value - 6f - 13f * fs * 1.3f) / 1.3f >= 18f
val tall = (maxHeight.value - 6f - (if (withLabel) 13f * fs * 1.3f else 0f)) / 1.3f
val size = minOf(40f, minOf(maxHeight.value * 0.42f, tall, room / (value.length.coerceAtLeast(1) * 0.62f)) / fs)
.coerceAtLeast(12f)
Column(Modifier.padding(horizontal = 4.dp, vertical = 3.dp), horizontalAlignment = Alignment.CenterHorizontally) {
if (withLabel) Row(verticalAlignment = Alignment.CenterVertically) {
if (selected) { Glyph(G.CROWN, ink, 8.dp); Box(Modifier.width(2.dp)) }
Text(label.uppercase(), color = ink, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
Row {
Text(value, style = Og.Number, fontSize = size.sp, color = ink, maxLines = 1, softWrap = false, modifier = Modifier.alignByBaseline())
if (unit != null) Text(" $unit", color = ink.copy(alpha = 0.8f), fontSize = 14.sp, modifier = Modifier.alignByBaseline(), maxLines = 1)
}
}
}
}

/** TalkBack's More and Less on a number the crown turns (the Apple Watch's adjustable action). */
@Composable
fun adjustActions(onAdjust: ((Int) -> Unit)?): List<CustomAccessibilityAction>? {
onAdjust ?: return null
val more = stringResource(R.string.more); val less = stringResource(R.string.less)
return listOf(CustomAccessibilityAction(more) { onAdjust(1); true }, CustomAccessibilityAction(less) { onAdjust(-1); true })
}

/** A clock that ticks: four times a second awake, once a second in Always On. */
@Composable
fun rememberNow(fast: Boolean = false): Long {
Expand Down Expand Up @@ -356,7 +392,7 @@ fun SyncPill(state: SyncState) {
) {
Glyph(if (state is SyncState.Away) G.PHONE_OFF else G.UP, Og.Orange, 9.dp)
Box(Modifier.width(2.dp))
Text("${state.count}", color = Og.Orange, fontSize = 11.sp, fontWeight = FontWeight.SemiBold, style = Og.Number)
Text("${state.count}", color = Og.Orange, fontSize = 12.sp, fontWeight = FontWeight.SemiBold, style = Og.Number)
}
}

Expand All @@ -367,14 +403,14 @@ fun SyncLine(state: SyncState, showSynced: Boolean = true, heard: Boolean = true
Column(modifier, horizontalAlignment = Alignment.CenterHorizontally) {
Row(verticalAlignment = Alignment.CenterVertically) {
Glyph(G.UP, Og.Orange, 10.dp); Box(Modifier.width(4.dp))
Text(stringResource(R.string.waiting_sync) + " ${state.count}", color = Og.Orange, fontSize = 11.sp, maxLines = 1)
Text(stringResource(R.string.waiting_sync) + " ${state.count}", color = Og.Orange, fontSize = 12.sp, maxLines = 1)
}
if (state is SyncState.Away) Quiet(stringResource(R.string.phone_out_of_reach), 11.sp)
if (state is SyncState.Away) Quiet(stringResource(R.string.phone_out_of_reach), 12.sp)
}
} else if (showSynced && heard) {
Row(modifier, verticalAlignment = Alignment.CenterVertically) {
Glyph(G.CHECK, Og.Label2, 10.dp); Box(Modifier.width(4.dp))
Text(stringResource(R.string.all_synced), color = Og.Label2, fontSize = 11.sp, maxLines = 1)
Text(stringResource(R.string.all_synced), color = Og.Label2, fontSize = 12.sp, maxLines = 1)
}
}
}
Expand Down
Loading
Loading