From 500f4e41d3a72f5865aa489c89ad11b947fa54b7 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 10 Aug 2023 12:57:31 +0200 Subject: Allow multiple custom layouts This merges the "Layouts" option with the "Custom layout" option. A custom layout becomes an item in the "Layouts" list among the other layouts. It's possible to add several custom layouts. Selecting the "Custom layout" item in the list opens a second dialog for entering the layout description. Layouts are serialized as JSON object and are decoded solely in the LayoutsPreference class. --- srcs/juloo.keyboard2/Config.java | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) (limited to 'srcs/juloo.keyboard2/Config.java') diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 24565ab..4684194 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -3,7 +3,6 @@ package juloo.keyboard2; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; -import android.content.res.TypedArray; import android.os.Build; import android.util.DisplayMetrics; import android.util.TypedValue; @@ -28,7 +27,6 @@ final class Config // From preferences /** [null] represent the [system] layout. */ public List layouts; - public KeyboardData custom_layout; // Might be 'null' public boolean show_numpad = false; // From the 'numpad_layout' option, also apply to the numeric pane. public boolean inverse_numpad = false; @@ -114,11 +112,7 @@ final class Config { keyboardHeightPercent = _prefs.getInt("keyboard_height", 35); } - List layout_names = LayoutsPreference.load_from_preferences(_prefs); - layouts = new ArrayList(); - for (String l : layout_names) - layouts.add(layout_of_string(res, l)); - custom_layout = KeyboardData.load_string(_prefs.getString("custom_layout", "")); + layouts = LayoutsPreference.load_from_preferences(res, _prefs); inverse_numpad = _prefs.getString("numpad_layout", "default").equals("low_first"); number_row = _prefs.getBoolean("number_row", false); // The baseline for the swipe distance correspond to approximately the @@ -335,36 +329,6 @@ final class Config } } - /** Obtained from XML. */ - static List layout_ids_str = null; - static TypedArray layout_ids_res = null; - - /** Might return [null] if the selected layout is "system", "custom" or if - the name is not recognized. */ - public KeyboardData layout_of_string(Resources res, String name) - { - if (layout_ids_str == null) - { - layout_ids_str = Arrays.asList(res.getStringArray(R.array.pref_layout_values)); - layout_ids_res = res.obtainTypedArray(R.array.layout_ids); - } - int i = layout_ids_str.indexOf(name); - if (i >= 0) - { - int id = layout_ids_res.getResourceId(i, 0); - if (id > 0) - return KeyboardData.load(res, id); - // Fallthrough - } - switch (name) - { - case "custom": return custom_layout; - case "system": - case "none": - default: return null; - } - } - char inverse_numpad_char(char c) { switch (c) -- cgit v1.2.3