From 324756535e139aacfb9d828a5bc9a2a6fef634ea Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 24 Jul 2022 20:02:48 +0200 Subject: 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. --- srcs/juloo.keyboard2/Keyboard2.java | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'srcs/juloo.keyboard2/Keyboard2.java') 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 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); @@ -236,6 +247,14 @@ public class Keyboard2 extends InputMethodService _keyboardView.setKeyboard(getLayout(_currentTextLayout)); } + @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) { @@ -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); } } -- cgit v1.2.3