This source file includes following definitions.
- onDateTimeSet
- onClick
- tryNotifyDateTimeSet
- onStop
- onDateChanged
- onTimeChanged
- updateDateTime
package org.chromium.content.browser.input;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Build;
import android.text.format.Time;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
import org.chromium.content.R;
class DateTimePickerDialog extends AlertDialog implements OnClickListener,
OnDateChangedListener, OnTimeChangedListener {
private final DatePicker mDatePicker;
private final TimePicker mTimePicker;
private final OnDateTimeSetListener mCallBack;
private final long mMinTimeMillis;
private final long mMaxTimeMillis;
public interface OnDateTimeSetListener {
void onDateTimeSet(DatePicker dateView, TimePicker timeView, int year, int monthOfYear,
int dayOfMonth, int hourOfDay, int minute);
}
public DateTimePickerDialog(Context context,
OnDateTimeSetListener callBack,
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay, int minute, boolean is24HourView,
double min, double max) {
super(context, 0);
mMinTimeMillis = (long) min;
mMaxTimeMillis = (long) max;
mCallBack = callBack;
setButton(BUTTON_POSITIVE, context.getText(
R.string.date_picker_dialog_set), this);
setButton(BUTTON_NEGATIVE, context.getText(android.R.string.cancel),
(OnClickListener) null);
setIcon(0);
setTitle(context.getText(R.string.date_time_picker_dialog_title));
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.date_time_picker_dialog, null);
setView(view);
mDatePicker = (DatePicker) view.findViewById(R.id.date_picker);
DateDialogNormalizer.normalize(mDatePicker, this,
year, monthOfYear, dayOfMonth, hourOfDay, minute, mMinTimeMillis, mMaxTimeMillis);
mTimePicker = (TimePicker) view.findViewById(R.id.time_picker);
mTimePicker.setIs24HourView(is24HourView);
mTimePicker.setCurrentHour(hourOfDay);
mTimePicker.setCurrentMinute(minute);
mTimePicker.setOnTimeChangedListener(this);
onTimeChanged(mTimePicker, mTimePicker.getCurrentHour(),
mTimePicker.getCurrentMinute());
}
@Override
public void onClick(DialogInterface dialog, int which) {
tryNotifyDateTimeSet();
}
private void tryNotifyDateTimeSet() {
if (mCallBack != null) {
mDatePicker.clearFocus();
mCallBack.onDateTimeSet(mDatePicker, mTimePicker, mDatePicker.getYear(),
mDatePicker.getMonth(), mDatePicker.getDayOfMonth(),
mTimePicker.getCurrentHour(), mTimePicker.getCurrentMinute());
}
}
@Override
protected void onStop() {
if (Build.VERSION.SDK_INT >= 16) {
tryNotifyDateTimeSet();
}
super.onStop();
}
@Override
public void onDateChanged(DatePicker view, int year,
int month, int day) {
if (mTimePicker != null) {
onTimeChanged(mTimePicker, mTimePicker.getCurrentHour(),
mTimePicker.getCurrentMinute());
}
}
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
Time time = new Time();
time.set(0, mTimePicker.getCurrentMinute(),
mTimePicker.getCurrentHour(), mDatePicker.getDayOfMonth(),
mDatePicker.getMonth(), mDatePicker.getYear());
if (time.toMillis(true) < mMinTimeMillis) {
time.set(mMinTimeMillis);
} else if (time.toMillis(true) > mMaxTimeMillis) {
time.set(mMaxTimeMillis);
}
mTimePicker.setCurrentHour(time.hour);
mTimePicker.setCurrentMinute(time.minute);
}
public void updateDateTime(int year, int monthOfYear, int dayOfMonth,
int hourOfDay, int minutOfHour) {
mDatePicker.updateDate(year, monthOfYear, dayOfMonth);
mTimePicker.setCurrentHour(hourOfDay);
mTimePicker.setCurrentMinute(minutOfHour);
}
}