Java 类android.widget.DatePicker.OnDateChangedListener 实例源码

项目:365browser    文件:DateDialogNormalizer.java   
/**
 * 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);
}
项目:AndroidSurvey    文件:DateFragment.java   
@Override
protected void createResponseComponent(ViewGroup responseComponent) {
    datePicker = new DatePicker(getActivity());
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    datePicker.setLayoutParams(params);
    Calendar c = Calendar.getInstance();
    datePicker.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH),
            new OnDateChangedListener() {
                @Override
                public void onDateChanged(DatePicker view, int newYear, int newMonth, int newDay) {
                    getResponse().setResponse((newMonth + 1) + "-" + newDay + "-" + newYear);
                }
            });
    responseComponent.addView(datePicker);
    updateDate(getResponse().getText());
}
项目:AndroidSurvey    文件:DateQuestionFragment.java   
protected DatePicker beforeAddViewHook(ViewGroup component) {
    DatePicker datePicker = new DatePicker(getActivity());
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    datePicker.setLayoutParams(params);
    datePicker.setCalendarViewShown(false);
    Calendar c = Calendar.getInstance();
    datePicker.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH),
            new OnDateChangedListener() {
                @Override
                public void onDateChanged(DatePicker view, int newYear,
                                          int newMonth, int newDay) {
                    mDay = newDay;
                    mMonth = newMonth;
                    mYear = newYear;
                    setResponseText();
                }
            });
    component.addView(datePicker);
    return datePicker;
}
项目:android-chromium-view    文件:DateDialogNormalizer.java   
/**
 * 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);
}
项目:android-chromium    文件:DateDialogNormalizer.java   
/**
 * 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);
}
项目:chromium_webview    文件:DateDialogNormalizer.java   
/**
 * 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 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);
}
项目:cordova-android-chromium    文件:DateDialogNormalizer.java   
/**
 * 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);
}
项目:matchmylife    文件:ProfileEditFragment.java   
private void initView(View view) {
    final OnDateChangedListener dateChangedListener = this;
    dateButton = (Button) view.findViewById(R.id.buttonDate);
    dateButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            DatePickerFragment datePickerFragment = new DatePickerFragment();
            datePickerFragment.setProfileAndOnDateChangedListener(profile, dateChangedListener);
            datePickerFragment.show(getActivity().getSupportFragmentManager(), "datePicker");
        }
    });
    updateButtonText();

    nameView = (EditText) view.findViewById(R.id.editTextName);
    if (profile.getName() != null) {
        nameView.setText(profile.getName());
    }
}
项目:DouDouToDoList    文件:EditItemView.java   
private void onDateButtonClicked()
{
    mDateLayout = (LinearLayout)mLayoutInflater.inflate(R.layout.date_dialog, null);
    mDatePicker = (DatePicker)mDateLayout.findViewById(R.id.date_picker);
    final Calendar calendar = Calendar.getInstance();
    mDatePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), new OnDateChangedListener() {

        @Override
        public void onDateChanged(DatePicker view, int year, int monthOfYear,
                int dayOfMonth) {
            // TODO Auto-generated method stub
            mToDoItemInfo.setDate_year(year);
            mToDoItemInfo.setDate_month(monthOfYear);
            mToDoItemInfo.setDate_day(dayOfMonth);
            mDateString = mToDoItemInfo.getDateString();
        }
    });
    new AlertDialog.Builder(mContext)
    .setTitle(getResources().getString(R.string.date_dialog_title))
    .setView(mDateLayout)
    .setPositiveButton(getResources().getString(R.string.date_dialog_save_button_default_text), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            if(mDateString == null){
                mDateString = String.format("%04d-%02d-%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
            }
            mDateButton.setText(mDateString);
        }
    })
    .setNegativeButton(getResources().getString(R.string.date_dialog_cancel_button_default_text), null)
    .show();
}
项目:DouDouToDoList    文件:EditItemView.java   
private void onDateButtonClicked()
{
    mDateLayout = (LinearLayout)mLayoutInflater.inflate(R.layout.date_dialog, null);
    mDatePicker = (DatePicker)mDateLayout.findViewById(R.id.date_picker);
    final Calendar calendar = Calendar.getInstance();
    mDatePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), new OnDateChangedListener() {

        @Override
        public void onDateChanged(DatePicker view, int year, int monthOfYear,
                int dayOfMonth) {
            // TODO Auto-generated method stub
            mToDoItemInfo.setDate_year(year);
            mToDoItemInfo.setDate_month(monthOfYear);
            mToDoItemInfo.setDate_day(dayOfMonth);
            mDateString = mToDoItemInfo.getDateString();
        }
    });
    new AlertDialog.Builder(mContext)
    .setTitle(getResources().getString(R.string.date_dialog_title))
    .setView(mDateLayout)
    .setPositiveButton(getResources().getString(R.string.date_dialog_save_button_default_text), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            if(mDateString == null){
                mDateString = String.format("%04d-%02d-%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
            }
            mDateButton.setText(mDateString);
        }
    })
    .setNegativeButton(getResources().getString(R.string.date_dialog_cancel_button_default_text), null)
    .show();
}
项目:androidBits    文件:DbDateTime.java   
/**
 * Convenience function to set the picker date.
 * @param aCal - Date to set, if null, use getNow().
 * @param aDatePicker - Widget to set.
 * @param aListener - part of the Widget's params
 * @return Returns the Calendar object used.
 */
static public Calendar setDateToDatePicker(Calendar aCal, DatePicker aDatePicker, OnDateChangedListener aListener) {
    if (aCal==null)
        aCal = getNow();
    if (aDatePicker!=null)
        aDatePicker.init(aCal.get(Calendar.YEAR),aCal.get(Calendar.MONTH),aCal.get(Calendar.DAY_OF_MONTH),aListener);
    return aCal;
}
项目:SlideDateTimePicker    文件:DateFragment.java   
/**
 * 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;
}
项目:SlideDateTimePicker-master    文件:DateFragment.java   
/**
 * 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;
}
项目:matchmylife    文件:DatePickerFragment.java   
public void setProfileAndOnDateChangedListener(Profile profile, OnDateChangedListener listener) {
    this.profile = profile;
    this.listener = listener;
}