From e51eff40503a9715a98f7d1fb41c3a607b8f67d0 Mon Sep 17 00:00:00 2001 From: Thialfihar Date: Thu, 25 Jun 2015 15:17:32 +0200 Subject: Add theme setting This prepares that different themes can be added. Currently light and dark will just use the default OK theme. --- .../keychain/ui/SettingsActivity.java | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java') 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 bcf42ba74..27ce3ac56 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -53,6 +53,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { public static final String ACTION_PREFS_CLOUD = "org.sufficientlysecure.keychain.ui.PREFS_CLOUD"; public static final String ACTION_PREFS_ADV = "org.sufficientlysecure.keychain.ui.PREFS_ADV"; public static final String ACTION_PREFS_PROXY = "org.sufficientlysecure.keychain.ui.PREFS_PROXY"; + public static final String ACTION_PREFS_GUI = "org.sufficientlysecure.keychain.ui.PREFS_GUI"; public static final int REQUEST_CODE_KEYSERVER_PREF = 0x00007005; @@ -106,6 +107,10 @@ public class SettingsActivity extends AppCompatPreferenceActivity { initializeUseNumKeypadForYubiKeyPin( (CheckBoxPreference) findPreference(Constants.Pref.USE_NUMKEYPAD_FOR_YUBIKEY_PIN)); + } else if (action != null && action.equals(ACTION_PREFS_GUI)) { + addPreferencesFromResource(R.xml.gui_preferences); + + initializeTheme((ListPreference) findPreference(Constants.Pref.THEME)); } } @@ -425,14 +430,30 @@ public class SettingsActivity extends AppCompatPreferenceActivity { mUseTor.setEnabled(true); } } + } + + /** + * This fragment shows gui preferences. + */ + public static class GuiPrefsFragment extends PreferenceFragment { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.gui_preferences); + + initializeTheme((ListPreference) findPreference(Constants.Pref.THEME)); + } } - @TargetApi(Build.VERSION_CODES.KITKAT) protected boolean isValidFragment(String fragmentName) { return AdvancedPrefsFragment.class.getName().equals(fragmentName) || CloudSearchPrefsFragment.class.getName().equals(fragmentName) || ProxyPrefsFragment.class.getName().equals(fragmentName) + || GuiPrefsFragment.class.getName().equals(fragmentName) || super.isValidFragment(fragmentName); } @@ -461,6 +482,19 @@ public class SettingsActivity extends AppCompatPreferenceActivity { }); } + private static void initializeTheme(final ListPreference mTheme) { + mTheme.setValue(sPreferences.getTheme()); + mTheme.setSummary(mTheme.getEntry()); + mTheme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + public boolean onPreferenceChange(Preference preference, Object newValue) { + mTheme.setValue((String) newValue); + mTheme.setSummary(mTheme.getEntry()); + sPreferences.setTheme((String) newValue); + return false; + } + }); + } + private static void initializeSearchKeyserver(final CheckBoxPreference mSearchKeyserver) { Preferences.CloudSearchPrefs prefs = sPreferences.getCloudSearchPrefs(); mSearchKeyserver.setChecked(prefs.searchKeyserver); -- cgit v1.2.3