From e01a2733b14e6c19cad3b5048a0b43f0563d7d51 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 24 Oct 2022 00:17:55 +0200 Subject: [PATCH] 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. --- res/xml/pin.xml | 27 ++++++++++++++++++++++++++ srcs/juloo.keyboard2/Keyboard2.java | 21 ++++++++++++++++---- srcs/juloo.keyboard2/KeyboardData.java | 3 ++- 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 res/xml/pin.xml diff --git a/res/xml/pin.xml b/res/xml/pin.xml new file mode 100644 index 0000000..0f0b3c6 --- /dev/null +++ b/res/xml/pin.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 35d5b26..972f266 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -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) diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index 21acde7..0d0a85b 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -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 rows = new ArrayList(); 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);