mirror of https://github.com/tasks/tasks
That's a wrap. Now you can close the task list by cancelling a notification.
parent
2354be6f40
commit
ff77679e5b
@ -0,0 +1,53 @@
|
||||
package com.timsu.astrid.activities;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.timsu.astrid.utilities.Notifications;
|
||||
|
||||
public class TaskViewNotifier extends TaskView {
|
||||
|
||||
// bundle tokens
|
||||
public static final String FROM_NOTIFICATION_TOKEN = "notify";
|
||||
public static final String NOTIF_FLAGS_TOKEN = "notif_flags";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if(extras != null && extras.containsKey(FROM_NOTIFICATION_TOKEN))
|
||||
showNotificationAlert();
|
||||
}
|
||||
|
||||
/** Called when user clicks on a notification to get here */
|
||||
private void showNotificationAlert() {
|
||||
Resources r = getResources();
|
||||
|
||||
// clear residual, schedule the next one
|
||||
Notifications.clearAllNotifications(this, model.getTaskIdentifier());
|
||||
Notifications.updateAlarm(this, model, true);
|
||||
|
||||
String[] responses = r.getStringArray(R.array.reminder_responses);
|
||||
String response = responses[new Random().nextInt(responses.length)];
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.taskView_notifyTitle)
|
||||
.setMessage(response)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setPositiveButton(R.string.yes, null)
|
||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
setResult(RESULT_CANCELED);
|
||||
TaskList.shouldCloseInstance = true;
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue