Made Locale Receiver use our notification code for ringtone and quiet hours

pull/14/head
Tim Su 14 years ago
parent 861bc9a4c9
commit 710e5825db

@ -4,7 +4,7 @@
<booleanAttribute key="ch.zork.quicklaunch" value="true"/>
<stringAttribute key="ch.zork.quicklaunch.icon" value="14.gif"/>
<intAttribute key="ch.zork.quicklaunch.index" value="0"/>
<stringAttribute key="ch.zork.quicklaunch.mode" value="debug"/>
<stringAttribute key="ch.zork.quicklaunch.mode" value="run"/>
<intAttribute key="com.android.ide.eclipse.adt.action" value="0"/>
<stringAttribute key="com.android.ide.eclipse.adt.avd" value="evo-8-google"/>
<stringAttribute key="com.android.ide.eclipse.adt.commandline" value="-scale 0.7"/>

@ -1,7 +1,5 @@
package com.todoroo.astrid.locale;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@ -13,12 +11,11 @@ import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.NotificationManager;
import com.todoroo.andlib.service.NotificationManager.AndroidNotificationManager;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.activity.ShortcutActivity;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.reminders.Notifications;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.utility.Preferences;
@ -82,17 +79,12 @@ public class LocaleReceiver extends BroadcastReceiver {
replace("$FILTER", title);
// show a reminder
String notificationTitle = r.getString(R.string.locale_edit_alerts_title);
Intent notifyIntent = ShortcutActivity.createIntent(filter);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context,
Constants.NOTIFICATION_TIMER, notifyIntent, 0);
Notification notification = new Notification(
R.drawable.notif_astrid, reminder, System.currentTimeMillis());
notification.setLatestEventInfo(context, r.getString(R.string.locale_edit_alerts_title),
reminder, pendingIntent);
Notifications.showNotification(Constants.NOTIFICATION_LOCALE,
notifyIntent, 0, notificationTitle, reminder, false);
NotificationManager nm = new AndroidNotificationManager(context);
nm.notify(Constants.NOTIFICATION_TIMER, notification);
Preferences.setLong(preferenceKey, DateUtilities.now());
} finally {
cursor.close();

@ -79,7 +79,7 @@ public class Notifications extends BroadcastReceiver {
else
reminder = getRandomReminder(r.getStringArray(R.array.reminders));
if(!showNotification(id, type, reminder)) {
if(!showTaskNotification(id, type, reminder)) {
notificationManager.cancel((int)id);
}
}
@ -94,14 +94,10 @@ public class Notifications extends BroadcastReceiver {
}
/**
* Schedule a new notification about the given task. Returns false if there was
* 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 showNotification(long id, int type, String reminder) {
Context context = ContextManager.getContext();
if(notificationManager == null)
notificationManager = new AndroidNotificationManager(context);
public boolean showTaskNotification(long id, int type, String reminder) {
Task task;
try {
task = taskDao.fetch(id, Task.TITLE, Task.HIDE_UNTIL, Task.COMPLETION_DATE,
@ -130,6 +126,28 @@ public class Notifications extends BroadcastReceiver {
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.putExtra(NotificationActivity.TOKEN_ID, id);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
showNotification((int)id, notifyIntent, type, title, text, nonstopMode);
return true;
}
/**
* Shows an Astrid notification. Pulls in ring tone and quiet hour settings
* from preferences. You can make it say anything you like.
*/
public static void showNotification(int notificationId, Intent intent, int type, String title,
String text, boolean nonstopMode) {
Context context = ContextManager.getContext();
if(notificationManager == null)
notificationManager = new AndroidNotificationManager(context);
// quiet hours? unless alarm clock
boolean quietHours = false;
Integer quietHoursStart = Preferences.getIntegerFromString(R.string.p_rmd_quietStart);
@ -145,16 +163,10 @@ public class Notifications extends BroadcastReceiver {
}
}
Resources r = context.getResources();
Intent notifyIntent = new Intent(context, NotificationActivity.class);
notifyIntent.putExtra(NotificationActivity.TOKEN_ID, id);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context,
(int)id, notifyIntent, PendingIntent.FLAG_ONE_SHOT);
notificationId, intent, PendingIntent.FLAG_ONE_SHOT);
// set up properties (name and icon) for the notification
String appName = r.getString(R.string.app_name);
Integer iconPreference = Preferences.getIntegerFromString(R.string.p_rmd_icon);
if(iconPreference == null)
iconPreference = ICON_SET_ASTRID;
@ -172,10 +184,10 @@ public class Notifications extends BroadcastReceiver {
// create notification object
Notification notification = new Notification(
icon, reminder, System.currentTimeMillis());
icon, text, System.currentTimeMillis());
notification.setLatestEventInfo(context,
appName,
reminder + " " + taskTitle, //$NON-NLS-1$
title,
text,
pendingIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
if(Preferences.getBoolean(R.string.p_rmd_persistent, true)) {
@ -235,11 +247,9 @@ public class Notifications extends BroadcastReceiver {
}
if(Constants.DEBUG)
Log.w("Astrid", "Logging notification: " + reminder); //$NON-NLS-1$ //$NON-NLS-2$
notificationManager.notify((int)id, notification);
Log.w("Astrid", "Logging notification: " + text); //$NON-NLS-1$ //$NON-NLS-2$
return true;
notificationManager.notify(notificationId, notification);
}
// --- notification manager

@ -28,7 +28,7 @@
</string-array>
<!-- Notification -->
<string name="locale_notification">You have $NUM in $FILTER</string>
<string name="locale_notification">You have $NUM matching: $FILTER</string>
<!-- Locale style -->
<style name="TextAppearance.Locale_Label">

@ -720,7 +720,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
case CONTEXT_MENU_DEBUG + 1: {
itemId = item.getGroupId();
new Notifications().showNotification(itemId, 0, "test reminder"); //$NON-NLS-1$
new Notifications().showTaskNotification(itemId, 0, "test reminder"); //$NON-NLS-1$
return true;
}

@ -38,4 +38,7 @@ public final class Constants {
/** Notification Manager id for timing */
public static final int NOTIFICATION_TIMER = -2;
/** Notification Manager id for locale */
public static final int NOTIFICATION_LOCALE = -3;
}

Loading…
Cancel
Save