CameraView
public
final
class
CameraView
extends FrameLayout
java.lang.Object | ||||
↳ | android.view.View | |||
↳ | android.view.ViewGroup | |||
↳ | android.widget.FrameLayout | |||
↳ | androidx.camera.view.CameraView |
A View
that displays a preview of the camera with methods takePicture(Executor, OnImageCapturedCallback)
,
takePicture(ImageCapture.OutputFileOptions, Executor, OnImageSavedCallback)
,
startRecording(File, Executor, OnVideoSavedCallback)
and stopRecording()
.
Because the Camera is a limited resource and consumes a high amount of power, CameraView must
be opened/closed. CameraView will handle opening/closing automatically through use of a LifecycleOwner
. Use bindToLifecycle(LifecycleOwner)
to start the camera.
Summary
Nested classes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
enum |
CameraView.CaptureMode
The capture mode used by CameraView. |
Inherited constants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.ViewGroup
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
android.view.View
|
Inherited fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.View
|
Public constructors | |
---|---|
CameraView(Context context)
|
|
CameraView(Context context, AttributeSet attrs)
|
|
CameraView(Context context, AttributeSet attrs, int defStyle)
|
|
CameraView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
|
Public methods | |
---|---|
void
|
bindToLifecycle(LifecycleOwner lifecycleOwner)
Binds control of the camera used by this view to the given lifecycle. |
void
|
enableTorch(boolean torch)
Turns on/off torch. |
Integer
|
getCameraLensFacing()
Returns the currently selected lensFacing. |
CameraView.CaptureMode
|
getCaptureMode()
Returns the scale type used to scale the preview. |
int
|
getFlash()
Gets the active flash strategy. |
float
|
getMaxZoomRatio()
Returns the maximum zoom ratio. |
float
|
getMinZoomRatio()
Returns the minimum zoom ratio. |
LiveData<PreviewView.StreamState>
|
getPreviewStreamState()
Gets the |
PreviewView.ScaleType
|
getScaleType()
Returns the scale type used to scale the preview. |
float
|
getZoomRatio()
Returns the current zoom ratio. |
boolean
|
hasCameraWithLensFacing(int lensFacing)
Queries whether the current device has a camera with the specified direction. |
boolean
|
isPinchToZoomEnabled()
Returns whether the view allows pinch-to-zoom. |
boolean
|
isRecording()
|
boolean
|
isTorchOn()
Returns current torch status. |
boolean
|
isZoomSupported()
Returns whether the bound camera supports zooming. |
boolean
|
onTouchEvent(MotionEvent event)
|
boolean
|
performClick()
Focus the position of the touch event, or focus the center of the preview for accessibility events |
void
|
setCameraLensFacing(Integer lensFacing)
Sets the desired camera by specifying desired lensFacing. |
void
|
setCaptureMode(CameraView.CaptureMode captureMode)
Sets the CameraView capture mode This controls only image or video capture function is enabled or both are enabled. |
void
|
setFlash(int flashMode)
Sets the active flash strategy. |
void
|
setPinchToZoomEnabled(boolean enabled)
Sets whether the view should allow pinch-to-zoom. |
void
|
setScaleType(PreviewView.ScaleType scaleType)
Sets the view finder scale type. |
void
|
setZoomRatio(float zoomRatio)
Sets the current zoom ratio. |
void
|
startRecording(OutputFileOptions outputFileOptions, Executor executor, OnVideoSavedCallback callback)
Takes a video and calls the OnVideoSavedCallback when done. |
void
|
startRecording(File file, Executor executor, OnVideoSavedCallback callback)
Takes a video and calls the OnVideoSavedCallback when done. |
void
|
startRecording(ParcelFileDescriptor fd, Executor executor, OnVideoSavedCallback callback)
Takes a video and calls the OnVideoSavedCallback when done. |
void
|
stopRecording()
Stops an in progress video. |
void
|
takePicture(ImageCapture.OutputFileOptions outputFileOptions, Executor executor, ImageCapture.OnImageSavedCallback callback)
Takes a picture and calls
|
void
|
takePicture(Executor executor, ImageCapture.OnImageCapturedCallback callback)
Takes a picture, and calls |
void
|
toggleCamera()
Toggles between the primary front facing camera and the primary back facing camera. |
Protected methods | |
---|---|
FrameLayout.LayoutParams
|
generateDefaultLayoutParams()
|
void
|
onAttachedToWindow()
|
void
|
onDetachedFromWindow()
|
void
|
onLayout(boolean changed, int left, int top, int right, int bottom)
|
void
|
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
void
|
onRestoreInstanceState(Parcelable savedState)
|
Parcelable
|
onSaveInstanceState()
|
Inherited methods | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.widget.FrameLayout
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
android.view.ViewGroup
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
android.view.View
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
java.lang.Object
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From interface
android.view.ViewParent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From interface
android.view.ViewManager
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From interface
android.graphics.drawable.Drawable.Callback
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From interface
android.view.KeyEvent.Callback
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From interface
android.view.accessibility.AccessibilityEventSource
|
Public constructors
CameraView
public CameraView (Context context, AttributeSet attrs)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
CameraView
public CameraView (Context context, AttributeSet attrs, int defStyle)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyle |
int |
CameraView
public CameraView (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
defStyleRes |
int |
Public methods
bindToLifecycle
public void bindToLifecycle (LifecycleOwner lifecycleOwner)
Binds control of the camera used by this view to the given lifecycle.
This links opening/closing the camera to the given lifecycle. The camera will not operate
unless this method is called with a valid LifecycleOwner
that is not in the Lifecycle.State.DESTROYED
state. Call this method only once camera
permissions have been obtained.
Once the provided lifecycle has transitioned to a Lifecycle.State.DESTROYED
state, CameraView must be bound to a new
lifecycle through this method in order to operate the camera.
Requires the CAMERA
permission.
Parameters | |
---|---|
lifecycleOwner |
LifecycleOwner : The lifecycle that will control this view's camera |
Throws | |
---|---|
IllegalArgumentException |
if provided lifecycle is in a Lifecycle.State.DESTROYED state. |
IllegalStateException |
if camera permissions are not granted. |
enableTorch
public void enableTorch (boolean torch)
Turns on/off torch.
Parameters | |
---|---|
torch |
boolean : True to turn on torch, false to turn off torch.
|
getCameraLensFacing
public Integer getCameraLensFacing ()
Returns the currently selected lensFacing.
Returns | |
---|---|
Integer |
getCaptureMode
public CameraView.CaptureMode getCaptureMode ()
Returns the scale type used to scale the preview.
Returns | |
---|---|
CameraView.CaptureMode |
The current CameraView.CaptureMode .
|
getFlash
public int getFlash ()
Gets the active flash strategy.
Returns | |
---|---|
int |
getMaxZoomRatio
public float getMaxZoomRatio ()
Returns the maximum zoom ratio.
The zoom ratio corresponds to the ratio between both the widths and heights of a non-zoomed image and a maximally zoomed image for the selected camera.
Returns | |
---|---|
float |
The maximum zoom ratio. |
getMinZoomRatio
public float getMinZoomRatio ()
Returns the minimum zoom ratio.
For most cameras this should return a zoom ratio of 1. A zoom ratio of 1 corresponds to a non-zoomed image.
Returns | |
---|---|
float |
The minimum zoom ratio. |
getPreviewStreamState
public LiveData<PreviewView.StreamState> getPreviewStreamState ()
Gets the LiveData
of the underlying PreviewView
's
PreviewView.StreamState
.
Returns | |
---|---|
LiveData<PreviewView.StreamState> |
A LiveData containing the PreviewView.StreamState . Apps can either
get current value by LiveData.getValue() or register a observer by
LiveData.observe(LifecycleOwner, Observer super T>) . |
See also:
getScaleType
public PreviewView.ScaleType getScaleType ()
Returns the scale type used to scale the preview.
Returns | |
---|---|
PreviewView.ScaleType |
The current PreviewView.ScaleType .
|
getZoomRatio
public float getZoomRatio ()
Returns the current zoom ratio.
Returns | |
---|---|
float |
The current zoom ratio. |
hasCameraWithLensFacing
public boolean hasCameraWithLensFacing (int lensFacing)
Queries whether the current device has a camera with the specified direction.
Requires the CAMERA
permission.
Parameters | |
---|---|
lensFacing |
int |
Returns | |
---|---|
boolean |
True if the device supports the direction. |
Throws | |
---|---|
IllegalStateException |
if the CAMERA permission is not currently granted. |
isPinchToZoomEnabled
public boolean isPinchToZoomEnabled ()
Returns whether the view allows pinch-to-zoom.
Returns | |
---|---|
boolean |
True if pinch to zoom is enabled. |
isRecording
public boolean isRecording ()
Returns | |
---|---|
boolean |
True if currently recording. |
isTorchOn
public boolean isTorchOn ()
Returns current torch status.
Returns | |
---|---|
boolean |
true if torch is on , otherwise false |
isZoomSupported
public boolean isZoomSupported ()
Returns whether the bound camera supports zooming.
Returns | |
---|---|
boolean |
True if the camera supports zooming. |
onTouchEvent
public boolean onTouchEvent (MotionEvent event)
Parameters | |
---|---|
event |
MotionEvent |
Returns | |
---|---|
boolean |
performClick
public boolean performClick ()
Focus the position of the touch event, or focus the center of the preview for accessibility events
Returns | |
---|---|
boolean |
setCameraLensFacing
public void setCameraLensFacing (Integer lensFacing)
Sets the desired camera by specifying desired lensFacing.
This will choose the primary camera with the specified camera lensFacing.
If called before bindToLifecycle(LifecycleOwner)
, this will set the camera to be
used when first bound to the lifecycle. If the specified lensFacing is not supported by the
device, as determined by hasCameraWithLensFacing(int)
, the first supported
lensFacing will be chosen when bindToLifecycle(LifecycleOwner)
is called.
If called with null
AFTER binding to the lifecycle, the behavior would be
equivalent to unbind the use cases without the lifecycle having to be destroyed.
Parameters | |
---|---|
lensFacing |
Integer : The desired camera lensFacing.
|
setCaptureMode
public void setCaptureMode (CameraView.CaptureMode captureMode)
Sets the CameraView capture mode
This controls only image or video capture function is enabled or both are enabled.
Parameters | |
---|---|
captureMode |
CameraView.CaptureMode : The desired CameraView.CaptureMode .
|
setFlash
public void setFlash (int flashMode)
Sets the active flash strategy.
Parameters | |
---|---|
flashMode |
int |
setPinchToZoomEnabled
public void setPinchToZoomEnabled (boolean enabled)
Sets whether the view should allow pinch-to-zoom.
When enabled, the user can pinch the camera to zoom in/out. This only has an effect if the bound camera supports zoom.
Parameters | |
---|---|
enabled |
boolean : True to enable pinch-to-zoom.
|
setScaleType
public void setScaleType (PreviewView.ScaleType scaleType)
Sets the view finder scale type.
This controls how the view finder should be scaled and positioned within the view.
Parameters | |
---|---|
scaleType |
PreviewView.ScaleType : The desired PreviewView.ScaleType .
|
setZoomRatio
public void setZoomRatio (float zoomRatio)
Sets the current zoom ratio.
Valid zoom values range from getMinZoomRatio()
to getMaxZoomRatio()
.
Parameters | |
---|---|
zoomRatio |
float : The requested zoom ratio.
|
startRecording
public void startRecording (OutputFileOptions outputFileOptions, Executor executor, OnVideoSavedCallback callback)
Takes a video and calls the OnVideoSavedCallback when done.
Parameters | |
---|---|
outputFileOptions |
OutputFileOptions : Options to store the newly captured video. |
executor |
Executor : The executor in which the callback methods will be run. |
callback |
OnVideoSavedCallback : Callback which will receive success or failure.
|
startRecording
public void startRecording (File file, Executor executor, OnVideoSavedCallback callback)
Takes a video and calls the OnVideoSavedCallback when done.
Parameters | |
---|---|
file |
File : The destination. |
executor |
Executor : The executor in which the callback methods will be run. |
callback |
OnVideoSavedCallback : Callback which will receive success or failure.
|
startRecording
public void startRecording (ParcelFileDescriptor fd, Executor executor, OnVideoSavedCallback callback)
Takes a video and calls the OnVideoSavedCallback when done.
Parameters | |
---|---|
fd |
ParcelFileDescriptor : The destination ParcelFileDescriptor . |
executor |
Executor : The executor in which the callback methods will be run. |
callback |
OnVideoSavedCallback : Callback which will receive success or failure.
|
stopRecording
public void stopRecording ()
Stops an in progress video.
takePicture
public void takePicture (ImageCapture.OutputFileOptions outputFileOptions, Executor executor, ImageCapture.OnImageSavedCallback callback)
Takes a picture and calls
ImageCapture.OnImageSavedCallback.onImageSaved(ImageCapture.OutputFileResults)
when done.
The value of ImageCapture.Metadata.isReversedHorizontal()
in the
ImageCapture.OutputFileOptions
will be overwritten based on camera direction. For
front camera, it will be set to true; for back camera, it will be set to false.
Parameters | |
---|---|
outputFileOptions |
ImageCapture.OutputFileOptions : Options to store the newly captured image. |
executor |
Executor : The executor in which the callback methods will be run. |
callback |
ImageCapture.OnImageSavedCallback : Callback which will receive success or failure.
|
takePicture
public void takePicture (Executor executor, ImageCapture.OnImageCapturedCallback callback)
Takes a picture, and calls ImageCapture.OnImageCapturedCallback.onCaptureSuccess(ImageProxy)
once when done.
Parameters | |
---|---|
executor |
Executor : The executor in which the callback methods will be run. |
callback |
ImageCapture.OnImageCapturedCallback : Callback which will receive success or failure callbacks.
|
toggleCamera
public void toggleCamera ()
Toggles between the primary front facing camera and the primary back facing camera.
This will have no effect if not already bound to a lifecycle via bindToLifecycle(LifecycleOwner)
.