Use ACTION_VIEW to view comment pictures

pull/189/head
Alex Baker 12 years ago
parent de33dc6280
commit 9cb27dbe90

@ -5,12 +5,10 @@
*/ */
package com.todoroo.astrid.data; package com.todoroo.astrid.data;
import android.annotation.TargetApi;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.net.Uri;
import android.os.Build;
import android.text.TextUtils; import android.text.TextUtils;
import com.todoroo.andlib.data.AbstractModel; import com.todoroo.andlib.data.AbstractModel;
@ -91,11 +89,6 @@ abstract public class RemoteModel extends AbstractModel {
return NO_UUID.equals(uuid) || TextUtils.isEmpty(uuid); return NO_UUID.equals(uuid) || TextUtils.isEmpty(uuid);
} }
public Bitmap getPictureBitmap(StringProperty pictureProperty) {
String value = getValue(pictureProperty);
return PictureHelper.getPictureBitmap(value);
}
public static class PictureHelper { public static class PictureHelper {
public static final String PICTURES_DIRECTORY = "pictures"; //$NON-NLS-1$ public static final String PICTURES_DIRECTORY = "pictures"; //$NON-NLS-1$
@ -133,7 +126,7 @@ abstract public class RemoteModel extends AbstractModel {
return null; return null;
} }
public static Bitmap getPictureBitmap(String value) { public static Uri getPictureUri(String value) {
try { try {
if (value == null) { if (value == null) {
return null; return null;
@ -142,7 +135,7 @@ abstract public class RemoteModel extends AbstractModel {
JSONObject pictureJson = new JSONObject(value); JSONObject pictureJson = new JSONObject(value);
if (pictureJson.has("path")) { if (pictureJson.has("path")) {
String path = pictureJson.getString("path"); String path = pictureJson.getString("path");
return BitmapFactory.decodeFile(path); return Uri.fromFile(new File(path));
} }
} }
return null; return null;
@ -150,7 +143,6 @@ abstract public class RemoteModel extends AbstractModel {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
return null; return null;
} }
} }
} }

@ -10,6 +10,8 @@ import com.todoroo.andlib.data.Table;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import java.io.File;
public class UserActivity extends RemoteModel { public class UserActivity extends RemoteModel {
// --- table // --- table
@ -147,4 +149,8 @@ public class UserActivity extends RemoteModel {
public void setPicture(String picture) { public void setPicture(String picture) {
setValue(PICTURE, picture); setValue(PICTURE, picture);
} }
public Uri getPictureUri() {
return PictureHelper.getPictureUri(getValue(PICTURE));
}
} }

@ -5,11 +5,10 @@
*/ */
package com.todoroo.astrid.adapter; package com.todoroo.astrid.adapter;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.net.Uri;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.text.Html; import android.text.Html;
import android.text.Spanned; import android.text.Spanned;
@ -20,7 +19,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.CursorAdapter; import android.widget.CursorAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -150,8 +148,8 @@ public class UpdateAdapter extends CursorAdapter {
private void setupUserActivityRow(View view, UserActivity activity) { private void setupUserActivityRow(View view, UserActivity activity) {
final ImageView commentPictureView = (ImageView)view.findViewById(R.id.comment_picture); { final ImageView commentPictureView = (ImageView)view.findViewById(R.id.comment_picture); {
Bitmap updateBitmap = activity.getPictureBitmap(UserActivity.PICTURE); Uri updateBitmap = activity.getPictureUri();
setupImagePopupForCommentView(view, commentPictureView, updateBitmap, activity.getMessage(), fragment); setupImagePopupForCommentView(view, commentPictureView, updateBitmap, fragment);
} }
// name // name
@ -175,29 +173,18 @@ public class UpdateAdapter extends CursorAdapter {
return false; return false;
} }
public static void setupImagePopupForCommentView(View view, ImageView commentPictureView, final Bitmap updateBitmap, public static void setupImagePopupForCommentView(View view, ImageView commentPictureView, final Uri updateBitmap,
final String message, final Fragment fragment) { final Fragment fragment) {
if (updateBitmap != null) { //$NON-NLS-1$ if (updateBitmap != null) { //$NON-NLS-1$
commentPictureView.setVisibility(View.VISIBLE); commentPictureView.setVisibility(View.VISIBLE);
commentPictureView.setImageBitmap(updateBitmap); commentPictureView.setImageURI(updateBitmap);
view.setOnClickListener(new OnClickListener() { view.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
AlertDialog image = new AlertDialog.Builder(fragment.getActivity()).create(); fragment.startActivity(new Intent(Intent.ACTION_VIEW) {{
ImageView imageView = new ImageView(fragment.getActivity()); setDataAndType(updateBitmap, "image/jpg");
imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); }});
imageView.setImageResource(android.R.drawable.ic_menu_gallery);
imageView.setImageBitmap(updateBitmap);
image.setView(imageView);
image.setMessage(message);
image.setButton(fragment.getString(R.string.DLG_close), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
image.show();
} }
}); });
} else { } else {

@ -10,6 +10,7 @@ import android.content.Intent;
import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.text.Editable; import android.text.Editable;
import android.text.Html; import android.text.Html;
@ -358,7 +359,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
// picture // picture
final ImageView commentPictureView = (ImageView)view.findViewById(R.id.comment_picture); final ImageView commentPictureView = (ImageView)view.findViewById(R.id.comment_picture);
UpdateAdapter.setupImagePopupForCommentView(view, commentPictureView, item.commentBitmap, item.title.toString(), fragment); UpdateAdapter.setupImagePopupForCommentView(view, commentPictureView, item.commentBitmap, fragment);
} }
private void addComment() { private void addComment() {
@ -407,10 +408,10 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
private static class NoteOrUpdate { private static class NoteOrUpdate {
private final Spanned title; private final Spanned title;
private final Bitmap commentBitmap; private final Uri commentBitmap;
private final long createdAt; private final long createdAt;
public NoteOrUpdate(Spanned title, Bitmap commentBitmap, long createdAt) { public NoteOrUpdate(Spanned title, Uri commentBitmap, long createdAt) {
super(); super();
this.title = title; this.title = title;
this.commentBitmap = commentBitmap; this.commentBitmap = commentBitmap;
@ -435,7 +436,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
throw new RuntimeException("UserActivity should never be null"); throw new RuntimeException("UserActivity should never be null");
} }
Bitmap commentBitmap = u.getPictureBitmap(UserActivity.PICTURE); Uri commentBitmap = u.getPictureUri();
Spanned title = UpdateAdapter.getUpdateComment(u); Spanned title = UpdateAdapter.getUpdateComment(u);
long createdAt = u.getCreatedAt(); long createdAt = u.getCreatedAt();

Loading…
Cancel
Save