Prep your TV app for Android 12. Refresh rate switching, text scaling… | by Paul Lammertsma | Android Developers | Mar, 2022

Prep your TV app for Android 12. Refresh rate switching, text scaling… | by Paul Lammertsma | Android Developers | Mar, 2022

Refresh rate switching, text scaling and 4K UI support are key areas to focus on in TV apps for Android 12.

Refresh rate switching allows apps to instruct TV panels to switch between different frequencies, such as multiples of 24, 25 and 30Hz. If your video content was for instance created at 24 fps, then your app can ensure smoother playback while simultaneously allowing for fluid UI animations by switching to 48Hz on supported panels.

Some panels support HDMI 2.1 VRR for seamless refresh rate transitions without any visual interruptions (like showing a black screen for a few seconds), and Android can inform you of these through getAlternativeRefreshRates().

From your playback Surface, you can request the desired refresh rate using setFrameRate(). For instance, to do so seamlessly or according to the user’s preference:

// Determine whether the transition will be seamless.
// Non-seamless transitions may cause a 1-2 second black screen.
val refreshRates = display?.mode?.alternativeRefreshRates
val willBeSeamless = Arrays.asList<FloatArray>(refreshRates).contains(newRefreshRate)
if (willBeSeamless) {
// Set the frame rate, but only if the transition will be seamless.
} else if ((getSystemService(Context.DISPLAY_SERVICE) as DisplayManager).getMatchContentFrameRateUserPreference()) {
// Set the frame rate if the user has requested it to match content

If you are using ExoPlayer, seamless frame rate switching is handled by default. If you would like to always change frame rates using CHANGE_FRAME_RATE_ALWAYS, disable the strategy through ExoPlayer.setVideoChangeFrameRateStrategy() before implementing the approach above.

If all your video content is the same frame rate, it may be more sensible to allow panels that cannot switch seamlessly to perform their refresh rate switch when your application receives focus. In this case, you may instead choose to enumerate all supported display modes through Display.getSupportedModes() to find a mode that best suits your needs, and specify it as the preferredDisplayModeId in the WindowManager’s attributes. For example:

val params: WindowManager.LayoutParams = window.attributes
if (requestedMode.modeId !== params.preferredDisplayModeId) {
params.preferredDisplayModeId = requestedMode.modeId
window.attributes = params

A new accessibility options screen in Android 12 allows users to adjust the size of text on the screen, so it’s now even more important to support text scaling. Specifying text sizes in scalable pixels is essential, but also take special care to ensure that layouts rearrange components as their dimensions change and that everything still fits on the screen when the text scale is increased or decreased.

Text scale has always been an accessibility setting in Android and with Android 12, we are introducing a settings screen in Android TV so users can adjust it to their preference. You don’t have to wait to get ahold of Android 12 to find this new settings screen; it can be adjusted through ADB:

adb shell settings put system font_scale 1.2f

It’s generally recommended to use dynamic layouts with components that use wrap_content for dimensions and allow the user to scroll to access content that doesn’t fit in the screen. You can always query the value of FONT_SCALE from resources.configuration.fontScale.

Android itself will begin rendering UIs natively at 4K on supported devices. Much like the migration from 720p to 1080p, TV apps should not make assumptions about the dimensions of the screen. Avoid hardcoding pixel values by designing responsive UIs and supporting different screen sizes.

Read more about managing layout resources in our recommendations for building TV layouts.

The Android 12 developer preview is available for the ADT-3.

Android 12 is available as a developer preview on the ADT-3 developer kit; the Android 12 developer preview for TV will be installed automatically through an OTA, or you can install the latest image manually.

Alternatively, you can use the Android Emulator for TV which allows you to try out these and other new user interface capabilities like window blurs.

Source link

Leave a reply

Please enter your comment!
Please enter your name here