abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/KeyboardData.java
diff options
context:
space:
mode:
authorJules Aguillon2022-11-26 22:12:40 +0100
committerJules Aguillon2022-11-26 22:14:29 +0100
commit69994a55c5b15f9bd9bd9cb750e5db6b9613616b (patch)
tree90273865ce0d76419af07a8b83ce85319e7f4b3e /srcs/juloo.keyboard2/KeyboardData.java
parentebdacbc2b2ac48e137dd9a1409aa334512e2fb62 (diff)
downloadunexpected-keyboard-69994a55c5b15f9bd9bd9cb750e5db6b9613616b.tar.gz
unexpected-keyboard-69994a55c5b15f9bd9bd9cb750e5db6b9613616b.zip
Refactor: Pass layout as a KeyboardData instead of ID
Parse layouts sooner.
Diffstat (limited to 'srcs/juloo.keyboard2/KeyboardData.java')
-rw-r--r--srcs/juloo.keyboard2/KeyboardData.java37
1 files changed, 26 insertions, 11 deletions
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java
index 0f67dfe..2a5cffa 100644
--- a/srcs/juloo.keyboard2/KeyboardData.java
+++ b/srcs/juloo.keyboard2/KeyboardData.java
@@ -53,10 +53,10 @@ class KeyboardData
public KeyboardData addNumPad()
{
- if (!num_pad || _numPadKeyboardData == null)
+ if (!num_pad)
return this;
ArrayList<Row> extendedRows = new ArrayList<Row>();
- Iterator<Row> iterNumPadRows = _numPadKeyboardData.rows.iterator();
+ Iterator<Row> iterNumPadRows = _num_pad.rows.iterator();
for (Row row : rows)
{
ArrayList<KeyboardData.Key> keys = new ArrayList<Key>(row.keys);
@@ -101,10 +101,31 @@ class KeyboardData
}));
}
- private static Row _bottomRow = null;
- private static KeyboardData _numPadKeyboardData = null;
+ private static Row _bottom_row;
+ private static KeyboardData _num_pad;
+ private static KeyboardData _pin_entry;
private static Map<Integer, KeyboardData> _layoutCache = new HashMap<Integer, KeyboardData>();
+ 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));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public static KeyboardData load_pin_entry(Resources res)
+ {
+ if (_pin_entry == null)
+ _pin_entry = load(res, R.xml.pin);
+ return _pin_entry;
+ }
+
public static KeyboardData load(Resources res, int id)
{
KeyboardData l = _layoutCache.get(id);
@@ -112,12 +133,6 @@ class KeyboardData
{
try
{
- 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);
}
@@ -142,7 +157,7 @@ class KeyboardData
rows.add(Row.parse(parser));
float kw = (specified_kw != 0f) ? specified_kw : compute_max_width(rows);
if (bottom_row)
- rows.add(_bottomRow.updateWidth(kw));
+ rows.add(_bottom_row.updateWidth(kw));
return new KeyboardData(rows, kw, extra_keys, num_pad);
}