diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt index 11da895df..fc002a187 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt @@ -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 } diff --git a/app/src/main/java/helium314/keyboard/latin/InputAttributes.java b/app/src/main/java/helium314/keyboard/latin/InputAttributes.java index a8b51659a..51aae327c 100644 --- a/app/src/main/java/helium314/keyboard/latin/InputAttributes.java +++ b/app/src/main/java/helium314/keyboard/latin/InputAttributes.java @@ -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( diff --git a/app/src/main/java/helium314/keyboard/latin/LatinIME.java b/app/src/main/java/helium314/keyboard/latin/LatinIME.java index d58c7609d..3a65b8f93 100644 --- a/app/src/main/java/helium314/keyboard/latin/LatinIME.java +++ b/app/src/main/java/helium314/keyboard/latin/LatinIME.java @@ -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) diff --git a/app/src/main/java/helium314/keyboard/latin/RichInputMethodManager.kt b/app/src/main/java/helium314/keyboard/latin/RichInputMethodManager.kt index 1bfb0bb71..b432e48dc 100644 --- a/app/src/main/java/helium314/keyboard/latin/RichInputMethodManager.kt +++ b/app/src/main/java/helium314/keyboard/latin/RichInputMethodManager.kt @@ -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.."}, $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.) diff --git a/app/src/main/java/helium314/keyboard/latin/RichInputMethodSubtype.kt b/app/src/main/java/helium314/keyboard/latin/RichInputMethodSubtype.kt index d79fc4133..0b0ccd8b9 100644 --- a/app/src/main/java/helium314/keyboard/latin/RichInputMethodSubtype.kt +++ b/app/src/main/java/helium314/keyboard/latin/RichInputMethodSubtype.kt @@ -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) } diff --git a/app/src/main/java/helium314/keyboard/latin/utils/InputMethodPicker.kt b/app/src/main/java/helium314/keyboard/latin/utils/InputMethodPicker.kt index 9879af717..71c5bda4d 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/InputMethodPicker.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/InputMethodPicker.kt @@ -26,8 +26,8 @@ fun createInputMethodPickerDialog(latinIme: LatinIME, richImm: RichInputMethodMa val enabledSubtypes = mutableListOf>() 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 { diff --git a/app/src/main/java/helium314/keyboard/latin/utils/SubtypeSettings.kt b/app/src/main/java/helium314/keyboard/latin/utils/SubtypeSettings.kt index 69db1b4a4..4a7aa9d2f 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/SubtypeSettings.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/SubtypeSettings.kt @@ -28,9 +28,11 @@ object SubtypeSettings { fun getEnabledSubtypes(fallback: Boolean = false): List { 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 = resourceSubtypesByLocale.values.flatten() + additionalSubtypes