Index: content/public/android/java/src/org/chromium/content/browser/InputDialogContainer.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/InputDialogContainer.java b/content/public/android/java/src/org/chromium/content/browser/InputDialogContainer.java |
index 389b4fd9adb75e30af47ebdd2fa92f0da95e4d03..d9a5d817ee5fc3bc56cd123b02f33ec3d5b7e495 100644 |
--- a/content/public/android/java/src/org/chromium/content/browser/InputDialogContainer.java |
+++ b/content/public/android/java/src/org/chromium/content/browser/InputDialogContainer.java |
@@ -64,7 +64,13 @@ class InputDialogContainer { |
private static int sTextInputTypeTime; |
private Context mContext; |
- private boolean mDialogCanceled; |
+ |
+ // Prevents sending two notifications (from onClick and from onDismiss) |
+ private boolean mDialogAlreadyDismissed; |
+ |
+ // Distinguishes between pressing the cancel button and dismissing the |
+ // dialog through other means (like pressing back on the device) |
+ private boolean mShouldSendCancelation; |
Peter Beverloo
2012/12/05 11:57:03
nit: \n after this as the coment doesn't apply to
Miguel Garcia
2012/12/05 16:23:16
Done.
|
private AlertDialog mDialog; |
private InputActionDelegate mInputActionDelegate; |
@@ -118,7 +124,8 @@ class InputDialogContainer { |
new DialogInterface.OnClickListener() { |
@Override |
public void onClick(DialogInterface dialog, int which) { |
- mDialogCanceled = true; |
+ mDialogAlreadyDismissed = true; |
+ mShouldSendCancelation = true; |
} |
}); |
@@ -127,7 +134,7 @@ class InputDialogContainer { |
new DialogInterface.OnClickListener() { |
@Override |
public void onClick(DialogInterface dialog, int which) { |
- mDialogCanceled = true; |
+ mDialogAlreadyDismissed = true; |
mInputActionDelegate.replaceText(""); |
} |
}); |
@@ -135,10 +142,14 @@ class InputDialogContainer { |
mDialog.setOnDismissListener(new OnDismissListener() { |
@Override |
Peter Beverloo
2012/12/05 11:57:03
nit: This is indented with 12 spaces for no appare
Miguel Garcia
2012/12/05 16:23:16
Done.
|
public void onDismiss(DialogInterface dialog) { |
+ if (mShouldSendCancelation) { |
+ mShouldSendCancelation = false; |
mInputActionDelegate.clearFocus(); |
+ } |
} |
}); |
- mDialogCanceled = false; |
+ mDialogAlreadyDismissed = false; |
+ mShouldSendCancelation = false; |
mDialog.show(); |
} |
@@ -200,7 +211,7 @@ class InputDialogContainer { |
private class DateListener implements OnDateSetListener { |
@Override |
public void onDateSet(DatePicker view, int year, int month, int monthDay) { |
- if (!mDialogCanceled) { |
+ if (!mDialogAlreadyDismissed) { |
setFieldDateTimeValue(year, month, monthDay, HOUR_DEFAULT, MINUTE_DEFAULT, |
HTML_DATE_FORMAT); |
} |
@@ -210,7 +221,7 @@ class InputDialogContainer { |
private class TimeListener implements OnTimeSetListener { |
@Override |
public void onTimeSet(TimePicker view, int hourOfDay, int minute) { |
- if (!mDialogCanceled) { |
+ if (!mDialogAlreadyDismissed) { |
setFieldDateTimeValue(YEAR_DEFAULT, MONTH_DEFAULT, MONTHDAY_DEFAULT, |
hourOfDay, minute, HTML_TIME_FORMAT); |
} |
@@ -228,7 +239,7 @@ class InputDialogContainer { |
public void onDateTimeSet(DatePicker dateView, TimePicker timeView, |
int year, int month, int monthDay, |
int hourOfDay, int minute) { |
- if (!mDialogCanceled) { |
+ if (!mDialogAlreadyDismissed) { |
setFieldDateTimeValue(year, month, monthDay, hourOfDay, minute, |
mLocal ? HTML_DATE_TIME_LOCAL_FORMAT : HTML_DATE_TIME_FORMAT); |
} |
@@ -238,7 +249,7 @@ class InputDialogContainer { |
private class MonthListener implements OnMonthSetListener { |
@Override |
public void onMonthSet(MonthPicker view, int year, int month) { |
- if (!mDialogCanceled) { |
+ if (!mDialogAlreadyDismissed) { |
setFieldDateTimeValue(year, month, MONTHDAY_DEFAULT, |
HOUR_DEFAULT, MINUTE_DEFAULT, HTML_MONTH_FORMAT); |
} |
@@ -247,6 +258,10 @@ class InputDialogContainer { |
private void setFieldDateTimeValue(int year, int month, int monthDay, int hourOfDay, |
int minute, String dateFormat) { |
+ // Just in case more than one signal is triggered by the dialog so that |
+ // no more than one callback is sent to the native side. |
Peter Beverloo
2012/12/05 11:57:03
nit: Maybe phrase as "Prevents more than one callb
Miguel Garcia
2012/12/05 16:23:16
Done.
|
+ mDialogAlreadyDismissed = true; |
+ |
Time time = new Time(); |
time.year = year; |
time.month = month; |