From 38a708821a136d0e1df6d82ac9fb3bc9bcc4d571 Mon Sep 17 00:00:00 2001 From: ErikWaegerle Date: Mon, 29 Jun 2020 15:25:19 +0200 Subject: [PATCH] Adjusting the Settings Activity Implementation of the case distinction for manual modification of the Dark Theme. It is possible to adjust the Dark Theme according to battery status or system settings. --- .../ui/SettingsActivity.java | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/SettingsActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/SettingsActivity.java index dc7da54..f6c20fd 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/SettingsActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/SettingsActivity.java @@ -59,31 +59,39 @@ public class SettingsActivity extends AppCompatPreferenceActivity { SharedPreferences.OnSharedPreferenceChangeListener x = new SharedPreferences.OnSharedPreferenceChangeListener() { + + public void recheckNightModeProperties(SharedPreferences sharedPreferences){ + if (sharedPreferences.getBoolean("pref_dark_mode_setting", false )) { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); + restartActivity(); + + } else if (sharedPreferences.getBoolean("pref_dark_mode_automatically_by_system", false)) { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); + restartActivity(); + } else if(sharedPreferences.getBoolean("pref_dark_mode_automatically_by_battery", false)){ + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY); + restartActivity(); + } else { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); + restartActivity(); + } + + } @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - - System.out.println(key); - if (key.equals("pref_dark_mode_setting")) { - if (sharedPreferences.getBoolean(key, false )) { - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); - restartActivity(); - } else { - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); - restartActivity(); - } - + if (key.equals("pref_dark_mode_setting")|| key.equals("pref_dark_mode_automatically_by_system")||key.equals("pref_dark_mode_automatically_by_battery")) { + recheckNightModeProperties(sharedPreferences); } } }; - // Listener registrieren preferenceManager.registerOnSharedPreferenceChangeListener(x); } public void restartActivity() { Intent i = new Intent(getApplicationContext(), MainActivity.class); - startActivity(i); finish(); + startActivity(i); } private void setupActionBar () {