diff --git a/app/src/main/java/org/awesomeapp/messenger/ui/ConversationDetailActivity.java b/app/src/main/java/org/awesomeapp/messenger/ui/ConversationDetailActivity.java index 299de6e0e..fe02a44ac 100644 --- a/app/src/main/java/org/awesomeapp/messenger/ui/ConversationDetailActivity.java +++ b/app/src/main/java/org/awesomeapp/messenger/ui/ConversationDetailActivity.java @@ -58,6 +58,7 @@ import org.awesomeapp.messenger.model.Presence; import org.awesomeapp.messenger.provider.Imps; import org.awesomeapp.messenger.service.IChatSession; +import org.awesomeapp.messenger.ui.camera.CameraActivity; import org.awesomeapp.messenger.ui.widgets.ShareRequest; import org.awesomeapp.messenger.util.SecureMediaStore; import org.awesomeapp.messenger.util.SystemServices; @@ -484,6 +485,7 @@ void startPhotoTaker() { } else { + /** // create Intent to take a picture and return control to the calling application Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File photo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "cs_" + new Date().getTime() + ".jpg"); @@ -497,6 +499,10 @@ void startPhotoTaker() { // start the image capture Intent startActivityForResult(intent, ConversationDetailActivity.REQUEST_TAKE_PICTURE); + **/ + + Intent intent = new Intent(this, CameraActivity.class); + startActivityForResult(intent, ConversationDetailActivity.REQUEST_TAKE_PICTURE); } } @@ -727,13 +733,22 @@ else if (requestCode == REQUEST_SEND_FILE || requestCode == REQUEST_SEND_AUDIO) } else if (requestCode == REQUEST_TAKE_PICTURE) { - if (mLastPhoto != null) { - boolean deleteFile = true; - boolean resizeImage = true; - boolean importContent = true; - handleSendDelete(mLastPhoto,"image/jpeg", deleteFile, resizeImage, importContent); - mLastPhoto = null; + if (resultIntent.getData() != null) + { + ShareRequest request = new ShareRequest(); + request.deleteFile = false; + request.resizeImage = false; + request.importContent = false; + request.media = resultIntent.getData(); + request.mimeType = "image/jpeg"; + + try { + mConvoView.setMediaDraft(request); + } + catch (Exception e){ + Log.w(ImApp.LOG_TAG,"error setting media draft",e); + } } } diff --git a/app/src/main/java/org/awesomeapp/messenger/ui/camera/CameraActivity.java b/app/src/main/java/org/awesomeapp/messenger/ui/camera/CameraActivity.java index b29c0b193..d91d03fa9 100644 --- a/app/src/main/java/org/awesomeapp/messenger/ui/camera/CameraActivity.java +++ b/app/src/main/java/org/awesomeapp/messenger/ui/camera/CameraActivity.java @@ -1,5 +1,6 @@ package org.awesomeapp.messenger.ui.camera; +import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Camera; import android.graphics.Matrix; @@ -230,6 +231,9 @@ private void storeBitmap (Bitmap bitmap) try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + bitmap = getResizedBitmap(bitmap,SecureMediaStore.DEFAULT_IMAGE_WIDTH,SecureMediaStore.DEFAULT_IMAGE_WIDTH); + bitmap.compress(Bitmap.CompressFormat.JPEG, 100 /*ignored for JPG*/, bos); ByteArrayInputStream bs = new ByteArrayInputStream(bos.toByteArray()); @@ -243,6 +247,11 @@ private void storeBitmap (Bitmap bitmap) System.currentTimeMillis(), Imps.MessageType.OUTGOING_ENCRYPTED_VERIFIED, 0, offerId, mimeType); + Intent data = new Intent(); + data.setData(vfsUri); + setResult(RESULT_OK,data); + finish(); + } catch (IOException ioe) { @@ -250,4 +259,20 @@ private void storeBitmap (Bitmap bitmap) } } + public Bitmap getResizedBitmap(Bitmap bm, int maxWidth, int maxHeight) { + + float scale = Math.min(((float)maxHeight / bm.getWidth()), ((float)maxWidth / bm.getHeight())); + + // CREATE A MATRIX FOR THE MANIPULATION + Matrix matrix = new Matrix(); + // RESIZE THE BIT MAP + matrix.postScale(scale, scale); + + // "RECREATE" THE NEW BITMAP + Bitmap resizedBitmap = Bitmap.createBitmap( + bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, false); + bm.recycle(); + return resizedBitmap; + } + } diff --git a/app/src/main/java/org/awesomeapp/messenger/util/SecureMediaStore.java b/app/src/main/java/org/awesomeapp/messenger/util/SecureMediaStore.java index 1522561bd..a1ae4c8e0 100644 --- a/app/src/main/java/org/awesomeapp/messenger/util/SecureMediaStore.java +++ b/app/src/main/java/org/awesomeapp/messenger/util/SecureMediaStore.java @@ -39,7 +39,7 @@ public class SecureMediaStore { private static String dbFilePath; private static final String BLOB_NAME = "media.db"; - private static final int DEFAULT_IMAGE_WIDTH = 720; + public static final int DEFAULT_IMAGE_WIDTH = 1080; public static void unmount() { VirtualFileSystem.get().unmount(); @@ -308,9 +308,20 @@ public static Uri resizeAndImportImage(Context context, String sessionId, Uri ur return vfsUri(targetPath); } + public static InputStream openInputStream (Context context, Uri uri) throws FileNotFoundException { + InputStream is; + + if (uri.getScheme() != null && uri.getScheme().equals("vfs")) + is = new info.guardianproject.iocipher.FileInputStream(uri.getPath()); + else + is = context.getContentResolver().openInputStream(uri); + + + return is; + } public static Bitmap getThumbnailFile(Context context, Uri uri, int thumbnailSize) throws IOException { - InputStream is = context.getContentResolver().openInputStream(uri); + InputStream is = openInputStream(context, uri); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; @@ -326,15 +337,15 @@ public static Bitmap getThumbnailFile(Context context, Uri uri, int thumbnailSiz : options.outWidth; is.close(); - is = context.getContentResolver().openInputStream(uri); - + is = openInputStream(context, uri); + BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inSampleSize = calculateInSampleSize(options, thumbnailSize, thumbnailSize); Bitmap scaledBitmap = BitmapFactory.decodeStream(is, null, opts); is.close(); - ExifInterface exif = new ExifInterface(context.getContentResolver().openInputStream(uri)); + ExifInterface exif = new ExifInterface(openInputStream(context,uri)); int orientationType = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int orientationD = 0; if (orientationType == ExifInterface.ORIENTATION_ROTATE_90)