diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java
index f681769b9..0df7a425b 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java
@@ -142,6 +142,7 @@ public final class Constants {
public static final String KEY_SIGNATURES_TABLE_INITIALIZED = "key_signatures_table_initialized";
public static final class Theme {
+ public static final String AUTO = "auto";
public static final String LIGHT = "light";
public static final String DARK = "dark";
public static final String DEFAULT = Constants.Pref.Theme.LIGHT;
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ThemeChanger.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ThemeChanger.java
index 065896d71..efa26ba95 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ThemeChanger.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ThemeChanger.java
@@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui.util;
import android.app.Activity;
import android.content.Context;
+import android.content.res.Configuration;
import android.view.ContextThemeWrapper;
import org.sufficientlysecure.keychain.Constants;
@@ -33,13 +34,35 @@ public class ThemeChanger {
private int mLightResId;
private int mDarkResId;
+ static private boolean isDark(final Preferences preferences, final Configuration config) {
+ final String preferedTheme = preferences.getTheme();
+ switch (preferedTheme) {
+ case Constants.Pref.Theme.AUTO:
+ final int currentNightMode = config.uiMode & Configuration.UI_MODE_NIGHT_MASK;
+ switch (currentNightMode) {
+ case Configuration.UI_MODE_NIGHT_NO:
+ return false;
+ case Configuration.UI_MODE_NIGHT_YES:
+ return true;
+ default:
+ throw new IllegalStateException("Unknown uiMode");
+ }
+ case Constants.Pref.Theme.LIGHT:
+ return false;
+ case Constants.Pref.Theme.DARK:
+ return true;
+ default:
+ throw new IllegalStateException("Unknown theme");
+ }
+ }
+
static public ContextThemeWrapper getDialogThemeWrapper(Context context) {
Preferences preferences = Preferences.getPreferences(context);
// if the dialog is displayed from the application class, design is missing.
// hack to get holo design (which is not automatically applied due to activity's
// Theme.NoDisplay)
- if (Constants.Pref.Theme.DARK.equals(preferences.getTheme())) {
+ if (isDark(preferences, context.getResources().getConfiguration())) {
return new ContextThemeWrapper(context, R.style.Theme_Keychain_Dark);
} else {
return new ContextThemeWrapper(context, R.style.Theme_Keychain_Light);
@@ -63,7 +86,11 @@ public class ThemeChanger {
* the caller can re-create the activity, if need be.
*/
public boolean changeTheme() {
- String newTheme = mPreferences.getTheme();
+ String newTheme = Constants.Pref.Theme.LIGHT;
+ if (isDark(mPreferences, mContext.getResources().getConfiguration())) {
+ newTheme = Constants.Pref.Theme.DARK;
+ }
+
if (mCurrentTheme != null && mCurrentTheme.equals(newTheme)) {
return false;
}
diff --git a/OpenKeychain/src/main/res/layout/main_activity.xml b/OpenKeychain/src/main/res/layout/main_activity.xml
index c620d999f..90b1b5242 100644
--- a/OpenKeychain/src/main/res/layout/main_activity.xml
+++ b/OpenKeychain/src/main/res/layout/main_activity.xml
@@ -14,7 +14,7 @@
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
- app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
+ app:popupTheme="?popupOverlayStyle"
tools:ignore="UnusedAttribute" />
diff --git a/OpenKeychain/src/main/res/values/arrays.xml b/OpenKeychain/src/main/res/values/arrays.xml
index 584d773b7..bf43600e6 100644
--- a/OpenKeychain/src/main/res/values/arrays.xml
+++ b/OpenKeychain/src/main/res/values/arrays.xml
@@ -32,11 +32,15 @@
- - @string/theme_dark
+ - @string/theme_auto
- @string/theme_light
+ - @string/theme_dark
+ - "auto"
- "dark"
- "light"
+
+
diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml
index a4b50a495..a6b7ff9fd 100644
--- a/OpenKeychain/src/main/res/values/strings.xml
+++ b/OpenKeychain/src/main/res/values/strings.xml
@@ -314,8 +314,9 @@
"Sign & Encrypt"
"Error"
"Error: %s"
- "Dark"
+ "Automatic"
"Light"
+ "Dark"
"Strip it"
diff --git a/OpenKeychain/src/main/res/values/themes.xml b/OpenKeychain/src/main/res/values/themes.xml
index f62238945..8bd07c50b 100644
--- a/OpenKeychain/src/main/res/values/themes.xml
+++ b/OpenKeychain/src/main/res/values/themes.xml
@@ -7,6 +7,8 @@
- #2196f3
- #dddddd
+ - @style/ThemeOverlay.AppCompat.Light
+
- #2196f3
- #1976d2
- #fafafa
@@ -48,6 +50,8 @@
- #2196f3
- #808080
+ - @style/ThemeOverlay.AppCompat.Dark
+
- #2196f3
- #1976d2
- #fafafa