abouttreesummaryrefslogcommitdiff
path: root/srcs
diff options
context:
space:
mode:
authorJules Aguillon2024-05-29 11:56:26 +0200
committerJules Aguillon2024-05-29 11:56:26 +0200
commit304375268d520687d41dc7834c442347d638da9c (patch)
tree9271983cd081ef4bcc60d4f4956370c26d1287ef /srcs
parent9d89297c15fa855215560890b46d993f732bd35a (diff)
downloadunexpected-keyboard-304375268d520687d41dc7834c442347d638da9c.tar.gz
unexpected-keyboard-304375268d520687d41dc7834c442347d638da9c.zip
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.
Diffstat (limited to 'srcs')
-rw-r--r--srcs/juloo.keyboard2/Config.java36
-rw-r--r--srcs/juloo.keyboard2/Keyboard2.java1
-rw-r--r--srcs/juloo.keyboard2/KeyboardData.java45
3 files changed, 49 insertions, 33 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java
index 9e9774b..09b3157 100644
--- a/srcs/juloo.keyboard2/Config.java
+++ b/srcs/juloo.keyboard2/Config.java
@@ -28,13 +28,17 @@ public final class Config
public final float labelTextSize;
public final float sublabelTextSize;
+ public final KeyboardData.Row bottom_row;
+ public final KeyboardData.Row number_row;
+ public final KeyboardData num_pad;
+
// From preferences
/** [null] represent the [system] layout. */
public List<KeyboardData> layouts;
public boolean show_numpad = false;
// From the 'numpad_layout' option, also apply to the numeric pane.
public boolean inverse_numpad = false;
- public boolean number_row;
+ public boolean add_number_row;
public float swipe_dist_px;
public float slide_step_px;
// Let the system handle vibration when false.
@@ -86,6 +90,16 @@ public final class Config
keyPadding = res.getDimension(R.dimen.key_padding);
labelTextSize = 0.33f;
sublabelTextSize = 0.22f;
+ try
+ {
+ number_row = KeyboardData.load_number_row(res);
+ bottom_row = KeyboardData.load_bottom_row(res);
+ num_pad = KeyboardData.load_num_pad(res);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e.getMessage()); // Not recoverable
+ }
// from prefs
refresh(res);
// initialized later
@@ -123,7 +137,7 @@ public final class Config
}
layouts = LayoutsPreference.load_from_preferences(res, _prefs);
inverse_numpad = _prefs.getString("numpad_layout", "default").equals("low_first");
- number_row = _prefs.getBoolean("number_row", false);
+ add_number_row = _prefs.getBoolean("number_row", false);
// The baseline for the swipe distance correspond to approximately the
// width of a key in portrait mode, as most layouts have 10 columns.
// Multipled by the DPI ratio because most swipes are made in the diagonals.
@@ -223,11 +237,13 @@ public final class Config
extra_keys_subtype.compute(extra_keys,
new ExtraKeys.Query(kw.script, present));
}
- KeyboardData.Row number_row = null;
- if (this.number_row && !show_numpad)
- number_row = modify_number_row(KeyboardData.number_row, kw);
- if (number_row != null)
- remove_keys.addAll(number_row.getKeys(0).keySet());
+ KeyboardData.Row added_number_row = null;
+ if (add_number_row && !show_numpad)
+ added_number_row = modify_number_row(number_row, kw);
+ if (added_number_row != null)
+ remove_keys.addAll(added_number_row.getKeys(0).keySet());
+ if (kw.bottom_row)
+ kw = kw.insert_row(bottom_row, kw.rows.size());
kw = kw.mapKeys(new KeyboardData.MapKeyValues() {
public KeyValue apply(KeyValue key, boolean localized)
{
@@ -279,9 +295,9 @@ public final class Config
}
});
if (show_numpad)
- kw = kw.addNumPad(modify_numpad(KeyboardData.num_pad, kw));
- if (number_row != null)
- kw = kw.addTopRow(number_row);
+ kw = kw.addNumPad(modify_numpad(num_pad, kw));
+ if (added_number_row != null)
+ kw = kw.insert_row(added_number_row, 0);
if (extra_keys.size() > 0)
kw = kw.addExtraKeys(extra_keys.entrySet().iterator());
return kw;
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java
index e25cd34..0b834d7 100644
--- a/srcs/juloo.keyboard2/Keyboard2.java
+++ b/srcs/juloo.keyboard2/Keyboard2.java
@@ -105,7 +105,6 @@ public class Keyboard2 extends InputMethodService
public void onCreate()
{
super.onCreate();
- KeyboardData.init(getResources());
SharedPreferences prefs = DirectBootAwarePreferences.get_shared_preferences(this);
_keyeventhandler = new KeyEventHandler(getMainLooper(), this.new Receiver());
Config.initGlobalConfig(prefs, getResources(), _keyeventhandler);
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<KeyValue, KeyPos> _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<Row> rows_ = new ArrayList<Row>(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<Integer, KeyboardData> _layoutCache = new HashMap<Integer, KeyboardData>();
- 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 <keyboard>");
- 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<Row> rows)
@@ -270,7 +270,7 @@ public final class KeyboardData
}
protected KeyboardData(List<Row> 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<Row> 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