|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.otaliastudios.cameraview; |
|
|
|
package com.otaliastudios.cameraview; |
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest; |
|
|
|
import android.Manifest; |
|
|
|
|
|
|
|
import android.annotation.SuppressLint; |
|
|
|
import android.annotation.TargetApi; |
|
|
|
import android.annotation.TargetApi; |
|
|
|
import android.app.Activity; |
|
|
|
import android.app.Activity; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Context; |
|
|
@ -11,6 +12,7 @@ import android.content.res.TypedArray; |
|
|
|
import android.graphics.PointF; |
|
|
|
import android.graphics.PointF; |
|
|
|
import android.graphics.Rect; |
|
|
|
import android.graphics.Rect; |
|
|
|
import android.graphics.YuvImage; |
|
|
|
import android.graphics.YuvImage; |
|
|
|
|
|
|
|
import android.media.MediaActionSound; |
|
|
|
import android.os.Build; |
|
|
|
import android.os.Build; |
|
|
|
import android.os.Handler; |
|
|
|
import android.os.Handler; |
|
|
|
import android.os.HandlerThread; |
|
|
|
import android.os.HandlerThread; |
|
|
@ -95,9 +97,11 @@ public class CameraView extends FrameLayout { |
|
|
|
@SuppressWarnings("WrongConstant") |
|
|
|
@SuppressWarnings("WrongConstant") |
|
|
|
private void init(@NonNull Context context, @Nullable AttributeSet attrs) { |
|
|
|
private void init(@NonNull Context context, @Nullable AttributeSet attrs) { |
|
|
|
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0); |
|
|
|
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0); |
|
|
|
mJpegQuality = a.getInteger(R.styleable.CameraView_cameraJpegQuality, DEFAULT_JPEG_QUALITY); |
|
|
|
// Self managed
|
|
|
|
mCropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, DEFAULT_CROP_OUTPUT); |
|
|
|
int jpegQuality = a.getInteger(R.styleable.CameraView_cameraJpegQuality, DEFAULT_JPEG_QUALITY); |
|
|
|
|
|
|
|
boolean cropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, DEFAULT_CROP_OUTPUT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Camera controller params
|
|
|
|
Facing facing = Facing.fromValue(a.getInteger(R.styleable.CameraView_cameraFacing, Facing.DEFAULT.value())); |
|
|
|
Facing facing = Facing.fromValue(a.getInteger(R.styleable.CameraView_cameraFacing, Facing.DEFAULT.value())); |
|
|
|
Flash flash = Flash.fromValue(a.getInteger(R.styleable.CameraView_cameraFlash, Flash.DEFAULT.value())); |
|
|
|
Flash flash = Flash.fromValue(a.getInteger(R.styleable.CameraView_cameraFlash, Flash.DEFAULT.value())); |
|
|
|
Grid grid = Grid.fromValue(a.getInteger(R.styleable.CameraView_cameraGrid, Grid.DEFAULT.value())); |
|
|
|
Grid grid = Grid.fromValue(a.getInteger(R.styleable.CameraView_cameraGrid, Grid.DEFAULT.value())); |
|
|
@ -105,6 +109,7 @@ public class CameraView extends FrameLayout { |
|
|
|
VideoQuality videoQuality = VideoQuality.fromValue(a.getInteger(R.styleable.CameraView_cameraVideoQuality, VideoQuality.DEFAULT.value())); |
|
|
|
VideoQuality videoQuality = VideoQuality.fromValue(a.getInteger(R.styleable.CameraView_cameraVideoQuality, VideoQuality.DEFAULT.value())); |
|
|
|
SessionType sessionType = SessionType.fromValue(a.getInteger(R.styleable.CameraView_cameraSessionType, SessionType.DEFAULT.value())); |
|
|
|
SessionType sessionType = SessionType.fromValue(a.getInteger(R.styleable.CameraView_cameraSessionType, SessionType.DEFAULT.value())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Gestures
|
|
|
|
GestureAction tapGesture = GestureAction.fromValue(a.getInteger(R.styleable.CameraView_cameraGestureTap, GestureAction.DEFAULT_TAP.value())); |
|
|
|
GestureAction tapGesture = GestureAction.fromValue(a.getInteger(R.styleable.CameraView_cameraGestureTap, GestureAction.DEFAULT_TAP.value())); |
|
|
|
GestureAction longTapGesture = GestureAction.fromValue(a.getInteger(R.styleable.CameraView_cameraGestureLongTap, GestureAction.DEFAULT_LONG_TAP.value())); |
|
|
|
GestureAction longTapGesture = GestureAction.fromValue(a.getInteger(R.styleable.CameraView_cameraGestureLongTap, GestureAction.DEFAULT_LONG_TAP.value())); |
|
|
|
GestureAction pinchGesture = GestureAction.fromValue(a.getInteger(R.styleable.CameraView_cameraGesturePinch, GestureAction.DEFAULT_PINCH.value())); |
|
|
|
GestureAction pinchGesture = GestureAction.fromValue(a.getInteger(R.styleable.CameraView_cameraGesturePinch, GestureAction.DEFAULT_PINCH.value())); |
|
|
@ -125,12 +130,20 @@ public class CameraView extends FrameLayout { |
|
|
|
addView(mScrollGestureLayout); |
|
|
|
addView(mScrollGestureLayout); |
|
|
|
|
|
|
|
|
|
|
|
mIsStarted = false; |
|
|
|
mIsStarted = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Self managed
|
|
|
|
|
|
|
|
setCropOutput(cropOutput); |
|
|
|
|
|
|
|
setJpegQuality(jpegQuality); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Camera controller params
|
|
|
|
setFacing(facing); |
|
|
|
setFacing(facing); |
|
|
|
setFlash(flash); |
|
|
|
setFlash(flash); |
|
|
|
setSessionType(sessionType); |
|
|
|
setSessionType(sessionType); |
|
|
|
setVideoQuality(videoQuality); |
|
|
|
setVideoQuality(videoQuality); |
|
|
|
setWhiteBalance(whiteBalance); |
|
|
|
setWhiteBalance(whiteBalance); |
|
|
|
setGrid(grid); |
|
|
|
setGrid(grid); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Gestures
|
|
|
|
mapGesture(Gesture.TAP, tapGesture); |
|
|
|
mapGesture(Gesture.TAP, tapGesture); |
|
|
|
// mapGesture(Gesture.DOUBLE_TAP, doubleTapGesture);
|
|
|
|
// mapGesture(Gesture.DOUBLE_TAP, doubleTapGesture);
|
|
|
|
mapGesture(Gesture.LONG_TAP, longTapGesture); |
|
|
|
mapGesture(Gesture.LONG_TAP, longTapGesture); |
|
|
@ -997,7 +1010,9 @@ public class CameraView extends FrameLayout { |
|
|
|
* @see #captureSnapshot() |
|
|
|
* @see #captureSnapshot() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void capturePicture() { |
|
|
|
public void capturePicture() { |
|
|
|
mCameraController.capturePicture(); |
|
|
|
if (mCameraController.capturePicture() && mUseSounds) { |
|
|
|
|
|
|
|
// TODO: sound
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1012,7 +1027,10 @@ public class CameraView extends FrameLayout { |
|
|
|
* @see #capturePicture() |
|
|
|
* @see #capturePicture() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void captureSnapshot() { |
|
|
|
public void captureSnapshot() { |
|
|
|
mCameraController.captureSnapshot(); |
|
|
|
if (mCameraController.captureSnapshot() && mUseSounds) { |
|
|
|
|
|
|
|
//noinspection all
|
|
|
|
|
|
|
|
sound(MediaActionSound.SHUTTER_CLICK); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1079,9 +1097,10 @@ public class CameraView extends FrameLayout { |
|
|
|
* This will fire {@link CameraListener#onVideoTaken(File)}. |
|
|
|
* This will fire {@link CameraListener#onVideoTaken(File)}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void stopCapturingVideo() { |
|
|
|
public void stopCapturingVideo() { |
|
|
|
mCameraController.endVideo(); |
|
|
|
if (mCameraController.endVideo()) { |
|
|
|
if (getKeepScreenOn() != mKeepScreenOn) setKeepScreenOn(mKeepScreenOn); |
|
|
|
if (getKeepScreenOn() != mKeepScreenOn) setKeepScreenOn(mKeepScreenOn); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -1144,6 +1163,17 @@ public class CameraView extends FrameLayout { |
|
|
|
// ----------------------
|
|
|
|
// ----------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MediaActionSound mSound; |
|
|
|
|
|
|
|
private final boolean mUseSounds = Build.VERSION.SDK_INT >= 16; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("all") |
|
|
|
|
|
|
|
private void sound(int soundType) { |
|
|
|
|
|
|
|
if (mUseSounds) { |
|
|
|
|
|
|
|
if (mSound == null) mSound = new MediaActionSound(); |
|
|
|
|
|
|
|
mSound.play(soundType); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class CameraCallbacks { |
|
|
|
class CameraCallbacks { |
|
|
|
|
|
|
|
|
|
|
|
private ArrayList<CameraListener> mListeners; |
|
|
|
private ArrayList<CameraListener> mListeners; |
|
|
@ -1289,6 +1319,11 @@ public class CameraView extends FrameLayout { |
|
|
|
uiHandler.post(new Runnable() { |
|
|
|
uiHandler.post(new Runnable() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
public void run() { |
|
|
|
|
|
|
|
if (success && mUseSounds) { |
|
|
|
|
|
|
|
//noinspection all
|
|
|
|
|
|
|
|
sound(MediaActionSound.FOCUS_COMPLETE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (gesture != null && mGestureMap.get(gesture) == GestureAction.FOCUS_WITH_MARKER) { |
|
|
|
if (gesture != null && mGestureMap.get(gesture) == GestureAction.FOCUS_WITH_MARKER) { |
|
|
|
mTapGestureLayout.onFocusEnd(success); |
|
|
|
mTapGestureLayout.onFocusEnd(success); |
|
|
|
} |
|
|
|
} |
|
|
|