diff options
| author | Jules Aguillon | 2022-07-24 20:02:48 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2022-07-24 20:02:48 +0200 |
| commit | 324756535e139aacfb9d828a5bc9a2a6fef634ea (patch) | |
| tree | 717553aab3e9bd5a0536aa8b2e2a3a69d5e335ca /srcs/juloo.keyboard2/Keyboard2.java | |
| parent | 2d8ed2d85849c95c7d39e0dfe11405bf70eeb395 (diff) | |
| download | unexpected-keyboard-324756535e139aacfb9d828a5bc9a2a6fef634ea.tar.gz unexpected-keyboard-324756535e139aacfb9d828a5bc9a2a6fef634ea.zip | |
Automatic capitalisation at beginning of sentences
Keep track of end-of-sentence characters while typing and automatically
enable shift when appropriate.
The last few characters just before the cursor need to be queried in
some cases: Begin of input, cursor has moved or text is deleted.
This might have a performance cost.
This normally only enable shift but it also needs to disable shift when
the cursor moves.
Diffstat (limited to 'srcs/juloo.keyboard2/Keyboard2.java')
| -rw-r--r-- | srcs/juloo.keyboard2/Keyboard2.java | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 8483a50..cec2b44 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -35,6 +35,7 @@ public class Keyboard2 extends InputMethodService private ViewGroup _emojiPane = null; private Config _config; + private Autocapitalisation _autocap = new Autocapitalisation(); private boolean _debug_logs = false; @@ -57,6 +58,14 @@ public class Keyboard2 extends InputMethodService _debug_logs = getResources().getBoolean(R.bool.debug_logs); } + private void update_shift_state(boolean might_disable) + { + if (_autocap.should_enable_shift()) + _keyboardView.set_shift_state(true); + else if (might_disable) + _keyboardView.set_shift_state(false); + } + private List<InputMethodSubtype> getEnabledSubtypes(InputMethodManager imm) { String pkg = getPackageName(); @@ -163,7 +172,7 @@ public class Keyboard2 extends InputMethodService return getResources().getString(res); } - private void refreshEditorInfo(EditorInfo info) + private void refresh_action_label(EditorInfo info) { // First try to look at 'info.actionLabel', if it isn't set, look at // 'imeOptions'. @@ -210,11 +219,13 @@ public class Keyboard2 extends InputMethodService public void onStartInputView(EditorInfo info, boolean restarting) { refreshConfig(); - refreshEditorInfo(info); + refresh_action_label(info); if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0) _keyboardView.setKeyboard(getLayout(R.xml.numeric)); else _keyboardView.setKeyboard(getLayout(_currentTextLayout)); + _autocap.started(info, getCurrentInputConnection()); + update_shift_state(false); setInputView(_keyboardView); if (_debug_logs) log_editor_info(info); @@ -237,6 +248,14 @@ public class Keyboard2 extends InputMethodService } @Override + public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd, int candidatesStart, int candidatesEnd) + { + super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd); + _autocap.selection_updated(oldSelStart, newSelStart, getCurrentInputConnection()); + update_shift_state(true); + } + + @Override public void onFinishInputView(boolean finishingInput) { super.onFinishInputView(finishingInput); @@ -330,11 +349,15 @@ public class Keyboard2 extends InputMethodService public void commitText(String text) { getCurrentInputConnection().commitText(text, 1); + _autocap.typed(text); + update_shift_state(false); } public void commitChar(char c) { sendKeyChar(c); + _autocap.typed(c); + update_shift_state(false); } } |
