|
|
@ -29,6 +29,9 @@ import static com.flurgle.camerakit.CameraKit.Constants.FLASH_AUTO; |
|
|
|
import static com.flurgle.camerakit.CameraKit.Constants.FLASH_OFF; |
|
|
|
import static com.flurgle.camerakit.CameraKit.Constants.FLASH_OFF; |
|
|
|
import static com.flurgle.camerakit.CameraKit.Constants.FLASH_ON; |
|
|
|
import static com.flurgle.camerakit.CameraKit.Constants.FLASH_ON; |
|
|
|
import static com.flurgle.camerakit.CameraKit.Constants.METHOD_STANDARD; |
|
|
|
import static com.flurgle.camerakit.CameraKit.Constants.METHOD_STANDARD; |
|
|
|
|
|
|
|
import static com.flurgle.camerakit.CameraKit.Constants.PERMISSIONS_LAZY; |
|
|
|
|
|
|
|
import static com.flurgle.camerakit.CameraKit.Constants.PERMISSIONS_PICTURE; |
|
|
|
|
|
|
|
import static com.flurgle.camerakit.CameraKit.Constants.PERMISSIONS_STRICT; |
|
|
|
|
|
|
|
|
|
|
|
public class CameraView extends FrameLayout { |
|
|
|
public class CameraView extends FrameLayout { |
|
|
|
|
|
|
|
|
|
|
@ -47,6 +50,9 @@ public class CameraView extends FrameLayout { |
|
|
|
@Zoom |
|
|
|
@Zoom |
|
|
|
private int mZoom; |
|
|
|
private int mZoom; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Permissions |
|
|
|
|
|
|
|
private int mPermissions; |
|
|
|
|
|
|
|
|
|
|
|
private int mJpegQuality; |
|
|
|
private int mJpegQuality; |
|
|
|
private boolean mCropOutput; |
|
|
|
private boolean mCropOutput; |
|
|
|
private boolean mAdjustViewBounds; |
|
|
|
private boolean mAdjustViewBounds; |
|
|
@ -76,6 +82,7 @@ public class CameraView extends FrameLayout { |
|
|
|
mFocus = a.getInteger(R.styleable.CameraView_ckFocus, CameraKit.Defaults.DEFAULT_FOCUS); |
|
|
|
mFocus = a.getInteger(R.styleable.CameraView_ckFocus, CameraKit.Defaults.DEFAULT_FOCUS); |
|
|
|
mMethod = a.getInteger(R.styleable.CameraView_ckMethod, CameraKit.Defaults.DEFAULT_METHOD); |
|
|
|
mMethod = a.getInteger(R.styleable.CameraView_ckMethod, CameraKit.Defaults.DEFAULT_METHOD); |
|
|
|
mZoom = a.getInteger(R.styleable.CameraView_ckZoom, CameraKit.Defaults.DEFAULT_ZOOM); |
|
|
|
mZoom = a.getInteger(R.styleable.CameraView_ckZoom, CameraKit.Defaults.DEFAULT_ZOOM); |
|
|
|
|
|
|
|
mPermissions = a.getInteger(R.styleable.CameraView_ckPermissions, CameraKit.Defaults.DEFAULT_PERMISSIONS); |
|
|
|
mJpegQuality = a.getInteger(R.styleable.CameraView_ckJpegQuality, CameraKit.Defaults.DEFAULT_JPEG_QUALITY); |
|
|
|
mJpegQuality = a.getInteger(R.styleable.CameraView_ckJpegQuality, CameraKit.Defaults.DEFAULT_JPEG_QUALITY); |
|
|
|
mCropOutput = a.getBoolean(R.styleable.CameraView_ckCropOutput, CameraKit.Defaults.DEFAULT_CROP_OUTPUT); |
|
|
|
mCropOutput = a.getBoolean(R.styleable.CameraView_ckCropOutput, CameraKit.Defaults.DEFAULT_CROP_OUTPUT); |
|
|
|
mAdjustViewBounds = a.getBoolean(R.styleable.CameraView_android_adjustViewBounds, CameraKit.Defaults.DEFAULT_ADJUST_VIEW_BOUNDS); |
|
|
|
mAdjustViewBounds = a.getBoolean(R.styleable.CameraView_android_adjustViewBounds, CameraKit.Defaults.DEFAULT_ADJUST_VIEW_BOUNDS); |
|
|
@ -139,7 +146,7 @@ public class CameraView extends FrameLayout { |
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
|
|
|
if (mAdjustViewBounds) { |
|
|
|
if (mAdjustViewBounds) { |
|
|
|
Size previewSize = getPreviewSize(); |
|
|
|
Size previewSize = getPreviewSize(); |
|
|
|
if(previewSize != null) { |
|
|
|
if (previewSize != null) { |
|
|
|
if (getLayoutParams().width == LayoutParams.WRAP_CONTENT) { |
|
|
|
if (getLayoutParams().width == LayoutParams.WRAP_CONTENT) { |
|
|
|
int height = MeasureSpec.getSize(heightMeasureSpec); |
|
|
|
int height = MeasureSpec.getSize(heightMeasureSpec); |
|
|
|
float ratio = (float) height / (float) previewSize.getWidth(); |
|
|
|
float ratio = (float) height / (float) previewSize.getWidth(); |
|
|
@ -159,7 +166,7 @@ public class CameraView extends FrameLayout { |
|
|
|
); |
|
|
|
); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -169,24 +176,46 @@ public class CameraView extends FrameLayout { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void start() { |
|
|
|
public void start() { |
|
|
|
int permissionCheck = ContextCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA); |
|
|
|
int cameraCheck = ContextCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA); |
|
|
|
if (permissionCheck == PackageManager.PERMISSION_GRANTED) { |
|
|
|
int audioCheck = ContextCompat.checkSelfPermission(getContext(), Manifest.permission.RECORD_AUDIO); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (mPermissions) { |
|
|
|
|
|
|
|
case PERMISSIONS_STRICT: |
|
|
|
|
|
|
|
if (cameraCheck != PackageManager.PERMISSION_GRANTED || audioCheck != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
|
|
|
requestPermissions(true, true); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case PERMISSIONS_LAZY: |
|
|
|
|
|
|
|
if (cameraCheck != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
|
|
|
requestPermissions(true, true); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case PERMISSIONS_PICTURE: |
|
|
|
|
|
|
|
if (cameraCheck != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
|
|
|
requestPermissions(true, false); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
new Thread(new Runnable() { |
|
|
|
new Thread(new Runnable() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
public void run() { |
|
|
|
mCameraImpl.start(); |
|
|
|
mCameraImpl.start(); |
|
|
|
} |
|
|
|
} |
|
|
|
}).start(); |
|
|
|
}).start(); |
|
|
|
} else { |
|
|
|
|
|
|
|
requestCameraPermission(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stop() { |
|
|
|
public void stop() { |
|
|
|
mCameraImpl.stop(); |
|
|
|
mCameraImpl.stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setFacing(@Facing final int facing) { |
|
|
|
public void setFacing(@Facing |
|
|
|
|
|
|
|
final int facing) { |
|
|
|
this.mFacing = facing; |
|
|
|
this.mFacing = facing; |
|
|
|
|
|
|
|
|
|
|
|
new Thread(new Runnable() { |
|
|
|
new Thread(new Runnable() { |
|
|
@ -288,7 +317,7 @@ public class CameraView extends FrameLayout { |
|
|
|
return mCameraImpl != null ? mCameraImpl.getCaptureResolution() : null; |
|
|
|
return mCameraImpl != null ? mCameraImpl.getCaptureResolution() : null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void requestCameraPermission() { |
|
|
|
private void requestPermissions(boolean requestCamera, boolean requestAudio) { |
|
|
|
Activity activity = null; |
|
|
|
Activity activity = null; |
|
|
|
Context context = getContext(); |
|
|
|
Context context = getContext(); |
|
|
|
while (context instanceof ContextWrapper) { |
|
|
|
while (context instanceof ContextWrapper) { |
|
|
|