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.
This commit is contained in:
Jules Aguillon 2022-11-13 00:24:23 +01:00
parent 815e30a505
commit 51b330c616
23 changed files with 75 additions and 64 deletions

View File

@ -12,8 +12,7 @@
<string name="pref_accents_e_none">Skrýt (univerzální) diakritická znaménka</string>
<string name="pref_autocapitalisation_title">Automatická kapitalizace</string>
<string name="pref_autocapitalisation_summary">Stiskne Shift na začátku věty</string>
<string name="pref_programming_layout_title">Rozložení klávesnice pro programování</string>
<string name="pref_programming_layout_none">Žádné</string>
<string name="pref_second_layout_none">Žádné</string>
<string name="pref_category_typing">Psaní</string>
<string name="pref_swipe_dist_title">Vzdálenost posunutí prstem</string>
<string name="pref_swipe_dist_summary">Jak daleko je třeba posunout prst pro napsaní znaku/diakritiky v rozích klávey (%s)</string>

View File

@ -14,9 +14,8 @@
<string name="pref_show_numpad_never">Nie</string>
<string name="pref_show_numpad_landscape">Nur im Querformat</string>
<string name="pref_show_numpad_always">Immer</string>
<string name="pref_programming_layout_title">Tastaturlayout zum Programmieren</string>
<string name="pref_extra_keys_title">Zusätzliche Zeichen zur Tastatur hinzufügen</string>
<string name="pref_programming_layout_none">Keines</string>
<string name="pref_second_layout_none">Keines</string>
<string name="pref_category_typing">Tippen</string>
<string name="pref_autocapitalisation_title">Automatische Großschreibung</string>
<string name="pref_autocapitalisation_summary">Shift-Taste am Satzanfang aktivieren</string>

View File

@ -12,8 +12,7 @@
<string name="pref_accents_e_none">Nascondi accenti</string>
<string name="pref_autocapitalisation_title">Maiuscole Automatiche</string>
<string name="pref_autocapitalisation_summary">Premi Shift all\'inizio di una frase</string>
<string name="pref_programming_layout_title">Layout tastiera per programmare</string>
<string name="pref_programming_layout_none">Nessuno</string>
<string name="pref_second_layout_none">Nessuno</string>
<string name="pref_category_typing">Digitando</string>
<string name="pref_swipe_dist_title">Distanza swipe</string>
<string name="pref_swipe_dist_summary">Distanza dei caratteri negli angoli dei tasti (%s)</string>

View File

@ -17,8 +17,7 @@
<string name="pref_autocapitalisation_title">Automātiski lielie burti</string>
<string name="pref_autocapitalisation_summary">Piespiest Shift teikuma sākumā</string>
<string name="pref_extra_keys_title">Pievienot tastatūrai taustiņus</string>
<string name="pref_programming_layout_title">Tastatūras izkārtojums programmēšanai</string>
<string name="pref_programming_layout_none">Neviens</string>
<string name="pref_second_layout_none">Neviens</string>
<string name="pref_category_typing">Rakstīšana</string>
<string name="pref_swipe_dist_title">Pavilkšanas attālums</string>
<string name="pref_swipe_dist_summary">Taustiņu stūros esošo rakstzīmju attālums (%s)</string>

View File

@ -12,8 +12,7 @@
<string name="pref_accents_e_none">Ocultar acentos</string>
<string name="pref_autocapitalisation_title">Maiusculização automática</string>
<string name="pref_autocapitalisation_summary">Aciona o shift no início de cada frase</string>
<string name="pref_programming_layout_title">Layout do teclado para programação</string>
<string name="pref_programming_layout_none">Nenhum</string>
<string name="pref_second_layout_none">Nenhum</string>
<string name="pref_category_typing">Digitação</string>
<string name="pref_swipe_dist_title">Distância a deslizar</string>
<string name="pref_swipe_dist_summary">Distância até acionar os cantos das teclas (%s)</string>

View File

@ -9,8 +9,7 @@
<string name="pref_accents_e_all_installed">Показывать акценты для всех установленных языков</string>
<string name="pref_accents_e_selected">Показывать акценты только для выбранного языка</string>
<string name="pref_accents_e_none">Скрыть акценты</string>
<string name="pref_programming_layout_title">Раскладка клавиатуры для программирования</string>
<string name="pref_programming_layout_none">Нету</string>
<string name="pref_second_layout_none">Нету</string>
<string name="pref_category_typing">Печатание</string>
<string name="pref_swipe_dist_title">Расстояние пролистывания</string>
<string name="pref_swipe_dist_summary">Расстояние между символами в углах клавиш (%s)</string>

View File

@ -10,8 +10,7 @@
<string name="pref_accents_e_all_installed">Yüklü tüm dillerin aksanlarını göster</string>
<string name="pref_accents_e_selected">Sadece seçili dilin aksanlarını göster</string>
<string name="pref_accents_e_none">Aksanları gizle</string>
<string name="pref_programming_layout_title">Programlama için klavye düzeni</string>
<string name="pref_programming_layout_none">Hiçbiri</string>
<string name="pref_second_layout_none">Hiçbiri</string>
<string name="pref_category_typing">Yazma</string>
<string name="pref_swipe_dist_title">Kaydırma mesafesi</string>
<string name="pref_swipe_dist_summary">Tuşların köşelerindeki karakterlerin uzaklıkları (%s)</string>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="pref_layout_values">
<item>system</item>
<item>none</item>
<item>azerty</item>
<item>qwerty</item>
<item>qwerty_pt</item>
@ -28,7 +28,7 @@
<item>hindi</item>
</string-array>
<string-array name="pref_layout_entries">
<item>@string/pref_layout_e_system</item>
<item>None</item>
<item>AZERTY</item>
<item>QWERTY</item>
<item>QWERTY (Brasileiro)</item>
@ -54,18 +54,6 @@
<item>বাংলা</item>
<item>हिन्दी</item>
</string-array>
<string-array name="pref_programming_layout_values">
<item>none</item>
<item>qwerty</item>
<item>dvorak</item>
<item>colemak</item>
</string-array>
<string-array name="pref_programming_layout_entries">
<item>@string/pref_programming_layout_none</item>
<item>QWERTY</item>
<item>Dvorak</item>
<item>Colemak</item>
</string-array>
<string-array name="pref_accents_entries">
<item>@string/pref_accents_e_all_installed</item>
<item>@string/pref_accents_e_selected</item>

View File

@ -3,4 +3,7 @@
<declare-styleable name="ExtraKeyCheckBoxPreference">
<attr name="index" format="integer"/>
</declare-styleable>
<declare-styleable name="LayoutListPreference">
<attr name="defaultString" format="string"/>
</declare-styleable>
</resources>

View File

@ -18,8 +18,8 @@
<string name="pref_autocapitalisation_title">Automatic capitalisation</string>
<string name="pref_autocapitalisation_summary">Press Shift at the beginning of a sentence</string>
<string name="pref_extra_keys_title">Add keys to the keyboard</string>
<string name="pref_programming_layout_title">Keyboard layout for programming</string>
<string name="pref_programming_layout_none">None</string>
<string name="pref_second_layout_title">Secondary layout</string>
<string name="pref_second_layout_none">None</string>
<string name="pref_category_typing">Typing</string>
<string name="pref_swipe_dist_title">Swiping distance</string>
<string name="pref_swipe_dist_summary">Distance of characters in the corners of the keys (%s)</string>

View File

@ -38,7 +38,7 @@
<row height="0.95">
<key width="1.8" key0="ctrl" key2="loc meta" key4="switch_numeric"/>
<key width="1.2" key0="fn" key1="loc alt" key2="change_method" key3="switch_emoji" key4="config"/>
<key width="4.0" key0="space" key1="switch_programming" key2="0" edgekeys="true"/>
<key width="4.0" key0="space" key1="switch_second" key2="0" edgekeys="true"/>
<key width="1.2" key1="up" key2="right" key3="left" key4="down" edgekeys="true"/>
<key width="1.8" key0="enter" key3="action"/>
</row>

View File

@ -2,7 +2,7 @@
<row height="0.95">
<key width="1.8" key0="ctrl" key1="loc switch_greekmath" key2="loc meta" key4="switch_numeric"/>
<key width="1.2" key0="fn" key1="loc alt" key2="change_method" key3="switch_emoji" key4="config"/>
<key width="4.0" key0="space" key1="switch_programming" edgekeys="true"/>
<key width="4.0" key0="space" key1="switch_second" edgekeys="true"/>
<key width="1.2" key1="up" key2="right" key3="left" key4="down" edgekeys="true"/>
<key width="1.8" key0="enter" key2="action"/>
</row>

View File

@ -41,7 +41,7 @@
<row height="0.95">
<key width="1.8" key0="ctrl" key2="loc meta" key4="switch_numeric"/>
<key width="1.2" key0="fn" key1="loc alt" key2="change_method" key3="switch_emoji" key4="config"/>
<key width="4.0" key0="space" key1="switch_programming" edgekeys="true"/>
<key width="4.0" key0="space" key1="switch_second" edgekeys="true"/>
<key width="1.2" key1="up" key2="right" key3="left" key4="down" edgekeys="true"/>
<key key0="j" key4=";"/>
<key width="1.8" key0="enter" key2="action"/>

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:title="@string/pref_category_layout">
<ListPreference android:key="layout" android:title="@string/pref_layout_title" android:summary="%s" android:defaultValue="system" android:entries="@array/pref_layout_entries" android:entryValues="@array/pref_layout_values"/>
<juloo.keyboard2.LayoutListPreference android:key="layout" android:title="@string/pref_layout_title" app:defaultString="@string/pref_layout_e_system"/>
<juloo.keyboard2.LayoutListPreference android:key="second_layout" android:title="@string/pref_second_layout_title" app:defaultString="@string/pref_second_layout_none"/>
<ListPreference android:key="accents" android:title="@string/pref_accents_title" android:summary="%s" android:defaultValue="1" android:entries="@array/pref_accents_entries" android:entryValues="@array/pref_accents_values"/>
<ListPreference android:key="show_numpad" android:title="@string/pref_show_numpad_title" android:summary="%s" android:defaultValue="1" android:entries="@array/pref_show_numpad_entries" android:entryValues="@array/pref_show_numpad_values"/>
<ListPreference android:key="programming_layout" android:title="@string/pref_programming_layout_title" android:summary="%s" android:defaultValue="none" android:entries="@array/pref_programming_layout_entries" android:entryValues="@array/pref_programming_layout_values"/>
<PreferenceScreen android:title="@string/pref_extra_keys_title">
<juloo.keyboard2.ExtraKeyCheckBoxPreference app:index="0"/>
<juloo.keyboard2.ExtraKeyCheckBoxPreference app:index="1"/>

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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;
}
});

View File

@ -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");
}
}

View File

@ -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>

Before

Width:  |  Height:  |  Size: 651 B

After

Width:  |  Height:  |  Size: 364 B

2
srcs/special_font/13.svg Normal file
View File

@ -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>

After

Width:  |  Height:  |  Size: 433 B

2
srcs/special_font/14.svg Normal file
View File

@ -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>

After

Width:  |  Height:  |  Size: 473 B

Binary file not shown.