Getting Started
Render a Quad image using the QuadView on a Leia Light-field device.
This section shows you how to set up and use the Android Media SDK to display an image in 4V in your Android project.
For this tutorial, we will simply load a Quad image from your project's resource directory into the QuadView.

Setup Resources

You can download the Quad image used for the tutorial below.
optician_2x2.jpg
1MB
Image
Optician_2x2
Place this image in your project's drawable resource directory, like shown below.
Optionally, you can also use any Quad image of your choice.

Setup Your Environment

To include the Android Media SDK to your project, add the following dependency to your app's build.gradle file. This adds Leia's Android Media SDK to your project.
1
dependencies {
2
implementation "com.leiainc:androidmediasdk:0.0.2"
3
}
Copied!
Optionally, you can also customize the modules you want to add to your project. The different modules and their use cases are discussed here.

Add the QuadView to your XML Layout file

1
<com.leiainc.androidsdk.core.QuadView
2
android:id="@+id/quad_view"
3
android:layout_width="match_parent"
4
android:layout_height="match_parent"/>
Copied!
The QuadView is a reusable Android view which allows you to easily render a quad with just one line of code.
Obtain the reference to the QuadView in your Activity or Fragment using findViewById()
Kotlin
Java
1
val quadView: QuadView = findViewById(R.id.quad_view)
Copied!
1
QuadView quadView = findViewById(R.id.quad_view);
Copied!

Load the image into the QuadView

Now, all we need to do is set the Optician2x2.jpg image placed in our resource directory into the QuadView. The QuadView takes in a Bitmap representing a Quad as an input.
Kotlin
Java
1
val quadView: QuadView = findViewById(R.id.quad_view)
2
3
/* Get Bitmap for Quad in the resource directory */
4
val bitmap = BitmapFactory.decodeResource(resources, R.drawable.optician_2x2)
5
6
/* Set the Quad Bitmap in the QuadView */
7
quadView.setQuadBitmap(bitmap)
Copied!
1
QuadView quadView = findViewById(R.id.quad_view);
2
3
/* Get Bitmap for Quad in the resource directory */
4
Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.optician_2x2);
5
6
/* Set the Quad Bitmap in the QuadView */
7
quadView.setQuadBitmap(bitmap);
Copied!
    Use the BitmapFactory.decodeResource() function to obtain the Bitmap for the Quad image in the resource directory.
    Use QuadView#setQuadBitmap() function to set the bitmap obtained from the previous step.
You're all set! The QuadView will handle rendering the image. However, at this point, if you run the app, the image will appear in 2D. We still have to turn on the backlight to view the image in 4V.

Toggle the Backlight

The last step is to switch on the backlight to view the image in 4V. We can request toggling backlight using the LeiaDisplayManager .
Place the following line of code in your Activity/Fragment's onResume() function.
Kotlin
Java
1
override fun onResume() {
2
super.onResume()
3
val displayManager: LeiaDisplayManager? = LeiaSDK.getDisplayManager(applicationContext)
4
displayManager?.requestBacklightMode(LeiaDisplayManager.BacklightMode.MODE_3D)
5
}
Copied!
1
@Override
2
protected void onResume() {
3
super.onResume();
4
LeiaDisplayManager displayManager = LeiaSDK.getDisplayManager(this);
5
displayManager.requestBacklightMode(LeiaDisplayManager.BacklightMode.MODE_3D);
6
}
Copied!
This will turn on the backlight on a Leia Light-field device.
To turn off the backlight, you can call the same line of code with BacklightMode.MODE_2D.
Kotlin
Java
1
override fun onPause() {
2
super.onPause()
3
val displayManager: LeiaDisplayManager? = LeiaSDK.getDisplayManager(applicationContext)
4
displayManager?.requestBacklightMode(LeiaDisplayManager.BacklightMode.MODE_2D)
5
}
Copied!
1
@Override
2
protected void onPause() {
3
super.onPause();
4
LeiaDisplayManager displayManager = LeiaSDK.getDisplayManager(this);
5
displayManager.requestBacklightMode(LeiaDisplayManager.BacklightMode.MODE_2D);
6
}
Copied!
Its good practice to turn off the backlight in your activity's onPause() function. This ensures the backlight is turned off when the user exits the app or the device is sleeping.

Build your app

If you followed the steps above correctly, you should be able to view the image in 4V. If you had trouble following the steps, you can always checkout the sample app on Github.
Last modified 2mo ago