Camera1 and Camera2 API wrapper that exposes simple to use interface
GoldenEye
Camera1 and Camera2 API wrapper that exposes simple to use interface.
Quick guide
Add dependency
implementation 'co.infinum:goldeneye:1.0.0-rc1'
Initialize
val goldenEye = GoldenEye.Builder(activity).build()
Open camera
if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED
) {
/* Find back camera */
val backCamera = goldenEye.availableCameras.find { it.facing == Facing.BACK }
/* Open back camera */
goldenEye.open(textureView, backCamera, initCallback)
}
Take picture
goldenEye.takePicture(pictureCallback)
Record video
goldenEye.startRecording(file, videoCallback)
/* Somewhere later */
goldenEye.stopRecording()
Builder
When initializing GoldenEye instance you can configure it to fit your needs with several interfaces.
Logger
By default logging is turned OFF. By implementing Logger interface, you can enable logs if needed.
object: Logger {
override fun log(message: String) {
/* Log standard message */
}
override fun log(t: Throwable) {
/* Log error */
}
}
OnZoomChangedCallback
GoldenEye supports pinch to zoom functionality. By using OnZoomChangedCallback you can receive callback every time the zoom changes.
object: OnZoomChangedCallback {
override fun onZoomChanged(zoom: Int) {
/* Do something */
}
}
OnFocusChangedCallback
GoldenEye supports tap to focus functionality. By using OnFocusChangedCallback you can receive callback every time the focus changes.
object: OnFocusChangedCallback {
override fun onFocusChanged(point: Point) {
/* Do something */
}
}
PictureTransformation
Once the picture is taken, by default, library will rotate the bitmap to be in sync with device's orientation and mirror
the image if it is taken with front camera. If you are not OK with this behavior, you can provide PictureTransformation
implementation
that will be used instead. PictureTransformation.transform
method is executed on the background thread!
object: PictureTransformation {
override fun transform(picture: Bitmap, config: CameraConfig, orientationDifference: Float): Bitmap {
/* Transform raw picture */
}
}
Advanced features
Advanced features are still in experimental phase and we noticed that they do not work on some devices and they were not
thoroughly tested so we decided to disable them by default. That means that if you try to change the value via setter, it will simply be ignored.
In case you want to try and play with advanced features, you can enable them when initializing GoldenEye instance.
GoldenEye.Builder(activity)
.withAdvancedFeatures()
.build()
Edge case behavior
- If you call
startRecording
ortakePicture
while GoldenEye is already taking a picture or recording a video, immediateonError
callback will be dispatched for the second call, first call tostartRecording
ortakePicture
will still be active - If you call
release
while GoldenEye is taking a picture or recording a video, everything will be canceled including all callbacks,
nothing will be dispatched - If you call
GoldenEye.config
beforeInitCallback#onReady
is dispatched, returnedconfig
will benull
- If you call
open
while camera is already opened, old camera will be released and closed and new camera will be opened
Known issues
- Video recording with external camera is not supported due to current video configuration limitations of the internal API design
- OnePlus 6 - ColorEffectMode does not work
- Huawei Nexus 6P - Picture taken with Flash is too dark
- LG G5 - Picture taken with Flash is too dark