List of usage examples for android.app DatePickerDialog show
public void show()
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); }// w w w .ja v a2 s .c om 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.akvo.caddisfly.sensor.colorimetry.liquid.SaveCalibrationDialogFragment.java
@NonNull @Override/* w ww . jav a2 s. c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { String testCode = CaddisflyApp.getApp().getCurrentTestInfo().getId(); final Context context = getActivity(); LayoutInflater i = getActivity().getLayoutInflater(); @SuppressLint("InflateParams") View view = i.inflate(R.layout.fragment_save_calibration, null); final DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, monthOfYear); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); String date = new SimpleDateFormat("dd MMM yyyy", Locale.US).format(calendar.getTime()); editExpiryDate.setText(date); } }; editExpiryDate = (EditText) view.findViewById(R.id.editExpiryDate); editBatchCode = (EditText) view.findViewById(R.id.editBatchCode); editRgb = (EditText) view.findViewById(R.id.editRgb); long milliseconds = PreferencesUtil.getLong(getActivity(), CaddisflyApp.getApp().getCurrentTestInfo().getId(), R.string.calibrationExpiryDateKey); if (milliseconds > new Date().getTime()) { editBatchCode.setText(PreferencesUtil.getString(context, testCode, R.string.batchNumberKey, "").trim()); long expiryDate = PreferencesUtil.getLong(getContext(), testCode, R.string.calibrationExpiryDateKey); if (expiryDate >= 0) { calendar.setTimeInMillis(expiryDate); editExpiryDate.setText(new SimpleDateFormat("dd-MMM-yyyy", Locale.US).format(new Date(expiryDate))); } } editRgb.setText(PreferencesUtil.getString(context, testCode, R.string.ledRgbKey, "").trim()); if (!AppPreferences.useExternalCamera()) { editRgb.setVisibility(View.GONE); view.findViewById(R.id.textRgb).setVisibility(View.GONE); } final DatePickerDialog datePickerDialog = new DatePickerDialog(context, onDateSetListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); Calendar date = Calendar.getInstance(); date.add(Calendar.DATE, 1); date.set(Calendar.HOUR_OF_DAY, date.getMinimum(Calendar.HOUR_OF_DAY)); date.set(Calendar.MINUTE, date.getMinimum(Calendar.MINUTE)); date.set(Calendar.SECOND, date.getMinimum(Calendar.SECOND)); date.set(Calendar.MILLISECOND, date.getMinimum(Calendar.MILLISECOND)); datePickerDialog.getDatePicker().setMinDate(date.getTimeInMillis()); date.add(Calendar.MONTH, CaddisflyApp.getApp().getCurrentTestInfo().getMonthsValid()); date.set(Calendar.HOUR_OF_DAY, date.getMaximum(Calendar.HOUR_OF_DAY)); date.set(Calendar.MINUTE, date.getMaximum(Calendar.MINUTE)); date.set(Calendar.SECOND, date.getMaximum(Calendar.SECOND)); date.set(Calendar.MILLISECOND, date.getMaximum(Calendar.MILLISECOND)); datePickerDialog.getDatePicker().setMaxDate(date.getTimeInMillis()); editExpiryDate.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { if (b) { closeKeyboard(getContext(), editBatchCode); datePickerDialog.show(); } } }); editExpiryDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { closeKeyboard(getContext(), editBatchCode); datePickerDialog.show(); } }); editName = (EditText) view.findViewById(R.id.editName); if (!isEditing && AppPreferences.isDiagnosticMode()) { editName.requestFocus(); } else { editName.setVisibility(View.GONE); editBatchCode.requestFocus(); } InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); AlertDialog.Builder b = new AlertDialog.Builder(getActivity()).setTitle(R.string.calibrationDetails) .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { closeKeyboard(context, editName); dismiss(); } }); b.setView(view); return b.create(); }
From source file:es.usc.citius.servando.calendula.fragments.ScheduleTimetableFragment.java
void setupStartEndDatePickers(View rootView) { if (schedule.start() == null) { schedule.setStart(LocalDate.now()); }//from www . j a v a2 s . c o m final LocalDate scheduleStart = schedule.start(); buttonScheduleStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DatePickerDialog dpd = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Log.d(TAG, year + " " + monthOfYear); LocalDate d = new LocalDate(year, monthOfYear + 1, dayOfMonth); setScheduleStart(d); } }, scheduleStart.getYear(), scheduleStart.getMonthOfYear() - 1, scheduleStart.getDayOfMonth()); dpd.show(); } }); buttonScheduleEnd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { LocalDate scheduleEnd = schedule.end() != null ? schedule.end() : scheduleStart.plusMonths(3); DatePickerDialog dpd = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { LocalDate d = new LocalDate(year, monthOfYear + 1, dayOfMonth); setScheduleEnd(d); } }, scheduleEnd.getYear(), scheduleEnd.getMonthOfYear() - 1, scheduleEnd.getDayOfMonth()); dpd.show(); } }); buttonScheduleEnd.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage("Do you want this schedule to continue indefinitely?").setCancelable(true) .setPositiveButton(getString(R.string.dialog_yes_option), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { setScheduleEnd(null); } }) .setNegativeButton(getString(R.string.dialog_no_option), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); return true; } }); clearStartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setScheduleStart(null); } }); clearEndButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setScheduleEnd(null); } }); setScheduleStart(schedule.start()); setScheduleEnd(schedule.end()); }
From source file:in.andres.kandroid.ui.TaskEditActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_task_edit); setupActionBar();// w w w . j a v a 2 s . c o m editTextTitle = (EditText) findViewById(R.id.edit_task_title); editTextDescription = (EditText) findViewById(R.id.edit_task_description); btnStartDate = (Button) findViewById(R.id.btn_start_date); btnDueDate = (Button) findViewById(R.id.btn_due_date); btnColor = (Button) findViewById(R.id.color_button); btnColor.setOnClickListener(btnColorClick); btnColor.setText(Utils.fromHtml(getString(R.string.taskedit_color, ""))); editHoursEstimated = (EditText) findViewById(R.id.edit_hours_estimated); editHoursSpent = (EditText) findViewById(R.id.edit_hours_spent); spinnerProjectUsers = (Spinner) findViewById(R.id.user_spinner); if (getIntent().hasExtra("task")) { isNewTask = false; task = (KanboardTask) getIntent().getSerializableExtra("task"); taskTitle = task.getTitle(); taskDescription = task.getDescription(); startDate = task.getDateStarted(); dueDate = task.getDateDue(); timeEstimated = task.getTimeEstimated(); timeSpent = task.getTimeSpent(); ownerId = task.getOwnerId(); colorId = task.getColorId(); setActionBarTitle(getString(R.string.taskview_fab_edit_task)); } else { isNewTask = true; projectid = getIntent().getIntExtra("projectid", 0); // colorId = getIntent().getIntExtra("colorid", 0); creatorId = getIntent().getIntExtra("creatorid", 0); ownerId = getIntent().getIntExtra("ownerid", 0); columnId = getIntent().getIntExtra("columnid", 0); swimlaneId = getIntent().getIntExtra("swimlaneid", 0); setActionBarTitle(getString(R.string.taskedit_new_task)); } SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getBaseContext()); try { kanboardAPI = new KanboardAPI(preferences.getString("serverurl", ""), preferences.getString("username", ""), preferences.getString("password", "")); kanboardAPI.addOnCreateTaskListener(this); kanboardAPI.addOnUpdateTaskListener(this); kanboardAPI.addOnGetDefaultColorListener(this); kanboardAPI.addOnGetDefaultColorsListener(this); kanboardAPI.addOnGetVersionListener(this); kanboardAPI.getDefaultTaskColor(); kanboardAPI.getDefaultTaskColors(); kanboardAPI.getVersion(); } catch (IOException e) { e.printStackTrace(); } if (getIntent().hasExtra("projectusers")) { if (getIntent().getSerializableExtra("projectusers") instanceof HashMap) { projectUsers = new Hashtable<>( (HashMap<Integer, String>) getIntent().getSerializableExtra("projectusers")); ArrayList<String> possibleOwners = Collections.list(projectUsers.elements()); possibleOwners.add(0, ""); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, possibleOwners); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerProjectUsers.setAdapter(adapter); if (ownerId != 0) { spinnerProjectUsers.setSelection(possibleOwners.indexOf(projectUsers.get(ownerId))); } } } editTextTitle.setText(taskTitle); editTextDescription.setText(taskDescription); editHoursEstimated.setText(Double.toString(timeEstimated)); editHoursSpent.setText(Double.toString(timeSpent)); btnStartDate.setText(Utils.fromHtml(getString(R.string.taskview_date_start, startDate))); btnDueDate.setText(Utils.fromHtml(getString(R.string.taskview_date_due, dueDate))); btnStartDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); if (startDate != null) calendar.setTime(startDate); DatePickerDialog dlgDate = new DatePickerDialog(TaskEditActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); startDate = calendar.getTime(); btnStartDate.setText( Utils.fromHtml(getString(R.string.taskview_date_start, startDate))); } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); dlgDate.setButton(DatePickerDialog.BUTTON_NEUTRAL, getString(R.string.taskedit_clear_date), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startDate = null; btnStartDate.setText( Utils.fromHtml(getString(R.string.taskview_date_start, startDate))); } }); dlgDate.show(); } }); btnDueDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); if (dueDate != null) calendar.setTime(dueDate); DatePickerDialog dlgDate = new DatePickerDialog(TaskEditActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); dueDate = calendar.getTime(); btnDueDate.setText(Utils.fromHtml(getString(R.string.taskview_date_due, dueDate))); } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); dlgDate.setButton(DatePickerDialog.BUTTON_NEUTRAL, getString(R.string.taskedit_clear_date), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dueDate = null; btnDueDate.setText(Utils.fromHtml(getString(R.string.taskview_date_due, dueDate))); } }); dlgDate.show(); } }); }
From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java
private void setupStartEndDatePickers(View rootView) { if (schedule.start() == null) { schedule.setStart(LocalDate.now()); }//from w w w.ja v a 2 s .co m final LocalDate scheduleStart = schedule.start(); buttonScheduleStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DatePickerDialog dpd = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Log.d(TAG, year + " " + monthOfYear); LocalDate d = new LocalDate(year, monthOfYear + 1, dayOfMonth); setScheduleStart(d); } }, scheduleStart.getYear(), scheduleStart.getMonthOfYear() - 1, scheduleStart.getDayOfMonth()); dpd.show(); } }); buttonScheduleEnd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { LocalDate scheduleEnd = schedule.end() != null ? schedule.end() : scheduleStart.plusMonths(3); DatePickerDialog dpd = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { LocalDate d = new LocalDate(year, monthOfYear + 1, dayOfMonth); setScheduleEnd(d); } }, scheduleEnd.getYear(), scheduleEnd.getMonthOfYear() - 1, scheduleEnd.getDayOfMonth()); dpd.show(); } }); buttonScheduleEnd.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage("Do you want this schedule to continue indefinitely?").setCancelable(true) .setPositiveButton(getString(R.string.dialog_yes_option), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { setScheduleEnd(null); } }) .setNegativeButton(getString(R.string.dialog_no_option), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); return true; } }); clearStartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setScheduleStart(null); } }); clearEndButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setScheduleEnd(null); } }); setScheduleStart(schedule.start()); if (schedule.end() == null && isNew && hasEnd && daysToEnd > 0) { LocalDate end = schedule.start().plusDays(daysToEnd); setScheduleEnd(end); } else { setScheduleEnd(schedule.end()); } }
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/* ww w. j a v a2s . 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:mobisocial.bento.ebento.ui.EditFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (savedInstanceState != null) { mbImageChanged = savedInstanceState.getBoolean(INSTANCE_STATE_IMAGE_CHANGED); }/*from w ww .j a va 2 s .com*/ mTargetWidth = (UIUtils.isTablet(getActivity()) ? MAX_IMG_WIDTH_TABLET : MAX_IMG_WIDTH_PHONE); mTargetHeight = (UIUtils.isTablet(getActivity()) ? MAX_IMG_HEIGHT_TABLET : MAX_IMG_HEIGHT_PHONE); // Check if this activity launched from internal activity or not if (getActivity().getIntent().hasExtra(EditActivity.EXTRA_EDIT)) { mbNewEventMode = false; } // Event Event event = new Event(); if (!mbNewEventMode) { event = mManager.getEvent(); } // View mRootView = (ViewGroup) inflater.inflate(R.layout.fragment_edit, container); // EditText View.OnFocusChangeListener unfocusListener = new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean flag) { if (flag == false) { InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } } }; mTitle = (EditText) mRootView.findViewById(R.id.title); mTitle.setOnFocusChangeListener(unfocusListener); if (!mbNewEventMode) mTitle.setText(event.title); mPlace = (EditText) mRootView.findViewById(R.id.place); mPlace.setOnFocusChangeListener(unfocusListener); if (!mbNewEventMode) mPlace.setText(event.place); mDetails = (EditText) mRootView.findViewById(R.id.details); mDetails.setOnFocusChangeListener(unfocusListener); if (!mbNewEventMode) mDetails.setText(event.details); // Date & Time Picker // TODO : All day option if (mbNewEventMode) { // start mStartDateTime = DateTimeUtils.getRoundedCurrentDateTime(); // end mEndDateTime = DateTimeUtils.getOneHourAheadEndTimeFromStartTime(mStartDateTime); } else { // start mStartDateTime.year = event.startDate.year; mStartDateTime.month = event.startDate.month; mStartDateTime.day = event.startDate.day; mStartDateTime.hour = event.startTime.hour; mStartDateTime.minute = event.startTime.minute; // end mEndDateTime.year = event.endDate.year; mEndDateTime.month = event.endDate.month; mEndDateTime.day = event.endDate.day; mEndDateTime.hour = event.endTime.hour; mEndDateTime.minute = event.endTime.minute; } mStartDateButton = (Button) mRootView.findViewById(R.id.start_date_button); mEndDateButton = (Button) mRootView.findViewById(R.id.end_date_button); mStartTimeButton = (Button) mRootView.findViewById(R.id.start_time_button); mEndTimeButton = (Button) mRootView.findViewById(R.id.end_time_button); setDateTimeButtonText(); // Date mStartDateButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { final DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { DateTime candidateStart = new DateTime(); candidateStart.year = year; candidateStart.month = (monthOfYear + 1); candidateStart.day = dayOfMonth; candidateStart.hour = mStartDateTime.hour; candidateStart.minute = mStartDateTime.minute; if (DateTimeUtils.isPastDateTime(candidateStart)) { Toast.makeText(getActivity(), R.string.toast_edit_past_time, Toast.LENGTH_SHORT) .show(); } else { mStartDateTime.year = year; mStartDateTime.month = (monthOfYear + 1); mStartDateTime.day = dayOfMonth; mEndDateTime = DateTimeUtils.getEndTimeFromStartTime(mStartDateTime, mEndDateTime); setDateTimeButtonText(); } } }, mStartDateTime.year, (mStartDateTime.month - 1), mStartDateTime.day); datePickerDialog.show(); } }); mEndDateButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { final DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { DateTime candidateEnd = new DateTime(); candidateEnd.year = year; candidateEnd.month = (monthOfYear + 1); candidateEnd.day = dayOfMonth; candidateEnd.hour = mEndDateTime.hour; candidateEnd.minute = mEndDateTime.minute; DateTime candidateStart = new DateTime(); candidateStart.year = mStartDateTime.year; candidateStart.month = mStartDateTime.month; candidateStart.day = mStartDateTime.day; candidateStart.hour = mStartDateTime.hour; candidateStart.minute = mStartDateTime.minute; candidateStart = DateTimeUtils.getStartTimeFromEndTime(candidateStart, candidateEnd); if (DateTimeUtils.isPastDateTime(candidateStart) || DateTimeUtils.isPastDateTime(candidateEnd)) { Toast.makeText(getActivity(), R.string.toast_edit_past_time, Toast.LENGTH_SHORT) .show(); } else { mEndDateTime.year = year; mEndDateTime.month = (monthOfYear + 1); mEndDateTime.day = dayOfMonth; mStartDateTime = DateTimeUtils.getStartTimeFromEndTime(mStartDateTime, mEndDateTime); setDateTimeButtonText(); } } }, mEndDateTime.year, (mEndDateTime.month - 1), mEndDateTime.day); datePickerDialog.show(); } }); // Time mStartTimeButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { final TimePickerDialog timePickerDialog = new FiveMinutesIntervalTimePickerDialog(getActivity(), new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { DateTime candidateStart = new DateTime(); candidateStart.year = mStartDateTime.year; candidateStart.month = mStartDateTime.month; candidateStart.day = mStartDateTime.day; candidateStart.hour = hourOfDay; candidateStart.minute = minute; if (DateTimeUtils.isPastDateTime(candidateStart)) { Toast.makeText(getActivity(), R.string.toast_edit_past_time, Toast.LENGTH_SHORT) .show(); } else { mStartDateTime.hour = hourOfDay; mStartDateTime.minute = minute; mEndDateTime = DateTimeUtils.getEndTimeFromStartTime(mStartDateTime, mEndDateTime); setDateTimeButtonText(); } } }, mStartDateTime.hour, mStartDateTime.minute, false); timePickerDialog.show(); } }); mEndTimeButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { final TimePickerDialog timePickerDialog = new FiveMinutesIntervalTimePickerDialog(getActivity(), new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { DateTime candidateEnd = new DateTime(); candidateEnd.year = mEndDateTime.year; candidateEnd.month = mEndDateTime.month; candidateEnd.day = mEndDateTime.day; candidateEnd.hour = hourOfDay; candidateEnd.minute = minute; DateTime candidateStart = new DateTime(); candidateStart.year = mStartDateTime.year; candidateStart.month = mStartDateTime.month; candidateStart.day = mStartDateTime.day; candidateStart.hour = mStartDateTime.hour; candidateStart.minute = mStartDateTime.minute; candidateStart = DateTimeUtils.getStartTimeFromEndTime(candidateStart, candidateEnd); if (DateTimeUtils.isPastDateTime(candidateStart) || DateTimeUtils.isPastDateTime(candidateEnd)) { Toast.makeText(getActivity(), R.string.toast_edit_past_time, Toast.LENGTH_SHORT) .show(); } else { mEndDateTime.hour = hourOfDay; mEndDateTime.minute = minute; mStartDateTime = DateTimeUtils.getStartTimeFromEndTime(mStartDateTime, mEndDateTime); setDateTimeButtonText(); } } }, mEndDateTime.hour, mEndDateTime.minute, false); timePickerDialog.show(); } }); // Image mImageButton = (Button) mRootView.findViewById(R.id.image_button); mImageButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { goPicture(v); } }); mImageView = (ImageView) mRootView.findViewById(R.id.image); if (mbNewEventMode) { if (!mbImageChanged) { sImageOrg = null; } } else { if (!mbImageChanged) { sImageOrg = event.image; } } if (sImageOrg != null) { mImageView.setImageBitmap(BitmapHelper.getResizedBitmap(sImageOrg, mTargetWidth, mTargetHeight, 0)); mImageView.setVisibility(View.VISIBLE); } else { mImageView.setVisibility(View.GONE); } // Quick Action ActionItem cameraItem = new ActionItem(REQUEST_IMAGE_CAPTURE, getResources().getString(R.string.label_camera), getResources().getDrawable(R.drawable.ic_menu_camera)); ActionItem galleryItem = new ActionItem(REQUEST_GALLERY, getResources().getString(R.string.label_gallery), getResources().getDrawable(R.drawable.ic_menu_gallery)); ActionItem removeItem = new ActionItem(REQUEST_REMOVE, getResources().getString(R.string.label_remove_picture), getResources().getDrawable(R.drawable.ic_menu_remove_picture)); mQuickAction = new QuickAction(getActivity()); mQuickAction.addActionItem(cameraItem); mQuickAction.addActionItem(galleryItem); mQuickAction.addActionItem(removeItem); mQuickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() { @Override public void onItemClick(QuickAction quickAction, int pos, int actionId) { if (actionId == REQUEST_IMAGE_CAPTURE) { goCamera(); } else if (actionId == REQUEST_GALLERY) { goGallery(); } else { goRemovePicture(); } } }); mQuickAction.setOnDismissListener(new QuickAction.OnDismissListener() { @Override public void onDismiss() { } }); // Add Cal mAddCalCheckBox = (CheckBox) mRootView.findViewById(R.id.add_cal_checkbox); mAddCalText = (TextView) mRootView.findViewById(R.id.add_cal_text); mAddCalLayout = (LinearLayout) mRootView.findViewById(R.id.add_cal_layout); mAddCalSub = (TextView) mRootView.findViewById(R.id.add_cal_sub); if (!mbNewEventMode) { mAddCalText.setVisibility(View.GONE); mAddCalLayout.setVisibility(View.GONE); } else { // not ICS if (!UIUtils.isIceCreamSandwich()) { mAddCalSub.setVisibility(View.GONE); } } // Save/Cancel Buttons mSaveButton = (Button) mRootView.findViewById(R.id.save_button); mSaveButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { goSave(); } }); mCancelButton = (Button) mRootView.findViewById(R.id.cancel_button); mCancelButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { getActivity().finish(); } }); return mRootView; }
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/* ww w . j a va 2 s .com*/ 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:de.ribeiro.android.gso.activities.PlanActivity.java
/** * @author ribeiro/*w w w .j a va 2 s .co m*/ * ffnet ein Datumsplugin und prft, ob dieses TimeTable verfgbar ist, wenn ja, springt er dorthin */ private void gotoDate() { ctxt.handler.post(new Runnable() { @Override public void run() { _logger.Info("Goto Date called"); if (ctxt.mIsRunning && ctxt.pager != null && ctxt.pager.size() > 1) { Calendar cal = ctxt.pager.getDateOfCurrentPage(); if (cal != null) { DatePickerDialog picker = new DatePickerDialog(PlanActivity.this, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { _logger.Info("Set Date " + dayOfMonth + "." + monthOfYear + "." + year); // das Ausgewhlte Datum einstellen Calendar newDate = new GregorianCalendar(); newDate.set(year, monthOfYear, dayOfMonth); // prfen, ob es sich dabei um wochenend tage // handelt: switch (newDate.get(Calendar.DAY_OF_WEEK)) { case Calendar.SATURDAY: newDate.setTimeInMillis( newDate.getTimeInMillis() + (1000 * 60 * 60 * 24 * 2)); break; case Calendar.SUNDAY: newDate.setTimeInMillis( newDate.getTimeInMillis() + (1000 * 60 * 60 * 24 * 1)); break; } int page = ctxt.pager.getPage(newDate, -1); if (page != -1) { // gefunden ctxt.pager.setPage(page); } else { _logger.Info("Selected date is unavailable"); Toast.makeText(PlanActivity.this, "Dieses Datum ist nicht verfgbar!", Toast.LENGTH_SHORT).show(); } } }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); picker.show(); } else _logger.Info("Cal Picker canceled, because Pager is empty"); } } }); }
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 {/*www. j a v a 2 s . 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); }