Easy Digital camera is a library that lets you use cameras in a simplified, straightforward, quick and efficient manner. It comprises CameraX as an inside library. It simplifies the digital camera options utilized by CameraX and supplies ease of use with a single library. As updates come on the CameraX aspect, the library will attempt to keep updated. Lacking options might be added quickly. Like video capturing.
To be added/Added Options
Preliminary Set up
Gradle
Add beneath codes to your root construct.gradle file (not your module construct.gradle file).
repositories {
maven { url ‘https://jitpack.io‘ }
}
}
And add a dependency code to your module’s construct.gradle file.
implementation ‘com.github.zekierciyas:SimpleCamera:1.0.0‘
}
Utilization
Add following XML namespace inside your XML format file.
SimpleCameraView
We are able to use SimpleCameraView with custom-made attributes.
android:id=“@+id/camera_view“
app:cameraID=“1“
android:layout_width=“match_parent“
android:layout_height=“match_parent“ />
Attribute descriptions
We are able to customise the palette picture and selector or numerous choices utilizing the beneath attributes.
app:cameraID=“1“ // Default Again Facet Lens
Observers
Observers can be utilized as separate objects as within the instance. You’ll be able to entry it from the interface object of Observers.
Observers.CameraState is a typical statement that gives normal statement of the digital camera. It can be utilized in different digital camera options.
override enjoyable cameraState(simpleCameraState: SimpleCameraStateModel) {
Log.d(TAG, “Digital camera state is ${simpleCameraState.motion.toString()} “)
when (simpleCameraState.motion) {
is SimpleCameraState.Motion.Closed -> {
}
is SimpleCameraState.Motion.Closing -> {
}
is SimpleCameraState.Motion.Open -> {
}
is SimpleCameraState.Motion.Opening -> {
}
is SimpleCameraState.Motion.Pending -> {
}
else -> {
}
}
when (simpleCameraState.error) {
is SimpleCameraState.Error.ErrorCameraDisabled -> {
}
is SimpleCameraState.Error.ErrorCameraFatalError -> {
}
is SimpleCameraState.Error.ErrorCameraInUse -> {
}
is SimpleCameraState.Error.ErrorDoNotDisturbModelEnabled -> {
}
is SimpleCameraState.Error.ErrorMaxCameraInUse -> {
}
is SimpleCameraState.Error.ErrorOtherRecoverableError -> {
}
is SimpleCameraState.Error.ErrorStreamConfig -> {
}
else -> {
}
}
}
}
Observers.ImageAnalysis can solely be used in the course of the picture evaluation function. It’s an observer sample that returns evaluation outcomes. You’ll find the easy utilization separated from right here.
override enjoyable outcome(bitmap: Bitmap?) {
bitmap?.let {
Log.i(TAG,“Bitmap acquired whereas analysi “ +
“n byte depend: ${it.byteCount} “ +
“n : density ${it.density}“)
}
}
}
Observers.ImageCapture can solely be used in the course of the Picture Seize function. It’s an observer sample that returns captured picture outcomes. You’ll find the easy utilization separated from right here.
override enjoyable outcome(savedUri: Uri?, exception: Exception?) {
if (savedUri != null) {
Log.i(TAG, “Picture seize is succeed“)
runOnUiThread {
capturedImagePreview.setImageBitmap(savedUri.toBitmap(this@ImageCaptureActivity))
}
}
}
}
Utilization
You’ll find View definitions and Builder configuration for every function individually.
Utilization of Picture Evaluation
// Have to be known as after getting digital camera permissions
simpleCameraView.observeCameraState(observerCameraState)
.startImageAnalysis(this, observerImageAnalysis)
Utilization of Picture Seize
// Have to be known as after getting digital camera permissions
simpleCameraView.observeCameraState(observerCameraState)
.imageCapture(this) {
prepared -> if(prepared) {
// Picture may very well be taken
// You’ll be able to set visibility of seize button right here for those who had one !
// Or you may take photograph instantly when it is prepared
simpleCameraView.takePhoto(observerImageCapture)
}
}
Frequent Characteristic
simpleCameraView.flipCamera()
Licensed underneath the Apache License, Model 2.0 (the “License”);
it’s possible you’ll not use this file besides in compliance with the License.
You might acquire a duplicate of the License at
http://www.apache.org/licenses/LICENSE-2.0
Except required by relevant regulation or agreed to in writing, software program
distributed underneath the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, both categorical or implied.
See the License for the precise language governing permissions and
limitations underneath the License.