Add: Dark Theme

This commit is contained in:
machiav3lli 2020-06-26 20:49:41 +02:00
commit 736197f289
5 changed files with 51 additions and 0 deletions

View file

@ -22,6 +22,7 @@ public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setDayNightTheme(PreferenceManager.getDefaultSharedPreferences(this).getInt("theme", AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM));
super.onCreate(savedInstanceState);
Intent mainIntent = null;
@ -40,4 +41,17 @@ public class SplashActivity extends AppCompatActivity {
SplashActivity.this.finish();
}
private void setDayNightTheme(int theme) {
switch (theme) {
case AppCompatDelegate.MODE_NIGHT_NO:
setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
break;
case AppCompatDelegate.MODE_NIGHT_YES:
setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
break;
default:
setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}
}
}

View file

@ -27,7 +27,9 @@ import org.secuso.aktivpause.activities.SettingsActivity;
import org.secuso.aktivpause.activities.TimerActivity;
import org.secuso.aktivpause.activities.tutorial.TutorialActivity;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode;
/**
*
@ -168,6 +170,29 @@ public abstract class BaseActivity extends AppCompatActivity implements OnNaviga
//intent.putExtra( PreferenceActivity.EXTRA_NO_HEADERS, true );
createBackStack(intent);
break;
case R.id.nav_theme:
new AlertDialog.Builder(this)
.setTitle(R.string.title_theme)
.setPositiveButton(R.string.follow_system, (dialog, which) -> {
mSharedPreferences.edit().putInt("theme",AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM).apply();
setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
Intent thisIntent = new Intent(this, getClass());
createBackStack(thisIntent);
})
.setNegativeButton(R.string.dark, (dialog, which) -> {
mSharedPreferences.edit().putInt("theme",AppCompatDelegate.MODE_NIGHT_YES).apply();
setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
Intent thisIntent = new Intent(this, getClass());
createBackStack(thisIntent);
})
.setNeutralButton(R.string.light, (dialog, which) -> {
mSharedPreferences.edit().putInt("theme",AppCompatDelegate.MODE_NIGHT_NO).apply();
setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
Intent thisIntent = new Intent(this, getClass());
createBackStack(thisIntent);
})
.show();
break;
default:
}
overridePendingTransition(0,0);

View file

@ -22,6 +22,10 @@
android:id="@+id/nav_settings"
android:icon="@drawable/ic_settings_24"
android:title="@string/title_activity_settings" />
<item
android:id="@+id/nav_theme"
android:icon="@drawable/ic_theme_24"
android:title="@string/title_theme" />
<item
android:id="@+id/nav_help"
android:icon="@drawable/ic_help"

View file

@ -176,5 +176,9 @@
<string name="dialog_evaluation_title">Online-Befragung</string>
<string name="dialog_evaluation_yes">Ja</string>
<string name="menu_display_evaluation_dialog">Online-Befragung</string>
<string name="title_theme">Theme</string>
<string name="follow_system">Standard</string>
<string name="dark">Dunkel</string>
<string name="light">Hell</string>
</resources>

View file

@ -59,6 +59,10 @@
<string name="set_contains_no_exercises">This set contains no exercises.</string>
<string name="take_a_break_now">Take a break now! Click here to do your chosen exercises.</string>
<string name="title_activity_settings">Settings</string>
<string name="title_theme">Theme</string>
<string name="follow_system">Standard</string>
<string name="dark">Dark Theme</string>
<string name="light">Light Theme</string>
<string name="no_exercise_sets">No exercise sets available. Please create a new one.</string>
<string name="activity_title_manage_exercise_sets">Exercise Sets</string>
<string name="activity_title_edit_exercise_set">Edit Exercise Set</string>