Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/input/InputDialogContainer.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/input/InputDialogContainer.java b/content/public/android/java/src/org/chromium/content/browser/input/InputDialogContainer.java |
| index bca0f01b39ea86a09228f2609fa261fbfba54414..f87bce53997d406af0b6d952dbef786edc4db1d2 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/input/InputDialogContainer.java |
| +++ b/content/public/android/java/src/org/chromium/content/browser/input/InputDialogContainer.java |
| @@ -5,6 +5,7 @@ |
| package org.chromium.content.browser.input; |
| import android.app.AlertDialog; |
| +import android.app.AlertDialog; |
|
Miguel Garcia
2013/10/08 17:44:40
double import
keishi
2013/10/21 17:00:58
Done.
|
| import android.app.DatePickerDialog; |
| import android.app.TimePickerDialog; |
| import android.app.DatePickerDialog.OnDateSetListener; |
| @@ -15,7 +16,13 @@ import android.content.DialogInterface.OnDismissListener; |
| import android.text.TextUtils; |
| import android.text.format.DateFormat; |
| import android.text.format.Time; |
| +import android.view.LayoutInflater; |
| +import android.view.View; |
| +import android.widget.AdapterView; |
| import android.widget.DatePicker; |
| +import android.widget.ListView; |
| +import android.widget.SimpleAdapter; |
| +import android.widget.TextView; |
| import android.widget.TimePicker; |
| import org.chromium.content.browser.input.DateTimePickerDialog.OnDateTimeSetListener; |
| @@ -23,10 +30,15 @@ import org.chromium.content.browser.input.MultiFieldTimePickerDialog.OnMultiFiel |
| import org.chromium.content.browser.input.TwoFieldDatePickerDialog; |
| import org.chromium.content.R; |
| +import java.util.Arrays; |
| import java.text.ParseException; |
| import java.text.SimpleDateFormat; |
| import java.util.Calendar; |
| import java.util.Date; |
| +import java.util.List; |
| +import java.util.Map; |
| +import java.util.HashMap; |
| +import java.util.ArrayList; |
| public class InputDialogContainer { |
| @@ -34,6 +46,7 @@ public class InputDialogContainer { |
| void cancelDateTimeDialog(); |
| void replaceDateTime(int dialogType, |
| int year, int month, int day, int hour, int minute, int second, int milli, int week); |
| + void acceptDataListSuggestion(String value); |
| } |
| // Default values used in Time representations of selected date/time before formatting. |
| @@ -108,9 +121,91 @@ public class InputDialogContainer { |
| return result; |
| } |
| + void showSuggestionDialog(final int dialogType, |
|
Miguel Garcia
2013/10/08 17:44:40
Add javadoc.
Can this be private?
I think this sh
|
| + final int year, final int month, final int monthDay, |
| + final int hour, final int minute, final int second, final int milli, final int week, |
| + final double min, final double max, final double step, |
| + DateTimeSuggestion[] suggestions) { |
| + if (isDialogShowing()) mDialog.dismiss(); |
| + |
| + ListView suggestionListView = new ListView(mContext); |
| + LayoutInflater inflater = |
|
newt (away)
2013/10/09 07:20:52
unused variable
keishi
2013/10/21 17:00:58
Done.
|
| + (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| + ArrayList<DateTimeSuggestion> suggestionList = |
| + new ArrayList<DateTimeSuggestion>(Arrays.asList(suggestions)); |
| + final DateTimeSuggestionListAdapter adapter = |
| + new DateTimeSuggestionListAdapter(mContext, suggestionList); |
|
Miguel Garcia
2013/10/08 17:44:40
nit: no need for the suggestionList temp variable,
keishi
2013/10/21 17:00:58
Done.
|
| + suggestionListView.setAdapter(adapter); |
| + suggestionListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { |
| + @Override |
| + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| + if (position == adapter.getCount() - 1) { |
| + showPickerDialog(dialogType, year, month, monthDay, |
| + hour, minute, second, milli, |
| + week, min, max, step); |
| + } else { |
| + mInputActionDelegate.acceptDataListSuggestion(adapter.getItem(position).mValue); |
|
Miguel Garcia
2013/10/08 17:44:40
can you call replaceDateTime with the right values
keishi
2013/10/21 17:00:58
Done.
|
| + mDialogAlreadyDismissed = true; |
| + } |
| + } |
| + }); |
| + |
| + int dialogTitleId = R.string.date_picker_dialog_title; |
|
Miguel Garcia
2013/10/08 17:44:40
How does this layout on a phone, it seems the desi
keishi
2013/10/21 17:00:58
I don't have a device with a small screen so here
|
| + if (dialogType == sTextInputTypeTime) { |
| + dialogTitleId = R.string.time_picker_dialog_title; |
| + } else if (dialogType == sTextInputTypeDateTime || |
| + dialogType == sTextInputTypeDateTimeLocal) { |
| + dialogTitleId = R.string.date_time_picker_dialog_title; |
| + } else if (dialogType == sTextInputTypeMonth) { |
| + dialogTitleId = R.string.month_picker_dialog_title; |
| + } else if (dialogType == sTextInputTypeWeek) { |
| + dialogTitleId = R.string.week_picker_dialog_title; |
| + } |
| + |
| + mDialog = new AlertDialog.Builder(mContext) |
| + .setTitle(dialogTitleId) |
| + .setView(suggestionListView) |
| + .setOnDismissListener(new DialogInterface.OnDismissListener() { |
| + @Override |
| + public void onDismiss(DialogInterface dialog) { |
| + if (mDialog == dialog && !mDialogAlreadyDismissed) { |
| + mDialogAlreadyDismissed = true; |
| + mInputActionDelegate.cancelDateTimeDialog(); |
| + } |
| + } |
| + }) |
| + .setNegativeButton(mContext.getText(android.R.string.cancel), |
| + new DialogInterface.OnClickListener() { |
| + @Override |
| + public void onClick(DialogInterface dialog, int which) { |
| + mDialogAlreadyDismissed = true; |
|
newt (away)
2013/10/09 07:20:52
Can you replace lines 181-182 with "mDialog.dismis
keishi
2013/10/21 17:00:58
Done.
|
| + mInputActionDelegate.cancelDateTimeDialog(); |
| + } |
| + }) |
| + .create(); |
| + |
| + mDialogAlreadyDismissed = false; |
| + mDialog.show(); |
| + } |
| + |
| void showDialog(final int dialogType, int year, int month, int monthDay, |
| int hour, int minute, int second, int milli, int week, |
| - double min, double max, double step) { |
| + double min, double max, double step, |
| + DateTimeSuggestion[] suggestions) { |
| + if (suggestions == null) { |
| + showPickerDialog(dialogType, year, month, monthDay, |
| + hour, minute, second, milli, |
| + week, min, max, step); |
| + } else { |
| + showSuggestionDialog(dialogType, year, month, monthDay, |
| + hour, minute, second, milli, week, |
| + min, max, step, suggestions); |
| + } |
| + } |
| + |
| + void showPickerDialog(final int dialogType, int year, int month, int monthDay, |
| + int hour, int minute, int second, int milli, int week, |
| + double min, double max, double step) { |
| if (isDialogShowing()) mDialog.dismiss(); |
|
Miguel Garcia
2013/10/08 17:44:40
can you move this check to the showDialog call ins
keishi
2013/10/21 17:00:58
Done.
|
| // Java Date dialogs like longs but Blink prefers doubles.. |