[Android Sample] How to create a custom layout & lenses carousel
Camera Kit Sample Custom Lenses Carousel and Camera Preview
This sample 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.
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 Camera Kit Portal. After that to build, install and launch the
camerakit-sample-custom-carousel on a connected device follow one of the following options:
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 custom layout and lenses carousel
- Create a
ViewStubthat you will be passing to Camera Kit
Sessionobject. In this sample app this is done in
activity_main.xmlfile with a
camera_kit_stub ID. This
Viewwill be used to inflate a view hierarchy from the Camera Kit
Sessionwhich includes rendering camera preview with a lens applied.
- Attach the
ViewStubto Camera Kit
Sessionusing its builder's
attachTomethod. This is done in
MainActivity.ktfile in this example.
- In this sample we are using the
Camera Kit's CameraXImageProcessorSourcesupport class for the image processing input at the time of
MainActivity.ktfile. However, you are free to use your own image processing input and connect it to Session.processor .
- We are using
GridLayoutManagerfor the lenses carousel. Once you have the view hierarchy setup you can simply query the lenses repository from the
Session.lensesobject to fetch lenses group and fill the
RecyclerViewwith the group's items using custom layout as a carousel.
- Fetching from the lenses repository is done in the
MainActivity.ktfile using the
cameraKitSession.lenses.repository.observemethod - the retrieved list of lenses are then passed on to
LensesAdapter.ktfile as a list of
- 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:
- 0 All Categories
- Snap AR | Categories
- 2K Lens Studio
- 150 Camera Kit
- 16 Spectacles