From 90b7944129ae0facc5c789f0a416f7ff36925a90 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 30 Jan 2023 22:33:01 +0100 Subject: [PATCH] Apply modify_layout to text layout only Refactor. Allows to remove the 'extra_keys' and 'num_pad' flags and to implement more complicated transformations to the layouts. --- res/xml/greekmath.xml | 2 +- res/xml/numeric.xml | 2 +- res/xml/pin.xml | 2 +- srcs/juloo.keyboard2/Config.java | 2 +- srcs/juloo.keyboard2/Keyboard2.java | 9 +++++++-- srcs/juloo.keyboard2/Keyboard2View.java | 2 +- srcs/juloo.keyboard2/KeyboardData.java | 22 +++++----------------- 7 files changed, 17 insertions(+), 24 deletions(-) diff --git a/res/xml/greekmath.xml b/res/xml/greekmath.xml index ff467e8..dd3ba3a 100644 --- a/res/xml/greekmath.xml +++ b/res/xml/greekmath.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/numeric.xml b/res/xml/numeric.xml index 9e6bc69..b64331e 100644 --- a/res/xml/numeric.xml +++ b/res/xml/numeric.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/pin.xml b/res/xml/pin.xml index db04fd5..9a8f75d 100644 --- a/res/xml/pin.xml +++ b/res/xml/pin.xml @@ -1,5 +1,5 @@ - + diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index b9546b2..691a424 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -170,7 +170,7 @@ final class Config if (extra_keys_subtype != null) extra_keys.addAll(extra_keys_subtype); extra_keys.addAll(extra_keys_param); - if (kw.num_pad && show_numpad) + if (show_numpad) kw = kw.addNumPad(); kw = kw.mapKeys(new KeyboardData.MapKeyValues() { /** Apply to the center value only. Partial match, fallback to [apply]. */ diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 6558539..5070439 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -47,9 +47,14 @@ public class Keyboard2 extends InputMethodService { if (_currentSpecialLayout != null) return _currentSpecialLayout; + KeyboardData layout; if (_currentTextLayout == Current_text_layout.SECONDARY) - return _config.second_layout; - return (_config.layout == null) ? _localeTextLayout : _config.layout; + layout = _config.second_layout; + else if (_config.layout == null) + layout = _localeTextLayout; + else + layout = _config.layout; + return _config.modify_layout(layout); } void setTextLayout(Current_text_layout layout) diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index be7647d..17b5eec 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -81,7 +81,7 @@ public class Keyboard2View extends View public void setKeyboard(KeyboardData kw) { - _keyboard = _config.modify_layout(kw); + _keyboard = kw; _shift_kv = KeyValue.getKeyByName("shift"); _shift_key = _keyboard.findKeyWithValue(_shift_kv); if (_shift_key == null) diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index 542c173..e3262bf 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -19,17 +19,13 @@ class KeyboardData public final float keysWidth; /** Total height of the keyboard. */ public final float keysHeight; - /** Whether to add extra keys. */ - public final boolean extra_keys; - /** Whether to possibly add NumPad. */ - public final boolean num_pad; public KeyboardData mapKeys(MapKey f) { ArrayList rows_ = new ArrayList(); for (Row r : rows) rows_.add(r.mapKeys(f)); - return new KeyboardData(rows_, keysWidth, extra_keys, num_pad); + return new KeyboardData(rows_, keysWidth); } /** Add keys from the given iterator into the keyboard. Extra keys are added @@ -38,8 +34,6 @@ class KeyboardData * third row. */ public KeyboardData addExtraKeys(Iterator k) { - if (!extra_keys) - return this; ArrayList rows = new ArrayList(this.rows); addExtraKeys_to_row(rows, k, 1, 4); addExtraKeys_to_row(rows, k, 1, 3); @@ -51,13 +45,11 @@ class KeyboardData for (int c = 1; c <= 4; c++) addExtraKeys_to_row(rows, k, r, c); } - return new KeyboardData(rows, keysWidth, extra_keys, num_pad); + return new KeyboardData(rows, keysWidth); } public KeyboardData addNumPad() { - if (!num_pad) - return this; ArrayList extendedRows = new ArrayList(); Iterator iterNumPadRows = _num_pad.rows.iterator(); for (Row row : rows) @@ -76,7 +68,7 @@ class KeyboardData } extendedRows.add(new Row(keys, row.height, row.shift)); } - return new KeyboardData(extendedRows, compute_max_width(extendedRows), extra_keys, num_pad); + return new KeyboardData(extendedRows, compute_max_width(extendedRows)); } public Key findKeyWithValue(KeyValue kv) @@ -170,8 +162,6 @@ class KeyboardData if (!expect_tag(parser, "keyboard")) throw new Exception("Empty layout file"); boolean bottom_row = attribute_bool(parser, "bottom_row", true); - boolean extra_keys = attribute_bool(parser, "extra_keys", true); - boolean num_pad = attribute_bool(parser, "num_pad", true); float specified_kw = attribute_float(parser, "width", 0f); ArrayList rows = new ArrayList(); while (expect_tag(parser, "row")) @@ -179,7 +169,7 @@ class KeyboardData float kw = (specified_kw != 0f) ? specified_kw : compute_max_width(rows); if (bottom_row) rows.add(_bottom_row.updateWidth(kw)); - return new KeyboardData(rows, kw, extra_keys, num_pad); + return new KeyboardData(rows, kw); } private static float compute_max_width(List rows) @@ -197,7 +187,7 @@ class KeyboardData return Row.parse(parser); } - protected KeyboardData(List rows_, float kw, boolean xk, boolean np) + protected KeyboardData(List rows_, float kw) { float kh = 0.f; for (Row r : rows_) @@ -205,8 +195,6 @@ class KeyboardData rows = rows_; keysWidth = kw; keysHeight = kh; - extra_keys = xk; - num_pad = np; } public static class Row