From c7184303e9e291487641324468ec60417ef47bf7 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 30 Jan 2023 23:54:39 +0100 Subject: [PATCH] Remove the digits when numpad is visible --- srcs/juloo.keyboard2/Config.java | 7 +++- srcs/juloo.keyboard2/KeyboardData.java | 48 +++++++++++++++++++------- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index db570e1..5ff7951 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -172,11 +172,12 @@ final class Config // Extra keys are removed from the set as they are encountered during the // first iteration then automatically added. final Set extra_keys = new HashSet(); + final Set remove_keys = new HashSet(); if (extra_keys_subtype != null) extra_keys.addAll(extra_keys_subtype); extra_keys.addAll(extra_keys_param); if (show_numpad) - kw = kw.addNumPad(); + KeyboardData.num_pad.getKeys(remove_keys); kw = kw.mapKeys(new KeyboardData.MapKeyValues() { public KeyValue apply(KeyValue key, boolean localized) { @@ -185,6 +186,8 @@ final class Config extra_keys.remove(key); if (localized && !is_extra_key) return null; + if (remove_keys.contains(key)) + return null; switch (key.getKind()) { case Event: @@ -218,6 +221,8 @@ final class Config return key; } }); + if (show_numpad) + kw = kw.addNumPad(); if (extra_keys.size() > 0) kw = kw.addExtraKeys(extra_keys.iterator()); return kw; diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index 31112b5..5130284 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -9,6 +9,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.function.Function; import org.xmlpull.v1.XmlPullParser; @@ -51,7 +52,7 @@ class KeyboardData public KeyboardData addNumPad() { ArrayList extendedRows = new ArrayList(); - Iterator iterNumPadRows = _num_pad.rows.iterator(); + Iterator iterNumPadRows = num_pad.rows.iterator(); for (Row row : rows) { ArrayList keys = new ArrayList(row.keys); @@ -82,6 +83,12 @@ class KeyboardData return null; } + public void getKeys(Set dst) + { + for (Row r : rows) + r.getKeys(dst); + } + private static void addExtraKeys_to_row(ArrayList rows, final Iterator extra_keys, int row_i, final int d) { if (!extra_keys.hasNext()) @@ -96,17 +103,17 @@ class KeyboardData })); } - private static Row _bottom_row; - private static KeyboardData _num_pad; - private static KeyboardData _pin_entry; + public static Row bottom_row; + public static KeyboardData num_pad; + public static KeyboardData pin_entry; private static Map _layoutCache = new HashMap(); public static void init(Resources res) { try { - _bottom_row = parse_bottom_row(res.getXml(R.xml.bottom_row)); - _num_pad = parse_keyboard(res.getXml(R.xml.numpad)); + bottom_row = parse_bottom_row(res.getXml(R.xml.bottom_row)); + num_pad = parse_keyboard(res.getXml(R.xml.numpad)); } catch (Exception e) { @@ -116,9 +123,9 @@ class KeyboardData public static KeyboardData load_pin_entry(Resources res) { - if (_pin_entry == null) - _pin_entry = load(res, R.xml.pin); - return _pin_entry; + if (pin_entry == null) + pin_entry = load(res, R.xml.pin); + return pin_entry; } /** Load a layout from a resource ID. Returns [null] on error. */ @@ -161,14 +168,14 @@ class KeyboardData { if (!expect_tag(parser, "keyboard")) throw new Exception("Empty layout file"); - boolean bottom_row = attribute_bool(parser, "bottom_row", true); + boolean add_bottom_row = attribute_bool(parser, "bottom_row", true); float specified_kw = attribute_float(parser, "width", 0f); ArrayList rows = new ArrayList(); while (expect_tag(parser, "row")) rows.add(Row.parse(parser)); float kw = (specified_kw != 0f) ? specified_kw : compute_max_width(rows); - if (bottom_row) - rows.add(_bottom_row.updateWidth(kw)); + if (add_bottom_row) + rows.add(bottom_row.updateWidth(kw)); return new KeyboardData(rows, kw); } @@ -228,6 +235,12 @@ class KeyboardData return new Row(keys, h, shift); } + public void getKeys(Set dst) + { + for (Key k : keys) + k.getKeys(dst); + } + public Row mapKeys(MapKey f) { ArrayList keys_ = new ArrayList(); @@ -317,6 +330,17 @@ class KeyboardData slider, indication); } + public void getKeys(Set dst) + { + getCorner(dst, key0); + getCorner(dst, key1); + getCorner(dst, key2); + getCorner(dst, key3); + getCorner(dst, key4); + } + + void getCorner(Set dst, Corner k) { if (k != null) dst.add(k.kv); } + public KeyValue getKeyValue(int i) { Corner c;