From a4470abc10452cd7a2867bc2379e94a3558baa47 Mon Sep 17 00:00:00 2001 From: Thialfihar Date: Tue, 21 Jul 2015 22:37:52 +0200 Subject: Refactor theme selection of dialogs This makes sure the dark theme also uses dark dialogs. --- .../keychain/ui/util/InstallDialogFragmentHelper.java | 7 ++----- .../sufficientlysecure/keychain/ui/util/ThemeChanger.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java index 5ddb013db..b2213ed10 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java @@ -31,6 +31,7 @@ import android.view.ContextThemeWrapper; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder; +import org.sufficientlysecure.keychain.ui.util.ThemeChanger; import org.sufficientlysecure.keychain.util.Log; public class InstallDialogFragmentHelper { @@ -65,11 +66,7 @@ public class InstallDialogFragmentHelper { final String installPath = args.getString(ARG_INSTALL_PATH); final boolean useMiddleButton = args.getBoolean(ARG_USE_MIDDLE_BUTTON); - // 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) - ContextThemeWrapper theme = new ContextThemeWrapper(activity, - R.style.Theme_AppCompat_Light_Dialog); + ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(activity); CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(theme); builder.setTitle(title).setMessage(message); 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 4878271a2..f53e43528 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 @@ -29,6 +29,19 @@ public class ThemeChanger { private Preferences mPreferences; private String mCurrentTheme = null; + 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())) { + return new ContextThemeWrapper(context, R.style.Theme_AppCompat_Dialog); + } else { + return new ContextThemeWrapper(context, R.style.Theme_AppCompat_Light_Dialog); + } + } + public ThemeChanger(Context context) { mContext = context; mPreferences = Preferences.getPreferences(mContext); -- cgit v1.2.3