This source file includes following definitions.
- setLimits
- trimToDate
- normalize
package org.chromium.content.browser.input;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import java.util.Calendar;
import java.util.TimeZone;
class DateDialogNormalizer {
private static void setLimits(DatePicker picker, long minMillis, long maxMillis) {
if (maxMillis <= minMillis) {
return;
}
Calendar minCal = trimToDate(minMillis);
Calendar maxCal = trimToDate(maxMillis);
int currentYear = picker.getYear();
int currentMonth = picker.getMonth();
int currentDayOfMonth = picker.getDayOfMonth();
picker.updateDate(maxCal.get(Calendar.YEAR),
maxCal.get(Calendar.MONTH),
maxCal.get(Calendar.DAY_OF_MONTH));
picker.setMinDate(minCal.getTimeInMillis());
picker.updateDate(minCal.get(Calendar.YEAR),
minCal.get(Calendar.MONTH),
minCal.get(Calendar.DAY_OF_MONTH));
picker.setMaxDate(maxCal.getTimeInMillis());
picker.updateDate(currentYear, currentMonth, currentDayOfMonth);
}
private static Calendar trimToDate(long time) {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.clear();
cal.setTimeInMillis(time);
Calendar result = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
result.clear();
result.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH),
0, 0, 0);
return result;
}
static void normalize(DatePicker picker, OnDateChangedListener listener,
int year, int month, int day, int hour, int minute, long minMillis, long maxMillis) {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar.clear();
calendar.set(year, month, day, hour, minute, 0);
if (calendar.getTimeInMillis() < minMillis) {
calendar.clear();
calendar.setTimeInMillis(minMillis);
} else if (calendar.getTimeInMillis() > maxMillis) {
calendar.clear();
calendar.setTimeInMillis(maxMillis);
}
picker.init(
calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH), listener);
setLimits(picker, minMillis, maxMillis);
}
}