mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-11-22 07:13:13 +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)
|
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)
|
if (number_row)
|
||||||
kw = kw.addNumberRow();
|
kw = kw.addNumberRow();
|
||||||
if (extra_keys.size() > 0)
|
if (extra_keys.size() > 0)
|
||||||
@ -276,13 +276,12 @@ final class Config
|
|||||||
return kw;
|
return kw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Handle the numpad layout. The [main_kw] is used to adapt the numpad to
|
||||||
* Handle the numpad layout.
|
the main layout's script. */
|
||||||
*/
|
public KeyboardData modify_numpad(KeyboardData kw, KeyboardData main_kw)
|
||||||
public KeyboardData modify_numpad(KeyboardData kw, String script)
|
|
||||||
{
|
{
|
||||||
final KeyValue action_key = action_key();
|
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() {
|
return kw.mapKeys(new KeyboardData.MapKeyValues() {
|
||||||
public KeyValue apply(KeyValue key, boolean localized)
|
public KeyValue apply(KeyValue key, boolean localized)
|
||||||
{
|
{
|
||||||
|
@ -83,11 +83,11 @@ class KeyModifier
|
|||||||
return k;
|
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;
|
return map_char_none;
|
||||||
switch (script)
|
switch (numpad_script)
|
||||||
{
|
{
|
||||||
case "arabic": return map_char_numpad_arabic;
|
case "arabic": return map_char_numpad_arabic;
|
||||||
case "bengali": return map_char_numpad_bengali;
|
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). */
|
/** Load a layout that contains a numpad (eg. the pin entry). */
|
||||||
KeyboardData loadNumpad(int layout_id)
|
KeyboardData loadNumpad(int layout_id)
|
||||||
{
|
{
|
||||||
String current_script = current_layout_unmodified().script;
|
|
||||||
return _config.modify_numpad(KeyboardData.load(getResources(), layout_id),
|
return _config.modify_numpad(KeyboardData.load(getResources(), layout_id),
|
||||||
current_script);
|
current_layout_unmodified());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,6 +25,8 @@ class KeyboardData
|
|||||||
public final Modmap modmap;
|
public final Modmap modmap;
|
||||||
/** Might be null. */
|
/** Might be null. */
|
||||||
public final String script;
|
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()]. */
|
/** Position of every keys on the layout, see [getKeys()]. */
|
||||||
private Map<KeyValue, KeyPos> _key_pos = null;
|
private Map<KeyValue, KeyPos> _key_pos = null;
|
||||||
|
|
||||||
@ -33,7 +35,7 @@ class KeyboardData
|
|||||||
ArrayList<Row> rows_ = new ArrayList<Row>();
|
ArrayList<Row> rows_ = new ArrayList<Row>();
|
||||||
for (Row r : rows)
|
for (Row r : rows)
|
||||||
rows_.add(r.mapKeys(f));
|
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
|
/** Add keys from the given iterator into the keyboard. Preferred position is
|
||||||
@ -51,7 +53,7 @@ class KeyboardData
|
|||||||
}
|
}
|
||||||
for (KeyValue kv : unplaced_keys)
|
for (KeyValue kv : unplaced_keys)
|
||||||
add_key_to_preferred_pos(rows, kv, PreferredPos.ANYWHERE);
|
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
|
/** 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));
|
extendedRows.add(new Row(keys, row.height, row.shift));
|
||||||
}
|
}
|
||||||
return new
|
return new KeyboardData(this, extendedRows);
|
||||||
KeyboardData(extendedRows, compute_max_width(extendedRows), modmap, script);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyboardData addNumberRow()
|
public KeyboardData addNumberRow()
|
||||||
{
|
{
|
||||||
ArrayList<Row> rows_ = new ArrayList<Row>(this.rows);
|
ArrayList<Row> rows_ = new ArrayList<Row>(this.rows);
|
||||||
rows_.add(0, number_row.updateWidth(keysWidth));
|
rows_.add(0, number_row.updateWidth(keysWidth));
|
||||||
return new KeyboardData(rows_, keysWidth, modmap, script);
|
return new KeyboardData(this, rows_);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Key findKeyWithValue(KeyValue kv)
|
public Key findKeyWithValue(KeyValue kv)
|
||||||
@ -225,6 +226,9 @@ class KeyboardData
|
|||||||
boolean add_bottom_row = attribute_bool(parser, "bottom_row", true);
|
boolean add_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");
|
||||||
|
if (numpad_script == null)
|
||||||
|
numpad_script = script;
|
||||||
ArrayList<Row> rows = new ArrayList<Row>();
|
ArrayList<Row> rows = new ArrayList<Row>();
|
||||||
Modmap modmap = null;
|
Modmap modmap = null;
|
||||||
while (next_tag(parser))
|
while (next_tag(parser))
|
||||||
@ -244,7 +248,7 @@ 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)
|
if (add_bottom_row)
|
||||||
rows.add(bottom_row.updateWidth(kw));
|
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)
|
private static float compute_max_width(List<Row> rows)
|
||||||
@ -262,7 +266,7 @@ class KeyboardData
|
|||||||
return Row.parse(parser);
|
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;
|
float kh = 0.f;
|
||||||
for (Row r : rows_)
|
for (Row r : rows_)
|
||||||
@ -270,10 +274,17 @@ class KeyboardData
|
|||||||
rows = rows_;
|
rows = rows_;
|
||||||
modmap = mm;
|
modmap = mm;
|
||||||
script = sc;
|
script = sc;
|
||||||
|
numpad_script = npsc;
|
||||||
keysWidth = kw;
|
keysWidth = kw;
|
||||||
keysHeight = kh;
|
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 static class Row
|
||||||
{
|
{
|
||||||
public final List<Key> keys;
|
public final List<Key> keys;
|
||||||
|
Loading…
Reference in New Issue
Block a user