abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/Keyboard2.java
diff options
context:
space:
mode:
authorJules Aguillon2021-05-09 00:09:10 +0200
committerJules Aguillon2021-05-09 00:09:10 +0200
commit7a3312fd01ef2bf48b146677766f7ea4b036b7df (patch)
treeff3493147ee33d36c82937fb570230200e6ea50c /srcs/juloo.keyboard2/Keyboard2.java
parentebfb8f3b3916d7735e67562931b571dacb86a6d9 (diff)
downloadunexpected-keyboard-7a3312fd01ef2bf48b146677766f7ea4b036b7df.tar.gz
unexpected-keyboard-7a3312fd01ef2bf48b146677766f7ea4b036b7df.zip
Add the accents preference
This replaces the "disable accent keys" checkbox. The default should work for anyone: Accents will be hidden unless the user has the french language installed. The value "show every accents" is useful for versions of android that don't have subtypes.
Diffstat (limited to 'srcs/juloo.keyboard2/Keyboard2.java')
-rw-r--r--srcs/juloo.keyboard2/Keyboard2.java57
1 files changed, 48 insertions, 9 deletions
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java
index 9e64310..ef497ff 100644
--- a/srcs/juloo.keyboard2/Keyboard2.java
+++ b/srcs/juloo.keyboard2/Keyboard2.java
@@ -11,6 +11,7 @@ import android.os.IBinder;
import android.text.InputType;
import android.preference.PreferenceManager;
import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import android.view.KeyEvent;
@@ -18,6 +19,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.util.Log;
import java.util.HashMap;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -66,25 +68,59 @@ public class Keyboard2 extends InputMethodService
return (_specialKeyFont);
}
- private void refreshSubtype(InputMethodSubtype subtype)
+ private List<InputMethodSubtype> getEnabledSubtypes(InputMethodManager imm)
+ {
+ String pkg = getPackageName();
+ for (InputMethodInfo imi : imm.getEnabledInputMethodList())
+ if (imi.getPackageName().equals(pkg))
+ return imm.getEnabledInputMethodSubtypeList(imi, true);
+ return null;
+ }
+
+ private void refreshSubtypeLayout(InputMethodSubtype subtype)
{
- int l;
if (_config.layout == -1)
- l = Config.layoutId_of_string(subtype.getExtraValueOf("default_layout"));
+ _currentTextLayout = Config.layoutId_of_string(subtype.getExtraValueOf("default_layout"));
else
- l = _config.layout;
- if (_currentTextLayout != l)
+ _currentTextLayout = _config.layout;
+ }
+
+ private int accents_of_subtype(InputMethodSubtype subtype)
+ {
+ String accents_option = subtype.getExtraValueOf("accents");
+ int flags = 0;
+ if (accents_option != null)
+ for (String acc : accents_option.split("\\|"))
+ flags |= Config.accentFlag_of_name(acc);
+ return flags;
+ }
+
+ private void refreshAccentsOption(InputMethodManager imm, InputMethodSubtype subtype)
+ {
+ final int DONT_REMOVE = KeyValue.FLAG_ACCENT_SUPERSCRIPT | KeyValue.FLAG_ACCENT_SUBSCRIPT;
+ int to_keep = DONT_REMOVE;
+ switch (_config.accents)
{
- _currentTextLayout = l;
- _keyboardView.setKeyboard(getLayout(l));
+ case 1:
+ to_keep |= accents_of_subtype(subtype);
+ for (InputMethodSubtype s : getEnabledSubtypes(imm))
+ to_keep |= accents_of_subtype(s);
+ break;
+ case 2: to_keep |= accents_of_subtype(subtype); break;
+ case 3: to_keep = KeyValue.FLAGS_ACCENTS; break;
+ case 4: break;
+ default: throw new IllegalArgumentException();
}
+ _config.accent_flags_to_remove = ~to_keep & KeyValue.FLAGS_ACCENTS;
}
private void refreshSubtypeImm()
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
_config.shouldOfferSwitchingToNextInputMethod = imm.shouldOfferSwitchingToNextInputMethod(getConnectionToken());
- refreshSubtype(imm.getCurrentInputMethodSubtype());
+ InputMethodSubtype subtype = imm.getCurrentInputMethodSubtype();
+ refreshSubtypeLayout(subtype);
+ refreshAccentsOption(imm, subtype);
}
@Override
@@ -103,13 +139,16 @@ public class Keyboard2 extends InputMethodService
refreshSubtypeImm();
if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0)
_keyboardView.setKeyboard(getLayout(R.xml.numeric));
+ else
+ _keyboardView.setKeyboard(getLayout(_currentTextLayout));
_keyboardView.reset(); // Layout might need to change due to rotation
}
@Override
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype)
{
- refreshSubtype(subtype);
+ refreshSubtypeImm();
+ _keyboardView.setKeyboard(getLayout(_currentTextLayout));
}
@Override