Adjusting the SettingsActivity
Case discrimination with AppCompatDelegate to cover both cases.
This commit is contained in:
parent
650bd797ba
commit
1106ee84bb
1 changed files with 42 additions and 5 deletions
|
@ -3,6 +3,8 @@ package org.secuso.privacyfriendlysudoku.ui;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -10,14 +12,19 @@ import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
|
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.Switch;
|
||||||
|
|
||||||
import org.secuso.privacyfriendlysudoku.ui.view.R;
|
import org.secuso.privacyfriendlysudoku.ui.view.R;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link PreferenceActivity} that presents a set of application settings. On
|
* A {@link PreferenceActivity} that presents a set of application settings. On
|
||||||
|
@ -43,12 +50,43 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||||
mainContent.setAlpha(0);
|
mainContent.setAlpha(0);
|
||||||
mainContent.animate().alpha(1).setDuration(BaseActivity.MAIN_CONTENT_FADEIN_DURATION);
|
mainContent.animate().alpha(1).setDuration(BaseActivity.MAIN_CONTENT_FADEIN_DURATION);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the {@link android.app.ActionBar}, if the API is available.
|
* Set up the {@link android.app.ActionBar}, if the API is available.
|
||||||
*/
|
*/
|
||||||
private void setupActionBar() {
|
|
||||||
|
SharedPreferences preferenceManager = PreferenceManager
|
||||||
|
.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
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 )) {
|
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
||||||
|
restartActivity();
|
||||||
|
} else {
|
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
||||||
|
restartActivity();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Listener registrieren
|
||||||
|
preferenceManager.registerOnSharedPreferenceChangeListener(x);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void restartActivity() {
|
||||||
|
Intent i = new Intent(getApplicationContext(), MainActivity.class);
|
||||||
|
startActivity(i);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupActionBar () {
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
// Show the Up button in the action bar.
|
// Show the Up button in the action bar.
|
||||||
|
@ -69,7 +107,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||||
return super.onMenuItemSelected(featureId, item);
|
return super.onMenuItemSelected(featureId, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue