Merge "Add a null check for getWindow()" am: 3c69948e6a

am: 71f52a6a0d

Change-Id: I41fbd9c87b360f7d4fd049cb313856bceeff0dee
This commit is contained in:
Siarhei Vishniakou
2019-03-08 06:04:23 -08:00
committed by android-build-merger

View File

@@ -342,16 +342,31 @@ public abstract class DialogPreference extends Preference implements
dialog.show(); dialog.show();
} }
/**
* Get the DecorView.
* @return the DecorView for the current dialog window, if it exists.
* If the window does not exist, null is returned.
*/
private View getDecorView() {
if (mDialog != null && mDialog.getWindow() != null) {
return mDialog.getWindow().getDecorView();
}
return null;
}
void postDismiss() { void postDismiss() {
removeDismissCallbacks(); removeDismissCallbacks();
View decorView = mDialog.getWindow().getDecorView(); View decorView = getDecorView();
if (decorView != null) {
// If decorView is null, dialog was already dismissed
decorView.post(mDismissRunnable); decorView.post(mDismissRunnable);
} }
}
private void removeDismissCallbacks() { private void removeDismissCallbacks() {
if (mDialog != null && mDialog.getWindow() != null View decorView = getDecorView();
&& mDialog.getWindow().getDecorView() != null) { if (decorView != null) {
mDialog.getWindow().getDecorView().removeCallbacks(mDismissRunnable); decorView.removeCallbacks(mDismissRunnable);
} }
} }