|
|
|
@ -50,11 +50,11 @@ import com.otaliastudios.cameraview.controls.Mode; |
|
|
|
|
import com.otaliastudios.cameraview.controls.Preview; |
|
|
|
|
import com.otaliastudios.cameraview.controls.VideoCodec; |
|
|
|
|
import com.otaliastudios.cameraview.controls.WhiteBalance; |
|
|
|
|
import com.otaliastudios.cameraview.gesture.GestureLayout; |
|
|
|
|
import com.otaliastudios.cameraview.gesture.GestureFinder; |
|
|
|
|
import com.otaliastudios.cameraview.gesture.GestureParser; |
|
|
|
|
import com.otaliastudios.cameraview.gesture.PinchGestureLayout; |
|
|
|
|
import com.otaliastudios.cameraview.gesture.ScrollGestureLayout; |
|
|
|
|
import com.otaliastudios.cameraview.gesture.TapGestureLayout; |
|
|
|
|
import com.otaliastudios.cameraview.gesture.PinchGestureFinder; |
|
|
|
|
import com.otaliastudios.cameraview.gesture.ScrollGestureFinder; |
|
|
|
|
import com.otaliastudios.cameraview.gesture.TapGestureFinder; |
|
|
|
|
import com.otaliastudios.cameraview.internal.GridLinesLayout; |
|
|
|
|
import com.otaliastudios.cameraview.internal.utils.CropHelper; |
|
|
|
|
import com.otaliastudios.cameraview.internal.utils.OrientationHelper; |
|
|
|
@ -115,11 +115,13 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
@VisibleForTesting List<FrameProcessor> mFrameProcessors = new CopyOnWriteArrayList<>(); |
|
|
|
|
private Lifecycle mLifecycle; |
|
|
|
|
|
|
|
|
|
// Gestures
|
|
|
|
|
@VisibleForTesting PinchGestureFinder mPinchGestureFinder; |
|
|
|
|
@VisibleForTesting TapGestureFinder mTapGestureFinder; |
|
|
|
|
@VisibleForTesting ScrollGestureFinder mScrollGestureFinder; |
|
|
|
|
|
|
|
|
|
// Views
|
|
|
|
|
GridLinesLayout mGridLinesLayout; |
|
|
|
|
PinchGestureLayout mPinchGestureLayout; |
|
|
|
|
TapGestureLayout mTapGestureLayout; |
|
|
|
|
ScrollGestureLayout mScrollGestureLayout; |
|
|
|
|
MarkerLayout mMarkerLayout; |
|
|
|
|
private boolean mKeepScreenOn; |
|
|
|
|
@SuppressWarnings({"FieldCanBeLocal", "unused"}) |
|
|
|
@ -173,16 +175,15 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
mUiHandler = new Handler(Looper.getMainLooper()); |
|
|
|
|
mFrameProcessorsHandler = WorkerHandler.get("FrameProcessorsWorker"); |
|
|
|
|
|
|
|
|
|
// Gestures
|
|
|
|
|
mPinchGestureFinder = new PinchGestureFinder(mCameraCallbacks); |
|
|
|
|
mTapGestureFinder = new TapGestureFinder(mCameraCallbacks); |
|
|
|
|
mScrollGestureFinder = new ScrollGestureFinder(mCameraCallbacks); |
|
|
|
|
|
|
|
|
|
// Views
|
|
|
|
|
mGridLinesLayout = new GridLinesLayout(context); |
|
|
|
|
mPinchGestureLayout = new PinchGestureLayout(context); |
|
|
|
|
mTapGestureLayout = new TapGestureLayout(context); |
|
|
|
|
mScrollGestureLayout = new ScrollGestureLayout(context); |
|
|
|
|
mMarkerLayout = new MarkerLayout(context); |
|
|
|
|
addView(mGridLinesLayout); |
|
|
|
|
addView(mPinchGestureLayout); |
|
|
|
|
addView(mTapGestureLayout); |
|
|
|
|
addView(mScrollGestureLayout); |
|
|
|
|
addView(mMarkerLayout); |
|
|
|
|
|
|
|
|
|
// Create the engine
|
|
|
|
@ -225,6 +226,26 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Engine is instantiated on creation and anytime |
|
|
|
|
* {@link #setEngine(Engine)} is called. |
|
|
|
|
*/ |
|
|
|
|
private void doInstantiateEngine() { |
|
|
|
|
mCameraEngine = instantiateCameraEngine(mEngine, mCameraCallbacks); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Preview is instantiated {@link #onAttachedToWindow()}, because |
|
|
|
|
* we want to know if we're hardware accelerated or not. |
|
|
|
|
* However, in tests, we might want to create the preview right after constructor. |
|
|
|
|
*/ |
|
|
|
|
@VisibleForTesting |
|
|
|
|
void doInstantiatePreview() { |
|
|
|
|
mCameraPreview = instantiatePreview(mPreview, getContext(), this); |
|
|
|
|
mCameraEngine.setPreview(mCameraPreview); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Instantiates the camera engine. |
|
|
|
|
* |
|
|
|
@ -269,16 +290,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@VisibleForTesting |
|
|
|
|
void doInstantiatePreview() { |
|
|
|
|
mCameraPreview = instantiatePreview(mPreview, getContext(), this); |
|
|
|
|
mCameraEngine.setPreview(mCameraPreview); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void doInstantiateEngine() { |
|
|
|
|
mCameraEngine = instantiateCameraEngine(mEngine, mCameraCallbacks); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onAttachedToWindow() { |
|
|
|
|
super.onAttachedToWindow(); |
|
|
|
@ -474,19 +485,19 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
mGestureMap.put(gesture, action); |
|
|
|
|
switch (gesture) { |
|
|
|
|
case PINCH: |
|
|
|
|
mPinchGestureLayout.setActive(mGestureMap.get(Gesture.PINCH) != none); |
|
|
|
|
mPinchGestureFinder.setActive(mGestureMap.get(Gesture.PINCH) != none); |
|
|
|
|
break; |
|
|
|
|
case TAP: |
|
|
|
|
// case DOUBLE_TAP:
|
|
|
|
|
case LONG_TAP: |
|
|
|
|
mTapGestureLayout.setActive( |
|
|
|
|
mTapGestureFinder.setActive( |
|
|
|
|
mGestureMap.get(Gesture.TAP) != none || |
|
|
|
|
// mGestureMap.get(Gesture.DOUBLE_TAP) != none ||
|
|
|
|
|
mGestureMap.get(Gesture.LONG_TAP) != none); |
|
|
|
|
break; |
|
|
|
|
case SCROLL_HORIZONTAL: |
|
|
|
|
case SCROLL_VERTICAL: |
|
|
|
|
mScrollGestureLayout.setActive( |
|
|
|
|
mScrollGestureFinder.setActive( |
|
|
|
|
mGestureMap.get(Gesture.SCROLL_HORIZONTAL) != none || |
|
|
|
|
mGestureMap.get(Gesture.SCROLL_VERTICAL) != none); |
|
|
|
|
break; |
|
|
|
@ -534,15 +545,15 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
// Pass to our own GestureLayouts
|
|
|
|
|
CameraOptions options = mCameraEngine.getCameraOptions(); // Non null
|
|
|
|
|
if (options == null) throw new IllegalStateException("Options should not be null here."); |
|
|
|
|
if (mPinchGestureLayout.onTouchEvent(event)) { |
|
|
|
|
if (mPinchGestureFinder.onTouchEvent(event)) { |
|
|
|
|
LOG.i("onTouchEvent", "pinch!"); |
|
|
|
|
onGesture(mPinchGestureLayout, options); |
|
|
|
|
} else if (mScrollGestureLayout.onTouchEvent(event)) { |
|
|
|
|
onGesture(mPinchGestureFinder, options); |
|
|
|
|
} else if (mScrollGestureFinder.onTouchEvent(event)) { |
|
|
|
|
LOG.i("onTouchEvent", "scroll!"); |
|
|
|
|
onGesture(mScrollGestureLayout, options); |
|
|
|
|
} else if (mTapGestureLayout.onTouchEvent(event)) { |
|
|
|
|
onGesture(mScrollGestureFinder, options); |
|
|
|
|
} else if (mTapGestureFinder.onTouchEvent(event)) { |
|
|
|
|
LOG.i("onTouchEvent", "tap!"); |
|
|
|
|
onGesture(mTapGestureLayout, options); |
|
|
|
|
onGesture(mTapGestureFinder, options); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -551,7 +562,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
// Some gesture layout detected a gesture. It's not known at this moment:
|
|
|
|
|
// (1) if it was mapped to some action (we check here)
|
|
|
|
|
// (2) if it's supported by the camera (CameraEngine checks)
|
|
|
|
|
private void onGesture(GestureLayout source, @NonNull CameraOptions options) { |
|
|
|
|
private void onGesture(GestureFinder source, @NonNull CameraOptions options) { |
|
|
|
|
Gesture gesture = source.getGesture(); |
|
|
|
|
GestureAction action = mGestureMap.get(gesture); |
|
|
|
|
PointF[] points = source.getPoints(); |
|
|
|
@ -1732,7 +1743,10 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
//region Callbacks and dispatching
|
|
|
|
|
|
|
|
|
|
@VisibleForTesting |
|
|
|
|
class CameraCallbacks implements CameraEngine.Callback, OrientationHelper.Callback { |
|
|
|
|
class CameraCallbacks implements |
|
|
|
|
CameraEngine.Callback, |
|
|
|
|
OrientationHelper.Callback, |
|
|
|
|
GestureFinder.Controller { |
|
|
|
|
|
|
|
|
|
private CameraLogger mLogger = CameraLogger.create(CameraCallbacks.class.getSimpleName()); |
|
|
|
|
|
|
|
|
@ -1742,6 +1756,16 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
return CameraView.this.getContext(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getWidth() { |
|
|
|
|
return CameraView.this.getWidth(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getHeight() { |
|
|
|
|
return CameraView.this.getHeight(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void dispatchOnCameraOpened(final CameraOptions options) { |
|
|
|
|
mLogger.i("dispatchOnCameraOpened", options); |
|
|
|
@ -1786,7 +1810,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
@Override |
|
|
|
|
public void onShutter(boolean shouldPlaySound) { |
|
|
|
|
if (shouldPlaySound && mPlaySounds) { |
|
|
|
|
//noinspection all
|
|
|
|
|
playSound(MediaActionSound.SHUTTER_CLICK); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1847,7 +1870,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
@Override |
|
|
|
|
public void run() { |
|
|
|
|
if (success && mPlaySounds) { |
|
|
|
|
//noinspection all
|
|
|
|
|
playSound(MediaActionSound.FOCUS_COMPLETE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|