mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-22 22:27:43 +01:00
offer the app at image_capture actions
This commit is contained in:
parent
cabc960317
commit
b4c76b4dfd
@ -25,6 +25,11 @@
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.media.action.IMAGE_CAPTURE"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
|
@ -9,8 +9,10 @@ import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.SurfaceView;
|
||||
@ -31,13 +33,14 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements SensorEventListener, PreviewListener {
|
||||
public class MainActivity extends AppCompatActivity implements SensorEventListener, PreviewListener, PhotoProcessor.MediaSavedListener {
|
||||
@BindView(R.id.viewHolder) RelativeLayout viewHolder;
|
||||
@BindView(R.id.toggle_camera) ImageView toggleCameraBtn;
|
||||
@BindView(R.id.toggle_flash) ImageView toggleFlashBtn;
|
||||
@BindView(R.id.toggle_videocam) ImageView togglePhotoVideoBtn;
|
||||
@BindView(R.id.shutter) ImageView shutterBtn;
|
||||
@BindView(R.id.video_rec_curr_timer) TextView recCurrTimer;
|
||||
@BindView(R.id.about) View aboutBtn;
|
||||
|
||||
private static final int CAMERA_STORAGE_PERMISSION = 1;
|
||||
private static final int AUDIO_PERMISSION = 2;
|
||||
@ -47,6 +50,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
||||
private boolean isInPhotoMode;
|
||||
private boolean isAskingPermissions;
|
||||
private boolean isCameraAvailable;
|
||||
private boolean isImageCaptureIntent;
|
||||
private int currVideoRecTimer;
|
||||
private int orientation;
|
||||
private int currCamera;
|
||||
@ -58,6 +62,18 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
tryInitCamera();
|
||||
|
||||
final Intent intent = getIntent();
|
||||
if (intent != null && intent.getExtras() != null && intent.getAction().equals(MediaStore.ACTION_IMAGE_CAPTURE)) {
|
||||
isImageCaptureIntent = true;
|
||||
togglePhotoVideoBtn.setVisibility(View.GONE);
|
||||
aboutBtn.setVisibility(View.GONE);
|
||||
|
||||
final Object output = intent.getExtras().get(MediaStore.EXTRA_OUTPUT);
|
||||
if (output != null && output instanceof Uri) {
|
||||
preview.setTargetUri((Uri) output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void tryInitCamera() {
|
||||
@ -347,4 +363,12 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
||||
public int getCurrentOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mediaSaved() {
|
||||
if (isImageCaptureIntent) {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.simplemobiletools.camera;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
@ -8,35 +8,66 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class PhotoProcessor extends AsyncTask<byte[], Void, Void> {
|
||||
private static final String TAG = PhotoProcessor.class.getSimpleName();
|
||||
private static Context mContext;
|
||||
private static WeakReference<MainActivity> mActivity;
|
||||
private static Uri mUri;
|
||||
|
||||
public PhotoProcessor(Context context) {
|
||||
mContext = context;
|
||||
public PhotoProcessor(MainActivity activity, Uri uri) {
|
||||
mActivity = new WeakReference<>(activity);
|
||||
mUri = uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(byte[]... params) {
|
||||
final String photoPath = Utils.getOutputMediaFile(mContext, true);
|
||||
if (photoPath.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FileOutputStream fos = null;
|
||||
String path;
|
||||
try {
|
||||
final File photoFile = new File(photoPath);
|
||||
if (mUri != null) {
|
||||
path = mUri.getPath();
|
||||
} else {
|
||||
path = Utils.getOutputMediaFile(mActivity.get(), true);
|
||||
}
|
||||
|
||||
if (path.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final File photoFile = new File(path);
|
||||
final byte[] data = params[0];
|
||||
final FileOutputStream fos = new FileOutputStream(photoFile);
|
||||
fos = new FileOutputStream(photoFile);
|
||||
fos.write(data);
|
||||
fos.close();
|
||||
Utils.scanFile(photoPath, mContext);
|
||||
Utils.scanFile(path, mActivity.get().getApplicationContext());
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.d(TAG, "PhotoProcessor file not found: " + e.getMessage());
|
||||
Log.e(TAG, "PhotoProcessor file not found: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "PhotoProcessor ioexception " + e.getMessage());
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "PhotoProcessor close ioexception " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
MediaSavedListener listener = mActivity.get();
|
||||
if (listener != null) {
|
||||
listener.mediaSaved();
|
||||
}
|
||||
}
|
||||
|
||||
public interface MediaSavedListener {
|
||||
void mediaSaved();
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.simplemobiletools.camera;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.hardware.Camera;
|
||||
import android.media.CamcorderProfile;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.MediaRecorder;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
@ -34,7 +34,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
||||
private static SurfaceView surfaceView;
|
||||
private static Camera.Size previewSize;
|
||||
private static boolean canTakePicture;
|
||||
private static Activity activity;
|
||||
private static MainActivity activity;
|
||||
private static int currCameraId;
|
||||
private static boolean isFlashEnabled;
|
||||
private static Camera.Parameters parameters;
|
||||
@ -47,12 +47,13 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
||||
private static int lastClickX;
|
||||
private static int lastClickY;
|
||||
private static int initVideoRotation;
|
||||
private static Uri targetUri;
|
||||
|
||||
public Preview(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public Preview(Activity act, SurfaceView sv, PreviewListener cb) {
|
||||
public Preview(MainActivity act, SurfaceView sv, PreviewListener cb) {
|
||||
super(act);
|
||||
|
||||
activity = act;
|
||||
@ -120,6 +121,10 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
||||
}
|
||||
}
|
||||
|
||||
public void setTargetUri(Uri uri) {
|
||||
targetUri = uri;
|
||||
}
|
||||
|
||||
private static int getPreviewRotation(int cameraId) {
|
||||
final Camera.CameraInfo info = Utils.getCameraInfo(cameraId);
|
||||
int degrees = getRotationDegrees();
|
||||
@ -200,7 +205,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
||||
}
|
||||
}, PHOTO_PREVIEW_LENGTH);
|
||||
|
||||
new PhotoProcessor(getContext()).execute(data);
|
||||
new PhotoProcessor(activity, targetUri).execute(data);
|
||||
if (isFlashEnabled) {
|
||||
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
|
||||
camera.setParameters(parameters);
|
||||
|
Loading…
x
Reference in New Issue
Block a user