Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backspace swipe right to delete word and Slide gestures improvements #439

Merged
merged 24 commits into from
Oct 20, 2023
Merged
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a4405f4
Grouped together 'slide gestures checkbox' and 'slide sensitivity sli…
sslater11 Sep 23, 2023
f284722
Enable/Disable 'Slide sensitivity' slider when the 'slide gestures' c…
sslater11 Sep 23, 2023
09fe4c5
Better swipe selection toggle and better swipe delete toggle.
sslater11 Sep 23, 2023
c0dd12c
Made swiping right on backspace key delete a whole word to the right.
sslater11 Sep 23, 2023
0f3d1f1
Merge branch 'main' into slide-gestures
dessalines Sep 26, 2023
824b91a
Swipe up or down to toggle slide gestures text selection.
sslater11 Oct 5, 2023
4d79ac6
Added a deadzone for slide gestures to allow normal swipes on spaceba…
sslater11 Oct 8, 2023
3ed9680
Added up and down swipes to spacebar to move cursor up and down.
sslater11 Oct 8, 2023
6dd9648
Merge branch 'slide-gestures' of https://github.com/sslater11/thumb-k…
sslater11 Oct 8, 2023
b0bb7d2
Merge branch 'main' into slide-gestures
sslater11 Oct 8, 2023
0020b1d
Fixes #410 - Added cursor acceleration for slide gestures on the spac…
sslater11 Oct 11, 2023
e6afd91
Format kotlin
sslater11 Oct 11, 2023
de489ba
Merge branch 'main' into slide-gestures
dessalines Oct 11, 2023
b867939
Fixing merge issue.
dessalines Oct 11, 2023
2220dc3
Fixed issue with selected text being deleted when we use the spacebar…
sslater11 Oct 12, 2023
a0c03d3
Copy/Cut actions now copy/cut all text if nothing is selected (#469)
sslater11 Oct 12, 2023
cf01818
Adding threshold acceleration
WadeWT Oct 19, 2023
5dcd7ae
Added more cursor acceleration modes.
sslater11 Oct 19, 2023
7c0f76d
DB Migration: Added settings menu for slide gestures cursor accelerat…
sslater11 Oct 19, 2023
ffe3c1e
Grouped all slide gesture settings together.
sslater11 Oct 19, 2023
543c7cb
Merge branch 'slide-gestures' into threshold-acceleration
sslater11 Oct 19, 2023
7350ea7
Merge pull request #2 from WadeWT/threshold-acceleration
sslater11 Oct 19, 2023
ccb67be
Added slide gestures Threshold Acceleration to the settings menu.
sslater11 Oct 19, 2023
e20636f
Merged with upstream/main
sslater11 Oct 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,50 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.max
import kotlin.math.min
import kotlin.math.pow
import kotlin.math.sqrt

const val TAG = "com.thumbkey"

const val THUMBKEY_IME_NAME = "com.dessalines.thumbkey/.IMEService"

fun accelCurve(offset: Float, threshold: Float, exp: Float): Float {
var x = abs(offset)
val belowThreshold = min(offset, threshold)
x = max(0.0f, x - belowThreshold)
return x.pow(exp) + belowThreshold
}

fun acceleratingCursorDistanceThreshold(offsetX: Float, timeOfLastAccelerationInput: Long, acceleration: Int): Int {
// val exp = 1.0f // Slow and we can cover 1 1/2 full lines, so perfect for most.
// val exp = 1.5f // Slow and we can cover 2 full lines, so perfect for most.
// val exp = 2.0f // 2.0 should be the default
// val exp = 3.0f // 3.0 should be the upper limit for this
// Convert user's chosen acceleration of 1-50 to the amount we need.
val exp = 1.0f + ((acceleration * 4) / 100f) // Will give us a range from 1-3
val threshold = 2.0f // The threshold before acceleration kicks in.

val timeDifference = System.currentTimeMillis() - timeOfLastAccelerationInput
// Prevent division by 0 error.
var distance = if (timeDifference == 0L) {
0f
} else {
abs(offsetX) / timeDifference
}

distance = accelCurve(distance, threshold, exp)
if (offsetX < 0) {
// Set the value back to negative.
// A distance of -1 will move the cursor left by 1 character
distance *= -1
}
// distance = offsetX / 10
return distance.toInt()
}


fun slideCursorDistance(offsetX: Float, timeOfLastAccelerationInput: Long, accelerationMode: Int, acceleration: Int): Int {
when (accelerationMode) {
CursorAccelerationMode.CONSTANT.ordinal -> {
Expand Down