Show G2 charging case on Settings tab and charging view rather than main activity

This commit is contained in:
James Babcock committed 2026-11-02 00:30:21 -08:00
1 parent 5e729d1236
commit 27756913d0
17 files changed
+277 -83

No files matched your search

@@ -95,6 +95,10 @@ data class PhoneState(
/** Current or last-known G2 charge percentage. */
val battery: Int?,
val charging: Boolean,
/** Last-known charging-case percentage; live only while the glasses are docked. */
val caseBattery: Int?,
/** The case is on USB; null while the glasses are out of the case. */
val caseCharging: Boolean?,
val silentMode: Boolean,
val foreground: AppEntry?,
val windows: List<WindowEntry>,
@@ -123,6 +127,8 @@ data class PhoneState(
listening = o.optBoolean("listening", false),
battery = if (o.isNull("battery")) null else o.optInt("battery", -1).takeIf { it in 0..100 },
charging = o.optBoolean("charging", false),
caseBattery = if (o.isNull("caseBattery")) null else o.optInt("caseBattery", -1).takeIf { it in 0..100 },
caseCharging = if (o.isNull("caseCharging")) null else o.optBoolean("caseCharging"),
silentMode = o.optBoolean("silentMode", false),
foreground = foreground?.let {
AppEntry(it.optString("appId", ""), it.optString("title", ""))
@@ -12,7 +12,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@@ -64,13 +63,10 @@ fun AmbientScreen(link: PhoneLink, ambient: AmbientMode) {
maxLines = 1,
modifier = Modifier.align(Alignment.Center),
)
Text(
text = padLine(state, linkStatus).text,
style = MaterialTheme.typography.title3,
PadStatusText(
pad = padLine(state, linkStatus),
color = statusColor,
textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
detailColor = statusColor,
modifier = Modifier
.align(Alignment.Center)
.offset(y = 46.dp)
@@ -14,6 +14,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
@@ -59,8 +60,11 @@ fun NoticeOverlay(notice: Notice?) {
}
}
/** The pad's single indicator line, with a tone that picks its colour. */
data class StatusLine(val text: String, val tone: StatusTone)
/**
* The pad's indicator line, with a tone that picks its colour, and an
* optional smaller line under it (the charging case's level while charging).
*/
data class StatusLine(val text: String, val tone: StatusTone, val detail: String? = null)
enum class StatusTone { GOOD, BUSY, OFF, PROBLEM }
@@ -76,7 +80,8 @@ fun padLine(state: PhoneState?, link: LinkStatus): StatusLine = when {
state == null -> StatusLine("Waiting for phone", StatusTone.BUSY)
state.remoteEnabled == false -> StatusLine("Watch control off", StatusTone.PROBLEM)
state.connected -> when {
state.charging || state.phase == "charging" -> StatusLine(chargingLine(state.battery), StatusTone.BUSY)
state.charging || state.phase == "charging" ->
StatusLine(chargingLine(state.battery), StatusTone.BUSY, caseLine(state))
state.silentMode -> StatusLine("Silent mode", StatusTone.OFF)
state.locked -> StatusLine("Locked", StatusTone.OFF)
!state.screenOn -> StatusLine("●● Wake", StatusTone.OFF)
@@ -91,6 +96,56 @@ fun padLine(state: PhoneState?, link: LinkStatus): StatusLine = when {
private fun chargingLine(battery: Int?): String =
if (battery != null) "Charging · G2 $battery%" else "Charging"
/**
* "Case 64%", with ⚡ while the case is on USB; null when the level is
* unknown. Matches the phone's watch face (glassesDisplayDetail). The case is
* only reported while the glasses are docked, so the line is only drawn while
* they charge.
*/
private fun caseLine(state: PhoneState): String? =
state.caseBattery?.let { "Case $it%" + if (state.caseCharging == true) " ⚡" else "" }
/**
* [pad]'s status line, with its detail (if any) drawn under it. Only the
* status line counts toward the measured height, so a caller that centres
* this keeps the status line in the same place whether or not a detail shows.
*/
@Composable
fun PadStatusText(pad: StatusLine, color: Color, detailColor: Color, modifier: Modifier = Modifier) {
Layout(
modifier = modifier,
content = {
Text(
text = pad.text,
style = MaterialTheme.typography.title3,
color = color,
textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
pad.detail?.let { detail ->
Text(
text = detail,
style = MaterialTheme.typography.caption1,
color = detailColor,
textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
},
) { measurables, constraints ->
val placeables = measurables.map { it.measure(constraints.copy(minWidth = 0, minHeight = 0)) }
val status = placeables.first()
val width = placeables.maxOf { it.width }.coerceIn(constraints.minWidth, constraints.maxWidth)
val height = status.height.coerceIn(constraints.minHeight, constraints.maxHeight)
layout(width, height) {
status.placeRelative((width - status.width) / 2, 0)
placeables.getOrNull(1)?.let { it.placeRelative((width - it.width) / 2, status.height) }
}
}
}
fun StatusTone.color(): Color = when (this) {
StatusTone.GOOD -> Color(0xFF7BD88F)
StatusTone.BUSY -> Color(0xFFF2C14E)
@@ -36,7 +36,6 @@ import androidx.compose.ui.platform.LocalViewConfiguration
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.Lifecycle
@@ -307,13 +306,10 @@ fun RemoteScreen(
modifier = Modifier.align(Alignment.Center).offset(y = 46.dp),
) {
val pad = padLine(state, linkStatus)
Text(
text = pad.text,
style = MaterialTheme.typography.title3,
PadStatusText(
pad = pad,
color = if (pad.tone == StatusTone.GOOD) MaterialTheme.colors.onSurface else pad.tone.color(),
textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
detailColor = MaterialTheme.colors.onSurfaceVariant,
modifier = Modifier.padding(horizontal = 42.dp),
)
}