Add optional number row

An option is added to enable an extra number row at the top of the
keyboard. Digits are removed from the keyboard while the number row is
visible.
This commit is contained in:
Jules Aguillon 2023-01-30 23:58:47 +01:00
parent c7184303e9
commit 540384bb0a
17 changed files with 59 additions and 3 deletions

View File

@ -21,6 +21,8 @@
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<!-- <string name="pref_number_row_title">Show number row</string> -->
<!-- <string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string> -->
<!-- <string name="pref_numpad_layout">NumPad layout</string> -->
<!-- <string name="pref_numpad_layout_e_high_first">High digits first</string> -->
<!-- <string name="pref_numpad_layout_e_low_first">Low digits first</string> -->

View File

@ -21,6 +21,8 @@
<string name="pref_show_numpad_never">Nie</string>
<string name="pref_show_numpad_landscape">Nur im Querformat</string>
<string name="pref_show_numpad_always">Immer</string>
<!-- <string name="pref_number_row_title">Show number row</string> -->
<!-- <string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string> -->
<!-- <string name="pref_numpad_layout">NumPad layout</string> -->
<!-- <string name="pref_numpad_layout_e_high_first">High digits first</string> -->
<!-- <string name="pref_numpad_layout_e_low_first">Low digits first</string> -->

View File

@ -21,6 +21,8 @@
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<!-- <string name="pref_number_row_title">Show number row</string> -->
<!-- <string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string> -->
<!-- <string name="pref_numpad_layout">NumPad layout</string> -->
<!-- <string name="pref_numpad_layout_e_high_first">High digits first</string> -->
<!-- <string name="pref_numpad_layout_e_low_first">Low digits first</string> -->

View File

@ -21,6 +21,8 @@
<string name="pref_show_numpad_never">Jamais</string>
<string name="pref_show_numpad_landscape">Seulement en mode paysage</string>
<string name="pref_show_numpad_always">Toujour</string>
<!-- <string name="pref_number_row_title">Show number row</string> -->
<!-- <string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string> -->
<string name="pref_numpad_layout">Disposition du pavé numérique</string>
<string name="pref_numpad_layout_e_high_first">Du plus haut au plus bas</string>
<string name="pref_numpad_layout_e_low_first">Du plus bas au plus haut</string>

View File

@ -21,6 +21,8 @@
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<!-- <string name="pref_number_row_title">Show number row</string> -->
<!-- <string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string> -->
<!-- <string name="pref_numpad_layout">NumPad layout</string> -->
<!-- <string name="pref_numpad_layout_e_high_first">High digits first</string> -->
<!-- <string name="pref_numpad_layout_e_low_first">Low digits first</string> -->

View File

@ -21,6 +21,8 @@
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<!-- <string name="pref_number_row_title">Show number row</string> -->
<!-- <string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string> -->
<!-- <string name="pref_numpad_layout">NumPad layout</string> -->
<!-- <string name="pref_numpad_layout_e_high_first">High digits first</string> -->
<!-- <string name="pref_numpad_layout_e_low_first">Low digits first</string> -->

View File

@ -21,6 +21,8 @@
<string name="pref_show_numpad_never">Nekad</string>
<string name="pref_show_numpad_landscape">Tikai guleniskajā skatā</string>
<string name="pref_show_numpad_always">Vienmēr</string>
<!-- <string name="pref_number_row_title">Show number row</string> -->
<!-- <string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string> -->
<!-- <string name="pref_numpad_layout">NumPad layout</string> -->
<!-- <string name="pref_numpad_layout_e_high_first">High digits first</string> -->
<!-- <string name="pref_numpad_layout_e_low_first">Low digits first</string> -->

View File

@ -21,6 +21,8 @@
<string name="pref_show_numpad_never">Nigdy</string>
<string name="pref_show_numpad_landscape">Tylko w orientacji poziomej</string>
<string name="pref_show_numpad_always">Zawsze</string>
<!-- <string name="pref_number_row_title">Show number row</string> -->
<!-- <string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string> -->
<string name="pref_numpad_layout">Układ klawiatury numerycznej</string>
<string name="pref_numpad_layout_e_high_first">Od największej cyfry</string>
<string name="pref_numpad_layout_e_low_first">Od najmniejszej cyfry</string>

View File

@ -21,6 +21,8 @@
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<!-- <string name="pref_number_row_title">Show number row</string> -->
<!-- <string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string> -->
<!-- <string name="pref_numpad_layout">NumPad layout</string> -->
<!-- <string name="pref_numpad_layout_e_high_first">High digits first</string> -->
<!-- <string name="pref_numpad_layout_e_low_first">Low digits first</string> -->

View File

@ -21,6 +21,8 @@
<string name="pref_show_numpad_never">Никогда</string>
<string name="pref_show_numpad_landscape">Только в ландшафтном режиме</string>
<string name="pref_show_numpad_always">Всегда</string>
<!-- <string name="pref_number_row_title">Show number row</string> -->
<!-- <string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string> -->
<string name="pref_numpad_layout">NumPad раскладка</string>
<string name="pref_numpad_layout_e_high_first">Старшие цифры сверху</string>
<string name="pref_numpad_layout_e_low_first">Младшие цифры сверху</string>

View File

@ -21,6 +21,8 @@
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<!-- <string name="pref_number_row_title">Show number row</string> -->
<!-- <string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string> -->
<!-- <string name="pref_numpad_layout">NumPad layout</string> -->
<!-- <string name="pref_numpad_layout_e_high_first">High digits first</string> -->
<!-- <string name="pref_numpad_layout_e_low_first">Low digits first</string> -->

View File

@ -21,6 +21,8 @@
<string name="pref_show_numpad_never">从不</string>
<string name="pref_show_numpad_landscape">只在横屏显示</string>
<string name="pref_show_numpad_always">一直显示</string>
<!-- <string name="pref_number_row_title">Show number row</string> -->
<!-- <string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string> -->
<!-- <string name="pref_numpad_layout">NumPad layout</string> -->
<!-- <string name="pref_numpad_layout_e_high_first">High digits first</string> -->
<!-- <string name="pref_numpad_layout_e_low_first">Low digits first</string> -->

View File

@ -21,6 +21,8 @@
<string name="pref_show_numpad_never">Never</string>
<string name="pref_show_numpad_landscape">Only in landscape mode</string>
<string name="pref_show_numpad_always">Always</string>
<string name="pref_number_row_title">Show number row</string>
<string name="pref_number_row_summary">Add a number row at the top of the keyboard when the numpad is hidden</string>
<string name="pref_numpad_layout">NumPad layout</string>
<string name="pref_numpad_layout_e_high_first">High digits first</string>
<string name="pref_numpad_layout_e_low_first">Low digits first</string>

13
res/xml/number_row.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<row height="0.75">
<key key0="1"/>
<key key0="2"/>
<key key0="3"/>
<key key0="4"/>
<key key0="5"/>
<key key0="6"/>
<key key0="7"/>
<key key0="8"/>
<key key0="9"/>
<key key0="0"/>
</row>

View File

@ -5,6 +5,7 @@
<juloo.keyboard2.LayoutListPreference android:key="second_layout" android:title="@string/pref_second_layout_title" app:defaultString="@string/pref_second_layout_none"/>
<ListPreference android:key="accents" android:title="@string/pref_accents_title" android:summary="%s" android:defaultValue="1" android:entries="@array/pref_accents_entries" android:entryValues="@array/pref_accents_values"/>
<ListPreference android:key="show_numpad" android:title="@string/pref_show_numpad_title" android:summary="%s" android:defaultValue="1" android:entries="@array/pref_show_numpad_entries" android:entryValues="@array/pref_show_numpad_values"/>
<CheckBoxPreference android:key="number_row" android:title="@string/pref_number_row_title" android:summary="@string/pref_number_row_summary" android:defaultValue="false"/>
<PreferenceScreen android:title="@string/pref_extra_keys_title">
<juloo.keyboard2.ExtraKeyCheckBoxPreference app:index="0"/>
<juloo.keyboard2.ExtraKeyCheckBoxPreference app:index="1"/>

View File

@ -28,6 +28,7 @@ final class Config
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 float swipe_dist_px;
public float slide_step_px;
public boolean vibrateEnabled;
@ -111,6 +112,7 @@ final class Config
second_layout = tweak_secondary_layout(layout_of_string(res, _prefs.getString("second_layout", "none")));
custom_layout = KeyboardData.load_string(_prefs.getString("custom_layout", ""));
inverse_numpad = _prefs.getString("numpad_layout", "default").equals("low_first");
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.
@ -165,6 +167,7 @@ final class Config
* - Remove "localized" keys from other locales (not in 'extra_keys')
* - Replace the action key to show the right label
* - Swap the enter and action keys
* - Add the optional numpad and number row
*/
public KeyboardData modify_layout(KeyboardData kw)
{
@ -176,8 +179,11 @@ final class Config
if (extra_keys_subtype != null)
extra_keys.addAll(extra_keys_subtype);
extra_keys.addAll(extra_keys_param);
boolean number_row = this.number_row && !show_numpad;
if (show_numpad)
KeyboardData.num_pad.getKeys(remove_keys);
if (number_row)
KeyboardData.number_row.getKeys(remove_keys);
kw = kw.mapKeys(new KeyboardData.MapKeyValues() {
public KeyValue apply(KeyValue key, boolean localized)
{
@ -223,6 +229,8 @@ final class Config
});
if (show_numpad)
kw = kw.addNumPad();
if (number_row)
kw = kw.addNumberRow();
if (extra_keys.size() > 0)
kw = kw.addExtraKeys(extra_keys.iterator());
return kw;

View File

@ -72,6 +72,12 @@ class KeyboardData
return new KeyboardData(extendedRows, compute_max_width(extendedRows));
}
public KeyboardData addNumberRow()
{
rows.add(0, number_row.updateWidth(keysWidth));
return this;
}
public Key findKeyWithValue(KeyValue kv)
{
for (Row r : rows)
@ -104,6 +110,7 @@ class KeyboardData
}
public static Row bottom_row;
public static Row number_row;
public static KeyboardData num_pad;
public static KeyboardData pin_entry;
private static Map<Integer, KeyboardData> _layoutCache = new HashMap<Integer, KeyboardData>();
@ -112,7 +119,8 @@ class KeyboardData
{
try
{
bottom_row = parse_bottom_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)
@ -187,10 +195,10 @@ class KeyboardData
return w;
}
private static Row parse_bottom_row(XmlPullParser parser) throws Exception
private static Row parse_row(XmlPullParser parser) throws Exception
{
if (!expect_tag(parser, "row"))
throw new Exception("Failed to parse bottom row");
throw new Exception("Failed to parse row");
return Row.parse(parser);
}