Class CameraView

  • All Implemented Interfaces:
    android.graphics.drawable.Drawable.Callback , android.view.KeyEvent.Callback , android.view.ViewManager , android.view.ViewParent , android.view.accessibility.AccessibilityEventSource , io.anyline2.camera.HighResolutionImageProvider , io.anyline2.image.ImageProvider , io.anyline2.image.NativeBarcodeProvider

    
    public class CameraView
    extends ViewGroup implements ImageProvider, NativeBarcodeProvider, HighResolutionImageProvider
                        
    • Method Detail

      • setPreferredPreviewSize

        @Deprecated() void setPreferredPreviewSize(int width, int height)

        Set the preferred preview size. If set, a preview size that fits in the given size will be used otherwise the views size is used to determine a fitting preview size. This must be set before the camera is initialized to have an effect.

        Parameters:
        width - the preferred width
        height - the preferred height
      • setPreferredPictureSize

        @Deprecated() void setPreferredPictureSize(int width, int height)

        Set the preferred picture size which is used when takeHighResolutionImage is called. If set, the supported picture size closest, and max the given size will be used. Otherwise the maximum supported size will be used. This must be set before the camera is initialized to have an effect.

        Parameters:
        width - the preferred picture width
        height - the preferred picture height
      • setSceneMode

        @Deprecated() void setSceneMode(String sceneMode)

        Set the scene mode that should be used if it is supported.

        This setting needs to be set before the camera is opened.

        This has no effect on Nexus 4 + 5, because the flash is not working if a scene mode is set on those devices.

        Parameters:
        sceneMode - the scene mode to use (one of: android.hardware.Camera.Parameters.
      • setUseMaxFpsRange

         void setUseMaxFpsRange(boolean isEnabled)

        Use maximum fps available or not. By enabling this mode, the camera tries to set the shutter speed as high as possible, and thus reducing motion blur and providing a more fluid look and feel.

        Generally, a high shutter speed leads to less camera sensor exposure, which means that the image may become darker and may need a flashlight, so that proper lighting conditions are met for the processing of the image.

        This setting needs to be set before the camera is opened.

        This setting is applied after the scene mode.

        Parameters:
        isEnabled - - true if high FPS mode should be enabled, false by default
      • setPreferredPreviewFps

         void setPreferredPreviewFps(int minFps, int maxFps)

        Set the proffered values for the minimum and maximum preview frames per second. This should usually NOT be used, but special values maybe required for certain hardware (like google glasses).

        This setting has higher priority then setUseMaxFpsRange.

        Parameters:
        minFps - the preferred min FPS
        maxFps - the preferred max FPS
      • setFocusConfig

        @Deprecated() void setFocusConfig(FocusConfig focusConfig)

        Set the focus config to use for focusing.

        This setting needs to be set before the camera is opened.

        Parameters:
        focusConfig - the focus config
      • getPreferredCameraConfig

         CameraConfig getPreferredCameraConfig()

        Get the current preferred camera settings.

        This can be used to change the preferred settings. Changes needs to be made before the camera is opened to have an effect.

        Returns:

        the preferred camera settings

      • setPreferredCameraConfig

         void setPreferredCameraConfig(CameraConfig preferredConfig)

        Set the preferred camera settings. The actual used settings will be composed of this and the available features.

        This needs to be set before the camera is opened.

        It is also possible to just manipulate the settings returned by getPreferredCameraConfig.

        Parameters:
        preferredConfig - the preferred settings
      • getSettings

         CameraConfig getSettings()

        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)

      • setCameraOpenListener

         void setCameraOpenListener(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
      • getScale

         float getScale()
        Returns:

        the scale that is applied to the actual image size in order to fit the view (e.g. will be 1.5 on fullscreen on a 1080p display with 720p preview)

      • getFrameWidth

         int getFrameWidth()
        Returns:

        the full width of the preview frame

      • getFrameHeight

         int getFrameHeight()
        Returns:

        the full height of the preview frame

      • callAutoFocus

         void callAutoFocus()

        Call auto focus. This will only do anything if the focus mode is set to auto. It usually should not be called manually. (is called through interval or through touch automatically if configured)

      • setFlashOn

         void setFlashOn(boolean isOn)

        Turn the torch flash on or off. Will only have an effect after the camera is opened.

        Parameters:
        isOn - true to turn the flash on false to turn it off
      • resetAutoFocusTimer

         void resetAutoFocusTimer()

        Reset the auto focus timer, if a focus config is set.

      • setImageListener

         void setImageListener(@Nullable() ImageListener imageListener)

        Set the listener that should be called when a new image is available

        Parameters:
        imageListener - the listener that should be notified if a new image is available
      • hasNewImage

         boolean hasNewImage()
        Returns:

        true if a new image is available in the buffer

      • takeHighResolutionImage

         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

         void takeHighResolutionImage(int top, int left, int right, int bottom, int scanViewWidth, int scanViewHeight)
      • openCameraInBackground

         boolean 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.

      • releaseCameraInBackground

         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!!