abouttreesummaryrefslogcommitdiff
diff options
context:
space:
mode:
-rw-r--r--srcs/juloo.keyboard2/KeyEventHandler.java42
-rw-r--r--srcs/juloo.keyboard2/Keyboard2.java129
2 files changed, 71 insertions, 100 deletions
diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java
index 70b54b9..36f6819 100644
--- a/srcs/juloo.keyboard2/KeyEventHandler.java
+++ b/srcs/juloo.keyboard2/KeyEventHandler.java
@@ -10,8 +10,6 @@ class KeyEventHandler implements Config.IKeyEventHandler
IReceiver _recv;
Autocapitalisation _autocap;
- public int actionId; // Action performed by the Action key.
-
public KeyEventHandler(Looper looper, IReceiver recv)
{
_recv = recv;
@@ -40,28 +38,7 @@ class KeyEventHandler implements Config.IKeyEventHandler
{
case Char: send_text(String.valueOf(key.getChar())); break;
case String: send_text(key.getString()); break;
- case Event:
- switch (key.getEvent())
- {
- case CONFIG: _recv.showKeyboardConfig(); break;
- case SWITCH_TEXT: _recv.set_layout(Layout.Current); break;
- 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.switchInputMethod(); break;
- case CHANGE_METHOD_PREV: _recv.switchToPrevInputMethod(); break;
- case ACTION:
- InputConnection conn = _recv.getCurrentInputConnection();
- if (conn != null)
- conn.performEditorAction(actionId);
- break;
- case SWITCH_SECOND: _recv.set_layout(Layout.Secondary); break;
- case SWITCH_SECOND_BACK: _recv.set_layout(Layout.Primary); break;
- case SWITCH_GREEKMATH: _recv.set_layout(Layout.Greekmath); break;
- case CAPS_LOCK: _recv.set_shift_state(true, true); break;
- case SWITCH_VOICE_TYPING: _recv.switch_voice_typing(); break;
- }
- break;
+ case Event: _recv.handle_event_key(key.getEvent()); break;
case Keyevent:
handleKeyUpWithModifier(key.getKeyevent(), mods);
break;
@@ -170,24 +147,9 @@ class KeyEventHandler implements Config.IKeyEventHandler
conn.performContextMenuAction(id);
}
- public enum Layout
- {
- Current, // The primary or secondary layout
- Primary,
- Secondary,
- Numeric,
- Greekmath
- }
-
public static interface IReceiver
{
- public void switchInputMethod();
- public void switchToPrevInputMethod();
- public void switch_voice_typing();
- public void setPane_emoji();
- public void setPane_normal();
- public void showKeyboardConfig();
- public void set_layout(Layout l);
+ public void handle_event_key(KeyValue.Event ev);
public void set_shift_state(boolean state, boolean lock);
public InputConnection getCurrentInputConnection();
}
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java
index 5394a6c..2742de7 100644
--- a/srcs/juloo.keyboard2/Keyboard2.java
+++ b/srcs/juloo.keyboard2/Keyboard2.java
@@ -36,6 +36,7 @@ public class Keyboard2 extends InputMethodService
// Layout associated with the currently selected locale.
private KeyboardData _localeTextLayout;
private ViewGroup _emojiPane = null;
+ public int actionId; // Action performed by the Action key.
private Config _config;
@@ -150,9 +151,14 @@ public class Keyboard2 extends InputMethodService
}
}
+ InputMethodManager get_imm()
+ {
+ return (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
+ }
+
private void refreshSubtypeImm()
{
- InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
+ InputMethodManager imm = get_imm();
if (VERSION.SDK_INT < 28)
_config.shouldOfferSwitchingToNextInputMethod = true;
else
@@ -213,14 +219,14 @@ public class Keyboard2 extends InputMethodService
if (info.actionLabel != null)
{
_config.actionLabel = info.actionLabel.toString();
- _keyeventhandler.actionId = info.actionId;
+ actionId = info.actionId;
_config.swapEnterActionKey = false;
}
else
{
int action = info.imeOptions & EditorInfo.IME_MASK_ACTION;
_config.actionLabel = actionLabel_of_imeAction(action); // Might be null
- _keyeventhandler.actionId = action;
+ actionId = action;
_config.swapEnterActionKey =
(info.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0;
}
@@ -398,82 +404,85 @@ public class Keyboard2 extends InputMethodService
/** Not static */
public class Receiver implements KeyEventHandler.IReceiver
{
- public void switchInputMethod()
- {
- InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
- imm.showInputMethodPicker();
- }
-
- public void switchToPrevInputMethod()
+ public void handle_event_key(KeyValue.Event ev)
{
- if (VERSION.SDK_INT < 28)
+ switch (ev)
{
- InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
- imm.switchToLastInputMethod(getConnectionToken());
- }
- else
- Keyboard2.this.switchToPreviousInputMethod();
- }
+ case CONFIG:
+ Intent intent = new Intent(Keyboard2.this, SettingsActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(intent);
+ break;
- public void switch_voice_typing()
- {
- InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
- SimpleEntry<String, InputMethodSubtype> im = get_voice_typing_im(imm);
- if (im == null)
- return;
- // Best-effort. Good enough for triggering Google's voice typing.
- if (VERSION.SDK_INT < 28)
- Keyboard2.this.switchInputMethod(im.getKey());
- else
- Keyboard2.this.switchInputMethod(im.getKey(), im.getValue());
- }
+ case SWITCH_TEXT:
+ _currentSpecialLayout = null;
+ _keyboardView.setKeyboard(current_layout());
+ break;
- public void setPane_emoji()
- {
- if (_emojiPane == null)
- _emojiPane = (ViewGroup)inflate_view(R.layout.emoji_pane);
- setInputView(_emojiPane);
- }
+ case SWITCH_NUMERIC:
+ setSpecialLayout(_config.modify_numpad(loadLayout(R.xml.numeric)));
+ break;
- public void setPane_normal()
- {
- setInputView(_keyboardView);
- }
+ case SWITCH_EMOJI:
+ if (_emojiPane == null)
+ _emojiPane = (ViewGroup)inflate_view(R.layout.emoji_pane);
+ setInputView(_emojiPane);
+ break;
- public void set_shift_state(boolean state, boolean lock)
- {
- _keyboardView.set_shift_state(state, lock);
- }
+ case SWITCH_BACK_EMOJI:
+ setInputView(_keyboardView);
+ break;
- public void set_layout(KeyEventHandler.Layout l)
- {
- switch (l)
- {
- case Current:
- _currentSpecialLayout = null;
- _keyboardView.setKeyboard(current_layout());
+ case CHANGE_METHOD:
+ get_imm().showInputMethodPicker();
break;
- case Primary:
- setTextLayout(Current_text_layout.PRIMARY);
+
+ case CHANGE_METHOD_PREV:
+ if (VERSION.SDK_INT < 28)
+ get_imm().switchToLastInputMethod(getConnectionToken());
+ else
+ switchToPreviousInputMethod();
+ break;
+
+ case ACTION:
+ InputConnection conn = getCurrentInputConnection();
+ if (conn != null)
+ conn.performEditorAction(actionId);
break;
- case Secondary:
+
+ case SWITCH_SECOND:
if (_config.second_layout != null)
setTextLayout(Current_text_layout.SECONDARY);
break;
- case Numeric:
- setSpecialLayout(_config.modify_numpad(loadLayout(R.xml.numeric)));
+
+ case SWITCH_SECOND_BACK:
+ setTextLayout(Current_text_layout.PRIMARY);
break;
- case Greekmath:
+
+ case SWITCH_GREEKMATH:
setSpecialLayout(_config.modify_numpad(loadLayout(R.xml.greekmath)));
break;
+
+ case CAPS_LOCK:
+ set_shift_state(true, true);
+ break;
+
+ case SWITCH_VOICE_TYPING:
+ SimpleEntry<String, InputMethodSubtype> im = get_voice_typing_im(get_imm());
+ if (im == null)
+ return;
+ // Best-effort. Good enough for triggering Google's voice typing.
+ if (VERSION.SDK_INT < 28)
+ switchInputMethod(im.getKey());
+ else
+ switchInputMethod(im.getKey(), im.getValue());
+ break;
}
}
- public void showKeyboardConfig()
+ public void set_shift_state(boolean state, boolean lock)
{
- Intent intent = new Intent(Keyboard2.this, SettingsActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(intent);
+ _keyboardView.set_shift_state(state, lock);
}
public InputConnection getCurrentInputConnection()