android.widget.DatePicker#init ( )源码实例Demo

下面列出了android.widget.DatePicker#init ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: DatePickerDialog.java
private DatePickerDialog(@NonNull Context context, @StyleRes int themeResId,
        @Nullable OnDateSetListener listener, @Nullable Calendar calendar, int year,
        int monthOfYear, int dayOfMonth) {
    super(context, resolveDialogTheme(context, themeResId));

    final Context themeContext = getContext();
    final LayoutInflater inflater = LayoutInflater.from(themeContext);
    final View view = inflater.inflate(R.layout.date_picker_dialog, null);
    setView(view);

    setButton(BUTTON_POSITIVE, themeContext.getString(R.string.ok), this);
    setButton(BUTTON_NEGATIVE, themeContext.getString(R.string.cancel), this);
    setButtonPanelLayoutHint(LAYOUT_HINT_SIDE);

    if (calendar != null) {
        year = calendar.get(Calendar.YEAR);
        monthOfYear = calendar.get(Calendar.MONTH);
        dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
    }

    mDatePicker = (DatePicker) view.findViewById(R.id.datePicker);
    mDatePicker.init(year, monthOfYear, dayOfMonth, this);
    mDatePicker.setValidationCallback(mValidationCallback);

    mDateSetListener = listener;
}
 
源代码2 项目: VideoMeeting   文件: DateTimePickDialogUtil.java
public void init(DatePicker datePicker, TimePicker timePicker) {
    Calendar calendar = Calendar.getInstance();
    if (!(null == initDateTime || "".equals(initDateTime))) {
        calendar = this.getCalendarByInintData(initDateTime);
    } else {
        initDateTime = calendar.get(Calendar.YEAR) + "年"
                + calendar.get(Calendar.MONTH) + "月"
                + calendar.get(Calendar.DAY_OF_MONTH) + "日 "
                + calendar.get(Calendar.HOUR_OF_DAY) + ":"
                + calendar.get(Calendar.MINUTE);
    }

    datePicker.init(calendar.get(Calendar.YEAR),
            calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH), this);
    timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
    timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));
}
 
源代码3 项目: zidoorecorder   文件: CalendarTool.java
public void init(DatePicker datePicker, TimePicker timePicker) {
	Calendar calendar = Calendar.getInstance();
	// if (!(null == initDateTime || "".equals(initDateTime))) {
	// calendar = this.getCalendarByInintData(initDateTime);
	// } else {
	initDateTime = calendar.get(Calendar.YEAR) + "年"
			+ calendar.get(Calendar.MONTH) + "月"
			+ calendar.get(Calendar.DAY_OF_MONTH) + "日 "
			+ calendar.get(Calendar.HOUR_OF_DAY) + ":"
			+ calendar.get(Calendar.MINUTE);
	// }

	datePicker.init(calendar.get(Calendar.YEAR),
			calendar.get(Calendar.MONTH),
			calendar.get(Calendar.DAY_OF_MONTH), this);
	timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
	timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));

}
 
源代码4 项目: 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);
}
 
源代码5 项目: 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);
}
 
源代码6 项目: 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);
}
 
源代码7 项目: quickhybrid-android   文件: DialogUtil.java
/**
 * 年月选择对话框
 *
 * @param con
 * @param title
 * @param calendar
 * @param listener
 */
public static void pickMonth(Context con, String title, Calendar calendar, final OnDateSetListener listener) {
    LinearLayout ll = new LinearLayout(con);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    ll.setLayoutParams(layoutParams);
    ll.setOrientation(LinearLayout.VERTICAL);
    //添加一条线
    LinearLayout line = new LinearLayout(con);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
    line.setBackgroundColor(con.getResources().getColor(R.color.line));
    line.setLayoutParams(lp);
    ll.addView(line);
    //添加选择器控件
    final DatePicker datePicker = new DatePicker(con, null, themeId);
    datePicker.setLayoutParams(layoutParams);
    datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), null);
    datePicker.setCalendarViewShown(false);
    ll.addView(datePicker);
    //初始化对话框
    QuickDialog.Builder builder = new QuickDialog.Builder(con);
    builder.setContentView(ll);
    builder.setTitle(title);
    builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            listener.onDateSet(datePicker, datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
        }
    });
    builder.create().show();
}
 
源代码8 项目: financisto   文件: DateFilterActivity.java
private void prepareDialog(Dialog dialog, Calendar c) {
	DatePicker dp = dialog.findViewById(R.id.date);
	dp.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), null);
	TimePicker tp = dialog.findViewById(R.id.time);
       tp.setIs24HourView(is24HourFormat(this));
       tp.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
	tp.setCurrentMinute(c.get(Calendar.MINUTE));
}
 
源代码9 项目: SimpleDialogFragments   文件: SimpleDateDialog.java
@Override
protected View onCreateContentView(Bundle savedInstanceState) {

    picker = new DatePicker(getContext());

    Calendar c = Calendar.getInstance();
    if (savedInstanceState != null){
        c.setTimeInMillis(savedInstanceState.getLong(DATE));
    } else if (getArguments().containsKey(DATE)) {
        c.setTimeInMillis(getArguments().getLong(DATE));
    }

    picker.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), this);

    if (getArguments().containsKey(MIN_DATE)) {
        picker.setMinDate(getArguments().getLong(MIN_DATE));
    }
    if (getArguments().containsKey(MAX_DATE)) {
        picker.setMaxDate(getArguments().getLong(MAX_DATE));
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
            && getArguments().containsKey(FIRST_DAY_OF_WEEK)) {
        picker.setFirstDayOfWeek(getArguments().getInt(FIRST_DAY_OF_WEEK));
    }



    return picker;
}
 
源代码10 项目: SimpleDialogFragments   文件: SimpleDateDialog.java
@Override
protected View onCreateContentView(Bundle savedInstanceState) {

    picker = new DatePicker(getContext());

    Calendar c = Calendar.getInstance();
    if (savedInstanceState != null){
        c.setTimeInMillis(savedInstanceState.getLong(DATE));
    } else if (getArguments().containsKey(DATE)) {
        c.setTimeInMillis(getArguments().getLong(DATE));
    }

    picker.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), this);

    if (getArguments().containsKey(MIN_DATE)) {
        picker.setMinDate(getArguments().getLong(MIN_DATE));
    }
    if (getArguments().containsKey(MAX_DATE)) {
        picker.setMaxDate(getArguments().getLong(MAX_DATE));
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
            && getArguments().containsKey(FIRST_DAY_OF_WEEK)) {
        picker.setFirstDayOfWeek(getArguments().getInt(FIRST_DAY_OF_WEEK));
    }



    return picker;
}
 
源代码11 项目: callmeter   文件: DatePreference.java
/**
 * {@inheritDoc}
 */
@Override
protected View onCreateDialogView() {
    final Calendar c = this.getPersitendCalendar(this.defValue);
    final DatePicker dp = new DatePicker(this.getContext());
    dp.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), this);
    return dp;
}
 
/**
 * 隐藏日,只选择年月
 */
public void hideDay() {
    if (Build.VERSION.SDK_INT >= 24) {
        try {
            final Field field = this.findField(DatePickerDialog.class,
                    DatePicker.class, "mDatePicker");

            DatePicker datePicker = (DatePicker) field.get(this);
            final Class<?> delegateClass = Class
                    .forName("android.widget.DatePicker$DatePickerDelegate");
            final Field delegateField = this.findField(DatePicker.class,
                    delegateClass, "mDelegate");

            final Object delegate = delegateField.get(datePicker);
            final Class<?> spinnerDelegateClass = Class
                    .forName("android.widget.DatePickerSpinnerDelegate");

            if (delegate.getClass() != spinnerDelegateClass) {
                delegateField.set(datePicker, null);
                datePicker.removeAllViews();

                final Constructor spinnerDelegateConstructor = spinnerDelegateClass
                        .getDeclaredConstructor(DatePicker.class,
                                Context.class, AttributeSet.class,
                                int.class, int.class);
                spinnerDelegateConstructor.setAccessible(true);

                final Object spinnerDelegate = spinnerDelegateConstructor
                        .newInstance(datePicker, con, null,
                                android.R.attr.datePickerStyle, 0);
                delegateField.set(datePicker, spinnerDelegate);

                datePicker.init(year, monthOfYear, dayOfMonth, this);
                datePicker.setCalendarViewShown(false);
                datePicker.setSpinnersShown(true);
            }
        } catch (Exception e) { /* Do nothing */
        }
    } else {
        ((ViewGroup) ((ViewGroup) getDatePicker().getChildAt(0)).getChildAt(0)).getChildAt(2).setVisibility(View.GONE);
    }
}
 
源代码13 项目: Easer   文件: DateEventSkillViewFragment.java
private static void setDatePicker(DatePicker datePicker, Calendar calendar) {
    datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH), null);
}
 
源代码14 项目: Easer   文件: DateSkillViewFragment.java
private static void setDatePicker(DatePicker datePicker, Calendar calendar) {
    datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH), null);
}