forked from extern/Unexpected-Keyboard
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.
This commit is contained in:
parent
9d89297c15
commit
304375268d
@ -28,13 +28,17 @@ public final class Config
|
|||||||
public final float labelTextSize;
|
public final float labelTextSize;
|
||||||
public final float sublabelTextSize;
|
public final float sublabelTextSize;
|
||||||
|
|
||||||
|
public final KeyboardData.Row bottom_row;
|
||||||
|
public final KeyboardData.Row number_row;
|
||||||
|
public final KeyboardData num_pad;
|
||||||
|
|
||||||
// From preferences
|
// From preferences
|
||||||
/** [null] represent the [system] layout. */
|
/** [null] represent the [system] layout. */
|
||||||
public List<KeyboardData> layouts;
|
public List<KeyboardData> layouts;
|
||||||
public boolean show_numpad = false;
|
public boolean show_numpad = false;
|
||||||
// From the 'numpad_layout' option, also apply to the numeric pane.
|
// From the 'numpad_layout' option, also apply to the numeric pane.
|
||||||
public boolean inverse_numpad = false;
|
public boolean inverse_numpad = false;
|
||||||
public boolean number_row;
|
public boolean add_number_row;
|
||||||
public float swipe_dist_px;
|
public float swipe_dist_px;
|
||||||
public float slide_step_px;
|
public float slide_step_px;
|
||||||
// Let the system handle vibration when false.
|
// Let the system handle vibration when false.
|
||||||
@ -86,6 +90,16 @@ public final class Config
|
|||||||
keyPadding = res.getDimension(R.dimen.key_padding);
|
keyPadding = res.getDimension(R.dimen.key_padding);
|
||||||
labelTextSize = 0.33f;
|
labelTextSize = 0.33f;
|
||||||
sublabelTextSize = 0.22f;
|
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
|
// from prefs
|
||||||
refresh(res);
|
refresh(res);
|
||||||
// initialized later
|
// initialized later
|
||||||
@ -123,7 +137,7 @@ public final class Config
|
|||||||
}
|
}
|
||||||
layouts = LayoutsPreference.load_from_preferences(res, _prefs);
|
layouts = LayoutsPreference.load_from_preferences(res, _prefs);
|
||||||
inverse_numpad = _prefs.getString("numpad_layout", "default").equals("low_first");
|
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
|
// The baseline for the swipe distance correspond to approximately the
|
||||||
// width of a key in portrait mode, as most layouts have 10 columns.
|
// 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.
|
// 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,
|
extra_keys_subtype.compute(extra_keys,
|
||||||
new ExtraKeys.Query(kw.script, present));
|
new ExtraKeys.Query(kw.script, present));
|
||||||
}
|
}
|
||||||
KeyboardData.Row number_row = null;
|
KeyboardData.Row added_number_row = null;
|
||||||
if (this.number_row && !show_numpad)
|
if (add_number_row && !show_numpad)
|
||||||
number_row = modify_number_row(KeyboardData.number_row, kw);
|
added_number_row = modify_number_row(number_row, kw);
|
||||||
if (number_row != null)
|
if (added_number_row != null)
|
||||||
remove_keys.addAll(number_row.getKeys(0).keySet());
|
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() {
|
kw = kw.mapKeys(new KeyboardData.MapKeyValues() {
|
||||||
public KeyValue apply(KeyValue key, boolean localized)
|
public KeyValue apply(KeyValue key, boolean localized)
|
||||||
{
|
{
|
||||||
@ -279,9 +295,9 @@ public final class Config
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (show_numpad)
|
if (show_numpad)
|
||||||
kw = kw.addNumPad(modify_numpad(KeyboardData.num_pad, kw));
|
kw = kw.addNumPad(modify_numpad(num_pad, kw));
|
||||||
if (number_row != null)
|
if (added_number_row != null)
|
||||||
kw = kw.addTopRow(number_row);
|
kw = kw.insert_row(added_number_row, 0);
|
||||||
if (extra_keys.size() > 0)
|
if (extra_keys.size() > 0)
|
||||||
kw = kw.addExtraKeys(extra_keys.entrySet().iterator());
|
kw = kw.addExtraKeys(extra_keys.entrySet().iterator());
|
||||||
return kw;
|
return kw;
|
||||||
|
@ -105,7 +105,6 @@ public class Keyboard2 extends InputMethodService
|
|||||||
public void onCreate()
|
public void onCreate()
|
||||||
{
|
{
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
KeyboardData.init(getResources());
|
|
||||||
SharedPreferences prefs = DirectBootAwarePreferences.get_shared_preferences(this);
|
SharedPreferences prefs = DirectBootAwarePreferences.get_shared_preferences(this);
|
||||||
_keyeventhandler = new KeyEventHandler(getMainLooper(), this.new Receiver());
|
_keyeventhandler = new KeyEventHandler(getMainLooper(), this.new Receiver());
|
||||||
Config.initGlobalConfig(prefs, getResources(), _keyeventhandler);
|
Config.initGlobalConfig(prefs, getResources(), _keyeventhandler);
|
||||||
|
@ -29,6 +29,8 @@ public final class KeyboardData
|
|||||||
public final String numpad_script;
|
public final String numpad_script;
|
||||||
/** The [name] attribute. Might be null. */
|
/** The [name] attribute. Might be null. */
|
||||||
public final String name;
|
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()]. */
|
/** Position of every keys on the layout, see [getKeys()]. */
|
||||||
private Map<KeyValue, KeyPos> _key_pos = null;
|
private Map<KeyValue, KeyPos> _key_pos = null;
|
||||||
|
|
||||||
@ -132,10 +134,12 @@ public final class KeyboardData
|
|||||||
return new KeyboardData(this, extendedRows);
|
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);
|
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_);
|
return new KeyboardData(this, rows_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,23 +163,21 @@ public final class KeyboardData
|
|||||||
return _key_pos;
|
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>();
|
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
|
return parse_row(res.getXml(R.xml.bottom_row));
|
||||||
{
|
|
||||||
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)
|
|
||||||
|
public static Row load_number_row(Resources res) throws Exception
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
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. */
|
/** Load a layout from a resource ID. Returns [null] on error. */
|
||||||
@ -225,7 +227,7 @@ public final class KeyboardData
|
|||||||
{
|
{
|
||||||
if (!expect_tag(parser, "keyboard"))
|
if (!expect_tag(parser, "keyboard"))
|
||||||
throw error(parser, "Expected tag <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);
|
float specified_kw = attribute_float(parser, "width", 0f);
|
||||||
String script = parser.getAttributeValue(null, "script");
|
String script = parser.getAttributeValue(null, "script");
|
||||||
String numpad_script = parser.getAttributeValue(null, "numpad_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);
|
float kw = (specified_kw != 0f) ? specified_kw : compute_max_width(rows);
|
||||||
if (add_bottom_row)
|
return new KeyboardData(rows, kw, modmap, script, numpad_script, name, bottom_row);
|
||||||
rows.add(bottom_row.updateWidth(kw));
|
|
||||||
return new KeyboardData(rows, kw, modmap, script, numpad_script, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float compute_max_width(List<Row> rows)
|
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,
|
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;
|
float kh = 0.f;
|
||||||
for (Row r : rows_)
|
for (Row r : rows_)
|
||||||
@ -282,13 +282,14 @@ public final class KeyboardData
|
|||||||
name = name_;
|
name = name_;
|
||||||
keysWidth = kw;
|
keysWidth = kw;
|
||||||
keysHeight = kh;
|
keysHeight = kh;
|
||||||
|
bottom_row = bottom_row_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Copies the fields of an other keyboard, with rows changed. */
|
/** Copies the fields of an other keyboard, with rows changed. */
|
||||||
protected KeyboardData(KeyboardData src, List<Row> rows)
|
protected KeyboardData(KeyboardData src, List<Row> rows)
|
||||||
{
|
{
|
||||||
this(rows, compute_max_width(rows), src.modmap, src.script,
|
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
|
public static class Row
|
||||||
|
Loading…
Reference in New Issue
Block a user