Merge pull request #99 from noln/master

Fixed Android Studio preview rendering issue, and 'captureImage' RuntimeException
pull/1/head
Dylan McIntyre 8 years ago committed by GitHub
commit 600b6497fc
  1. 35
      camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java
  2. 7
      camerakit/src/main/java/com/flurgle/camerakit/CameraView.java

@ -6,6 +6,7 @@ import android.hardware.Camera;
import android.media.CamcorderProfile; import android.media.CamcorderProfile;
import android.media.MediaRecorder; import android.media.MediaRecorder;
import android.os.Handler; import android.os.Handler;
import android.util.Log;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
@ -30,6 +31,8 @@ import static com.flurgle.camerakit.CameraKit.Constants.METHOD_STILL;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class Camera1 extends CameraImpl { public class Camera1 extends CameraImpl {
private static final String TAG = Camera1.class.getSimpleName();
private static final int FOCUS_AREA_SIZE_DEFAULT = 300; private static final int FOCUS_AREA_SIZE_DEFAULT = 300;
private static final int FOCUS_METERING_AREA_WEIGHT_DEFAULT = 1000; private static final int FOCUS_METERING_AREA_WEIGHT_DEFAULT = 1000;
private static final int DELAY_MILLIS_BEFORE_RESETTING_FOCUS = 3000; private static final int DELAY_MILLIS_BEFORE_RESETTING_FOCUS = 3000;
@ -44,6 +47,7 @@ public class Camera1 extends CameraImpl {
private MediaRecorder mMediaRecorder; private MediaRecorder mMediaRecorder;
private File mVideoFile; private File mVideoFile;
private Camera.AutoFocusCallback mAutofocusCallback; private Camera.AutoFocusCallback mAutofocusCallback;
private boolean capturingImage = false;
private int mDisplayOrientation; private int mDisplayOrientation;
@ -210,15 +214,28 @@ public class Camera1 extends CameraImpl {
void captureImage() { void captureImage() {
switch (mMethod) { switch (mMethod) {
case METHOD_STANDARD: case METHOD_STANDARD:
mCamera.takePicture(null, null, null, new Camera.PictureCallback() { // Null check required for camera here as is briefly null when View is detached
@Override if (!capturingImage && mCamera != null) {
public void onPictureTaken(byte[] data, Camera camera) {
mCameraListener.onPictureTaken(data); // Set boolean to wait for image callback
if (mCamera != null) { capturingImage = true;
mCamera.startPreview();
} mCamera.takePicture(null, null, null,
} new Camera.PictureCallback() {
}); @Override
public void onPictureTaken(byte[] data, Camera camera) {
mCameraListener.onPictureTaken(data);
// Reset capturing state to allow photos to be taken
capturingImage = false;
camera.startPreview();
}
});
}
else {
Log.w(TAG, "Unable, waiting for picture to be taken");
}
break; break;
case METHOD_STILL: case METHOD_STILL:

@ -183,9 +183,10 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
super.onAttachedToWindow(); super.onAttachedToWindow();
if (!isInEditMode()) { if (!isInEditMode()) {
mDisplayOrientationDetector.enable( mDisplayOrientationDetector.enable(
ViewCompat.isAttachedToWindow(this) ViewCompat.isAttachedToWindow(this)
? DisplayManagerCompat.getInstance(getContext()).getDisplay(Display.DEFAULT_DISPLAY) ? DisplayManagerCompat.getInstance(getContext())
: null .getDisplay(Display.DEFAULT_DISPLAY)
: null
); );
} }
} }

Loading…
Cancel
Save