mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
feat: add configurable touchscreen gestures (#940)
This commit is contained in:
1 parent
fd74819c50
commit
fe7b75318a
55 files changed
+7404
-14
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class GestureActionsTest {
|
||||
@Test fun categoryActionsAreAlphabeticalIncludingFilteredResults() {
|
||||
val actions = listOf("Z", "C", "A", "B").map { GestureAction("key_$it", it, GestureActionGroup.LETTERS) } +
|
||||
listOf("Right click", "Middle click", "Left click").map { GestureAction(it, it, GestureActionGroup.MOUSE) }
|
||||
assertEquals(listOf("A", "B", "C", "Z"), filterGestureActions(actions, "", GestureActionGroup.LETTERS).map { it.title })
|
||||
assertEquals(listOf("Left click", "Middle click", "Right click"), filterGestureActions(actions, "click", null).map { it.title })
|
||||
}
|
||||
|
||||
@Test fun numberedFunctionKeysStayInNumericOrder() {
|
||||
val actions = listOf(12, 2, 10, 1).map { GestureAction("key_F$it", "F$it", GestureActionGroup.FUNCTION) }
|
||||
assertEquals(listOf("F1", "F2", "F10", "F12"), filterGestureActions(actions, "", null).map { it.title })
|
||||
}
|
||||
|
||||
@Test fun actionGroupsKeepKeysAndMouseBindingsInTheirOwnCategories() {
|
||||
assertEquals(GestureActionGroup.MOUSE, gestureActionGroup("middle_mouse_pan"))
|
||||
assertEquals(GestureActionGroup.LETTERS, gestureActionGroup("key_F"))
|
||||
assertEquals(GestureActionGroup.FUNCTION, gestureActionGroup("key_F12"))
|
||||
assertEquals(GestureActionGroup.NUMPAD, gestureActionGroup("key_KP_ENTER"))
|
||||
assertEquals(GestureActionGroup.MODIFIERS, gestureActionGroup("key_CTRL_R"))
|
||||
}
|
||||
|
||||
@Test fun searchCombinesWordsAndCategoryWithoutChangingTheSelection() {
|
||||
val actions = listOf(
|
||||
GestureAction("key_ENTER", "Enter", GestureActionGroup.NAVIGATION),
|
||||
GestureAction("key_KP_ENTER", "Numpad Enter", GestureActionGroup.NUMPAD),
|
||||
GestureAction("key_KP_1", "Numpad 1", GestureActionGroup.NUMPAD),
|
||||
)
|
||||
assertEquals(listOf(actions[1]), filterGestureActions(actions, " ENTER numpad ", null))
|
||||
assertEquals(listOf(actions[1]), filterGestureActions(actions, "enter", GestureActionGroup.NUMPAD))
|
||||
assertTrue(filterGestureActions(actions, "not a key", null).isEmpty())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.app.Application
|
||||
import android.view.View
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.test.*
|
||||
import androidx.compose.ui.unit.Density
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.GesturePrefs
|
||||
import com.droiddeck.launcher.input.TouchGestureConfig
|
||||
import com.droiddeck.launcher.input.TouchscreenGestures.Gesture
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class, qualifiers = "w400dp-h850dp-port")
|
||||
class GestureLocalizationTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
private val context get() = RuntimeEnvironment.getApplication()
|
||||
|
||||
@Before fun clearPrefs() {
|
||||
context.getSharedPreferences("touch_gestures", 0).edit().clear().commit()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "fr-rFR-w400dp-h850dp-port")
|
||||
fun pageKeysAndModifierNamesUseLocalizedResources() {
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
Column {
|
||||
Text(gestureActionTitle("page_up_down"))
|
||||
Text(gestureActionTitle("key_SHIFT_L"))
|
||||
}
|
||||
}
|
||||
}
|
||||
compose.onNodeWithText("Page précédente / Page suivante").assertIsDisplayed()
|
||||
compose.onNodeWithText("Maj gauche").assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "de-rDE-w400dp-h850dp-port")
|
||||
fun longTranslationsKeepDefaultRestorationAndSaveUsable() {
|
||||
GesturePrefs.save(context, "123", TouchGestureConfig(tapAction = "key_E"))
|
||||
compose.setContent {
|
||||
val density = LocalDensity.current
|
||||
CompositionLocalProvider(LocalDensity provides Density(density.density, fontScale = 1.5f)) {
|
||||
DroidDeckTheme { TouchGestureDialog("123", {}, {}) }
|
||||
}
|
||||
}
|
||||
val restore = compose.onNodeWithTag("gesture-inherit")
|
||||
restore.assertIsDisplayed()
|
||||
val scope = compose.onNodeWithTag("gesture-scope-game").fetchSemanticsNode().boundsInRoot
|
||||
assertTrue("The restore action must have room for its translated label", restore.fetchSemanticsNode().boundsInRoot.width > scope.width)
|
||||
restore.performClick()
|
||||
compose.onNodeWithTag("gesture-save").assertIsDisplayed().performClick()
|
||||
compose.runOnIdle { assertFalse(GesturePrefs.hasOverride(context, "123")) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "ar-rEG-w400dp-h850dp-port")
|
||||
fun arabicPickerSearchPreservesBindingsAndMirrorsFooter() {
|
||||
assertEquals(View.LAYOUT_DIRECTION_RTL, context.resources.configuration.layoutDirection)
|
||||
compose.setContent { DroidDeckTheme { TouchGestureDialog(null, {}, {}) } }
|
||||
compose.onNodeWithText("إعدادات إيماءات اللمس").assertIsDisplayed()
|
||||
val save = compose.onNodeWithTag("gesture-save").fetchSemanticsNode().boundsInRoot
|
||||
val cancel = compose.onNodeWithText(context.getString(R.string.gesture_cancel)).fetchSemanticsNode().boundsInRoot
|
||||
assertTrue("Save $save and Cancel $cancel should follow the right-to-left layout", save.left < cancel.left)
|
||||
compose.onNodeWithTag("gesture-choice-tap").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("gesture-action-search").performTextInput("هروب")
|
||||
compose.onNodeWithTag("gesture-action-key_ESC").assertIsDisplayed().performClick()
|
||||
compose.onNodeWithTag("gesture-save").performClick()
|
||||
compose.runOnIdle { assertEquals("key_ESC", GesturePrefs.read(context).tapAction) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "ja-rJP-w400dp-h850dp-port")
|
||||
fun recognizedGestureFeedbackUsesTheActiveLanguage() {
|
||||
compose.setContent { DroidDeckTheme { GestureFeedback(Gesture.TWO_FINGER_HOLD) } }
|
||||
compose.onNodeWithText("2本指で長押し").assertIsDisplayed()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.app.Application
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.snapshots.Snapshot
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.unit.Density
|
||||
import androidx.compose.ui.test.*
|
||||
import com.droiddeck.launcher.input.GesturePrefs
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class, qualifiers = "w960dp-h640dp-land")
|
||||
class TouchGestureDialogTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
private val context get() = RuntimeEnvironment.getApplication()
|
||||
|
||||
@Before fun clearPrefs() {
|
||||
context.getSharedPreferences("touch_gestures", 0).edit().clear().commit()
|
||||
}
|
||||
|
||||
@Test fun searchSelectAndSaveAKeyboardAction() {
|
||||
compose.setContent { DroidDeckTheme { TouchGestureDialog(null, {}, {}) } }
|
||||
compose.onNodeWithTag("gesture-choice-tap").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("gesture-action-left_click").assertIsSelected()
|
||||
compose.onNodeWithTag("gesture-action-search").performTextInput("numpad enter")
|
||||
compose.onNodeWithTag("gesture-action-key_KP_ENTER").assertIsDisplayed().performClick()
|
||||
compose.onNodeWithTag("gesture-save").performClick()
|
||||
compose.runOnIdle { assertEquals("key_KP_ENTER", GesturePrefs.read(context).tapAction) }
|
||||
}
|
||||
|
||||
@Test fun switchingTabsKeepsEditsAndLetsTwoFingerPanBeChanged() {
|
||||
compose.setContent { DroidDeckTheme { TouchGestureDialog(null, {}, {}) } }
|
||||
compose.onNodeWithTag("gesture-tab-1").performClick()
|
||||
compose.onNodeWithTag("gesture-choice-two-drag").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("gesture-action-search").performTextInput("middle mouse pan")
|
||||
compose.onNodeWithTag("gesture-action-middle_mouse_pan").performClick()
|
||||
compose.onNodeWithTag("gesture-tab-3").performClick()
|
||||
compose.onNodeWithTag("gesture-tab-1").performClick()
|
||||
compose.onNodeWithText("Middle mouse pan").performScrollTo().assertIsDisplayed()
|
||||
compose.onNodeWithTag("gesture-save").performClick()
|
||||
compose.runOnIdle { assertEquals("middle_mouse_pan", GesturePrefs.read(context).twoFingerDragAction) }
|
||||
}
|
||||
|
||||
@Test fun closingWithoutSavingDiscardsTheDraft() {
|
||||
val open = mutableStateOf(true)
|
||||
compose.setContent { DroidDeckTheme { if (open.value) TouchGestureDialog(null, { open.value = false }, {}) } }
|
||||
chooseTap("Escape", "key_ESC")
|
||||
compose.onNodeWithContentDescription("Close").performClick()
|
||||
compose.runOnIdle { assertEquals("left_click", GesturePrefs.read(context).tapAction) }
|
||||
}
|
||||
|
||||
@Test fun defaultsAndGameDraftsSurviveScopeChangesAndSaveTogether() {
|
||||
compose.setContent { DroidDeckTheme { TouchGestureDialog("123", {}, {}) } }
|
||||
chooseTap("numpad enter", "key_KP_ENTER")
|
||||
compose.onNodeWithTag("gesture-scope-default").performClick()
|
||||
chooseTap("Escape", "key_ESC")
|
||||
compose.onNodeWithTag("gesture-scope-game").performClick()
|
||||
compose.onNodeWithTag("gesture-choice-tap").performScrollTo()
|
||||
compose.onNodeWithText("Numpad Enter").assertIsDisplayed()
|
||||
compose.onNodeWithTag("gesture-save").performClick()
|
||||
compose.runOnIdle {
|
||||
assertEquals("key_ESC", GesturePrefs.read(context).tapAction)
|
||||
assertEquals("key_KP_ENTER", GesturePrefs.read(context, "123").tapAction)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aFocusChangeCannotRetargetAnOpenGameEditor() {
|
||||
val game = mutableStateOf("123")
|
||||
compose.setContent { DroidDeckTheme { TouchGestureDialog(game.value, {}, {}) } }
|
||||
chooseTap("Escape", "key_ESC")
|
||||
compose.runOnIdle {
|
||||
game.value = "456"
|
||||
Snapshot.sendApplyNotifications()
|
||||
}
|
||||
compose.onNodeWithTag("gesture-save").performClick()
|
||||
compose.runOnIdle {
|
||||
assertEquals("key_ESC", GesturePrefs.read(context, "123").tapAction)
|
||||
assertFalse(GesturePrefs.hasOverride(context, "456"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "w400dp-h850dp-port")
|
||||
fun aNarrowWindowWithLargeTextKeepsNavigationAndSaveReachable() {
|
||||
compose.setContent {
|
||||
val density = LocalDensity.current
|
||||
CompositionLocalProvider(LocalDensity provides Density(density.density, fontScale = 1.5f)) {
|
||||
DroidDeckTheme { TouchGestureDialog("123", {}, {}) }
|
||||
}
|
||||
}
|
||||
compose.onNodeWithContentDescription("Close").assertIsDisplayed()
|
||||
compose.onNodeWithTag("gesture-save").assertIsDisplayed()
|
||||
compose.onNodeWithTag("gesture-tab-3").performScrollTo().performClick()
|
||||
compose.onNodeWithText("Mouse movement").performScrollTo().assertIsDisplayed()
|
||||
compose.onNodeWithTag("gesture-save").assertIsDisplayed()
|
||||
}
|
||||
|
||||
private fun chooseTap(search: String, id: String) {
|
||||
compose.onNodeWithTag("gesture-choice-tap").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("gesture-action-search").performTextInput(search)
|
||||
compose.onNodeWithTag("gesture-action-$id").performClick()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user