Class 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 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.
      • 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.
      • setCameraSettings

        public void setCameraSettings​(CameraSettings settings)
      • setDisplayConfiguration

        public void setDisplayConfiguration​(DisplayConfiguration displayConfiguration)
      • setTorch

        public void setTorch​(boolean on)
      • 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