mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-22 14:59:14 +00:00
automatically adapt to system theme
added two new theme options: SYSTEM: dynamically switches between light and dark SYSTEM_AMOLED: dynamically switches between light and amoled reversed workaround for amoled themed preferences launch screen now always follows the system theme
This commit is contained in:
parent
7ce74d378f
commit
f37d70b58e
8 changed files with 27 additions and 24 deletions
|
@ -90,7 +90,7 @@ public class Preferences {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Theme getCurrentTheme() {
|
public Theme getCurrentTheme() {
|
||||||
return Theme.fromInteger(_prefs.getInt("pref_current_theme", 0));
|
return Theme.fromInteger(_prefs.getInt("pref_current_theme", Theme.SYSTEM.ordinal()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentTheme(Theme theme) {
|
public void setCurrentTheme(Theme theme) {
|
||||||
|
|
|
@ -3,7 +3,9 @@ package com.beemdevelopment.aegis;
|
||||||
public enum Theme {
|
public enum Theme {
|
||||||
LIGHT,
|
LIGHT,
|
||||||
DARK,
|
DARK,
|
||||||
AMOLED;
|
AMOLED,
|
||||||
|
SYSTEM,
|
||||||
|
SYSTEM_AMOLED;
|
||||||
|
|
||||||
private static Theme[] _values;
|
private static Theme[] _values;
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,19 @@ public abstract class AegisActivity extends AppCompatActivity implements AegisAp
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setPreferredTheme(Theme theme) {
|
protected void setPreferredTheme(Theme theme) {
|
||||||
|
if (theme == Theme.SYSTEM || theme == Theme.SYSTEM_AMOLED) {
|
||||||
|
// set the theme based on the system theme
|
||||||
|
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||||
|
switch (currentNightMode) {
|
||||||
|
case Configuration.UI_MODE_NIGHT_NO:
|
||||||
|
theme = Theme.LIGHT;
|
||||||
|
break;
|
||||||
|
case Configuration.UI_MODE_NIGHT_YES:
|
||||||
|
theme = theme == Theme.SYSTEM_AMOLED ? Theme.AMOLED : Theme.DARK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_currentTheme = theme;
|
_currentTheme = theme;
|
||||||
|
|
||||||
switch (theme) {
|
switch (theme) {
|
||||||
|
|
|
@ -39,21 +39,4 @@ public class PreferencesActivity extends AegisActivity {
|
||||||
outState.putParcelable("result", _fragment.getResult());
|
outState.putParcelable("result", _fragment.getResult());
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setPreferredTheme(Theme theme) {
|
|
||||||
switch (theme) {
|
|
||||||
case LIGHT:
|
|
||||||
setTheme(R.style.AppTheme);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DARK:
|
|
||||||
setTheme(R.style.AppTheme_Dark);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AMOLED:
|
|
||||||
setTheme(R.style.AppTheme_TrueBlack_Preferences);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
5
app/src/main/res/values-v29/strings.xml
Normal file
5
app/src/main/res/values-v29/strings.xml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="system_theme_title">System default</string>
|
||||||
|
<string name="system_amoled_theme_title">System default (AMOLED)</string>
|
||||||
|
</resources>
|
|
@ -22,6 +22,8 @@
|
||||||
<item>@string/light_theme_title</item>
|
<item>@string/light_theme_title</item>
|
||||||
<item>@string/dark_theme_title</item>
|
<item>@string/dark_theme_title</item>
|
||||||
<item>@string/amoled_theme_title</item>
|
<item>@string/amoled_theme_title</item>
|
||||||
|
<item>@string/system_theme_title</item>
|
||||||
|
<item>@string/system_amoled_theme_title</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="view_mode_titles">
|
<string-array name="view_mode_titles">
|
||||||
|
|
|
@ -189,6 +189,8 @@
|
||||||
<string name="dark_theme_title">Dark theme</string>
|
<string name="dark_theme_title">Dark theme</string>
|
||||||
<string name="light_theme_title">Light theme</string>
|
<string name="light_theme_title">Light theme</string>
|
||||||
<string name="amoled_theme_title">AMOLED theme</string>
|
<string name="amoled_theme_title">AMOLED theme</string>
|
||||||
|
<string name="system_theme_title">Set by Battery Saver</string>
|
||||||
|
<string name="system_amoled_theme_title">Set by Battery Saver (AMOLED)</string>
|
||||||
<string name="normal_viewmode_title">Normal</string>
|
<string name="normal_viewmode_title">Normal</string>
|
||||||
<string name="compact_mode_title">Compact</string>
|
<string name="compact_mode_title">Compact</string>
|
||||||
<string name="small_mode_title">Small</string>
|
<string name="small_mode_title">Small</string>
|
||||||
|
|
|
@ -70,9 +70,7 @@
|
||||||
<item name="android:textColor">@android:color/white</item>
|
<item name="android:textColor">@android:color/white</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="AppTheme.NoActionBar">
|
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||||
<item name="windowActionBar">false</item>
|
|
||||||
<item name="windowNoTitle">true</item>
|
|
||||||
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item>
|
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item>
|
||||||
<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
|
<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
|
||||||
</style>
|
</style>
|
||||||
|
@ -123,9 +121,7 @@
|
||||||
|
|
||||||
<item name="android:navigationBarColor" tools:targetApi="lollipop">@color/background_true_dark</item>
|
<item name="android:navigationBarColor" tools:targetApi="lollipop">@color/background_true_dark</item>
|
||||||
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
|
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="AppTheme.TrueBlack.Preferences" parent="AppTheme.TrueBlack">
|
|
||||||
<item name="android:windowBackground">@color/background_true_dark</item>
|
<item name="android:windowBackground">@color/background_true_dark</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue