abouttreesummaryrefslogcommitdiff
path: root/srcs
diff options
context:
space:
mode:
authorJules Aguillon2021-04-18 00:55:31 +0200
committerJules Aguillon2021-04-18 00:55:31 +0200
commitf8bce500ff3f870e6eadae591541a1210e458cff (patch)
tree168adda0641f5f90a29c295cc3f8317db96bacb7 /srcs
parent1421bccc7b6588484fcf02517d35c98bbd05f6c4 (diff)
downloadunexpected-keyboard-f8bce500ff3f870e6eadae591541a1210e458cff.tar.gz
unexpected-keyboard-f8bce500ff3f870e6eadae591541a1210e458cff.zip
Hide the input switching key if it's not needed
Android has a new way of switching between input methods and this key need to be hidden in most cases.
Diffstat (limited to 'srcs')
-rw-r--r--srcs/juloo.keyboard2/Config.java4
-rw-r--r--srcs/juloo.keyboard2/Keyboard2.java3
-rw-r--r--srcs/juloo.keyboard2/Keyboard2View.java9
-rw-r--r--srcs/juloo.keyboard2/KeyboardData.java12
4 files changed, 23 insertions, 5 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java
index 20e0311..366cc0c 100644
--- a/srcs/juloo.keyboard2/Config.java
+++ b/srcs/juloo.keyboard2/Config.java
@@ -24,6 +24,8 @@ class Config
public float horizontalMargin;
public boolean disableAccentKeys;
+ public boolean shouldOfferSwitchingToNextInputMethod;
+
public Config(Keyboard2 context)
{
Resources res = context.getResources();
@@ -46,6 +48,8 @@ class Config
disableAccentKeys = false;
// from prefs
refresh();
+ // initialized later
+ shouldOfferSwitchingToNextInputMethod = false;
}
/*
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java
index f4226f6..f94ef3a 100644
--- a/srcs/juloo.keyboard2/Keyboard2.java
+++ b/srcs/juloo.keyboard2/Keyboard2.java
@@ -100,6 +100,7 @@ public class Keyboard2 extends InputMethodService
public void onStartInputView(EditorInfo info, boolean restarting)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
+ _config.shouldOfferSwitchingToNextInputMethod = imm.shouldOfferSwitchingToNextInputMethod(getCurrentInputBinding().getConnectionToken());
refreshSubtype(imm.getCurrentInputMethodSubtype());
if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0)
_keyboardView.setKeyboard(getLayout(R.xml.numeric));
@@ -156,7 +157,7 @@ public class Keyboard2 extends InputMethodService
{
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
- imm.switchToNextInputMethod(getWindow().getWindow().getAttributes().token, false);
+ imm.switchToNextInputMethod(getCurrentInputBinding().getConnectionToken(), false);
}
else if ((flags & (KeyValue.FLAG_CTRL | KeyValue.FLAG_ALT)) != 0)
handleMetaKeyUp(key, flags);
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java
index ccbbb7e..1dbfb87 100644
--- a/srcs/juloo.keyboard2/Keyboard2View.java
+++ b/srcs/juloo.keyboard2/Keyboard2View.java
@@ -83,12 +83,13 @@ public class Keyboard2View extends View
return (paint);
}
- public void setKeyboard(KeyboardData keyboard)
+ public void setKeyboard(KeyboardData kw)
{
+ if (!_config.shouldOfferSwitchingToNextInputMethod)
+ kw = kw.removeKeys(new KeyboardData.RemoveKeysByEvent(KeyValue.EVENT_CHANGE_METHOD));
if (_config.disableAccentKeys)
- _keyboard = keyboard.removeKeys(new KeyboardData.RemoveKeysByFlags(KeyValue.FLAGS_ACCENTS));
- else
- _keyboard = keyboard;
+ kw = kw.removeKeys(new KeyboardData.RemoveKeysByFlags(KeyValue.FLAGS_ACCENTS));
+ _keyboard = kw;
reset();
}
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java
index 000c7e0..c137af2 100644
--- a/srcs/juloo.keyboard2/KeyboardData.java
+++ b/srcs/juloo.keyboard2/KeyboardData.java
@@ -171,4 +171,16 @@ class KeyboardData
return (k == null || (k.getFlags() & _flags) != 0) ? null : k;
}
}
+
+ public static class RemoveKeysByEvent implements MapKeys
+ {
+ private final int _eventCode;
+
+ public RemoveKeysByEvent(int ev) { _eventCode = ev; }
+
+ public KeyValue map(KeyValue k)
+ {
+ return (k == null || k.getEventCode() == _eventCode) ? null : k;
+ }
+ }
}