From 2f87b67248697d24ed349a0c101aad4b98fa6e14 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Tue, 1 Feb 2011 22:09:03 -0800 Subject: [PATCH] Moved notes from action into a decoration --- astrid/AndroidManifest.xml | 6 --- .../astrid/notes/NoteViewingActivity.java | 6 ++- .../astrid/notes/NotesActionExposer.java | 4 +- .../astrid/notes/NotesDecorationExposer.java | 51 +++++++++++++++++++ astrid/res/layout/note_decoration.xml | 18 +++++++ .../todoroo/astrid/adapter/TaskAdapter.java | 7 ++- 6 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 astrid/plugin-src/com/todoroo/astrid/notes/NotesDecorationExposer.java create mode 100644 astrid/res/layout/note_decoration.xml diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index d561cefea..aa0e54374 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -418,12 +418,6 @@ - - - - - - diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/NoteViewingActivity.java b/astrid/plugin-src/com/todoroo/astrid/notes/NoteViewingActivity.java index 608cb9bcb..670331004 100644 --- a/astrid/plugin-src/com/todoroo/astrid/notes/NoteViewingActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/notes/NoteViewingActivity.java @@ -7,15 +7,17 @@ import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout; +import android.widget.LinearLayout.LayoutParams; import android.widget.ScrollView; import android.widget.TextView; -import android.widget.LinearLayout.LayoutParams; import com.timsu.astrid.R; import com.todoroo.astrid.data.Task; public class NoteViewingActivity extends Activity { + public static final String EXTRA_TASK = "task"; //$NON-NLS-1$ + private Task task; @Override @@ -27,7 +29,7 @@ public class NoteViewingActivity extends Activity { LinearLayout body = (LinearLayout) findViewById(R.id.body); - task = getIntent().getParcelableExtra(NotesActionExposer.EXTRA_TASK); + task = getIntent().getParcelableExtra(EXTRA_TASK); setTitle(task.getValue(Task.TITLE)); ScrollView scrollView = new ScrollView(this); diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/NotesActionExposer.java b/astrid/plugin-src/com/todoroo/astrid/notes/NotesActionExposer.java index bd052b268..eecbd5e51 100644 --- a/astrid/plugin-src/com/todoroo/astrid/notes/NotesActionExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/notes/NotesActionExposer.java @@ -28,8 +28,6 @@ import com.todoroo.astrid.data.Task; */ public class NotesActionExposer extends BroadcastReceiver { - static final String EXTRA_TASK = "task"; //$NON-NLS-1$ - @Override public void onReceive(Context context, Intent intent) { ContextManager.setContext(context); @@ -50,7 +48,7 @@ public class NotesActionExposer extends BroadcastReceiver { private void displayNote(Context context, Task task) { Intent intent = new Intent(context, NoteViewingActivity.class); - intent.putExtra(EXTRA_TASK, task); + intent.putExtra(NoteViewingActivity.EXTRA_TASK, task); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/NotesDecorationExposer.java b/astrid/plugin-src/com/todoroo/astrid/notes/NotesDecorationExposer.java new file mode 100644 index 000000000..8d4f68f2d --- /dev/null +++ b/astrid/plugin-src/com/todoroo/astrid/notes/NotesDecorationExposer.java @@ -0,0 +1,51 @@ +/** + * See the file "LICENSE" for the full license governing this code. + */ +package com.todoroo.astrid.notes; + +import android.app.PendingIntent; +import android.content.Intent; +import android.text.TextUtils; +import android.widget.RemoteViews; + +import com.timsu.astrid.R; +import com.todoroo.andlib.service.ContextManager; +import com.todoroo.astrid.api.TaskDecoration; +import com.todoroo.astrid.api.TaskDecorationExposer; +import com.todoroo.astrid.data.Task; + +/** + * Exposes {@link TaskDecoration} for notes + * + * @author Tim Su + * + */ +public class NotesDecorationExposer implements TaskDecorationExposer { + + @Override + public TaskDecoration expose(Task task) { + if(task == null || TextUtils.isEmpty(task.getValue(Task.NOTES))) + return null; + + TaskDecoration decoration; + RemoteViews remoteViews = new RemoteViews(ContextManager.getContext().getPackageName(), + R.layout.note_decoration); + decoration = new TaskDecoration(remoteViews, TaskDecoration.POSITION_RIGHT, 0); + + Intent intent = new Intent(ContextManager.getContext(), NoteViewingActivity.class); + intent.putExtra(NoteViewingActivity.EXTRA_TASK, task); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + PendingIntent pendingIntent = PendingIntent.getActivity(ContextManager.getContext(), + (int)task.getId(), intent, PendingIntent.FLAG_CANCEL_CURRENT); + + remoteViews.setOnClickPendingIntent(R.id.icon, pendingIntent); + + return decoration; + } + + @Override + public String getAddon() { + return NotesPlugin.IDENTIFIER; + } + +} diff --git a/astrid/res/layout/note_decoration.xml b/astrid/res/layout/note_decoration.xml new file mode 100644 index 000000000..d19848dae --- /dev/null +++ b/astrid/res/layout/note_decoration.xml @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java index 60574f16e..7f4dfbc17 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java @@ -59,6 +59,7 @@ import com.todoroo.astrid.api.TaskDecoration; import com.todoroo.astrid.api.TaskDecorationExposer; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.helper.TaskAdapterAddOnManager; +import com.todoroo.astrid.notes.NotesDecorationExposer; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.timers.TimerDecorationExposer; import com.todoroo.astrid.utility.Constants; @@ -639,6 +640,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable { private final TaskDecorationExposer[] exposers = new TaskDecorationExposer[] { new TimerDecorationExposer(), + new NotesDecorationExposer(), }; /** @@ -660,8 +662,10 @@ public class TaskAdapter extends CursorAdapter implements Filterable { for(TaskDecorationExposer exposer : exposers) { TaskDecoration deco = exposer.expose(viewHolder.task); - if(deco != null) + if(deco != null) { addNew(viewHolder.task.getId(), exposer.getAddon(), deco); + System.err.println("new chilli - " + exposer.getAddon()); + } } return true; @@ -694,6 +698,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable { viewHolder.taskRow.addView(view, 2); break; case TaskDecoration.POSITION_RIGHT: + System.err.println("addin da child"); viewHolder.taskRow.addView(view, viewHolder.taskRow.getChildCount() - 1); } }