/** * Show a new notification about the given task. Returns false if there was some sort of error or * the alarm should be disabled. */ public boolean showTaskNotification(long id, int type, String reminder) { Task task; try { task = taskDao.fetch( id, Task.ID, Task.TITLE, Task.HIDE_UNTIL, Task.COMPLETION_DATE, Task.DUE_DATE, Task.DELETION_DATE, Task.REMINDER_FLAGS); if (task == null) throw new IllegalArgumentException("cound not find item with id"); // $NON-NLS-1$ } catch (Exception e) { exceptionService.reportError("show-notif", e); // $NON-NLS-1$ return false; } // you're done - don't sound, do delete if (task.isCompleted() || task.isDeleted()) return false; // it's hidden - don't sound, don't delete if (task.isHidden() && type == ReminderService.TYPE_RANDOM) return true; // task due date was changed, but alarm wasn't rescheduled if ((type == ReminderService.TYPE_DUE || type == ReminderService.TYPE_OVERDUE) && (!task.hasDueDate() || task.getValue(Task.DUE_DATE) > DateUtilities.now())) return true; // read properties String taskTitle = task.getValue(Task.TITLE); boolean nonstopMode = task.getFlag(Task.REMINDER_FLAGS, Task.NOTIFY_MODE_NONSTOP); boolean ringFiveMode = task.getFlag(Task.REMINDER_FLAGS, Task.NOTIFY_MODE_FIVE); int ringTimes = nonstopMode ? -1 : (ringFiveMode ? 5 : 1); // update last reminder time task.setValue(Task.REMINDER_LAST, DateUtilities.now()); taskDao.saveExisting(task); Context context = ContextManager.getContext(); String title = context.getString(R.string.app_name); String text = reminder + " " + taskTitle; // $NON-NLS-1$ Intent notifyIntent = new Intent(context, NotificationActivity.class); notifyIntent.setAction("NOTIFY" + id); // $NON-NLS-1$ notifyIntent.putExtra(NotificationActivity.TOKEN_ID, id); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); showNotification((int) id, notifyIntent, type, title, text, ringTimes); return true; }