abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2
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
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')
-rw-r--r--srcs/juloo.keyboard2/Config.java25
-rw-r--r--srcs/juloo.keyboard2/Keyboard2.java57
-rw-r--r--srcs/juloo.keyboard2/Keyboard2View.java12
3 files changed, 76 insertions, 18 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java
index 386dc73..dff52d3 100644
--- a/srcs/juloo.keyboard2/Config.java
+++ b/srcs/juloo.keyboard2/Config.java
@@ -9,12 +9,14 @@ class Config
{
private Keyboard2 _context;
+ // From resources
public final float marginTop;
public final float keyPadding;
public final float keyVerticalInterval;
public final float keyHorizontalInterval;
public final float keyRound;
+ // From preferences
public int layout; // Or '-1' for the system defaults
public float subValueDist;
public boolean vibrateEnabled;
@@ -24,11 +26,13 @@ class Config
public float marginBottom;
public float keyHeight;
public float horizontalMargin;
- public boolean disableAccentKeys;
public boolean preciseRepeat;
public float characterSize; // Ratio
+ public int accents; // Values are R.values.pref_accents_v_*
+ // Dynamically set
public boolean shouldOfferSwitchingToNextInputMethod;
+ public int accent_flags_to_remove;
public Config(Keyboard2 context)
{
@@ -51,13 +55,14 @@ class Config
marginBottom = res.getDimension(R.dimen.margin_bottom);
keyHeight = res.getDimension(R.dimen.key_height);
horizontalMargin = res.getDimension(R.dimen.horizontal_margin);
- disableAccentKeys = false;
preciseRepeat = true;
characterSize = 1.f;
+ accents = 0;
// from prefs
refresh();
// initialized later
shouldOfferSwitchingToNextInputMethod = false;
+ accent_flags_to_remove = 0;
}
/*
@@ -76,9 +81,9 @@ class Config
marginBottom = getDipPref(prefs, "margin_bottom", marginBottom);
keyHeight = getDipPref(prefs, "key_height", keyHeight);
horizontalMargin = getDipPref(prefs, "horizontal_margin", horizontalMargin);
- disableAccentKeys = prefs.getBoolean("disable_accent_keys", disableAccentKeys);
preciseRepeat = prefs.getBoolean("precise_repeat", preciseRepeat);
characterSize = prefs.getFloat("character_size", characterSize);
+ accents = Integer.valueOf(prefs.getString("accents", ""));
}
private float getDipPref(SharedPreferences prefs, String pref_name, float def)
@@ -102,4 +107,18 @@ class Config
}
}
+ /* Used for the accents option. */
+ public static int accentFlag_of_name(String name)
+ {
+ switch (name)
+ {
+ case "grave": return KeyValue.FLAG_ACCENT1;
+ case "aigu": return KeyValue.FLAG_ACCENT2;
+ case "circonflexe": return KeyValue.FLAG_ACCENT3;
+ case "tilde": return KeyValue.FLAG_ACCENT4;
+ case "cedille": return KeyValue.FLAG_ACCENT5;
+ case "trema": return KeyValue.FLAG_ACCENT6;
+ default: throw new RuntimeException(name);
+ }
+ }
}
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
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java
index 546ebca..03d58a7 100644
--- a/srcs/juloo.keyboard2/Keyboard2View.java
+++ b/srcs/juloo.keyboard2/Keyboard2View.java
@@ -92,15 +92,15 @@ public class Keyboard2View extends View
return (paint);
}
- public void setKeyboard(KeyboardData kw)
- {
+ public void setKeyboard(KeyboardData kw)
+ {
if (!_config.shouldOfferSwitchingToNextInputMethod)
kw = kw.removeKeys(new KeyboardData.RemoveKeysByEvent(KeyValue.EVENT_CHANGE_METHOD));
- if (_config.disableAccentKeys)
- kw = kw.removeKeys(new KeyboardData.RemoveKeysByFlags(KeyValue.FLAGS_ACCENTS));
+ if (_config.accent_flags_to_remove != 0)
+ kw = kw.removeKeys(new KeyboardData.RemoveKeysByFlags(_config.accent_flags_to_remove));
_keyboard = kw;
- reset();
- }
+ reset();
+ }
public void reset()
{