forked from Blendman974/faceclaw
Wear watchface design
Makes the button-row appear and disappear with a slide-in/out gesture.
Rearranges the other UI elements for a more watchface-like view.
<details>
<summary>Prompts used</summary>
In faceclaw/wear, we have an Android Wear watch app which can be used as a glasses controller. Currently, its UI is a bit chaotic: we have a bottom row of buttons, the time, a foreground-window title, some help text, and a ring of indicators. The core interaction is tapping, double tapping, long tapping, and swiping (which have the same effect as on the R1 ring), which aren't location sensitive except that they can't hit the row of buttons. There is also a crown, which can be rotated as a prev/next input.
First, let's make a crown-direction setting (in the Watch section of the on-glasses Settings app), which is a toggle that can swap which crown-rotation direction is considered next vs prev. The default will be off, which will be opposite the direction that is currently default.
Next, we will make it so that the row of buttons is hidden by default. They will slide in from the bottom when the user swipes up from off-screen (distinguished from a swipe-up gesture sent to the glasses by the starting position of the swipe). They will slide out with a swipe down starting from anywhere below the top of the buttons (distinguishing from a swipe-down gesture sent to the glasses by the starting position of the swipe).
Next, we will remove the circle and four arrows; change the time from being small, curved and at the top of the screen to being larger, straight and vertically centered. We'll delete the gesture current hint ("● select ●● back"), and take the current foreground-window display (which is currently either "Disconnected", "Screen off", or an app title) and place it below the time. When the current state is "Screen off", it will display as "●● Wake". We'll then make it so that when the glasses screen is off, all gestures except for double tap (which wakes the screen) are ignored.
gpt-5.6-Sol:
> Implemented the Wear controller redesign.
>
> - Added on-glasses Settings → Watch toggle: “Clockwise crown = next.” Default off maps clockwise to previous, opposite the former default.
> - Replaced the obsolete “Watch input wakes display” setting.
> - Bottom buttons are hidden initially, slide up from a bottom-edge swipe, and dismiss with a downward swipe anywhere in the tray.
> - Removed the ring, arrows, and gesture hint.
> - Added a large centered straight clock with foreground status beneath it; screen-off status is now “●● Wake.”
> - While the glasses display is off, non-double-tap gestures are ignored locally and defensively on the phone.
> - Updated faceclaw/wear/README.md and faceclaw/wear/PROTOCOL.md.
>
> Verification:
>
> - TypeScript type-check passed.
> - All 59 tests passed.
> - git diff --check passed.
> - Wear Gradle compilation could not start because the sandbox blocks Gradle’s local lock socket/cache access.
</details>
This commit is contained in:
1 parent
b9e5e56ac8
commit
f858f10ce2
13 files changed
+220
-173
No files matched your search
@@ -32,6 +32,14 @@ android {
|
||||
buildConfig = true
|
||||
}
|
||||
|
||||
lint {
|
||||
// androidx.lifecycle 2.9.x ships a NullSafeMutableLiveData lint check
|
||||
// that crashes under this AGP's lint (Kotlin analysis API mismatch:
|
||||
// "Found class KaCallableMemberCall, but interface was expected").
|
||||
// We don't use LiveData, so nothing is lost by disabling it.
|
||||
disable += "NullSafeMutableLiveData"
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
@@ -20,6 +20,7 @@ class MainActivity : ComponentActivity() {
|
||||
private val stemHandler = Handler(Looper.getMainLooper())
|
||||
private var stemHoldRunnable: Runnable? = null
|
||||
private var stemHoldSent = false
|
||||
private var stemOneIgnored = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -67,10 +68,16 @@ class MainActivity : ComponentActivity() {
|
||||
if (event.repeatCount == 0) {
|
||||
cancelStemHold()
|
||||
stemHoldSent = false
|
||||
stemOneIgnored = glassesScreenIsOff()
|
||||
if (stemOneIgnored) return true
|
||||
val runnable = Runnable {
|
||||
stemHoldSent = true
|
||||
haptics.heavy()
|
||||
link.sendGesture(Gesture.LONG_PRESS_START)
|
||||
if (glassesScreenIsOff()) {
|
||||
stemOneIgnored = true
|
||||
} else {
|
||||
stemHoldSent = true
|
||||
haptics.heavy()
|
||||
link.sendGesture(Gesture.LONG_PRESS_START)
|
||||
}
|
||||
}
|
||||
stemHoldRunnable = runnable
|
||||
stemHandler.postDelayed(runnable, STEM_HOLD_MS)
|
||||
@@ -85,7 +92,7 @@ class MainActivity : ComponentActivity() {
|
||||
return true
|
||||
}
|
||||
KeyEvent.KEYCODE_STEM_3 -> {
|
||||
if (event.repeatCount == 0) {
|
||||
if (event.repeatCount == 0 && !glassesScreenIsOff()) {
|
||||
haptics.click()
|
||||
link.sendGesture(Gesture.WAKEWORD)
|
||||
}
|
||||
@@ -98,11 +105,15 @@ class MainActivity : ComponentActivity() {
|
||||
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
|
||||
if (keyCode == KeyEvent.KEYCODE_STEM_1) {
|
||||
cancelStemHold()
|
||||
if (stemOneIgnored) {
|
||||
stemOneIgnored = false
|
||||
return true
|
||||
}
|
||||
if (stemHoldSent) {
|
||||
stemHoldSent = false
|
||||
haptics.click()
|
||||
link.sendGesture(Gesture.LONG_PRESS_RELEASE)
|
||||
} else {
|
||||
} else if (!glassesScreenIsOff()) {
|
||||
haptics.click()
|
||||
link.sendGesture(Gesture.CLICK)
|
||||
}
|
||||
@@ -117,6 +128,9 @@ class MainActivity : ComponentActivity() {
|
||||
stemHoldRunnable = null
|
||||
}
|
||||
|
||||
private fun glassesScreenIsOff(): Boolean =
|
||||
link.state.value?.let { it.connected && !it.screenOn } == true
|
||||
|
||||
private companion object {
|
||||
const val STEM_HOLD_MS = 450L
|
||||
}
|
||||
|
||||
@@ -107,6 +107,8 @@ data class PhoneState(
|
||||
val windows: List<WindowEntry>,
|
||||
val apps: List<AppEntry>,
|
||||
val remoteEnabled: Boolean,
|
||||
/** False by default: clockwise moves to the previous item. */
|
||||
val crownClockwiseNext: Boolean,
|
||||
val canUnlock: Boolean,
|
||||
val mirrorAssistant: Boolean,
|
||||
val assistantAvailable: Boolean,
|
||||
@@ -151,6 +153,7 @@ data class PhoneState(
|
||||
}
|
||||
} ?: emptyList(),
|
||||
remoteEnabled = o.optBoolean("remoteEnabled", true),
|
||||
crownClockwiseNext = o.optBoolean("crownClockwiseNext", false),
|
||||
canUnlock = o.optBoolean("canUnlock", true),
|
||||
mirrorAssistant = o.optBoolean("mirrorAssistant", true),
|
||||
assistantAvailable = o.optBoolean("assistantAvailable", false),
|
||||
|
||||
@@ -37,7 +37,7 @@ data class Prefs(
|
||||
* exactly when a remote wants to stay ready.
|
||||
*/
|
||||
val keepScreenOn: Boolean = true,
|
||||
/** Swipe/crown direction follows the content (touch-scroll style) instead of the ring. */
|
||||
/** Swipe direction follows the content (touch-scroll style) instead of the ring. */
|
||||
val naturalScroll: Boolean = false,
|
||||
/** Tap the top/bottom of the pad to scroll instead of swiping. */
|
||||
val tapZones: Boolean = false,
|
||||
|
||||
@@ -64,7 +64,7 @@ fun padLine(state: PhoneState?, link: LinkStatus): StatusLine = when {
|
||||
state.remoteEnabled == false -> StatusLine("Watch control off", StatusTone.PROBLEM)
|
||||
state.connected -> when {
|
||||
state.locked -> StatusLine("Locked", StatusTone.OFF)
|
||||
!state.screenOn -> StatusLine("Screen off", StatusTone.OFF)
|
||||
!state.screenOn -> StatusLine("●● Wake", StatusTone.OFF)
|
||||
state.listening -> StatusLine("Listening…", StatusTone.BUSY)
|
||||
else -> StatusLine(state.foreground?.title ?: "Launcher", StatusTone.GOOD)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package com.faceclaw.wear.ui
|
||||
|
||||
import androidx.compose.foundation.Canvas
|
||||
import android.text.format.DateFormat
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.focusable
|
||||
@@ -24,18 +27,18 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.input.rotary.onRotaryScrollEvent
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
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
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import androidx.lifecycle.compose.LocalLifecycleOwner
|
||||
@@ -47,7 +50,6 @@ import androidx.wear.compose.material.ButtonDefaults
|
||||
import androidx.wear.compose.material.Icon
|
||||
import androidx.wear.compose.material.MaterialTheme
|
||||
import androidx.wear.compose.material.Text
|
||||
import androidx.wear.compose.material.TimeText
|
||||
import com.faceclaw.wear.Command
|
||||
import com.faceclaw.wear.FingerTapDetector
|
||||
import com.faceclaw.wear.Gesture
|
||||
@@ -59,20 +61,15 @@ import com.faceclaw.wear.R
|
||||
import com.faceclaw.wear.SwipeAction
|
||||
import com.faceclaw.wear.WristTwistDetector
|
||||
import kotlinx.coroutines.delay
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import kotlin.math.abs
|
||||
|
||||
private const val MAX_SWIPE_STEPS = 4
|
||||
/** A two-finger swipe scrolls this many steps: a "page". */
|
||||
private const val TWO_FINGER_SWIPE_STEPS = 3
|
||||
private const val FLASH_MS = 160L
|
||||
private const val ARROW_LIT_MS = 220L
|
||||
private const val RING_RADIUS_FRACTION = 0.33f
|
||||
private const val RING_CENTER_Y_FRACTION = 0.47f
|
||||
private val ARROW_INSET = 6.dp
|
||||
private val ARROW_SIZE = 18.dp
|
||||
|
||||
/** The d-pad directions, for lighting the arrow that was just swiped. */
|
||||
enum class Arrow { UP, DOWN, LEFT, RIGHT }
|
||||
private val EDGE_REVEAL_ZONE = 24.dp
|
||||
private val BUTTON_TRAY_HEIGHT = 62.dp
|
||||
|
||||
/**
|
||||
* The touchpad. The whole screen is the pad: tap = select, double-tap =
|
||||
@@ -80,8 +77,8 @@ enum class Arrow { UP, DOWN, LEFT, RIGHT }
|
||||
* the hold menu ("right click"), swipes in four directions = spatial
|
||||
* navigation (crown and two-finger vertical swipes = plain scrolling, a page
|
||||
* at a time for the latter). Fingertip pinch-taps from the motion sensors
|
||||
* select / go back, and two quick wrist twists go back. The small buttons at
|
||||
* the bottom reach the rest.
|
||||
* select / go back, and two quick wrist twists go back. An upward swipe that
|
||||
* begins at the bottom edge reveals the otherwise-hidden action buttons.
|
||||
*/
|
||||
// rememberActiveFocusRequester (rotary focus) is still experimental in Wear Compose 1.4.
|
||||
@OptIn(ExperimentalWearFoundationApi::class)
|
||||
@@ -98,14 +95,13 @@ fun RemoteScreen(
|
||||
val linkStatus by link.link.collectAsStateWithLifecycle()
|
||||
val notice by link.notice.collectAsStateWithLifecycle()
|
||||
val currentPrefs by rememberUpdatedState(prefs)
|
||||
val currentState by rememberUpdatedState(state)
|
||||
val view = LocalView.current
|
||||
var holding by remember { mutableStateOf(false) }
|
||||
// Brief ring highlight acknowledging a sensor (tip-tap) gesture.
|
||||
var flashUntil by remember { mutableStateOf(0L) }
|
||||
var flashing by remember { mutableStateOf(false) }
|
||||
// Which d-pad arrow lights up for the swipe just sent.
|
||||
var litArrow by remember { mutableStateOf<Arrow?>(null) }
|
||||
var litTick by remember { mutableStateOf(0L) }
|
||||
val density = LocalDensity.current
|
||||
val edgeRevealPx = remember(density) { with(density) { EDGE_REVEAL_ZONE.toPx() } }
|
||||
val buttonTrayHeightPx = remember(density) { with(density) { BUTTON_TRAY_HEIGHT.toPx() } }
|
||||
var controlsVisible by remember { mutableStateOf(false) }
|
||||
var longPressSent by remember { mutableStateOf(false) }
|
||||
// Rotary (crown) events are only delivered to a focused node.
|
||||
// rememberActiveFocusRequester requests focus through the hierarchical
|
||||
// focus machinery; the resume observer below takes it back after every
|
||||
@@ -130,17 +126,19 @@ fun RemoteScreen(
|
||||
onUnavailable = { haptics.error() },
|
||||
)
|
||||
|
||||
fun glassesScreenIsOff(): Boolean = currentState?.connected == true && currentState?.screenOn == false
|
||||
|
||||
fun gestureAllowed(gesture: Gesture): Boolean =
|
||||
!glassesScreenIsOff() || gesture == Gesture.DOUBLE_CLICK
|
||||
|
||||
fun scroll(gesture: Gesture, steps: Int) {
|
||||
if (!gestureAllowed(gesture)) return
|
||||
haptics.tick()
|
||||
link.sendGesture(gesture, steps)
|
||||
}
|
||||
|
||||
fun light(arrow: Arrow) {
|
||||
litArrow = arrow
|
||||
litTick = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
fun click() {
|
||||
if (!gestureAllowed(Gesture.CLICK)) return
|
||||
haptics.click()
|
||||
link.sendGesture(Gesture.CLICK)
|
||||
}
|
||||
@@ -153,12 +151,18 @@ fun RemoteScreen(
|
||||
/** Run a horizontal-swipe action; `left` says which way the finger went. */
|
||||
fun perform(action: SwipeAction, left: Boolean) {
|
||||
when (action) {
|
||||
SwipeAction.NAVIGATE -> { haptics.click(); link.sendGesture(if (left) Gesture.SWIPE_LEFT else Gesture.SWIPE_RIGHT) }
|
||||
SwipeAction.SIDEBAR -> { haptics.click(); link.sendCommand(Command.SIDEBAR) }
|
||||
SwipeAction.NAVIGATE -> {
|
||||
val gesture = if (left) Gesture.SWIPE_LEFT else Gesture.SWIPE_RIGHT
|
||||
if (gestureAllowed(gesture)) { haptics.click(); link.sendGesture(gesture) }
|
||||
}
|
||||
SwipeAction.SIDEBAR -> if (!glassesScreenIsOff()) {
|
||||
haptics.click()
|
||||
link.sendCommand(Command.SIDEBAR, "source" to "gesture")
|
||||
}
|
||||
SwipeAction.DOUBLE_CLICK -> doubleClick()
|
||||
SwipeAction.CLICK -> click()
|
||||
SwipeAction.LONG_PRESS -> { haptics.heavy(); link.sendGesture(Gesture.LONG_PRESS) }
|
||||
SwipeAction.WAKEWORD -> { haptics.click(); link.sendGesture(Gesture.WAKEWORD) }
|
||||
SwipeAction.LONG_PRESS -> if (!glassesScreenIsOff()) { haptics.heavy(); link.sendGesture(Gesture.LONG_PRESS) }
|
||||
SwipeAction.WAKEWORD -> if (!glassesScreenIsOff()) { haptics.click(); link.sendGesture(Gesture.WAKEWORD) }
|
||||
SwipeAction.NONE -> Unit
|
||||
}
|
||||
}
|
||||
@@ -196,28 +200,41 @@ fun RemoteScreen(
|
||||
}
|
||||
},
|
||||
onLongPressStart = {
|
||||
holding = true
|
||||
haptics.heavy()
|
||||
link.sendGesture(Gesture.LONG_PRESS_START)
|
||||
longPressSent = !glassesScreenIsOff()
|
||||
if (longPressSent) {
|
||||
haptics.heavy()
|
||||
link.sendGesture(Gesture.LONG_PRESS_START)
|
||||
}
|
||||
},
|
||||
onLongPressEnd = {
|
||||
holding = false
|
||||
haptics.click()
|
||||
link.sendGesture(Gesture.LONG_PRESS_RELEASE)
|
||||
if (longPressSent) {
|
||||
longPressSent = false
|
||||
haptics.click()
|
||||
link.sendGesture(Gesture.LONG_PRESS_RELEASE)
|
||||
}
|
||||
},
|
||||
onSwipe = { dx, dy, _ ->
|
||||
if (abs(dy) >= abs(dx)) {
|
||||
// One step per swipe, regardless of length: the glasses
|
||||
// repaint per step, and multi-step swipes overshot lists
|
||||
// whenever the display lagged the finger. Fast repeated
|
||||
// swiping, the crown, or a two-finger page swipe cover
|
||||
// long distances instead.
|
||||
val up = swipeIsUp(dy)
|
||||
light(if (up) Arrow.UP else Arrow.DOWN)
|
||||
scroll(if (up) Gesture.SWIPE_UP else Gesture.SWIPE_DOWN, 1)
|
||||
} else {
|
||||
light(if (dx < 0) Arrow.LEFT else Arrow.RIGHT)
|
||||
perform(if (dx < 0) currentPrefs.swipeLeft else currentPrefs.swipeRight, left = dx < 0)
|
||||
onSwipe = { start, dx, dy, _ ->
|
||||
val vertical = abs(dy) >= abs(dx)
|
||||
val padBottom = padHeight[0]
|
||||
when {
|
||||
vertical && !controlsVisible && dy < 0 && start.y >= padBottom - edgeRevealPx -> {
|
||||
controlsVisible = true
|
||||
haptics.click()
|
||||
}
|
||||
vertical && controlsVisible && dy > 0 && start.y >= padBottom - buttonTrayHeightPx -> {
|
||||
controlsVisible = false
|
||||
haptics.click()
|
||||
}
|
||||
vertical -> {
|
||||
// One step per swipe, regardless of length: the glasses
|
||||
// repaint per step, and multi-step swipes overshot lists
|
||||
// whenever the display lagged the finger. Fast repeated
|
||||
// swiping, the crown, or a two-finger page swipe cover
|
||||
// long distances instead.
|
||||
val up = swipeIsUp(dy)
|
||||
scroll(if (up) Gesture.SWIPE_UP else Gesture.SWIPE_DOWN, 1)
|
||||
}
|
||||
else -> perform(if (dx < 0) currentPrefs.swipeLeft else currentPrefs.swipeRight, left = dx < 0)
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -235,8 +252,8 @@ fun RemoteScreen(
|
||||
sensitivity = { currentPrefs.tapSensitivity },
|
||||
quietUntil = { haptics.quietUntil() },
|
||||
onBody = { onBody.onBody },
|
||||
onTap = { flashUntil = System.currentTimeMillis() + FLASH_MS; click() },
|
||||
onDoubleTap = { flashUntil = System.currentTimeMillis() + FLASH_MS; doubleClick() },
|
||||
onTap = { click() },
|
||||
onDoubleTap = { doubleClick() },
|
||||
)
|
||||
}
|
||||
WhileStartedEffect(fingerTapDetector, start = { fingerTapDetector?.start() }, stop = { fingerTapDetector?.stop() })
|
||||
@@ -248,21 +265,10 @@ fun RemoteScreen(
|
||||
sensitivity = { currentPrefs.twistSensitivity },
|
||||
quietUntil = { haptics.quietUntil() },
|
||||
onBody = { onBody.onBody },
|
||||
onDoubleTwist = { flashUntil = System.currentTimeMillis() + FLASH_MS; doubleClick() },
|
||||
onDoubleTwist = { doubleClick() },
|
||||
)
|
||||
}
|
||||
WhileStartedEffect(wristTwistDetector, start = { wristTwistDetector?.start() }, stop = { wristTwistDetector?.stop() })
|
||||
LaunchedEffect(litTick) {
|
||||
if (litTick == 0L) return@LaunchedEffect
|
||||
delay(ARROW_LIT_MS)
|
||||
litArrow = null
|
||||
}
|
||||
LaunchedEffect(flashUntil) {
|
||||
if (flashUntil == 0L) return@LaunchedEffect
|
||||
flashing = true
|
||||
delay((flashUntil - System.currentTimeMillis()).coerceAtLeast(1L))
|
||||
flashing = false
|
||||
}
|
||||
|
||||
// A refused or unanswered gesture gets a distinct buzz, so the wrist knows
|
||||
// without looking (the notice pill says why).
|
||||
@@ -275,15 +281,16 @@ fun RemoteScreen(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.onRotaryScrollEvent { event ->
|
||||
// Clockwise (positive) scrolls down, as in every Wear list.
|
||||
crownAccumulator += event.verticalScrollPixels
|
||||
val threshold = currentPrefs.crownSensitivity.pixelsPerStep
|
||||
var steps = 0
|
||||
while (crownAccumulator >= threshold) { crownAccumulator -= threshold; steps++ }
|
||||
while (crownAccumulator <= -threshold) { crownAccumulator += threshold; steps-- }
|
||||
// Capped low: a fast twirl otherwise outruns the display.
|
||||
if (steps > 0) { light(Arrow.DOWN); scroll(Gesture.SCROLL_DOWN, steps.coerceAtMost(2)) }
|
||||
if (steps < 0) { light(Arrow.UP); scroll(Gesture.SCROLL_UP, (-steps).coerceAtMost(2)) }
|
||||
val clockwise = if (currentState?.crownClockwiseNext == true) Gesture.SCROLL_DOWN else Gesture.SCROLL_UP
|
||||
val counterClockwise = if (currentState?.crownClockwiseNext == true) Gesture.SCROLL_UP else Gesture.SCROLL_DOWN
|
||||
if (steps > 0) scroll(clockwise, steps.coerceAtMost(2))
|
||||
if (steps < 0) scroll(counterClockwise, (-steps).coerceAtMost(2))
|
||||
true
|
||||
}
|
||||
.focusRequester(focusRequester)
|
||||
@@ -291,68 +298,47 @@ fun RemoteScreen(
|
||||
.onSizeChanged { padHeight[0] = it.height.toFloat() }
|
||||
.pointerInput(callbacks) { detectTouchpadGestures(callbacks) },
|
||||
) {
|
||||
// The pad: a ring with a d-pad arrow at each compass point (the one
|
||||
// you swiped lights up), the current glasses app in the middle, and
|
||||
// the tap legend under it. Brightens while a hold is in progress.
|
||||
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
|
||||
val ringRadius = minOf(maxWidth, maxHeight) * RING_RADIUS_FRACTION
|
||||
val ringCenterY = maxHeight * RING_CENTER_Y_FRACTION
|
||||
val ringColor = if (holding || flashing) MaterialTheme.colors.primary else Color(0xFF2E2E2E)
|
||||
Canvas(modifier = Modifier.fillMaxSize()) {
|
||||
drawCircle(
|
||||
color = ringColor,
|
||||
radius = ringRadius.toPx(),
|
||||
center = Offset(size.width / 2f, ringCenterY.toPx()),
|
||||
style = Stroke(width = if (holding || flashing) 4f else 2f),
|
||||
)
|
||||
}
|
||||
StraightTime(modifier = Modifier.align(Alignment.Center))
|
||||
|
||||
TimeText()
|
||||
|
||||
ArrowGlyph("▲", litArrow == Arrow.UP, Modifier.align(Alignment.TopCenter).padding(top = ringCenterY - ringRadius + ARROW_INSET))
|
||||
ArrowGlyph("▼", litArrow == Arrow.DOWN, Modifier.align(Alignment.TopCenter).padding(top = ringCenterY + ringRadius - ARROW_INSET - ARROW_SIZE))
|
||||
ArrowGlyph("◀", litArrow == Arrow.LEFT, Modifier.align(Alignment.TopStart).padding(start = maxWidth / 2 - ringRadius + ARROW_INSET, top = ringCenterY - ARROW_SIZE / 2))
|
||||
ArrowGlyph("▶", litArrow == Arrow.RIGHT, Modifier.align(Alignment.TopEnd).padding(end = maxWidth / 2 - ringRadius + ARROW_INSET, top = ringCenterY - ARROW_SIZE / 2))
|
||||
|
||||
// The single status indicator: what the next gesture lands on (the
|
||||
// app on the glasses, or the screen/lock state in the way of it),
|
||||
// or the connection problem to fix first. Above the centre line;
|
||||
// the tap legend below it, clear of the side arrows.
|
||||
AnimatedVisibility(
|
||||
visible = !controlsVisible,
|
||||
enter = fadeIn(),
|
||||
exit = fadeOut(),
|
||||
modifier = Modifier.align(Alignment.Center).offset(y = 46.dp),
|
||||
) {
|
||||
val pad = padLine(state, linkStatus)
|
||||
Text(
|
||||
text = if (holding) "holding" else pad.text,
|
||||
text = pad.text,
|
||||
style = MaterialTheme.typography.title3,
|
||||
color = when {
|
||||
holding -> MaterialTheme.colors.primary
|
||||
pad.tone == StatusTone.GOOD -> MaterialTheme.colors.onSurface
|
||||
else -> pad.tone.color()
|
||||
},
|
||||
color = if (pad.tone == StatusTone.GOOD) MaterialTheme.colors.onSurface else pad.tone.color(),
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopCenter)
|
||||
.padding(top = ringCenterY - 44.dp, start = 60.dp, end = 60.dp),
|
||||
)
|
||||
Text(
|
||||
text = if (prefs.tapZones) "▲▼ tap zones · ● select" else "● select ●● back ‒ menu",
|
||||
style = MaterialTheme.typography.caption3,
|
||||
color = MaterialTheme.colors.onSurfaceVariant,
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 1,
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopCenter)
|
||||
.padding(top = ringCenterY + 18.dp, start = 56.dp, end = 56.dp),
|
||||
modifier = Modifier.padding(horizontal = 42.dp),
|
||||
)
|
||||
}
|
||||
|
||||
AnimatedVisibility(
|
||||
visible = controlsVisible,
|
||||
enter = slideInVertically(initialOffsetY = { it }),
|
||||
exit = slideOutVertically(targetOffsetY = { it }),
|
||||
modifier = Modifier.align(Alignment.BottomCenter),
|
||||
) {
|
||||
Row(
|
||||
// Four 36dp buttons need 144dp; at this height the round
|
||||
// display's chord is ~186dp wide, so 36dp margins keep every
|
||||
// button inside the glass.
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomCenter)
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 36.dp, vertical = 26.dp),
|
||||
.height(BUTTON_TRAY_HEIGHT)
|
||||
.pointerInput(Unit) {
|
||||
detectTrayDismiss {
|
||||
controlsVisible = false
|
||||
haptics.click()
|
||||
}
|
||||
}
|
||||
.padding(horizontal = 36.dp)
|
||||
.padding(bottom = 26.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
@@ -393,14 +379,27 @@ private fun WhileStartedEffect(key: Any?, start: () -> Unit, stop: () -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
/** A large, straight clock fixed on the vertical centre of the touchpad. */
|
||||
@Composable
|
||||
private fun ArrowGlyph(glyph: String, lit: Boolean, modifier: Modifier) {
|
||||
private fun StraightTime(modifier: Modifier = Modifier) {
|
||||
val context = LocalContext.current
|
||||
var now by remember { mutableStateOf(System.currentTimeMillis()) }
|
||||
val pattern = remember(context) { if (DateFormat.is24HourFormat(context)) "HH:mm" else "h:mm" }
|
||||
val formatter = remember(pattern) { SimpleDateFormat(pattern, Locale.getDefault()) }
|
||||
LaunchedEffect(Unit) {
|
||||
while (true) {
|
||||
val current = System.currentTimeMillis()
|
||||
now = current
|
||||
delay(60_000L - current % 60_000L)
|
||||
}
|
||||
}
|
||||
Text(
|
||||
text = glyph,
|
||||
style = MaterialTheme.typography.caption1,
|
||||
color = if (lit) MaterialTheme.colors.primary else Color(0xFF6E6E6E),
|
||||
text = formatter.format(Date(now)),
|
||||
color = MaterialTheme.colors.onSurface,
|
||||
fontSize = 42.sp,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = modifier.size(ARROW_SIZE),
|
||||
maxLines = 1,
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,10 @@ import androidx.compose.foundation.gestures.awaitEachGesture
|
||||
import androidx.compose.foundation.gestures.awaitFirstDown
|
||||
import androidx.compose.foundation.gestures.waitForUpOrCancellation
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.input.pointer.PointerEventPass
|
||||
import androidx.compose.ui.input.pointer.PointerInputScope
|
||||
import androidx.compose.ui.input.pointer.positionChanged
|
||||
import kotlin.math.abs
|
||||
|
||||
/** What the remote's touch surface can report. */
|
||||
class TouchpadCallbacks(
|
||||
@@ -17,7 +19,7 @@ class TouchpadCallbacks(
|
||||
val onLongPressStart: () -> Unit,
|
||||
val onLongPressEnd: () -> Unit,
|
||||
/** Finger travelled past touch slop; dx/dy are the total displacement. */
|
||||
val onSwipe: (dx: Float, dy: Float, durationMs: Long) -> Unit,
|
||||
val onSwipe: (start: Offset, dx: Float, dy: Float, durationMs: Long) -> Unit,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -86,7 +88,7 @@ suspend fun PointerInputScope.detectTouchpadGestures(callbacks: TouchpadCallback
|
||||
callbacks.onLongPressEnd()
|
||||
}
|
||||
maxPointers >= 2 -> if (moved) callbacks.onTwoFingerSwipe(displacement.x, displacement.y) else callbacks.onTwoFingerTap()
|
||||
moved -> callbacks.onSwipe(displacement.x, displacement.y, duration)
|
||||
moved -> callbacks.onSwipe(down.position, displacement.x, displacement.y, duration)
|
||||
else -> {
|
||||
// A plain tap; give a second tap a chance to make it a double.
|
||||
val second = withTimeoutOrNull(doubleTapTimeout) { awaitFirstDown() }
|
||||
@@ -108,6 +110,30 @@ suspend fun PointerInputScope.detectTouchpadGestures(callbacks: TouchpadCallback
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Observe the button tray before its child buttons consume a pointer. A
|
||||
* downward drag claims the gesture and dismisses the tray; a tap remains
|
||||
* untouched so the button below receives its normal click.
|
||||
*/
|
||||
suspend fun PointerInputScope.detectTrayDismiss(onDismiss: () -> Unit) {
|
||||
val slop = viewConfiguration.touchSlop
|
||||
awaitEachGesture {
|
||||
val down = awaitFirstDown(requireUnconsumed = false, pass = PointerEventPass.Initial)
|
||||
var dismissed = false
|
||||
while (true) {
|
||||
val event = awaitPointerEvent(PointerEventPass.Initial)
|
||||
val primary = event.changes.firstOrNull { it.id == down.id } ?: event.changes.first()
|
||||
val displacement = primary.position - down.position
|
||||
if (!dismissed && displacement.y > slop && displacement.y >= abs(displacement.x)) {
|
||||
dismissed = true
|
||||
onDismiss()
|
||||
}
|
||||
if (dismissed) event.changes.forEach { it.consume() }
|
||||
if (event.changes.none { it.pressed }) break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Poll interval while a hold or drag is in progress (no timeout semantics needed). */
|
||||
private const val HOLD_POLL_MS = 60_000L
|
||||
|
||||
|
||||
Reference in new issue
Block a user