Class CameraManager
- java.lang.Object
-
- com.journeyapps.barcodescanner.camera.CameraManager
-
public final class CameraManager extends Object
Wrapper to manage the Camera. This is not thread-safe, and the methods must always be called from the same thread. Call order: 1. setCameraSettings() 2. open(), set desired preview size (any order) 3. configure(), setPreviewDisplay(holder) (any order) 4. startPreview() 5. requestPreviewFrame (repeat) 6. stopPreview() 7. close()
-
-
Constructor Summary
Constructors Constructor Description CameraManager(Context context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchangeCameraParameters(CameraParametersCallback callback)Changes the settings for Camera.voidclose()Closes the camera driver if still in use.voidconfigure()Configure the camera parameters, including preview size.CameragetCamera()Returns the Camera.intgetCameraRotation()CameraSettingsgetCameraSettings()DisplayConfigurationgetDisplayConfiguration()SizegetNaturalPreviewSize()Actual preview size in *natural camera* orientation.SizegetPreviewSize()Actual preview size in *current display* rotation.booleanisCameraRotated()booleanisOpen()This returns false if the camera is not opened yet, failed to open, or has been closed.booleanisTorchOn()voidopen()Must be called from camera thread.voidrequestPreviewFrame(PreviewCallback callback)A single preview frame will be returned to the supplied callback.voidsetCameraSettings(CameraSettings settings)voidsetDisplayConfiguration(DisplayConfiguration displayConfiguration)voidsetPreviewDisplay(SurfaceHolder holder)Must be called from camera thread.voidsetPreviewDisplay(CameraSurface surface)voidsetTorch(boolean on)voidstartPreview()Asks the camera hardware to begin drawing preview frames to the screen.voidstopPreview()Tells the camera to stop drawing preview frames.
-
-
-
Constructor Detail
-
CameraManager
public CameraManager(Context context)
-
-
Method Detail
-
open
public void open()
Must be called from camera thread.
-
configure
public void configure()
Configure the camera parameters, including preview size. The camera must be opened before calling this. Must be called from camera thread.
-
setPreviewDisplay
public void setPreviewDisplay(SurfaceHolder holder) throws IOException
Must be called from camera thread.- Throws:
IOException
-
setPreviewDisplay
public void setPreviewDisplay(CameraSurface surface) throws IOException
- Throws:
IOException
-
startPreview
public void startPreview()
Asks the camera hardware to begin drawing preview frames to the screen. Must be called from camera thread.
-
stopPreview
public void stopPreview()
Tells the camera to stop drawing preview frames. Must be called from camera thread.
-
close
public void close()
Closes the camera driver if still in use. Must be called from camera thread.
-
isCameraRotated
public boolean isCameraRotated()
- Returns:
- true if the camera rotation is perpendicular to the current display rotation.
-
getCameraRotation
public int getCameraRotation()
- Returns:
- the camera rotation relative to display rotation, in degrees. Typically 0 if the display is in landscape orientation.
-
isOpen
public boolean isOpen()
This returns false if the camera is not opened yet, failed to open, or has been closed.
-
getNaturalPreviewSize
public Size getNaturalPreviewSize()
Actual preview size in *natural camera* orientation. null if not determined yet.- Returns:
- preview size
-
getPreviewSize
public Size getPreviewSize()
Actual preview size in *current display* rotation. null if not determined yet.- Returns:
- preview size
-
requestPreviewFrame
public void requestPreviewFrame(PreviewCallback callback)
A single preview frame will be returned to the supplied callback. The thread on which this called is undefined, so a Handler should be used to post the result to the correct thread.- Parameters:
callback- The callback to receive the preview.
-
getCameraSettings
public CameraSettings getCameraSettings()
-
setCameraSettings
public void setCameraSettings(CameraSettings settings)
-
getDisplayConfiguration
public DisplayConfiguration getDisplayConfiguration()
-
setDisplayConfiguration
public void setDisplayConfiguration(DisplayConfiguration displayConfiguration)
-
setTorch
public void setTorch(boolean on)
-
changeCameraParameters
public void changeCameraParameters(CameraParametersCallback callback)
Changes the settings for Camera.- Parameters:
callback-CameraParametersCallback
-
isTorchOn
public boolean isTorchOn()
- Returns:
- true if the torch is on
- Throws:
RuntimeException- if there is a camera error
-
getCamera
public Camera getCamera()
Returns the Camera. This returns null if the camera is not opened yet, failed to open, or has been closed.- Returns:
- the Camera
-
-