CCMultiple library provides you with the convenience of accessing the camera of your android device using the latest CameraX API, with just a few lines of code.
Star this repo to show your support stargazers for this repository. 🌟
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency
dependencies {
implementation 'com.github.Priyansh-Kedia:CustomCamera:<latest_version>'
}
You can include the camera directly in the XML code, by
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.kedia.customcamera.CCMultiple android:id="@+id/cc"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:showFlashButton="true"
app:showNoPermissionToast="true"
app:streamContinuously="true"
app:showRotateCamera="true" />
</androidx.constraintlayout.widget.ConstraintLayout>
This library provides with customisable features, which provides with a better control over the features.
These features include:
- Snap button visibility:- You can set the snap button visibility, just by setting the value of
showSnapButton
totrue
in your XML code. You can also set the value of this attribute by usingsetSnapButtonVisibility
from your Java / Kotlin code. - Snap button color:- You can set the snap button color, just by setting the value of
snapButtonColor
to a color resource in your XML code. You can also set the value of this attribute by usingsetSnapButtonColor
from your Java / Kotlin code. - Snap button selected color:- This lets you set the color of the snap button when it is clicked. You can set the value by
snapButtonSelectedColor
to a color resource in your XML code. You can also set the value of this attribute by usingsetSnapButtonSelectedColor
from your Java / Kotlin code. - Permission toast visibility:- You can set if the user should see the toast message if the camera permission is not granted. You can set the value of this attribute by setting
showNoPermissionToast
totrue
orfalse
- Rotate camera button visibility:- You can control the visibility of the rotate camera button. This can be done by setting
showRotateCamera
totrue
from the XML code, or by settingsetRotateVisibility
from your Java / Kotlin code. - Flash button visibility:- You can control the visibility of the flash button. This can be done by setting
showFlashButton
totrue
from the XML code, or by settingshowFlashToggle
from your Java / Kotlin code. - Captured images number:- You can control if the user can capture single or multiple photos using the camera. This can be done by setting
captureSingle
orcaptureMultiple
to true. Remember, if you set the value of both these attributes totrue
at the same time, it will lead to a runtime exception. - Image deselection option:- You can give the user the freedom to delete the captured images in case of multiple captures. This can be done by setting
showImageDeselectionOption
totrue
in your XML code. If the value of this attribute is set totrue
, the user will be able to see a small cross button at the top-right corner of the captured images, which can be used to delete a particular click. The default value of this attribute istrue
. - Front flash:- When the camera is facing front, in case of multiple or single capture, there is a functionality for front flash, which runs on all Android devices by using the screen as a flash screen.
To receive the callbacks from the camera, you need to implement the interface CustomMultiple
. You can do this by using setListener
from your Java / Kotlin code.
The callback which can be invoked, is onConfirmImagesClicked
, which gets a list of Uri
, you can extract the images using the given Uri
.
The size of the list is 1 in case of single image capture.
To receive continuous frames from the camera, set the value of streamContinuously
to true
from the XML code. The value of this attribute can also be set using setContinuousStreaming
from Java / Kotlin code.
Remember that flash button cannot be visible when receiving continuous frames from the camera.
Currently the library supports only STRATEGY_KEEP_ONLY_LATEST
of CameraX, which keeps only the latest image captured, until the image is closed. You can close the image by using the closeImage()
method from Java / Kotlin code. Only after closing the image, will the next frame be available.
The continuous frames of the camera can be received in the callback onCameraFrameReceived
which has the current bitmap.
- Fork the repo
- Create a new branch and make changes
- Push the code to the branch and make a PR! 👍
Copyright 2021 Priyansh Kedia
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Support it by joining stargazers for this repository. 🌟