Class CameraController
-
- All Implemented Interfaces:
public abstract class CameraController
Class to abstract away camera api 1 and 2 differences.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enum
CameraController.CameraOrientation
Helper enum to be able to get the back camera orientation
public interface
CameraController.CameraControllerListener
-
Constructor Summary
Constructors Constructor Description CameraController()
-
Method Summary
Modifier and Type Method Description CameraConfig
getPreferredCameraConfig()
void
setPreferredCameraConfig(@NonNull() CameraConfig preferredCameraConfig)
Set the preferred camera settings. CameraConfig
getCameraConfig()
Get the actually used settings (this is only available after the camera has been opened). abstract boolean
hasNewImage()
abstract AnylineYuvImage
getNewImage()
abstract AnylineImage
getLastImageWithFullSize()
Get the latest image in full size. abstract ImageReceiver
getLastImageWithFullSizeReceiver()
Get the a receiver for the latest image in full size. abstract void
takeHighResolutionImage()
Takes a picture from the camera and calls onImageTaken after the image is taken successfully. abstract void
takeHighResolutionImage(int top, int left, int right, int bottom, int viewWidth, int viewHeight)
void
setHighResolutionImageListener(@Nullable() HighResolutionImageListener highResolutionImageListener)
Sets an optional listener which is called with the final AnylineImage, once a picture was taken with the camera via the takeHighResolutionImage method. void
setCameraOpenListener(@Nullable() CameraOpenListener listener)
Set the listener that is called when the camera is opened or a camera related error occurred. void
removeCameraOpenListener(CameraOpenListener listener)
void
removeAllCameraOpenListeners()
void
setImageListener(ImageListener imageListener)
Set the listener that should be called when a new image is available abstract void
setFlashOn(boolean isOn)
Turn the torch flash on or off. void
setZoomGestureEnabled(boolean isZoomEnabled)
Enable zoom for the camera Needs to be called before setupZoomHandler() abstract void
setupZoomHandler(View view)
Set up the zoom for the camera double
getFocalLength()
Get custom zoom level abstract void
setFocalLength(double focalLength)
Set a zoom level through focal length abstract void
setMaxFocalLength(double maxFocalLength)
Set a maximum focal length abstract void
setMaxZoomRatio(double maxZoomRatio)
Set a maximum zoom ratio abstract double
getZoomRatio()
Get the current zoom ratio abstract void
setZoomRatio(double zoomLevelRatio)
Set a zoom level through zoom Ratio abstract double
getCurrentFocalLength()
Get the current focal length abstract void
callAutoFocus()
Call auto focus. void
resetAutoFocusTimer()
Reset the auto focus timer, if a focus config is set. abstract void
releaseCamera()
Release the camera. abstract void
releaseCameraAndPreview()
Release the camera for the landscape to landscape mode. abstract void
openCameraInBackground()
Open the camera in a background thread, if surface is already created and camera is not opened already. abstract boolean
openCameraInBackgroundSuccessfully()
abstract void
releaseCameraInBackground()
Release the camera in a background thread. View
getPreviewView()
int
getFrameWidth()
int
getFrameHeight()
float
getFrameToViewScale()
float
getFrameToViewScaleWidth()
CameraFeatures
getCameraFeatures()
abstract void
setCameraOrientation(CameraController.CameraOrientation cameraOrientation)
Allows you to set the camera orientation for the BACK camera. abstract void
setFocusRegionToCutout(@NonNull() Context context, @NonNull() RectF cutOutRect, float surfaceWidth, float surfaceHeight)
Updates the focus and metering region to be the same as the given cutout. void
setCameraControllerListener(CameraController.CameraControllerListener cameraControllerListener)
-
-
Method Detail
-
getPreferredCameraConfig
@NonNull() CameraConfig getPreferredCameraConfig()
- Returns:
the preferred camera settings
-
setPreferredCameraConfig
void setPreferredCameraConfig(@NonNull() CameraConfig preferredCameraConfig)
Set the preferred camera settings. The actual used settings will be composed of this and the available features.
- Parameters:
preferredCameraConfig
- the preferred settings
-
getCameraConfig
@Nullable() CameraConfig getCameraConfig()
Get the actually used settings (this is only available after the camera has been opened).
This is for information purposes only (to see what settings are actually used). To change the settings use the getPreferredCameraConfig instead.
- Returns:
the actually used settings (or null if camera not yet opened)
-
hasNewImage
abstract boolean hasNewImage()
- Returns:
true if a new image is available in the buffer
-
getNewImage
@Nullable() abstract AnylineYuvImage getNewImage()
- Returns:
the next new image (sets hasNewImage to false until another image is available)
-
getLastImageWithFullSize
@Nullable() abstract AnylineImage getLastImageWithFullSize()
Get the latest image in full size. This does not check or manipulate hasNewImage.
Prefer getLastImageWithFullSizeReceiver, if you are not sure if the image is actually needed, to save resources.
- Returns:
the latest image in full size.
-
getLastImageWithFullSizeReceiver
@Nullable() abstract ImageReceiver getLastImageWithFullSizeReceiver()
Get the a receiver for the latest image in full size. This does not check or manipulate hasNewImage.
The receiver does not copy the image if no getter is called.
- Returns:
a receiver for the latest image in full size.
-
takeHighResolutionImage
abstract void takeHighResolutionImage()
Takes a picture from the camera and calls onImageTaken after the image is taken successfully. If no HighResolutionImageListener is set, the method returns. Additionally, a picture is only taken if the safeToTakePicture flag is set to true, which means the camera is open and preview is started.
-
takeHighResolutionImage
abstract void takeHighResolutionImage(int top, int left, int right, int bottom, int viewWidth, int viewHeight)
-
setHighResolutionImageListener
void setHighResolutionImageListener(@Nullable() HighResolutionImageListener highResolutionImageListener)
Sets an optional listener which is called with the final AnylineImage, once a picture was taken with the camera via the takeHighResolutionImage method.
- Parameters:
highResolutionImageListener
- the listener to call if a picture was taken (or an error occured)
-
setCameraOpenListener
void setCameraOpenListener(@Nullable() CameraOpenListener listener)
Set the listener that is called when the camera is opened or a camera related error occurred. If not set the opening of the camera will be logged and an error will be thrown as a RuntimeException.
- Parameters:
listener
- the listener
-
removeCameraOpenListener
void removeCameraOpenListener(CameraOpenListener listener)
-
removeAllCameraOpenListeners
void removeAllCameraOpenListeners()
-
setImageListener
void setImageListener(ImageListener imageListener)
Set the listener that should be called when a new image is available
- Parameters:
imageListener
- the listener that should be notified if an image is available
-
setFlashOn
abstract void setFlashOn(boolean isOn)
Turn the torch flash on or off.
- Parameters:
isOn
- true to turn the flash on false to turn it off
-
setZoomGestureEnabled
void setZoomGestureEnabled(boolean isZoomEnabled)
Enable zoom for the camera Needs to be called before setupZoomHandler()
-
setupZoomHandler
abstract void setupZoomHandler(View view)
Set up the zoom for the camera
-
getFocalLength
double getFocalLength()
Get custom zoom level
-
setFocalLength
abstract void setFocalLength(double focalLength)
Set a zoom level through focal length
-
setMaxFocalLength
abstract void setMaxFocalLength(double maxFocalLength)
Set a maximum focal length
-
setMaxZoomRatio
abstract void setMaxZoomRatio(double maxZoomRatio)
Set a maximum zoom ratio
-
getZoomRatio
abstract double getZoomRatio()
Get the current zoom ratio
-
setZoomRatio
abstract void setZoomRatio(double zoomLevelRatio)
Set a zoom level through zoom Ratio
-
getCurrentFocalLength
abstract double getCurrentFocalLength()
Get the current focal length
-
callAutoFocus
abstract void callAutoFocus()
Call auto focus.
-
resetAutoFocusTimer
void resetAutoFocusTimer()
Reset the auto focus timer, if a focus config is set.
-
releaseCamera
abstract void releaseCamera()
Release the camera.
ALWAYS call this or releaseCameraInBackground in onPause of your activity!!
-
releaseCameraAndPreview
abstract void releaseCameraAndPreview()
Release the camera for the landscape to landscape mode.
-
openCameraInBackground
abstract void openCameraInBackground()
Open the camera in a background thread, if surface is already created and camera is not opened already. Reports opening or error to the CameraOpenListener set with setCameraOpenListener.
-
openCameraInBackgroundSuccessfully
abstract boolean openCameraInBackgroundSuccessfully()
-
releaseCameraInBackground
abstract void releaseCameraInBackground()
Release the camera in a background thread. Camera releasing may take a bit, so it may interfere with your exit animation. Use this to do it in the background.
ALWAYS call this or releaseCamera in onPause of your activity!!
-
getPreviewView
View getPreviewView()
- Returns:
the view on which the preview is displayed
-
getFrameWidth
int getFrameWidth()
- Returns:
the width of the frames received (only available after the camera is opened)
-
getFrameHeight
int getFrameHeight()
- Returns:
the height of the frames received (only available after the camera is opened)
-
getFrameToViewScale
float getFrameToViewScale()
- Returns:
the scale, the ratio of the view size to the frame size (only available after the camera is opened)
-
getFrameToViewScaleWidth
float getFrameToViewScaleWidth()
-
getCameraFeatures
@Nullable() CameraFeatures getCameraFeatures()
- Returns:
the available camera features for the opened camera (will be null if no camera is open yet)
-
setCameraOrientation
abstract void setCameraOrientation(CameraController.CameraOrientation cameraOrientation)
Allows you to set the camera orientation for the BACK camera.
- Parameters:
cameraOrientation
- represents orientation type
-
setFocusRegionToCutout
abstract void setFocusRegionToCutout(@NonNull() Context context, @NonNull() RectF cutOutRect, float surfaceWidth, float surfaceHeight)
Updates the focus and metering region to be the same as the given cutout.
- Parameters:
context
- the contextcutOutRect
- the cutout rect relative to the surfacesurfaceWidth
- the width of the surfacesurfaceHeight
- the height of the surface
-
setCameraControllerListener
void setCameraControllerListener(CameraController.CameraControllerListener cameraControllerListener)
-
-
-
-