todos after RichIMM overhaul

This commit is contained in:
Helium314 2025-05-31 13:56:02 +02:00
parent ad71b49c04
commit 7dc6279d87
7 changed files with 24 additions and 50 deletions

View file

@ -150,7 +150,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(true) val subtypes = RichInputMethodManager.getInstance().getMyEnabledInputMethodSubtypes(true)
if (subtypes.size <= 1) { // only allow if we have more than one subtype if (subtypes.size <= 1) { // only allow if we have more than one subtype
return false return false
} }

View file

@ -103,7 +103,7 @@ public final class InputAttributes {
|| InputTypeUtils.isEmailVariation(variation) || InputTypeUtils.isEmailVariation(variation)
|| hasNoMicrophoneKeyOption() || hasNoMicrophoneKeyOption()
|| !RichInputMethodManager.isInitialized() // avoid crash when only using spell checker || !RichInputMethodManager.isInitialized() // avoid crash when only using spell checker
|| !RichInputMethodManager.getInstance().hasShortcutIme(); || !RichInputMethodManager.getInstance().isShortcutImeReady();
mShouldShowVoiceInputKey = !noMicrophone; mShouldShowVoiceInputKey = !noMicrophone;
mDisableGestureFloatingPreviewText = InputAttributes.inPrivateImeOptions( mDisableGestureFloatingPreviewText = InputAttributes.inPrivateImeOptions(

View file

@ -608,7 +608,7 @@ public class LatinIME extends InputMethodService implements
mCurrentSubtypeHasBeenUsed = false; mCurrentSubtypeHasBeenUsed = false;
} }
if (currentSubtypeHasBeenUsed if (currentSubtypeHasBeenUsed
&& richImm.checkIfSubtypeBelongsToThisImeAndEnabled(lastActiveSubtype) && SubtypeSettings.INSTANCE.isEnabled(lastActiveSubtype)
&& !currentSubtype.equals(lastActiveSubtype)) { && !currentSubtype.equals(lastActiveSubtype)) {
switchToSubtype(lastActiveSubtype); switchToSubtype(lastActiveSubtype);
return; return;
@ -1461,7 +1461,7 @@ public class LatinIME extends InputMethodService implements
// switch IME if wanted and possible // switch IME if wanted and possible
if (switchIme && !switchSubtype && switchInputMethod()) if (switchIme && !switchSubtype && switchInputMethod())
return; 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 // switch subtype if wanted, do nothing if no other subtype is available
if (switchSubtype && !switchIme) { if (switchSubtype && !switchIme) {
if (hasMoreThanOneSubtype) if (hasMoreThanOneSubtype)

View file

@ -22,7 +22,6 @@ import helium314.keyboard.latin.utils.SubtypeLocaleUtils
import helium314.keyboard.latin.utils.SubtypeSettings import helium314.keyboard.latin.utils.SubtypeSettings
import helium314.keyboard.latin.utils.getSecondaryLocales import helium314.keyboard.latin.utils.getSecondaryLocales
import helium314.keyboard.latin.utils.locale import helium314.keyboard.latin.utils.locale
import helium314.keyboard.latin.utils.mainLayoutNameOrQwerty
import helium314.keyboard.latin.utils.prefs import helium314.keyboard.latin.utils.prefs
import java.util.Locale import java.util.Locale
@ -53,35 +52,21 @@ class RichInputMethodManager private constructor() {
val isShortcutImeReady get() = shortcutInputMethodInfo != null val isShortcutImeReady get() = shortcutInputMethodInfo != null
fun hasShortcutIme() = isShortcutImeReady // todo fun getMyEnabledInputMethodSubtypes(allowsImplicitlySelectedSubtypes: Boolean) =
SubtypeSettings.getEnabledSubtypes(allowsImplicitlySelectedSubtypes)
fun checkIfSubtypeBelongsToThisImeAndEnabled(subtype: InputMethodSubtype?) = fun getEnabledInputMethodSubtypes(imi: InputMethodInfo, allowsImplicitlySelectedSubtypes: Boolean) =
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) =
inputMethodInfoCache.getEnabledInputMethodSubtypeList(imi, allowsImplicitlySelectedSubtypes) 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) = fun hasMultipleEnabledIMEsOrSubtypes(shouldIncludeAuxiliarySubtypes: Boolean) =
hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imm.enabledInputMethodList) hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imm.enabledInputMethodList)
fun hasMultipleEnabledSubtypesInThisIme(shouldIncludeAuxiliarySubtypes: Boolean) = fun hasMultipleEnabledSubtypesInThisIme(shouldIncludeAuxiliarySubtypes: Boolean) =
hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, listOf(inputMethodInfoOfThisIme)) SubtypeSettings.getEnabledSubtypes(shouldIncludeAuxiliarySubtypes).size > 1
fun getNextSubtypeInThisIme(onlyCurrentIme: Boolean): InputMethodSubtype? { fun getNextSubtypeInThisIme(onlyCurrentIme: Boolean): InputMethodSubtype? {
val currentSubtype = currentSubtype.rawSubtype val currentSubtype = currentSubtype.rawSubtype
val enabledSubtypes = getMyEnabledInputMethodSubtypeList(true) val enabledSubtypes = getMyEnabledInputMethodSubtypes(true)
val currentIndex = enabledSubtypes.indexOf(currentSubtype) val currentIndex = enabledSubtypes.indexOf(currentSubtype)
if (currentIndex == -1) { if (currentIndex == -1) {
Log.w(TAG, "Can't find current subtype in enabled subtypes: subtype=" + Log.w(TAG, "Can't find current subtype in enabled subtypes: subtype=" +
@ -97,22 +82,9 @@ class RichInputMethodManager private constructor() {
return enabledSubtypes[nextIndex] 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? { fun findSubtypeForHintLocale(locale: Locale): InputMethodSubtype? {
// Find the best subtype based on a locale matching // Find the best subtype based on a locale matching
val subtypes = getMyEnabledInputMethodSubtypeList(true) val subtypes = getMyEnabledInputMethodSubtypes(true)
var bestMatch = getBestMatch(locale, subtypes) { it.locale() } var bestMatch = getBestMatch(locale, subtypes) { it.locale() }
if (bestMatch != null) return bestMatch if (bestMatch != null) return bestMatch
@ -173,10 +145,11 @@ class RichInputMethodManager private constructor() {
Log.d(TAG, ("Update shortcut IME from: ${shortcutInputMethodInfo?.id ?: "<null>"}, $subtype")) Log.d(TAG, ("Update shortcut IME from: ${shortcutInputMethodInfo?.id ?: "<null>"}, $subtype"))
} }
val richSubtype = currentRichInputMethodSubtype 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() val systemLocale = context.resources.configuration.locale()
LanguageOnSpacebarUtils.onSubtypeChanged(richSubtype, implicitlyEnabledSubtype, systemLocale) LanguageOnSpacebarUtils.onSubtypeChanged(richSubtype, implicitlyEnabledSubtype, systemLocale)
LanguageOnSpacebarUtils.setEnabledSubtypes(getMyEnabledInputMethodSubtypeList(true)) LanguageOnSpacebarUtils.setEnabledSubtypes(getMyEnabledInputMethodSubtypes(true))
// TODO: Update an icon for shortcut IME // TODO: Update an icon for shortcut IME
val shortcuts = inputMethodManager.shortcutInputMethodsAndSubtypes val shortcuts = inputMethodManager.shortcutInputMethodsAndSubtypes
@ -203,7 +176,7 @@ class RichInputMethodManager private constructor() {
imiList.forEach { imi -> imiList.forEach { imi ->
// We can return true immediately after we find two or more filtered IMEs. // We can return true immediately after we find two or more filtered IMEs.
if (filteredImisCount > 1) return true if (filteredImisCount > 1) return true
val subtypes = getEnabledInputMethodSubtypeList(imi, true) val subtypes = getEnabledInputMethodSubtypes(imi, true)
// IMEs that have no subtypes should be counted. // IMEs that have no subtypes should be counted.
if (subtypes.isEmpty()) { if (subtypes.isEmpty()) {
++filteredImisCount ++filteredImisCount
@ -230,7 +203,7 @@ class RichInputMethodManager private constructor() {
if (filteredImisCount > 1) { if (filteredImisCount > 1) {
return true return true
} }
val subtypes = getMyEnabledInputMethodSubtypeList(true) val subtypes = getMyEnabledInputMethodSubtypes(true)
// imm.getEnabledInputMethodSubtypeList(null, true) will return the current IME's // imm.getEnabledInputMethodSubtypeList(null, true) will return the current IME's
// both explicitly and implicitly enabled input method subtype. // both explicitly and implicitly enabled input method subtype.
// (The current IME should be LatinIME.) // (The current IME should be LatinIME.)

View file

@ -16,7 +16,9 @@ import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.ScriptUtils import helium314.keyboard.latin.utils.ScriptUtils
import helium314.keyboard.latin.utils.ScriptUtils.script import helium314.keyboard.latin.utils.ScriptUtils.script
import helium314.keyboard.latin.utils.SubtypeLocaleUtils import helium314.keyboard.latin.utils.SubtypeLocaleUtils
import helium314.keyboard.latin.utils.SubtypeSettings
import helium314.keyboard.latin.utils.locale import helium314.keyboard.latin.utils.locale
import helium314.keyboard.latin.utils.mainLayoutNameOrQwerty
import java.util.Locale import java.util.Locale
/** /**
@ -104,11 +106,8 @@ class RichInputMethodSubtype private constructor(val rawSubtype: InputMethodSubt
val noLanguageSubtype: RichInputMethodSubtype get() { val noLanguageSubtype: RichInputMethodSubtype get() {
sNoLanguageSubtype?.let { return it } sNoLanguageSubtype?.let { return it }
var noLanguageSubtype = sNoLanguageSubtype var noLanguageSubtype = sNoLanguageSubtype
val rawNoLanguageSubtype = RichInputMethodManager.getInstance() val rawNoLanguageSubtype = SubtypeSettings.getResourceSubtypesForLocale(SubtypeLocaleUtils.NO_LANGUAGE.constructLocale())
.findSubtypeByLocaleAndKeyboardLayoutSet( .firstOrNull { it.mainLayoutNameOrQwerty() == SubtypeLocaleUtils.QWERTY }
SubtypeLocaleUtils.NO_LANGUAGE.constructLocale(),
SubtypeLocaleUtils.QWERTY
)
if (rawNoLanguageSubtype != null) { if (rawNoLanguageSubtype != null) {
noLanguageSubtype = RichInputMethodSubtype(rawNoLanguageSubtype) noLanguageSubtype = RichInputMethodSubtype(rawNoLanguageSubtype)
} }

View file

@ -26,8 +26,8 @@ fun createInputMethodPickerDialog(latinIme: LatinIME, richImm: RichInputMethodMa
val enabledSubtypes = mutableListOf<Pair<InputMethodInfo, InputMethodSubtype?>>() val enabledSubtypes = mutableListOf<Pair<InputMethodInfo, InputMethodSubtype?>>()
var currentSubtypeIndex = 0 var currentSubtypeIndex = 0
enabledImis.forEach { imi -> enabledImis.forEach { imi ->
val subtypes = if (imi != thisImi) richImm.getEnabledInputMethodSubtypeList(imi, true) val subtypes = if (imi != thisImi) richImm.getEnabledInputMethodSubtypes(imi, true)
else richImm.getEnabledInputMethodSubtypeList(imi, true).sortedBy { it.displayName() } else richImm.getEnabledInputMethodSubtypes(imi, true).sortedBy { it.displayName() }
if (subtypes.isEmpty()) { if (subtypes.isEmpty()) {
enabledSubtypes.add(imi to null) enabledSubtypes.add(imi to null)
} else { } else {

View file

@ -28,9 +28,11 @@ object SubtypeSettings {
fun getEnabledSubtypes(fallback: Boolean = false): List<InputMethodSubtype> { fun getEnabledSubtypes(fallback: Boolean = false): List<InputMethodSubtype> {
if (fallback && enabledSubtypes.isEmpty()) if (fallback && enabledSubtypes.isEmpty())
return getDefaultEnabledSubtypes() return getDefaultEnabledSubtypes()
return enabledSubtypes.toList() return enabledSubtypes
} }
fun isEnabled(subtype: InputMethodSubtype): Boolean = subtype in enabledSubtypes || subtype in getDefaultEnabledSubtypes()
fun getAllAvailableSubtypes(): List<InputMethodSubtype> = fun getAllAvailableSubtypes(): List<InputMethodSubtype> =
resourceSubtypesByLocale.values.flatten() + additionalSubtypes resourceSubtypesByLocale.values.flatten() + additionalSubtypes