diff options
| author | Jules Aguillon | 2022-11-13 00:24:23 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2022-11-13 00:24:23 +0100 |
| commit | 51b330c6168a8b0e0c16482254d4674fbe5476c7 (patch) | |
| tree | bc3b05120d606e386269322e7fab2694e20ee845 /srcs | |
| parent | 815e30a505eb6766e29d85c2e1a5d8f4da9c83d3 (diff) | |
| download | unexpected-keyboard-51b330c6168a8b0e0c16482254d4674fbe5476c7.tar.gz unexpected-keyboard-51b330c6168a8b0e0c16482254d4674fbe5476c7.zip | |
Allow switching quickly between two layouts
A new option allow to choose a secondary layout, the switching key is
placed on the top edge of the space bar.
The "Programming layout" option was basically doing that but it was
possible to choose from a few layouts only. It is improved and renamed.
The 'LayoutListPreference' allows setting the string for the first entry
but otherwise share the rest of the array.
Add nice icons from materialdesignicons.
Diffstat (limited to 'srcs')
| -rw-r--r-- | srcs/juloo.keyboard2/Config.java | 19 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/KeyEventHandler.java | 7 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/KeyValue.java | 6 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/Keyboard2.java | 16 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/LayoutListPreference.java | 25 | ||||
| -rw-r--r-- | srcs/special_font/09.svg | 8 | ||||
| -rw-r--r-- | srcs/special_font/13.svg | 2 | ||||
| -rw-r--r-- | srcs/special_font/14.svg | 2 | ||||
| -rw-r--r-- | srcs/special_font/result.ttf | bin | 7460 -> 7900 bytes |
9 files changed, 56 insertions, 29 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index b2c23a5..6c1dced 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -25,7 +25,7 @@ final class Config // From preferences public int layout; // Or '-1' for the system defaults - public int programming_layout; // Or '-1' for none + public int second_layout; // Or '-1' for none public boolean show_numpad = false; public float swipe_dist_px; public boolean vibrateEnabled; @@ -46,7 +46,7 @@ final class Config // Dynamically set public boolean shouldOfferSwitchingToNextInputMethod; - public boolean shouldOfferSwitchingToProgramming; + public boolean shouldOfferSwitchingToSecond; public String actionLabel; // Might be 'null' public int actionId; // Meaningful only when 'actionLabel' isn't 'null' public boolean swapEnterActionKey; // Swap the "enter" and "action" keys @@ -65,7 +65,7 @@ final class Config sublabelTextSize = 0.22f; // default values layout = -1; - programming_layout = -1; + second_layout = -1; vibrateEnabled = true; longPressTimeout = 600; longPressInterval = 65; @@ -81,7 +81,7 @@ final class Config refresh(res); // initialized later shouldOfferSwitchingToNextInputMethod = false; - shouldOfferSwitchingToProgramming = false; + shouldOfferSwitchingToSecond = false; actionLabel = null; actionId = 0; swapEnterActionKey = false; @@ -115,10 +115,8 @@ final class Config { keyboardHeightPercent = _prefs.getInt("keyboard_height", 35); } - String layout_s = _prefs.getString("layout", "system"); - layout = layout_s.equals("system") ? -1 : layoutId_of_string(layout_s); - String prog_layout_s = _prefs.getString("programming_layout", "none"); - programming_layout = prog_layout_s.equals("none") ? -1 : layoutId_of_string(prog_layout_s); + layout = layoutId_of_string(_prefs.getString("layout", "none")); + second_layout = layoutId_of_string(_prefs.getString("second_layout", "none")); // The swipe distance is defined relatively to the "exact physical pixels // per inch of the screen", which isn't affected by the scaling settings. // Take the mean of both dimensions as an approximation of the diagonal. @@ -185,8 +183,8 @@ final class Config case ACTION: return (swapEnterActionKey && action_key != null) ? KeyValue.getKeyByName("enter") : action_key; - case SWITCH_PROGRAMMING: - return shouldOfferSwitchingToProgramming ? key : null; + case SWITCH_SECOND: + return shouldOfferSwitchingToSecond ? key : null; } break; case Keyevent: @@ -249,6 +247,7 @@ final class Config { switch (name) { + case "system": case "none": return -1; case "azerty": return R.xml.azerty; case "bangla": return R.xml.bangla; case "bgph1": return R.xml.local_bgph1; diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index 4623dec..5d23903 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -27,13 +27,14 @@ class KeyEventHandler implements Config.IKeyEventHandler switch (key.getEvent()) { case CONFIG: _recv.showKeyboardConfig(); break; - case SWITCH_TEXT: _recv.switchMain(); break; + case SWITCH_TEXT: + case SWITCH_SECOND_BACK: _recv.switchMain(); break; case SWITCH_NUMERIC: _recv.switchNumeric(); break; case SWITCH_EMOJI: _recv.setPane_emoji(); break; case SWITCH_BACK_EMOJI: _recv.setPane_normal(); break; case CHANGE_METHOD: _recv.switchToNextInputMethod(); break; case ACTION: _recv.performAction(); break; - case SWITCH_PROGRAMMING: _recv.switchProgramming(); break; + case SWITCH_SECOND: _recv.switchSecond(); break; case SWITCH_GREEKMATH: _recv.switchGreekmath(); break; case CAPS_LOCK: _recv.enableCapsLock(); break; } @@ -107,7 +108,7 @@ class KeyEventHandler implements Config.IKeyEventHandler public void switchMain(); public void switchNumeric(); - public void switchProgramming(); + public void switchSecond(); public void switchGreekmath(); public void sendKeyEvent(int eventAction, int eventCode, int meta); diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index e8155f6..0c19eb7 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -15,7 +15,8 @@ final class KeyValue SWITCH_BACK_EMOJI, CHANGE_METHOD, ACTION, - SWITCH_PROGRAMMING, + SWITCH_SECOND, + SWITCH_SECOND_BACK, SWITCH_GREEKMATH, CAPS_LOCK, } @@ -304,7 +305,8 @@ final class KeyValue addEventKey("switch_numeric", "123+", Event.SWITCH_NUMERIC, FLAG_SMALLER_FONT); addEventKey("switch_emoji", 0x01, Event.SWITCH_EMOJI, FLAG_SMALLER_FONT); addEventKey("switch_back_emoji", "ABC", Event.SWITCH_BACK_EMOJI, 0); - addEventKey("switch_programming", "Prog", Event.SWITCH_PROGRAMMING, FLAG_SMALLER_FONT); + addEventKey("switch_second", 0x13, Event.SWITCH_SECOND, FLAG_SMALLER_FONT); + addEventKey("switch_second_back", 0x14, Event.SWITCH_SECOND_BACK, FLAG_SMALLER_FONT); addEventKey("switch_greekmath", "πλ∇¬", Event.SWITCH_GREEKMATH, FLAG_SMALLER_FONT); addEventKey("change_method", 0x09, Event.CHANGE_METHOD, FLAG_SMALLER_FONT); addEventKey("action", "Action", Event.ACTION, FLAG_SMALLER_FONT); // Will always be replaced diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 7bf9812..d2fdb2c 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -157,9 +157,9 @@ public class Keyboard2 extends InputMethodService refreshAccentsOption(imm, subtype); } } - _config.shouldOfferSwitchingToProgramming = - _config.programming_layout != -1 && - _currentTextLayout != _config.programming_layout; + _config.shouldOfferSwitchingToSecond = + _config.second_layout != -1 && + _currentTextLayout != _config.second_layout; } private String actionLabel_of_imeAction(int action) @@ -343,17 +343,17 @@ public class Keyboard2 extends InputMethodService _keyboardView.setKeyboard(getLayout(R.xml.greekmath)); } - public void switchProgramming() + public void switchSecond() { - if (_config.programming_layout == -1) + if (_config.second_layout == -1) return; KeyboardData layout = - getLayout(_config.programming_layout).mapKeys(new KeyboardData.MapKeyValues() { + getLayout(_config.second_layout).mapKeys(new KeyboardData.MapKeyValues() { public KeyValue apply(KeyValue key, boolean localized) { if (key.getKind() == KeyValue.Kind.Event - && key.getEvent() == KeyValue.Event.SWITCH_PROGRAMMING) - return KeyValue.getKeyByName("switch_text"); + && key.getEvent() == KeyValue.Event.SWITCH_SECOND) + return KeyValue.getKeyByName("switch_second_back"); return key; } }); diff --git a/srcs/juloo.keyboard2/LayoutListPreference.java b/srcs/juloo.keyboard2/LayoutListPreference.java new file mode 100644 index 0000000..9e3072c --- /dev/null +++ b/srcs/juloo.keyboard2/LayoutListPreference.java @@ -0,0 +1,25 @@ +package juloo.keyboard2; + +import android.content.Context; +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.preference.ListPreference; +import android.util.AttributeSet; + +public class LayoutListPreference extends ListPreference +{ + public LayoutListPreference(Context context, AttributeSet attrs) + { + super(context, attrs); + final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LayoutListPreference); + String defaultString = a.getString(R.styleable.LayoutListPreference_defaultString); + a.recycle(); + Resources res = context.getResources(); + String[] entries = res.getStringArray(R.array.pref_layout_entries); + entries[0] = defaultString; + setEntries(entries); + setEntryValues(res.getStringArray(R.array.pref_layout_values)); + setSummary("%s"); + setDefaultValue("none"); + } +} diff --git a/srcs/special_font/09.svg b/srcs/special_font/09.svg index 049cc30..ebdc956 100644 --- a/srcs/special_font/09.svg +++ b/srcs/special_font/09.svg @@ -1,6 +1,2 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Generated by IcoMoon.io --> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> -<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="18" height="16" viewBox="0 0 18 16"> -<path fill="#000000" d="M17 2h-16c-0.55 0-1 0.45-1 1v10c0 0.55 0.45 1 1 1h16c0.55 0 1-0.45 1-1v-10c0-0.55-0.45-1-1-1zM10 4h2v2h-2v-2zM13 7v2h-2v-2h2zM7 4h2v2h-2v-2zM10 7v2h-2v-2h2zM4 4h2v2h-2v-2zM7 7v2h-2v-2h2zM2 4h1v2h-1v-2zM2 7h2v2h-2v-2zM3 12h-1v-2h1v2zM12 12h-8v-2h8v2zM16 12h-3v-2h3v2zM16 9h-2v-2h2v2zM16 6h-3v-2h3v2z"></path> -</svg> +<!-- materialdesignicons.com keyboard @Google --> +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19,10H17V8H19M19,13H17V11H19M16,10H14V8H16M16,13H14V11H16M16,17H8V15H16M7,10H5V8H7M7,13H5V11H7M8,11H10V13H8M8,8H10V10H8M11,11H13V13H11M11,8H13V10H11M20,5H4C2.89,5 2,5.89 2,7V17A2,2 0 0,0 4,19H20A2,2 0 0,0 22,17V7C22,5.89 21.1,5 20,5Z" /></svg> diff --git a/srcs/special_font/13.svg b/srcs/special_font/13.svg new file mode 100644 index 0000000..6b4f78a --- /dev/null +++ b/srcs/special_font/13.svg @@ -0,0 +1,2 @@ +<!-- materialdesignicons.com keyboard-settings Michael Richins @MrGrigri --> +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19,10H17V8H19M19,13H17V11H19M16,10H14V8H16M16,13H14V11H16M16,17H8V15H16M7,10H5V8H7M7,13H5V11H7M8,11H10V13H8M8,8H10V10H8M11,11H13V13H11M11,8H13V10H11M20,5H4A2,2 0 0,0 2,7V17A2,2 0 0,0 4,19H20A2,2 0 0,0 22,17V7A2,2 0 0,0 20,5M7,22H9V24H7V22M11,22H13V24H11V22M15,22H17V24H15V22Z" /></svg> diff --git a/srcs/special_font/14.svg b/srcs/special_font/14.svg new file mode 100644 index 0000000..48b39cc --- /dev/null +++ b/srcs/special_font/14.svg @@ -0,0 +1,2 @@ +<!-- materialdesignicons.com keyboard-settings Michael Richins @MrGrigri --> +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7,22H9V24H7V22M11,22H13V24H11V22M15,22H17V24H15V22M4,5A2,2 0 0,0 2,7V17A2,2 0 0,0 4,19H20A2,2 0 0,0 22,17V7A2,2 0 0,0 20,5H4M4,7H20V17H4V7M5,8V10H7V8H5M8,8V10H10V8H8M11,8V10H13V8H11M14,8V10H16V8H14M17,8V10H19V8H17M5,11V13H7V11H5M8,11V13H10V11H8M11,11V13H13V11H11M14,11V13H16V11H14M17,11V13H19V11H17M8,14V16H16V14H8Z" /></svg> diff --git a/srcs/special_font/result.ttf b/srcs/special_font/result.ttf Binary files differindex f81838f..31a4892 100644 --- a/srcs/special_font/result.ttf +++ b/srcs/special_font/result.ttf |
