Implement press-and-hold for glanceboard in watch and simulated inputs

This commit is contained in:
James Babcock committed 2026-09-11 19:34:50 -07:00
1 parent cd1e815174
commit 4681f14dae
4 files changed
+43 -16

No files matched your search

@@ -139,16 +139,13 @@ class MainActivity : ComponentActivity() {
if (event.repeatCount == 0) {
cancelStemHold()
stemHoldSent = false
stemOneIgnored = glassesScreenIsOff()
if (stemOneIgnored) return true
// A dark display takes the stem too: a press shows the
// phone's Glanceboard, a hold keeps it up until release.
stemOneIgnored = false
val runnable = Runnable {
if (glassesScreenIsOff()) {
stemOneIgnored = true
} else {
stemHoldSent = true
haptics.heavy()
link.sendGesture(Gesture.LONG_PRESS_START)
}
stemHoldSent = true
haptics.heavy()
link.sendGesture(Gesture.LONG_PRESS_START)
}
stemHoldRunnable = runnable
stemHandler.postDelayed(runnable, STEM_HOLD_MS)
@@ -184,7 +181,7 @@ class MainActivity : ComponentActivity() {
stemHoldSent = false
haptics.click()
link.sendGesture(Gesture.LONG_PRESS_RELEASE)
} else if (!glassesScreenIsOff()) {
} else {
haptics.click()
link.sendGesture(Gesture.CLICK)
}
@@ -143,8 +143,16 @@ fun RemoteScreen(
fun glassesScreenIsOff(): Boolean = currentState?.connected == true && currentState?.screenOn == false
// A dark display still takes a double-click (wake), and a tap or a hold
// (the phone's Glanceboard: a tap shows it for a few seconds, a hold
// until released). Scrolls, swipes and the menu gesture mean nothing
// there, so they are dropped here without a buzz.
fun gestureAllowed(gesture: Gesture): Boolean =
!glassesScreenIsOff() || gesture == Gesture.DOUBLE_CLICK
!glassesScreenIsOff() ||
gesture == Gesture.DOUBLE_CLICK ||
gesture == Gesture.CLICK ||
gesture == Gesture.LONG_PRESS_START ||
gesture == Gesture.LONG_PRESS_RELEASE
fun scroll(gesture: Gesture, steps: Int) {
if (!gestureAllowed(gesture)) return
@@ -186,7 +194,7 @@ fun RemoteScreen(
}
},
onLongPressStart = {
longPressSent = !glassesScreenIsOff()
longPressSent = gestureAllowed(Gesture.LONG_PRESS_START)
if (longPressSent) {
haptics.heavy()
link.sendGesture(Gesture.LONG_PRESS_START)