From 76aa34300c16d1eba59115d9502d92c65e4117b0 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Sun, 7 Jun 2015 21:40:27 +0530 Subject: [PATCH] fixed prefs --- .../keychain/ui/SettingsActivity.java | 3 +++ .../sufficientlysecure/keychain/util/Preferences.java | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index 1d0bac1cf..3c1af1918 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -279,6 +279,9 @@ public class SettingsActivity extends PreferenceActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + // makes android's preference framework write to our file instead of default + // This allows us to use the "persistent" attribute to simplify code + sPreferences.setPreferenceManagerFileAndMode(getPreferenceManager()); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.proxy_prefs); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java index 4aaf8b17b..48840ae71 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; +import android.preference.PreferenceManager; import info.guardianproject.onionkit.ui.OrbotHelper; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants.Pref; @@ -42,6 +43,9 @@ public class Preferences { private SharedPreferences mSharedPreferences; private Resources mResources; + private static String PREF_FILE_NAME = "APG.main"; + private static int PREF_FILE_MODE = Context.MODE_MULTI_PROCESS; + public static synchronized Preferences getPreferences(Context context) { return getPreferences(context, false); } @@ -61,9 +65,14 @@ public class Preferences { updateSharedPreferences(context); } + public void setPreferenceManagerFileAndMode(PreferenceManager manager) { + manager.setSharedPreferencesName(PREF_FILE_NAME); + manager.setSharedPreferencesMode(PREF_FILE_MODE); + } + public void updateSharedPreferences(Context context) { // multi-process safe preferences - mSharedPreferences = context.getSharedPreferences("APG.main", Context.MODE_MULTI_PROCESS); + mSharedPreferences = context.getSharedPreferences(PREF_FILE_NAME, PREF_FILE_MODE); } public String getLanguage() {