From 89aa3a00c9e8d4cc924f857bce6fc9592a16b487 Mon Sep 17 00:00:00 2001 From: Andrew Shaw Date: Thu, 26 Jan 2012 16:58:59 -0800 Subject: [PATCH] Comment pictures show up in taskeditactivity now YAAA --- .../astrid/actfm/ActFmCameraModule.java | 42 +++++++++++++++++++ .../astrid/notes/EditNoteActivity.java | 41 +++++++++++++++--- .../todoroo/astrid/notes/NoteMetadata.java | 4 ++ astrid/res/layout/update_adapter_row.xml | 11 +++++ .../astrid/activity/TaskEditActivity.java | 19 ++++----- 5 files changed, 101 insertions(+), 16 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmCameraModule.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmCameraModule.java index 957ae1d17..b857832de 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmCameraModule.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmCameraModule.java @@ -14,6 +14,7 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; +import android.support.v4.app.Fragment; import android.widget.ArrayAdapter; import com.timsu.astrid.R; @@ -70,6 +71,47 @@ public class ActFmCameraModule { .show().setOwnerActivity(activity); } + + public static void showPictureLauncher(final Fragment fragment, final ClearImageCallback clearImageOption) { + ArrayList options = new ArrayList(); + options.add(fragment.getString(R.string.actfm_picture_camera)); + options.add(fragment.getString(R.string.actfm_picture_gallery)); + + if (clearImageOption != null) { + options.add(fragment.getString(R.string.actfm_picture_clear)); + } + ArrayAdapter adapter = new ArrayAdapter(fragment.getActivity(), + android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()])); + + DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { + @SuppressWarnings("nls") + @Override + public void onClick(DialogInterface d, int which) { + if(which == 0) { + lastTempFile = getTempFile(fragment.getActivity()); + Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + if (lastTempFile != null) { + intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile)); + } + fragment.startActivityForResult(intent, REQUEST_CODE_CAMERA); + } else if (which == 1) { + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("image/*"); + fragment.startActivityForResult(Intent.createChooser(intent, + fragment.getString(R.string.actfm_TVA_tag_picture)), REQUEST_CODE_PICTURE); + } else { + if (clearImageOption != null) + clearImageOption.clearImage(); + } + } + }; + + // show a menu of available options + new AlertDialog.Builder(fragment.getActivity()) + .setAdapter(adapter, listener) + .show().setOwnerActivity(fragment.getActivity()); + } + @SuppressWarnings("nls") private static File getTempFile(Activity activity) { try { diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java index e8c0ad753..f8876edc4 100644 --- a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java @@ -15,6 +15,7 @@ import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Color; +import android.support.v4.app.Fragment; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; @@ -84,6 +85,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen private int commentItems = 10; private ImageButton pictureButton; private Bitmap picture = null; + private final Fragment fragment; private final List listeners = new LinkedList(); @@ -92,8 +94,11 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen public void commentAdded(); } - public EditNoteActivity(Activity activity, View parent, long t) { - super(activity); + public EditNoteActivity(Fragment fragment, View parent, long t) { + super(fragment.getActivity()); + + Log.d("EditnoteActivity", "Contructor being called"); + this.fragment = fragment; DependencyInjectionService.getInstance().inject(this); setOrientation(VERTICAL); @@ -191,6 +196,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen final ClearImageCallback clearImage = new ClearImageCallback() { @Override public void clearImage() { + Log.e("Errrr EditNOtes activity", "Picture clear image called"); picture = null; pictureButton.setImageResource(R.drawable.camera_button); } @@ -200,9 +206,9 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen @Override public void onClick(View v) { if (picture != null) - ActFmCameraModule.showPictureLauncher((Activity)getContext(), clearImage); + ActFmCameraModule.showPictureLauncher(fragment, clearImage); else - ActFmCameraModule.showPictureLauncher((Activity)getContext(), null); + ActFmCameraModule.showPictureLauncher(fragment, null); } }); if(!TextUtils.isEmpty(task.getValue(Task.NOTES))) { @@ -217,6 +223,10 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen // loadingText = (TextView) findViewById(R.id.loading); loadingText = new TextView(getContext()); + + for (UpdatesChangedListener l : listeners) { + l.updatesChanged(); + } } private void setUpListAdapter() { @@ -334,6 +344,16 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen DateUtils.FORMAT_ABBREV_RELATIVE); date.setText(dateString); } + + // picture + final AsyncImageView commentPictureView = (AsyncImageView)view.findViewById(R.id.comment_picture); { + if(TextUtils.isEmpty(item.commentPicture)) + commentPictureView.setVisibility(View.GONE); + else { + commentPictureView.setVisibility(View.VISIBLE); + commentPictureView.setUrl(item.commentPicture); + } + } } public void refreshData(boolean manual, SyncResultCallback existingCallback) { @@ -390,10 +410,11 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen update.setValue(Update.TASK, task.getValue(Task.REMOTE_ID)); update.setValue(Update.CREATION_DATE, DateUtilities.now()); + Log.d("Add comment", "The picture is: " + picture); if (picture != null) { update.setValue(Update.PICTURE, Update.PICTURE_LOADING); } - Flags.checkAndClear(Flags.ACTFM_SUPPRESS_SYNC); + Flags.set(Flags.ACTFM_SUPPRESS_SYNC); updateDao.createNew(update); final long updateId = update.getId(); @@ -402,6 +423,8 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen @Override public void run() { actFmSyncService.pushUpdate(updateId, tempPicture); + + Log.d("Run thread", "The picture is: " + picture); } }.start(); commentField.setText(""); //$NON-NLS-1$ @@ -424,14 +447,16 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen private final String picture; private final String title; private final String body; + private final String commentPicture; private final long createdAt; - public NoteOrUpdate(String picture, String title, String body, + public NoteOrUpdate(String picture, String title, String body, String commentPicture, long createdAt) { super(); this.picture = picture; this.title = title; this.body = body; + this.commentPicture = commentPicture; this.createdAt = createdAt; } @@ -442,6 +467,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen return new NoteOrUpdate(m.getValue(NoteMetadata.THUMBNAIL), m.getValue(NoteMetadata.TITLE), m.getValue(NoteMetadata.BODY), + m.getValue(NoteMetadata.COMMENTPICTURE), m.getValue(Metadata.CREATION_DATE)); } @@ -455,10 +481,12 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen description = message; else if(!TextUtils.isEmpty(message)) description += " " + message; + String commentPicture = u.getValue(Update.PICTURE); return new NoteOrUpdate(user.optString("picture"), user.optString("name", ""), description, + commentPicture, u.getValue(Update.CREATION_DATE)); } @@ -504,6 +532,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen public void handleCameraResult(Bitmap bitmap) { picture = bitmap; pictureButton.setImageBitmap(picture); + Log.d("Picture", "Picture = " + picture); } }; diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/NoteMetadata.java b/astrid/plugin-src/com/todoroo/astrid/notes/NoteMetadata.java index 8718c1e69..a8cf0be7d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/notes/NoteMetadata.java +++ b/astrid/plugin-src/com/todoroo/astrid/notes/NoteMetadata.java @@ -23,10 +23,14 @@ public class NoteMetadata { /** note thumbnail URL */ public static final StringProperty THUMBNAIL = Metadata.VALUE3; + /** note external id (use for your own purposes) */ + public static final StringProperty COMMENTPICTURE = Metadata.VALUE6; + /** note external provider (use for your own purposes) */ public static final StringProperty EXT_PROVIDER = Metadata.VALUE4; /** note external id (use for your own purposes) */ public static final StringProperty EXT_ID = Metadata.VALUE5; + } diff --git a/astrid/res/layout/update_adapter_row.xml b/astrid/res/layout/update_adapter_row.xml index 20e53c563..4db74123a 100644 --- a/astrid/res/layout/update_adapter_row.xml +++ b/astrid/res/layout/update_adapter_row.xml @@ -47,6 +47,17 @@ android:paddingLeft="50dip" android:textSize="14sp" /> + + + + 0 && idParam > -1L) { -// if (editNotes == null) { - editNotes = new EditNoteActivity(getActivity(), getView(), + if (editNotes == null) { + editNotes = new EditNoteActivity(this, getView(), idParam); editNotes.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); + editNotes.addListener(this); if (timerAction != null) { timerAction.addListener(editNotes); } - else { - Log.d("Did not add timerAction", "did not add timer action"); - } -// } -// else { -// editNotes.loadViewForTaskID(idParam); -// } + } + else { + editNotes.loadViewForTaskID(idParam); + } if (mAdapter == null) { mAdapter = new TaskEditViewPager(getActivity()); mAdapter.parent = this; - editNotes = new EditNoteActivity(getActivity(), getView(), + editNotes = new EditNoteActivity(this, getView(), idParam); editNotes.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); @@ -1087,6 +1085,7 @@ public final class TaskEditActivity extends Fragment implements @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { + Log.d("Activity !!!", "Called on camera for request code: " + requestCode + "EditNOtes: " + editNotes.toString()); if (editNotes.activityResult(requestCode, resultCode, data)) { return; }