Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2d65cad authored by tobias's avatar tobias
Browse files

- added support for start alarms

parent 20021c45
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -155,9 +155,19 @@
                android:resource="@xml/task_widget_info" />
        </receiver>
        <!-- Start the Service if applicable on boot -->
        <receiver android:name="org.dmfs.provider.tasks.handler.AlarmNotificationHandler" >
        <receiver android:name="org.dmfs.provider.tasks.broadcast.StartAlarmBroadcastHandler" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>
        <receiver android:name="org.dmfs.provider.tasks.broadcast.DueAlarmBroadcastHandler" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>
@@ -176,6 +186,9 @@
            <intent-filter>
                <action android:name="org.dmfs.android.tasks.taskdue" />
            </intent-filter>
            <intent-filter>
                <action android:name="org.dmfs.android.tasks.taskstart" />
            </intent-filter>
        </receiver>
    </application>

+1 −0
Original line number Diff line number Diff line
@@ -158,5 +158,6 @@
    
    <!-- Strings for notification -->
    <string name="notification_task_due_title">Aufgabe fällig</string>
     <string name="notification_task_start_title">Aufgabe startet</string>

</resources>
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -158,5 +158,6 @@
    
    <!-- Strings for notification -->
    <string name="notification_task_due_title">Task due</string>
    <string name="notification_task_start_title">Task starts</string>
	
</resources>
 No newline at end of file
+86 −39
Original line number Diff line number Diff line
@@ -3,7 +3,8 @@ package org.dmfs.tasks;
import java.net.URI;

import org.dmfs.provider.tasks.TaskContract.Tasks;
import org.dmfs.provider.tasks.handler.AlarmNotificationHandler;
import org.dmfs.provider.tasks.broadcast.DueAlarmBroadcastHandler;
import org.dmfs.provider.tasks.broadcast.StartAlarmBroadcastHandler;

import android.app.Notification;
import android.app.NotificationManager;
@@ -38,11 +39,56 @@ public class AlarmBroadcastReceiver extends BroadcastReceiver
	public void onReceive(Context context, Intent intent)
	{
		// continue if alarms where enabled
		if (intent.getAction().equals(StartAlarmBroadcastHandler.BROADCAST_START_ALARM))
		{
			if (getAlarmPreference(context))
			{
			long taskId = intent.getLongExtra(AlarmNotificationHandler.EXTRA_TASK_ID, 0);
				long taskId = intent.getLongExtra(StartAlarmBroadcastHandler.EXTRA_TASK_ID, 0);
				// long dueTime = intent.getLongExtra(AlarmNotificationHandler.EXTRA_TASK_DUE_TIME, System.currentTimeMillis());
			String title = intent.getStringExtra(AlarmNotificationHandler.EXTRA_TASK_TITLE);
				String title = intent.getStringExtra(StartAlarmBroadcastHandler.EXTRA_TASK_TITLE);

				NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

				// build notification
				NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_notification_completed)
					.setContentTitle(context.getString(R.string.notification_task_start_title)).setContentText(title);

				// dismisses the notification on click
				mBuilder.setAutoCancel(true);

				// set status bar test
				mBuilder.setTicker(title);

				// enable light, sound and vibration
				mBuilder.setDefaults(Notification.DEFAULT_ALL);

				// Creates an explicit intent for an Activity in your app
				Intent resultIntent = new Intent(context, ViewTaskActivity.class);
				resultIntent.setData(getUriForTask(taskId));

				// The stack builder object will contain an artificial back stack for the
				// started Activity.
				// This ensures that navigating backward from the Activity leads out of
				// your application to the Home screen.
				TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
				// Adds the back stack for the Intent (but not the Intent itself)
				stackBuilder.addParentStack(ViewTaskActivity.class);
				// Adds the Intent that starts the Activity to the top of the stack
				stackBuilder.addNextIntent(resultIntent);
				PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

				mBuilder.setContentIntent(resultPendingIntent);
				notificationManager.notify((int) taskId, mBuilder.build());

			}
		}
		else if (intent.getAction().equals(DueAlarmBroadcastHandler.BROADCAST_DUE_ALARM))
		{
			if (getAlarmPreference(context))
			{
				long taskId = intent.getLongExtra(DueAlarmBroadcastHandler.EXTRA_TASK_ID, 0);
				// long dueTime = intent.getLongExtra(AlarmNotificationHandler.EXTRA_TASK_DUE_TIME, System.currentTimeMillis());
				String title = intent.getStringExtra(DueAlarmBroadcastHandler.EXTRA_TASK_TITLE);

				NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

@@ -78,6 +124,7 @@ public class AlarmBroadcastReceiver extends BroadcastReceiver
				notificationManager.notify((int) taskId, mBuilder.build());

			}
		}

	}