Controlling the Backlight
Toggle the backlight to switch between 4V and 2D
Leia Lightfield devices allow you to view content in 4V as well as regular 2D. You can instantaneously switch between the two modes. You might want to turn off the backlight on parts of your Android application where there is no media, to achieve full resolution.
The Leia Media SDK offers APIs to turn on and turn off the backlight instantaneously, by calling just one line of code. You can do so by using the Leia Display Manager.

Using Leia Display Manager

You can get an instance of the LeiaDisplayManager in your Android application using the following line of code
Kotlin
Java
1
val displayManager = LeiaSDK.getDisplayManager(context)
Copied!
1
LeiaDisplayManager displayManager = LeiaSDK.getDisplayManager(context);
Copied!

Toggling the Backlight

After you retrieve an instance of the LeiaDisplayManager, you can toggle the backlight by requesting the desired mode.
You can turn on the backlight using the requestBacklightMode() by passing in MODE_3D
Kotlin
Java
1
val displayManager = LeiaSDK.getDisplayManager(applicationContext)
2
displayManager?.requestBacklightMode(LeiaDisplayManager.BacklightMode.MODE_3D)
Copied!
1
LeiaDisplayManager displayManager = LeiaSDK.getDisplayManager(context);
2
displayManager.requestBacklightMode(LeiaDisplayManager.BacklightMode.MODE_3D);
Copied!
To turn off the backlight, you can request it using MODE_2D
Kotlin
Java
1
displayManager?.requestBacklightMode(LeiaDisplayManager.BacklightMode.MODE_2D)
Copied!
1
displayManager.requestBacklightMode(LeiaDisplayManager.BacklightMode.MODE_2D);
Copied!

Get Current Mode

You can check the currently active backlight mode in code by using getBacklightMode()
Kotlin
Java
1
val currentBacklightMode = displayManager.getBacklightMode()
Copied!
1
LeiaDisplayManager.BacklightMode currentBacklightMode = displayManager.getBacklightMode();
Copied!

UI Conveniences

The LeiaDisplayManager provides the ability to switch to 2D when UI elements that provide a poor 3D experience, such as the notification shade or keyboard, are shown. To take advantage of this behavior, your activities should forward the onWindowFocusChanged(boolean hasFocus) callback into the SDK.
Kotlin
Java
1
override fun onWindowFocusChanged(hasFocus: Boolean) {
2
super.onWindowFocusChanged(hasFocus)
3
displayManager?.onWindowFocusedChanged(hasFocus)
4
}
Copied!
1
@Override
2
public void onWindowFocusChanged(boolean hasFocus) {
3
super.onWindowFocusChanged(hasFocus);
4
if (displayManager != null) {
5
displayManager.onWindowFocusedChanged(hasFocus);
6
}
7
}
Copied!

Handling Backlight Mode Changes

You should not assume that the backlight will change modes immediately when you call requestBacklightMode(). You should also keep in mind that the backlight may change modes without you requesting it.
For example, if the device overheats, the backlight will automatically switch to 2D mode. Your application should respond to this event, and render content in 2D. In the event that 3D is disabled for a reason outside of your app's control, your app will be provided with the list of reasons why this happened.
Kotlin
Java
1
displayManager.registerBacklightEventListener(object : BacklightEventListener {
2
/**
3
* This callback is invoked when the backlight mode changes, and your app is in the foreground.
4
*/
5
override fun onBacklightModeChanged(backlightMode: LeiaDisplayManager.BacklightMode?) {
6
// TODO: Change your application's rendering mode to 2D or 3D.
7
}
8
9
/**
10
* This callback is called when the list of reasons why 3D may be disabled changes.
11
*/
12
override fun onBacklightDisableReasonChanged(disableReasons: Set<BacklightDisableReason?>?) {
13
// TODO: Optionally perform some reason-specific action.
14
}
15
})
Copied!
1
mDisplayManager.registerBacklightEventListener(new BacklightEventListener() {
2
3
/**
4
* This callback is invoked when the backlight mode changes, and your app is in the foreground.
5
*/
6
@Override
7
public void onBacklightModeChanged(LeiaDisplayManager.BacklightMode backlightMode) {
8
// TODO: Change your application's rendering mode to 2D or 3D.
9
}
10
11
/**
12
* This callback is called when the list of reasons why 3D may be disabled changes.
13
*/
14
@Override
15
public void onBacklightDisableReasonChanged(Set<BacklightDisableReason> disableReasons) {
16
// TODO: Optionally perform some reason-specific action.
17
}
18
});
Copied!
To test your application's responsiveness to these event changes, you may use the following ADB commands. Before sending any of them, run adb root to acquire the necessary permissions.
This command simulates an overheat condition: adb shell am broadcast -a com.leia.broadcast.3DMODE_DISABLED --esa "com.android.server.lights.DisableReasons" "OVERHEAT"
This command simulates returning to 3D because of normal temperature: adb shell am broadcast -a com.leia.broadcast.3DMODE_ENABLED
This command simulates switching to 2D because of bright sunlight: adb shell am broadcast -a com.leia.broadcast.3DMODE_DISABLED --esa "com.android.server.lights.DisableReasons" "OVERBRIGHT"
This command simulates returning to 3D because of returning to a darker environment: adb shell am broadcast -a com.leia.broadcast.3DMODE_ENABLED
Note that you must be running a recent version of firmware (>=V5 platform) for the thermal callback to work. (On earlier versions, you will still receive the callback when you request backlight changes, but the 3D backlight may not turn off due to overheat)
In order to avoid resource leaks and reduce memory pressure, your activities should deregister their event listeners in their onDestroy() methods.
Kotlin
Java
1
override fun onDestroy() {
2
super.onDestroy()
3
displayManager?.deregisterBacklightEventListener(mBacklightEventListener)
4
}
Copied!
1
@Override
2
protected void onDestroy() {
3
super.onDestroy();
4
if (displayManager != null) {
5
displayManager.deregisterBacklightEventListener(mBacklightEventListener);
6
}
7
}
Copied!
Last modified 9mo ago