diff --git a/res/xml/beng_national.xml b/res/xml/beng_national.xml index 2df7bce..a3c0d55 100644 --- a/res/xml/beng_national.xml +++ b/res/xml/beng_national.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/beng_provat.xml b/res/xml/beng_provat.xml index 572e0ef..ee7be4a 100644 --- a/res/xml/beng_provat.xml +++ b/res/xml/beng_provat.xml @@ -1,5 +1,5 @@ - + diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 8900656..30be772 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -242,7 +242,7 @@ final class Config } }); if (show_numpad) - kw = kw.addNumPad(modify_numpad(KeyboardData.num_pad)); + kw = kw.addNumPad(modify_numpad(KeyboardData.num_pad, kw.script)); if (number_row) kw = kw.addNumberRow(); if (extra_keys.size() > 0) @@ -253,9 +253,10 @@ final class Config /** * Handle the numpad layout. */ - public KeyboardData modify_numpad(KeyboardData kw) + public KeyboardData modify_numpad(KeyboardData kw, String script) { final KeyValue action_key = action_key(); + final KeyModifier.Map_char map_digit = KeyModifier.modify_numpad_script(script); return kw.mapKeys(new KeyboardData.MapKeyValues() { public KeyValue apply(KeyValue key, boolean localized) { @@ -277,11 +278,15 @@ final class Config } break; case Char: - char a = key.getChar(), b = a; + char prev_c = key.getChar(); + char c = prev_c; if (inverse_numpad) - b = inverse_numpad_char(a); - if (a != b) - return key.withChar(b); + c = inverse_numpad_char(c); + String modified = map_digit.apply(c); + if (modified != null) // Was modified by script + return key.withSymbol(modified); + if (prev_c != c) // Was inverted + return key.withChar(c); break; } return key; diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java index 20834b9..32ee570 100644 --- a/srcs/juloo.keyboard2/KeyModifier.java +++ b/srcs/juloo.keyboard2/KeyModifier.java @@ -83,6 +83,20 @@ class KeyModifier return k; } + public static Map_char modify_numpad_script(String script) + { + if (script == null) + return map_char_none; + switch (script) + { + case "arabic": return map_char_numpad_arabic; + case "bengali": return map_char_numpad_bengali; + case "devanagari": return map_char_numpad_devanagari; + case "persian": return map_char_numpad_persian; + default: return map_char_none; + } + } + private static KeyValue apply_map_char(KeyValue k, Map_char map) { switch (k.getKind()) @@ -427,13 +441,18 @@ class KeyModifier return ks; } - private static abstract class Map_char + public static abstract class Map_char { /** Modify a char or return [null] if the modifier do not apply. Return a [String] that can contains combining diacritics. */ public abstract String apply(char c); } + private static final Map_char map_char_none = + new Map_char() { + public String apply(char _c) { return null; } + }; + private static char map_char_shift(char c) { switch (c) @@ -971,4 +990,88 @@ class KeyModifier } } }; + + private static final Map_char map_char_numpad_arabic = + new Map_char() { + public String apply(char c) + { + switch (c) + { + case '0': return "٠"; + case '1': return "١"; + case '2': return "٢"; + case '3': return "٣"; + case '4': return "٤"; + case '5': return "٥"; + case '6': return "٦"; + case '7': return "٧"; + case '8': return "٨"; + case '9': return "٩"; + default: return null; + } + } + }; + + private static final Map_char map_char_numpad_bengali = + new Map_char() { + public String apply(char c) + { + switch (c) + { + case '0': return "০"; + case '1': return "১"; + case '2': return "২"; + case '3': return "৩"; + case '4': return "৪"; + case '5': return "৫"; + case '6': return "৬"; + case '7': return "৭"; + case '8': return "৮"; + case '9': return "৯"; + default: return null; + } + } + }; + + private static final Map_char map_char_numpad_devanagari = + new Map_char() { + public String apply(char c) + { + switch (c) + { + case '0': return "०"; + case '1': return "१"; + case '2': return "२"; + case '3': return "३"; + case '4': return "४"; + case '5': return "५"; + case '6': return "६"; + case '7': return "७"; + case '8': return "८"; + case '9': return "९"; + default: return null; + } + } + }; + + private static final Map_char map_char_numpad_persian = + new Map_char() { + public String apply(char c) + { + switch (c) + { + case '0': return "۰"; + case '1': return "۱"; + case '2': return "۲"; + case '3': return "۳"; + case '4': return "۴"; + case '5': return "۵"; + case '6': return "۶"; + case '7': return "۷"; + case '8': return "۸"; + case '9': return "۹"; + default: return null; + } + } + }; } diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 924f87b..5720f64 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -40,8 +40,8 @@ public class Keyboard2 extends InputMethodService private Config _config; - /** Layout currently visible. */ - KeyboardData current_layout() + /** Layout currently visible before it has been modified. */ + KeyboardData current_layout_unmodified() { if (_currentSpecialLayout != null) return _currentSpecialLayout; @@ -52,7 +52,13 @@ public class Keyboard2 extends InputMethodService layout = _config.layouts.get(_currentTextLayout); if (layout == null) layout = _localeTextLayout; - return _config.modify_layout(layout); + return layout; + } + + /** Layout currently visible. */ + KeyboardData current_layout() + { + return _config.modify_layout(current_layout_unmodified()); } void setTextLayout(int l) @@ -84,7 +90,9 @@ public class Keyboard2 extends InputMethodService /** Load a layout that contains a numpad (eg. the pin entry). */ KeyboardData loadNumpad(int layout_id) { - return _config.modify_numpad(KeyboardData.load(getResources(), layout_id)); + String current_script = current_layout_unmodified().script; + return _config.modify_numpad(KeyboardData.load(getResources(), layout_id), + current_script); } @Override