diff options
Diffstat (limited to 'srcs/juloo.keyboard2/Config.java')
| -rw-r--r-- | srcs/juloo.keyboard2/Config.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 4684194..fdc7730 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -348,6 +348,7 @@ final class Config public static void initGlobalConfig(SharedPreferences prefs, Resources res, IKeyEventHandler handler) { + migrate(prefs); _globalConfig = new Config(prefs, res, handler); } @@ -360,4 +361,45 @@ final class Config { public void key_up(KeyValue value, Pointers.Modifiers flags); } + + /** Config migrations. */ + + private static int CONFIG_VERSION = 1; + + public static void migrate(SharedPreferences prefs) + { + int saved_version = prefs.getInt("version", 0); + Logs.debug_config_migration(saved_version, CONFIG_VERSION); + if (saved_version == CONFIG_VERSION) + return; + SharedPreferences.Editor e = prefs.edit(); + e.putInt("version", CONFIG_VERSION); + // Migrations might run on an empty [prefs] for new installs, in this case + // they set the default values of complex options. + switch (saved_version) // Fallback switch + { + case 0: + // Primary, secondary and custom layout options are merged into the new + // Layouts option. This also sets the default value. + List<LayoutsPreference.Layout> l = new ArrayList<LayoutsPreference.Layout>(); + l.add(migrate_layout(prefs.getString("layout", "system"))); + String snd_layout = prefs.getString("second_layout", "none"); + if (snd_layout != null && !snd_layout.equals("none")) + l.add(migrate_layout(snd_layout)); + String custom_layout = prefs.getString("custom_layout", ""); + if (custom_layout != null && !custom_layout.equals("")) + l.add(new LayoutsPreference.CustomLayout(custom_layout)); + LayoutsPreference.save_to_preferences(e, l); + case 1: + default: break; + } + e.commit(); + } + + private static LayoutsPreference.Layout migrate_layout(String name) + { + if (name == null || name.equals("system")) + return new LayoutsPreference.SystemLayout(); + return new LayoutsPreference.NamedLayout(name); + } } |
