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

Commit 919e151b authored by Siarhei Vishniakou's avatar Siarhei Vishniakou Committed by android-build-merger
Browse files

Merge "Dismiss Dialog in post instead of immediately"

am: 9b2c026f

Change-Id: Iceb48f0a6f0172a4de2d3da668a38c7977cf20dd
parents a0484ac4 9b2c026f
Loading
Loading
Loading
Loading
+78 −50
Original line number Diff line number Diff line
@@ -77,6 +77,14 @@ public abstract class DialogPreference extends Preference implements
    @UnsupportedAppUsage
    private int mWhichButtonClicked;

    /** Dismiss the dialog on the UI thread, but not inline with handlers */
    private final Runnable mDismissRunnable = new Runnable() {
        @Override
        public void run() {
            mDialog.dismiss();
        }
    };

    public DialogPreference(
            Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
@@ -324,10 +332,29 @@ public abstract class DialogPreference extends Preference implements
        if (needInputMethod()) {
            requestInputMethod(dialog);
        }
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                removeDismissCallbacks();
            }
        });
        dialog.setOnDismissListener(this);
        dialog.show();
    }

    void postDismiss() {
        removeDismissCallbacks();
        View decorView = mDialog.getWindow().getDecorView();
        decorView.post(mDismissRunnable);
    }

    private void removeDismissCallbacks() {
        if (mDialog != null && mDialog.getWindow() != null
                && mDialog.getWindow().getDecorView() != null) {
            mDialog.getWindow().getDecorView().removeCallbacks(mDismissRunnable);
        }
    }

    /**
     * Returns whether the preference needs to display a soft input method when the dialog
     * is displayed. Default is false. Subclasses should override this method if they need
@@ -396,8 +423,9 @@ public abstract class DialogPreference extends Preference implements
        mWhichButtonClicked = which;
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        
        removeDismissCallbacks();
        getPreferenceManager().unregisterOnActivityDestroyListener(this);

        mDialog = null;
+22 −22
Original line number Diff line number Diff line
@@ -263,7 +263,7 @@ public class ListPreference extends DialogPreference {
                         * click, and dismisses the dialog.
                         */
                        ListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                        dialog.dismiss();
                        postDismiss();
                    }
        });