avoid getting stuck after one full round

now doing a full round in language swipe is not allowed any more
This commit is contained in:
Helium314 2025-02-02 21:26:38 +01:00 committed by GitHub
parent 18283df0e3
commit 1815bbbf76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
package helium314.keyboard.keyboard
import android.view.KeyEvent
import android.view.inputmethod.InputMethodSubtype
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode
import helium314.keyboard.latin.LatinIME
import helium314.keyboard.latin.RichInputMethodManager
@ -17,9 +18,12 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
private val keyboardSwitcher = KeyboardSwitcher.getInstance()
private val settings = Settings.getInstance()
private var mSubtypeSwitchCount = 0 // for use with onLanguageSlide()
private var metaState = 0 // is this enough, or are there threading issues with the different PointerTrackers?
// language slide state
private var initialSubtype: InputMethodSubtype? = null
private var subtypeSwitchCount = 0
// todo: maybe keep meta state presses to KeyboardActionListenerImpl, and avoid calls to press/release key
private fun adjustMetaState(code: Int, remove: Boolean) {
val metaCode = when (code) {
@ -86,7 +90,8 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
}
override fun onEndSpaceSwipe(){
mSubtypeSwitchCount = 0
initialSubtype = null
subtypeSwitchCount = 0
}
override fun toggleNumpad(withSliding: Boolean, forceReturnToAlpha: Boolean): Boolean {
@ -131,7 +136,7 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
private fun onLanguageSlide(steps: Int): Boolean {
if (abs(steps) < settings.current.mLanguageSwipeDistance) return false
val subtypes = RichInputMethodManager.getInstance().getMyEnabledInputMethodSubtypeList(false)
if (subtypes.size - 1 <= abs(mSubtypeSwitchCount)) { // only allow if we are yet to cycle through all subtypes
if (subtypes.size <= 1) { // only allow if we have more than one subtype
return false
}
// decide next or previous dependent on up or down
@ -140,8 +145,18 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
wantedIndex %= subtypes.size
if (wantedIndex < 0)
wantedIndex += subtypes.size
KeyboardSwitcher.getInstance().switchToSubtype(subtypes[wantedIndex])
if (steps > 0) mSubtypeSwitchCount++ else mSubtypeSwitchCount--
val newSubtype = subtypes[wantedIndex]
// do not switch if we would switch to the initial subtype after cycling all other subtypes
if (initialSubtype == null)
initialSubtype = current
if (initialSubtype == newSubtype) {
if ((subtypeSwitchCount > 0 && steps > 0) || ((subtypeSwitchCount < 0 && steps < 0)))
return true
}
if (steps > 0) subtypeSwitchCount++ else subtypeSwitchCount--
KeyboardSwitcher.getInstance().switchToSubtype(newSubtype)
return true
}