Merge "Dismiss Dialog in post instead of immediately"
This commit is contained in:
@@ -77,6 +77,14 @@ public abstract class DialogPreference extends Preference implements
|
|||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
private int mWhichButtonClicked;
|
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(
|
public DialogPreference(
|
||||||
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
@@ -324,10 +332,29 @@ public abstract class DialogPreference extends Preference implements
|
|||||||
if (needInputMethod()) {
|
if (needInputMethod()) {
|
||||||
requestInputMethod(dialog);
|
requestInputMethod(dialog);
|
||||||
}
|
}
|
||||||
|
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||||
|
@Override
|
||||||
|
public void onShow(DialogInterface dialog) {
|
||||||
|
removeDismissCallbacks();
|
||||||
|
}
|
||||||
|
});
|
||||||
dialog.setOnDismissListener(this);
|
dialog.setOnDismissListener(this);
|
||||||
dialog.show();
|
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
|
* 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
|
* 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;
|
mWhichButtonClicked = which;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onDismiss(DialogInterface dialog) {
|
public void onDismiss(DialogInterface dialog) {
|
||||||
|
removeDismissCallbacks();
|
||||||
getPreferenceManager().unregisterOnActivityDestroyListener(this);
|
getPreferenceManager().unregisterOnActivityDestroyListener(this);
|
||||||
|
|
||||||
mDialog = null;
|
mDialog = null;
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ public class ListPreference extends DialogPreference {
|
|||||||
* click, and dismisses the dialog.
|
* click, and dismisses the dialog.
|
||||||
*/
|
*/
|
||||||
ListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
ListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
||||||
dialog.dismiss();
|
postDismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user