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.
This commit is contained in:
Jules Aguillon 2023-07-29 18:37:06 +02:00
parent 818aa4c7d5
commit dad5f57a03
28 changed files with 172 additions and 85 deletions

View File

@ -50,8 +50,8 @@ def check_layout(layout):
bottom_row_keys = [
"ctrl", "fn", "switch_numeric", "change_method", "switch_emoji",
"config", "switch_second", "enter", "action", "left", "up", "right",
"down", "space"
"config", "switch_forward", "switch_backward", "enter", "action",
"left", "up", "right", "down", "space"
]
if root.get("bottom_row") == "false":

View File

@ -54,10 +54,10 @@ def generate_arrays(out, layouts):
item.text = s
elem.append(item)
return elem
none_item = [ ("none", "None") ]
none_item = [ ("system", "@string/pref_layout_e_system") ]
custom_item = [ ("custom", "@string/pref_layout_e_custom") ]
values_items, entries_items = zip(*(none_item + layouts + custom_item)) # unzip
ids_items = map(lambda s: "@xml/%s" % s if s not in ["none", "custom"] else "-1", values_items)
ids_items = map(lambda s: "@xml/%s" % s if s not in ["system", "custom"] else "-1", values_items)
root = XML.Element("resources")
root.append(XML.Comment(text="DO NOT EDIT. This file is generated, see gen_layouts.py."))
root.append(mk_array("string-array", "pref_layout_values", values_items))

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:minHeight="?android:attr/listPreferredItemHeightSmall">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/pref_layouts_add" android:textAppearance="?android:attr/textAppearanceListItemSmall"/>
</LinearLayout>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">Upravit průhlednost pozadí klávesnice</string>
<string name="pref_key_opacity">Upravit průhlednost kláves</string>
<string name="pref_key_activated_opacity">Upravit průhlednost stisknutých kláves</string>
<string name="pref_layout_title">Změnit rozvržení klávesnice</string>
<string name="pref_layout_e_system">Dle nastavení systému</string>
<string name="pref_layout_e_custom">Vlastní rozvržení</string>
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">(Univerzální) Diakritická znaménka</string>
<string name="pref_accents_e_all_installed">Zobrazovat znaménka pro všechny instalované systémové jazyky</string>
<string name="pref_accents_e_selected">Zobrazovat znaménka pouze pro současně zvolený jazyk</string>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">Deckkraft des Tastaturhintergrunds anpassen</string>
<string name="pref_key_opacity">Deckkraft der Tasten anpassen</string>
<string name="pref_key_activated_opacity">Deckkraft gedrückter Tasten anpassen</string>
<string name="pref_layout_title">Tastaturlayout ändern</string>
<string name="pref_layout_e_system">Systemeinstellung</string>
<string name="pref_layout_e_custom">Eigenes Layout</string>
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">Akzente</string>
<string name="pref_accents_e_all_installed">Akzente für alle installierten Sprachen anzeigen</string>
<string name="pref_accents_e_selected">Akzente nur für die gewählte Sprache anzeigen</string>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">Ajustar opacidad del fondo del teclado</string>
<string name="pref_key_opacity">Ajustar opacidad de teclas</string>
<string name="pref_key_activated_opacity">Ajustar opacidad de teclas apretadas</string>
<string name="pref_layout_title">Cambiar formato de teclado</string>
<string name="pref_layout_e_system">Ajustes del sistema</string>
<string name="pref_layout_e_custom">Formato personalizado</string>
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">Acentos</string>
<string name="pref_accents_e_all_installed">Mostrar acentos para todos los lenguajes instalados</string>
<string name="pref_accents_e_selected">Solo mostrar acentos para el lenguaje seleccionado</string>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">تنظیم کدر بودن پس‌زمینه صفحه کلید</string>
<string name="pref_key_opacity">تنظیم کدر بودن کلید</string>
<string name="pref_key_activated_opacity">تنظیم کدر بودن کلید فشرده شده</string>
<string name="pref_layout_title">تغییر طرح صفحه کلید</string>
<string name="pref_layout_e_system">تنظیمات سامانه</string>
<string name="pref_layout_e_custom">طرح صفارشی</string>
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">لهجه‌ها</string>
<string name="pref_accents_e_all_installed">نمایش لهجه‌ها برای تمام زبان‌هی نصب شده</string>
<string name="pref_accents_e_selected">فقط نمایش لهجه‌ها برای زبان‌های انتخاب شده</string>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">Transparence du clavier</string>
<string name="pref_key_opacity">Transparence des touches</string>
<string name="pref_key_activated_opacity">Transparence des touches pressées</string>
<string name="pref_layout_title">Disposition des touches</string>
<string name="pref_layout_e_system">Paramètre système</string>
<string name="pref_layout_e_custom">Disposition personnalisée</string>
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">Accents</string>
<string name="pref_accents_e_all_installed">Afficher les accents pour les langues installées</string>
<string name="pref_accents_e_selected">Afficher les accents pour la langue sélectionnée</string>

View File

@ -10,9 +10,10 @@
<!-- <string name="pref_keyboard_opacity">Adjust keyboard background opacity</string> -->
<!-- <string name="pref_key_opacity">Adjust key opacity</string> -->
<!-- <string name="pref_key_activated_opacity">Adjust pressed key opacity</string> -->
<string name="pref_layout_title">Cambia layout tastiera</string>
<string name="pref_layout_e_system">Impostazioni di sistema</string>
<!-- <string name="pref_layout_e_custom">Custom layout</string> -->
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">Accenti</string>
<string name="pref_accents_e_all_installed">Mostra accenti per tutte le lingue installate</string>
<string name="pref_accents_e_selected">Mostra accenti solo per le lingue selezionate</string>

View File

@ -10,9 +10,10 @@
<!-- <string name="pref_keyboard_opacity">Adjust keyboard background opacity</string> -->
<!-- <string name="pref_key_opacity">Adjust key opacity</string> -->
<!-- <string name="pref_key_activated_opacity">Adjust pressed key opacity</string> -->
<string name="pref_layout_title">키보드 레이아웃 변경</string>
<string name="pref_layout_e_system">시스템 세팅</string>
<!-- <string name="pref_layout_e_custom">Custom layout</string> -->
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">악센트</string>
<string name="pref_accents_e_all_installed">설치된 모든 언어의 악센트 표시</string>
<string name="pref_accents_e_selected">선택한 언어의 악센트만 표시</string>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">Pielāgot tastatūras fona necaurredzamību</string>
<string name="pref_key_opacity">Pielāgot taustiņu necaurredzamību</string>
<string name="pref_key_activated_opacity">Pielāgot piespiesta taustiņa necaurredzamību</string>
<string name="pref_layout_title">Mainīt tastatūras izkārtojumu</string>
<string name="pref_layout_e_system">Ierīces iestatījumi</string>
<string name="pref_layout_e_custom">Pielāgots izkārtojums</string>
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">Uzsvara zīmes</string>
<string name="pref_accents_e_all_installed">Rādīt uzsvara zīmes visām uzstādītajām valodām</string>
<string name="pref_accents_e_selected">Rādīt uzsvara zīmes tikai atlasītajām valodām</string>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">Nieprzezroczystość tła klawiatury</string>
<string name="pref_key_opacity">Nieprzezroczystość klawisza</string>
<string name="pref_key_activated_opacity">Nieprzezroczystość naciśniętego klawisza</string>
<string name="pref_layout_title">Zmień układ klawiatury</string>
<string name="pref_layout_e_system">Systemowy</string>
<string name="pref_layout_e_custom">Własny układ</string>
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">Znaki diakrytyczne</string>
<string name="pref_accents_e_all_installed">Pokaż znaki diakryt. dla wszystkich zainstalowanych języków</string>
<string name="pref_accents_e_selected">Pokaż znaki diakryt. tylko dla wybranego języka</string>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">Ajustar opacidade do fundo do teclado</string>
<string name="pref_key_opacity">Ajustar opacidade das teclas</string>
<string name="pref_key_activated_opacity">Ajustar opacidade das teclas pressionadas</string>
<string name="pref_layout_title">Mudar layout do teclado</string>
<string name="pref_layout_e_system">Mesmo do sistema</string>
<string name="pref_layout_e_custom">Layout personalizado</string>
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">Acentos</string>
<string name="pref_accents_e_all_installed">Mostrar acentos para todos os idiomas instalados</string>
<string name="pref_accents_e_selected">Mostrar acentos só para o idioma selecionado</string>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">Modifică opacitatea fundalului tastaturii</string>
<string name="pref_key_opacity">Modifică opacitatea tastelor</string>
<string name="pref_key_activated_opacity">Modifică opacitatea tastei apăsate</string>
<string name="pref_layout_title">Schimbă aranjamentul tastaturii</string>
<string name="pref_layout_e_system">Setări de Sistem</string>
<string name="pref_layout_e_custom">Aranjament personalizat</string>
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">Accente</string>
<string name="pref_accents_e_all_installed">Arată accentele pentru toate limbile instalate</string>
<string name="pref_accents_e_selected">Aratp accentele doar pentru limba selectată</string>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">Изменить прозрачность фона</string>
<string name="pref_key_opacity">Изменить прозрачность клавиш</string>
<string name="pref_key_activated_opacity">Изменить прозрачность нажатой клавиши</string>
<string name="pref_layout_title">Изменить раскладку клавиатуры</string>
<string name="pref_layout_e_system">Системные настройки</string>
<string name="pref_layout_e_custom">Пользовательская раскладка</string>
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">Акцент</string>
<string name="pref_accents_e_all_installed">Показывать акценты для всех установленных языков</string>
<string name="pref_accents_e_selected">Показывать акценты только для выбранного языка</string>

View File

@ -10,9 +10,10 @@
<!-- <string name="pref_keyboard_opacity">Adjust keyboard background opacity</string> -->
<!-- <string name="pref_key_opacity">Adjust key opacity</string> -->
<!-- <string name="pref_key_activated_opacity">Adjust pressed key opacity</string> -->
<string name="pref_layout_title">Klavye Düzenini Değiştir</string>
<string name="pref_layout_e_system">Sistem Ayarları</string>
<!-- <string name="pref_layout_e_custom">Custom layout</string> -->
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">Aksanlar</string>
<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>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">Tùy chỉnh độ trong suốt của bàn phím</string>
<string name="pref_key_opacity">Tùy chỉnh độ trong suốt của phím</string>
<string name="pref_key_activated_opacity">Tùy chỉnh độ trong suốt của phím khi nhấn</string>
<string name="pref_layout_title">Thay đổi bố cục bàn phím</string>
<string name="pref_layout_e_system">Hệ thống</string>
<string name="pref_layout_e_custom">Tùy chỉnh bố cục</string>
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">Dấu phụ</string>
<string name="pref_accents_e_all_installed">Hiển thị cho các ngôn ngữ đã cài đặt</string>
<string name="pref_accents_e_selected">Chỉ hiển thị cho các ngôn ngữ đã chọn</string>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">调整键盘背景透明度</string>
<string name="pref_key_opacity">调整按键透明度</string>
<string name="pref_key_activated_opacity">调整按下的按键的透明度</string>
<string name="pref_layout_title">改变键盘布局</string>
<string name="pref_layout_e_system">系统设置</string>
<string name="pref_layout_e_custom">自定义布局</string>
<!-- <string name="pref_layouts_add">Add an alternate layout</string> -->
<!-- <string name="pref_layouts_item">Layout %1$d: %2$s</string> -->
<string name="pref_accents_title">声调</string>
<string name="pref_accents_e_all_installed">显示所有安装的语言的声调符号</string>
<string name="pref_accents_e_selected">只显示选择的语言的声调符号</string>

View File

@ -2,7 +2,7 @@
<resources>
<!--DO NOT EDIT. This file is generated, see gen_layouts.py.-->
<string-array name="pref_layout_values">
<item>none</item>
<item>system</item>
<item>latn_qwerty_us</item>
<item>latn_colemak</item>
<item>latn_dvorak</item>
@ -43,7 +43,7 @@
<item>custom</item>
</string-array>
<string-array name="pref_layout_entries">
<item>None</item>
<item>@string/pref_layout_e_system</item>
<item>QWERTY (US)</item>
<item>Colemak</item>
<item>Dvorak</item>

View File

@ -10,9 +10,10 @@
<string name="pref_keyboard_opacity">Adjust keyboard background opacity</string>
<string name="pref_key_opacity">Adjust key opacity</string>
<string name="pref_key_activated_opacity">Adjust pressed key opacity</string>
<string name="pref_layout_title">Change keyboard layout</string>
<string name="pref_layout_e_system">System settings</string>
<string name="pref_layout_e_custom">Custom layout</string>
<string name="pref_layouts_add">Add an alternate layout</string>
<string name="pref_layouts_item">Layout %1$d: %2$s</string>
<string name="pref_accents_title">Accents</string>
<string name="pref_accents_e_all_installed">Show accents for all installed languages</string>
<string name="pref_accents_e_selected">Only show accents for the selected language</string>

View File

@ -2,7 +2,7 @@
<row height="0.95">
<key width="1.7" key0="ctrl" key1="loc switch_greekmath" key2="loc meta" key4="switch_numeric"/>
<key width="1.1" key0="fn" key1="loc alt" key2="change_method" key3="switch_emoji" key4="config"/>
<key width="4.4" key0="space" key7="switch_second" key5="left" key6="right" slider="true"/>
<key width="4.4" key0="space" key7="switch_forward" key8="switch_backward" key5="left" key6="right" slider="true"/>
<key width="1.1" key0="loc voice_typing" key7="up" key6="right" key5="left" key8="down"/>
<key width="1.7" key0="enter" key2="action"/>
</row>

View File

@ -39,7 +39,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" key7="switch_second" key8="0"/>
<key width="4.0" key0="space" key7="switch_forward" key8="0"/>
<key width="1.2" key7="up" key6="right" key5="left" key8="down"/>
<key width="1.8" key0="enter" key3="action"/>
</row>

View File

@ -42,7 +42,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" key7="switch_second"/>
<key width="4.0" key0="space" key7="switch_second" key8="switch_backward"/>
<key width="1.2" key7="up" key6="right" key5="left" key8="down"/>
<key key0="j" key4=";"/>
<key width="1.8" key0="enter" key2="action"/>

View File

@ -1,8 +1,7 @@
<?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">
<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"/>
<juloo.keyboard2.LayoutsPreference/>
<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"/>
<CheckBoxPreference android:key="number_row" android:title="@string/pref_number_row_title" android:summary="@string/pref_number_row_summary" android:defaultValue="false"/>

View File

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

View File

@ -15,8 +15,8 @@ final class KeyValue
CHANGE_METHOD,
CHANGE_METHOD_PREV,
ACTION,
SWITCH_SECOND,
SWITCH_SECOND_BACK,
SWITCH_FORWARD,
SWITCH_BACKWARD,
SWITCH_GREEKMATH,
CAPS_LOCK,
SWITCH_VOICE_TYPING,
@ -346,8 +346,8 @@ final class KeyValue
case "switch_numeric": return eventKey("123+", Event.SWITCH_NUMERIC, FLAG_SMALLER_FONT);
case "switch_emoji": return eventKey(0x01, Event.SWITCH_EMOJI, FLAG_SMALLER_FONT);
case "switch_back_emoji": return eventKey("ABC", Event.SWITCH_BACK_EMOJI, 0);
case "switch_second": return eventKey(0x13, Event.SWITCH_SECOND, FLAG_SMALLER_FONT);
case "switch_second_back": return eventKey(0x14, Event.SWITCH_SECOND_BACK, FLAG_SMALLER_FONT);
case "switch_forward": return eventKey(0x13, Event.SWITCH_FORWARD, FLAG_SMALLER_FONT);
case "switch_backward": return eventKey(0x14, Event.SWITCH_BACKWARD, FLAG_SMALLER_FONT);
case "switch_greekmath": return eventKey("πλ∇¬", Event.SWITCH_GREEKMATH, FLAG_SMALLER_FONT);
case "change_method": return eventKey(0x09, Event.CHANGE_METHOD, FLAG_SMALLER_FONT);
case "change_method_prev": return eventKey(0x09, Event.CHANGE_METHOD_PREV, FLAG_SMALLER_FONT);

View File

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

View File

@ -0,0 +1,89 @@
package juloo.keyboard2;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class LayoutsPreference extends ListGroupPreference
{
static final String KEY = "layouts";
static final List<String> DEFAULT = Collections.singletonList("system");
/** Layout names as stored in the preferences. */
String[] _layout_names;
/** Text displayed for each layout in the dialog list. */
String[] _layout_display_names;
public LayoutsPreference(Context ctx, AttributeSet attrs)
{
super(ctx, attrs);
setKey(KEY);
Resources res = ctx.getResources();
_layout_names = res.getStringArray(R.array.pref_layout_values);
_layout_display_names = res.getStringArray(R.array.pref_layout_entries);
}
public static List<String> load_from_preferences(SharedPreferences prefs)
{
return load_from_preferences(KEY, prefs, DEFAULT);
}
@Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue)
{
super.onSetInitialValue(restoreValue, defaultValue);
if (_values.size() == 0)
set_values(new ArrayList<String>(DEFAULT), false);
}
@Override
String label_of_value(String value, int i)
{
return getContext().getString(R.string.pref_layouts_item, i + 1, value);
}
@Override
AddButton on_attach_add_button(AddButton prev_btn)
{
if (prev_btn == null)
return new LayoutsAddButton(getContext());
return prev_btn;
}
@Override
boolean should_allow_remove_item()
{
return (_values.size() > 1);
}
void select(final SelectionCallback callback)
{
ArrayAdapter layouts = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_1, _layout_display_names);
new AlertDialog.Builder(getContext())
.setView(R.layout.custom_extra_key_add_dialog)
.setAdapter(layouts, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which)
{
callback.select(_layout_names[which]);
}
})
.show();
}
class LayoutsAddButton extends AddButton
{
public LayoutsAddButton(Context ctx)
{
super(ctx);
setLayoutResource(R.layout.pref_layouts_add_btn);
}
}
}