From 9bcfec8bd1c1662b250c0a313505aa6e0bc06383 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sat, 24 Jun 2023 23:29:24 +0200 Subject: Per-script extra keys Allows to define a locale's script in 'method.xml' and use that to add the extra keys for a locale to layouts of the same script only. A locale of an undefined script will add its extra keys to every layouts. A layout of an undefined script will have the extra keys of all the enabled locales. --- srcs/juloo.keyboard2/ExtraKeys.java | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 srcs/juloo.keyboard2/ExtraKeys.java (limited to 'srcs/juloo.keyboard2/ExtraKeys.java') diff --git a/srcs/juloo.keyboard2/ExtraKeys.java b/srcs/juloo.keyboard2/ExtraKeys.java new file mode 100644 index 0000000..22187c1 --- /dev/null +++ b/srcs/juloo.keyboard2/ExtraKeys.java @@ -0,0 +1,57 @@ +package juloo.keyboard2; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +class ExtraKeys +{ + Map> _keys_per_script; + + public ExtraKeys() + { + _keys_per_script = new HashMap>(); + } + + public void add_keys_for_script(String script, List kvs) + { + List ks = _keys_per_script.get(script); + if (ks == null) ks = new ArrayList(); + ks.addAll(kvs); + _keys_per_script.put(script, ks); + } + + /** Add the keys that should be added to the keyboard into [dst]. [null] is + a valid script. */ + public void compute(Set dst, String script) + { + if (script == null) + { + for (String sc : _keys_per_script.keySet()) + get_keys_of_script(dst, sc); + } + else + { + get_keys_of_script(dst, null); + get_keys_of_script(dst, script); + } + } + + void get_keys_of_script(Set dst, String script) + { + List ks = _keys_per_script.get(script); + if (ks != null) + dst.addAll(ks); + } + + public static List parse_extra_keys(String str) + { + List dst = new ArrayList(); + String[] ks = str.split("\\|"); + for (int i = 0; i < ks.length; i++) + dst.add(KeyValue.getKeyByName(ks[i])); + return dst; + } +} -- cgit v1.2.3