List of usage examples for java.util Calendar AM
int AM
To view the source code for java.util Calendar AM.
Click Source Link
From source file:org.primefaces.extensions.showcase.controller.TimePickerController.java
public TimePickerController() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.AM_PM, Calendar.AM); calendar.set(Calendar.HOUR, 8); calendar.set(Calendar.MINUTE, 15); time1 = calendar.getTime();//from ww w .ja v a 2s.c om calendar.set(Calendar.HOUR, 11); calendar.set(Calendar.MINUTE, 40); time2 = calendar.getTime(); time3 = new Date(); time5 = new Date(); time6 = new Date(); }
From source file:com.brayanarias.alarmproject.receiver.AlarmReceiver.java
private static void setAlarmCumple(Context context) { PendingIntent pendingIntent = null;//from w w w . j a v a 2s . com Intent intent = new Intent(context, AlarmService.class); intent.putExtra(Constant.alarmIdKey, 2809); intent.putExtra(Constant.alarmNameKey, "Feliz cumple mamita"); pendingIntent = PendingIntent.getService(context, 2809, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = getAlarmManager(context); Calendar actual = Calendar.getInstance(); actual.set(Calendar.MONTH, 8); actual.set(Calendar.DAY_OF_MONTH, 28); actual.set(Calendar.SECOND, 0); actual.set(Calendar.MILLISECOND, 0); actual.set(Calendar.HOUR, 5); actual.set(Calendar.AM_PM, Calendar.AM); actual.set(Calendar.MINUTE, 0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { AlarmManager.AlarmClockInfo clockInfo = new AlarmManager.AlarmClockInfo(actual.getTimeInMillis(), pendingIntent); alarmManager.setAlarmClock(clockInfo, pendingIntent); } else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, actual.getTimeInMillis(), pendingIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, actual.getTimeInMillis(), pendingIntent); } }
From source file:helper.util.DateHelper.java
/** * Take a local time calendar and represent it as a day * (truncate to day, retain yy/mm/dd from original date) **///from ww w.ja v a2s . c om public static Calendar asDay(Calendar localTimeCalendar) { Calendar asDay = Calendar.getInstance(localTimeCalendar.getTimeZone()); asDay.clear(); asDay.set(localTimeCalendar.get(Calendar.YEAR), localTimeCalendar.get(Calendar.MONTH), localTimeCalendar.get(Calendar.DATE), 0, 0, 0); asDay.set(Calendar.AM_PM, Calendar.AM); asDay.set(Calendar.MILLISECOND, 0); asDay.set(Calendar.HOUR, 0); return asDay; }
From source file:org.osaf.cosmo.scheduler.ForwardLookingNotificationJob.java
@Override protected Report generateReport(JobExecutionContext context) throws JobExecutionException { TimeZone tz = timezone == null ? null : TimeZoneUtils.getTimeZone(timezone); Locale loc = locale == null ? Locale.getDefault() : new Locale(locale); // start date is the start of the day of the fire time Calendar cal = new GregorianCalendar(); if (tz != null) cal.setTimeZone(tz);/*w w w. ja v a2 s . c o m*/ cal.setTime(context.getFireTime()); cal.set(Calendar.AM_PM, Calendar.AM); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); Date startDate = new Date(cal.getTime().getTime()); // End date is either 1 day or 1 week later // depending on report type if (REPORT_TYPE_DAILY.equals(reportType)) cal.add(Calendar.DAY_OF_YEAR, 1); else cal.add(Calendar.WEEK_OF_YEAR, 1); cal.add(Calendar.SECOND, -1); Date endDate = cal.getTime(); if (log.isDebugEnabled()) { log.debug("startDate=" + startDate); log.debug("endDate = " + endDate); } // get results List<UpcomingResult> upcomingItems = new ArrayList<UpcomingResult>(); List<NowResult> nowItems = new ArrayList<NowResult>(); Iterator<String> it = getCollectionUids().iterator(); while (it.hasNext()) { String colUid = it.next(); // We have to handle changes to underlying collections. // A collection could have been deleted, or access to the // collection has been removed. In both cases, remove the // collection from the list so that the next job run // won't attempt to access it. try { getCollectionResults(colUid, startDate, endDate, tz, upcomingItems, nowItems); } catch (ItemSecurityException ise) { // user is not authorized for collection, // remove collection for next execution log.info("user " + getUsername() + " not authorized for collection " + colUid + ", removing from schedule " + context.getJobDetail().getName()); it.remove(); } catch (ItemNotFoundException infe) { // collection not found, remove collection for next execution log.info("collection " + colUid + " not found removing from schedule " + getUsername() + ":" + context.getJobDetail().getName()); it.remove(); } } // sort results Comparator<UpcomingResult> comparator = new UpcomingResultComparator(false, tz); Collections.sort(upcomingItems, comparator); // return results ForwardLookingReport report = new ForwardLookingReport(getUser()); report.setStartDate(startDate); report.setTimezone(tz == null ? TimeZone.getDefault() : tz); report.setLocale(loc); report.setReportType(reportType); report.setUpcomingItems(upcomingItems); report.setNowItems(nowItems); return report; }
From source file:org.sakaiproject.tool.section.jsf.backingbean.LocalMeetingModel.java
public LocalMeetingModel(Meeting meeting) { this.location = meeting.getLocation(); this.monday = meeting.isMonday(); this.tuesday = meeting.isTuesday(); this.wednesday = meeting.isWednesday(); this.thursday = meeting.isThursday(); this.friday = meeting.isFriday(); this.saturday = meeting.isSaturday(); this.sunday = meeting.isSunday(); this.startTimeString = JsfUtil.convertTimeToString(meeting.getStartTime()); if (startTimeString == null) { startTimeString = JsfUtil.getLocalizedMessage("section_start_time_default"); }/*w w w .j a v a2 s. com*/ this.endTimeString = JsfUtil.convertTimeToString(meeting.getEndTime()); if (endTimeString == null) { endTimeString = JsfUtil.getLocalizedMessage("section_end_time_default"); } Calendar cal = new GregorianCalendar(); if (meeting.getStartTime() == null) { this.startTimeAm = true; } else { cal.setTime(meeting.getStartTime()); if (log.isDebugEnabled()) log.debug("cal.get(Calendar.AM_PM) = " + cal.get(Calendar.AM_PM)); this.startTimeAm = (cal.get(Calendar.AM_PM) == Calendar.AM); } if (meeting.getEndTime() == null) { this.endTimeAm = true; } else { cal.setTime(meeting.getEndTime()); if (log.isDebugEnabled()) log.debug("cal.get(Calendar.AM_PM) = " + cal.get(Calendar.AM_PM)); this.endTimeAm = (cal.get(Calendar.AM_PM) == Calendar.AM); } }
From source file:helper.util.DateHelper.java
/** * Take a local time calendar and represent it as a UTC day * (truncate to day, retain yy/mm/dd from original date) **//* w ww .j a v a 2 s . c o m*/ public static Calendar asUtcDay(Calendar localTimeCalendar) { Calendar utcDate = Calendar.getInstance(DateUtils.UTC_TIME_ZONE); utcDate.clear(); utcDate.set(localTimeCalendar.get(Calendar.YEAR), localTimeCalendar.get(Calendar.MONTH), localTimeCalendar.get(Calendar.DATE), 0, 0, 0); utcDate.set(Calendar.AM_PM, Calendar.AM); utcDate.set(Calendar.MILLISECOND, 0); utcDate.set(Calendar.HOUR, 0); return utcDate; }
From source file:com.brayanarias.alarmproject.receiver.AlarmReceiver.java
private static void setAlarm(Context context, Alarm alarm) { try {//from w w w . java 2s .c om PendingIntent pendingIntent = createPendingIntent(context, alarm); AlarmManager alarmManager = getAlarmManager(context); Calendar actual = Calendar.getInstance(); actual.set(Calendar.SECOND, 0); actual.set(Calendar.MILLISECOND, 0); Calendar calendar = (Calendar) actual.clone(); int ampm = alarm.getAmPm().equals("AM") ? Calendar.AM : Calendar.PM; if (alarm.getHour() == 12) { calendar.set(Calendar.HOUR, 0); } else { calendar.set(Calendar.HOUR, alarm.getHour()); } calendar.set(Calendar.AM_PM, ampm); calendar.set(Calendar.MINUTE, alarm.getMinute()); int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); if (actual.getTimeInMillis() >= calendar.getTimeInMillis()) { if (alarm.getDaysOfAlamr().equals("0000000")) { calendar.add(Calendar.DATE, 1); } else { calendar.add(Calendar.DATE, getDaysFromNextAlarm(alarm.getDaysOfAlamr())); } } else { if (!AlarmUtilities.isToday(alarm.getDaysOfAlamr(), day)) { calendar.add(Calendar.DATE, getDaysFromNextAlarm(alarm.getDaysOfAlamr())); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { AlarmManager.AlarmClockInfo clockInfo = new AlarmManager.AlarmClockInfo(calendar.getTimeInMillis(), pendingIntent); alarmManager.setAlarmClock(clockInfo, pendingIntent); } else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); } } catch (Exception e) { Log.e(tag, e.getLocalizedMessage(), e); } }
From source file:com.brayanarias.alarmproject.activity.AlarmScreenActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_alarm_screen); int alarmId = getIntent().getIntExtra(Constant.alarmIdKey, -1); if (alarmId == -1) { finish();/* w ww . ja v a2 s . co m*/ } NotificationManager alarmNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); alarmNotificationManager.cancelAll(); String name = getIntent().getStringExtra(Constant.alarmNameKey); if (name == null || name.isEmpty()) { name = getString(R.string.app_name); } String hourFormatted = getIntent().getStringExtra(Constant.alarmHourFormattedKey); String msgampm = getIntent().getStringExtra(Constant.alarmAmPmKey); String msgNotification = name; msgNotification = msgNotification + " - " + hourFormatted + " " + msgampm; sendNotification(msgNotification); Calendar calendar = Calendar.getInstance(); String hourText; int actualAmPm = calendar.get(Calendar.AM_PM); String ampm = actualAmPm == Calendar.AM ? "AM" : "PM"; int hour = calendar.get(Calendar.HOUR); hour = hour == 0 ? 12 : hour; int minute = calendar.get(Calendar.MINUTE); String minuteString = minute >= 10 ? "" + minute : "0" + minute; hourText = hour + ":" + minuteString + " " + ampm; TextView tvAlarmHourScreen = (TextView) findViewById(R.id.tvAlarmHourScreen); tvAlarmHourScreen.setText(hourText); TextView tvAlarmNameScreen = (TextView) findViewById(R.id.tvAlarmNameScreen); if (name.equals(getString(R.string.app_name))) { name = AlarmUtilities.getSalute(getApplicationContext()); } if (tvAlarmNameScreen != null) { tvAlarmNameScreen.setText(name); } FloatingActionButton btDismiss = (FloatingActionButton) findViewById(R.id.btDismiss); if (btDismiss != null) { btDismiss.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mediaPlayer != null && mediaPlayer.isPlaying()) { mediaPlayer.stop(); } if (vibrator != null) { vibrator.cancel(); } finish(); } }); } FloatingActionButton btPostpone = (FloatingActionButton) findViewById(R.id.btPostpone); if (btPostpone != null) { btPostpone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int alarmId = getIntent().getIntExtra(Constant.alarmIdKey, -1); int postpone = getIntent().getIntExtra(Constant.alarmPostponeKey, -1); int minutes = getResources().getIntArray(R.array.alarm_postpone_value_array)[postpone]; AlarmReceiver.dismissAlarm(alarmId, minutes, getApplicationContext()); String text = AlarmUtilities.getMessageRemainingPostpone(postpone, getResources()); Toast.makeText(getApplication(), text, Toast.LENGTH_SHORT).show(); flag = false; finish(); } }); } int postpone = getIntent().getIntExtra(Constant.alarmPostponeKey, -1); //postpone configuration if (postpone > 0) { String timeText = getResources().getStringArray(R.array.alarm_postpone_array)[postpone]; } else { if (btPostpone != null) { btPostpone.setEnabled(false); } } String tone = getIntent().getStringExtra(Constant.alarmToneKey); playRingtone(tone); //Start animation starAnimation(); //Ensure wakelock release Runnable releaseWakelock = new Runnable() { @Override public void run() { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); if (wakeLock != null && wakeLock.isHeld()) { wakeLock.release(); if (mediaPlayer != null && mediaPlayer.isPlaying()) { mediaPlayer.stop(); } if (vibrator != null) { vibrator.cancel(); } Log.e(TAG, "Entra a realease wakelock"); finish(); } } }; new Handler().postDelayed(releaseWakelock, WAKELOCK_TIMEOUT); }
From source file:org.syncope.console.wicket.markup.html.form.DateTimeFieldPanel.java
public DateTimeFieldPanel(final String id, final String name, final IModel<Date> model, final boolean active, final String datePattern) { super(id, name, model, active); this.datePattern = datePattern; field = new DateTimeField("field", model); final Calendar cal = Calendar.getInstance(); field.get("hours").add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -1107858522700306810L; @Override// w w w . java 2s . c o m protected void onUpdate(AjaxRequestTarget art) { if (((DateTimeField) field).getHours() > 12) { cal.set(Calendar.HOUR_OF_DAY, ((DateTimeField) field).getHours()); } else { cal.set(Calendar.HOUR, ((DateTimeField) field).getHours()); } field.setModelObject(cal.getTime()); } }); field.get("minutes").add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { cal.set(Calendar.MINUTE, ((DateTimeField) field).getMinutes()); field.setModelObject(cal.getTime()); } }); field.get("date").add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { cal.setTime(((DateTimeField) field).getDate()); if ("PM".equals("" + ((DateTimeField) field).getAmOrPm())) { cal.set(Calendar.AM_PM, Calendar.PM); } else { cal.set(Calendar.AM_PM, Calendar.AM); } field.setModelObject(cal.getTime()); } }); field.get("amOrPmChoice").add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { if ("PM".equals("" + ((DateTimeField) field).getAmOrPm())) { cal.set(Calendar.AM_PM, Calendar.PM); } else { cal.set(Calendar.AM_PM, Calendar.AM); } field.setModelObject(cal.getTime()); } }); add(field.setLabel(new Model(name)).setOutputMarkupId(true)); }
From source file:net.kjmaster.cookiemom.booth.add.AddBoothDialogFragment.java
private void showDateTimeDialog() { // Create the dialog final Dialog mDateTimeDialog = new Dialog(getActivity()); // Inflate the root layout final RelativeLayout mDateTimeDialogView = (RelativeLayout) getActivity().getLayoutInflater() .inflate(R.layout.ui_date_time_dialog, null); // Grab widget instance final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView .findViewById(R.id.DateTimePicker); // Check is system is set to use 24h time (this doesn't seem to work as expected though) final String timeS = android.provider.Settings.System.getString(getActivity().getContentResolver(), android.provider.Settings.System.TIME_12_24); final boolean is24h = !(timeS == null || timeS.equals("12")); // Update demo TextViews when the "OK" button is clicked mDateTimeDialogView.findViewById(R.id.SetDateTime).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { mDateTimePicker.clearFocus(); // TODO Auto-generated method stub String eventDate = SimpleDateFormat.getDateInstance(DateFormat.LONG) .format(new Date(mDateTimePicker.getDateTimeMillis())); ((TextView) getActivity().findViewById(R.id.Date)).setText(eventDate); if (mDateTimePicker.is24HourView()) { ((TextView) getActivity().findViewById(R.id.Time)).setText( mDateTimePicker.get(Calendar.HOUR_OF_DAY) + ":" + mDateTimePicker.get(Calendar.MINUTE)); } else { NumberFormat fmt = NumberFormat.getNumberInstance(); fmt.setMinimumIntegerDigits(2); ((TextView) getActivity().findViewById(R.id.Time)) .setText(fmt.format(mDateTimePicker.get(Calendar.HOUR)) + ":" + fmt.format(mDateTimePicker.get(Calendar.MINUTE)) + " " + (mDateTimePicker.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM")); }/* w ww.j a v a 2s. co m*/ hiddenDateTime.setText(String.valueOf(mDateTimePicker.getDateTimeMillis())); mDateTimeDialog.dismiss(); } }); // Cancel the dialog when the "Cancel" button is clicked mDateTimeDialogView.findViewById(R.id.CancelDialog).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub mDateTimeDialog.cancel(); } }); // Reset Date and Time pickers when the "Reset" button is clicked mDateTimeDialogView.findViewById(R.id.ResetDateTime).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub mDateTimePicker.reset(); } }); // Setup TimePicker mDateTimePicker.setIs24HourView(is24h); // No title on the dialog window mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // Set the dialog content view mDateTimeDialog.setContentView(mDateTimeDialogView); // Display the dialog mDateTimeDialog.show(); }