From b6369df23c1b76e3dc15b1c79791ef7d90ae52de Mon Sep 17 00:00:00 2001 From: Eiron Rabbit Date: Mon, 4 Jun 2018 15:26:07 -0400 Subject: [PATCH] improve camera UX and media preview as well - pause camera after one picture is taken - add a "cancel" icon for media preview before send - use built-in camera if "proofmode" is not enabled --- .../ui/ConversationDetailActivity.java | 62 +++++++++++-------- .../messenger/ui/ConversationView.java | 13 ++++ .../messenger/ui/camera/CameraActivity.java | 25 ++++++-- .../res/layout/awesome_activity_detail.xml | 11 +++- 4 files changed, 80 insertions(+), 31 deletions(-) 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 ab7b48a73..db14a16c5 100644 --- a/app/src/main/java/org/awesomeapp/messenger/ui/ConversationDetailActivity.java +++ b/app/src/main/java/org/awesomeapp/messenger/ui/ConversationDetailActivity.java @@ -55,6 +55,7 @@ import android.widget.TextView; import org.awesomeapp.messenger.ImApp; +import org.awesomeapp.messenger.Preferences; import org.awesomeapp.messenger.model.Presence; import org.awesomeapp.messenger.provider.Imps; import org.awesomeapp.messenger.service.IChatSession; @@ -485,25 +486,29 @@ 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"); + if (Preferences.useProofMode()) + { + Intent intent = new Intent(this, CameraActivity.class); + intent.putExtra(CameraActivity.SETTING_ONE_AND_DONE,true); + startActivityForResult(intent, ConversationDetailActivity.REQUEST_TAKE_PICTURE); + } + 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"); - mLastPhoto = FileProvider.getUriForFile(this, - BuildConfig.APPLICATION_ID + ".provider", - photo); + mLastPhoto = FileProvider.getUriForFile(this, + BuildConfig.APPLICATION_ID + ".provider", + photo); - intent.putExtra(MediaStore.EXTRA_OUTPUT, - mLastPhoto); + intent.putExtra(MediaStore.EXTRA_OUTPUT, + mLastPhoto); - // start the image capture Intent - startActivityForResult(intent, ConversationDetailActivity.REQUEST_TAKE_PICTURE); - **/ + // start the image capture Intent + startActivityForResult(intent, ConversationDetailActivity.REQUEST_TAKE_PICTURE); + + } - Intent intent = new Intent(this, CameraActivity.class); - intent.putExtra(CameraActivity.SETTING_ONE_AND_DONE,true); - startActivityForResult(intent, ConversationDetailActivity.REQUEST_TAKE_PICTURE); } } @@ -734,22 +739,29 @@ else if (requestCode == REQUEST_SEND_FILE || requestCode == REQUEST_SEND_AUDIO) } else if (requestCode == REQUEST_TAKE_PICTURE) { + ShareRequest request = new ShareRequest(); - if (resultIntent.getData() != null) - { - ShareRequest request = new ShareRequest(); + if (Preferences.useProofMode()) { request.deleteFile = false; request.resizeImage = false; request.importContent = false; request.media = resultIntent.getData(); - request.mimeType = "image/jpeg"; + } + else + { + request.deleteFile = false; + request.resizeImage = true; + request.importContent = true; + request.media = mLastPhoto; + } - try { - mConvoView.setMediaDraft(request); - } - catch (Exception e){ - Log.w(ImApp.LOG_TAG,"error setting media draft",e); - } + 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/ConversationView.java b/app/src/main/java/org/awesomeapp/messenger/ui/ConversationView.java index 45e12c2ef..2cb422071 100644 --- a/app/src/main/java/org/awesomeapp/messenger/ui/ConversationView.java +++ b/app/src/main/java/org/awesomeapp/messenger/ui/ConversationView.java @@ -906,6 +906,13 @@ public void onClick(View v) { }); + mActivity.findViewById(R.id.mediaPreviewCancel).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + clearMediaDraft(); + + } + }); mActivity.findViewById(R.id.btnAttachPicture).setOnClickListener(new View.OnClickListener() { @@ -2145,6 +2152,12 @@ void setMediaDraft (ShareRequest mediaDraft) throws IOException { } + void clearMediaDraft () { + mShareDraft = null; + mComposeMessage.setText(""); + mActivity.findViewById(R.id.mediaPreviewContainer).setVisibility(View.GONE); + } + void deleteMessage (String packetId, String message) { if (!TextUtils.isEmpty(message)) { 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 bffb5e305..be7760b75 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 @@ -29,6 +29,10 @@ import java.io.IOException; import java.util.Date; import java.util.UUID; +import java.util.concurrent.Executor; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import im.zom.messenger.R; @@ -56,11 +60,17 @@ public void handleMessage(Message msg) { if (msg.what == 1) { - Toast.makeText(CameraActivity.this,"\uD83D\uDCF7",Toast.LENGTH_SHORT).show(); + // Toast.makeText(CameraActivity.this,"\uD83D\uDCF7",Toast.LENGTH_SHORT).show(); + } + else if (msg.what == 2) + { + mCameraView.stop(); } } }; + private Executor mExec = new ThreadPoolExecutor(1,3,60L, TimeUnit.SECONDS, new LinkedBlockingQueue()); + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -77,14 +87,18 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onPictureTaken(final Bitmap bitmap, final int rotationDegrees) { - new Thread () + mExec.execute(new Runnable() { public void run () { + + if (mOneAndDone) + mHandler.sendEmptyMessage(2); + storeBitmap(rotate(bitmap,rotationDegrees)); } - }.start(); + }); mHandler.sendEmptyMessage(1); } @@ -225,7 +239,10 @@ protected void onResume() { @Override protected void onPause() { - mCameraView.stop(); + + if (mCameraView.isCameraOpened()) + mCameraView.stop(); + super.onPause(); } diff --git a/app/src/main/res/layout/awesome_activity_detail.xml b/app/src/main/res/layout/awesome_activity_detail.xml index b2416d38a..daf47c305 100644 --- a/app/src/main/res/layout/awesome_activity_detail.xml +++ b/app/src/main/res/layout/awesome_activity_detail.xml @@ -272,14 +272,21 @@ +