From baec5a76ee51e86c8256423924331908da75279f Mon Sep 17 00:00:00 2001 From: Gero Streng Date: Sun, 25 Sep 2022 02:23:33 +0200 Subject: Add optional NumPad Shows a NumPad depending on preference: Never/Landscape/Always --- srcs/juloo.keyboard2/KeyboardData.java | 49 ++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'srcs/juloo.keyboard2/KeyboardData.java') diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index 5bbbac1..21acde7 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -18,13 +18,15 @@ class KeyboardData 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); + return new KeyboardData(rows_, keysWidth, extra_keys, num_pad); } /** Add keys from the given iterator into the keyboard. Extra keys are added @@ -46,7 +48,32 @@ class KeyboardData for (int c = 1; c <= 4; c++) addExtraKeys_to_row(rows, k, r, c); } - return new KeyboardData(rows, keysWidth, extra_keys); + return new KeyboardData(rows, keysWidth, extra_keys, num_pad); + } + + public KeyboardData addNumPad() + { + if (!num_pad || _numPadKeyboardData == null) + return this; + ArrayList extendedRows = new ArrayList(); + Iterator iterNumPadRows = _numPadKeyboardData.rows.iterator(); + for (Row row : rows) + { + ArrayList keys = new ArrayList(row.keys); + if (iterNumPadRows.hasNext()) + { + Row numPadRow = iterNumPadRows.next(); + List nps = numPadRow.keys; + if (nps.size() > 0) { + float firstNumPadShift = 0.5f + keysWidth - row.keysWidth; + keys.add(nps.get(0).withShift(firstNumPadShift)); + for (int i = 1; i < nps.size(); i++) + keys.add(nps.get(i)); + } + } + extendedRows.add(new Row(keys, row.height, row.shift)); + } + return new KeyboardData(extendedRows, compute_max_width(extendedRows), extra_keys, num_pad); } public Key findKeyWithValue(KeyValue kv) @@ -75,6 +102,7 @@ class KeyboardData } private static Row _bottomRow = null; + private static KeyboardData _numPadKeyboardData = null; private static Map _layoutCache = new HashMap(); public static KeyboardData load(Resources res, int id) @@ -86,6 +114,10 @@ class KeyboardData { if (_bottomRow == null) _bottomRow = parse_bottom_row(res.getXml(R.xml.bottom_row)); + if (_numPadKeyboardData == null) + { + _numPadKeyboardData = parse_keyboard(res.getXml(R.xml.numpad)); + } l = parse_keyboard(res.getXml(id)); _layoutCache.put(id, l); } @@ -103,13 +135,14 @@ class KeyboardData throw new Exception("Empty layout file"); boolean bottom_row = parser.getAttributeBooleanValue(null, "bottom_row", true); boolean extra_keys = parser.getAttributeBooleanValue(null, "extra_keys", true); + boolean num_pad = parser.getAttributeBooleanValue(null, "num_pad", true); ArrayList rows = new ArrayList(); while (expect_tag(parser, "row")) rows.add(Row.parse(parser)); float kw = compute_max_width(rows); if (bottom_row) rows.add(_bottomRow.updateWidth(kw)); - return new KeyboardData(rows, kw, extra_keys); + return new KeyboardData(rows, kw, extra_keys, num_pad); } private static float compute_max_width(List rows) @@ -127,7 +160,7 @@ class KeyboardData return Row.parse(parser); } - protected KeyboardData(List rows_, float kw, boolean xk) + protected KeyboardData(List rows_, float kw, boolean xk, boolean np) { float kh = 0.f; for (Row r : rows_) @@ -136,6 +169,7 @@ class KeyboardData keysWidth = kw; keysHeight = kh; extra_keys = xk; + num_pad = np; } public static class Row @@ -146,7 +180,7 @@ class KeyboardData /** Extra empty space on the top. */ public final float shift; /** Total width of the row. */ - private final float keysWidth; + public final float keysWidth; protected Row(List keys_, float h, float s) { @@ -278,6 +312,11 @@ class KeyboardData return new Key(k0, k1, k2, k3, k4, width, shift, edgekeys); } + public Key withShift(float s) + { + return new Key(key0, key1, key2, key3, key4, width, s, edgekeys); + } + /** * See Pointers.onTouchMove() for the represented direction. */ -- cgit v1.2.3