mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-11-25 08:43:24 +01:00
Add layout attribute 'numpad_script'
This new attribute is now used instead of 'script' for modifying the numpad according to the selected layout's script. If not provided, it defaults to the value of 'script'.
This commit is contained in:
parent
1af4e45117
commit
9ff8179d49
@ -268,7 +268,7 @@ final class Config
|
||||
}
|
||||
});
|
||||
if (show_numpad)
|
||||
kw = kw.addNumPad(modify_numpad(KeyboardData.num_pad, kw.script));
|
||||
kw = kw.addNumPad(modify_numpad(KeyboardData.num_pad, kw));
|
||||
if (number_row)
|
||||
kw = kw.addNumberRow();
|
||||
if (extra_keys.size() > 0)
|
||||
@ -276,13 +276,12 @@ final class Config
|
||||
return kw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the numpad layout.
|
||||
*/
|
||||
public KeyboardData modify_numpad(KeyboardData kw, String script)
|
||||
/** Handle the numpad layout. The [main_kw] is used to adapt the numpad to
|
||||
the main layout's script. */
|
||||
public KeyboardData modify_numpad(KeyboardData kw, KeyboardData main_kw)
|
||||
{
|
||||
final KeyValue action_key = action_key();
|
||||
final KeyModifier.Map_char map_digit = KeyModifier.modify_numpad_script(script);
|
||||
final KeyModifier.Map_char map_digit = KeyModifier.modify_numpad_script(main_kw.numpad_script);
|
||||
return kw.mapKeys(new KeyboardData.MapKeyValues() {
|
||||
public KeyValue apply(KeyValue key, boolean localized)
|
||||
{
|
||||
|
@ -83,11 +83,11 @@ class KeyModifier
|
||||
return k;
|
||||
}
|
||||
|
||||
public static Map_char modify_numpad_script(String script)
|
||||
public static Map_char modify_numpad_script(String numpad_script)
|
||||
{
|
||||
if (script == null)
|
||||
if (numpad_script == null)
|
||||
return map_char_none;
|
||||
switch (script)
|
||||
switch (numpad_script)
|
||||
{
|
||||
case "arabic": return map_char_numpad_arabic;
|
||||
case "bengali": return map_char_numpad_bengali;
|
||||
|
@ -89,9 +89,8 @@ public class Keyboard2 extends InputMethodService
|
||||
/** Load a layout that contains a numpad (eg. the pin entry). */
|
||||
KeyboardData loadNumpad(int layout_id)
|
||||
{
|
||||
String current_script = current_layout_unmodified().script;
|
||||
return _config.modify_numpad(KeyboardData.load(getResources(), layout_id),
|
||||
current_script);
|
||||
current_layout_unmodified());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,6 +25,8 @@ class KeyboardData
|
||||
public final Modmap modmap;
|
||||
/** Might be null. */
|
||||
public final String script;
|
||||
/** Might be different from [script]. Might be null. */
|
||||
public final String numpad_script;
|
||||
/** Position of every keys on the layout, see [getKeys()]. */
|
||||
private Map<KeyValue, KeyPos> _key_pos = null;
|
||||
|
||||
@ -33,7 +35,7 @@ class KeyboardData
|
||||
ArrayList<Row> rows_ = new ArrayList<Row>();
|
||||
for (Row r : rows)
|
||||
rows_.add(r.mapKeys(f));
|
||||
return new KeyboardData(rows_, keysWidth, modmap, script);
|
||||
return new KeyboardData(this, rows_);
|
||||
}
|
||||
|
||||
/** Add keys from the given iterator into the keyboard. Preferred position is
|
||||
@ -51,7 +53,7 @@ class KeyboardData
|
||||
}
|
||||
for (KeyValue kv : unplaced_keys)
|
||||
add_key_to_preferred_pos(rows, kv, PreferredPos.ANYWHERE);
|
||||
return new KeyboardData(rows, keysWidth, modmap, script);
|
||||
return new KeyboardData(this, rows);
|
||||
}
|
||||
|
||||
/** Place a key on the keyboard according to its preferred position. Mutates
|
||||
@ -125,15 +127,14 @@ class KeyboardData
|
||||
}
|
||||
extendedRows.add(new Row(keys, row.height, row.shift));
|
||||
}
|
||||
return new
|
||||
KeyboardData(extendedRows, compute_max_width(extendedRows), modmap, script);
|
||||
return new KeyboardData(this, extendedRows);
|
||||
}
|
||||
|
||||
public KeyboardData addNumberRow()
|
||||
{
|
||||
ArrayList<Row> rows_ = new ArrayList<Row>(this.rows);
|
||||
rows_.add(0, number_row.updateWidth(keysWidth));
|
||||
return new KeyboardData(rows_, keysWidth, modmap, script);
|
||||
return new KeyboardData(this, rows_);
|
||||
}
|
||||
|
||||
public Key findKeyWithValue(KeyValue kv)
|
||||
@ -225,6 +226,9 @@ class KeyboardData
|
||||
boolean add_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");
|
||||
if (numpad_script == null)
|
||||
numpad_script = script;
|
||||
ArrayList<Row> rows = new ArrayList<Row>();
|
||||
Modmap modmap = null;
|
||||
while (next_tag(parser))
|
||||
@ -244,7 +248,7 @@ 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);
|
||||
return new KeyboardData(rows, kw, modmap, script, numpad_script);
|
||||
}
|
||||
|
||||
private static float compute_max_width(List<Row> rows)
|
||||
@ -262,7 +266,7 @@ class KeyboardData
|
||||
return Row.parse(parser);
|
||||
}
|
||||
|
||||
protected KeyboardData(List<Row> rows_, float kw, Modmap mm, String sc)
|
||||
protected KeyboardData(List<Row> rows_, float kw, Modmap mm, String sc, String npsc)
|
||||
{
|
||||
float kh = 0.f;
|
||||
for (Row r : rows_)
|
||||
@ -270,10 +274,17 @@ class KeyboardData
|
||||
rows = rows_;
|
||||
modmap = mm;
|
||||
script = sc;
|
||||
numpad_script = npsc;
|
||||
keysWidth = kw;
|
||||
keysHeight = kh;
|
||||
}
|
||||
|
||||
/** 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);
|
||||
}
|
||||
|
||||
public static class Row
|
||||
{
|
||||
public final List<Key> keys;
|
||||
|
Loading…
Reference in New Issue
Block a user