mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-11 17:09:35 +00:00
fallback to default layouts on parsing errors
This commit is contained in:
parent
8b36ff1c54
commit
38547b0c81
2 changed files with 17 additions and 5 deletions
|
@ -157,10 +157,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
} catch (KeyboardLayoutSetException e) {
|
} catch (KeyboardLayoutSetException e) {
|
||||||
Log.e(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());
|
Log.e(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());
|
||||||
try {
|
try {
|
||||||
final InputMethodSubtype qwerty = SubtypeUtilsAdditional.INSTANCE
|
final InputMethodSubtype defaults = SubtypeUtilsAdditional.INSTANCE.createDefaultSubtype(mRichImm.getCurrentSubtypeLocale());
|
||||||
.createEmojiCapableAdditionalSubtype(mRichImm.getCurrentSubtypeLocale(), SubtypeLocaleUtils.QWERTY, true);
|
|
||||||
mKeyboardLayoutSet = builder.setKeyboardGeometry(keyboardWidth, keyboardHeight)
|
mKeyboardLayoutSet = builder.setKeyboardGeometry(keyboardWidth, keyboardHeight)
|
||||||
.setSubtype(RichInputMethodSubtype.Companion.get(qwerty))
|
.setSubtype(RichInputMethodSubtype.Companion.get(defaults))
|
||||||
.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey)
|
.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey)
|
||||||
.setNumberRowEnabled(settingsValues.mShowsNumberRow)
|
.setNumberRowEnabled(settingsValues.mShowsNumberRow)
|
||||||
.setLanguageSwitchKeyEnabled(settingsValues.isLanguageSwitchKeyEnabled())
|
.setLanguageSwitchKeyEnabled(settingsValues.isLanguageSwitchKeyEnabled())
|
||||||
|
@ -169,9 +168,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
.setOneHandedModeEnabled(oneHandedModeEnabled)
|
.setOneHandedModeEnabled(oneHandedModeEnabled)
|
||||||
.build();
|
.build();
|
||||||
mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState, oneHandedModeEnabled);
|
mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState, oneHandedModeEnabled);
|
||||||
showToast("error loading the keyboard, falling back to qwerty", false);
|
showToast("error loading the keyboard, falling back to defaults", false);
|
||||||
} catch (KeyboardLayoutSetException e2) {
|
} catch (KeyboardLayoutSetException e2) {
|
||||||
Log.e(TAG, "even fallback to qwerty failed: " + e2.mKeyboardId, e2.getCause());
|
Log.e(TAG, "even fallback to defaults failed: " + e2.mKeyboardId, e2.getCause());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,13 @@ import helium314.keyboard.latin.common.Constants
|
||||||
import helium314.keyboard.latin.common.Constants.Separators
|
import helium314.keyboard.latin.common.Constants.Separators
|
||||||
import helium314.keyboard.latin.common.Constants.Subtype.ExtraValue
|
import helium314.keyboard.latin.common.Constants.Subtype.ExtraValue
|
||||||
import helium314.keyboard.latin.settings.Defaults
|
import helium314.keyboard.latin.settings.Defaults
|
||||||
|
import helium314.keyboard.latin.settings.Defaults.default
|
||||||
import helium314.keyboard.latin.settings.Settings
|
import helium314.keyboard.latin.settings.Settings
|
||||||
import helium314.keyboard.latin.settings.SettingsSubtype
|
import helium314.keyboard.latin.settings.SettingsSubtype
|
||||||
import helium314.keyboard.latin.settings.SettingsSubtype.Companion.toSettingsSubtype
|
import helium314.keyboard.latin.settings.SettingsSubtype.Companion.toSettingsSubtype
|
||||||
|
import helium314.keyboard.latin.utils.LayoutType.Companion.toExtraValue
|
||||||
|
import helium314.keyboard.latin.utils.ScriptUtils.script
|
||||||
|
import java.util.EnumMap
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
object SubtypeUtilsAdditional {
|
object SubtypeUtilsAdditional {
|
||||||
|
@ -46,9 +50,18 @@ object SubtypeUtilsAdditional {
|
||||||
fun createDummyAdditionalSubtype(locale: Locale, mainLayoutName: String) =
|
fun createDummyAdditionalSubtype(locale: Locale, mainLayoutName: String) =
|
||||||
createAdditionalSubtype(locale, "${ExtraValue.KEYBOARD_LAYOUT_SET}=MAIN${Separators.KV}$mainLayoutName", false, false)
|
createAdditionalSubtype(locale, "${ExtraValue.KEYBOARD_LAYOUT_SET}=MAIN${Separators.KV}$mainLayoutName", false, false)
|
||||||
|
|
||||||
|
// only used in tests
|
||||||
fun createEmojiCapableAdditionalSubtype(locale: Locale, mainLayoutName: String, asciiCapable: Boolean) =
|
fun createEmojiCapableAdditionalSubtype(locale: Locale, mainLayoutName: String, asciiCapable: Boolean) =
|
||||||
createAdditionalSubtype(locale, "${ExtraValue.KEYBOARD_LAYOUT_SET}=MAIN${Separators.KV}$mainLayoutName", asciiCapable, true)
|
createAdditionalSubtype(locale, "${ExtraValue.KEYBOARD_LAYOUT_SET}=MAIN${Separators.KV}$mainLayoutName", asciiCapable, true)
|
||||||
|
|
||||||
|
/** creates a subtype with every layout being the default for its type */
|
||||||
|
fun createDefaultSubtype(locale: Locale): InputMethodSubtype {
|
||||||
|
val layouts = LayoutType.entries.associateWithTo(LayoutType.getLayoutMap(null)) { it.default }
|
||||||
|
SubtypeSettings.getResourceSubtypesForLocale(locale).firstOrNull()?.mainLayoutName()?.let { layouts[LayoutType.MAIN] = it }
|
||||||
|
val extra = ExtraValue.KEYBOARD_LAYOUT_SET + "=" + layouts.toExtraValue()
|
||||||
|
return createAdditionalSubtype(locale, extra, locale.script() == ScriptUtils.SCRIPT_LATIN, true)
|
||||||
|
}
|
||||||
|
|
||||||
fun removeAdditionalSubtype(context: Context, subtype: InputMethodSubtype) {
|
fun removeAdditionalSubtype(context: Context, subtype: InputMethodSubtype) {
|
||||||
val prefs = context.prefs()
|
val prefs = context.prefs()
|
||||||
SubtypeSettings.removeEnabledSubtype(context, subtype)
|
SubtypeSettings.removeEnabledSubtype(context, subtype)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue