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.
This commit is contained in:
ErikWaegerle 2020-06-29 15:25:19 +02:00
parent eb78716249
commit 38a708821a

View file

@ -59,31 +59,39 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
SharedPreferences.OnSharedPreferenceChangeListener x = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
System.out.println(key);
if (key.equals("pref_dark_mode_setting")) {
if (sharedPreferences.getBoolean(key, false )) {
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) {
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 () {