From 539822e3e41f72f37a77d771e0d5389a4b57122e Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 24 May 2012 17:30:02 -0700 Subject: [PATCH] Introduced quick action for viewing notes --- .../astrid/core/LinkActionExposer.java | 16 ++++++- .../com/todoroo/astrid/notes/NotesAction.java | 39 ++++++++++++++++++ astrid/res/drawable/action_notes.png | Bin 0 -> 239 bytes astrid/res/layout/notes_view_dialog.xml | 32 ++++++++++++++ astrid/res/layout/task_adapter_row.xml | 2 +- .../todoroo/astrid/adapter/TaskAdapter.java | 39 +++++++++++++++++- 6 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 astrid/plugin-src/com/todoroo/astrid/notes/NotesAction.java create mode 100644 astrid/res/drawable/action_notes.png create mode 100644 astrid/res/layout/notes_view_dialog.xml diff --git a/astrid/plugin-src/com/todoroo/astrid/core/LinkActionExposer.java b/astrid/plugin-src/com/todoroo/astrid/core/LinkActionExposer.java index 908ca7462..3a2740402 100644 --- a/astrid/plugin-src/com/todoroo/astrid/core/LinkActionExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/core/LinkActionExposer.java @@ -17,13 +17,16 @@ import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.text.Spannable; +import android.text.TextUtils; import android.text.style.URLSpan; import android.text.util.Linkify; import com.timsu.astrid.R; +import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.api.TaskAction; import com.todoroo.astrid.api.TaskDecoration; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.notes.NotesAction; /** * Exposes {@link TaskDecoration} for phone numbers, emails, urls, etc @@ -40,14 +43,15 @@ public class LinkActionExposer { if(taskId == -1) return result; - Task task = PluginServices.getTaskService().fetchById(taskId, Task.ID, Task.TITLE); + Task task = PluginServices.getTaskService().fetchById(taskId, Task.ID, Task.TITLE, Task.NOTES); if (task == null) return result; + String notes = task.getValue(Task.NOTES); Spannable titleSpan = Spannable.Factory.getInstance().newSpannable(task.getValue(Task.TITLE)); Linkify.addLinks(titleSpan, Linkify.ALL); URLSpan[] urlSpans = titleSpan.getSpans(0, titleSpan.length(), URLSpan.class); - if(urlSpans.length == 0) + if(urlSpans.length == 0 && TextUtils.isEmpty(notes)) return result; pm = context.getPackageManager(); @@ -61,6 +65,14 @@ public class LinkActionExposer { if (taskAction != null) result.add(taskAction); } + + if (!TextUtils.isEmpty(notes) && !Preferences.getBoolean(R.string.p_showNotes, false)) { + Resources r = context.getResources(); + Bitmap icon = ((BitmapDrawable) r.getDrawable(R.drawable.action_notes)).getBitmap(); + NotesAction notesAction = new NotesAction("", null, icon); //$NON-NLS-1$ + result.add(notesAction); + } + return result; } diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/NotesAction.java b/astrid/plugin-src/com/todoroo/astrid/notes/NotesAction.java new file mode 100644 index 000000000..948a95e6d --- /dev/null +++ b/astrid/plugin-src/com/todoroo/astrid/notes/NotesAction.java @@ -0,0 +1,39 @@ +package com.todoroo.astrid.notes; + +import android.app.PendingIntent; +import android.graphics.Bitmap; +import android.os.Parcel; +import android.os.Parcelable; + +import com.todoroo.astrid.api.TaskAction; + +public class NotesAction extends TaskAction { + + public NotesAction(String text, PendingIntent intent, Bitmap icon) { + super(text, intent, icon); + } + + /** + * Parcelable creator + */ + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + /** + * {@inheritDoc} + */ + public NotesAction createFromParcel(Parcel source) { + NotesAction action = new NotesAction(source.readString(), + (PendingIntent)source.readParcelable(PendingIntent.class.getClassLoader()), + (Bitmap)source.readParcelable(Bitmap.class.getClassLoader())); + action.drawable = source.readInt(); + return action; + } + + /** + * {@inheritDoc} + */ + public NotesAction[] newArray(int size) { + return new NotesAction[size]; + }; + }; + +} diff --git a/astrid/res/drawable/action_notes.png b/astrid/res/drawable/action_notes.png new file mode 100644 index 0000000000000000000000000000000000000000..77da7f2f25466ead5227b6eb490881c7c0861b4d GIT binary patch literal 239 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1G6FprVLn>~)xwTucK|#bNFkyw$ai*DT4|uJ(U{!E}$1pJL zy_&$D2Xh}z7l_V2X!+5&A?Vb@D-~-?-zIZCV`O;nzM*EO{u-b`n1El^|H|oid@pXY zy?(N%^+^relbVjFHQXnEN=^N2t?<0vN7?n{&YzKtyMpJ;nf<==Pgtepat3CGFja{; TTTj0@3Np~s)z4*}Q$iB}*dABA literal 0 HcmV?d00001 diff --git a/astrid/res/layout/notes_view_dialog.xml b/astrid/res/layout/notes_view_dialog.xml new file mode 100644 index 000000000..67edc3c77 --- /dev/null +++ b/astrid/res/layout/notes_view_dialog.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + diff --git a/astrid/res/layout/task_adapter_row.xml b/astrid/res/layout/task_adapter_row.xml index d111e862f..6aed88a9a 100644 --- a/astrid/res/layout/task_adapter_row.xml +++ b/astrid/res/layout/task_adapter_row.xml @@ -80,7 +80,7 @@ android:id="@+id/taskActionContainer" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginRight="4dip" + android:layout_marginRight="10dip" android:orientation="vertical" android:gravity="right|center_vertical"> = 9 && size == Configuration.SCREENLAYOUT_SIZE_XLARGE) { + DisplayMetrics metrics = fragment.getResources().getDisplayMetrics(); + params.width = metrics.widthPixels / 2; + } + dialog.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); + + dialog.show(); + } + /* ====================================================================== * ============================================================== details * ====================================================================== */