mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-09 08:07:42 +00:00
todos after RichIMM overhaul
This commit is contained in:
parent
ad71b49c04
commit
7dc6279d87
7 changed files with 24 additions and 50 deletions
|
@ -150,7 +150,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(true)
|
||||
val subtypes = RichInputMethodManager.getInstance().getMyEnabledInputMethodSubtypes(true)
|
||||
if (subtypes.size <= 1) { // only allow if we have more than one subtype
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ public final class InputAttributes {
|
|||
|| InputTypeUtils.isEmailVariation(variation)
|
||||
|| hasNoMicrophoneKeyOption()
|
||||
|| !RichInputMethodManager.isInitialized() // avoid crash when only using spell checker
|
||||
|| !RichInputMethodManager.getInstance().hasShortcutIme();
|
||||
|| !RichInputMethodManager.getInstance().isShortcutImeReady();
|
||||
mShouldShowVoiceInputKey = !noMicrophone;
|
||||
|
||||
mDisableGestureFloatingPreviewText = InputAttributes.inPrivateImeOptions(
|
||||
|
|
|
@ -608,7 +608,7 @@ public class LatinIME extends InputMethodService implements
|
|||
mCurrentSubtypeHasBeenUsed = false;
|
||||
}
|
||||
if (currentSubtypeHasBeenUsed
|
||||
&& richImm.checkIfSubtypeBelongsToThisImeAndEnabled(lastActiveSubtype)
|
||||
&& SubtypeSettings.INSTANCE.isEnabled(lastActiveSubtype)
|
||||
&& !currentSubtype.equals(lastActiveSubtype)) {
|
||||
switchToSubtype(lastActiveSubtype);
|
||||
return;
|
||||
|
@ -1461,7 +1461,7 @@ public class LatinIME extends InputMethodService implements
|
|||
// switch IME if wanted and possible
|
||||
if (switchIme && !switchSubtype && switchInputMethod())
|
||||
return;
|
||||
final boolean hasMoreThanOneSubtype = mRichImm.getMyEnabledInputMethodSubtypeList(true).size() > 1;
|
||||
final boolean hasMoreThanOneSubtype = mRichImm.hasMultipleEnabledSubtypesInThisIme(true);
|
||||
// switch subtype if wanted, do nothing if no other subtype is available
|
||||
if (switchSubtype && !switchIme) {
|
||||
if (hasMoreThanOneSubtype)
|
||||
|
|
|
@ -22,7 +22,6 @@ import helium314.keyboard.latin.utils.SubtypeLocaleUtils
|
|||
import helium314.keyboard.latin.utils.SubtypeSettings
|
||||
import helium314.keyboard.latin.utils.getSecondaryLocales
|
||||
import helium314.keyboard.latin.utils.locale
|
||||
import helium314.keyboard.latin.utils.mainLayoutNameOrQwerty
|
||||
import helium314.keyboard.latin.utils.prefs
|
||||
import java.util.Locale
|
||||
|
||||
|
@ -53,35 +52,21 @@ class RichInputMethodManager private constructor() {
|
|||
|
||||
val isShortcutImeReady get() = shortcutInputMethodInfo != null
|
||||
|
||||
fun hasShortcutIme() = isShortcutImeReady // todo
|
||||
fun getMyEnabledInputMethodSubtypes(allowsImplicitlySelectedSubtypes: Boolean) =
|
||||
SubtypeSettings.getEnabledSubtypes(allowsImplicitlySelectedSubtypes)
|
||||
|
||||
fun checkIfSubtypeBelongsToThisImeAndEnabled(subtype: InputMethodSubtype?) =
|
||||
getEnabledInputMethodSubtypeList(inputMethodInfoOfThisIme, true).contains(subtype)
|
||||
|
||||
// todo: same as SubtypeSettings.getEnabledSubtypes(allowsImplicitlySelectedSubtypes), right?
|
||||
fun getMyEnabledInputMethodSubtypeList(allowsImplicitlySelectedSubtypes: Boolean) =
|
||||
getEnabledInputMethodSubtypeList(inputMethodInfoOfThisIme, allowsImplicitlySelectedSubtypes)
|
||||
|
||||
fun getEnabledInputMethodSubtypeList(imi: InputMethodInfo, allowsImplicitlySelectedSubtypes: Boolean) =
|
||||
fun getEnabledInputMethodSubtypes(imi: InputMethodInfo, allowsImplicitlySelectedSubtypes: Boolean) =
|
||||
inputMethodInfoCache.getEnabledInputMethodSubtypeList(imi, allowsImplicitlySelectedSubtypes)
|
||||
|
||||
// could also check SubtypeSettings.getEnabledSubtypes(allowsImplicitlySelectedSubtypes)
|
||||
fun checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(subtype: InputMethodSubtype): Boolean {
|
||||
val subtypeEnabled = checkIfSubtypeBelongsToThisImeAndEnabled(subtype)
|
||||
val subtypeExplicitlyEnabled = getMyEnabledInputMethodSubtypeList(false)
|
||||
.contains(subtype)
|
||||
return subtypeEnabled && !subtypeExplicitlyEnabled
|
||||
}
|
||||
|
||||
fun hasMultipleEnabledIMEsOrSubtypes(shouldIncludeAuxiliarySubtypes: Boolean) =
|
||||
hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imm.enabledInputMethodList)
|
||||
|
||||
fun hasMultipleEnabledSubtypesInThisIme(shouldIncludeAuxiliarySubtypes: Boolean) =
|
||||
hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, listOf(inputMethodInfoOfThisIme))
|
||||
SubtypeSettings.getEnabledSubtypes(shouldIncludeAuxiliarySubtypes).size > 1
|
||||
|
||||
fun getNextSubtypeInThisIme(onlyCurrentIme: Boolean): InputMethodSubtype? {
|
||||
val currentSubtype = currentSubtype.rawSubtype
|
||||
val enabledSubtypes = getMyEnabledInputMethodSubtypeList(true)
|
||||
val enabledSubtypes = getMyEnabledInputMethodSubtypes(true)
|
||||
val currentIndex = enabledSubtypes.indexOf(currentSubtype)
|
||||
if (currentIndex == -1) {
|
||||
Log.w(TAG, "Can't find current subtype in enabled subtypes: subtype=" +
|
||||
|
@ -97,22 +82,9 @@ class RichInputMethodManager private constructor() {
|
|||
return enabledSubtypes[nextIndex]
|
||||
}
|
||||
|
||||
// todo: this is about main layout, not layout set
|
||||
fun findSubtypeByLocaleAndKeyboardLayoutSet(locale: Locale, keyboardLayoutSetName: String): InputMethodSubtype? {
|
||||
val myImi = inputMethodInfoOfThisIme
|
||||
val count = myImi.subtypeCount
|
||||
for (i in 0..<count) {
|
||||
val subtype = myImi.getSubtypeAt(i)
|
||||
if (locale == subtype.locale() && keyboardLayoutSetName == subtype.mainLayoutNameOrQwerty()) {
|
||||
return subtype
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun findSubtypeForHintLocale(locale: Locale): InputMethodSubtype? {
|
||||
// Find the best subtype based on a locale matching
|
||||
val subtypes = getMyEnabledInputMethodSubtypeList(true)
|
||||
val subtypes = getMyEnabledInputMethodSubtypes(true)
|
||||
var bestMatch = getBestMatch(locale, subtypes) { it.locale() }
|
||||
if (bestMatch != null) return bestMatch
|
||||
|
||||
|
@ -173,10 +145,11 @@ class RichInputMethodManager private constructor() {
|
|||
Log.d(TAG, ("Update shortcut IME from: ${shortcutInputMethodInfo?.id ?: "<null>"}, $subtype"))
|
||||
}
|
||||
val richSubtype = currentRichInputMethodSubtype
|
||||
val implicitlyEnabledSubtype = checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(richSubtype.rawSubtype)
|
||||
val implicitlyEnabledSubtype = SubtypeSettings.isEnabled(richSubtype.rawSubtype)
|
||||
&& !SubtypeSettings.getEnabledSubtypes(false).contains(richSubtype.rawSubtype)
|
||||
val systemLocale = context.resources.configuration.locale()
|
||||
LanguageOnSpacebarUtils.onSubtypeChanged(richSubtype, implicitlyEnabledSubtype, systemLocale)
|
||||
LanguageOnSpacebarUtils.setEnabledSubtypes(getMyEnabledInputMethodSubtypeList(true))
|
||||
LanguageOnSpacebarUtils.setEnabledSubtypes(getMyEnabledInputMethodSubtypes(true))
|
||||
|
||||
// TODO: Update an icon for shortcut IME
|
||||
val shortcuts = inputMethodManager.shortcutInputMethodsAndSubtypes
|
||||
|
@ -203,7 +176,7 @@ class RichInputMethodManager private constructor() {
|
|||
imiList.forEach { imi ->
|
||||
// We can return true immediately after we find two or more filtered IMEs.
|
||||
if (filteredImisCount > 1) return true
|
||||
val subtypes = getEnabledInputMethodSubtypeList(imi, true)
|
||||
val subtypes = getEnabledInputMethodSubtypes(imi, true)
|
||||
// IMEs that have no subtypes should be counted.
|
||||
if (subtypes.isEmpty()) {
|
||||
++filteredImisCount
|
||||
|
@ -230,7 +203,7 @@ class RichInputMethodManager private constructor() {
|
|||
if (filteredImisCount > 1) {
|
||||
return true
|
||||
}
|
||||
val subtypes = getMyEnabledInputMethodSubtypeList(true)
|
||||
val subtypes = getMyEnabledInputMethodSubtypes(true)
|
||||
// imm.getEnabledInputMethodSubtypeList(null, true) will return the current IME's
|
||||
// both explicitly and implicitly enabled input method subtype.
|
||||
// (The current IME should be LatinIME.)
|
||||
|
|
|
@ -16,7 +16,9 @@ import helium314.keyboard.latin.utils.Log
|
|||
import helium314.keyboard.latin.utils.ScriptUtils
|
||||
import helium314.keyboard.latin.utils.ScriptUtils.script
|
||||
import helium314.keyboard.latin.utils.SubtypeLocaleUtils
|
||||
import helium314.keyboard.latin.utils.SubtypeSettings
|
||||
import helium314.keyboard.latin.utils.locale
|
||||
import helium314.keyboard.latin.utils.mainLayoutNameOrQwerty
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
|
@ -104,11 +106,8 @@ class RichInputMethodSubtype private constructor(val rawSubtype: InputMethodSubt
|
|||
val noLanguageSubtype: RichInputMethodSubtype get() {
|
||||
sNoLanguageSubtype?.let { return it }
|
||||
var noLanguageSubtype = sNoLanguageSubtype
|
||||
val rawNoLanguageSubtype = RichInputMethodManager.getInstance()
|
||||
.findSubtypeByLocaleAndKeyboardLayoutSet(
|
||||
SubtypeLocaleUtils.NO_LANGUAGE.constructLocale(),
|
||||
SubtypeLocaleUtils.QWERTY
|
||||
)
|
||||
val rawNoLanguageSubtype = SubtypeSettings.getResourceSubtypesForLocale(SubtypeLocaleUtils.NO_LANGUAGE.constructLocale())
|
||||
.firstOrNull { it.mainLayoutNameOrQwerty() == SubtypeLocaleUtils.QWERTY }
|
||||
if (rawNoLanguageSubtype != null) {
|
||||
noLanguageSubtype = RichInputMethodSubtype(rawNoLanguageSubtype)
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ fun createInputMethodPickerDialog(latinIme: LatinIME, richImm: RichInputMethodMa
|
|||
val enabledSubtypes = mutableListOf<Pair<InputMethodInfo, InputMethodSubtype?>>()
|
||||
var currentSubtypeIndex = 0
|
||||
enabledImis.forEach { imi ->
|
||||
val subtypes = if (imi != thisImi) richImm.getEnabledInputMethodSubtypeList(imi, true)
|
||||
else richImm.getEnabledInputMethodSubtypeList(imi, true).sortedBy { it.displayName() }
|
||||
val subtypes = if (imi != thisImi) richImm.getEnabledInputMethodSubtypes(imi, true)
|
||||
else richImm.getEnabledInputMethodSubtypes(imi, true).sortedBy { it.displayName() }
|
||||
if (subtypes.isEmpty()) {
|
||||
enabledSubtypes.add(imi to null)
|
||||
} else {
|
||||
|
|
|
@ -28,9 +28,11 @@ object SubtypeSettings {
|
|||
fun getEnabledSubtypes(fallback: Boolean = false): List<InputMethodSubtype> {
|
||||
if (fallback && enabledSubtypes.isEmpty())
|
||||
return getDefaultEnabledSubtypes()
|
||||
return enabledSubtypes.toList()
|
||||
return enabledSubtypes
|
||||
}
|
||||
|
||||
fun isEnabled(subtype: InputMethodSubtype): Boolean = subtype in enabledSubtypes || subtype in getDefaultEnabledSubtypes()
|
||||
|
||||
fun getAllAvailableSubtypes(): List<InputMethodSubtype> =
|
||||
resourceSubtypesByLocale.values.flatten() + additionalSubtypes
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue