Added system theme settings to support auto mode

This commit is contained in:
M66B 2019-02-04 14:32:39 +00:00
parent dc7b5736ae
commit 271d401f19
3 changed files with 17 additions and 4 deletions

View File

@ -51,6 +51,12 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String theme = prefs.getString("theme", null);
if ("system".equals(theme)) {
int uiMode = getResources().getConfiguration().uiMode;
Log.i("UI mode=" + uiMode);
if ((uiMode & Configuration.UI_MODE_NIGHT_YES) != 0)
setTheme(R.style.AppThemeDark);
}
if ("dark".equals(theme))
setTheme(R.style.AppThemeDark);
else if ("black".equals(theme))

View File

@ -143,6 +143,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
case R.string.title_setup_light_theme:
case R.string.title_setup_dark_theme:
case R.string.title_setup_black_theme:
case R.string.title_setup_system_theme:
onMenuTheme(item.getId());
break;
case R.string.title_setup_notifications:
@ -178,13 +179,15 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_unarchive_24, R.string.title_setup_import));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String theme = prefs.getString("theme", "light");
if ("dark".equals(theme))
String theme = prefs.getString("theme", "system");
if ("light".equals(theme))
drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_palette_24, R.string.title_setup_dark_theme));
else if ("dark".equals(theme))
drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_palette_24, R.string.title_setup_black_theme));
else if ("black".equals(theme))
drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_palette_24, R.string.title_setup_light_theme));
drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_palette_24, R.string.title_setup_system_theme));
else
drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_palette_24, R.string.title_setup_dark_theme));
drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_palette_24, R.string.title_setup_light_theme));
if (getIntentNotifications(this).resolveActivity(pm) != null)
drawerArray.add(new DrawerItem(this, R.layout.item_drawer, R.drawable.baseline_notifications_24, R.string.title_setup_notifications));
@ -375,6 +378,9 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
case R.string.title_setup_black_theme:
prefs.edit().putString("theme", "black").apply();
break;
case R.string.title_setup_system_theme:
prefs.edit().putString("theme", "system").apply();
break;
}
}

View File

@ -128,6 +128,7 @@
<string name="title_setup_light_theme">Light theme</string>
<string name="title_setup_dark_theme">Dark theme</string>
<string name="title_setup_black_theme">Black theme</string>
<string name="title_setup_system_theme">System theme</string>
<string name="title_setup_defaults">Restore defaults</string>
<string name="title_advanced">Advanced options</string>