Debloat your Android TV, install apps, browse and transfer files on it, all from your phone. Just 3 MB, no tracking, no root, no PC.
Touchpad: repeat only once the finger is still; type hint off when cramped
jesse-agent-2323d1bebf82f38
diff --git a/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt b/app/src/main/java/app/tellyscope/ui/RemoteScreen.ktindex 84e0f53..9970b01 100644--- a/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt@@ -2,6 +2,8 @@package app.tellyscope.ui+import android.os.SystemClock+import android.view.accessibility.AccessibilityManagerimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.clickableimport androidx.compose.foundation.gestures.awaitEachGesture@@ -35,6 +37,7 @@ import androidx.compose.material.icons.Iconsimport androidx.compose.material.icons.automirrored.filled.ArrowBackimport androidx.compose.material.icons.automirrored.filled.Sendimport androidx.compose.material.icons.filled.Add+import androidx.compose.material.icons.filled.Checkimport androidx.compose.material.icons.filled.Menuimport androidx.compose.material.icons.filled.KeyboardArrowDownimport androidx.compose.material.icons.filled.KeyboardArrowLeft@@ -42,14 +45,6 @@ import androidx.compose.material.icons.filled.KeyboardArrowRightimport androidx.compose.material.icons.filled.KeyboardArrowUpimport androidx.compose.material.icons.outlined.Homeimport androidx.compose.material.icons.outlined.Info-import androidx.compose.material.icons.filled.Check-import androidx.compose.runtime.DisposableEffect-import androidx.compose.ui.focus.FocusRequester-import androidx.compose.ui.focus.focusRequester-import androidx.compose.ui.focus.onFocusChanged-import androidx.compose.ui.semantics.selected-import android.view.accessibility.AccessibilityManager-import kotlin.math.absimport androidx.compose.material3.AlertDialogimport androidx.compose.material3.Buttonimport androidx.compose.material3.Card@@ -81,6 +76,7 @@ import androidx.compose.material3.rippleimport androidx.compose.material3.toShapeimport androidx.compose.runtime.Composableimport androidx.compose.runtime.CompositionLocalProvider+import androidx.compose.runtime.DisposableEffectimport androidx.compose.runtime.LaunchedEffectimport androidx.compose.runtime.collectAsStateimport androidx.compose.runtime.getValue@@ -97,6 +93,9 @@ import androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.alphaimport androidx.compose.ui.draw.clip+import androidx.compose.ui.focus.FocusRequester+import androidx.compose.ui.focus.focusRequester+import androidx.compose.ui.focus.onFocusChangedimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.graphics.PathFillTypeimport androidx.compose.ui.graphics.Shape@@ -119,6 +118,7 @@ import androidx.compose.ui.semantics.contentDescriptionimport androidx.compose.ui.semantics.customActionsimport androidx.compose.ui.semantics.onClickimport androidx.compose.ui.semantics.role+import androidx.compose.ui.semantics.selectedimport androidx.compose.ui.semantics.semanticsimport androidx.compose.ui.text.input.ImeActionimport androidx.compose.ui.text.style.TextOverflow@@ -158,6 +158,7 @@ import app.tellyscope.data.DeviceStateimport app.tellyscope.data.Dockimport app.tellyscope.data.Dockedimport kotlin.math.roundToInt+import kotlin.math.absimport kotlinx.coroutines.delayimport kotlinx.coroutines.launchimport androidx.compose.foundation.layout.fillMaxHeight@@ -284,7 +285,8 @@ fun RemoteScreen(else if (keyboardShown) { keyboardShown = false; keyboard = false }}// A swipe pad can't be explored by touch, so TalkBack always gets the D-pad.- val pad = state.touchpad && !talkBackOn()+ val talkBack = talkBackOn()+ val pad = state.touchpad && !talkBackif (editing) ButtonsSheet(state.device.dock, state.device.apps, cap, actions.setDock, onDismiss = { editing = false })ModalBottomSheet(@@ -319,7 +321,7 @@ fun RemoteScreen(horizontalAlignment = Alignment.CenterHorizontally,) {RemoteHeader(state, device, restart, screenOff, onRestartTap = { hidden = null }) {- HeaderMenu(screenControl, screenOff, live, showTip = state.screenOffTip, actions, pad = if (talkBackOn()) null else pad, onRestart = { confirmReboot = true }, onButtons = { editing = true })+ HeaderMenu(screenControl, screenOff, live, showTip = state.screenOffTip, actions, pad = if (talkBack) null else pad, onRestart = { confirmReboot = true }, onButtons = { editing = true })}CompositionLocalProvider(LocalKeyHaptics provides state.keyHaptics) { Column(Modifier.weight(1f).alpha(if (live) 1f else 0.38f),@@ -390,7 +392,7 @@ fun RemoteScreen(if (keyboard) {Spacer(Modifier.height(rowGap))Keyboard(- live, actions.type, actions.press, onClose = { keyboard = false },+ live, actions.type, actions.press, hint = !tight, onClose = { keyboard = false },modifier = Modifier.onGloballyPositioned { field = it.boundsInWindow() },)DisposableEffect(Unit) { onDispose { field = Rect.Zero } }@@ -558,8 +560,8 @@ private fun KeySurface(/*** The text box the keyboard key opens: focused at once, so the phone's keyboard comes up under it.- * [onClose] once it loses focus, a tap outside. The hint shows under it until something is typed;- * as a placeholder it would be cut to half its length.+ * [onClose] once it loses focus, a tap outside. The hint shows under it until something is typed,+ * unless [hint] is off on a screen too short for it; as a placeholder it would be cut to half its length.*/@Composable@OptIn(ExperimentalMaterial3Api::class)@@ -567,6 +569,7 @@ private fun Keyboard(enabled: Boolean,type: (String) -> UiText?,press: suspend (RemoteKey) -> Boolean,+ hint: Boolean,onClose: () -> Unit,modifier: Modifier = Modifier,) {@@ -585,7 +588,7 @@ private fun Keyboard(onValueChange = { text = it; error = null },enabled = enabled,label = { Text(stringResource(R.string.remote_type_label)) },- supportingText = if (error != null || text.isEmpty()) ({ Text(error ?: Copy.TYPE_HINT.resolve()) }) else null,+ supportingText = if (error != null || (hint && text.isEmpty())) ({ Text(error ?: Copy.TYPE_HINT.resolve()) }) else null,isError = error != null,singleLine = true,keyboardOptions = KeyboardOptions(imeAction = ImeAction.Send),@@ -638,6 +641,24 @@ private fun KeyboardKey(enabled: Boolean, size: Dp = 64.dp, onClick: () -> Unit)}}+/**+ * A touchpad swipe's arrow: one press, then repeats while [held], but only once the finger has been+ * still for [REPEAT_AFTER_MS]. A slow swipe still moving past the threshold sends just the one.+ */+internal suspend fun repeatWhileStill(+ key: RemoteKey,+ held: () -> Boolean,+ stillFor: () -> Long,+ press: suspend (RemoteKey) -> Boolean,+) {+ if (!press(key)) return+ while (true) {+ delay(REPEAT_EVERY_MS)+ if (!held()) return+ if (stillFor() >= REPEAT_AFTER_MS && !press(key)) return+ }+}+/** Swipes past this send an arrow; under the touch slop a lift is a tap, and in between nothing. */private val SWIPE = 40.dp@@ -669,9 +690,16 @@ private fun Touchpad(enabled: Boolean, press: suspend (RemoteKey) -> Boolean, movar held = truevar moved = Offset.Zerovar tapped = false+ // Where the finger last settled, and when it last moved past the slop from there.+ var anchor = down.position+ var movedAt = 0Lwhile (true) {val change = awaitPointerEvent().changes.firstOrNull { it.id == down.id } ?: breakmoved = change.position - down.position+ if ((change.position - anchor).getDistance() > viewConfiguration.touchSlop) {+ anchor = change.position+ movedAt = change.uptimeMillis+ }// Read before consuming: changedToUp() is false for a consumed change.val up = change.changedToUp()change.consume()@@ -679,7 +707,7 @@ private fun Touchpad(enabled: Boolean, press: suspend (RemoteKey) -> Boolean, moif (key == null && moved.getDistance() >= swipe) {val k = swipeKey(moved.x, moved.y).also { key = it }if (haptics) haptic.performHapticFeedback(HapticFeedbackType.VirtualKey)- scope.launch { repeatWhileHeld(k, { held }, press = press) }+ scope.launch { repeatWhileStill(k, { held }, stillFor = { SystemClock.uptimeMillis() - movedAt }, press = press) }}}held = falsediff --git a/app/src/test/java/app/tellyscope/TouchpadTest.kt b/app/src/test/java/app/tellyscope/TouchpadTest.ktindex 6fa702b..a9eb25c 100644--- a/app/src/test/java/app/tellyscope/TouchpadTest.kt+++ b/app/src/test/java/app/tellyscope/TouchpadTest.kt@@ -4,8 +4,11 @@ package app.tellyscopeimport app.tellyscope.adb.RemoteKeyimport app.tellyscope.data.KeyHaptics+import app.tellyscope.ui.repeatWhileStillimport app.tellyscope.ui.swipeKeyimport java.io.File+import kotlinx.coroutines.test.currentTime+import kotlinx.coroutines.test.runTestimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertFalseimport org.junit.Assert.assertTrue@@ -25,6 +28,21 @@ class TouchpadTest {assertEquals(RemoteKey.RIGHT, swipeKey(40f, 40f))}+ @Test fun aSwipeStillMovingSendsOneArrow() = runTest {+ var presses = 0+ // A slow swipe: a second of the finger never settling, then the lift.+ repeatWhileStill(RemoteKey.RIGHT, held = { currentTime < 1_000 }, stillFor = { 0 }) { presses++; true }+ assertEquals(1, presses)+ }++ @Test fun aSwipeHeldStillRepeatsAfterTheDelay() = runTest {+ var presses = 0+ // Moving for 300 ms, then still: repeats begin 400 ms after it stopped, at 700 ms.+ repeatWhileStill(RemoteKey.RIGHT, held = { currentTime < 1_000 }, stillFor = { (currentTime - 300).coerceAtLeast(0) }) { presses++; true }+ // The first press, then one every 50 ms from 700 to 950.+ assertEquals(1 + 6, presses)+ }+@Test fun theModeIsKeptForThePhoneAndTheDpadIsTheDefault() {val file = File(dir.root, "remote.properties")assertFalse(KeyHaptics(file).touchpad)