abouttreesummaryrefslogcommitdiff
path: root/srcs
diff options
context:
space:
mode:
authorJules Aguillon2022-01-10 00:27:22 +0100
committerJules Aguillon2022-01-10 00:27:22 +0100
commitdfec26a93be8cc3bf605273a49a46223e2551cde (patch)
treefd942a142fb5c84835079875092bc7cb95620bf8 /srcs
parent53113cadd9654c827ae306905dae4d738dedf818 (diff)
downloadunexpected-keyboard-dfec26a93be8cc3bf605273a49a46223e2551cde.tar.gz
unexpected-keyboard-dfec26a93be8cc3bf605273a49a46223e2551cde.zip
Swap the Enter and Action keys when needed
When IME_FLAG_NO_ENTER_ACTION is set.
Diffstat (limited to 'srcs')
-rw-r--r--srcs/juloo.keyboard2/Config.java2
-rw-r--r--srcs/juloo.keyboard2/Keyboard2.java3
-rw-r--r--srcs/juloo.keyboard2/Keyboard2View.java13
-rw-r--r--srcs/juloo.keyboard2/KeyboardData.java26
4 files changed, 42 insertions, 2 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java
index f7a104b..63befa5 100644
--- a/srcs/juloo.keyboard2/Config.java
+++ b/srcs/juloo.keyboard2/Config.java
@@ -36,6 +36,7 @@ final class Config
public int key_flags_to_remove;
public String actionLabel; // Might be 'null'
public int actionId; // Meaningful only when 'actionLabel' isn't 'null'
+ public boolean swapEnterActionKey; // Swap the "enter" and "action" keys
public final IKeyEventHandler handler;
@@ -66,6 +67,7 @@ final class Config
key_flags_to_remove = 0;
actionLabel = null;
actionId = 0;
+ swapEnterActionKey = false;
handler = h;
}
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java
index f54b3fa..20e93de 100644
--- a/srcs/juloo.keyboard2/Keyboard2.java
+++ b/srcs/juloo.keyboard2/Keyboard2.java
@@ -162,12 +162,15 @@ public class Keyboard2 extends InputMethodService
{
_config.actionLabel = info.actionLabel.toString();
_config.actionId = info.actionId;
+ _config.swapEnterActionKey = false;
}
else
{
int action = info.imeOptions & EditorInfo.IME_MASK_ACTION;
_config.actionLabel = actionLabel_of_imeAction(action); // Might be null
_config.actionId = action;
+ _config.swapEnterActionKey =
+ (info.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0;
}
}
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java
index 984920e..5e687d7 100644
--- a/srcs/juloo.keyboard2/Keyboard2View.java
+++ b/srcs/juloo.keyboard2/Keyboard2View.java
@@ -9,6 +9,7 @@ import android.os.Message;
import android.os.Vibrator;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
+import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.PopupWindow;
@@ -68,10 +69,18 @@ public class Keyboard2View extends View
// Replace the action key to show the right label.
KeyValue action_key = null;
if (_config.actionLabel != null)
+ {
action_key = new KeyValue(_config.actionLabel, _config.actionLabel,
KeyValue.CHAR_NONE, KeyValue.EVENT_ACTION, KeyValue.FLAG_NOREPEAT);
- kw = kw.replaceKeys(
- new KeyboardData.ReplaceKeysByEvent(KeyValue.EVENT_ACTION, action_key));
+ }
+ if (_config.swapEnterActionKey && action_key != null)
+ kw = kw.replaceKeys(
+ new KeyboardData.ReplaceKeysByEvent2(KeyEvent.KEYCODE_ENTER,
+ action_key, KeyValue.EVENT_ACTION,
+ KeyValue.getKeyByName("enter")));
+ else
+ kw = kw.replaceKeys(
+ new KeyboardData.ReplaceKeysByEvent(KeyValue.EVENT_ACTION, action_key));
_keyboard = kw;
reset();
}
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java
index 67b5db4..61a4ebf 100644
--- a/srcs/juloo.keyboard2/KeyboardData.java
+++ b/srcs/juloo.keyboard2/KeyboardData.java
@@ -201,4 +201,30 @@ class KeyboardData
return (k != null && k.eventCode == _eventCode) ? _replacement : k;
}
}
+
+ /* Replace two keys at the same time. Used for swaping keys. */
+ public static class ReplaceKeysByEvent2 implements MapKeys
+ {
+ private final int _e1;
+ private final KeyValue _r1;
+ private final int _e2;
+ private final KeyValue _r2;
+
+ public ReplaceKeysByEvent2(int e1, KeyValue r1, int e2, KeyValue r2)
+ {
+ _e1 = e1;
+ _r1 = r1;
+ _e2 = e2;
+ _r2 = r2;
+ }
+
+ public KeyValue map(KeyValue k)
+ {
+ if (k == null)
+ return null;
+ if (k.eventCode == _e1) return _r1;
+ if (k.eventCode == _e2) return _r2;
+ return k;
+ }
+ }
}