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/Config.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/Config.java')
| -rw-r--r-- | srcs/juloo.keyboard2/Config.java | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 09db10d..b38604b 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -8,6 +8,7 @@ import android.os.Build; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.KeyEvent; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -25,8 +26,8 @@ final class Config public final float sublabelTextSize; // From preferences - public KeyboardData layout; // Or 'null' for the system defaults - public KeyboardData second_layout; // Or 'null' for none + /** [null] represent the [system] layout. */ + public List<KeyboardData> layouts; public KeyboardData custom_layout; // Might be 'null' public boolean show_numpad = false; // From the 'numpad_layout' option, also apply to the numeric pane. @@ -56,7 +57,6 @@ final class Config // Dynamically set public boolean shouldOfferSwitchingToNextInputMethod; - public boolean shouldOfferSwitchingToSecond; public boolean shouldOfferVoiceTyping; public String actionLabel; // Might be 'null' public int actionId; // Meaningful only when 'actionLabel' isn't 'null' @@ -80,7 +80,6 @@ final class Config refresh(res); // initialized later shouldOfferSwitchingToNextInputMethod = false; - shouldOfferSwitchingToSecond = false; shouldOfferVoiceTyping = false; actionLabel = null; actionId = 0; @@ -116,8 +115,10 @@ final class Config { keyboardHeightPercent = _prefs.getInt("keyboard_height", 35); } - layout = layout_of_string(res, _prefs.getString("layout", "none")); - second_layout = tweak_secondary_layout(layout_of_string(res, _prefs.getString("second_layout", "none"))); + List<String> layout_names = LayoutsPreference.load_from_preferences(_prefs); + layouts = new ArrayList<KeyboardData>(); + for (String l : layout_names) + layouts.add(layout_of_string(res, l)); custom_layout = KeyboardData.load_string(_prefs.getString("custom_layout", "")); inverse_numpad = _prefs.getString("numpad_layout", "default").equals("low_first"); number_row = _prefs.getBoolean("number_row", false); @@ -214,8 +215,10 @@ final class Config case ACTION: return (swapEnterActionKey && action_key != null) ? KeyValue.getKeyByName("enter") : action_key; - case SWITCH_SECOND: - return shouldOfferSwitchingToSecond ? key : null; + case SWITCH_FORWARD: + return (layouts.size() > 1) ? key : null; + case SWITCH_BACKWARD: + return (layouts.size() > 2) ? key : null; case SWITCH_VOICE_TYPING: return shouldOfferVoiceTyping ? key : null; } @@ -287,23 +290,6 @@ final class Config }); } - /** Modify a layout to turn it into a secondary layout by changing the - "switch_second" key. */ - KeyboardData tweak_secondary_layout(KeyboardData layout) - { - if (layout == null) - return null; - return layout.mapKeys(new KeyboardData.MapKeyValues() { - public KeyValue apply(KeyValue key, boolean localized) - { - if (key.getKind() == KeyValue.Kind.Event - && key.getEvent() == KeyValue.Event.SWITCH_SECOND) - return KeyValue.getKeyByName("switch_second_back"); - return key; - } - }); - } - private float get_dip_pref(DisplayMetrics dm, String pref_name, float def) { float value; |
