public class ScanbotCameraView 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 class 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 interface PreviewBuffer: .getPreviewBuffer.
public ScanbotCameraView(@NotNull
android.content.Context context,
@Nullable
android.util.AttributeSet attrs)
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 class 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 interface PreviewBuffer: .getPreviewBuffer.
public ScanbotCameraView(@NotNull
android.content.Context context)
public 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.
public void setDelayAfterFocusCompleteMs(long p)
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.
protected void onLayout(boolean changed,
int left,
int top,
int right,
int bottom)
@NotNull public PreviewBuffer getPreviewBuffer()
public void onResume()
Notifies view that enclosing android.app.Activity or android.app.Fragment was resumed and therefore camera can be started.
public void onPause()
Notifies view that enclosing android.app.Activity or android.app.Fragment was paused and therefore camera must be closed.
public void startPreview()
Starts/resumes camera preview stream. Usually used after picture was taken. Note, that 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.
public void stopPreview()
Stops camera preview stream.
public void takePicture(boolean acquireFocus)
Takes picture.
acquireFocus - {@code true} to perform auto-focus before shooting. {@code false} to shoot as fast as possible using current camera state.public void 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.
useFlash - true to enable flash. false to disable flash.public void setAutoFocusOnTouch(boolean autoFocusOnTouch)
autoFocusOnTouch - if true - auto focus on touch will be enabled, false - otherwise.By default this feature is enabled.public void autoFocus()
Performs auto-focus.
If there is no auto-focus capabilities on this device, does nothing.
If view is paused, this call is ignored.
public void 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.
public void addPictureCallback(@NotNull
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.
pictureCallback - callback to register. Must not be null. If this callbackwas already added, nothing happens.class PictureCallbackpublic void removePictureCallback(@NotNull
BasePictureCallback pictureCallback)
Removes callback, so it won't receive any further notifications.
pictureCallback - callback to unregister. If it was not registered before, nothinghappens.public void addCameraStateCallback(@NotNull
CameraStateCallback cameraStateCallback)
Adds callback which will be notified about camera state changes. Callbacks are invoked on a main thread.
cameraStateCallback - callback to register. Must not be null. If this callbackwas already added, nothing happens.public void removeCameraStateCallback(@NotNull
CameraStateCallback cameraStateCallback)
Removes callback, so it won't receive any further notifications.
cameraStateCallback - callback to unregister. If it was not registered before, nothinghappens.public void addTakePictureCallback(@NotNull
CameraTakePictureCallback cameraTakePictureCallback)
Adds callback which will be notified about take picture operation process. Callbacks are invoked on a main thread.
cameraTakePictureCallback - callback to register. Must not be null. If this callbackwas already added, nothing happens.public void removeTakePictureCallback(@NotNull
CameraTakePictureCallback cameraTakePictureCallback)
Removes callback, so it won't receive any further notifications.
cameraTakePictureCallback - callback to unregister. If it was not registered before, nothinghappens.public void setCameraOpenCallback(@NotNull
CameraOpenCallback cameraOpenCallback)
Callback which will be invoked when camera will be opened
cameraOpenCallback - callback@NotNull public java.util.List<android.hardware.Camera.Size> getSupportedPictureSizes()
@NotNull public java.util.List<android.hardware.Camera.Size> getSupportedPreviewSizes()
public void setPictureSize(@NotNull
android.hardware.Camera.Size pictureSize)
Set camera picture size
pictureSize - public void setPreviewSize(@NotNull
android.hardware.Camera.Size previewSize)
Set camera preview size
previewSize - public void 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.
enabled - @RequiresApi public void 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.
enabled - public void setPreviewMode(@NotNull
CameraPreviewMode mode)
Set the camera preview mode. By default - CameraPreviewMode.FILL_IN.
mode - camera preview mode
public void lockToPortrait(boolean lockPicture)
Locks camera in portrait mode
lockPicture - if true - taken picture will ba locked to the portrait orientation,false - picture orientation depends on the device sensor.public void lockToLandscape(boolean lockPicture)
Locks camera in landscape mode
lockPicture - if true - taken picture will ba locked to the landscape orientation,false - picture orientation depends on the device sensor.public void unlockOrientation()
Unlocks camera orientation
public void usePinchToZoom(boolean usePinchToZoom)
Enables/disables Pinch-to-Zoom camera functionality
usePinchToZoom - true if Pinch-to-Zoom should be enabled, false - otherwisepublic void setOpticalZoomLevel(float zoomLevel)
Sets current zoom by a linear zoom value ranging from 0f to 1.0f. Zoom Level 0f represents the minimum zoom while Zoom Level 1.0f represents the maximum zoom. Default value is 0f.
zoomLevel - Target zoom levelpublic void setOpticalZoomRange(@NotNull
ZoomRange zoomRange)
Set custom zoom range. Default value is ZoomRange0f,1f.
zoomRange - Target zoom rangepublic void setCameraModule(@NotNull
CameraModule cameraModule)
Defines a camera module. By default is CameraModule.BACK.
cameraModule - enum CameraModule to use.@Nullable public <T extends FrameHandler> T getAttachedFrameHandler(@NotNull java.lang.Class<T> clazz)
Check whether there is same class of interface FrameHandler attached to the view
return object of the same class if exists otherwise null
interface FrameHandler,
nullpublic void addFrameHandler(@NotNull
FrameHandler frameHandler)
Used to add frame handler that will be called on each next frame
public void removeFrameHandler(@NotNull
FrameHandler frameHandler)
Unregisters interface FrameHandler.
frameHandler - handler to unregister. If it was not registered before, nothing happens.interface FrameHandlerprotected void onDetachedFromWindow()
public void setUiZoomLevel(float zoomLevel)
Passes the zoom value to the dependent view
zoomLevel - the new scale of the UIpublic int getFinderViewId()
Default is R.id.finder_overlay