List of usage examples for android.app DatePickerDialog getDatePicker
@NonNull
public DatePicker getDatePicker()
From source file:org.egov.android.view.activity.EditProfileActivity.java
/** * Function used to choose the user dob//from www .j a v a2 s . c o m */ @SuppressLint("NewApi") private void _showDatePicker() { DatePickerDialog datePicker = null; Calendar c = Calendar.getInstance(); int year = 0; int month = 0; int date = 0; if (dateOfBirth.equals("")) { year = c.get(Calendar.YEAR); month = c.get(Calendar.MONTH); date = c.get(Calendar.DAY_OF_MONTH); datePicker = new DatePickerDialog(this, datepicker, year, month, date); } else { String[] birth = dateOfBirth.split("-"); year = Integer.valueOf(birth[0]); month = Integer.valueOf(birth[1]) - 1; date = Integer.valueOf(birth[2]); datePicker = new DatePickerDialog(this, datepicker, date, month, year); } if (apiLevel > 13) { datePicker.getDatePicker().setMaxDate(System.currentTimeMillis()); } datePicker.show(); }
From source file:me.tipi.kiosk.ui.fragments.IdentityFragment.java
/** * Show dob dialog.//w w w . j a v a2 s . c om */ private void showDobDialog() { DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), android.R.style.Theme_Holo_Light_Dialog, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { birthdayLayout.setError(null); Calendar calendar = Calendar.getInstance(); birthDayPickerView.setText( String.format(Locale.US, "%d - %d - %d", dayOfMonth, monthOfYear + 1, year)); calendar.set(year, monthOfYear, dayOfMonth); dob = calendar.getTime(); } }, 1985, 6, 15); DatePicker datePicker = datePickerDialog.getDatePicker(); datePickerDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); styleDatePicker(datePicker); datePickerDialog.show(); }
From source file:rta.ae.sharekni.RegisterNewTest.java
@Override protected Dialog onCreateDialog(int id) { if (id == DILOG_ID) { DatePickerDialog dp = new DatePickerDialog(this, dPickerListener, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); d = dp.getDatePicker(); d.updateDate(year_x, month_x, day_x); d.setMaxDate(cal.getTimeInMillis()); return dp; }/*www .j av a 2 s. com*/ return null; }
From source file:nl.mpcjanssen.simpletask.AddTask.java
private void insertDate(final int dateType) { Dialog d = Util.createDeferDialog(this, dateType, false, new Util.InputDialogListener() { @Override/* w w w . ja va 2s.c o m*/ public void onClick(@NotNull String selected) { if (selected.equals("pick")) { /* Note on some Android versions the OnDateSetListener can fire twice * https://code.google.com/p/android/issues/detail?id=34860 * With the current implementation which replaces the dates this is not an * issue. The date is just replaced twice */ final DateTime today = DateTime.today(TimeZone.getDefault()); DatePickerDialog dialog = new DatePickerDialog(AddTask.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int year, int month, int day) { month++; DateTime date = DateTime.forDateOnly(year, month, day); insertDateAtSelection(dateType, date); } }, today.getYear(), today.getMonth() - 1, today.getDay()); boolean showCalendar = m_app.showCalendar(); dialog.getDatePicker().setCalendarViewShown(showCalendar); dialog.getDatePicker().setSpinnersShown(!showCalendar); dialog.show(); } else { insertDateAtSelection(dateType, Util.addInterval(DateTime.today(TimeZone.getDefault()), selected)); } } }); d.show(); }
From source file:com.QuarkLabs.BTCeClient.fragments.HistoryFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mAdapter = new OrdersAdapter(getActivity(), mHistoryType); mListView = (ListView) getView().findViewById(R.id.HistoryContainer); final EditText startDate = (EditText) getView().findViewById(R.id.StartDateValue); final EditText endDate = (EditText) getView().findViewById(R.id.EndDateValue); startDate.setText(mDateFormat.format(mStartDateValue)); endDate.setText(mDateFormat.format(mEndDateValue)); Button makeQuery = (Button) getView().findViewById(R.id.MakeQueryButton); View.OnClickListener showDatePicker = new View.OnClickListener() { @Override//from w w w .j a v a 2s.co m public void onClick(View v) { final TextView dateValue = (TextView) v; Date date = null; try { date = mDateFormat.parse(dateValue.getText().toString()); } catch (ParseException e) { e.printStackTrace(); } int year = 1999; int month = 0; int day = 1; if (date != null) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); year = calendar.get(Calendar.YEAR); month = calendar.get(Calendar.MONTH); day = calendar.get(Calendar.DAY_OF_MONTH); } DatePickerDialog datePickerDialog = new android.app.DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); if (dateValue.getId() == R.id.StartDateValue) { calendar.setTime(mStartDateValue); calendar.set(year, monthOfYear, dayOfMonth, 0, 0, 0); mStartDateValue = calendar.getTime(); } else { calendar.setTime(mEndDateValue); calendar.set(year, monthOfYear, dayOfMonth, 23, 59, 59); mEndDateValue = calendar.getTime(); } dateValue.setText(mDateFormat.format(calendar.getTime())); } }, year, month, day); datePickerDialog.getDatePicker().setCalendarViewShown(false); datePickerDialog.show(); } }; startDate.setOnClickListener(showDatePicker); endDate.setOnClickListener(showDatePicker); makeQuery.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle bundle = new Bundle(); bundle.putString("startDate", String.valueOf(mStartDateValue.getTime() / 1000)); bundle.putString("endDate", String.valueOf(mEndDateValue.getTime() / 1000)); getLoaderManager().restartLoader(mLoaderId, bundle, HistoryFragment.this); mListView.setAdapter(null); mNoItems.setVisibility(View.GONE); mListView.setEmptyView(mLoadingView); } }); mLoadingView = (ProgressBar) getView().findViewById(R.id.Loading); mNoItems = (TextView) getView().findViewById(R.id.NoItems); mListView.setEmptyView(mLoadingView); }
From source file:cz.tsystems.portablecheckin.MainActivity.java
private void getModelYear(Button theButton) { Calendar c = Calendar.getInstance(); final String dateStr = txtModelYear.getText().toString(); if (!dateStr.isEmpty()) { c.set(Calendar.YEAR, Integer.parseInt(dateStr)); c.set(Calendar.DAY_OF_MONTH, 1); c.set(Calendar.MONTH, 1); }//from w w w . jav a 2 s .c o m DatePickerDialog dialog = new DatePickerDialog(getActivity(), DialogFragment.STYLE_NO_FRAME | DialogFragment.STYLE_NORMAL, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { ((FragmentPagerActivity) getActivity()).unsavedCheckin(); txtModelYear.setText(String.valueOf(year)); btnModelYear.setEnabled(true); } }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); findAndHideField(dialog.getDatePicker(), "mDayPicker"); findAndHideField(dialog.getDatePicker(), "mDaySpinner"); findAndHideField(dialog.getDatePicker(), "mMounthPicker"); findAndHideField(dialog.getDatePicker(), "mMonthSpinner"); dialog.getDatePicker().getCalendarView().setVisibility(View.GONE); dialog.show(); }
From source file:org.openmrs.mobile.activities.addeditpatient.AddEditPatientFragment.java
private void addListeners() { gen.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup rGroup, int checkedId) { gendererror.setVisibility(View.GONE); }/*w ww. ja va2s . co m*/ }); edcountry.setThreshold(2); edcountry.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (edcountry.getText().length() >= edcountry.getThreshold()) { edcountry.showDropDown(); } if (Arrays.asList(countries).contains(edcountry.getText().toString())) { edcountry.dismissDropDown(); } } }); edstate.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { addSuggestionsToCities(); } }); if (eddob != null) { eddob.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int cYear; int cMonth; int cDay; if (bdt == null) { Calendar currentDate = Calendar.getInstance(); cYear = currentDate.get(Calendar.YEAR); cMonth = currentDate.get(Calendar.MONTH); cDay = currentDate.get(Calendar.DAY_OF_MONTH); } else { cYear = bdt.getYear(); cMonth = bdt.getMonthOfYear() - 1; cDay = bdt.getDayOfMonth(); } edmonth.getText().clear(); edyr.getText().clear(); DatePickerDialog mDatePicker = new DatePickerDialog(AddEditPatientFragment.this.getActivity(), new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) { int adjustedMonth = selectedmonth + 1; eddob.setText(selectedday + "/" + adjustedMonth + "/" + selectedyear); birthdate = new LocalDate(selectedyear, adjustedMonth, selectedday); bdt = birthdate.toDateTimeAtStartOfDay().toDateTime(); } }, cYear, cMonth, cDay); mDatePicker.getDatePicker().setMaxDate(System.currentTimeMillis()); mDatePicker.setTitle("Select Date"); mDatePicker.show(); } }); } capturePhoto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AddEditPatientFragmentPermissionsDispatcher.capturePhotoWithCheck(AddEditPatientFragment.this); } }); submitConfirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mPresenter.confirmRegister(createPatient()); } }); patientImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (output != null) { Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.fromFile(output), "image/jpeg"); startActivity(i); } else if (patientPhoto != null) { Intent intent = new Intent(getContext(), PatientPhotoActivity.class); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); patientPhoto.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); intent.putExtra("photo", byteArrayOutputStream.toByteArray()); intent.putExtra("name", patientName); startActivity(intent); } } }); TextWatcher textWatcher = new PatientBirthdateValidatorWatcher(eddob, edmonth, edyr); edmonth.addTextChangedListener(textWatcher); edyr.addTextChangedListener(textWatcher); }
From source file:com.hackensack.umc.activity.DependentDetailsActivity.java
public void showDatePickerDialog(Context context, final TextView tv) { DatePickerDialog dDialog = new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() { @Override//w w w. j a va2 s . c om public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { mMonth = monthOfYear; mDay = dayOfMonth; mYear = year; Calendar calendar = Calendar.getInstance(); calendar.set(year, monthOfYear, dayOfMonth); birthDate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime()); String birthDateToshow = new SimpleDateFormat("MM-dd-yyyy").format(calendar.getTime()); // birthDate = format.(calendar.getTime()); Log.v(TAG, "strDate is::" + birthDateToshow); tv.setText(birthDateToshow); } }, mYear, mMonth, mDay); dDialog.getDatePicker().setMaxDate(new Date().getTime()); dDialog.show(); }
From source file:nl.mpcjanssen.simpletask.Simpletask.java
private void deferTasks(List<Task> tasks, final int dateType) { final List<Task> tasksToDefer = tasks; Dialog d = Util.createDeferDialog(this, dateType, true, new Util.InputDialogListener() { @Override/* w w w . ja v a 2 s . co m*/ public void onClick(@Nullable String selected) { if (selected == null) { Log.w(TAG, "Can't defer, selected is null. This should not happen"); return; } if (selected.equals("pick")) { final DateTime today = DateTime.today(TimeZone.getDefault()); DatePickerDialog dialog = new DatePickerDialog(Simpletask.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int year, int month, int day) { month++; DateTime date = DateTime.forDateOnly(year, month, day); getTaskBag().defer(date.format(Constants.DATE_FORMAT), tasksToDefer, dateType); } }, today.getYear(), today.getMonth() - 1, today.getDay()); boolean showCalendar = m_app.showCalendar(); dialog.getDatePicker().setCalendarViewShown(showCalendar); dialog.getDatePicker().setSpinnersShown(!showCalendar); dialog.show(); } else { getTaskBag().defer(selected, tasksToDefer, dateType); } } }); d.show(); }
From source file:com.metinkale.prayerapp.vakit.fragments.MainFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.notification: Fragment frag = getActivity().getSupportFragmentManager().findFragmentByTag("notPrefs"); if (frag == null) { ((Main) getActivity()).setFooterText("", false); getActivity().getSupportFragmentManager().beginTransaction() .add(R.id.fragContainer, NotificationPrefs.create(mTimes), "notPrefs") .commitAllowingStateLoss(); } else {//from w w w .j a v a 2s .co m ((Main) getActivity()).setFooterText(getString(R.string.monthly), true); getActivity().getSupportFragmentManager().beginTransaction().remove(frag).commitAllowingStateLoss(); } break; case R.id.export: AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.export).setItems(new CharSequence[] { "CSV", "PDF" }, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, final int which) { long minDate = 0; long maxDate = Long.MAX_VALUE; if (mTimes instanceof WebTimes) { minDate = ((WebTimes) mTimes).getFirstSyncedDay().toDateTimeAtCurrentTime() .getMillis(); maxDate = ((WebTimes) mTimes).getLastSyncedDay().toDateTimeAtCurrentTime() .getMillis(); } final LocalDate ld = LocalDate.now(); final long finalMaxDate = maxDate; DatePickerDialog dlg = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int y, int m, int d) { final LocalDate from = new LocalDate(y, m + 1, d); DatePickerDialog dlg = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int y, int m, int d) { final LocalDate to = new LocalDate(y, m + 1, d); try { export(which, from, to); } catch (IOException e) { e.printStackTrace(); Crashlytics.logException(e); Toast.makeText(getActivity(), R.string.error, Toast.LENGTH_SHORT).show(); } } }, ld.getYear(), ld.getMonthOfYear() - 1, ld.getDayOfMonth()); DateTime startDate = DateTime.now().withDate(y, m + 1, d); long start = startDate.getMillis(); dlg.getDatePicker().setMinDate(start); if (which == 1) dlg.getDatePicker().setMaxDate( Math.min(finalMaxDate, startDate.plusDays(31).getMillis())); else dlg.getDatePicker().setMaxDate(finalMaxDate); dlg.setTitle(R.string.to); dlg.show(); } }, ld.getYear(), ld.getMonthOfYear() - 1, ld.getDayOfMonth()); dlg.getDatePicker().setMinDate(minDate); dlg.getDatePicker().setMaxDate(maxDate); dlg.setTitle(R.string.from); dlg.show(); } }); builder.show(); break; case R.id.refresh: if (mTimes instanceof WebTimes) { ((WebTimes) mTimes).syncAsync(); } break; case R.id.share: String txt = getString(R.string.shareTimes, mTimes.getName()) + ":"; LocalDate date = LocalDate.now(); String[] times = { mTimes.getTime(date, 0), mTimes.getTime(date, 1), mTimes.getTime(date, 2), mTimes.getTime(date, 3), mTimes.getTime(date, 4), mTimes.getTime(date, 5) }; for (int i = 0; i < times.length; i++) { txt += "\n " + Vakit.getByIndex(i).getString() + ": " + times[i]; } Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name)); sharingIntent.putExtra(Intent.EXTRA_TEXT, txt); startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share))); } return super.onOptionsItemSelected(item); }