|
|
|
@ -46,12 +46,14 @@ public class CameraView extends FrameLayout { |
|
|
|
|
|
|
|
|
|
final static int DEFAULT_JPEG_QUALITY = 100; |
|
|
|
|
final static boolean DEFAULT_CROP_OUTPUT = false; |
|
|
|
|
final static boolean DEFAULT_PLAY_SOUNDS = true; |
|
|
|
|
|
|
|
|
|
// Self managed parameters
|
|
|
|
|
private int mJpegQuality; |
|
|
|
|
private boolean mCropOutput; |
|
|
|
|
private float mZoomValue; |
|
|
|
|
private float mExposureCorrectionValue; |
|
|
|
|
private boolean mPlaySounds; |
|
|
|
|
private HashMap<Gesture, GestureAction> mGestureMap = new HashMap<>(4); |
|
|
|
|
|
|
|
|
|
// Components
|
|
|
|
@ -60,7 +62,7 @@ public class CameraView extends FrameLayout { |
|
|
|
|
private CameraController mCameraController; |
|
|
|
|
private Preview mPreviewImpl; |
|
|
|
|
private ArrayList<CameraListener> mListeners = new ArrayList<>(2); |
|
|
|
|
|
|
|
|
|
private MediaActionSound mSound; |
|
|
|
|
|
|
|
|
|
// Views
|
|
|
|
|
GridLinesLayout mGridLinesLayout; |
|
|
|
@ -91,6 +93,7 @@ public class CameraView extends FrameLayout { |
|
|
|
|
// Self managed
|
|
|
|
|
int jpegQuality = a.getInteger(R.styleable.CameraView_cameraJpegQuality, DEFAULT_JPEG_QUALITY); |
|
|
|
|
boolean cropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, DEFAULT_CROP_OUTPUT); |
|
|
|
|
boolean playSounds = a.getBoolean(R.styleable.CameraView_cameraPlaySounds, DEFAULT_PLAY_SOUNDS); |
|
|
|
|
|
|
|
|
|
// Camera controller params
|
|
|
|
|
Facing facing = Facing.fromValue(a.getInteger(R.styleable.CameraView_cameraFacing, Facing.DEFAULT.value())); |
|
|
|
@ -130,6 +133,7 @@ public class CameraView extends FrameLayout { |
|
|
|
|
// Apply self managed
|
|
|
|
|
setCropOutput(cropOutput); |
|
|
|
|
setJpegQuality(jpegQuality); |
|
|
|
|
setPlaySounds(playSounds); |
|
|
|
|
|
|
|
|
|
// Apply camera controller params
|
|
|
|
|
setFacing(facing); |
|
|
|
@ -1083,8 +1087,8 @@ public class CameraView extends FrameLayout { |
|
|
|
|
* @see #captureSnapshot() |
|
|
|
|
*/ |
|
|
|
|
public void capturePicture() { |
|
|
|
|
if (mCameraController.capturePicture() && mUseSounds) { |
|
|
|
|
// TODO: sound
|
|
|
|
|
if (mCameraController.capturePicture() && mPlaySounds) { |
|
|
|
|
// TODO: playSound on Camera2
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1100,9 +1104,9 @@ public class CameraView extends FrameLayout { |
|
|
|
|
* @see #capturePicture() |
|
|
|
|
*/ |
|
|
|
|
public void captureSnapshot() { |
|
|
|
|
if (mCameraController.captureSnapshot() && mUseSounds) { |
|
|
|
|
if (mCameraController.captureSnapshot() && mPlaySounds) { |
|
|
|
|
//noinspection all
|
|
|
|
|
sound(MediaActionSound.SHUTTER_CLICK); |
|
|
|
|
playSound(MediaActionSound.SHUTTER_CLICK); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1243,19 +1247,42 @@ public class CameraView extends FrameLayout { |
|
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
|
|
//region Callbacks and dispatching
|
|
|
|
|
|
|
|
|
|
private MediaActionSound mSound; |
|
|
|
|
private final boolean mUseSounds = Build.VERSION.SDK_INT >= 16; |
|
|
|
|
//region Sounds
|
|
|
|
|
|
|
|
|
|
@SuppressLint("NewApi") |
|
|
|
|
private void sound(int soundType) { |
|
|
|
|
if (mUseSounds) { |
|
|
|
|
private void playSound(int soundType) { |
|
|
|
|
if (mPlaySounds) { |
|
|
|
|
if (mSound == null) mSound = new MediaActionSound(); |
|
|
|
|
mSound.play(soundType); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Controls whether CameraView should play sound effects on certain |
|
|
|
|
* events (picture taken, focus complete). Note that: |
|
|
|
|
* - On API level < 16, this flag is always false |
|
|
|
|
* - Camera1 will always play the shutter sound when taking pictures |
|
|
|
|
* |
|
|
|
|
* @param playSounds whether to play sound effects |
|
|
|
|
*/ |
|
|
|
|
public void setPlaySounds(boolean playSounds) { |
|
|
|
|
mPlaySounds = playSounds && Build.VERSION.SDK_INT >= 16; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets the current sound effect behavior. |
|
|
|
|
* |
|
|
|
|
* @see #setPlaySounds(boolean) |
|
|
|
|
* @return whether sound effects are supported |
|
|
|
|
*/ |
|
|
|
|
public boolean getPlaySounds() { |
|
|
|
|
return mPlaySounds; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
|
|
//region Callbacks and dispatching
|
|
|
|
|
|
|
|
|
|
interface CameraCallbacks extends OrientationHelper.Callbacks { |
|
|
|
|
void dispatchOnCameraOpened(CameraOptions options); |
|
|
|
|
void dispatchOnCameraClosed(); |
|
|
|
@ -1436,9 +1463,9 @@ public class CameraView extends FrameLayout { |
|
|
|
|
mUiHandler.post(new Runnable() { |
|
|
|
|
@Override |
|
|
|
|
public void run() { |
|
|
|
|
if (success && mUseSounds) { |
|
|
|
|
if (success && mPlaySounds) { |
|
|
|
|
//noinspection all
|
|
|
|
|
sound(MediaActionSound.FOCUS_COMPLETE); |
|
|
|
|
playSound(MediaActionSound.FOCUS_COMPLETE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (gesture != null && mGestureMap.get(gesture) == GestureAction.FOCUS_WITH_MARKER) { |
|
|
|
|