Add the pin entry layout

The layout is used for phone number and datetime input boxes as well as
some numbers.
It is easier to use when the full numeric layout is not needed.
This commit is contained in:
Jules Aguillon 2022-10-24 00:17:55 +02:00
parent e1145d3851
commit e01a2733b1
3 changed files with 46 additions and 5 deletions

27
res/xml/pin.xml Normal file
View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<keyboard width="6.0" bottom_row="false" extra_keys="false" num_pad="false">
<row>
<key shift="1.0" key0="1"/>
<key key0="2"/>
<key key0="3"/>
<key key0="backspace" key2="delete"/>
</row>
<row>
<key shift="1.0" key0="4"/>
<key key0="5"/>
<key key0="6"/>
<key key0="(" key3=":"/>
</row>
<row>
<key shift="1.0" key0="7"/>
<key key0="8"/>
<key key0="9"/>
<key key0=")" key3="/"/>
</row>
<row>
<key shift="1.0" key0="*" key1="switch_text" key3="switch_numeric"/>
<key key0="0" key3="+" key4="space"/>
<key key0="\#" key1="up" key2="right" key3="left" key4="down" edgekeys="true"/>
<key key0="enter" key2="action"/>
</row>
</keyboard>

View File

@ -225,15 +225,28 @@ public class Keyboard2 extends InputMethodService
Log.d(TAG, "actionLabel: "+_config.actionLabel);
}
private int chooseLayout(EditorInfo info)
{
switch (info.inputType & InputType.TYPE_MASK_CLASS)
{
case InputType.TYPE_CLASS_NUMBER:
if ((info.inputType & (InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED)) != 0)
return R.xml.numeric;
return R.xml.pin;
case InputType.TYPE_CLASS_PHONE:
case InputType.TYPE_CLASS_DATETIME:
return R.xml.pin;
default:
return _currentTextLayout;
}
}
@Override
public void onStartInputView(EditorInfo info, boolean restarting)
{
refreshConfig();
refresh_action_label(info);
if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0)
_keyboardView.setKeyboard(getLayout(R.xml.numeric));
else
_keyboardView.setKeyboard(getLayout(_currentTextLayout));
_keyboardView.setKeyboard(getLayout(chooseLayout(info)));
_autocap.started(info, getCurrentInputConnection());
setInputView(_keyboardView);
if (_debug_logs)

View File

@ -136,10 +136,11 @@ class KeyboardData
boolean bottom_row = parser.getAttributeBooleanValue(null, "bottom_row", true);
boolean extra_keys = parser.getAttributeBooleanValue(null, "extra_keys", true);
boolean num_pad = parser.getAttributeBooleanValue(null, "num_pad", true);
float specified_kw = parser.getAttributeFloatValue(null, "width", 0f);
ArrayList<Row> rows = new ArrayList<Row>();
while (expect_tag(parser, "row"))
rows.add(Row.parse(parser));
float kw = compute_max_width(rows);
float kw = (specified_kw != 0f) ? specified_kw : compute_max_width(rows);
if (bottom_row)
rows.add(_bottomRow.updateWidth(kw));
return new KeyboardData(rows, kw, extra_keys, num_pad);