android.widget.DatePicker.OnDateChangedListener Java Examples

The following examples show how to use android.widget.DatePicker.OnDateChangedListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DateDialogNormalizer.java    From 365browser with Apache License 2.0 7 votes vote down vote up
/**
 * Sets the current, min, and max values on the given DatePicker and ensures that
 * min <= current <= max, adjusting current and max if needed.
 *
 * @param year The current year to set.
 * @param month The current month to set. 0-based.
 * @param day The current day to set.
 * @param minMillisUtc The minimum allowed date, in milliseconds from the epoch according to a
 *                     proleptic Gregorian calendar (no Julian switch).
 * @param maxMillisUtc The maximum allowed date, in milliseconds from the epoch according to a
 *                     proleptic Gregorian calendar (no Julian switch).
 */
public static void normalize(DatePicker picker, final OnDateChangedListener listener,
        int year, int month, int day, long minMillisUtc, long maxMillisUtc) {
    DateAndMillis currentDate = DateAndMillis.create(year, month, day);
    DateAndMillis minDate = DateAndMillis.create(minMillisUtc);
    DateAndMillis maxDate = DateAndMillis.create(maxMillisUtc);

    // Ensure min <= current <= max, adjusting current and max if needed.
    if (maxDate.millisForPicker < minDate.millisForPicker) {
        maxDate = minDate;
    }
    if (currentDate.millisForPicker < minDate.millisForPicker) {
        currentDate = minDate;
    } else if (currentDate.millisForPicker > maxDate.millisForPicker) {
        currentDate = maxDate;
    }

    setLimits(picker, currentDate.millisForPicker, minDate.millisForPicker,
            maxDate.millisForPicker);
    picker.init(currentDate.year, currentDate.month, currentDate.day, listener);
}
 
Example #2
Source File: DateDialogNormalizer.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Normalizes an existing DateDialogPicker changing the default date if
 * needed to comply with the {@code min} and {@code max} attributes.
 */
static void normalize(DatePicker picker, OnDateChangedListener listener,
        int year, int month, int day, int hour, int minute, long min, long max) {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    calendar.clear();
    calendar.set(year, month, day, hour, minute, 0);
    if (calendar.getTimeInMillis() < min) {
        calendar.clear();
        calendar.setTimeInMillis(min);
    } else if (calendar.getTimeInMillis() > max) {
        calendar.clear();
        calendar.setTimeInMillis(max);
    }
    picker.init(
            calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH), listener);

    setLimits(picker, min, max);
}
 
Example #3
Source File: DateDialogNormalizer.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Normalizes an existing DateDialogPicker changing the default date if
 * needed to comply with the {@code min} and {@code max} attributes.
 */
static void normalize(DatePicker picker, OnDateChangedListener listener,
        int year, int month, int day, int hour, int minute, long min, long max) {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    calendar.clear();
    calendar.set(year, month, day, hour, minute, 0);
    if (calendar.getTimeInMillis() < min) {
        calendar.clear();
        calendar.setTimeInMillis(min);
    } else if (calendar.getTimeInMillis() > max) {
        calendar.clear();
        calendar.setTimeInMillis(max);
    }
    picker.init(
            calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH), listener);

    setLimits(picker, min, max);
}
 
Example #4
Source File: DateFragment.java    From SlideDateTimePicker with Apache License 2.0 4 votes vote down vote up
/**
 * Create and return the user interface view for this fragment.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState)
{
    int theme = getArguments().getInt("theme");
    int initialYear = getArguments().getInt("year");
    int initialMonth = getArguments().getInt("month");
    int initialDay = getArguments().getInt("day");
    Date minDate = (Date) getArguments().getSerializable("minDate");
    Date maxDate = (Date) getArguments().getSerializable("maxDate");

    // Unless we inflate using a cloned inflater with a Holo theme,
    // on Lollipop devices the DatePicker will be the new-style
    // DatePicker, which is not what we want. So we will
    // clone the inflater that we're given but with our specified
    // theme, then inflate the layout with this new inflater.

    Context contextThemeWrapper = new ContextThemeWrapper(
            getActivity(),
            theme == SlideDateTimePicker.HOLO_DARK ?
                     android.R.style.Theme_Holo :
                     android.R.style.Theme_Holo_Light);

    LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);

    View v = localInflater.inflate(R.layout.fragment_date, container, false);

    mDatePicker = (CustomDatePicker) v.findViewById(R.id.datePicker);
    // block keyboard popping up on touch
    mDatePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
    mDatePicker.init(
        initialYear,
        initialMonth,
        initialDay,
        new OnDateChangedListener() {

            @Override
            public void onDateChanged(DatePicker view, int year,
                    int monthOfYear, int dayOfMonth)
            {
                mCallback.onDateChanged(year, monthOfYear, dayOfMonth);
            }
        });

    if (minDate != null)
        mDatePicker.setMinDate(minDate.getTime());

    if (maxDate != null)
        mDatePicker.setMaxDate(maxDate.getTime());

    return v;
}