mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-20 06:09:09 +00:00
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:
parent
18283df0e3
commit
1815bbbf76
1 changed files with 20 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
package helium314.keyboard.keyboard
|
package helium314.keyboard.keyboard
|
||||||
|
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
|
import android.view.inputmethod.InputMethodSubtype
|
||||||
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode
|
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode
|
||||||
import helium314.keyboard.latin.LatinIME
|
import helium314.keyboard.latin.LatinIME
|
||||||
import helium314.keyboard.latin.RichInputMethodManager
|
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 keyboardSwitcher = KeyboardSwitcher.getInstance()
|
||||||
private val settings = Settings.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?
|
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
|
// todo: maybe keep meta state presses to KeyboardActionListenerImpl, and avoid calls to press/release key
|
||||||
private fun adjustMetaState(code: Int, remove: Boolean) {
|
private fun adjustMetaState(code: Int, remove: Boolean) {
|
||||||
val metaCode = when (code) {
|
val metaCode = when (code) {
|
||||||
|
@ -86,7 +90,8 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onEndSpaceSwipe(){
|
override fun onEndSpaceSwipe(){
|
||||||
mSubtypeSwitchCount = 0
|
initialSubtype = null
|
||||||
|
subtypeSwitchCount = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toggleNumpad(withSliding: Boolean, forceReturnToAlpha: Boolean): Boolean {
|
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 {
|
private fun onLanguageSlide(steps: Int): Boolean {
|
||||||
if (abs(steps) < settings.current.mLanguageSwipeDistance) return false
|
if (abs(steps) < settings.current.mLanguageSwipeDistance) return false
|
||||||
val subtypes = RichInputMethodManager.getInstance().getMyEnabledInputMethodSubtypeList(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
|
return false
|
||||||
}
|
}
|
||||||
// decide next or previous dependent on up or down
|
// 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
|
wantedIndex %= subtypes.size
|
||||||
if (wantedIndex < 0)
|
if (wantedIndex < 0)
|
||||||
wantedIndex += subtypes.size
|
wantedIndex += subtypes.size
|
||||||
KeyboardSwitcher.getInstance().switchToSubtype(subtypes[wantedIndex])
|
val newSubtype = subtypes[wantedIndex]
|
||||||
if (steps > 0) mSubtypeSwitchCount++ else mSubtypeSwitchCount--
|
|
||||||
|
// 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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue