That's a wrap. Now you can close the task list by cancelling a notification.

pull/14/head
Tim Su 16 years ago
parent 2354be6f40
commit ff77679e5b

@ -18,6 +18,12 @@
<activity android:name=".activities.TaskView"/>
<activity android:name=".activities.TaskViewNotifier"
android:excludeFromRecents="true"
android:theme="@android:style/Theme.Dialog"
android:launchMode="singleTask"
android:taskAffinity="@null" />
<activity android:name=".activities.TaskEdit"/>
<activity android:name=".activities.TagList"/>

@ -29,7 +29,6 @@
<CheckBox android:id="@+id/cb1"
android:gravity="center_vertical"
android:background="@drawable/btn_check0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"/>

@ -87,8 +87,12 @@ public class TaskList extends Activity {
private boolean filterShowDone = false;
private TagModelForView filterTag = null;
static boolean shouldCloseInstance = false;
/** Called when loading up the activity for the first time */
private void onLoad() {
shouldCloseInstance = false;
controller = new TaskController(this);
controller.open();
tagController = new TagController(this);
@ -237,6 +241,19 @@ public class TaskList extends Activity {
fillData();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus) { // stuff might have changed...
if(shouldCloseInstance) // user wants to quit
finish();
else
fillData();
shouldCloseInstance = false;
}
}
// --- list adapter
private void createTask() {

@ -251,6 +251,7 @@ public class TaskListAdapter extends ArrayAdapter<TaskModelForList> {
if(task.isTaskCompleted()) {
name.setBackgroundDrawable(r.getDrawable(R.drawable.strikeout));
name.setTextColor(r.getColor(R.color.task_list_done));
progress.setButtonDrawable(R.drawable.btn_check0);
} else {
name.setBackgroundDrawable(null);
name.setTextColor(r.getColor(task.getTaskColorResource()));

@ -19,7 +19,6 @@
*/
package com.timsu.astrid.activities;
import java.util.Date;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
@ -39,7 +38,6 @@ import com.timsu.astrid.R;
import com.timsu.astrid.data.task.TaskIdentifier;
import com.timsu.astrid.data.task.TaskModelForView;
import com.timsu.astrid.utilities.DateUtilities;
import com.timsu.astrid.utilities.Notifications;
import com.timsu.astrid.widget.NumberPicker;
import com.timsu.astrid.widget.NumberPickerDialog;
@ -51,10 +49,6 @@ import com.timsu.astrid.widget.NumberPickerDialog;
*/
public class TaskView extends TaskModificationActivity<TaskModelForView> {
// bundle tokens
public static final String FROM_NOTIFICATION_TOKEN = "notify";
public static final String NOTIF_FLAGS_TOKEN = "notif_flags";
// activities
private static final int ACTIVITY_EDIT = 0;
@ -90,10 +84,6 @@ public class TaskView extends TaskModificationActivity<TaskModelForView> {
setUpUIComponents();
setUpListeners();
populateFields();
Bundle extras = getIntent().getExtras();
if(extras != null && extras.containsKey(FROM_NOTIFICATION_TOKEN))
showNotificationAlert();
}
@Override
@ -103,31 +93,6 @@ public class TaskView extends TaskModificationActivity<TaskModelForView> {
return controller.fetchTaskForView(this, identifier);
}
/** 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);
finish();
}
})
.show();
}
/* ======================================================================
* =================================================== reading from model
* ====================================================================== */

@ -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();
}
}

@ -16,7 +16,7 @@ import android.content.res.Resources;
import android.util.Log;
import com.timsu.astrid.R;
import com.timsu.astrid.activities.TaskView;
import com.timsu.astrid.activities.TaskViewNotifier;
import com.timsu.astrid.data.task.TaskController;
import com.timsu.astrid.data.task.TaskIdentifier;
import com.timsu.astrid.data.task.TaskModelForList;
@ -37,6 +37,9 @@ public class Notifications extends BroadcastReceiver {
private static final int TIME_IN_PAST_OFFSET = 60;
/** # of seconds after first deadline reminder to repeat */
private static final int DEADLINE_REPEAT = 600;
/** Minimum number of seconds before you see a notification on something
* you just touched */
private static final int SNOOZE_TIME = 600;
// flags
public static final int FLAG_DEFINITE_DEADLINE = 1;
@ -152,7 +155,7 @@ public class Notifications extends BroadcastReceiver {
// snooze if the user just interacted with this item
if(shouldSnooze) {
long snoozeWhen = System.currentTimeMillis() +
DEADLINE_REPEAT * 1000;
SNOOZE_TIME * 1000;
if(when < snoozeWhen)
when = snoozeWhen;
} else if(when < System.currentTimeMillis())
@ -181,6 +184,9 @@ public class Notifications extends BroadcastReceiver {
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
am.cancel(createPendingIntent(context, id, 0));
// clear current notifications too
clearAllNotifications(context, new TaskIdentifier(id));
}
/** Schedules a single alarm for a single task */
@ -256,10 +262,12 @@ public class Notifications extends BroadcastReceiver {
.getSystemService(Context.NOTIFICATION_SERVICE);
Resources r = context.getResources();
Intent notifyIntent = new Intent(context, TaskView.class);
notifyIntent.putExtra(TaskView.LOAD_INSTANCE_TOKEN, id);
notifyIntent.putExtra(TaskView.FROM_NOTIFICATION_TOKEN, true);
notifyIntent.putExtra(TaskView.NOTIF_FLAGS_TOKEN, flags);
Intent notifyIntent = new Intent(context, TaskViewNotifier.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
notifyIntent.putExtra(TaskViewNotifier.LOAD_INSTANCE_TOKEN, id);
notifyIntent.putExtra(TaskViewNotifier.FROM_NOTIFICATION_TOKEN, true);
notifyIntent.putExtra(TaskViewNotifier.NOTIF_FLAGS_TOKEN, flags);
PendingIntent pendingIntent = PendingIntent.getActivity(context,
0, notifyIntent, PendingIntent.FLAG_ONE_SHOT);

Loading…
Cancel
Save