Refactor theme selection of dialogs

This makes sure the dark theme also uses dark dialogs.
This commit is contained in:
Thialfihar
2015-07-21 22:37:52 +02:00
parent 313188c695
commit a4470abc10
7 changed files with 27 additions and 27 deletions

View File

@@ -49,6 +49,7 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
import org.sufficientlysecure.keychain.util.Log;
import java.util.Date;
@@ -254,8 +255,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
final long[] masterKeyIds = getArguments().getLongArray(ARG_DELETE_MASTER_KEY_IDS);
final boolean hasSecret = getArguments().getBoolean(ARG_HAS_SECRET);
ContextThemeWrapper theme = new ContextThemeWrapper(activity,
R.style.Theme_AppCompat_Light_Dialog);
ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(activity);
CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(theme);
@@ -351,10 +351,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
final String CHOICE_REVOKE = getString(R.string.del_rev_dialog_choice_rev_upload);
final String CHOICE_DELETE = getString(R.string.del_rev_dialog_choice_delete);
// 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(getString(R.string.del_rev_dialog_title,

View File

@@ -59,6 +59,7 @@ import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Passphrase;
import org.sufficientlysecure.keychain.util.Preferences;
@@ -196,10 +197,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Activity activity = getActivity();
// 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);
mSubKeyId = getArguments().getLong(EXTRA_SUBKEY_ID);
mServiceIntent = getArguments().getParcelable(EXTRA_SERVICE_INTENT);

View File

@@ -29,6 +29,7 @@ import android.support.v4.app.FragmentActivity;
import android.view.ContextThemeWrapper;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
public class RetryUploadDialogActivity extends FragmentActivity {
@@ -54,8 +55,7 @@ public class RetryUploadDialogActivity extends FragmentActivity {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
ContextThemeWrapper theme = new ContextThemeWrapper(getActivity(),
R.style.Theme_AppCompat_Light_Dialog);
ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(getActivity());
CustomAlertDialogBuilder dialogBuilder = new CustomAlertDialogBuilder(theme);
dialogBuilder.setTitle(R.string.retry_up_dialog_title);

View File

@@ -30,6 +30,7 @@ import android.view.ContextThemeWrapper;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
@@ -67,11 +68,7 @@ public class OrbotStartDialogFragment extends DialogFragment {
int middleButton = getArguments().getInt(ARG_MIDDLE_BUTTON);
final Activity activity = getActivity();
// 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);
@@ -126,4 +123,4 @@ public class OrbotStartDialogFragment extends DialogFragment {
return builder.show();
}
}
}

View File

@@ -35,6 +35,7 @@ import android.widget.Button;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.service.KeychainService;
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
/**
* meant to be used
@@ -98,10 +99,7 @@ public class ProgressDialogFragment extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Activity activity = getActivity();
// if the progress 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 context = new ContextThemeWrapper(activity,
R.style.Theme_AppCompat_Light);
ContextThemeWrapper context = ThemeChanger.getDialogThemeWrapper(activity);
ProgressDialog dialog = new ProgressDialog(context);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

View File

@@ -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);

View File

@@ -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);