Merge branch 'auto_theme'
This commit is contained in:
@@ -147,6 +147,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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
android:elevation="4dp"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
||||
app:popupTheme="?popupOverlayStyle"
|
||||
tools:ignore="UnusedAttribute" />
|
||||
|
||||
<FrameLayout
|
||||
|
||||
@@ -148,7 +148,7 @@
|
||||
android:touchscreenBlocksFocus="false"
|
||||
android:transitionGroup="false"
|
||||
app:layout_collapseMode="pin"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
||||
app:popupTheme="?popupOverlayStyle"
|
||||
tools:ignore="UnusedAttribute" />
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
|
||||
@@ -32,11 +32,15 @@
|
||||
</string-array>
|
||||
|
||||
<string-array name="theme_entries" translatable="false">
|
||||
<item>@string/theme_dark</item>
|
||||
<item>@string/theme_auto</item>
|
||||
<item>@string/theme_light</item>
|
||||
<item>@string/theme_dark</item>
|
||||
</string-array>
|
||||
<string-array name="theme_values" translatable="false">
|
||||
<item>"auto"</item>
|
||||
<item>"dark"</item>
|
||||
<item>"light"</item>
|
||||
</string-array>
|
||||
|
||||
<attr name="popupOverlayStyle" format="reference" />
|
||||
</resources>
|
||||
|
||||
@@ -314,8 +314,9 @@
|
||||
<string name="usage_sign_and_encrypt">"Sign & Encrypt"</string>
|
||||
<string name="error">"Error"</string>
|
||||
<string name="error_message">"Error: %s"</string>
|
||||
<string name="theme_dark">"Dark"</string>
|
||||
<string name="theme_auto">"Automatic"</string>
|
||||
<string name="theme_light">"Light"</string>
|
||||
<string name="theme_dark">"Dark"</string>
|
||||
<string name="strip">"Strip it"</string>
|
||||
|
||||
<!-- sentences -->
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
<item name="colorAccent">#2196f3</item>
|
||||
<item name="colorBrightToolbar">#dddddd</item>
|
||||
|
||||
<item name="popupOverlayStyle">@style/ThemeOverlay.AppCompat.Light</item>
|
||||
|
||||
<item name="colorFab">#2196f3</item>
|
||||
<item name="colorFabPressed">#1976d2</item>
|
||||
<item name="colorFabText">#fafafa</item>
|
||||
@@ -48,6 +50,8 @@
|
||||
<item name="colorAccent">#2196f3</item>
|
||||
<item name="colorBrightToolbar">#808080</item>
|
||||
|
||||
<item name="popupOverlayStyle">@style/ThemeOverlay.AppCompat.Dark</item>
|
||||
|
||||
<item name="colorFab">#2196f3</item>
|
||||
<item name="colorFabPressed">#1976d2</item>
|
||||
<item name="colorFabText">#fafafa</item>
|
||||
|
||||
Reference in New Issue
Block a user