From 4629410230b50c07d873f21db57b2be9052724f1 Mon Sep 17 00:00:00 2001
From: Jules Aguillon
Date: Sun, 14 Jul 2024 16:15:18 +0200
Subject: Fix unintended layout used for unsupported languages
The arabic layout was used as the default on devices where all the
installed languages are not supported by the keyboard. This is not
intended.
This is probably caused by 'getCurrentInputMethodSubtype' returning the
first layout in the list of disabled subtypes in alphabetical or
language tag order.
Re-ordering the subtypes in method.xml had no effect.
Setting 'overridesImplicitlyEnabledSubtype' in method.xml has no
measured effect.
---
res/xml/method.xml | 2 +-
srcs/juloo.keyboard2/Keyboard2.java | 23 ++++++++++++++++-------
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/res/xml/method.xml b/res/xml/method.xml
index 49d5063..88fb097 100644
--- a/res/xml/method.xml
+++ b/res/xml/method.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java
index 0c82aaf..f08f177 100644
--- a/srcs/juloo.keyboard2/Keyboard2.java
+++ b/srcs/juloo.keyboard2/Keyboard2.java
@@ -136,13 +136,9 @@ public class Keyboard2 extends InputMethodService
return ExtraKeys.EMPTY;
}
- @TargetApi(12)
- private void refreshAccentsOption(InputMethodManager imm, InputMethodSubtype subtype)
+ private void refreshAccentsOption(InputMethodManager imm, List enabled_subtypes)
{
- List enabled_subtypes = getEnabledSubtypes(imm);
List extra_keys = new ArrayList();
- // Gather extra keys from all enabled subtypes
- extra_keys.add(extra_keys_of_subtype(subtype));
for (InputMethodSubtype s : enabled_subtypes)
extra_keys.add(extra_keys_of_subtype(s));
_config.extra_keys_subtype = ExtraKeys.merge(extra_keys);
@@ -153,6 +149,18 @@ public class Keyboard2 extends InputMethodService
return (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
}
+ @TargetApi(12)
+ private String defaultLayoutForSubtypes(InputMethodManager imm, List enabled_subtypes)
+ {
+ // Android might return a random subtype, for example, the first in the
+ // list alphabetically.
+ InputMethodSubtype current_subtype = imm.getCurrentInputMethodSubtype();
+ for (InputMethodSubtype s : enabled_subtypes)
+ if (s.getLanguageTag().equals(current_subtype.getLanguageTag()))
+ return s.getExtraValueOf("default_layout");
+ return null;
+ }
+
private void refreshSubtypeImm()
{
InputMethodManager imm = get_imm();
@@ -161,13 +169,14 @@ public class Keyboard2 extends InputMethodService
_config.extra_keys_subtype = null;
if (VERSION.SDK_INT >= 12)
{
+ List enabled_subtypes = getEnabledSubtypes(imm);
InputMethodSubtype subtype = imm.getCurrentInputMethodSubtype();
if (subtype != null)
{
- String s = subtype.getExtraValueOf("default_layout");
+ String s = defaultLayoutForSubtypes(imm, enabled_subtypes);
if (s != null)
default_layout = LayoutsPreference.layout_of_string(getResources(), s);
- refreshAccentsOption(imm, subtype);
+ refreshAccentsOption(imm, enabled_subtypes);
}
}
if (default_layout == null)
--
cgit v1.2.3