Allow to hide more keys than just accents

Add the "FLAGS_LANGS" set of flags, which will be used to hide
individual keys that are not accents.
This commit is contained in:
Jules Aguillon 2022-01-09 12:47:47 +01:00
parent 2764e96eb1
commit 23e59c6b09
5 changed files with 31 additions and 23 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<input-method xmlns:android="http://schemas.android.com/apk/res/android" android:settingsActivity="juloo.keyboard2.SettingsActivity" android:supportsSwitchingToNextInputMethod="true">
<subtype android:label="%s" android:languageTag="en" android:imeSubtypeLocale="en_US" android:imeSubtypeMode="keyboard" android:isAsciiCapable="true" android:imeSubtypeExtraValue="default_layout=qwerty"/>
<subtype android:label="%s" android:languageTag="fr" android:imeSubtypeLocale="fr_FR" android:imeSubtypeMode="keyboard" android:isAsciiCapable="true" android:imeSubtypeExtraValue="default_layout=azerty,accents=grave|aigu|circonflexe|cedille|trema"/>
<subtype android:label="%s" android:languageTag="es" android:imeSubtypeLocale="es_ES" android:imeSubtypeMode="keyboard" android:isAsciiCapable="true" android:imeSubtypeExtraValue="default_layout=qwerty,accents=aigu|tilde|trema"/>
<subtype android:label="%s" android:languageTag="it" android:imeSubtypeLocale="it_IT" android:imeSubtypeMode="keyboard" android:isAsciiCapable="true" android:imeSubtypeExtraValue="default_layout=qwerty,accents=grave|aigu"/>
<subtype android:label="%s" android:languageTag="sv" android:imeSubtypeLocale="sv_SE" android:imeSubtypeMode="keyboard" android:isAsciiCapable="true" android:imeSubtypeExtraValue="default_layout=qwerty,accents=aigu|trema|ring"/>
<subtype android:label="%s" android:languageTag="fr" android:imeSubtypeLocale="fr_FR" android:imeSubtypeMode="keyboard" android:isAsciiCapable="true" android:imeSubtypeExtraValue="default_layout=azerty,extra_keys=grave|aigu|circonflexe|cedille|trema"/>
<subtype android:label="%s" android:languageTag="es" android:imeSubtypeLocale="es_ES" android:imeSubtypeMode="keyboard" android:isAsciiCapable="true" android:imeSubtypeExtraValue="default_layout=qwerty,extra_keys=aigu|tilde|trema"/>
<subtype android:label="%s" android:languageTag="it" android:imeSubtypeLocale="it_IT" android:imeSubtypeMode="keyboard" android:isAsciiCapable="true" android:imeSubtypeExtraValue="default_layout=qwerty,extra_keys=grave|aigu"/>
<subtype android:label="%s" android:languageTag="sv" android:imeSubtypeLocale="sv_SE" android:imeSubtypeMode="keyboard" android:isAsciiCapable="true" android:imeSubtypeExtraValue="default_layout=qwerty,extra_keys=aigu|trema|ring"/>
</input-method>

View File

@ -33,7 +33,7 @@ final class Config
// Dynamically set
public boolean shouldOfferSwitchingToNextInputMethod;
public int accent_flags_to_remove;
public int key_flags_to_remove;
public final IKeyEventHandler handler;
@ -61,7 +61,7 @@ final class Config
refresh(context);
// initialized later
shouldOfferSwitchingToNextInputMethod = false;
accent_flags_to_remove = 0;
key_flags_to_remove = 0;
handler = h;
}
@ -107,7 +107,7 @@ final class Config
}
/* Used for the accents option. */
public static int accentFlag_of_name(String name)
public static int extra_key_flag_of_name(String name)
{
switch (name)
{

View File

@ -47,6 +47,15 @@ class KeyValue
FLAG_ACCENT3 | FLAG_ACCENT4 | FLAG_ACCENT5 | FLAG_ACCENT6 |
FLAG_ACCENT_SUPERSCRIPT | FLAG_ACCENT_SUBSCRIPT | FLAG_ACCENT_RING;
// Language specific keys
public static final int FLAGS_LANGS = 0;
public static final int FLAGS_NOT_HIDDEN_ACCENTS = FLAG_ACCENT_SUPERSCRIPT |
FLAG_ACCENT_SUBSCRIPT;
// Keys that have to be enabled per language
public static final int FLAGS_HIDDEN_KEYS =
(FLAGS_ACCENTS & ~FLAGS_NOT_HIDDEN_ACCENTS) | FLAGS_LANGS;
public final String name;
public final String symbol;
public final char char_;

View File

@ -81,33 +81,32 @@ public class Keyboard2 extends InputMethodService
_currentTextLayout = l;
}
private int accents_of_subtype(InputMethodSubtype subtype)
private int extra_keys_of_subtype(InputMethodSubtype subtype)
{
String accents_option = subtype.getExtraValueOf("accents");
String extra_keys = subtype.getExtraValueOf("extra_keys");
int flags = 0;
if (accents_option != null)
for (String acc : accents_option.split("\\|"))
flags |= Config.accentFlag_of_name(acc);
if (extra_keys != null)
for (String acc : extra_keys.split("\\|"))
flags |= Config.extra_key_flag_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;
int to_keep = 0;
switch (_config.accents)
{
case 1:
to_keep |= accents_of_subtype(subtype);
to_keep |= extra_keys_of_subtype(subtype);
for (InputMethodSubtype s : getEnabledSubtypes(imm))
to_keep |= accents_of_subtype(s);
to_keep |= extra_keys_of_subtype(s);
break;
case 2: to_keep |= accents_of_subtype(subtype); break;
case 3: to_keep = KeyValue.FLAGS_ACCENTS; break;
case 2: to_keep |= extra_keys_of_subtype(subtype); break;
case 3: to_keep = KeyValue.FLAGS_HIDDEN_KEYS; break;
case 4: break;
default: throw new IllegalArgumentException();
}
_config.accent_flags_to_remove = ~to_keep & KeyValue.FLAGS_ACCENTS;
_config.key_flags_to_remove = ~to_keep & KeyValue.FLAGS_HIDDEN_KEYS;
}
private void refreshSubtypeLegacyFallback()
@ -115,8 +114,8 @@ public class Keyboard2 extends InputMethodService
// Fallback for the accents option: Only respect the "None" case
switch (_config.accents)
{
case 1: case 2: case 3: _config.accent_flags_to_remove = 0; break;
case 4: _config.accent_flags_to_remove = KeyValue.FLAGS_ACCENTS; break;
case 1: case 2: case 3: _config.key_flags_to_remove = 0; break;
case 4: _config.key_flags_to_remove = KeyValue.FLAGS_HIDDEN_KEYS; break;
}
// Fallback for the layout option: Use qwerty in the "system settings" case
_currentTextLayout = (_config.layout == -1) ? R.xml.qwerty : _config.layout;

View File

@ -61,8 +61,8 @@ public class Keyboard2View extends View
{
if (!_config.shouldOfferSwitchingToNextInputMethod)
kw = kw.removeKeys(new KeyboardData.RemoveKeysByEvent(KeyValue.EVENT_CHANGE_METHOD));
if (_config.accent_flags_to_remove != 0)
kw = kw.removeKeys(new KeyboardData.RemoveKeysByFlags(_config.accent_flags_to_remove));
if (_config.key_flags_to_remove != 0)
kw = kw.removeKeys(new KeyboardData.RemoveKeysByFlags(_config.key_flags_to_remove));
_keyboard = kw;
reset();
}