Skip to content

Commit 5c9e32a

Browse files
committed
feat(gesture): add a cursor swipe distance setting (#942)
Moving the cursor on the space bar, deleting by character on the delete key and the full keyboard cursor swipe used a fixed 10 dp per character, and touchpad sensitivity does not apply to them. Settings > Gestures & swipes > Cursor swipe distance (5-40 dp, default 10 dp) now sets that step. The default keeps the current behaviour. Word-by-word delete and the language swipe distance are unchanged.
1 parent e01a196 commit 5c9e32a

43 files changed

Lines changed: 217 additions & 7 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎app/src/main/java/helium314/keyboard/keyboard/PointerTracker.kt‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,8 @@ class PointerTracker private constructor(
891891
}
892892

893893
// Horizontal movement
894-
val stepsX = dX / sPointerStep
894+
val cursorStep = cursorSwipeStepPx(sv)
895+
val stepsX = dX / cursorStep
895896
if (stepsX != 0 && !mInVerticalSwipe) {
896897
if (!mInHorizontalSwipe) {
897898
getTimerProxy().cancelKeyTimersOf(this)
@@ -900,7 +901,7 @@ class PointerTracker private constructor(
900901
return
901902
}
902903
if (sListener.onHorizontalSpaceSwipe(stepsX)) {
903-
mStartX += stepsX * sPointerStep
904+
mStartX += stepsX * cursorStep
904905
}
905906
}
906907
} else if (code == KeyCode.DELETE) {
@@ -909,7 +910,7 @@ class PointerTracker private constructor(
909910
// The curve is only for a purely sideways word swipe. A line step restarts the word count (see
910911
// prepareExactVertical), so after it the even steps count from the finger, not from the swipe start.
911912
val curved = byWord && !mDeleteSwipeLineMoved
912-
val evenStep = if (byWord) sWordDeletePointerStep else sPointerStep
913+
val evenStep = if (byWord) sWordDeletePointerStep else cursorSwipeStepPx(sv)
913914
// on the curve mStartX stays at the position that selected the current word count
914915
fun boundaryPx(words: Int) = (WordSwipeCurve.boundary(words) * density).roundToInt()
915916
var words = mDeleteSwipeWords
@@ -999,11 +1000,12 @@ class PointerTracker private constructor(
9991000
}
10001001

10011002
if (action == KeyboardActionListener.SWIPE_MOVE_CURSOR) {
1002-
val stepsX = dX / sPointerStep
1003+
val cursorStep = cursorSwipeStepPx(sv)
1004+
val stepsX = dX / cursorStep
10031005
if (stepsX != 0) {
10041006
mInHorizontalSwipe = true
10051007
if (sListener.onFullKeyboardSwipe(stepsX, action)) {
1006-
mStartX += stepsX * sPointerStep
1008+
mStartX += stepsX * cursorStep
10071009
}
10081010
}
10091011
} else {
@@ -1425,6 +1427,8 @@ class PointerTracker private constructor(
14251427

14261428
private var sParams: PointerTrackerParams? = null
14271429
private val sPointerStep = 10.dpToPx(Resources.getSystem())
1430+
/** finger travel for one character when moving the cursor or deleting by swipe, from the settings */
1431+
private fun cursorSwipeStepPx(sv: SettingsValues) = max(1, sv.mCursorSwipeStep.dpToPx(Resources.getSystem()))
14281432
private val sWordDeletePointerStep = 24.dpToPx(Resources.getSystem())
14291433
private var sGestureStrokeRecognitionParams: GestureStrokeRecognitionParams? = null
14301434
private var sGestureStrokeDrawingParams: GestureStrokeDrawingParams? = null

‎app/src/main/java/helium314/keyboard/latin/settings/Defaults.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ object Defaults {
152152
const val PREF_SPACE_VERTICAL_SWIPE = "touchpad_mode"
153153
const val PREF_SPACE_VERTICAL_DOWN_SWIPE = "none"
154154
const val PREF_VERTICAL_SWIPE_THRESHOLD = 24
155+
const val PREF_CURSOR_SWIPE_STEP = 10
155156
const val PREF_DELETE_SWIPE = true
156157
const val PREF_DELETE_SWIPE_WORD_BY_WORD = false
157158
const val PREF_AUTO_PAIR_SYMBOLS = false

‎app/src/main/java/helium314/keyboard/latin/settings/Settings.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ class Settings private constructor() : SharedPreferences.OnSharedPreferenceChang
413413
const val PREF_SPACE_VERTICAL_SWIPE = "vertical_space_swipe"
414414
const val PREF_SPACE_VERTICAL_DOWN_SWIPE = "vertical_down_space_swipe"
415415
const val PREF_VERTICAL_SWIPE_THRESHOLD = "vertical_swipe_threshold"
416+
const val PREF_CURSOR_SWIPE_STEP = "cursor_swipe_step"
416417
const val PREF_DELETE_SWIPE = "delete_swipe"
417418
const val PREF_DELETE_SWIPE_WORD_BY_WORD = "delete_swipe_word_by_word"
418419
const val PREF_FULL_KEYBOARD_SWIPE = "full_keyboard_swipe"

‎app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.kt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ open class SettingsValues(
102102
val mSpaceSwipeVertical: Int
103103
val mSpaceSwipeVerticalDown: Int
104104
val mVerticalSwipeThreshold: Int
105+
/** finger travel in dp for one character when moving the cursor or deleting by swipe */
106+
val mCursorSwipeStep: Int
105107
val mLanguageSwipeDistance: Int
106108
val mTouchpadSensitivity: Int
107109
val mTouchpadFullscreen: Boolean
@@ -442,6 +444,7 @@ open class SettingsValues(
442444
mSpaceSwipeVertical = Settings.readVerticalSpaceSwipe(prefs)
443445
mSpaceSwipeVerticalDown = Settings.readVerticalDownSpaceSwipe(prefs)
444446
mVerticalSwipeThreshold = prefs.getInt(Settings.PREF_VERTICAL_SWIPE_THRESHOLD, Defaults.PREF_VERTICAL_SWIPE_THRESHOLD)
447+
mCursorSwipeStep = prefs.getInt(Settings.PREF_CURSOR_SWIPE_STEP, Defaults.PREF_CURSOR_SWIPE_STEP)
445448
mLanguageSwipeDistance = prefs.getInt(Settings.PREF_LANGUAGE_SWIPE_DISTANCE, Defaults.PREF_LANGUAGE_SWIPE_DISTANCE)
446449
mTouchpadSensitivity = prefs.getInt(Settings.PREF_TOUCHPAD_SENSITIVITY, Defaults.PREF_TOUCHPAD_SENSITIVITY)
447450
mTouchpadFullscreen = prefs.getBoolean(Settings.PREF_TOUCHPAD_FULLSCREEN, Defaults.PREF_TOUCHPAD_FULLSCREEN)

‎app/src/main/java/helium314/keyboard/settings/screens/GestureTypingScreen.kt‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ fun GestureTypingScreen(
119119
|| Settings.readHorizontalSpaceSwipe(prefs) == KeyboardActionListener.SWIPE_SWITCH_LANGUAGE) {
120120
add(Settings.PREF_LANGUAGE_SWIPE_DISTANCE)
121121
}
122+
add(Settings.PREF_CURSOR_SWIPE_STEP)
122123
add(Settings.PREF_VERTICAL_SWIPE_THRESHOLD)
123124
add(Settings.PREF_SPACE_VERTICAL_SWIPE)
124125
add(Settings.PREF_SPACE_VERTICAL_DOWN_SWIPE)
@@ -353,6 +354,22 @@ fun createGestureTypingSettings(context: Context) = listOf(
353354
}
354355
)
355356
},
357+
Setting(context, Settings.PREF_CURSOR_SWIPE_STEP, R.string.cursor_swipe_step, R.string.cursor_swipe_step_summary) {
358+
SliderPreference(
359+
name = it.title,
360+
key = it.key,
361+
default = Defaults.PREF_CURSOR_SWIPE_STEP,
362+
range = 5f..40f,
363+
stepSize = 1,
364+
description = { value ->
365+
if (value.toInt() == Defaults.PREF_CURSOR_SWIPE_STEP) {
366+
"${value.toInt()} dp (${stringResource(R.string.button_default)})"
367+
} else {
368+
"${value.toInt()} dp"
369+
}
370+
}
371+
)
372+
},
356373
Setting(context, Settings.PREF_TOUCHPAD_SENSITIVITY, R.string.touchpad_sensitivity) {
357374
SliderPreference(
358375
name = it.title,

‎app/src/main/res/values-ar/strings.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,4 +1774,9 @@
17741774
<string name="storage_type_language_pack">ترجمة التطبيق</string>
17751775
<string name="ocr_camera_failed">فشل تشغيل الكاميرا. اضغط لإعادة المحاولة.</string>
17761776
<string name="handwriting_not_recognized">تعذّر التعرف على الكتابة اليدوية. حاول مرة أخرى.</string>
1777+
<string name="keyboard_test_field">جرّب لوحة المفاتيح هنا</string>
1778+
<string name="keyboard_test_field_hint">تظهر التغييرات في المرة التالية التي تفتح فيها لوحة المفاتيح. لا يتم تعلّم أي شيء مكتوب هنا.</string>
1779+
<string name="cursor_swipe_step">مسافة سحب المؤشر</string>
1780+
<string name="cursor_swipe_step_summary">المسافة التي يقطعها إصبعك لكل حرف عند السحب على مفتاح المسافة أو مفتاح الحذف. كلما زادت القيمة، كان التحرك أبطأ</string>
1781+
<string name="ai_cancelled">تم إلغاء طلب الذكاء الاصطناعي</string>
17771782
</resources>

‎app/src/main/res/values-be/strings.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,4 +1803,9 @@
18031803
<string name="storage_type_language_pack">пераклад праграмы</string>
18041804
<string name="ocr_camera_failed">Не ўдалося запусціць камеру. Націсніце, каб паўтарыць спробу.</string>
18051805
<string name="handwriting_not_recognized">Не ўдалося распазнаць рукапісны тэкст. Паспрабуйце яшчэ раз.</string>
1806+
<string name="keyboard_test_field">Паспрабуйце клавіятуру тут</string>
1807+
<string name="keyboard_test_field_hint">Змены будуць паказаны пры наступным адкрыцці клавіятуры. Тое, што набіраецца тут, не запамінаецца.</string>
1808+
<string name="cursor_swipe_step">Адлегласць свайпа курсора</string>
1809+
<string name="cursor_swipe_step_summary">Колькасць руху пальцам для кожнага знака пры свайпе па прасторы або клавішы выдалення. Больш значэнне - павольней</string>
1810+
<string name="ai_cancelled">Запыт ШІ скасаваны</string>
18061811
</resources>

‎app/src/main/res/values-bg/strings.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,4 +1803,9 @@
18031803
<string name="storage_type_language_pack">превод на приложението</string>
18041804
<string name="ocr_camera_failed">Камерата не успя да се стартира. Докоснете, за да опитате отново.</string>
18051805
<string name="handwriting_not_recognized">Ръкописният текст не можа да бъде разпознат. Опитайте отново.</string>
1806+
<string name="keyboard_test_field">Опитайте клавиатурата тук</string>
1807+
<string name="keyboard_test_field_hint">Промените се показват при следващото отваряне на клавиатурата. Нищо въведено тук не се научава.</string>
1808+
<string name="cursor_swipe_step">Разстояние на плъзгане на курсора</string>
1809+
<string name="cursor_swipe_step_summary">Разстоянието, което пръстът изминава за всеки символ при плъзгане по интервала или клавиша за изтриване. По-голямата стойност означава по-бавно</string>
1810+
<string name="ai_cancelled">Заявката към AI е отменена</string>
18061811
</resources>

‎app/src/main/res/values-bn/strings.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,4 +1664,9 @@
16641664
<string name="storage_type_language_pack">অ্যাপ অনুবাদ</string>
16651665
<string name="ocr_camera_failed">ক্যামেরা চালু করা যায়নি। আবার চেষ্টা করতে ট্যাপ করুন।</string>
16661666
<string name="handwriting_not_recognized">হাতের লেখা শনাক্ত করা যায়নি। আবার চেষ্টা করুন।</string>
1667+
<string name="keyboard_test_field">কিবোর্ড এখানে পরীক্ষা করুন</string>
1668+
<string name="keyboard_test_field_hint">পরিবর্তনগুলি পরের বার কিবোর্ড খুললে দেখা যাবে। এখানে যা টাইপ করা হয় তা শেখা হয় না।</string>
1669+
<string name="cursor_swipe_step">কার্সার সোয়াইপের দূরত্ব</string>
1670+
<string name="cursor_swipe_step_summary">স্পেস বার বা মুছুন বোতামে সোয়াইপ করার সময় প্রতিটি অক্ষরের জন্য আঙুলের চলাচলের দূরত্ব। বেশি হলে ধীর হবে</string>
1671+
<string name="ai_cancelled">AI অনুরোধ বাতিল করা হয়েছে</string>
16671672
</resources>

‎app/src/main/res/values-cs/strings.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,4 +1768,9 @@ Umožňuje lokální inferenci GGUF / llama.cpp na zařízení pro korektury a p
17681768
<string name="storage_type_language_pack">překlad aplikace</string>
17691769
<string name="ocr_camera_failed">Kameru se nepodařilo spustit. Klepnutím to zkuste znovu.</string>
17701770
<string name="handwriting_not_recognized">Rukopis se nepodařilo rozpoznat. Zkuste to znovu.</string>
1771+
<string name="keyboard_test_field">Vyzkoušejte klávesnici zde</string>
1772+
<string name="keyboard_test_field_hint">Změny se zobrazí při příštím otevření klávesnice. Nic zde napsaného se nenaučí.</string>
1773+
<string name="cursor_swipe_step">Vzdálenost posunu kurzoru</string>
1774+
<string name="cursor_swipe_step_summary">Vzdálenost prstu pro každý znak při posunu na mezerníku nebo klávese delete. Vyšší hodnota znamená pomalejší posun</string>
1775+
<string name="ai_cancelled">Požadavek AI zrušen</string>
17711776
</resources>

0 commit comments

Comments
 (0)