|
|
@ -1,7 +1,6 @@
|
|
|
|
package com.todoroo.astrid.reminders;
|
|
|
|
package com.todoroo.astrid.reminders;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Notification;
|
|
|
|
import android.app.Notification;
|
|
|
@ -17,85 +16,66 @@ import android.net.Uri;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
import com.timsu.astrid.R;
|
|
|
|
import com.timsu.astrid.R;
|
|
|
|
import com.timsu.astrid.activities.TaskListNotify;
|
|
|
|
|
|
|
|
import com.timsu.astrid.activities.TaskListSubActivity;
|
|
|
|
|
|
|
|
import com.timsu.astrid.data.task.TaskController;
|
|
|
|
|
|
|
|
import com.timsu.astrid.data.task.TaskIdentifier;
|
|
|
|
import com.timsu.astrid.data.task.TaskIdentifier;
|
|
|
|
import com.timsu.astrid.data.task.TaskModelForReminder;
|
|
|
|
|
|
|
|
import com.timsu.astrid.utilities.Constants;
|
|
|
|
import com.timsu.astrid.utilities.Constants;
|
|
|
|
import com.timsu.astrid.utilities.Preferences;
|
|
|
|
import com.timsu.astrid.utilities.Preferences;
|
|
|
|
|
|
|
|
import com.todoroo.andlib.service.Autowired;
|
|
|
|
|
|
|
|
import com.todoroo.andlib.service.DependencyInjectionService;
|
|
|
|
|
|
|
|
import com.todoroo.andlib.service.ExceptionService;
|
|
|
|
|
|
|
|
import com.todoroo.andlib.utility.DateUtilities;
|
|
|
|
|
|
|
|
import com.todoroo.astrid.dao.TaskDao;
|
|
|
|
|
|
|
|
import com.todoroo.astrid.model.Task;
|
|
|
|
|
|
|
|
import com.todoroo.astrid.service.AstridDependencyInjector;
|
|
|
|
|
|
|
|
|
|
|
|
public class Notifications extends BroadcastReceiver {
|
|
|
|
public class Notifications extends BroadcastReceiver {
|
|
|
|
|
|
|
|
|
|
|
|
static final String ID_KEY = "id";
|
|
|
|
// --- constants
|
|
|
|
static final String TYPE_KEY = "flags";
|
|
|
|
|
|
|
|
private static final String REPEAT_KEY = "repeat";
|
|
|
|
/** task id extra */
|
|
|
|
private static final int TAG_ID_OFFSET = 100000;
|
|
|
|
static final String ID_KEY = "id"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
|
|
// stuff for scheduling
|
|
|
|
/** notification type extra */
|
|
|
|
/** minimum # of seconds before a deadline to notify */
|
|
|
|
static final String TYPE_KEY = "flags"; //$NON-NLS-1$
|
|
|
|
private static final int DEADLINE_NOTIFY_SECS = 60 * 60;
|
|
|
|
|
|
|
|
/** # of seconds after deadline to repeat reminder*/
|
|
|
|
// --- instance variables
|
|
|
|
private static final int DEADLINE_REPEAT = 10 * 60;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
// flags
|
|
|
|
private TaskDao taskDao;
|
|
|
|
public static final int FLAG_DEFINITE_DEADLINE = 1 << 0;
|
|
|
|
|
|
|
|
public static final int FLAG_PREFERRED_DEADLINE = 1 << 1;
|
|
|
|
@Autowired
|
|
|
|
public static final int FLAG_OVERDUE = 1 << 2;
|
|
|
|
private ExceptionService exceptionService;
|
|
|
|
public static final int FLAG_PERIODIC = 1 << 3;
|
|
|
|
|
|
|
|
public static final int FLAG_FIXED = 1 << 4;
|
|
|
|
// --- alarm handling
|
|
|
|
public static final int FLAG_SNOOZE = 1 << 5;
|
|
|
|
|
|
|
|
/** # of bits to shift the fixed alert ID */
|
|
|
|
static {
|
|
|
|
public static final int FIXED_ID_SHIFT = 6;
|
|
|
|
AstridDependencyInjector.initialize();
|
|
|
|
|
|
|
|
|
|
|
|
private static Random random = new Random();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Something we can create a notification for */
|
|
|
|
|
|
|
|
public interface Notifiable {
|
|
|
|
|
|
|
|
public TaskIdentifier getTaskIdentifier();
|
|
|
|
|
|
|
|
public Integer getNotificationIntervalSeconds();
|
|
|
|
|
|
|
|
public boolean isTaskCompleted();
|
|
|
|
|
|
|
|
public Date getHiddenUntil();
|
|
|
|
|
|
|
|
public Date getDefiniteDueDate();
|
|
|
|
|
|
|
|
public Date getPreferredDueDate();
|
|
|
|
|
|
|
|
public Date getLastNotificationDate();
|
|
|
|
|
|
|
|
public int getNotificationFlags();
|
|
|
|
|
|
|
|
public Integer getEstimatedSeconds();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
/** Alarm intent */
|
|
|
|
/** Alarm intent */
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
|
|
|
DependencyInjectionService.getInstance().inject(this);
|
|
|
|
|
|
|
|
|
|
|
|
long id = intent.getLongExtra(ID_KEY, 0);
|
|
|
|
long id = intent.getLongExtra(ID_KEY, 0);
|
|
|
|
int flags = intent.getIntExtra(FLAGS_KEY, 0);
|
|
|
|
int type = intent.getIntExtra(TYPE_KEY, 0);
|
|
|
|
|
|
|
|
|
|
|
|
Resources r = context.getResources();
|
|
|
|
Resources r = context.getResources();
|
|
|
|
String reminder;
|
|
|
|
String reminder;
|
|
|
|
if((flags & FLAG_DEFINITE_DEADLINE) > 0)
|
|
|
|
if(type == ReminderService.TYPE_DUE || type == ReminderService.TYPE_OVERDUE)
|
|
|
|
reminder = r.getString(R.string.notif_definiteDueDate);
|
|
|
|
reminder = getRandomReminder(r.getStringArray(R.array.reminders_due));
|
|
|
|
else if((flags & FLAG_PREFERRED_DEADLINE) > 0)
|
|
|
|
else if(type == ReminderService.TYPE_SNOOZE)
|
|
|
|
reminder = r.getString(R.string.notif_preferredDueDate);
|
|
|
|
reminder = getRandomReminder(r.getStringArray(R.array.reminders_snooze));
|
|
|
|
else
|
|
|
|
else
|
|
|
|
reminder = getRandomReminder(r);
|
|
|
|
reminder = getRandomReminder(r.getStringArray(R.array.reminders));
|
|
|
|
|
|
|
|
|
|
|
|
long repeatInterval = intent.getLongExtra(REPEAT_KEY, 0);
|
|
|
|
|
|
|
|
if(Constants.DEBUG)
|
|
|
|
|
|
|
|
Log.e("ALARM", "Alarm triggered id " + id +", flags " + flags +
|
|
|
|
|
|
|
|
", repeat " + repeatInterval);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!showNotification(context, id, flags, repeatInterval, reminder)) {
|
|
|
|
if(!showNotification(context, id, type, reminder)) {
|
|
|
|
deleteAlarm(context, intent, id);
|
|
|
|
|
|
|
|
NotificationManager nm = (NotificationManager)
|
|
|
|
NotificationManager nm = (NotificationManager)
|
|
|
|
context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
nm.cancel((int)id);
|
|
|
|
nm.cancel((int)id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// --- alarm manager stuff
|
|
|
|
// --- notification creation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- notification manager stuff
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Clear notifications associated with this application */
|
|
|
|
/** Clear notifications associated with this application */
|
|
|
|
public static void clearAllNotifications(Context context, TaskIdentifier taskId) {
|
|
|
|
public static void clearAllNotifications(Context context, TaskIdentifier taskId) {
|
|
|
@ -104,57 +84,46 @@ public class Notifications extends BroadcastReceiver {
|
|
|
|
nm.cancel((int)taskId.getId());
|
|
|
|
nm.cancel((int)taskId.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static String getRandomReminder(Resources r) {
|
|
|
|
/** @return a random reminder string */
|
|
|
|
String[] reminders = r.getStringArray(R.array.reminders);
|
|
|
|
private static String getRandomReminder(String[] reminders) {
|
|
|
|
int next = random.nextInt(reminders.length);
|
|
|
|
int next = ReminderService.random.nextInt(reminders.length);
|
|
|
|
String reminder = reminders[next];
|
|
|
|
String reminder = reminders[next];
|
|
|
|
return reminder;
|
|
|
|
return reminder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Schedule a new notification about the given task. Returns false if there was
|
|
|
|
/**
|
|
|
|
* some sort of error or the alarm should be disabled. */
|
|
|
|
* Schedule a new notification about the given task. Returns false if there was
|
|
|
|
public static boolean showNotification(Context context, long id,
|
|
|
|
* some sort of error or the alarm should be disabled.
|
|
|
|
int flags, long repeatInterval, String reminder) {
|
|
|
|
*/
|
|
|
|
|
|
|
|
public boolean showNotification(Context context, long id,
|
|
|
|
|
|
|
|
int type, String reminder) {
|
|
|
|
|
|
|
|
|
|
|
|
String taskName;
|
|
|
|
Task task;
|
|
|
|
TaskController controller = new TaskController(context);
|
|
|
|
|
|
|
|
boolean nonstopMode = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
controller.open();
|
|
|
|
task = taskDao.fetch(id, Task.TITLE, Task.HIDE_UNTIL, Task.COMPLETION_DATE,
|
|
|
|
TaskModelForReminder task = controller.fetchTaskForReminder(new TaskIdentifier(id));
|
|
|
|
Task.DELETION_DATE, Task.REMINDER_FLAGS);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
// you're working on it - don't sound, don't delete
|
|
|
|
exceptionService.reportError("show-notif", e); //$NON-NLS-1$
|
|
|
|
if(task.getTimerStart() != null)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// you're done - don't sound, do delete
|
|
|
|
|
|
|
|
if(task.isTaskCompleted())
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// it's hidden - don't sound, don't delete
|
|
|
|
// you're done - don't sound, do delete
|
|
|
|
if(task.getHiddenUntil() != null &&
|
|
|
|
if(task.isCompleted() || task.isDeleted())
|
|
|
|
task.getHiddenUntil().after(new Date()) &&
|
|
|
|
return false;
|
|
|
|
(flags & FLAG_PERIODIC) > 0)
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
taskName = task.getName();
|
|
|
|
// it's hidden - don't sound, don't delete
|
|
|
|
if((flags & FLAG_PERIODIC) > 0)
|
|
|
|
if(task.isHidden() && type == ReminderService.TYPE_RANDOM)
|
|
|
|
controller.setLastNotificationTime(task.getTaskIdentifier(),
|
|
|
|
return true;
|
|
|
|
new Date());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if((task.getNotificationFlags() & TaskModelForReminder.NOTIFY_NONSTOP) > 0)
|
|
|
|
// read properties
|
|
|
|
nonstopMode = true;
|
|
|
|
String taskTitle = task.getValue(Task.TITLE);
|
|
|
|
|
|
|
|
boolean nonstopMode = task.getFlag(Task.REMINDER_FLAGS, Task.NOTIFY_NONSTOP);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
// update last reminder time
|
|
|
|
// task might have been deleted
|
|
|
|
task.setValue(Task.REMINDER_LAST, DateUtilities.now());
|
|
|
|
Log.e(Notifications.class.getSimpleName(),
|
|
|
|
taskDao.save(task, false);
|
|
|
|
"Error loading task for notification", e);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
controller.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// quiet hours? disabled if alarm clock
|
|
|
|
// quiet hours? unless alarm clock
|
|
|
|
boolean quietHours = false;
|
|
|
|
boolean quietHours = false;
|
|
|
|
Integer quietHoursStart = Preferences.getQuietHourStart(context);
|
|
|
|
Integer quietHoursStart = Preferences.getQuietHourStart(context);
|
|
|
|
Integer quietHoursEnd = Preferences.getQuietHourEnd(context);
|
|
|
|
Integer quietHoursEnd = Preferences.getQuietHourEnd(context);
|
|
|
@ -173,11 +142,11 @@ public class Notifications extends BroadcastReceiver {
|
|
|
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
Resources r = context.getResources();
|
|
|
|
Resources r = context.getResources();
|
|
|
|
|
|
|
|
|
|
|
|
Intent notifyIntent = new Intent(context, TaskListNotify.class);
|
|
|
|
Intent notifyIntent = new Intent(context, NotificationActivity.class);
|
|
|
|
notifyIntent.putExtra(TaskListSubActivity.LOAD_INSTANCE_TOKEN, id);
|
|
|
|
/*notifyIntent.putExtra(TaskListSubActivity.LOAD_INSTANCE_TOKEN, id);
|
|
|
|
notifyIntent.putExtra(TaskListSubActivity.FROM_NOTIFICATION_TOKEN, true);
|
|
|
|
notifyIntent.putExtra(TaskListSubActivity.FROM_NOTIFICATION_TOKEN, true);
|
|
|
|
notifyIntent.putExtra(TaskListSubActivity.NOTIF_FLAGS_TOKEN, flags);
|
|
|
|
notifyIntent.putExtra(TaskListSubActivity.NOTIF_FLAGS_TOKEN, flags);
|
|
|
|
notifyIntent.putExtra(TaskListSubActivity.NOTIF_REPEAT_TOKEN, repeatInterval);
|
|
|
|
notifyIntent.putExtra(TaskListSubActivity.NOTIF_REPEAT_TOKEN, repeatInterval); TODO */
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(context,
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(context,
|
|
|
|
(int)id, notifyIntent, PendingIntent.FLAG_ONE_SHOT);
|
|
|
|
(int)id, notifyIntent, PendingIntent.FLAG_ONE_SHOT);
|
|
|
|
|
|
|
|
|
|
|
@ -200,7 +169,7 @@ public class Notifications extends BroadcastReceiver {
|
|
|
|
icon, reminder, System.currentTimeMillis());
|
|
|
|
icon, reminder, System.currentTimeMillis());
|
|
|
|
notification.setLatestEventInfo(context,
|
|
|
|
notification.setLatestEventInfo(context,
|
|
|
|
appName,
|
|
|
|
appName,
|
|
|
|
reminder + " " + taskName,
|
|
|
|
reminder + " " + taskTitle, //$NON-NLS-1$
|
|
|
|
pendingIntent);
|
|
|
|
pendingIntent);
|
|
|
|
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
|
|
|
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
|
|
|
if(Preferences.isPersistenceMode(context)) {
|
|
|
|
if(Preferences.isPersistenceMode(context)) {
|
|
|
@ -216,10 +185,10 @@ public class Notifications extends BroadcastReceiver {
|
|
|
|
AudioManager audioManager = (AudioManager)context.getSystemService(
|
|
|
|
AudioManager audioManager = (AudioManager)context.getSystemService(
|
|
|
|
Context.AUDIO_SERVICE);
|
|
|
|
Context.AUDIO_SERVICE);
|
|
|
|
|
|
|
|
|
|
|
|
// if nonstop mode is activated, set up the flags for insistent
|
|
|
|
// if non-stop mode is activated, set up the flags for insistent
|
|
|
|
// notification, and increase the volume to full volume, so the user
|
|
|
|
// notification, and increase the volume to full volume, so the user
|
|
|
|
// will actually pay attention to the alarm
|
|
|
|
// will actually pay attention to the alarm
|
|
|
|
if(nonstopMode && (flags & FLAG_PERIODIC) == 0) {
|
|
|
|
if(nonstopMode && (type != ReminderService.TYPE_RANDOM)) {
|
|
|
|
notification.flags |= Notification.FLAG_INSISTENT;
|
|
|
|
notification.flags |= Notification.FLAG_INSISTENT;
|
|
|
|
notification.audioStreamType = AudioManager.STREAM_ALARM;
|
|
|
|
notification.audioStreamType = AudioManager.STREAM_ALARM;
|
|
|
|
audioManager.setStreamVolume(AudioManager.STREAM_ALARM,
|
|
|
|
audioManager.setStreamVolume(AudioManager.STREAM_ALARM,
|
|
|
@ -236,7 +205,7 @@ public class Notifications extends BroadcastReceiver {
|
|
|
|
if(audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0) {
|
|
|
|
if(audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0) {
|
|
|
|
notification.sound = null;
|
|
|
|
notification.sound = null;
|
|
|
|
} else if(notificationSound != null &&
|
|
|
|
} else if(notificationSound != null &&
|
|
|
|
!notificationSound.toString().equals("")) {
|
|
|
|
!notificationSound.toString().equals("")) { //$NON-NLS-1$
|
|
|
|
notification.sound = notificationSound;
|
|
|
|
notification.sound = notificationSound;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
notification.defaults |= Notification.DEFAULT_SOUND;
|
|
|
|
notification.defaults |= Notification.DEFAULT_SOUND;
|
|
|
@ -244,7 +213,7 @@ public class Notifications extends BroadcastReceiver {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// quiet hours + periodic = no vibrate
|
|
|
|
// quiet hours + periodic = no vibrate
|
|
|
|
if(quietHours && (flags & FLAG_PERIODIC) > 0) {
|
|
|
|
if(quietHours && (type == ReminderService.TYPE_RANDOM)) {
|
|
|
|
notification.vibrate = null;
|
|
|
|
notification.vibrate = null;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (Preferences.shouldVibrate(context)
|
|
|
|
if (Preferences.shouldVibrate(context)
|
|
|
@ -256,121 +225,10 @@ public class Notifications extends BroadcastReceiver {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(Constants.DEBUG)
|
|
|
|
if(Constants.DEBUG)
|
|
|
|
Log.w("Astrid", "Logging notification: " + reminder);
|
|
|
|
Log.w("Astrid", "Logging notification: " + reminder); //$NON-NLS-1$ //$NON-NLS-2$
|
|
|
|
nm.notify((int)id, notification);
|
|
|
|
nm.notify((int)id, notification);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Show a notification when a user is "on-the-clock" for a given task */
|
|
|
|
|
|
|
|
public static boolean showTimingNotification(Context context,
|
|
|
|
|
|
|
|
TaskIdentifier taskId, String taskName) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String text = context.getResources().getString(R.string.notif_timerStarted) +
|
|
|
|
|
|
|
|
" " + taskName;
|
|
|
|
|
|
|
|
NotificationManager nm = (NotificationManager) context
|
|
|
|
|
|
|
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
|
|
|
|
Resources r = context.getResources();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Intent notifyIntent = new Intent(context, TaskListNotify.class);
|
|
|
|
|
|
|
|
notifyIntent.putExtra(TaskListSubActivity.LOAD_INSTANCE_TOKEN, taskId.getId());
|
|
|
|
|
|
|
|
notifyIntent.putExtra(TaskListSubActivity.FROM_NOTIFICATION_TOKEN, true);
|
|
|
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(context,
|
|
|
|
|
|
|
|
(int)taskId.getId(), notifyIntent, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create notification object
|
|
|
|
|
|
|
|
int icon;
|
|
|
|
|
|
|
|
switch(Preferences.getNotificationIconTheme(context)) {
|
|
|
|
|
|
|
|
case Preferences.ICON_SET_PINK:
|
|
|
|
|
|
|
|
icon = R.drawable.notif_pink_working;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Preferences.ICON_SET_BORING:
|
|
|
|
|
|
|
|
icon = R.drawable.notif_boring_working;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
icon = R.drawable.notif_astrid;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String appName = r.getString(R.string.app_name);
|
|
|
|
|
|
|
|
Notification notification = new Notification(
|
|
|
|
|
|
|
|
icon, text, System.currentTimeMillis());
|
|
|
|
|
|
|
|
notification.setLatestEventInfo(context,
|
|
|
|
|
|
|
|
appName,
|
|
|
|
|
|
|
|
text,
|
|
|
|
|
|
|
|
pendingIntent);
|
|
|
|
|
|
|
|
notification.flags |= Notification.FLAG_ONGOING_EVENT |
|
|
|
|
|
|
|
|
Notification.FLAG_NO_CLEAR;
|
|
|
|
|
|
|
|
notification.flags &= ~Notification.FLAG_AUTO_CANCEL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(Constants.DEBUG)
|
|
|
|
|
|
|
|
Log.w("Astrid", "Logging timing notification: " + text);
|
|
|
|
|
|
|
|
nm.notify((int)taskId.getId(), notification);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Schedule a new notification about the given tag. */
|
|
|
|
|
|
|
|
public static boolean showTagNotification(Context context, long tagId,
|
|
|
|
|
|
|
|
String reminder) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// quiet hours? only for periodic reminders
|
|
|
|
|
|
|
|
boolean quietHours = false;
|
|
|
|
|
|
|
|
Integer quietHoursStart = Preferences.getQuietHourStart(context);
|
|
|
|
|
|
|
|
Integer quietHoursEnd = Preferences.getQuietHourEnd(context);
|
|
|
|
|
|
|
|
if(quietHoursStart != null && quietHoursEnd != null) {
|
|
|
|
|
|
|
|
int hour = new Date().getHours();
|
|
|
|
|
|
|
|
if(quietHoursStart < quietHoursEnd) {
|
|
|
|
|
|
|
|
if(hour >= quietHoursStart && hour < quietHoursEnd)
|
|
|
|
|
|
|
|
quietHours = true;
|
|
|
|
|
|
|
|
} else { // wrap across 24/hour boundary
|
|
|
|
|
|
|
|
if(hour >= quietHoursStart || hour < quietHoursEnd)
|
|
|
|
|
|
|
|
quietHours = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NotificationManager nm = (NotificationManager) context
|
|
|
|
|
|
|
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
|
|
|
|
Resources r = context.getResources();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Intent notifyIntent = new Intent(context, TaskListNotify.class);
|
|
|
|
|
|
|
|
notifyIntent.putExtra(TaskListSubActivity.TAG_TOKEN, tagId);
|
|
|
|
|
|
|
|
notifyIntent.putExtra(TaskListSubActivity.FROM_NOTIFICATION_TOKEN, true);
|
|
|
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(context,
|
|
|
|
|
|
|
|
TAG_ID_OFFSET + (int)tagId, notifyIntent, PendingIntent.FLAG_ONE_SHOT);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set up properties (name and icon) for the notification
|
|
|
|
|
|
|
|
String appName = r.getString(R.string.app_name);
|
|
|
|
|
|
|
|
int icon = R.drawable.notif_tag;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create notification object
|
|
|
|
|
|
|
|
Notification notification = new Notification(
|
|
|
|
|
|
|
|
icon, reminder, System.currentTimeMillis());
|
|
|
|
|
|
|
|
notification.setLatestEventInfo(context,
|
|
|
|
|
|
|
|
appName,
|
|
|
|
|
|
|
|
reminder,
|
|
|
|
|
|
|
|
pendingIntent);
|
|
|
|
|
|
|
|
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
|
|
|
|
|
|
|
notification.ledARGB = Color.BLUE;
|
|
|
|
|
|
|
|
notification.defaults = Notification.DEFAULT_LIGHTS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(quietHours) {
|
|
|
|
|
|
|
|
notification.vibrate = null;
|
|
|
|
|
|
|
|
notification.sound = null;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
notification.defaults |= Notification.DEFAULT_VIBRATE;
|
|
|
|
|
|
|
|
Uri notificationSound = Preferences.getNotificationRingtone(context);
|
|
|
|
|
|
|
|
if(notificationSound != null &&
|
|
|
|
|
|
|
|
!notificationSound.toString().equals("")) {
|
|
|
|
|
|
|
|
notification.sound = notificationSound;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
notification.defaults |= Notification.DEFAULT_SOUND;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(Constants.DEBUG)
|
|
|
|
|
|
|
|
Log.w("Astrid", "Logging tag notification: " + reminder);
|
|
|
|
|
|
|
|
nm.notify(TAG_ID_OFFSET + (int)tagId, notification);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|