Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0680bcd1 authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Avoid double-apply of dialog theme"

parents 5f76360f 5696f045
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
     * {@code context}'s theme.
     *
     * @param context the parent context
     * @see android.R.styleable#Theme_alertDialogTheme
     */
    protected AlertDialog(Context context) {
        this(context, 0);
@@ -155,6 +156,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
     * {@code context}'s theme.
     *
     * @param context the parent context
     * @see android.R.styleable#Theme_alertDialogTheme
     */
    protected AlertDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        this(context, 0);
@@ -187,16 +189,24 @@ public class AlertDialog extends Dialog implements DialogInterface {
     * @param themeResId the resource ID of the theme against which to inflate
     *                   this dialog, or {@code 0} to use the parent
     *                   {@code context}'s default alert dialog theme
     * @see android.R.styleable#Theme_alertDialogTheme
     */
    protected AlertDialog(Context context, @AttrRes int themeResId) {
        super(context, resolveDialogTheme(context, themeResId));
        this(context, themeResId, true);
    }

    AlertDialog(Context context, @AttrRes int themeResId, boolean createContextThemeWrapper) {
        super(context, createContextThemeWrapper ? resolveDialogTheme(context, themeResId) : 0,
                createContextThemeWrapper);

        mWindow.alwaysReadCloseOnTouchAttr();
        mAlert = new AlertController(getContext(), this, getWindow());
    }

    static int resolveDialogTheme(Context context, int themeResId) {
        if (themeResId == THEME_TRADITIONAL) {
        if (themeResId == 0) {
            return 0;
        } else if (themeResId == THEME_TRADITIONAL) {
            return R.style.Theme_Dialog_Alert;
        } else if (themeResId == THEME_HOLO_DARK) {
            return R.style.Theme_Holo_Dialog_Alert;
@@ -428,7 +438,6 @@ public class AlertDialog extends Dialog implements DialogInterface {

    public static class Builder {
        private final AlertController.AlertParams P;
        private int mThemeResId;

        /**
         * Creates a builder for an alert dialog that uses the default alert
@@ -473,7 +482,6 @@ public class AlertDialog extends Dialog implements DialogInterface {
        public Builder(Context context, int themeResId) {
            P = new AlertController.AlertParams(new ContextThemeWrapper(
                    context, resolveDialogTheme(context, themeResId)));
            mThemeResId = themeResId;
        }

        /**
@@ -1075,7 +1083,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
         * create and display the dialog.
         */
        public AlertDialog create() {
            final AlertDialog dialog = new AlertDialog(P.mContext, mThemeResId);
            final AlertDialog dialog = new AlertDialog(P.mContext);
            P.apply(dialog.mAlert);
            dialog.setCancelable(P.mCancelable);
            if (P.mCancelable) {
+27 −19
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.annotation.DrawableRes;
import android.annotation.IdRes;
import android.annotation.LayoutRes;
import android.annotation.StringRes;
import com.android.internal.app.WindowDecorActionBar;

import android.annotation.Nullable;
import android.content.ComponentName;
@@ -56,6 +55,9 @@ import android.view.Window;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;

import com.android.internal.R;
import com.android.internal.app.WindowDecorActionBar;

import java.lang.ref.WeakReference;

/**
@@ -130,27 +132,32 @@ public class Dialog implements DialogInterface, Window.Callback,
    };

    /**
     * Create a Dialog window that uses the default dialog frame style.
     * Creates a dialog window that uses the default dialog theme.
     * <p>
     * The supplied {@code context} is used to obtain the window manager and
     * base theme used to present the dialog.
     *
     * @param context The Context the Dialog is to run it.  In particular, it
     *                uses the window manager and theme in this context to
     *                present its UI.
     * @param context the context in which the dialog should run
     * @see android.R.styleable#Theme_dialogTheme
     */
    public Dialog(Context context) {
        this(context, 0, true);
    }

    /**
     * Create a Dialog window that uses a custom dialog style.
     * Creates a dialog window that uses a custom dialog style.
     * <p>
     * The supplied {@code context} is used to obtain the window manager and
     * base theme used to present the dialog.
     * <p>
     * The supplied {@code theme} is applied on top of the context's theme. See
     * <a href="{@docRoot}guide/topics/resources/available-resources.html#stylesandthemes">
     * Style and Theme Resources</a> for more information about defining and
     * using styles.
     *
     * @param context The Context in which the Dialog should run. In particular, it
     *                uses the window manager and theme from this context to
     *                present its UI.
     * @param theme A style resource describing the theme to use for the
     * window. See <a href="{@docRoot}guide/topics/resources/available-resources.html#stylesandthemes">Style
     * and Theme Resources</a> for more information about defining and using
     * styles.  This theme is applied on top of the current theme in
     * <var>context</var>.  If 0, the default dialog theme will be used.
     * @param context the context in which the dialog should run
     * @param theme a style resource describing the theme to use for the
     *              window, or {@code 0} to use the default dialog theme
     */
    public Dialog(Context context, int theme) {
        this(context, theme, true);
@@ -159,9 +166,8 @@ public class Dialog implements DialogInterface, Window.Callback,
    Dialog(Context context, int theme, boolean createContextThemeWrapper) {
        if (createContextThemeWrapper) {
            if (theme == 0) {
                TypedValue outValue = new TypedValue();
                context.getTheme().resolveAttribute(com.android.internal.R.attr.dialogTheme,
                        outValue, true);
                final TypedValue outValue = new TypedValue();
                context.getTheme().resolveAttribute(R.attr.dialogTheme, outValue, true);
                theme = outValue.resourceId;
            }
            mContext = new ContextThemeWrapper(context, theme);
@@ -170,12 +176,14 @@ public class Dialog implements DialogInterface, Window.Callback,
        }

        mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
        Window w = new PhoneWindow(mContext);

        final Window w = new PhoneWindow(mContext);
        mWindow = w;
        w.setCallback(this);
        w.setOnWindowDismissedCallback(this);
        w.setWindowManager(mWindowManager, null, null);
        w.setGravity(Gravity.CENTER);

        mListenersHandler = new ListenersHandler(this);
    }