From 304375268d520687d41dc7834c442347d638da9c Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Wed, 29 May 2024 11:56:26 +0200 Subject: Fix uninitialized bottom_row when editing custom layout This happen when opening the settings from the launcher activity without ever opening the keyboard. To remove this bug entirely, the KeyboardData.init method is removed, the pieces needing initialization are now cached in Config. --- srcs/juloo.keyboard2/KeyboardData.java | 45 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'srcs/juloo.keyboard2/KeyboardData.java') diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index d174957..6206f5b 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -29,6 +29,8 @@ public final class KeyboardData public final String numpad_script; /** The [name] attribute. Might be null. */ public final String name; + /** Whether the bottom row should be added. */ + public final boolean bottom_row; /** Position of every keys on the layout, see [getKeys()]. */ private Map _key_pos = null; @@ -132,10 +134,12 @@ public final class KeyboardData return new KeyboardData(this, extendedRows); } - public KeyboardData addTopRow(Row row) + /** Insert the given row at the given indice. The row is scaled so that the + keys already on the keyboard don't change width. */ + public KeyboardData insert_row(Row row, int i) { ArrayList rows_ = new ArrayList(this.rows); - rows_.add(0, row.updateWidth(keysWidth)); + rows_.add(i, row.updateWidth(keysWidth)); return new KeyboardData(this, rows_); } @@ -159,23 +163,21 @@ public final class KeyboardData return _key_pos; } - public static Row bottom_row; - public static Row number_row; - public static KeyboardData num_pad; private static Map _layoutCache = new HashMap(); - public static void init(Resources res) + public static Row load_bottom_row(Resources res) throws Exception { - try - { - bottom_row = parse_row(res.getXml(R.xml.bottom_row)); - number_row = parse_row(res.getXml(R.xml.number_row)); - num_pad = parse_keyboard(res.getXml(R.xml.numpad)); - } - catch (Exception e) - { - e.printStackTrace(); - } + return parse_row(res.getXml(R.xml.bottom_row)); + } + + public static Row load_number_row(Resources res) throws Exception + { + return parse_row(res.getXml(R.xml.number_row)); + } + + public static KeyboardData load_num_pad(Resources res) throws Exception + { + return parse_keyboard(res.getXml(R.xml.numpad)); } /** Load a layout from a resource ID. Returns [null] on error. */ @@ -225,7 +227,7 @@ public final class KeyboardData { if (!expect_tag(parser, "keyboard")) throw error(parser, "Expected tag "); - boolean add_bottom_row = attribute_bool(parser, "bottom_row", true); + boolean bottom_row = attribute_bool(parser, "bottom_row", true); float specified_kw = attribute_float(parser, "width", 0f); String script = parser.getAttributeValue(null, "script"); String numpad_script = parser.getAttributeValue(null, "numpad_script"); @@ -249,9 +251,7 @@ public final class KeyboardData } } float kw = (specified_kw != 0f) ? specified_kw : compute_max_width(rows); - if (add_bottom_row) - rows.add(bottom_row.updateWidth(kw)); - return new KeyboardData(rows, kw, modmap, script, numpad_script, name); + return new KeyboardData(rows, kw, modmap, script, numpad_script, name, bottom_row); } private static float compute_max_width(List rows) @@ -270,7 +270,7 @@ public final class KeyboardData } protected KeyboardData(List rows_, float kw, Modmap mm, String sc, - String npsc, String name_) + String npsc, String name_, boolean bottom_row_) { float kh = 0.f; for (Row r : rows_) @@ -282,13 +282,14 @@ public final class KeyboardData name = name_; keysWidth = kw; keysHeight = kh; + bottom_row = bottom_row_; } /** Copies the fields of an other keyboard, with rows changed. */ protected KeyboardData(KeyboardData src, List rows) { this(rows, compute_max_width(rows), src.modmap, src.script, - src.numpad_script, src.name); + src.numpad_script, src.name, src.bottom_row); } public static class Row -- cgit v1.2.3