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
ViewStubthat you will be passing to Camera KitSessionobject. In this sample app this is done inactivity_main.xmlfile with aViewwithcamera_kit_stubID. ThisViewwill be used to inflate a view hierarchy from the Camera KitSessionwhich includes rendering camera preview with a lens applied. - Attach the
ViewStubto Camera KitSessionusing its builder'sattachTomethod. This is done inMainActivity.ktfile in this example. - In this sample we are using the Camera Kit's
CameraXImageProcessorSourcesupport class for the image processing input at the time ofSessioncreation inMainActivity.ktfile. However, you are free to use your own image processing input and connect it toSession.processor. - We are using
RecyclerViewwithGridLayoutManagerfor the lenses carousel. Once you have the view hierarchy setup you can simply query the lenses repository from theSession.lensesobject to fetch lenses group and fill theRecyclerViewwith the group's items using custom layout as a carousel. - Fetching from the lenses repository is done in the
MainActivity.ktfile using thecameraKitSession.lenses.repository.observemethod - the retrieved list of lenses are then passed on toLensesAdapter.ktfile as a list ofLensesComponent.Lensobjects.
-
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:






