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

Commit 48728c21 authored by Alan Viverette's avatar Alan Viverette
Browse files

Clean up Dialog annotations, lint warnings, and declarations

No functional changes.

Change-Id: If38c9d829d83e762f8c2d05c2fe060c56804b38f
parent 29cbe66c
Loading
Loading
Loading
Loading
+102 −88
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package android.app;

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

import android.annotation.CallSuper;
import android.annotation.DrawableRes;
import android.annotation.IdRes;
@@ -56,12 +60,7 @@ 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 com.android.internal.policy.PhoneWindow;

import java.lang.ref.WeakReference;
import java.util.List;

/**
 * Base class for Dialogs.
@@ -94,10 +93,13 @@ public class Dialog implements DialogInterface, Window.Callback,
    private static final String TAG = "Dialog";
    private Activity mOwnerActivity;

    private final WindowManager mWindowManager;

    final Context mContext;
    final WindowManager mWindowManager;
    Window mWindow;
    final Window mWindow;

    View mDecor;

    private ActionBar mActionBar;
    /**
     * This field should be made private, so it is hidden from the SDK.
@@ -122,7 +124,7 @@ public class Dialog implements DialogInterface, Window.Callback,
    private static final int CANCEL = 0x44;
    private static final int SHOW = 0x45;

    private Handler mListenersHandler;
    private final Handler mListenersHandler;

    private SearchEvent mSearchEvent;

@@ -130,11 +132,7 @@ public class Dialog implements DialogInterface, Window.Callback,

    private int mActionModeTypeStarting = ActionMode.TYPE_PRIMARY;

    private final Runnable mDismissAction = new Runnable() {
        public void run() {
            dismissDialog();
        }
    };
    private final Runnable mDismissAction = this::dismissDialog;

    /**
     * Creates a dialog window that uses the default dialog theme.
@@ -197,14 +195,15 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @hide
     */
    @Deprecated
    protected Dialog(@NonNull Context context, boolean cancelable, Message cancelCallback) {
    protected Dialog(@NonNull Context context, boolean cancelable,
            @Nullable Message cancelCallback) {
        this(context);
        mCancelable = cancelable;
        mCancelMessage = cancelCallback;
    }

    protected Dialog(@NonNull Context context, boolean cancelable,
            OnCancelListener cancelListener) {
            @Nullable OnCancelListener cancelListener) {
        this(context);
        mCancelable = cancelable;
        setOnCancelListener(cancelListener);
@@ -215,8 +214,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * 
     * @return Context The Context used by the Dialog.
     */
    @NonNull
    public final Context getContext() {
    public final @NonNull Context getContext() {
        return mContext;
    }

@@ -225,7 +223,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     *
     * @return The ActionBar attached to the dialog or null if no ActionBar is present.
     */
    public ActionBar getActionBar() {
    public @Nullable ActionBar getActionBar() {
        return mActionBar;
    }

@@ -235,7 +233,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * 
     * @param activity The Activity that owns this dialog.
     */
    public final void setOwnerActivity(Activity activity) {
    public final void setOwnerActivity(@NonNull Activity activity) {
        mOwnerActivity = activity;
        
        getWindow().setVolumeControlStream(mOwnerActivity.getVolumeControlStream());
@@ -249,7 +247,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * 
     * @return The Activity that owns this Dialog.
     */
    public final Activity getOwnerActivity() {
    public final @Nullable Activity getOwnerActivity() {
        return mOwnerActivity;
    }
    
@@ -315,13 +313,10 @@ public class Dialog implements DialogInterface, Window.Callback,
            l = nl;
        }

        try {
        mWindowManager.addView(mDecor, l);
        mShowing = true;

        sendShowMessage();
        } finally {
        }
    }
    
    /**
@@ -387,7 +382,7 @@ public class Dialog implements DialogInterface, Window.Callback,
        }
    }

    // internal method to make sure mcreated is set properly without requiring
    // internal method to make sure mCreated is set properly without requiring
    // users to call through to super in onCreate
    void dispatchOnCreate(Bundle savedInstanceState) {
        if (!mCreated) {
@@ -399,7 +394,7 @@ public class Dialog implements DialogInterface, Window.Callback,
    /**
     * Similar to {@link Activity#onCreate}, you should initialize your dialog
     * in this method, including calling {@link #setContentView}.
     * @param savedInstanceState If this dialog is being reinitalized after a
     * @param savedInstanceState If this dialog is being reinitialized after a
     *     the hosting activity was previously shut down, holds the result from
     *     the most recent call to {@link #onSaveInstanceState}, or null if this
     *     is the first time.
@@ -432,7 +427,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * state.
     * @return A bundle with the state of the dialog.
     */
    public Bundle onSaveInstanceState() {
    public @NonNull Bundle onSaveInstanceState() {
        Bundle bundle = new Bundle();
        bundle.putBoolean(DIALOG_SHOWING_TAG, mShowing);
        if (mCreated) {
@@ -451,7 +446,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @param savedInstanceState The state of the dialog previously saved by
     *     {@link #onSaveInstanceState()}.
     */
    public void onRestoreInstanceState(Bundle savedInstanceState) {
    public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
        final Bundle dialogHierarchyState = savedInstanceState.getBundle(DIALOG_HIERARCHY_TAG);
        if (dialogHierarchyState == null) {
            // dialog has never been shown, or onCreated, nothing to restore.
@@ -472,7 +467,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @return Window The current window, or null if the activity is not
     *         visual.
     */
    public Window getWindow() {
    public @Nullable Window getWindow() {
        return mWindow;
    }

@@ -485,7 +480,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @see #getWindow
     * @see android.view.Window#getCurrentFocus
     */
    public View getCurrentFocus() {
    public @Nullable View getCurrentFocus() {
        return mWindow != null ? mWindow.getCurrentFocus() : null;
    }

@@ -497,8 +492,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @param id the identifier of the view to find
     * @return The view with the given id or null.
     */
    @Nullable
    public View findViewById(@IdRes int id) {
    public @Nullable View findViewById(@IdRes int id) {
        return mWindow.findViewById(id);
    }

@@ -519,19 +513,19 @@ public class Dialog implements DialogInterface, Window.Callback,
     * 
     * @param view The desired content to display.
     */
    public void setContentView(View view) {
    public void setContentView(@NonNull View view) {
        mWindow.setContentView(view);
    }

    /**
     * Set the screen content to an explicit view.  This view is placed
     * directly into the screen's view hierarchy.  It can itself be a complex
     * view hierarhcy.
     * view hierarchy.
     * 
     * @param view The desired content to display.
     * @param params Layout parameters for the view.
     */
    public void setContentView(View view, ViewGroup.LayoutParams params) {
    public void setContentView(@NonNull View view, @Nullable ViewGroup.LayoutParams params) {
        mWindow.setContentView(view, params);
    }

@@ -542,7 +536,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @param view The desired content to display.
     * @param params Layout parameters for the view.
     */
    public void addContentView(View view, ViewGroup.LayoutParams params) {
    public void addContentView(@NonNull View view, @Nullable ViewGroup.LayoutParams params) {
        mWindow.addContentView(view, params);
    }

@@ -551,7 +545,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * 
     * @param title The new text to display in the title.
     */
    public void setTitle(CharSequence title) {
    public void setTitle(@Nullable CharSequence title) {
        mWindow.setTitle(title);
        mWindow.getAttributes().setTitle(title);
    }
@@ -577,7 +571,8 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @see #onKeyUp
     * @see android.view.KeyEvent
     */
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    @Override
    public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            event.startTracking();
            return true;
@@ -591,7 +586,8 @@ public class Dialog implements DialogInterface, Window.Callback,
     * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle
     * the event).
     */
    public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    @Override
    public boolean onKeyLongPress(int keyCode, @NonNull KeyEvent event) {
        return false;
    }

@@ -604,7 +600,8 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @see #onKeyDown
     * @see KeyEvent
     */
    public boolean onKeyUp(int keyCode, KeyEvent event) {
    @Override
    public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking()
                && !event.isCanceled()) {
            onBackPressed();
@@ -618,7 +615,8 @@ public class Dialog implements DialogInterface, Window.Callback,
     * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle
     * the event).
     */
    public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
    @Override
    public boolean onKeyMultiple(int keyCode, int repeatCount, @NonNull KeyEvent event) {
        return false;
    }
    
@@ -643,7 +641,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @param event Description of the key event.
     * @return True if the key shortcut was handled.
     */
    public boolean onKeyShortcut(int keyCode, KeyEvent event) {
    public boolean onKeyShortcut(int keyCode, @NonNull KeyEvent event) {
        return false;
    }

@@ -657,7 +655,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     *         The default implementation will cancel the dialog when a touch
     *         happens outside of the window bounds.
     */
    public boolean onTouchEvent(MotionEvent event) {
    public boolean onTouchEvent(@NonNull MotionEvent event) {
        if (mCancelable && mShowing && mWindow.shouldCloseOnTouch(mContext, event)) {
            cancel();
            return true;
@@ -680,7 +678,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @return Return true if you have consumed the event, false if you haven't.
     * The default implementation always returns false.
     */
    public boolean onTrackballEvent(MotionEvent event) {
    public boolean onTrackballEvent(@NonNull MotionEvent event) {
        return false;
    }

@@ -709,25 +707,30 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @return Return true if you have consumed the event, false if you haven't.
     * The default implementation always returns false.
     */
    public boolean onGenericMotionEvent(MotionEvent event) {
    public boolean onGenericMotionEvent(@NonNull MotionEvent event) {
        return false;
    }

    @Override
    public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
        if (mDecor != null) {
            mWindowManager.updateViewLayout(mDecor, params);
        }
    }

    @Override
    public void onContentChanged() {
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
    }

    @Override
    public void onAttachedToWindow() {
    }

    @Override
    public void onDetachedFromWindow() {
    }

@@ -746,7 +749,8 @@ public class Dialog implements DialogInterface, Window.Callback,
     *
     * @return boolean Return true if this event was consumed.
     */
    public boolean dispatchKeyEvent(KeyEvent event) {
    @Override
    public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
        if ((mOnKeyListener != null) && (mOnKeyListener.onKey(this, event.getKeyCode(), event))) {
            return true;
        }
@@ -766,7 +770,8 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @param event The key shortcut event.
     * @return True if this event was consumed.
     */
    public boolean dispatchKeyShortcutEvent(KeyEvent event) {
    @Override
    public boolean dispatchKeyShortcutEvent(@NonNull KeyEvent event) {
        if (mWindow.superDispatchKeyShortcutEvent(event)) {
            return true;
        }
@@ -783,7 +788,8 @@ public class Dialog implements DialogInterface, Window.Callback,
     * 
     * @return boolean Return true if this event was consumed.
     */
    public boolean dispatchTouchEvent(MotionEvent ev) {
    @Override
    public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
        if (mWindow.superDispatchTouchEvent(ev)) {
            return true;
        }
@@ -800,7 +806,8 @@ public class Dialog implements DialogInterface, Window.Callback,
     * 
     * @return boolean Return true if this event was consumed.
     */
    public boolean dispatchTrackballEvent(MotionEvent ev) {
    @Override
    public boolean dispatchTrackballEvent(@NonNull MotionEvent ev) {
        if (mWindow.superDispatchTrackballEvent(ev)) {
            return true;
        }
@@ -817,14 +824,16 @@ public class Dialog implements DialogInterface, Window.Callback,
     *
     * @return boolean Return true if this event was consumed.
     */
    public boolean dispatchGenericMotionEvent(MotionEvent ev) {
    @Override
    public boolean dispatchGenericMotionEvent(@NonNull MotionEvent ev) {
        if (mWindow.superDispatchGenericMotionEvent(ev)) {
            return true;
        }
        return onGenericMotionEvent(ev);
    }

    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    @Override
    public boolean dispatchPopulateAccessibilityEvent(@NonNull AccessibilityEvent event) {
        event.setClassName(getClass().getName());
        event.setPackageName(mContext.getPackageName());

@@ -839,6 +848,7 @@ public class Dialog implements DialogInterface, Window.Callback,
    /**
     * @see Activity#onCreatePanelView(int)
     */
    @Override
    public View onCreatePanelView(int featureId) {
        return null;
    }
@@ -846,7 +856,8 @@ public class Dialog implements DialogInterface, Window.Callback,
    /**
     * @see Activity#onCreatePanelMenu(int, Menu)
     */
    public boolean onCreatePanelMenu(int featureId, Menu menu) {
    @Override
    public boolean onCreatePanelMenu(int featureId, @NonNull Menu menu) {
        if (featureId == Window.FEATURE_OPTIONS_PANEL) {
            return onCreateOptionsMenu(menu);
        }
@@ -857,10 +868,10 @@ public class Dialog implements DialogInterface, Window.Callback,
    /**
     * @see Activity#onPreparePanel(int, View, Menu)
     */
    @Override
    public boolean onPreparePanel(int featureId, View view, Menu menu) {
        if (featureId == Window.FEATURE_OPTIONS_PANEL && menu != null) {
            boolean goforit = onPrepareOptionsMenu(menu);
            return goforit && menu.hasVisibleItems();
            return onPrepareOptionsMenu(menu) && menu.hasVisibleItems();
        }
        return true;
    }
@@ -868,6 +879,7 @@ public class Dialog implements DialogInterface, Window.Callback,
    /**
     * @see Activity#onMenuOpened(int, Menu)
     */
    @Override
    public boolean onMenuOpened(int featureId, Menu menu) {
        if (featureId == Window.FEATURE_ACTION_BAR) {
            mActionBar.dispatchMenuVisibilityChanged(true);
@@ -878,6 +890,7 @@ public class Dialog implements DialogInterface, Window.Callback,
    /**
     * @see Activity#onMenuItemSelected(int, MenuItem)
     */
    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
        return false;
    }
@@ -885,6 +898,7 @@ public class Dialog implements DialogInterface, Window.Callback,
    /**
     * @see Activity#onPanelClosed(int, Menu)
     */
    @Override
    public void onPanelClosed(int featureId, Menu menu) {
        if (featureId == Window.FEATURE_ACTION_BAR) {
            mActionBar.dispatchMenuVisibilityChanged(false);
@@ -899,7 +913,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @see Activity#onCreateOptionsMenu(Menu)
     * @see #getOwnerActivity()
     */
    public boolean onCreateOptionsMenu(Menu menu) {
    public boolean onCreateOptionsMenu(@NonNull Menu menu) {
        return true;
    }

@@ -911,21 +925,21 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @see Activity#onPrepareOptionsMenu(Menu)
     * @see #getOwnerActivity()
     */
    public boolean onPrepareOptionsMenu(Menu menu) {
    public boolean onPrepareOptionsMenu(@NonNull Menu menu) {
        return true;
    }

    /**
     * @see Activity#onOptionsItemSelected(MenuItem)
     */
    public boolean onOptionsItemSelected(MenuItem item) {
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        return false;
    }

    /**
     * @see Activity#onOptionsMenuClosed(Menu)
     */
    public void onOptionsMenuClosed(Menu menu) {
    public void onOptionsMenuClosed(@NonNull Menu menu) {
    }

    /**
@@ -958,47 +972,49 @@ public class Dialog implements DialogInterface, Window.Callback,
    /**
     * @see Activity#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)
     */
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    }

    /**
     * @see Activity#registerForContextMenu(View)
     */
    public void registerForContextMenu(View view) {
    public void registerForContextMenu(@NonNull View view) {
        view.setOnCreateContextMenuListener(this);
    }
    
    /**
     * @see Activity#unregisterForContextMenu(View)
     */
    public void unregisterForContextMenu(View view) {
    public void unregisterForContextMenu(@NonNull View view) {
        view.setOnCreateContextMenuListener(null);
    }
    
    /**
     * @see Activity#openContextMenu(View)
     */
    public void openContextMenu(View view) {
    public void openContextMenu(@NonNull View view) {
        view.showContextMenu();
    }

    /**
     * @see Activity#onContextItemSelected(MenuItem)
     */
    public boolean onContextItemSelected(MenuItem item) {
    public boolean onContextItemSelected(@NonNull MenuItem item) {
        return false;
    }

    /**
     * @see Activity#onContextMenuClosed(Menu)
     */
    public void onContextMenuClosed(Menu menu) {
    public void onContextMenuClosed(@NonNull Menu menu) {
    }

    /**
     * This hook is called when the user signals the desire to start a search.
     */
    public boolean onSearchRequested(SearchEvent searchEvent) {
    @Override
    public boolean onSearchRequested(@NonNull SearchEvent searchEvent) {
        mSearchEvent = searchEvent;
        return onSearchRequested();
    }
@@ -1006,6 +1022,7 @@ public class Dialog implements DialogInterface, Window.Callback,
    /**
     * This hook is called when the user signals the desire to start a search.
     */
    @Override
    public boolean onSearchRequested() {
        final SearchManager searchManager = (SearchManager) mContext
                .getSystemService(Context.SEARCH_SERVICE);
@@ -1028,13 +1045,10 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @return SearchEvent The SearchEvent that triggered the {@link
     *                    #onSearchRequested} callback.
     */
    public final SearchEvent getSearchEvent() {
    public final @Nullable SearchEvent getSearchEvent() {
        return mSearchEvent;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) {
        if (mActionBar != null && mActionModeTypeStarting == ActionMode.TYPE_PRIMARY) {
@@ -1043,9 +1057,6 @@ public class Dialog implements DialogInterface, Window.Callback,
        return null;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int type) {
        try {
@@ -1062,6 +1073,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * Note that if you override this method you should always call through
     * to the superclass implementation by calling super.onActionModeStarted(mode).
     */
    @Override
    @CallSuper
    public void onActionModeStarted(ActionMode mode) {
        mActionMode = mode;
@@ -1073,6 +1085,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * Note that if you override this method you should always call through
     * to the superclass implementation by calling super.onActionModeFinished(mode).
     */
    @Override
    @CallSuper
    public void onActionModeFinished(ActionMode mode) {
        if (mode == mActionMode) {
@@ -1138,7 +1151,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * Convenience for calling
     * {@link android.view.Window#setFeatureDrawableUri}.
     */
    public final void setFeatureDrawableUri(int featureId, Uri uri) {
    public final void setFeatureDrawableUri(int featureId, @Nullable Uri uri) {
        getWindow().setFeatureDrawableUri(featureId, uri);
    }

@@ -1146,7 +1159,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * Convenience for calling
     * {@link android.view.Window#setFeatureDrawable(int, Drawable)}.
     */
    public final void setFeatureDrawable(int featureId, Drawable drawable) {
    public final void setFeatureDrawable(int featureId, @Nullable Drawable drawable) {
        getWindow().setFeatureDrawable(featureId, drawable);
    }

@@ -1158,7 +1171,7 @@ public class Dialog implements DialogInterface, Window.Callback,
        getWindow().setFeatureDrawableAlpha(featureId, alpha);
    }

    public LayoutInflater getLayoutInflater() {
    public @NonNull LayoutInflater getLayoutInflater() {
        return getWindow().getLayoutInflater();
    }

@@ -1190,6 +1203,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * Cancel the dialog.  This is essentially the same as calling {@link #dismiss()}, but it will
     * also call your {@link DialogInterface.OnCancelListener} (if registered).
     */
    @Override
    public void cancel() {
        if (!mCanceled && mCancelMessage != null) {
            mCanceled = true;
@@ -1210,7 +1224,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * 
     * @param listener The {@link DialogInterface.OnCancelListener} to use.
     */
    public void setOnCancelListener(final OnCancelListener listener) {
    public void setOnCancelListener(@Nullable OnCancelListener listener) {
        if (mCancelAndDismissTaken != null) {
            throw new IllegalStateException(
                    "OnCancelListener is already taken by "
@@ -1228,7 +1242,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * @param msg The msg to send when the dialog is canceled.
     * @see #setOnCancelListener(android.content.DialogInterface.OnCancelListener)
     */
    public void setCancelMessage(final Message msg) {
    public void setCancelMessage(@Nullable Message msg) {
        mCancelMessage = msg;
    }

@@ -1236,7 +1250,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * Set a listener to be invoked when the dialog is dismissed.
     * @param listener The {@link DialogInterface.OnDismissListener} to use.
     */
    public void setOnDismissListener(final OnDismissListener listener) {
    public void setOnDismissListener(@Nullable OnDismissListener listener) {
        if (mCancelAndDismissTaken != null) {
            throw new IllegalStateException(
                    "OnDismissListener is already taken by "
@@ -1253,7 +1267,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     * Sets a listener to be invoked when the dialog is shown.
     * @param listener The {@link DialogInterface.OnShowListener} to use.
     */
    public void setOnShowListener(OnShowListener listener) {
    public void setOnShowListener(@Nullable OnShowListener listener) {
        if (listener != null) {
            mShowMessage = mListenersHandler.obtainMessage(SHOW, listener);
        } else {
@@ -1265,13 +1279,13 @@ public class Dialog implements DialogInterface, Window.Callback,
     * Set a message to be sent when the dialog is dismissed.
     * @param msg The msg to send when the dialog is dismissed.
     */
    public void setDismissMessage(final Message msg) {
    public void setDismissMessage(@Nullable Message msg) {
        mDismissMessage = msg;
    }

    /** @hide */
    public boolean takeCancelAndDismissListeners(String msg, final OnCancelListener cancel,
            final OnDismissListener dismiss) {
    public boolean takeCancelAndDismissListeners(@Nullable String msg,
            @Nullable OnCancelListener cancel, @Nullable OnDismissListener dismiss) {
        if (mCancelAndDismissTaken != null) {
            mCancelAndDismissTaken = null;
        } else if (mCancelMessage != null || mDismissMessage != null) {
@@ -1305,15 +1319,15 @@ public class Dialog implements DialogInterface, Window.Callback,
    /**
     * Sets the callback that will be called if a key is dispatched to the dialog.
     */
    public void setOnKeyListener(final OnKeyListener onKeyListener) {
    public void setOnKeyListener(@Nullable OnKeyListener onKeyListener) {
        mOnKeyListener = onKeyListener;
    }

    private static final class ListenersHandler extends Handler {
        private WeakReference<DialogInterface> mDialog;
        private final WeakReference<DialogInterface> mDialog;

        public ListenersHandler(Dialog dialog) {
            mDialog = new WeakReference<DialogInterface>(dialog);
            mDialog = new WeakReference<>(dialog);
        }

        @Override