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

Commit 66743006 authored by Marten Gajda's avatar Marten Gajda
Browse files

improve alarm handling

parent 77ff13bc
Loading
Loading
Loading
Loading
+33 −13
Original line number Diff line number Diff line
@@ -146,8 +146,16 @@
            <intent-filter>
                <action android:name="android.intent.action.PROVIDER_CHANGED" />

                <data android:scheme="content" />
                <data android:host="org.dmfs.tasks" />
                <data
                    android:host="org.dmfs.tasks"
                    android:scheme="content" />
            </intent-filter>
            <intent-filter>
                <action android:name="org.dmfs.android.tasks.TASK_START" />

                <data
                    android:host="org.dmfs.tasks"
                    android:scheme="content" />
            </intent-filter>

            <meta-data
@@ -177,8 +185,16 @@
            <intent-filter>
                <action android:name="android.intent.action.PROVIDER_CHANGED" />

                <data android:scheme="content" />
                <data android:host="org.dmfs.tasks" />
                <data
                    android:host="org.dmfs.tasks"
                    android:scheme="content" />
            </intent-filter>
            <intent-filter>
                <action android:name="org.dmfs.android.tasks.TASK_START" />

                <data
                    android:host="org.dmfs.tasks"
                    android:mimeType="vnd.android.cursor.item/org.dmfs.tasks.tasks" />
            </intent-filter>
        </receiver>
        <receiver android:name="org.dmfs.provider.tasks.broadcast.AccountsChangeBroadcastReceiver" >
@@ -187,16 +203,20 @@
            </intent-filter>
        </receiver>
        <!-- custom alarm receivers -->
        <receiver android:name=".AlarmBroadcastReceiver" >
        <receiver android:name="org.dmfs.tasks.AlarmBroadcastReceiver" >
            <intent-filter>
                <action android:name="org.dmfs.android.tasks.taskdue" />
                <data android:scheme="content" />
                <data android:host="org.dmfs.tasks" />
                <action android:name="org.dmfs.android.tasks.TASK_DUE" />

                <data
                    android:host="org.dmfs.tasks"
                    android:mimeType="vnd.android.cursor.item/org.dmfs.tasks.tasks" />
            </intent-filter>
            <intent-filter>
                <action android:name="org.dmfs.android.tasks.taskstart" />
                <data android:scheme="content" />
                <data android:host="org.dmfs.tasks" />
                <action android:name="org.dmfs.android.tasks.TASK_START" />

                <data
                    android:host="org.dmfs.tasks"
                    android:mimeType="vnd.android.cursor.item/org.dmfs.tasks.tasks" />
            </intent-filter>
        </receiver>
    </application>
+4 −25
Original line number Diff line number Diff line
package org.dmfs.tasks;

import java.net.URI;

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

@@ -13,7 +10,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;

@@ -63,16 +59,14 @@ public class AlarmBroadcastReceiver extends BroadcastReceiver
				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));
				Intent resultIntent = new Intent(Intent.ACTION_VIEW);
				resultIntent.setData(intent.getData());

				// 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);
@@ -106,16 +100,14 @@ public class AlarmBroadcastReceiver extends BroadcastReceiver
				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));
				Intent resultIntent = new Intent(Intent.ACTION_VIEW);
				resultIntent.setData(intent.getData());

				// 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);
@@ -129,19 +121,6 @@ public class AlarmBroadcastReceiver extends BroadcastReceiver
	}


	/**
	 * Helper that constructs a task {@link URI} for a given task id.
	 * 
	 * @param taskId
	 *            The task row id.
	 * @return The task {@link URI}.
	 */
	private Uri getUriForTask(long taskId)
	{
		return Uri.withAppendedPath(Tasks.CONTENT_URI, "/" + taskId);
	}


	public static void setAlarmPreference(Context context, boolean value)
	{
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);