mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-17 03:40:38 +01:00
add a helper function for getting the camer amanager
This commit is contained in:
parent
b25beb3a34
commit
bf314ecf22
@ -122,12 +122,11 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
|||||||
|
|
||||||
private fun openCamera(width: Int, height: Int) {
|
private fun openCamera(width: Int, height: Int) {
|
||||||
setupCameraOutputs(width, height)
|
setupCameraOutputs(width, height)
|
||||||
val manager = mActivity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
|
||||||
try {
|
try {
|
||||||
if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
|
if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
|
||||||
throw RuntimeException("Time out waiting to lock camera opening.")
|
throw RuntimeException("Time out waiting to lock camera opening.")
|
||||||
}
|
}
|
||||||
manager.openCamera(mCameraId, cameraStateCallback, mBackgroundHandler)
|
getCameraManager().openCamera(mCameraId, cameraStateCallback, mBackgroundHandler)
|
||||||
} catch (e: InterruptedException) {
|
} catch (e: InterruptedException) {
|
||||||
} catch (e: SecurityException) {
|
} catch (e: SecurityException) {
|
||||||
}
|
}
|
||||||
@ -156,14 +155,13 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getIsUsingFrontCamera(): Boolean {
|
private fun getIsUsingFrontCamera(): Boolean {
|
||||||
val manager = mActivity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
val characteristics = getCameraManager().getCameraCharacteristics(mCameraId)
|
||||||
val characteristics = manager.getCameraCharacteristics(mCameraId)
|
|
||||||
val facing = characteristics.get(CameraCharacteristics.LENS_FACING)
|
val facing = characteristics.get(CameraCharacteristics.LENS_FACING)
|
||||||
return facing == CameraCharacteristics.LENS_FACING_FRONT
|
return facing == CameraCharacteristics.LENS_FACING_FRONT
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupCameraOutputs(width: Int, height: Int) {
|
private fun setupCameraOutputs(width: Int, height: Int) {
|
||||||
val manager = mActivity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
val manager = getCameraManager()
|
||||||
try {
|
try {
|
||||||
for (cameraId in manager.cameraIdList) {
|
for (cameraId in manager.cameraIdList) {
|
||||||
val characteristics = manager.getCameraCharacteristics(cameraId)
|
val characteristics = manager.getCameraCharacteristics(cameraId)
|
||||||
@ -381,8 +379,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
|||||||
private fun focusArea() {
|
private fun focusArea() {
|
||||||
mActivity.drawFocusCircle(mLastClickX, mLastClickY)
|
mActivity.drawFocusCircle(mLastClickX, mLastClickY)
|
||||||
|
|
||||||
val manager = mActivity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
val characteristics = getCameraManager().getCameraCharacteristics(mCameraId)
|
||||||
val characteristics = manager.getCameraCharacteristics(mCameraId)
|
|
||||||
val sensorArraySize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE)
|
val sensorArraySize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE)
|
||||||
|
|
||||||
val captureCallbackHandler = object : CameraCaptureSession.CaptureCallback() {
|
val captureCallbackHandler = object : CameraCaptureSession.CaptureCallback() {
|
||||||
@ -444,6 +441,8 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getCameraManager() = mActivity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
||||||
|
|
||||||
private fun takePicture() {
|
private fun takePicture() {
|
||||||
lockFocus()
|
lockFocus()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user