mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-30 14:42:27 +02:00
Per-script extra keys
Allows to define a locale's script in 'method.xml' and use that to add the extra keys for a locale to layouts of the same script only. A locale of an undefined script will add its extra keys to every layouts. A layout of an undefined script will have the extra keys of all the enabled locales.
This commit is contained in:
@ -57,7 +57,7 @@ final class Config
|
|||||||
public String actionLabel; // Might be 'null'
|
public String actionLabel; // Might be 'null'
|
||||||
public int actionId; // Meaningful only when 'actionLabel' isn't 'null'
|
public int actionId; // Meaningful only when 'actionLabel' isn't 'null'
|
||||||
public boolean swapEnterActionKey; // Swap the "enter" and "action" keys
|
public boolean swapEnterActionKey; // Swap the "enter" and "action" keys
|
||||||
public Set<KeyValue> extra_keys_subtype;
|
public ExtraKeys extra_keys_subtype;
|
||||||
public Set<KeyValue> extra_keys_param;
|
public Set<KeyValue> extra_keys_param;
|
||||||
|
|
||||||
public final IKeyEventHandler handler;
|
public final IKeyEventHandler handler;
|
||||||
@ -176,7 +176,7 @@ final class Config
|
|||||||
final Set<KeyValue> extra_keys = new HashSet<KeyValue>();
|
final Set<KeyValue> extra_keys = new HashSet<KeyValue>();
|
||||||
final Set<KeyValue> remove_keys = new HashSet<KeyValue>();
|
final Set<KeyValue> remove_keys = new HashSet<KeyValue>();
|
||||||
if (extra_keys_subtype != null)
|
if (extra_keys_subtype != null)
|
||||||
extra_keys.addAll(extra_keys_subtype);
|
extra_keys_subtype.compute(extra_keys, kw.script);
|
||||||
extra_keys.addAll(extra_keys_param);
|
extra_keys.addAll(extra_keys_param);
|
||||||
boolean number_row = this.number_row && !show_numpad;
|
boolean number_row = this.number_row && !show_numpad;
|
||||||
if (number_row)
|
if (number_row)
|
||||||
|
57
srcs/juloo.keyboard2/ExtraKeys.java
Normal file
57
srcs/juloo.keyboard2/ExtraKeys.java
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package juloo.keyboard2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
class ExtraKeys
|
||||||
|
{
|
||||||
|
Map<String, List<KeyValue>> _keys_per_script;
|
||||||
|
|
||||||
|
public ExtraKeys()
|
||||||
|
{
|
||||||
|
_keys_per_script = new HashMap<String, List<KeyValue>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add_keys_for_script(String script, List<KeyValue> kvs)
|
||||||
|
{
|
||||||
|
List<KeyValue> ks = _keys_per_script.get(script);
|
||||||
|
if (ks == null) ks = new ArrayList<KeyValue>();
|
||||||
|
ks.addAll(kvs);
|
||||||
|
_keys_per_script.put(script, ks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Add the keys that should be added to the keyboard into [dst]. [null] is
|
||||||
|
a valid script. */
|
||||||
|
public void compute(Set<KeyValue> dst, String script)
|
||||||
|
{
|
||||||
|
if (script == null)
|
||||||
|
{
|
||||||
|
for (String sc : _keys_per_script.keySet())
|
||||||
|
get_keys_of_script(dst, sc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
get_keys_of_script(dst, null);
|
||||||
|
get_keys_of_script(dst, script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_keys_of_script(Set<KeyValue> dst, String script)
|
||||||
|
{
|
||||||
|
List<KeyValue> ks = _keys_per_script.get(script);
|
||||||
|
if (ks != null)
|
||||||
|
dst.addAll(ks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<KeyValue> parse_extra_keys(String str)
|
||||||
|
{
|
||||||
|
List<KeyValue> dst = new ArrayList<KeyValue>();
|
||||||
|
String[] ks = str.split("\\|");
|
||||||
|
for (int i = 0; i < ks.length; i++)
|
||||||
|
dst.add(KeyValue.getKeyByName(ks[i]));
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
}
|
@ -99,19 +99,18 @@ public class Keyboard2 extends InputMethodService
|
|||||||
return Arrays.asList();
|
return Arrays.asList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extra_keys_of_subtype(Set<KeyValue> dst, InputMethodSubtype subtype)
|
private void extra_keys_of_subtype(ExtraKeys dst, InputMethodSubtype subtype)
|
||||||
{
|
{
|
||||||
String extra_keys = subtype.getExtraValueOf("extra_keys");
|
String extra_keys = subtype.getExtraValueOf("extra_keys");
|
||||||
|
String script = subtype.getExtraValueOf("script");
|
||||||
if (extra_keys == null)
|
if (extra_keys == null)
|
||||||
return;
|
return;
|
||||||
String[] ks = extra_keys.split("\\|");
|
dst.add_keys_for_script(script, ExtraKeys.parse_extra_keys(extra_keys));
|
||||||
for (int i = 0; i < ks.length; i++)
|
|
||||||
dst.add(KeyValue.getKeyByName(ks[i]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshAccentsOption(InputMethodManager imm, InputMethodSubtype subtype)
|
private void refreshAccentsOption(InputMethodManager imm, InputMethodSubtype subtype)
|
||||||
{
|
{
|
||||||
HashSet<KeyValue> extra_keys = new HashSet<KeyValue>();
|
ExtraKeys extra_keys = new ExtraKeys();
|
||||||
List<InputMethodSubtype> enabled_subtypes = getEnabledSubtypes(imm);
|
List<InputMethodSubtype> enabled_subtypes = getEnabledSubtypes(imm);
|
||||||
switch (_config.accents)
|
switch (_config.accents)
|
||||||
{
|
{
|
||||||
@ -132,16 +131,6 @@ public class Keyboard2 extends InputMethodService
|
|||||||
_config.shouldOfferSwitchingToNextInputMethod = true;
|
_config.shouldOfferSwitchingToNextInputMethod = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshSubtypeLegacyFallback()
|
|
||||||
{
|
|
||||||
// Fallback for the accents option: Only respect the "None" case
|
|
||||||
switch (_config.accents)
|
|
||||||
{
|
|
||||||
case 1: case 2: case 3: _config.extra_keys_subtype = null; break;
|
|
||||||
case 4: _config.extra_keys_subtype = new HashSet<KeyValue>(); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
InputMethodManager get_imm()
|
InputMethodManager get_imm()
|
||||||
{
|
{
|
||||||
return (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
|
return (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
|
||||||
@ -156,20 +145,11 @@ public class Keyboard2 extends InputMethodService
|
|||||||
_config.shouldOfferSwitchingToNextInputMethod = shouldOfferSwitchingToNextInputMethod();
|
_config.shouldOfferSwitchingToNextInputMethod = shouldOfferSwitchingToNextInputMethod();
|
||||||
_config.shouldOfferVoiceTyping = (get_voice_typing_im(imm) != null);
|
_config.shouldOfferVoiceTyping = (get_voice_typing_im(imm) != null);
|
||||||
KeyboardData default_layout = null;
|
KeyboardData default_layout = null;
|
||||||
if (VERSION.SDK_INT < 12)
|
_config.extra_keys_subtype = null;
|
||||||
{
|
if (VERSION.SDK_INT >= 12)
|
||||||
// Subtypes won't work well under API level 12 (getExtraValueOf)
|
|
||||||
refreshSubtypeLegacyFallback();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
InputMethodSubtype subtype = imm.getCurrentInputMethodSubtype();
|
InputMethodSubtype subtype = imm.getCurrentInputMethodSubtype();
|
||||||
if (subtype == null)
|
if (subtype != null)
|
||||||
{
|
|
||||||
// On some rare cases, [subtype] is null.
|
|
||||||
refreshSubtypeLegacyFallback();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
String s = subtype.getExtraValueOf("default_layout");
|
String s = subtype.getExtraValueOf("default_layout");
|
||||||
if (s != null)
|
if (s != null)
|
||||||
|
Reference in New Issue
Block a user