Java Code Examples for android.widget.DatePicker#init()
The following examples show how to use
android.widget.DatePicker#init() .
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 |
/** * 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: DatePickerDialog.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
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; }
Example 3
Source File: DateTimePickDialogUtil.java From VideoMeeting with Apache License 2.0 | 6 votes |
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)); }
Example 4
Source File: CalendarTool.java From zidoorecorder with Apache License 2.0 | 6 votes |
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)); }
Example 5
Source File: DateDialogNormalizer.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * 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 6
Source File: DateDialogNormalizer.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * 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 7
Source File: DialogUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 年月选择对话框 * * @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(); }
Example 8
Source File: DateFilterActivity.java From financisto with GNU General Public License v2.0 | 5 votes |
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)); }
Example 9
Source File: SimpleDateDialog.java From SimpleDialogFragments with Apache License 2.0 | 5 votes |
@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; }
Example 10
Source File: SimpleDateDialog.java From SimpleDialogFragments with Apache License 2.0 | 5 votes |
@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; }
Example 11
Source File: DatePreference.java From callmeter with GNU General Public License v3.0 | 5 votes |
/** * {@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; }
Example 12
Source File: QuickDatePickerDialog.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * 隐藏日,只选择年月 */ 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); } }
Example 13
Source File: DateEventSkillViewFragment.java From Easer with GNU General Public License v3.0 | 4 votes |
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); }
Example 14
Source File: DateSkillViewFragment.java From Easer with GNU General Public License v3.0 | 4 votes |
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); }