cameraViewEx / com.priyankvasa.android.cameraviewex / CameraView

CameraView

class CameraView

Constructors

<init>

CameraView(context: <ERROR CLASS>, attrs: <ERROR CLASS>? = null, defStyleAttr: Int = 0)

Properties

adjustViewBounds

var adjustViewBounds: Boolean

True when this CameraView is adjusting its bounds to preserve the aspect ratio of camera.

aspectRatio

var aspectRatio: AspectRatio

Set aspect ratio of camera. Valid format is "height:width" eg. "4:3".

autoFocus

var autoFocus: Int

Set auto focus mode for selected camera. Supported modes are Modes.AutoFocus. See android.hardware.camera2.CaptureRequest.CONTROL_AF_MODE

awb

var awb: Int

Set auto white balance mode for preview and still captures. Supported values are Modes.AutoWhiteBalance. See android.hardware.camera2.CaptureRequest.CONTROL_AWB_MODE

currentDigitalZoom

var currentDigitalZoom: Float

Set digital zoom value. Must be between 1.0f and maxDigitalZoom inclusive.

facing

var facing: Int

Set which camera to use (like front or back). Supported values are Modes.Facing.

flash

var flash: Int

Set flash mode. Supported values are Modes.Flash. See android.hardware.camera2.CaptureRequest.FLASH_MODE

isActive

val isActive: Boolean

Returns true if this CameraView instance is active and usable. It will return false after destroy is called. A new instance should be created if isActive is false.

isCameraOpened

val isCameraOpened: Boolean

true if the camera is opened false otherwise.

isContinuousFrameModeEnabled

val isContinuousFrameModeEnabled: Boolean

Check if Modes.CameraMode.CONTINUOUS_FRAME is enabled

isSingleCaptureModeEnabled

val isSingleCaptureModeEnabled: Boolean

Check if Modes.CameraMode.SINGLE_CAPTURE is enabled

isVideoCaptureModeEnabled

val isVideoCaptureModeEnabled: Boolean

Check if Modes.CameraMode.VIDEO_CAPTURE is enabled

isVideoRecording

val isVideoRecording: Boolean

true if there is a video recording in progress, false otherwise.

jpegQuality

var jpegQuality: Int

Set image quality of the output image. This property is only applicable for outputFormat Supported values are Modes.JpegQuality.

maxDigitalZoom

val maxDigitalZoom: Float

Maximum digital zoom supported by selected camera device.

noiseReduction

var noiseReduction: Int

Set noise reduction mode. Supported values are Modes.NoiseReduction. See android.hardware.camera2.CaptureRequest.NOISE_REDUCTION_MODE

opticalStabilization

var opticalStabilization: Boolean

Turn on or off optical stabilization for preview and still captures. See android.hardware.camera2.CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE

outputFormat

var outputFormat: Int

Set format of the output of image data produced from the camera for Modes.CameraMode.SINGLE_CAPTURE mode. Supported values are Modes.OutputFormat.

pinchToZoom

var pinchToZoom: Boolean

Allow pinch gesture on camera view for digital zooming. True is on and false is off.

shutter

var shutter: Int

Current shutter time in milliseconds. Supported values are Modes.Shutter.

supportedAspectRatios

val supportedAspectRatios: Set<AspectRatio>

Gets all the aspect ratios supported by the current camera.

touchToFocus

var touchToFocus: Boolean

Allow manual focus on an area by tapping on camera view. True is on and false is off.

zsl

var zsl: Boolean

Set zero shutter lag mode capture. See android.hardware.camera2.CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG

Functions

addCameraClosedListener

fun addCameraClosedListener(listener: () -> Unit): CameraView

Add a new camera closed listener.

addCameraErrorListener

fun addCameraErrorListener(listener: (t: Throwable, errorLevel: ErrorLevel) -> Unit): CameraView
fun addCameraErrorListener(listener: (t: Throwable, <ERROR CLASS>) -> Unit): CameraView

Add a new camera error listener. If no error listeners are added, then "critical" errors will be thrown to system exception handler (ie. hard crash) The only critical error thrown for now is for invalid aspect ratio.

addCameraOpenedListener

fun addCameraOpenedListener(listener: () -> Unit): CameraView

Add a new camera opened listener.

addPictureTakenListener

fun addPictureTakenListener(listener: (imageData: ByteArray) -> Unit): CameraView

Add a new picture taken listener.

addVideoRecordStartedListener

fun addVideoRecordStartedListener(listener: () -> Unit): CameraView

Add a new video record started listener.

addVideoRecordStoppedListener

fun addVideoRecordStoppedListener(listener: (isSuccess: Boolean) -> Unit): CameraView

Add a new video record stopped listener.

capture

fun capture(): Unit

Take a picture. The result will be returned to listeners added by addPictureTakenListener.

destroy

fun destroy(): Unit

Clear all listeners, stop camera, and kill background threads. Once destroy is called, camera cannot be started. A new CameraView instance must be created to use camera again. This is typically called from fragment's onDestroyView callback.

onAttachedToWindow

fun onAttachedToWindow(): Unit

onDetachedFromWindow

fun onDetachedFromWindow(): Unit

onMeasure

fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit

onRestoreInstanceState

fun onRestoreInstanceState(state: <ERROR CLASS>?): Unit

onSaveInstanceState

fun onSaveInstanceState(): <ERROR CLASS>?

pauseVideoRecording

fun pauseVideoRecording(): Boolean

Pause video recording

removeAllListeners

fun removeAllListeners(): Unit

Remove all listeners previously set.

removeCameraClosedListener

fun removeCameraClosedListener(listener: () -> Unit): CameraView

Remove camera closed listener.

removeCameraErrorListener

fun removeCameraErrorListener(listener: (Throwable, ErrorLevel) -> Unit): CameraView
fun removeCameraErrorListener(listener: (Throwable, <ERROR CLASS>) -> Unit): CameraView

Remove camera error listener.

removeCameraOpenedListener

fun removeCameraOpenedListener(listener: () -> Unit): CameraView

Remove camera opened listener.

removePictureTakenListener

fun removePictureTakenListener(listener: (ByteArray) -> Unit): CameraView

Remove picture taken listener.

removePreviewFrameListener

fun removePreviewFrameListener(): CameraView

Remove preview frame listener.

removeVideoRecordStartedListener

fun removeVideoRecordStartedListener(listener: () -> Unit): CameraView

Remove video record started listener.

removeVideoRecordStoppedListener

fun removeVideoRecordStoppedListener(listener: (isSuccess: Boolean) -> Unit): CameraView

Remove video record stopped listener.

resumeVideoRecording

fun resumeVideoRecording(): Boolean

Resume video recording

setCameraMode

fun setCameraMode(mode: Int): Unit

Set camera mode of operation. Supported values are Modes.CameraMode.

setPreviewFrameListener

fun setPreviewFrameListener(listener: (<ERROR CLASS>) -> Unit): CameraView

Set preview frame listener. Be careful while using this listener as it is invoked on each frame, which could be 60 times per second if frame rate is 60 fps. Ideally, next frame should only be processed once current frame is done processing. Continuously launching background tasks for each frame is is not memory efficient, the device will run out of memory very quickly and force close the app.

start

fun start(): Unit

Open a camera device and start showing camera preview. This is typically called from Activity.onResume.

startVideoRecording

fun startVideoRecording(outputFile: File, videoConfig: VideoConfiguration.() -> Unit = {}): Unit
fun startVideoRecording(outputFile: File, videoConfig: <ERROR CLASS>.() -> Unit = {}): Unit

Start capturing video.

stop

fun stop(): Unit

Stop camera preview and close the device. This is typically called from fragment's onPause callback.

stopVideoRecording

fun stopVideoRecording(): Boolean

Stop video recording