Class ScanbotCameraView
-
- All Implemented Interfaces:
-
android.graphics.drawable.Drawable.Callback
,android.view.KeyEvent.Callback
,android.view.ViewManager
,android.view.ViewParent
,android.view.accessibility.AccessibilityEventSource
,io.scanbot.sdk.ui.camera.IScanbotCameraView
,io.scanbot.sdk.ui.camera.UiZoomDelegate
,io.scanbot.sdk.ui.camera.util.FinderViewAttributeHandler
public final class ScanbotCameraView extends FrameLayout implements IScanbotCameraView, UiZoomDelegate, FinderViewAttributeHandler
Provides interface to native Camera and displays camera stream. Use this class if you want to fine-tune camera behavior.
It is required to pass android.app.Activity (or android.app.Fragment) lifecycle events to this view: .onResume, .onPause. They are used to automatically start and stop camera.
It is possible to include other views inside of ScanbotCameraView. In such case they will be drawn on top of camera preview with size matching the camera frame. You can use this fact to draw overlays on top of camera.
Preview frames are provided via PreviewBuffer: .getPreviewBuffer.
-
-
Field Summary
Fields Modifier and Type Field Description private Long
delayAfterFocusCompleteMs
private final PreviewBuffer
previewBuffer
private final List<Camera.Size>
supportedPictureSizes
private final List<Camera.Size>
supportedPreviewSizes
-
Constructor Summary
Constructors Constructor Description ScanbotCameraView(Context context)
ScanbotCameraView(Context context, AttributeSet attrs)
-
Method Summary
Modifier and Type Method Description Long
getDelayAfterFocusCompleteMs()
Delay that camera will took before snap on auto focus complete called from camera core in ms. Unit
setDelayAfterFocusCompleteMs(Long delayAfterFocusCompleteMs)
Delay that camera will took before snap on auto focus complete called from camera core in ms. final PreviewBuffer
getPreviewBuffer()
final List<Camera.Size>
getSupportedPictureSizes()
final List<Camera.Size>
getSupportedPreviewSizes()
final Unit
onResume()
Notifies view that enclosing android.app.Activity or android.app.Fragment was resumed and therefore camera can be started. final Unit
onPause()
Notifies view that enclosing android.app.Activity or android.app.Fragment was paused and therefore camera must be closed. Unit
startPreview()
Starts/resumes camera preview stream. Unit
stopPreview()
Stops camera preview stream. Unit
restartPreview()
Restarts preview stream. Unit
lockMinFocusDistance(Boolean lock)
Locks the min supported focus distance and disables continuous focus Unit
setForceMaxSnappingSize(Boolean enabled)
Set whether camera should force maximum possible size of snapped picture or use maximum size that available with the same aspect ratio as preview by default set to false
This parameter works only withScanbotCameraXView
enabledUnit
setForceMaxSnappingQuality(Boolean enabled)
Set whether camera should force maximum possible quality of snapped picture. Unit
setSnappingAutoAdjustment(Boolean enabled)
Set whether camera should automatically adjusts the final image with the surrounding scenery. Unit
takePicture(Boolean acquireFocus)
Takes picture. Unit
takePicture(Boolean acquireFocus, Boolean isCapturedAutomatically)
Takes picture. Unit
useFlash(Boolean useFlash)
Enables or disables camera flash. Unit
setAutoFocusOnTouch(Boolean autoFocusOnTouch)
Unit
autoFocus()
Performs auto-focus. Unit
continuousFocus()
Cancels auto-focus and performs continuous-focus. Unit
addPictureCallback(BasePictureCallback pictureCallback)
Adds callback which will be notified when picture will be taken. Unit
removePictureCallback(BasePictureCallback pictureCallback)
Removes callback, so it won't receive any further notifications. Unit
addCameraStateCallback(CameraStateCallback cameraStateCallback)
Adds callback which will be notified about camera state changes. Unit
setCaptureCallback(CaptureCallback captureCallback)
Sets the callback which will be notified about the moment of actual image capture. Unit
removeCameraStateCallback(CameraStateCallback cameraStateCallback)
Removes callback, so it won't receive any further notifications. Unit
addTakePictureCallback(CameraTakePictureCallback cameraTakePictureCallback)
Adds callback which will be notified about take picture operation process. Unit
removeTakePictureCallback(CameraTakePictureCallback cameraTakePictureCallback)
Removes callback, so it won't receive any further notifications. Unit
setCameraOpenCallback(CameraOpenCallback cameraOpenCallback)
Callback which will be invoked when camera will be opened final Unit
setPictureSize(Camera.Size pictureSize)
Set camera picture size final Unit
setPreviewSize(Camera.Size previewSize)
Set camera preview size final Unit
setAutoFocusSound(Boolean enabled)
Set camera auto focus sound state. Unit
setShutterSound(Boolean enabled)
Set camera shutter sound state. Unit
setPreviewMode(CameraPreviewMode mode)
Set the camera preview mode. Unit
lockToPortrait(Boolean lockPicture)
Locks camera in portrait mode Unit
lockToLandscape(Boolean lockPicture)
Locks camera in landscape mode Unit
unlockOrientation()
Unlocks camera orientation Unit
usePinchToZoom(Boolean usePinchToZoom)
Enables/disables Pinch-to-Zoom camera functionality Unit
setPhysicalZoomRange(ZoomRange zoomRange)
Set custom zoom range. Unit
setUiZoomLevel(Float zoomLevel)
Passes the zoom value to the dependent view Unit
setPhysicalZoom(Float zoomLevel)
Allows to set camera physical zoom value, if the value out of range of real camera min and max values it chooses min or max value. Unit
setCameraModule(CameraModule cameraModule)
Defines a camera module. Boolean
isFlashEnabled()
Returns the current state of the flashlight Should be executed from the main thread and when camera is opened <T extends FrameHandler> T
getAttachedFrameHandler(Class<T> clazz)
Check whether there is same class of FrameHandler attached to the view return object of the same class if exists otherwise null Unit
addFrameHandler(FrameHandler frameHandler)
Used to add frame handler that will be called on each next frame Unit
removeFrameHandler(FrameHandler frameHandler)
Unregisters FrameHandler. -
-
Constructor Detail
-
ScanbotCameraView
ScanbotCameraView(Context context)
-
ScanbotCameraView
ScanbotCameraView(Context context, AttributeSet attrs)
-
-
Method Detail
-
getDelayAfterFocusCompleteMs
Long getDelayAfterFocusCompleteMs()
Delay that camera will took before snap on auto focus complete called from camera core in ms. For some devices this callback could call even before real auto focus completed, so we need to take some delay before snapping. Usually you can set 500ms. By default it is set to 20ms.
-
setDelayAfterFocusCompleteMs
Unit setDelayAfterFocusCompleteMs(Long delayAfterFocusCompleteMs)
Delay that camera will took before snap on auto focus complete called from camera core in ms. For some devices this callback could call even before real auto focus completed, so we need to take some delay before snapping. Usually you can set 500ms. By default it is set to 20ms.
-
getPreviewBuffer
final PreviewBuffer getPreviewBuffer()
-
getSupportedPictureSizes
final List<Camera.Size> getSupportedPictureSizes()
-
getSupportedPreviewSizes
final List<Camera.Size> getSupportedPreviewSizes()
-
onResume
final Unit onResume()
Notifies view that enclosing android.app.Activity or android.app.Fragment was resumed and therefore camera can be started.
-
onPause
final Unit onPause()
Notifies view that enclosing android.app.Activity or android.app.Fragment was paused and therefore camera must be closed.
-
startPreview
@Synchronized() Unit startPreview()
Starts/resumes camera preview stream. Usually used after picture was taken. Note, the preview is started by default after .onResume, so there is no need to call it at the start of the app.
If view is paused, this call is ignored.
-
stopPreview
@Synchronized() Unit stopPreview()
Stops camera preview stream.
-
restartPreview
Unit restartPreview()
Restarts preview stream.
-
lockMinFocusDistance
Unit lockMinFocusDistance(Boolean lock)
Locks the min supported focus distance and disables continuous focus
- Parameters:
lock
- iftrue
minimal available focus distance will be locked,false
- otherwise Default isfalse
.
-
setForceMaxSnappingSize
Unit setForceMaxSnappingSize(Boolean enabled)
Set whether camera should force maximum possible size of snapped picture or use maximum size that available with the same aspect ratio as preview by default set to
false
This parameter works only withScanbotCameraXView
enabled
-
setForceMaxSnappingQuality
Unit setForceMaxSnappingQuality(Boolean enabled)
Set whether camera should force maximum possible quality of snapped picture. As a result snapping speed could be significantly slower and result image could be bigger. By default set to
false
This parameter works only withScanbotCameraXView
enabled
-
setSnappingAutoAdjustment
Unit setSnappingAutoAdjustment(Boolean enabled)
Set whether camera should automatically adjusts the final image with the surrounding scenery. For example, the vendor library implementation might do low-light detection and switch to low-light mode or HDR to take the picture. Alternatively, the face retouch mode could be automatically applied when taking a portrait image. This delegates modes to the vendor library implementation to decide.
-
takePicture
Unit takePicture(Boolean acquireFocus)
Takes picture.
This is asynchronous process, so results are reported via PictureCallback added in addPictureCallback. If snapping process is still going all subsequent calls to takePicture are ignored.
After picture is taken, camera preview is stopped. If you wish it continue, use startPreview If view is paused, this call is ignored.
- Parameters:
acquireFocus
- true to perform auto-focus before shooting.
-
takePicture
@Synchronized() Unit takePicture(Boolean acquireFocus, Boolean isCapturedAutomatically)
Takes picture.
This is asynchronous process, so results are reported via PictureCallback added in addPictureCallback. If snapping process is still going all subsequent calls to takePicture are ignored.
After picture is taken, camera preview is stopped. If you wish it continue, use startPreview If view is paused, this call is ignored.
- Parameters:
acquireFocus
-true
to perform auto-focus before shooting.isCapturedAutomatically
- allows to define if the picture was taken automatically by any of AutoSnappingController.
-
useFlash
Unit useFlash(Boolean useFlash)
Enables or disables camera flash.
If there is no flash on this device, does nothing.
If view is paused, this call is ignored.
- Parameters:
useFlash
-true
to enable flash.
-
setAutoFocusOnTouch
Unit setAutoFocusOnTouch(Boolean autoFocusOnTouch)
- Parameters:
autoFocusOnTouch
- iftrue
- auto focus on touch will be enabled,false
- otherwise.
-
autoFocus
Unit autoFocus()
Performs auto-focus.
If there is no auto-focus capabilities on this device, does nothing.
If view is paused, this call is ignored.
-
continuousFocus
Unit continuousFocus()
Cancels auto-focus and performs continuous-focus. Should be executed from the main thread and when camera is opened
If there is no continuous-focus capabilities on this device, does auto-focus.
If view is paused, this call is ignored.
-
addPictureCallback
Unit addPictureCallback(BasePictureCallback pictureCallback)
Adds callback which will be notified when picture will be taken. Callbacks are invoked on a worker thread, so you can safely perform "heavy" operations here.
- Parameters:
pictureCallback
- callback to register.
-
removePictureCallback
Unit removePictureCallback(BasePictureCallback pictureCallback)
Removes callback, so it won't receive any further notifications.
- Parameters:
pictureCallback
- callback to unregister.
-
addCameraStateCallback
Unit addCameraStateCallback(CameraStateCallback cameraStateCallback)
Adds callback which will be notified about camera state changes. Callbacks are invoked on a main thread.
- Parameters:
cameraStateCallback
- callback to register.
-
setCaptureCallback
Unit setCaptureCallback(CaptureCallback captureCallback)
Sets the callback which will be notified about the moment of actual image capture.
- Parameters:
captureCallback
- callback to register
-
removeCameraStateCallback
Unit removeCameraStateCallback(CameraStateCallback cameraStateCallback)
Removes callback, so it won't receive any further notifications.
- Parameters:
cameraStateCallback
- callback to unregister.
-
addTakePictureCallback
Unit addTakePictureCallback(CameraTakePictureCallback cameraTakePictureCallback)
Adds callback which will be notified about take picture operation process. Callbacks are invoked on a main thread.
- Parameters:
cameraTakePictureCallback
- callback to register.
-
removeTakePictureCallback
Unit removeTakePictureCallback(CameraTakePictureCallback cameraTakePictureCallback)
Removes callback, so it won't receive any further notifications.
- Parameters:
cameraTakePictureCallback
- callback to unregister.
-
setCameraOpenCallback
Unit setCameraOpenCallback(CameraOpenCallback cameraOpenCallback)
Callback which will be invoked when camera will be opened
- Parameters:
cameraOpenCallback
- callback
-
setPictureSize
final Unit setPictureSize(Camera.Size pictureSize)
Set camera picture size
-
setPreviewSize
final Unit setPreviewSize(Camera.Size previewSize)
Set camera preview size
-
setAutoFocusSound
final Unit setAutoFocusSound(Boolean enabled)
Set camera auto focus sound state.
true
if system sound should be played on successful auto focus event,false
- otherwise. By default, the camera plays the system-defined camera auto focus sound when autoFocus() is called.
-
setShutterSound
Unit setShutterSound(Boolean enabled)
Set camera shutter sound state.
true
if system sound should be played on the take picture event,false
- otherwise. By default, the camera plays the system-defined camera shutter sound when takePicture() is called.Note that devices may not always allow disabling the camera shutter sound. If the shutter sound state cannot be set to the desired value, this method will be ignored.
-
setPreviewMode
Unit setPreviewMode(CameraPreviewMode mode)
Set the camera preview mode. By default - CameraPreviewMode.FILL_IN.
- Parameters:
mode
-camera preview mode
-
lockToPortrait
Unit lockToPortrait(Boolean lockPicture)
Locks camera in portrait mode
- Parameters:
lockPicture
- iftrue
- taken picture will ba locked to the portrait orientation,false
- picture orientation depends on the device sensor.
-
lockToLandscape
Unit lockToLandscape(Boolean lockPicture)
Locks camera in landscape mode
- Parameters:
lockPicture
- iftrue
- taken picture will ba locked to the landscape orientation,false
- picture orientation depends on the device sensor.
-
unlockOrientation
Unit unlockOrientation()
Unlocks camera orientation
-
usePinchToZoom
Unit usePinchToZoom(Boolean usePinchToZoom)
Enables/disables Pinch-to-Zoom camera functionality
- Parameters:
usePinchToZoom
-true
if Pinch-to-Zoom should be enabled,false
- otherwise
-
setPhysicalZoomRange
Unit setPhysicalZoomRange(ZoomRange zoomRange)
Set custom zoom range. Default value is ZoomRange(0.5f, 100f).
- Parameters:
zoomRange
- Target zoom range
-
setUiZoomLevel
Unit setUiZoomLevel(Float zoomLevel)
Passes the zoom value to the dependent view
- Parameters:
zoomLevel
- the new scale of the UI
-
setPhysicalZoom
Unit setPhysicalZoom(Float zoomLevel)
Allows to set camera physical zoom value, if the value out of range of real camera min and max values it chooses min or max value. Example: camera physical zoom range 1f..5f if we set 6f it will set 5f. Default value is 1f.
- Parameters:
zoomLevel
- Target zoom level
-
setCameraModule
Unit setCameraModule(CameraModule cameraModule)
Defines a camera module. By default is CameraModule.BACK.
- Parameters:
cameraModule
- CameraModule to use.
-
isFlashEnabled
Boolean isFlashEnabled()
Returns the current state of the flashlight Should be executed from the main thread and when camera is opened
-
getAttachedFrameHandler
<T extends FrameHandler> T getAttachedFrameHandler(Class<T> clazz)
Check whether there is same class of FrameHandler attached to the view return object of the same class if exists otherwise null
-
addFrameHandler
Unit addFrameHandler(FrameHandler frameHandler)
Used to add frame handler that will be called on each next frame
-
removeFrameHandler
Unit removeFrameHandler(FrameHandler frameHandler)
Unregisters FrameHandler.
- Parameters:
frameHandler
- handler to unregister.
-
-
-
-