|
|
|
---
|
|
|
|
layout: page
|
|
|
|
title: "Gestures"
|
|
|
|
subtitle: "Gestures control"
|
|
|
|
category: docs
|
|
|
|
order: 4
|
|
|
|
date: 2018-12-20 20:49:35
|
|
|
|
disqus: 1
|
|
|
|
---
|
|
|
|
|
|
|
|
`CameraView` listen to lots of different gestures inside its bounds. You have the chance to map
|
|
|
|
these gestures to particular actions or camera controls, using the `mapGesture()` method.
|
|
|
|
This lets you emulate typical behaviors in a single line:
|
|
|
|
|
|
|
|
```java
|
|
|
|
cameraView.mapGesture(Gesture.PINCH, GestureAction.ZOOM); // Pinch to zoom!
|
|
|
|
cameraView.mapGesture(Gesture.TAP, GestureAction.FOCUS_WITH_MARKER); // Tap to focus!
|
|
|
|
cameraView.mapGesture(Gesture.LONG_TAP, GestureAction.CAPTURE); // Long tap to shoot!
|
|
|
|
```
|
|
|
|
|
|
|
|
Simple as that. There are two things to be noted:
|
|
|
|
|
|
|
|
- Not every mapping is valid. For example, you can't control zoom with long taps, or start focusing by pinching.
|
|
|
|
- Some actions might not be supported by the sensor. Check out `CameraOptions` to know what's legit and what's not.
|
|
|
|
|
|
|
|
|Gesture|Description|Can be mapped to|
|
|
|
|
|-------------|-----------|----------------|
|
|
|
|
|`PINCH`|Pinch gesture, typically assigned to the zoom control.|`zoom` `exposureCorrection` `none`|
|
|
|
|
|`TAP`|Single tap gesture, typically assigned to the focus control.|`focus` `focusWithMarker` `capture` `none`|
|
|
|
|
|`LONG_TAP`|Long tap gesture.|`focus` `focusWithMarker` `capture` `none`|
|
|
|
|
|`SCROLL_HORIZONTAL`|Horizontal movement gesture.|`zoom` `exposureCorrection` `none`|
|
|
|
|
|`SCROLL_VERTICAL`|Vertical movement gesture.|`zoom` `exposureCorrection` `none`|
|
|
|
|
|
|
|
|
### XML Attributes
|
|
|
|
|
|
|
|
```xml
|
|
|
|
<com.otaliastudios.cameraview.CameraView
|
|
|
|
app:cameraGesturePinch="zoom|exposureCorrection|none"
|
|
|
|
app:cameraGestureTap="focus|focusWithMarker|capture|none"
|
|
|
|
app:cameraGestureLongTap="focus|focusWithMarker|capture|none"
|
|
|
|
app:cameraGestureScrollHorizontal="zoom|exposureCorrection|none"
|
|
|
|
app:cameraGestureScrollVertical="zoom|exposureCorrection|none"/>
|
|
|
|
```
|
|
|
|
|
|
|
|
### Related APIs
|
|
|
|
|
|
|
|
|Method|Description|
|
|
|
|
|------|-----------|
|
|
|
|
|`mapGesture(Gesture, GestureAction)`|Maps a certain gesture to a certain action. No-op if the action is not supported.|
|
|
|
|
|`getGestureAction(Gesture)`|Returns the action currently mapped to the given gesture.|
|
|
|
|
|`clearGesture(Gesture)`|Clears any action mapped to the given gesture.|
|
|
|
|
|