|
|
@ -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.Build; |
|
|
|
import android.os.Build; |
|
|
|
|
|
|
|
import android.support.annotation.NonNull; |
|
|
|
import android.support.v4.util.SparseArrayCompat; |
|
|
|
import android.support.v4.util.SparseArrayCompat; |
|
|
|
import android.view.SurfaceHolder; |
|
|
|
import android.view.SurfaceHolder; |
|
|
|
|
|
|
|
|
|
|
@ -19,7 +20,7 @@ import java.util.List; |
|
|
|
import java.util.SortedSet; |
|
|
|
import java.util.SortedSet; |
|
|
|
import java.util.TreeSet; |
|
|
|
import java.util.TreeSet; |
|
|
|
|
|
|
|
|
|
|
|
public class Camera1 extends CameraViewImpl { |
|
|
|
public class Camera1 extends CameraImpl { |
|
|
|
|
|
|
|
|
|
|
|
private static final SparseArrayCompat<String> FLASH_MODES = new SparseArrayCompat<>(); |
|
|
|
private static final SparseArrayCompat<String> FLASH_MODES = new SparseArrayCompat<>(); |
|
|
|
static { |
|
|
|
static { |
|
|
@ -28,10 +29,10 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
FLASH_MODES.put(CameraKit.Constants.FLASH_AUTO, Camera.Parameters.FLASH_MODE_AUTO); |
|
|
|
FLASH_MODES.put(CameraKit.Constants.FLASH_AUTO, Camera.Parameters.FLASH_MODE_AUTO); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static File VIDEO_FILE; |
|
|
|
private File mVideoFile; |
|
|
|
|
|
|
|
|
|
|
|
private int mCameraId; |
|
|
|
private int mCameraId; |
|
|
|
Camera mCamera; |
|
|
|
private Camera mCamera; |
|
|
|
private Camera.Parameters mCameraParameters; |
|
|
|
private Camera.Parameters mCameraParameters; |
|
|
|
private final Camera.CameraInfo mCameraInfo = new Camera.CameraInfo(); |
|
|
|
private final Camera.CameraInfo mCameraInfo = new Camera.CameraInfo(); |
|
|
|
|
|
|
|
|
|
|
@ -46,8 +47,16 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
|
|
|
|
|
|
|
|
private MediaRecorder mMediaRecorder; |
|
|
|
private MediaRecorder mMediaRecorder; |
|
|
|
|
|
|
|
|
|
|
|
Camera1(CameraListener callback, PreviewImpl preview) { |
|
|
|
private CameraListener mCameraListener; |
|
|
|
super(callback, preview); |
|
|
|
|
|
|
|
|
|
|
|
Camera1(@NonNull CameraListener cameraListener, @NonNull PreviewImpl preview) { |
|
|
|
|
|
|
|
super(cameraListener, preview); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.mCameraListener = cameraListener; |
|
|
|
|
|
|
|
this.mPreviewSizes = new TreeSet<>(); |
|
|
|
|
|
|
|
this.mCaptureSizes = new TreeSet<>(); |
|
|
|
|
|
|
|
this.mVideoFile = new File(getView().getContext().getExternalFilesDir(null), "video.mp4"); |
|
|
|
|
|
|
|
|
|
|
|
preview.setCallback(new PreviewImpl.Callback() { |
|
|
|
preview.setCallback(new PreviewImpl.Callback() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onSurfaceChanged() { |
|
|
|
public void onSurfaceChanged() { |
|
|
@ -57,11 +66,6 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
mPreviewSizes = new TreeSet<>(); |
|
|
|
|
|
|
|
mCaptureSizes = new TreeSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VIDEO_FILE = new File(getView().getContext().getExternalFilesDir(null), "video.mp4");; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -113,11 +117,6 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
int getFacing() { |
|
|
|
|
|
|
|
return mFacing; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
void setFlash(int flash) { |
|
|
|
void setFlash(int flash) { |
|
|
|
if (flash == mFlash) { |
|
|
|
if (flash == mFlash) { |
|
|
@ -150,11 +149,6 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
int getFlash() { |
|
|
|
|
|
|
|
return mFlash; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
void setAutoFocus(boolean autoFocus) { |
|
|
|
void setAutoFocus(boolean autoFocus) { |
|
|
|
if (autoFocus == mAutoFocus) { |
|
|
|
if (autoFocus == mAutoFocus) { |
|
|
@ -178,6 +172,8 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mCameraParameters.setFocusMode(modes.get(0)); |
|
|
|
mCameraParameters.setFocusMode(modes.get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -215,7 +211,7 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
mCamera.takePicture(null, null, null, new Camera.PictureCallback() { |
|
|
|
mCamera.takePicture(null, null, null, new Camera.PictureCallback() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onPictureTaken(byte[] data, Camera camera) { |
|
|
|
public void onPictureTaken(byte[] data, Camera camera) { |
|
|
|
getCameraListener().onPictureTaken(data); |
|
|
|
mCameraListener.onPictureTaken(data); |
|
|
|
camera.startPreview(); |
|
|
|
camera.startPreview(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -232,7 +228,7 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
getView().post(new Runnable() { |
|
|
|
getView().post(new Runnable() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
public void run() { |
|
|
|
getCameraListener().onPictureTaken(data); |
|
|
|
mCameraListener.onPictureTaken(data); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -318,7 +314,7 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); |
|
|
|
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); |
|
|
|
mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P)); |
|
|
|
mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P)); |
|
|
|
|
|
|
|
|
|
|
|
mMediaRecorder.setOutputFile(VIDEO_FILE.getAbsolutePath()); |
|
|
|
mMediaRecorder.setOutputFile(mVideoFile.getAbsolutePath()); |
|
|
|
mMediaRecorder.setOrientationHint(mCameraInfo.orientation); |
|
|
|
mMediaRecorder.setOrientationHint(mCameraInfo.orientation); |
|
|
|
|
|
|
|
|
|
|
|
mMediaRecorder.prepare(); |
|
|
|
mMediaRecorder.prepare(); |
|
|
@ -332,10 +328,15 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
mMediaRecorder = null; |
|
|
|
mMediaRecorder = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getCameraListener().onVideoTaken(VIDEO_FILE); |
|
|
|
mCameraListener.onVideoTaken(mVideoFile); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
void focus() { |
|
|
|
|
|
|
|
mCamera.autoFocus(null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
void setDisplayOrientation(int displayOrientation) { |
|
|
|
void setDisplayOrientation(int displayOrientation) { |
|
|
|
if (mDisplayOrientation == displayOrientation) { |
|
|
|
if (mDisplayOrientation == displayOrientation) { |
|
|
@ -399,7 +400,6 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
|
|
|
|
|
|
|
|
mCameraParameters.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight()); |
|
|
|
mCameraParameters.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight()); |
|
|
|
|
|
|
|
|
|
|
|
// TODO: fix this
|
|
|
|
|
|
|
|
mCameraParameters.setRotation(calcCameraRotation(mDisplayOrientation) + (mFacing == CameraKit.Constants.FACING_FRONT ? 180 : 0)); |
|
|
|
mCameraParameters.setRotation(calcCameraRotation(mDisplayOrientation) + (mFacing == CameraKit.Constants.FACING_FRONT ? 180 : 0)); |
|
|
|
|
|
|
|
|
|
|
|
setAutoFocusInternal(mAutoFocus); |
|
|
|
setAutoFocusInternal(mAutoFocus); |
|
|
@ -458,14 +458,14 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
adjustCameraParameters(); |
|
|
|
adjustCameraParameters(); |
|
|
|
mCamera.setDisplayOrientation(calcCameraRotation(mDisplayOrientation)); |
|
|
|
mCamera.setDisplayOrientation(calcCameraRotation(mDisplayOrientation)); |
|
|
|
|
|
|
|
|
|
|
|
getCameraListener().onCameraOpened(); |
|
|
|
mCameraListener.onCameraOpened(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void releaseCamera() { |
|
|
|
private void releaseCamera() { |
|
|
|
if (mCamera != null) { |
|
|
|
if (mCamera != null) { |
|
|
|
mCamera.release(); |
|
|
|
mCamera.release(); |
|
|
|
mCamera = null; |
|
|
|
mCamera = null; |
|
|
|
getCameraListener().onCameraClosed(); |
|
|
|
mCameraListener.onCameraClosed(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|