From 0f62b3044c501dc5679583e06447285ebeb31118 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 12 Feb 2023 23:20:11 +0100 Subject: Option to switch to the previous input method A new option changes the "change_method" into the new "change_method_prev". It switch to the previously used input method. A long press on "change_method_prev" sends "change_method". A new section is added in the settings and existing options are moved. --- srcs/juloo.keyboard2/Config.java | 8 +++++++- srcs/juloo.keyboard2/KeyEventHandler.java | 6 ++++-- srcs/juloo.keyboard2/KeyModifier.java | 10 ++++++++++ srcs/juloo.keyboard2/KeyValue.java | 2 ++ srcs/juloo.keyboard2/Keyboard2.java | 16 +++++++++++++--- 5 files changed, 36 insertions(+), 6 deletions(-) (limited to 'srcs') diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index eda2740..586db4e 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -48,6 +48,7 @@ final class Config public int accents; // Values are R.values.pref_accents_v_* public int theme; // Values are R.style.* public boolean autocapitalisation; + public boolean switch_input_immediate; // Dynamically set public boolean shouldOfferSwitchingToNextInputMethod; @@ -152,6 +153,7 @@ final class Config accents = Integer.valueOf(_prefs.getString("accents", "1")); theme = getThemeId(res, _prefs.getString("theme", "")); autocapitalisation = _prefs.getBoolean("autocapitalisation", true); + switch_input_immediate = _prefs.getBoolean("switch_input_immediate", false); extra_keys_param = ExtraKeyCheckBoxPreference.get_extra_keys(_prefs); } @@ -200,7 +202,11 @@ final class Config switch (key.getEvent()) { case CHANGE_METHOD: - return shouldOfferSwitchingToNextInputMethod ? key : null; + if (!shouldOfferSwitchingToNextInputMethod) + return null; + if (switch_input_immediate) + return KeyValue.getKeyByName("change_method_prev"); + return key; case ACTION: return (swapEnterActionKey && action_key != null) ? KeyValue.getKeyByName("enter") : action_key; diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index 5b0762e..1a591c8 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -48,7 +48,8 @@ class KeyEventHandler implements Config.IKeyEventHandler case SWITCH_NUMERIC: _recv.set_layout(Layout.Numeric); break; case SWITCH_EMOJI: _recv.setPane_emoji(); break; case SWITCH_BACK_EMOJI: _recv.setPane_normal(); break; - case CHANGE_METHOD: _recv.switchToNextInputMethod(); break; + case CHANGE_METHOD: _recv.switchInputMethod(); break; + case CHANGE_METHOD_PREV: _recv.switchToPrevInputMethod(); break; case ACTION: InputConnection conn = _recv.getCurrentInputConnection(); if (conn != null) @@ -179,7 +180,8 @@ class KeyEventHandler implements Config.IKeyEventHandler public static interface IReceiver { - public void switchToNextInputMethod(); + public void switchInputMethod(); + public void switchToPrevInputMethod(); public void setPane_emoji(); public void setPane_normal(); public void showKeyboardConfig(); diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java index 1529835..392b740 100644 --- a/srcs/juloo.keyboard2/KeyModifier.java +++ b/srcs/juloo.keyboard2/KeyModifier.java @@ -70,6 +70,16 @@ class KeyModifier /** Modify a key after a long press. */ public static KeyValue modify_long_press(KeyValue k) { + switch (k.getKind()) + { + case Event: + switch (k.getEvent()) + { + case CHANGE_METHOD_PREV: + return KeyValue.getKeyByName("change_method"); + } + break; + } return k; } diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index f45bc7c..c4bd069 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -13,6 +13,7 @@ final class KeyValue SWITCH_EMOJI, SWITCH_BACK_EMOJI, CHANGE_METHOD, + CHANGE_METHOD_PREV, ACTION, SWITCH_SECOND, SWITCH_SECOND_BACK, @@ -332,6 +333,7 @@ final class KeyValue case "switch_second_back": return eventKey(0x14, Event.SWITCH_SECOND_BACK, FLAG_SMALLER_FONT); case "switch_greekmath": return eventKey("πλ∇¬", Event.SWITCH_GREEKMATH, FLAG_SMALLER_FONT); case "change_method": return eventKey(0x09, Event.CHANGE_METHOD, FLAG_SMALLER_FONT); + case "change_method_prev": return eventKey(0x09, Event.CHANGE_METHOD_PREV, FLAG_SMALLER_FONT); case "action": return eventKey("Action", Event.ACTION, FLAG_SMALLER_FONT); // Will always be replaced case "capslock": return eventKey(0x12, Event.CAPS_LOCK, 0); diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 0065e0d..54caf3c 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -329,11 +329,21 @@ public class Keyboard2 extends InputMethodService /** Not static */ public class Receiver implements KeyEventHandler.IReceiver { - public void switchToNextInputMethod() { + public void switchInputMethod() + { InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); imm.showInputMethodPicker(); - // deprecated in version 28: imm.switchToNextInputMethod(getConnectionToken(), false); - // added in version 28: switchToNextInputMethod(false); + } + + public void switchToPrevInputMethod() + { + if (VERSION.SDK_INT < 28) + { + InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); + imm.switchToLastInputMethod(getConnectionToken()); + } + else + Keyboard2.this.switchToPreviousInputMethod(); } public void setPane_emoji() -- cgit v1.2.3