Use ACTION_VIEW to view comment pictures

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

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

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

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

@ -10,6 +10,7 @@ import android.content.Intent;
import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.Html;
@ -358,7 +359,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
// 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() {
@ -407,10 +408,10 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
private static class NoteOrUpdate {
private final Spanned title;
private final Bitmap commentBitmap;
private final Uri commentBitmap;
private final long createdAt;
public NoteOrUpdate(Spanned title, Bitmap commentBitmap, long createdAt) {
public NoteOrUpdate(Spanned title, Uri commentBitmap, long createdAt) {
super();
this.title = title;
this.commentBitmap = commentBitmap;
@ -435,7 +436,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
throw new RuntimeException("UserActivity should never be null");
}
Bitmap commentBitmap = u.getPictureBitmap(UserActivity.PICTURE);
Uri commentBitmap = u.getPictureUri();
Spanned title = UpdateAdapter.getUpdateComment(u);
long createdAt = u.getCreatedAt();

Loading…
Cancel
Save