Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
implement in-app camera for conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
iamironrabbit committed Jun 1, 2018
1 parent 68994d9 commit 2646699
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());

Expand All @@ -243,11 +247,32 @@ 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)
{
Log.e(ImApp.LOG_TAG,"error importing photo",ioe);
}
}

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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit 2646699

Please sign in to comment.