@ -86,7 +86,7 @@ public class Notifications extends BroadcastReceiver {
", repeat " + repeatInterval ) ;
", repeat " + repeatInterval ) ;
if ( ! showNotification ( context , id , flags , repeatInterval , reminder ) ) {
if ( ! showNotification ( context , id , flags , repeatInterval , reminder ) ) {
deleteAlarm ( context , i d) ;
deleteAlarm ( context , i ntent, i d) ;
NotificationManager nm = ( NotificationManager )
NotificationManager nm = ( NotificationManager )
context . getSystemService ( Context . NOTIFICATION_SERVICE ) ;
context . getSystemService ( Context . NOTIFICATION_SERVICE ) ;
nm . cancel ( ( int ) id ) ;
nm . cancel ( ( int ) id ) ;
@ -138,7 +138,7 @@ public class Notifications extends BroadcastReceiver {
// return if we don't need to go any further
// return if we don't need to go any further
if ( shouldDeleteAlarm ( task ) ) {
if ( shouldDeleteAlarm ( task ) ) {
deleteAlarm ( context , task . getTaskIdentifier ( ) . getId ( ) ) ;
deleteAlarm ( context , null , task . getTaskIdentifier ( ) . getId ( ) ) ;
return ;
return ;
}
}
@ -149,8 +149,8 @@ public class Notifications extends BroadcastReceiver {
long when ;
long when ;
// get or make up a last notification time
// get or make up a last notification time
if ( task . getLastNotificationDate ( ) = = null ) {
if ( task . getLastNotificationDate ( ) = = null ) {
when = System . currentTimeMillis ( ) +
when = System . currentTimeMillis ( ) -
( long ) ( interval * ( 0. 3f + 0. 7f * random . nextFloat ( ) ) ) ;
( long ) ( interval * ( 0. 7f * random . nextFloat ( ) ) ) ;
taskController . setLastNotificationTime ( task . getTaskIdentifier ( ) ,
taskController . setLastNotificationTime ( task . getTaskIdentifier ( ) ,
new Date ( when ) ) ;
new Date ( when ) ) ;
} else {
} else {
@ -167,6 +167,12 @@ public class Notifications extends BroadcastReceiver {
int estimatedDuration = DEADLINE_NOTIFY_SECS ;
int estimatedDuration = DEADLINE_NOTIFY_SECS ;
if ( task . getEstimatedSeconds ( ) ! = null & & task . getEstimatedSeconds ( ) > DEADLINE_NOTIFY_SECS )
if ( task . getEstimatedSeconds ( ) ! = null & & task . getEstimatedSeconds ( ) > DEADLINE_NOTIFY_SECS )
estimatedDuration = ( int ) ( task . getEstimatedSeconds ( ) * 1.5f ) ;
estimatedDuration = ( int ) ( task . getEstimatedSeconds ( ) * 1.5f ) ;
clearAlarm ( context , task . getTaskIdentifier ( ) . getId ( ) , FLAG_DEFINITE_DEADLINE ) ;
clearAlarm ( context , task . getTaskIdentifier ( ) . getId ( ) , FLAG_PREFERRED_DEADLINE ) ;
clearAlarm ( context , task . getTaskIdentifier ( ) . getId ( ) , FLAG_DEFINITE_DEADLINE | FLAG_OVERDUE ) ;
clearAlarm ( context , task . getTaskIdentifier ( ) . getId ( ) , FLAG_PREFERRED_DEADLINE | FLAG_OVERDUE ) ;
if ( ( task . getNotificationFlags ( ) & TaskModelForList . NOTIFY_BEFORE_DEADLINE ) > 0 ) {
if ( ( task . getNotificationFlags ( ) & TaskModelForList . NOTIFY_BEFORE_DEADLINE ) > 0 ) {
scheduleDeadline ( context , task . getDefiniteDueDate ( ) , - estimatedDuration ,
scheduleDeadline ( context , task . getDefiniteDueDate ( ) , - estimatedDuration ,
0 , FLAG_DEFINITE_DEADLINE , task ) ;
0 , FLAG_DEFINITE_DEADLINE , task ) ;
@ -215,6 +221,7 @@ public class Notifications extends BroadcastReceiver {
* /
* /
private static void scheduleDeadline ( Context context , Date deadline , int
private static void scheduleDeadline ( Context context , Date deadline , int
offsetSeconds , int intervalSeconds , int flags , Notifiable task ) {
offsetSeconds , int intervalSeconds , int flags , Notifiable task ) {
long id = task . getTaskIdentifier ( ) . getId ( ) ;
if ( deadline = = null )
if ( deadline = = null )
return ;
return ;
long when = deadline . getTime ( ) + offsetSeconds * 1000 ;
long when = deadline . getTime ( ) + offsetSeconds * 1000 ;
@ -222,10 +229,10 @@ public class Notifications extends BroadcastReceiver {
return ;
return ;
if ( intervalSeconds = = 0 )
if ( intervalSeconds = = 0 )
scheduleAlarm ( context , task. getTaskIdentif ier( ) . getI d( ) , when ,
scheduleAlarm ( context , id, when ,
flags ) ;
flags ) ;
else
else
scheduleRepeatingAlarm ( context , task. getTaskIdentif ier( ) . getI d( ) ,
scheduleRepeatingAlarm ( context , id,
when , flags , intervalSeconds * 1000 ) ;
when , flags , intervalSeconds * 1000 ) ;
}
}
@ -255,13 +262,12 @@ public class Notifications extends BroadcastReceiver {
}
}
/** Delete the given alarm */
/** Delete the given alarm */
public static void deleteAlarm ( Context context , long id ) {
public static void deleteAlarm ( Context context , Intent trigger , long id ) {
AlarmManager am = ( AlarmManager ) context . getSystemService ( Context . ALARM_SERVICE ) ;
AlarmManager am = ( AlarmManager ) context . getSystemService ( Context . ALARM_SERVICE ) ;
// clear all possible alarms
if ( trigger ! = null ) {
for ( int flag = 0 ; flag < ( 6 < < FIXED_ID_SHIFT ) ; flag + + ) {
PendingIntent pendingIntent = PendingIntent . getBroadcast ( context , 0 ,
PendingIntent pendingIntent = PendingIntent . getBroadcast ( context , 0 ,
createAlarmIntent( context , id , flag ) , 0 ) ;
trigger , 0 ) ;
am . cancel ( pendingIntent ) ;
am . cancel ( pendingIntent ) ;
}
}
@ -269,6 +275,14 @@ public class Notifications extends BroadcastReceiver {
clearAllNotifications ( context , new TaskIdentifier ( id ) ) ;
clearAllNotifications ( context , new TaskIdentifier ( id ) ) ;
}
}
/** Clear the alarm given by the id and flags */
public static void clearAlarm ( Context context , long id , int flags ) {
AlarmManager am = ( AlarmManager ) context . getSystemService ( Context . ALARM_SERVICE ) ;
PendingIntent pendingIntent = PendingIntent . getBroadcast ( context , 0 ,
createAlarmIntent ( context , id , flags ) , 0 ) ;
am . cancel ( pendingIntent ) ;
}
/** Schedules a single alarm for a single task */
/** Schedules a single alarm for a single task */
public static void scheduleAlarm ( Context context , long id , long when ,
public static void scheduleAlarm ( Context context , long id , long when ,
int flags ) {
int flags ) {
@ -386,9 +400,20 @@ public class Notifications extends BroadcastReceiver {
// create notification object
// create notification object
String appName = r . getString ( R . string . app_name ) ;
String appName = r . getString ( R . string . app_name ) ;
int icon ;
switch ( Preferences . getNotificationIconTheme ( context ) ) {
case PINK :
icon = R . drawable . notif_pink_alarm ;
break ;
case BORING :
icon = R . drawable . notif_boring_alarm ;
break ;
default :
icon = R . drawable . notif_astrid ;
}
Notification notification = new Notification (
Notification notification = new Notification (
R . drawable . notification_tag_pink , reminder ,
icon , reminder , System . currentTimeMillis ( ) ) ;
System . currentTimeMillis ( ) ) ;
notification . setLatestEventInfo ( context ,
notification . setLatestEventInfo ( context ,
appName ,
appName ,
reminder + " " + taskName ,
reminder + " " + taskName ,
@ -452,10 +477,21 @@ public class Notifications extends BroadcastReceiver {
( int ) taskId . getId ( ) , notifyIntent , 0 ) ;
( int ) taskId . getId ( ) , notifyIntent , 0 ) ;
// create notification object
// create notification object
int icon ;
switch ( Preferences . getNotificationIconTheme ( context ) ) {
case PINK :
icon = R . drawable . notif_pink_working ;
break ;
case BORING :
icon = R . drawable . notif_boring_working ;
break ;
default :
icon = R . drawable . notif_astrid ;
}
String appName = r . getString ( R . string . app_name ) ;
String appName = r . getString ( R . string . app_name ) ;
Notification notification = new Notification (
Notification notification = new Notification (
R . drawable . notification_clock , text ,
icon , text , System . currentTimeMillis ( ) ) ;
System . currentTimeMillis ( ) ) ;
notification . setLatestEventInfo ( context ,
notification . setLatestEventInfo ( context ,
appName ,
appName ,
text ,
text ,