Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Calendar getNextAlarmTime() {
- Calendar now = Calendar.getInstance();
- Calendar reminderTime = Calendar.getInstance();
- Calendar expireDate = Calendar.getInstance();
- SimpleDateFormat hourMinuteFormat = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
- SimpleDateFormat expireDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
- try {
- expireDate.setTime(expireDateFormat.parse(expired));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- expireDate.add(Calendar.DATE, 1);
- String nowHourString = hourMinuteFormat.format(now);
- int listSize = reminderTimes.size();
- for (int i = 0; i<listSize; i++) {
- String time = reminderTimes.get(i);
- int stringComp = nowHourString.compareTo(time);
- if (stringComp<0) {
- try {
- reminderTime.setTime(hourMinuteFormat.parse(time));
- if (reminderTime.before(expireDate))
- return reminderTime;
- else
- return null;
- } catch (ParseException e) {
- e.printStackTrace();
- return null;
- }
- } else if (i==listSize-1) {
- try {
- reminderTime.setTime(hourMinuteFormat.parse(reminderTimes.get(0)));
- reminderTime.add(Calendar.DATE, reminderInterval);
- if (reminderTime.before(expireDate))
- return reminderTime;
- else
- return null;
- } catch (ParseException e) {
- e.printStackTrace();
- return null;
- }
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment