You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 14, 2018. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 14, 2018. It is now read-only.
If Camera 1 extension methods are accepted, I'd like to propose some.
This for Camera parameter modification idiom :
fun Camera.setParameters(setAction: (Camera.Parameters) -> Unit) {
val params = parameters
setAction(params)
parameters = params
}
This for opening Front / Back cameras :
enum class FACING {
FRONT, BACK
}
fun openCamera(facing: FACING): Camera = Camera.open(getCameraId(facing))
private fun getCameraId(facing: CameraExtensions.FACING): Int {
val info = Camera.CameraInfo()
val numCameras = Camera.getNumberOfCameras()
val direction =
when (facing) {
FACING.FRONT -> Camera.CameraInfo.CAMERA_FACING_FRONT
FACING.BACK -> Camera.CameraInfo.CAMERA_FACING_BACK
}
for (i in 0 until numCameras) {
Camera.getCameraInfo(i, info)
if (info.facing == direction) {
return i
}
}
throw RuntimeException("No matching camera for $facing")
}
Activity
jaredsburrows commentedon Mar 2, 2018
Make a PR + tests. See example tests here: https://android.googlesource.com/platform/cts/+/4338156/tests/tests/hardware/src/android/hardware/cts/CameraTest.java.
minsik-ai commentedon Mar 2, 2018
@jaredsburrows Thank you for the link. I'll look at it & file a PR soon.
romainguy commentedon Mar 2, 2018
These kind of APIs go beyond the scope of android-ktx extensions and belong to a dedicated library. Thank you for the suggestion though!
jaredsburrows commentedon Mar 2, 2018
@romainguy Maybe
androidx.core:camera-ktx?