diff options
| author | Jules Aguillon | 2023-07-29 18:37:06 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2023-07-30 21:44:14 +0200 |
| commit | dad5f57a036e3f0ad7278ccee5bd248192cbbad2 (patch) | |
| tree | 022b170f190edcf204dc453a49e83193821aeb80 /srcs/juloo.keyboard2/Keyboard2.java | |
| parent | 818aa4c7d597116ed595e960d4415b57ed56d2ec (diff) | |
| download | unexpected-keyboard-dad5f57a036e3f0ad7278ccee5bd248192cbbad2.tar.gz unexpected-keyboard-dad5f57a036e3f0ad7278ccee5bd248192cbbad2.zip | |
Allow more than 2 layouts
The two layout selection options are replaced by a ListGroupPreference
that allow to enter an arbitrary amount of layouts.
The "switch_second" and "switch_second_back" keys are replaced by
"switch_forward" and "switch_backward", which allow to cycle through the
selected layouts in two directions.
Layouts are changed to place these two key on the space bar.
The backward key is not shown if there's only two layouts.
Diffstat (limited to 'srcs/juloo.keyboard2/Keyboard2.java')
| -rw-r--r-- | srcs/juloo.keyboard2/Keyboard2.java | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 3606213..1b59e5e 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -30,7 +30,8 @@ public class Keyboard2 extends InputMethodService private KeyEventHandler _keyeventhandler; // If not 'null', the layout to use instead of [_currentTextLayout]. private KeyboardData _currentSpecialLayout; - private Current_text_layout _currentTextLayout; + /** Current layout index in [Config.layouts]. */ + private int _currentTextLayout; // Layout associated with the currently selected locale. Not 'null'. private KeyboardData _localeTextLayout; private ViewGroup _emojiPane = null; @@ -43,23 +44,31 @@ public class Keyboard2 extends InputMethodService { if (_currentSpecialLayout != null) return _currentSpecialLayout; - KeyboardData layout; - if (_currentTextLayout == Current_text_layout.SECONDARY) - layout = _config.second_layout; - else if (_config.layout == null) + KeyboardData layout = null; + if (_currentTextLayout >= _config.layouts.size()) + _currentTextLayout = 0; + if (_currentTextLayout < _config.layouts.size()) + layout = _config.layouts.get(_currentTextLayout); + if (layout == null) layout = _localeTextLayout; - else - layout = _config.layout; return _config.modify_layout(layout); } - void setTextLayout(Current_text_layout layout) + void setTextLayout(int l) { - _currentTextLayout = layout; + if (l == _currentTextLayout) + return; + _currentTextLayout = l; _currentSpecialLayout = null; _keyboardView.setKeyboard(current_layout()); } + void incrTextLayout(int delta) + { + int s = _config.layouts.size(); + setTextLayout((_currentTextLayout + delta + s) % s); + } + void setSpecialLayout(KeyboardData l) { _currentSpecialLayout = l; @@ -162,15 +171,6 @@ public class Keyboard2 extends InputMethodService if (default_layout == null) default_layout = loadLayout(R.xml.latn_qwerty_us); _localeTextLayout = default_layout; - if (_config.second_layout == null) - { - _config.shouldOfferSwitchingToSecond = false; - _currentTextLayout = Current_text_layout.PRIMARY; - } - else - { - _config.shouldOfferSwitchingToSecond = true; - } } private String actionLabel_of_imeAction(int action) @@ -419,13 +419,12 @@ public class Keyboard2 extends InputMethodService conn.performEditorAction(actionId); break; - case SWITCH_SECOND: - if (_config.second_layout != null) - setTextLayout(Current_text_layout.SECONDARY); + case SWITCH_FORWARD: + incrTextLayout(1); break; - case SWITCH_SECOND_BACK: - setTextLayout(Current_text_layout.PRIMARY); + case SWITCH_BACKWARD: + incrTextLayout(-1); break; case SWITCH_GREEKMATH: @@ -469,10 +468,4 @@ public class Keyboard2 extends InputMethodService { return View.inflate(new ContextThemeWrapper(this, _config.theme), layout, null); } - - private static enum Current_text_layout - { - PRIMARY, - SECONDARY - } } |
