diff options
| author | Jules Aguillon | 2022-09-24 22:36:06 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2022-09-24 22:36:06 +0200 |
| commit | 3081af5190b370409d858dc33f6dae00f84f2fd6 (patch) | |
| tree | 7af4c3ab642ba88cffff1f9f26b7d1bdbb098be0 /srcs/juloo.keyboard2/Keyboard2View.java | |
| parent | c778b4e8a24896a779cb295fb59a22d9253a2bc5 (diff) | |
| download | unexpected-keyboard-3081af5190b370409d858dc33f6dae00f84f2fd6.tar.gz unexpected-keyboard-3081af5190b370409d858dc33f6dae00f84f2fd6.zip | |
Improve the auto capitalisation
- Detect when the input box is cleared
- Avoid looking up keys on the keyboard every time the shift state needs
to change.
Diffstat (limited to 'srcs/juloo.keyboard2/Keyboard2View.java')
| -rw-r--r-- | srcs/juloo.keyboard2/Keyboard2View.java | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 422548a..e613925 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -19,6 +19,8 @@ public class Keyboard2View extends View implements View.OnTouchListener, Pointers.IPointerEventHandler { private KeyboardData _keyboard; + private KeyValue _shift_kv; + private KeyboardData.Key _shift_key; private Pointers _pointers; @@ -79,6 +81,13 @@ public class Keyboard2View extends View public void setKeyboard(KeyboardData kw) { _keyboard = _config.modify_layout(kw); + _shift_kv = KeyValue.getKeyByName("shift"); + _shift_key = _keyboard.findKeyWithValue(_shift_kv); + if (_shift_key == null) + { + _shift_kv = _shift_kv.withFlags(_shift_kv.getFlags() | KeyValue.FLAG_LOCK); + _shift_key = _keyboard.findKeyWithValue(_shift_kv); + } reset(); } @@ -93,24 +102,13 @@ public class Keyboard2View extends View /** Called by auto-capitalisation. */ public void set_shift_state(boolean state) { - if (_keyboard == null) + if (_keyboard == null || _shift_key == null) return; - KeyValue shift = KeyValue.getKeyByName("shift"); - KeyboardData.Key key = _keyboard.findKeyWithValue(shift); - if (key == null) - { - // Lookup again for the lockable shift key, which is a different value. - shift = shift.withFlags(shift.getFlags() | KeyValue.FLAG_LOCK); - key = _keyboard.findKeyWithValue(shift); - } - if (key != null) - { - if (state) - _pointers.add_fake_pointer(shift, key); - else - _pointers.remove_fake_pointer(shift, key); - invalidate(); - } + if (state) + _pointers.add_fake_pointer(_shift_kv, _shift_key); + else + _pointers.remove_fake_pointer(_shift_kv, _shift_key); + invalidate(); } public KeyValue modifyKey(KeyValue k, Pointers.Modifiers mods) |
