From 51b330c6168a8b0e0c16482254d4674fbe5476c7 Mon Sep 17 00:00:00 2001
From: Jules Aguillon
Date: Sun, 13 Nov 2022 00:24:23 +0100
Subject: 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.
---
srcs/juloo.keyboard2/Config.java | 19 +++++++++----------
srcs/juloo.keyboard2/KeyEventHandler.java | 7 ++++---
srcs/juloo.keyboard2/KeyValue.java | 6 ++++--
srcs/juloo.keyboard2/Keyboard2.java | 16 ++++++++--------
srcs/juloo.keyboard2/LayoutListPreference.java | 25 +++++++++++++++++++++++++
srcs/special_font/09.svg | 8 ++------
srcs/special_font/13.svg | 2 ++
srcs/special_font/14.svg | 2 ++
srcs/special_font/result.ttf | Bin 7460 -> 7900 bytes
9 files changed, 56 insertions(+), 29 deletions(-)
create mode 100644 srcs/juloo.keyboard2/LayoutListPreference.java
create mode 100644 srcs/special_font/13.svg
create mode 100644 srcs/special_font/14.svg
(limited to 'srcs')
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 @@
-
-
-
-
+
+
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 @@
+
+
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 @@
+
+
diff --git a/srcs/special_font/result.ttf b/srcs/special_font/result.ttf
index f81838f..31a4892 100644
Binary files a/srcs/special_font/result.ttf and b/srcs/special_font/result.ttf differ
--
cgit v1.2.3