This example app shows how to create a custom carousel for your lenses and use a custom layout to display a camera preview with lenses applied using Camera Kit.
Open project's gradle.properties
file and enter values for com.snap.camerakit.api.token
from Snap Kit Developer Portal and com.snap.camerakit.lenses.group.id
from your My Lenses Portal (Under the apps tab). After that to build, install and launch the camerakit-sample-custom-carousel
on a connected device follow one of the following options:
-
./gradlew camerakit-sample-custom-carousel:installDebug
-
adb shell am start -n com.snap.camerakit.sample.carousel/com.snap.camerakit.sample.carousel.MainActivity
Select the camerakit-sample-custom-carousel
module configuration and click run:
- Create a
ViewStub
that you will be passing to Camera KitSession
object. In this sample app this is done inactivity_main.xml
file with aView
withcamera_kit_stub
ID. ThisView
will be used to inflate a view hierarchy from the Camera KitSession
which includes rendering camera preview with a lens applied. - Attach the
ViewStub
to Camera KitSession
using its builder'sattachTo
method. This is done inMainActivity.kt
file in this example. - In this sample we are using the Camera Kit's
CameraXImageProcessorSource
support class for the image processing input at the time ofSession
creation inMainActivity.kt
file. However, you are free to use your own image processing input and connect it toSession.processor
. - We are using
RecyclerView
withGridLayoutManager
for the lenses carousel. Once you have the view hierarchy setup you can simply query the lenses repository from theSession.lenses
object to fetch lenses group and fill theRecyclerView
with the group's items using custom layout as a carousel. - Fetching from the lenses repository is done in the
MainActivity.kt
file using thecameraKitSession.lenses.repository.observe
method - the retrieved list of lenses are then passed on toLensesAdapter.kt
file as a list ofLensesComponent.Lens
objects.
-
Open the lenses carousel by clicking on the lens explorer button to the left of the capture button:
-
Click on the lens icon to apply that particular lens with auto-flip camera (front or rear facing) as per the lens' camera facing preference set in the Lens Studio project.
-
Swipe down to go full screen and hide the lenses carousel:
-
Flip the camera button to toggle between the front or the rear facing camera.
-
Highlight the selected lens item in lenses carousel.
-
Capture a photo or a video to preview it, and share it with other apps using the Android's share sheet:
-
Click on the cancel button to clear any applied lens and present the camera with no lens applied:
-
Tap on the preview screen while the lenses carousel is open to make it go full screen: