abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/Config.java
diff options
context:
space:
mode:
authorJules Aguillon2022-05-29 12:27:46 +0200
committerJules Aguillon2022-05-29 12:27:46 +0200
commit2e81cb5cf717ef68df9bd66d2af1c7f5ccaaa3fe (patch)
tree6349235c0f0e63371a910428be3915fad016eef5 /srcs/juloo.keyboard2/Config.java
parent89dfc782a7985053728d54072fb104728796a843 (diff)
downloadunexpected-keyboard-2e81cb5cf717ef68df9bd66d2af1c7f5ccaaa3fe.tar.gz
unexpected-keyboard-2e81cb5cf717ef68df9bd66d2af1c7f5ccaaa3fe.zip
Automatically place localized keys on the layouts
Layouts no longer need to mention every localized keys and dead keys. They are now placed automatically starting from the second row on the bottom-right corner. The "loc " prefix is not removed to still be able to define a more optimal and consistent placement for some extra keys (eg. 'ß' near 's'). Programming layouts no longer need to place every dead keys.
Diffstat (limited to 'srcs/juloo.keyboard2/Config.java')
-rw-r--r--srcs/juloo.keyboard2/Config.java28
1 files changed, 22 insertions, 6 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java
index fd0c3ec..199fe35 100644
--- a/srcs/juloo.keyboard2/Config.java
+++ b/srcs/juloo.keyboard2/Config.java
@@ -9,6 +9,7 @@ import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.KeyEvent;
+import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;
@@ -142,20 +143,26 @@ final class Config
/** Update the layout according to the configuration.
* - Remove the switching key if it isn't needed
- * - Remove keys from other locales (not in 'extra_keys')
+ * - Remove "localized" keys from other locales (not in 'extra_keys')
* - Replace the action key to show the right label
* - Swap the enter and action keys
*/
- public KeyboardData modify_layout(KeyboardData kw)
+ public KeyboardData modify_layout(KeyboardData original_kw)
{
// Update the name to avoid caching in KeyModifier
final KeyValue action_key = (actionLabel == null) ? null :
KeyValue.getKeyByName("action").withNameAndSymbol(actionLabel, actionLabel);
- return kw.replaceKeys(new KeyboardData.MapKeys() {
+ // Extra keys are removed from the set as they are encountered during the
+ // first iteration then automatically added.
+ final Set<String> extra_keys = new HashSet<String>(this.extra_keys);
+ KeyboardData kw = original_kw.mapKeys(new KeyboardData.MapKeyValues() {
public KeyValue apply(KeyValue key)
{
if (key == null)
return null;
+ boolean is_extra_key = extra_keys.contains(key.name);
+ if (is_extra_key)
+ extra_keys.remove(key.name);
switch (key.eventCode)
{
case KeyValue.EVENT_CHANGE_METHOD:
@@ -170,9 +177,7 @@ final class Config
default:
if (key.flags != 0)
{
- if ((key.flags & KeyValue.FLAG_LOCALIZED) != 0 &&
- extra_keys != null &&
- !extra_keys.contains(key.name))
+ if ((key.flags & KeyValue.FLAG_LOCALIZED) != 0 && !is_extra_key)
return null;
if ((key.flags & lockable_modifiers) != 0)
return key.withFlags(key.flags | KeyValue.FLAG_LOCK);
@@ -181,6 +186,17 @@ final class Config
}
}
});
+ if (extra_keys.size() > 0)
+ {
+ final Iterator<String> extra_keys_it = extra_keys.iterator();
+ kw = kw.addExtraKeys(
+ new Iterator<KeyValue>()
+ {
+ public boolean hasNext() { return extra_keys_it.hasNext(); }
+ public KeyValue next() { return KeyValue.getKeyByName(extra_keys_it.next()); }
+ });
+ }
+ return kw;
}
private float getDipPref(DisplayMetrics dm, SharedPreferences prefs, String pref_name, float def)