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

Commit

Permalink
improve camera UX and media preview as well
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
iamironrabbit committed Jun 4, 2018
1 parent e99fe85 commit b6369df
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

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

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

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

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

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -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);
}
Expand Down Expand Up @@ -225,7 +239,10 @@ protected void onResume() {

@Override
protected void onPause() {
mCameraView.stop();

if (mCameraView.isCameraOpened())
mCameraView.stop();

super.onPause();
}

Expand Down
11 changes: 9 additions & 2 deletions app/src/main/res/layout/awesome_activity_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,21 @@
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:orientation="vertical"
android:layout_gravity="left"
android:layout_margin="3dp"
android:background="@android:color/transparent"
android:background="#CCCCCCCC"
android:id="@+id/mediaPreviewContainer"
android:layout_weight="2"
android:visibility="gone"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|end"
android:src="@drawable/ic_menu_close"
android:id="@+id/mediaPreviewCancel"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
Expand Down

0 comments on commit b6369df

Please sign in to comment.