public class

CameraHelper

extends Object
java.lang.Object
   ↳ com.hvt.horizonSDK.CameraHelper

Class Overview

A helper class that provides with useful information about the device's cameras and their capabilities.

The class has many methods to return compatible photo and video resolutions. The easiest to use is getDefaultVideoAndPhotoSize(int, boolean).

Note: All methods may return null or an empty List.

The methods that return compatible video sizes may return sizes that are smaller than the ones returned by getSupportedVideoSizes(). This is because HVTCamera uses the preview frames to process them at real time. CameraHelper reads the supported preview sizes instead.

Summary

Public Constructors
CameraHelper(File cacheFile)
Creates a CameraHelper instance that can be used to get information about the device cameras.
Public Methods
Camera.Parameters getCameraParameters(int cameraFacing)
Returns the camera parameters of the camera having the provided cameraFacing.
Size[] getDefaultVideoAndPhotoSize(int cameraFacing)
Returns the highest supported video and photo size for the camera having the provided cameraFacing.
static Size[] getDefaultVideoAndPhotoSize(Camera.Parameters params, boolean priorityPhoto)
Returns the highest supported video and photo size.
Size[] getDefaultVideoAndPhotoSize(int cameraFacing, boolean priorityPhoto)
Returns the highest supported video and photo size for the camera having the provided cameraFacing.
int getNumberOfCameras()
Returns the number of physical cameras available on this device.
static List<Size> getPhotoSizesForVideoSize(Camera.Parameters params, Size videoSize)
Returns a list of the supported photo sizes having the same aspect ratio as the provided videoSize.
List<Size> getPhotoSizesForVideoSize(int cameraFacing, Size videoSize)
Returns a list of the supported photo sizes having the same aspect ratio as the provided video size, for the camera having the provided cameraFacing.
List<String> getSupportedFlashModes(int cameraFacing)
Returns the supported flash modes for the camera having the provided cameraFacing.
static List<String> getSupportedFlashModes(Camera.Parameters params)
Returns the supported flash modes.
List<Size> getSupportedPhotoSizes(int cameraFacing)
Returns a list with the supported photo sizes of the camera having the provided cameraFacing.
static List<Size> getSupportedPhotoSizes(Camera.Parameters params)
Returns a list with the supported photo sizes.
List<Size> getSupportedVideoSize(int cameraFacing)
Returns a list with the supported video sizes of the camera having the provided cameraFacing.
static List<Size> getSupportedVideoSizes(Camera.Parameters params)
Returns a list with the supported video sizes.
List<Size> getVideoSizesForPhotoSize(int cameraFacing, Size photoSize)
Returns a list of the supported video sizes having the same aspect ratio as the provided photoSize, for the camera having the provided cameraFacing.
static List<Size> getVideoSizesForPhotoSize(Camera.Parameters params, Size photoSize)
Returns a list of the supported video sizes having the same aspect ratio as the provided photoSize.
boolean hasCamera(int cameraFacing)
Returns if the device has a camera with the provided cameraFacing.
void printCameraParameters()
Prints the details of all cameras in the device.
void printCameraParameters(int facing)
Prints the details of the camera having the specified facing.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public CameraHelper (File cacheFile)

Creates a CameraHelper instance that can be used to get information about the device cameras.

By default, the instance opens the device cameras to retrieve the camera information. If it fails to access the cameras, an IOException is thrown. If a cacheFile is provided, the instance writes all the camera information to the file. If a new instance is created in the future, it will use the provided cacheFile to get the information, without accessing the device cameras.

Note:If targetSdkVersion is 23 or above, you need to request permission at runtime, before calling this method.

Parameters
cacheFile a file to write or read the camera information. If the file does not exist, the instance will create it and populate it with camera information.
Throws
IOException an exception is thrown if the instance needs to access the device cameras but fails to do so

Public Methods

public Camera.Parameters getCameraParameters (int cameraFacing)

Returns the camera parameters of the camera having the provided cameraFacing.

Parameters
cameraFacing the facing of the camera. Can be CAMERA_FACING_BACK or CAMERA_FACING_FRONT
Returns
  • the camera parameters

public Size[] getDefaultVideoAndPhotoSize (int cameraFacing)

Returns the highest supported video and photo size for the camera having the provided cameraFacing.

Both sizes will have the same aspect ratio.

Priority will be given to video.

Parameters
cameraFacing the facing of the camera. Can be CAMERA_FACING_BACK or CAMERA_FACING_FRONT
Returns
  • an array containing the following elements: video size, photo size

public static Size[] getDefaultVideoAndPhotoSize (Camera.Parameters params, boolean priorityPhoto)

Returns the highest supported video and photo size.

Both sizes will have the same aspect ratio.

If priorityPhoto is true, the highest photo size will be selected and the highest compatible video size will be found. If false, the highest video size will be selected and the highest compatible photo size will be found.

Parameters
params the camera's parameters
priorityPhoto true for photo priority, false for video priority
Returns
  • an array containing the following elements: video size, photo size

public Size[] getDefaultVideoAndPhotoSize (int cameraFacing, boolean priorityPhoto)

Returns the highest supported video and photo size for the camera having the provided cameraFacing.

Both sizes will have the same aspect ratio.

If priorityPhoto is true, the highest photo size will be selected and the highest compatible video size will be found. If false, the highest video size will be selected and the highest compatible photo size will be found.

Parameters
cameraFacing the facing of the camera. Can be CAMERA_FACING_BACK or CAMERA_FACING_FRONT
priorityPhoto true for photo priority, false for video priority
Returns
  • an array containing the following elements: video size, photo size

public int getNumberOfCameras ()

Returns the number of physical cameras available on this device.

public static List<Size> getPhotoSizesForVideoSize (Camera.Parameters params, Size videoSize)

Returns a list of the supported photo sizes having the same aspect ratio as the provided videoSize.

Parameters
params the camera's parameters
videoSize the video size
Returns
  • a descending list of photo sizes

public List<Size> getPhotoSizesForVideoSize (int cameraFacing, Size videoSize)

Returns a list of the supported photo sizes having the same aspect ratio as the provided video size, for the camera having the provided cameraFacing.

Parameters
cameraFacing the facing of the camera. Can be CAMERA_FACING_BACK or CAMERA_FACING_FRONT
videoSize the video size
Returns
  • a descending list of photo sizes

public List<String> getSupportedFlashModes (int cameraFacing)

Returns the supported flash modes for the camera having the provided cameraFacing.

Parameters
cameraFacing the facing of the camera. Can be CAMERA_FACING_BACK or CAMERA_FACING_FRONT
Returns
See Also

public static List<String> getSupportedFlashModes (Camera.Parameters params)

Returns the supported flash modes.

Parameters
params the camera's parameters
Returns
See Also

public List<Size> getSupportedPhotoSizes (int cameraFacing)

Returns a list with the supported photo sizes of the camera having the provided cameraFacing.

Parameters
cameraFacing the facing of the camera. Can be CAMERA_FACING_BACK or CAMERA_FACING_FRONT
Returns
  • a descending list of photo sizes

public static List<Size> getSupportedPhotoSizes (Camera.Parameters params)

Returns a list with the supported photo sizes.

Parameters
params the camera's parameters
Returns
  • a descending list of photo sizes

public List<Size> getSupportedVideoSize (int cameraFacing)

Returns a list with the supported video sizes of the camera having the provided cameraFacing.

Parameters
cameraFacing the facing of the camera. Can be CAMERA_FACING_BACK or CAMERA_FACING_FRONT
Returns
  • a descending list of video sizes

public static List<Size> getSupportedVideoSizes (Camera.Parameters params)

Returns a list with the supported video sizes.

Parameters
params the camera's parameters
Returns
  • a descending list of video sizes

public List<Size> getVideoSizesForPhotoSize (int cameraFacing, Size photoSize)

Returns a list of the supported video sizes having the same aspect ratio as the provided photoSize, for the camera having the provided cameraFacing.

Parameters
cameraFacing the facing of the camera. Can be CAMERA_FACING_BACK or CAMERA_FACING_FRONT
photoSize the photo size
Returns
  • a descending list of video sizes

public static List<Size> getVideoSizesForPhotoSize (Camera.Parameters params, Size photoSize)

Returns a list of the supported video sizes having the same aspect ratio as the provided photoSize.

Parameters
params the camera's parameters
photoSize the photo size
Returns
  • a descending list of video sizes

public boolean hasCamera (int cameraFacing)

Returns if the device has a camera with the provided cameraFacing.

Parameters
cameraFacing the facing of the camera. Can be CAMERA_FACING_BACK or CAMERA_FACING_FRONT

public void printCameraParameters ()

Prints the details of all cameras in the device.

public void printCameraParameters (int facing)

Prints the details of the camera having the specified facing.

Note: The facing of the camera is required, not the camera id.

Parameters
facing the facing of the camera. Can be CAMERA_FACING_BACK or CAMERA_FACING_FRONT