Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,20 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
}

private fun moveCursor(moveRight: Boolean) {
val extractedText = currentInputConnection?.getExtractedText(ExtractedTextRequest(), 0) ?: return
var newCursorPosition = extractedText.selectionStart
newCursorPosition = if (moveRight) {
newCursorPosition + 1
val inputConnection = currentInputConnection
val extractedText = inputConnection.getExtractedText(ExtractedTextRequest(), 0) ?: return
val text = extractedText.text ?: return
val oldPos = extractedText.selectionStart
val newPos = if (moveRight) {
oldPos + 1
} else {
newCursorPosition - 1
}
oldPos - 1
}.coerceIn(0, text.length)

currentInputConnection?.setSelection(newCursorPosition, newCursorPosition)
if (newPos != oldPos) {
inputConnection?.setSelection(newPos, newPos)
keyboardView?.performHapticHandleMove()
}
}

private fun getImeOptionsActionId(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.os.Build
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.os.SystemClock
import android.util.AttributeSet
import android.util.TypedValue
import android.view.*
Expand All @@ -33,6 +34,7 @@ import androidx.emoji2.text.EmojiCompat.EMOJI_SUPPORTED
import androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup
import org.fossify.commons.extensions.*
import org.fossify.commons.helpers.ensureBackgroundThread
import org.fossify.commons.helpers.isOreoMr1Plus
import org.fossify.commons.helpers.isPiePlus
import org.fossify.keyboard.R
import org.fossify.keyboard.activities.ManageClipboardItemsActivity
Expand Down Expand Up @@ -143,6 +145,7 @@ class MyKeyboardView @JvmOverloads constructor(
private var mTopSmallNumberMarginHeight = 0f
private val mSpaceMoveThreshold: Int
private var ignoreTouches = false
private var lastHandleMoveAt = 0L

private var mKeyBackground: Drawable? = null
private var mShowKeyBorders: Boolean = false
Expand Down Expand Up @@ -185,6 +188,7 @@ class MyKeyboardView @JvmOverloads constructor(
private const val REPEAT_INTERVAL = 50 // ~20 keys per second
private const val REPEAT_START_DELAY = 400
private val LONGPRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout()
private const val HANDLE_MOVE_MIN_MS = 35L
}

init {
Expand Down Expand Up @@ -491,6 +495,20 @@ class MyKeyboardView @JvmOverloads constructor(
}
}

fun performHapticHandleMove() {
if (!context.config.vibrateOnKeypress) return
val now = SystemClock.uptimeMillis()
if (now - lastHandleMoveAt < HANDLE_MOVE_MIN_MS) return
lastHandleMoveAt = now
if (isOreoMr1Plus()) {
@Suppress("DEPRECATION")
performHapticFeedback(
HapticFeedbackConstants.TEXT_HANDLE_MOVE,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING
)
}
}

/**
* Sets the state of the shift key of the keyboard, if any.
* @param shifted whether or not to enable the state of the shift key
Expand Down
Loading