public void button(View v) { // カレンダー型変数を取得 calendar = Calendar.getInstance(); // 一分五秒後に設定 int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); // TimePicker TimePickerDialog dialog = new TimePickerDialog( this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { Log.d("test", String.format(" % 02d:%02d", hourOfDay, minute)); calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, 0); } }, hour, minute, true); dialog.show(); }
@Click(R.id.time_text) public void showTimePicker() { TimePickerDialog timepicker = new TimePickerDialog( getActivity(), new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hourOfDay, int minute) { String hour = ""; String minuteString = ""; if (hourOfDay < 10) hour = "0" + hourOfDay; else hour = "" + hourOfDay; if ((minute + 1) < 10) minuteString = "0" + (minute + 1); else minuteString = "" + (minute + 1); timeText.setText(hour + ":" + minuteString + ":00"); } }, hour, minute, DateFormat.is24HourFormat(getActivity())); timepicker.show(); }
private void timePick() { Calendar calendar = Calendar.getInstance(); final int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); TimePickerDialog timePickerDialog = new TimePickerDialog( BaseInfoPostActivity.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { String newHour; String newMinute; if (hourOfDay < 10) { newHour = "0" + hourOfDay; } else { newHour = String.valueOf(hourOfDay); } if (minute < 10) { newMinute = "0" + minute; } else { newMinute = String.valueOf(minute); } String time = newHour + ":" + newMinute; mBtnTimePicker.setText(time); host.setTime(time); } }, hour, minute, true); timePickerDialog.show(); }
@Override public void onClick(View v) { if (v.getId() == R.id.date) { if (date == null) { date = Calendar.getInstance(); } DatePickerDialog datePickerDialog = new DatePickerDialog( getContext(), ServiceDatesFragment.this, date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH)); datePickerDialog.show(); } else { if (time == null) { time = Calendar.getInstance(); } TimePickerDialog datePickerDialog = new TimePickerDialog( getContext(), ServiceDatesFragment.this, time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE), true); datePickerDialog.show(); } }
private void showTimePicker() { Calendar calendar = Calendar.getInstance(); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); TimePickerDialog timeDialog = new TimePickerDialog(getActivity(), timeSetListener, hour, minute, false); timeDialog.show(); }
/** * Called when user clicked on end hour EditText * * @param view target */ public void onEndHourClick(View view) { TimePickerDialog timePickerDialog = new TimePickerDialog( activity, onEndHourTimeSetListener, endDateCalendar.get(Calendar.HOUR_OF_DAY), endDateCalendar.get(Calendar.MINUTE), true); timePickerDialog.show(); }
@Override public void onCellSelected() { super.onCellSelected(); TimePickerDialog dialog = new TimePickerDialog( getContext(), this, getCalendar().get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE), true); dialog.show(); }
private void openTimePickerDialog(boolean is24r) { Calendar calendar = Calendar.getInstance(); timePickerDialog = new TimePickerDialog( MainActivity.this, onTimeSetListener, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true); timePickerDialog.setTitle("Set Alarm Time"); timePickerDialog.show(); }
public void onTimeSet( android.widget.TimePicker view, int selectedHour, int selectedMinute) { hour = selectedHour; minute = selectedMinute; time.updateTime(hour, minute); AfterTimeSet(); }
private void showSelectTimeDialog(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { TimePickerDialog timePickerDialog = new TimePickerDialog( AddMemoActivity.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { selectTime.setText(DateUtils.timeAddZero(hourOfDay + ":" + minute, ":")); } }, 10, 0, true); timePickerDialog.show(); } }
@Override public boolean onMotionEvent(MotionEvent event, float offset) { if (position == null) { return false; } // Get the pointer ID int activePointerIndex = event.getActionIndex(); int activePointerId = event.getPointerId(activePointerIndex); float x, y; switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: x = event.getX(activePointerIndex); y = event.getY(activePointerIndex); // if the current touch is inside the left click button if (rectWithOffset(position, offset).contains((int) x, (int) y)) { pressedId = activePointerId; return true; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: if (activePointerId == pressedId) { pressedId = -1; if (PresentationController.getInstance(context).isStarted()) { PresentationController.getInstance(context).stop(); } else { // show dialog to select time TimePickerDialog dialog = new TimePickerDialog(context, timeSetListener, 0, 10, true); dialog.setTitle("Presentation duration in hours and minutes"); dialog.show(); } return true; } break; } return false; }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Iniciar con el tiempo actual final Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); TimePickerDialog tpd = new TimePickerDialog( getActivity(), (TimePickerDialog.OnTimeSetListener) getActivity(), // La clase que lo llame implementara la interfaz hour, minute, DateFormat.is24HourFormat(getActivity())); tpd.setTitle("Hora de Notificacion"); // Retornar en nueva instancia del dialogo selector de tiempo return tpd; }
public void showTimePicker(View v) { TimePickerDialog.OnTimeSetListener callback = new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // Button b = (Button) findViewById(R.id.start_time); b.setText(String.format("%02d:%02d", hourOfDay, minute)); } }; Button b = (Button) findViewById(R.id.start_time); String[] hm = b.getText().toString().split(":"); int hour = Integer.parseInt(hm[0]); int minute = Integer.parseInt(hm[1]); TimePickerDialog dialog = new TimePickerDialog(this, callback, hour, minute, true); dialog.show(); }
@Override protected void onPrepareDialog(int id, Dialog dialog) { switch (id) { case TIME_DIALOG_ID: ((TimePickerDialog) dialog).updateTime(mHour, mMinute); break; case DATE_DIALOG_ID: ((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay); break; } }
private void showTimeDialog(final TextView txtDisplay, final GregorianCalendar time) { TimePickerDialog timePickerDialog = new TimePickerDialog( getActivity(), new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { txtDisplay.setText( StringUtils.leftPad(String.valueOf(hourOfDay), 2, "0") + ":" + StringUtils.leftPad(String.valueOf(minute), 2, "0")); time.set(Calendar.HOUR_OF_DAY, hourOfDay); time.set(Calendar.MINUTE, minute); } }, time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE), true); timePickerDialog.show(); }
private void showTimeDialog(String time, final TextView tv) { df.applyPattern("kk:mm"); Date date = new Date(); mCalendar.setTime(date); int hours = mCalendar.get(Calendar.HOUR); int minute = mCalendar.get(Calendar.MINUTE); try { date = df.parse(time); mCalendar.setTime(date); hours = mCalendar.get(Calendar.HOUR_OF_DAY); minute = mCalendar.get(Calendar.MINUTE); } catch (Exception ex) { } TimePickerDialog pickerDialog = new TimePickerDialog( this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker arg0, int house, int min) { String str = ""; if (house < 10) { str += "0"; } str += house + ":"; if (min < 10) str += "0"; str += min; tv.setText(str); } }, hours, minute, true); pickerDialog.show(); }
private void createTimePickerDialog(final Date time, final boolean isStartDate) { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(time); int hourOfDay = gc.get(Calendar.HOUR_OF_DAY); int minute = gc.get(Calendar.MINUTE); TimePickerDialog dialog = new TimePickerDialog( this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { if (isStartDate) { gc.set(Calendar.HOUR_OF_DAY, hourOfDay); gc.set(Calendar.MINUTE, minute); ponto.setStartDate(gc.getTime()); startTime.setText(sdfTime.format(gc.getTime())); } else { gc.setTime(ponto.getStartDate()); gc.set(Calendar.HOUR_OF_DAY, hourOfDay); gc.set(Calendar.MINUTE, minute); ponto.setFinishDate(gc.getTime()); finishTime.setText(sdfTime.format(gc.getTime())); } repository.saveOrUpdate(ponto); } }, hourOfDay, minute, true); dialog.show(); }
@Override public void onRestoreInstanceState(Bundle savedInstanceState) { // Restoration of title field if (savedInstanceState.containsKey(STATE_TITLE)) { String title = savedInstanceState.getString(STATE_TITLE); titleEditText.setText(title); } // Restoration of description field if (savedInstanceState.containsKey(STATE_DESCRIPTION)) { String description = savedInstanceState.getString(STATE_DESCRIPTION); descriptionEditText.setText(description); } // Restoration of time field if (savedInstanceState.containsKey(STATE_TIME_HOUR) && savedInstanceState.containsKey(STATE_TIME_MINUTES)) { int hour = savedInstanceState.getInt(STATE_TIME_HOUR); int minutes = savedInstanceState.getInt(STATE_TIME_MINUTES); time = new Pair(hour, minutes); setTime(hour, minutes); if (timePicker == null) { setTimePicker(hour, minutes); } else { timePicker.updateTime(hour, minutes); } } // Restoration of week days field if (savedInstanceState.containsKey(STATE_WEEK_DAYS)) { weekDays = savedInstanceState.getBooleanArray(STATE_WEEK_DAYS); if (weekDays != null) { for (int i = 0; i < weekDays.length; i++) { LinearLayout dayLayout = getDayLayout(i); if (weekDays[i]) { activateDay(i, dayLayout, false); } else { deactivateDay(i, dayLayout, false); } } } } // The call to super method must be at the end here super.onRestoreInstanceState(savedInstanceState); }
@Override public void onClick(View v) { int id = v.getId(); if (id == R.id.event_location) { Intent i = new Intent(context, MapsActivity.class); CreateEventActivity.this.startActivity(i); } else if (id == R.id.event_date) { DPD = new DatePickerDialog(context, mDateSetListener, 2013, 11, 30); DPD.getDatePicker().setMinDate(System.currentTimeMillis() - 1000); DPD.show(); } else if (id == R.id.event_time) { TPD = new TimePickerDialog( context, mTimeSetListener, Calendar.HOUR_OF_DAY, Calendar.MINUTE, true); TPD.show(); } }
@Override protected void onPrepareDialog(int id, Dialog dialog) { switch (id) { case TIME_DIALOG_ID: ((TimePickerDialog) dialog) .updateTime(mCalendar.get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE)); break; case DATE_DIALOG_ID: ((DatePickerDialog) dialog) .updateDate( mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)); break; case DIALOG_MULTIPLE_CATEGORY: final AlertDialog alert = (AlertDialog) dialog; final ListView list = alert.getListView(); // been // selected, then uncheck // selected categories if (mVectorCategories.size() > 0) { for (String s : mVectorCategories) { try { // @inoran fix if (list != null) { list.setItemChecked(mCategoryLength - Integer.parseInt(s), true); } } catch (NumberFormatException e) { log("NumberFormatException", e); } } } else { if (list != null) { list.clearChoices(); } } break; } }
@Override public void onClick(View v) { // TODO Auto-generated method stub mTxtResult.setText(""); Calendar now = Calendar.getInstance(); TimePickerDialog timePicDlg = new TimePickerDialog( DialogActivity.this, timePicDlgOnTimeSelLis, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), true); timePicDlg.setTitle("选择时间"); timePicDlg.setMessage("请选择适合您的时间"); timePicDlg.setIcon(android.R.drawable.ic_dialog_info); timePicDlg.setCancelable(false); timePicDlg.show(); }
@Override public void onClick(View v) { // TODO Auto-generated method stub Calendar c = Calendar.getInstance(); switch (v.getId()) { case R.id.startTime: // Process to get Current Time startHour = c.get(Calendar.HOUR_OF_DAY); startMinute = c.get(Calendar.MINUTE); // Launch Time Picker Dialog TimePickerDialog tpd1 = new TimePickerDialog( this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // Display Selected time in textbox eStart.setText(hourOfDay + ":" + minute); startHour = hourOfDay; startMinute = minute; alarmIntent.putExtra("startHour", startHour); if (day.equals("Friday")) { pendingIntent = PendingIntent.getBroadcast( Friday.this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmRepeat(); } alarmIntent.putExtra("startMinute", startMinute); if (day.equals("Friday")) { pendingIntent = PendingIntent.getBroadcast( Friday.this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmRepeat(); } } }, startHour, startMinute, false); tpd1.show(); break; case R.id.stopTime: // Process to get Current Time stopHour = c.get(Calendar.HOUR_OF_DAY); stopMinute = c.get(Calendar.MINUTE); // Launch Time Picker Dialog TimePickerDialog tpd2 = new TimePickerDialog( this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // Display Selected time in textbox eStop.setText(hourOfDay + ":" + minute); stopHour = hourOfDay; stopMinute = minute; alarmIntent.putExtra("stopHour", stopHour); if (day.equals("Friday")) { pendingIntent = PendingIntent.getBroadcast( Friday.this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmRepeat(); } alarmIntent.putExtra("stopMinute", stopMinute); if (day.equals("Friday")) { pendingIntent = PendingIntent.getBroadcast( Friday.this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmRepeat(); } } }, stopHour, stopMinute, false); tpd2.show(); break; case R.id.wifiStart: // Process to get Current Time wstartHour = c.get(Calendar.HOUR_OF_DAY); wstartMinute = c.get(Calendar.MINUTE); // Launch Time Picker Dialog TimePickerDialog tpd3 = new TimePickerDialog( this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // Display Selected time in textbox eWifiStart.setText(hourOfDay + ":" + minute); wstartHour = hourOfDay; wstartMinute = minute; alarmIntent.putExtra("wstartHour", wstartHour); if (day.equals("Friday")) { pendingIntent = PendingIntent.getBroadcast( Friday.this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmRepeat(); } alarmIntent.putExtra("wstartMinute", wstartMinute); if (day.equals("Friday")) { pendingIntent = PendingIntent.getBroadcast( Friday.this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmRepeat(); } } }, wstartHour, wstartMinute, false); tpd3.show(); break; case R.id.wifiStop: // Process to get Current Time wstopHour = c.get(Calendar.HOUR_OF_DAY); wstopMinute = c.get(Calendar.MINUTE); // Launch Time Picker Dialog TimePickerDialog tpd4 = new TimePickerDialog( this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // Display Selected time in textbox eWifiStop.setText(hourOfDay + ":" + minute); wstopHour = hourOfDay; wstopMinute = minute; alarmIntent.putExtra("wstopHour", wstopHour); if (day.equals("Friday")) { pendingIntent = PendingIntent.getBroadcast( Friday.this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmRepeat(); } alarmIntent.putExtra("wstopMinute", wstopMinute); if (day.equals("Friday")) { pendingIntent = PendingIntent.getBroadcast( Friday.this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmRepeat(); } } }, wstopHour, wstopMinute, false); tpd4.show(); break; } }
@Override public void click() { time.show(); }
@Override public void onClick(View v) { if (v.getId() == R.id.tvAction) { sendCreateReminderRequest(); } else { final Calendar calendar = Calendar.getInstance(); switch (v.getId()) { case R.id.tvStartDate: case R.id.tvStartTime: calendar.setTime(startTime); break; case R.id.tvEndDate: case R.id.tvEndTime: calendar.setTime(endTime); break; case R.id.tvRepeatEndDate: calendar.setTime(endDate); break; } int date = calendar.get(Calendar.DATE); int month = calendar.get(Calendar.MONTH); int year = calendar.get(Calendar.YEAR); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); switch (v.getId()) { case R.id.tvRepeatEndDate: { DatePickerDialog dialogEndDate = new DatePickerDialog( this, new OnDateSetListener() { boolean fired = false; @Override public void onDateSet(DatePicker view, int year, int month, int day) { // onDateSet call twice, so, we will check for first call if (!fired) { calendar.set(Calendar.DATE, day); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.YEAR, year); endDate = calendar.getTime(); // check if end time is less than start time, set default end time is // start time if (DateTimeFormater.timeServerFormat .format(endDate) .compareToIgnoreCase( DateTimeFormater.timeServerFormat.format(startTime)) < 0) { showCenterToast(R.string.msg_err_end_time_must_greater_start_time); calendar.setTime(startTime); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); endDate = calendar.getTime(); } tvRepeatEndDate.setText( DateTimeFormater.dateFullFormater.format(endDate)); fired = true; } } }, year, month, date); dialogEndDate.setTitle("Select End Date repeat"); dialogEndDate.show(); break; } case R.id.tvStartDate: { DatePickerDialog dialog = new DatePickerDialog( this, new OnDateSetListener() { boolean fired = false; @Override public void onDateSet(DatePicker view, int year, int month, int day) { // onDateSet call twice, so, we will check for first call if (!fired) { calendar.set(Calendar.DATE, day); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.YEAR, year); startTime = calendar.getTime(); tvStartDate.setText(DateTimeFormater.dateFullFormater.format(startTime)); // check if end time is less than start time, set default end time is // start time + 1 hour if (DateTimeFormater.timeServerFormat .format(endTime) .compareToIgnoreCase( DateTimeFormater.timeServerFormat.format(startTime)) < 0) { calendar.setTime(startTime); calendar.add(Calendar.HOUR, 1); endTime = calendar.getTime(); tvEndDate.setText(DateTimeFormater.dateFullFormater.format(endTime)); tvEndTime.setText(DateTimeFormater.timeFormater.format(endTime)); } if (DateTimeFormater.timeServerFormat .format(endDate) .compareToIgnoreCase( DateTimeFormater.timeServerFormat.format(startTime)) < 0) { // set end date calendar.setTime(startTime); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); endDate = calendar.getTime(); tvRepeatEndDate.setText( DateTimeFormater.dateFullFormater.format(endDate)); } fired = true; } } }, year, month, date); dialog.setTitle("Select Start Date"); dialog.show(); break; } case R.id.tvEndDate: { DatePickerDialog dialog = new DatePickerDialog( this, new OnDateSetListener() { boolean fired = false; @Override public void onDateSet(DatePicker view, int year, int month, int day) { // onDateSet call twice, so, we will check for first call if (!fired) { calendar.set(Calendar.DATE, day); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.YEAR, year); endTime = calendar.getTime(); // check if end time is less than start time, show error toast and set // default end time // is // start time + 1 hour if (DateTimeFormater.timeServerFormat .format(endTime) .compareToIgnoreCase( DateTimeFormater.timeServerFormat.format(startTime)) < 0) { showCenterToast(R.string.msg_err_end_time_must_greater_start_time); calendar.setTime(startTime); calendar.add(Calendar.HOUR, 1); endTime = calendar.getTime(); } tvEndDate.setText(DateTimeFormater.dateFullFormater.format(endTime)); fired = true; } } }, year, month, date); dialog.setTitle("Select End Date"); dialog.show(); break; } case R.id.tvStartTime: { TimePickerDialog dialog = new TimePickerDialog( this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); calendar.set(Calendar.MINUTE, minute); startTime = calendar.getTime(); tvStartTime.setText(DateTimeFormater.timeFormater.format(startTime)); // check if end time is less than start time, set default end time is // start time + 1 hour if (DateTimeFormater.timeServerFormat .format(endTime) .compareToIgnoreCase( DateTimeFormater.timeServerFormat.format(startTime)) < 0) { // set end time calendar.setTime(startTime); calendar.add(Calendar.HOUR, 1); endTime = calendar.getTime(); tvEndDate.setText(DateTimeFormater.dateFullFormater.format(endTime)); tvEndTime.setText(DateTimeFormater.timeFormater.format(endTime)); } if (DateTimeFormater.timeServerFormat .format(endDate) .compareToIgnoreCase( DateTimeFormater.timeServerFormat.format(startTime)) < 0) { // set end date calendar.setTime(startTime); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); endDate = calendar.getTime(); tvRepeatEndDate.setText( DateTimeFormater.dateFullFormater.format(endDate)); } } }, hour, minute, true); dialog.setTitle("Select Start Time"); dialog.show(); break; } case R.id.tvEndTime: { TimePickerDialog dialog = new TimePickerDialog( this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); calendar.set(Calendar.MINUTE, minute); endTime = calendar.getTime(); // check if end time is less than start time, show error toast and set // default end time is // start time + 1 hour if (DateTimeFormater.timeServerFormat .format(endTime) .compareToIgnoreCase( DateTimeFormater.timeServerFormat.format(startTime)) < 0) { showCenterToast(R.string.msg_err_end_time_must_greater_start_time); calendar.setTime(startTime); calendar.add(Calendar.HOUR, 1); endTime = calendar.getTime(); } tvEndTime.setText(DateTimeFormater.timeFormater.format(endTime)); } }, hour, minute, true); dialog.setTitle("Select End Time"); dialog.show(); break; } default: break; } } }
/* (non-Javadoc) * @see android.app.Activity#onPrepareDialog(int, android.app.Dialog) */ @Override protected void onPrepareDialog(int id, Dialog dialog) { if (DIALOG_ID_ALARM_TIME == id && null != alarmTime) { ((TimePickerDialog) dialog).updateTime(alarmTime.getHourOfDay(), alarmTime.getMinutes()); } }
@Override public void onClick(final View v) { if (v == btnCalendarStart) { // Launch Date Picker Dialog DatePickerDialog dpdStart = new DatePickerDialog( this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // Display Selected date in textbox txtDateStart.setText( String.format("%02d", dayOfMonth) + "/" + String.format("%02d", (monthOfYear + 1)) + "/" + year); startYear = year; startMonth = monthOfYear; startDay = dayOfMonth; } }, startYear, startMonth, startDay); dpdStart.show(); } if (v == btnCalendarEnd) { // Launch End Date Picker Dialog DatePickerDialog dpdEnd = new DatePickerDialog( this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { txtDateEnd.setText( String.format("%02d", dayOfMonth) + "/" + String.format("%02d", (monthOfYear + 1)) + "/" + year); endYear = year; endMonth = monthOfYear; endDay = dayOfMonth; } }, endYear, endMonth, endDay); dpdEnd.show(); } if (v == btnTimeStart) { // Launch Time Picker Dialog TimePickerDialog tpdStart = new TimePickerDialog( this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { startHour = hourOfDay; startMinute = minute; if (startMinute != 0) { Date startDate = convertStringToDate( startDay, startMonth, startYear, startHour, startMinute); Date startDateRoundedToNearestHour = roundToNearestHour(startDate); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm"); // the format of your date sdf.setTimeZone( TimeZone.getTimeZone("GMT-5")); // give a timezone reference for formating String formattedDate = sdf.format(startDateRoundedToNearestHour); String[] formattedDateSeparated = formattedDate.split(" "); String[] formatDate = formattedDateSeparated[0].split("/"); String[] formatTime = formattedDateSeparated[1].split(":"); startDay = Integer.parseInt(formatDate[0]); startMonth = Integer.parseInt(formatDate[1]) - 1; startYear = Integer.parseInt(formatDate[2]); startHour = Integer.parseInt(formatTime[0]); startMinute = Integer.parseInt(formatTime[1]); txtDateStart.setText( String.format("%02d", startDay) + "/" + String.format("%02d", (startMonth + 1)) + "/" + startYear); } txtTimeStart.setText( String.format("%02d", startHour) + ":" + String.format("%02d", startMinute)); } }, startHour, startMinute, false); tpdStart.show(); } if (v == btnTimeEnd) { // Launch Time Picker Dialog TimePickerDialog tpdEnd = new TimePickerDialog( this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { endHour = hourOfDay; endMinute = minute; if (endMinute != 0) { Date endDate = convertStringToDate(endDay, endMonth, endYear, endHour, endMinute); Date endDateRoundedToNearestHour = roundToNearestHour(endDate); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm"); // the format of your date sdf.setTimeZone( TimeZone.getTimeZone("GMT-5")); // give a timezone reference for formating String formattedDate = sdf.format(endDateRoundedToNearestHour); String[] formattedDateSeparated = formattedDate.split(" "); String[] formatDate = formattedDateSeparated[0].split("/"); String[] formatTime = formattedDateSeparated[1].split(":"); endDay = Integer.parseInt(formatDate[0]); endMonth = Integer.parseInt(formatDate[1]) - 1; endYear = Integer.parseInt(formatDate[2]); endHour = Integer.parseInt(formatTime[0]); endMinute = Integer.parseInt(formatTime[1]); txtDateEnd.setText( String.format("%02d", endDay) + "/" + String.format("%02d", (endMonth + 1)) + "/" + endYear); } txtTimeEnd.setText( String.format("%02d", endHour) + ":" + String.format("%02d", endMinute)); } }, endHour, endMinute, false); tpdEnd.show(); } if (v == submitUpdate) { if (userSelectedDestination == null) { if (apiResults.getListings() != null) { mMap = mapFragment.getMap(); mMap.clear(); } Toast.makeText(MainActivity.this, "Destination cannot be empty", Toast.LENGTH_SHORT).show(); } else { if (doDateTimeValidation()) { spinner.setVisibility(View.VISIBLE); submitUpdate.setEnabled(false); autoCompView.setFocusable(false); autoCompView.setFocusableInTouchMode(true); submitUpdate.getBackground().setColorFilter(0xFFFFFFFF, PorterDuff.Mode.MULTIPLY); String sorting = "rating"; int checked_restroom = 0; int checked_mobile = 0; int checked_indoor = 0; int checked_attended = 0; int checked_security = 0; int checked_valet = 0; long epoch_start = userSelectedStartDateTime; long epoch_end = userSelectedEndDateTime; String urlString = "http://api.parkwhiz.com/search?destination=" + userSelectedDestination + "&key=" + getResources().getString(R.string.park_whiz_key) + "&start=" + epoch_start + "&end=" + epoch_end + "&sort=" + sorting + "&restroom=" + 0 + "&security=" + 0 + "&valet=" + 0 + "&indoor=" + 0 + "&eticket=" + 0 + "&attended=" + 0; Toast.makeText(MainActivity.this, "Sending your request", Toast.LENGTH_SHORT).show(); mMap = mapFragment.getMap(); mMap.clear(); apiResults = new GetAPIResults(getBaseContext(), mapFragment, this); apiResults.execute(urlString); hideSoftKeyboard(); } } } }
@Override public void onClick(View v) { // TODO Auto-generated method stub Toast toast = null; switch (v.getId()) { case R.id.editDailyDietChartDate: mYear = mCalendar.get(Calendar.YEAR); mMonth = mCalendar.get(Calendar.MONTH); mDay = mCalendar.get(Calendar.DAY_OF_MONTH); DatePickerDialog dialog = new DatePickerDialog(this, this, mYear, mMonth, mDay); dialog.show(); break; case R.id.editDailyDietChartTime: // Process to get Current Time mHour = mCalendar.get(Calendar.HOUR_OF_DAY); mMinute = mCalendar.get(Calendar.MINUTE); // Launch Time Picker Dialog TimePickerDialog tpd = new TimePickerDialog(this, this, mHour, mMinute, false); tpd.show(); break; case R.id.btnDietSave: mDate = etDate.getText().toString(); mTime = etTime.getText().toString(); mName = etName.getText().toString(); mDescription = etDescription.getText().toString(); if (cbAlarm.isChecked()) { mAlarm = "1"; Intent alarmIntent = new Intent(AlarmClock.ACTION_SET_ALARM); alarmIntent.putExtra(AlarmClock.EXTRA_MESSAGE, mDescription); alarmIntent.putExtra(AlarmClock.EXTRA_HOUR, mSetHour); alarmIntent.putExtra(AlarmClock.EXTRA_MINUTES, mSetMinute); alarmIntent.putExtra(AlarmClock.EXTRA_SKIP_UI, true); alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(alarmIntent); } DietChartModel activityDataInsert = new DietChartModel(); activityDataInsert.setDate(mDate); activityDataInsert.setTime(mTime); activityDataInsert.setEventName(mName); activityDataInsert.setFoodMenu(mDescription); activityDataInsert.setAlarm(mAlarm); /* * if update is needed then update otherwise submit */ if (mStrActivityID != null) { mActivityId = Long.parseLong(mStrActivityID); activityDS = new DietChartDataSource(this); if (activityDS.updateData(mActivityId, activityDataInsert) == true) { toast = Toast.makeText(this, "Successfully Updated.", Toast.LENGTH_LONG); toast.show(); // Intent intent = new Intent(); // intent.putExtra("activityID", mStrActivityID); // setResult(Activity.RESULT_OK, intent); // finish(); startActivity( new Intent( FTFLICareCreateDietChartActivity.this, FTFLICareDietChartActivity.class)); finish(); } else { toast = Toast.makeText(this, "Not Updated.", Toast.LENGTH_LONG); toast.show(); } } else { activityDS = new DietChartDataSource(this); if (activityDS.insert(activityDataInsert) == true) { toast = Toast.makeText(this, "Successfully Saved.", Toast.LENGTH_LONG); toast.show(); startActivity( new Intent(FTFLICareCreateDietChartActivity.this, FTFLICareHomeActivity.class)); /* startActivity(new Intent( ICareCreateDietChartActivity.this, ICareDietChartListActivity.class));*/ // finish(); } else { toast = Toast.makeText(this, "Not Saved.", Toast.LENGTH_LONG); toast.show(); } } break; } }
@Override public void onTimeChanged(TimePicker view, int hour, int minute) { super.onTimeChanged(view, hour, minute); updateTitle(hour, minute); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act_my_date_picker); Initial(); // 初始化方法 }
private void showUpdateIntervalTimePreferencesDialog() { final Context context = ui.getActivity(); MaterialDialog.Builder builder = new MaterialDialog.Builder(context); builder.title(R.string.pref_autoUpdateIntervallOrTime_title); builder.content(R.string.pref_autoUpdateIntervallOrTime_message); builder.positiveText(R.string.pref_autoUpdateIntervallOrTime_Interval); builder.negativeText(R.string.pref_autoUpdateIntervallOrTime_TimeOfDay); builder.neutralText(R.string.pref_autoUpdateIntervallOrTime_Disable); builder.onPositive( (dialog, which) -> { AlertDialog.Builder builder1 = new AlertDialog.Builder(context); builder1.setTitle(context.getString(R.string.pref_autoUpdateIntervallOrTime_Interval)); final String[] values = context.getResources().getStringArray(R.array.update_intervall_values); final String[] entries = getUpdateIntervalEntries(values); long currInterval = UserPreferences.getUpdateInterval(); int checkedItem = -1; if (currInterval > 0) { String currIntervalStr = String.valueOf(TimeUnit.MILLISECONDS.toHours(currInterval)); checkedItem = ArrayUtils.indexOf(values, currIntervalStr); } builder1.setSingleChoiceItems( entries, checkedItem, (dialog1, which1) -> { int hours = Integer.parseInt(values[which1]); UserPreferences.setUpdateInterval(hours); dialog1.dismiss(); setUpdateIntervalText(); }); builder1.setNegativeButton(context.getString(R.string.cancel_label), null); builder1.show(); }); builder.onNegative( (dialog, which) -> { int hourOfDay = 7, minute = 0; int[] updateTime = UserPreferences.getUpdateTimeOfDay(); if (updateTime.length == 2) { hourOfDay = updateTime[0]; minute = updateTime[1]; } TimePickerDialog timePickerDialog = new TimePickerDialog( context, (view, selectedHourOfDay, selectedMinute) -> { if (view.getTag() == null) { // onTimeSet() may get called twice! view.setTag("TAGGED"); UserPreferences.setUpdateTimeOfDay(selectedHourOfDay, selectedMinute); setUpdateIntervalText(); } }, hourOfDay, minute, DateFormat.is24HourFormat(context)); timePickerDialog.setTitle( context.getString(R.string.pref_autoUpdateIntervallOrTime_TimeOfDay)); timePickerDialog.show(); }); builder.onNeutral( (dialog, which) -> { UserPreferences.setUpdateInterval(0); setUpdateIntervalText(); }); builder.show(); }