Dual-screen library update with Jetpack Window Manager

Andrei Cirja

Hello Kotlin and Java developers,

We’re excited to announce version 1.0.0-beta1 of our dual-screen libraries for Microsoft Surface Duo, which integrates Google’s Jetpack Window Manager support. We’ve made the underlying device interface swappable, so you can continue to use the existing Display Mask API as long as you wish and migrate to Window Manager when you’re ready.

The main changes in this update are:

  • Jetpack Window Manager is an option for the core device interface layer.
  • Refactor code so that DisplayMask can still be used by existing developers.
  • Includes UI and unit tests for each component.
  • New RecyclerView layout manager for Microsoft Surface Duo.
  • Transparency and animation support added to BottomNavigation and Tabs.
  • Updated documentation and samples.

This blog post explains how to switch between Window Manager and the Display Mask API, tips for migrating from the previous version, and discusses the other new features of this release.

Jetpack Window Manager core

Older versions of the dual-screen libraries used the Microsoft display-mask API to provide dual-screen awareness. With this release we now provide the option to use the Jetpack Window Manager as the device interface, which will work with foldable devices beyond the Surface Duo.

Dual-screen device support is encapsulated in the ScreenManager component – use this gradle line to add to your app:

implementation "com.microsoft.device.dualscreen:screenmanager-windowmanager:1.0.0-beta1"

The rest of the modules all behave identically, regardless of which ScreenManager has been used, including:

The underlying Jetpack Window Manager is currently in alpha. Being able to easily swap the implementation allows you to test both, and release with the version you feel most comfortable with. Over time, the Jetpack Window Manager implementation will be preferred as it provides support for other foldable devices, helping developers get the best return from their investments in dual-screen enhancements.

Display Mask core

Existing apps built on the Display Mask API can continue to use it. If you would like to try out the dual-screen libraries in conjunction with the Display Mask API, include the correct ScreenManager component with this gradle line:

implementation "com.microsoft.device.dualscreen:screenmanager-displaymask:1.0.0-beta1"

When you add the other modules (BottomNavigation, etc), they will all work the same regardless of which ScreenManager is included.

Migrating from older releases

To align with the lifecycle supported by Window Manager, the library code no longer accesses dual-screen properties in the onCreate method. Instead, the details are accessed after the activity onAttachToWindow callback.

Existing apps that used the display-mask API in the onCreate method (to lay out views, for example) should move that code later in the activity lifecycle. The new ScreenManager implementation compensates for this by refactoring the libraries with an event-driven architecture. This means that in onCreate you can add a listener for screen mode change events.

When you update to this version of the libraries, you should move any dual-screen specific code that was in onCreate to a listener so that your code can work with both core implementations.

Libraries available in JCenter

Starting with this release we are publishing to the JCenter repository. JCenter is a default repository in Android Studio which means you’ll no longer need to add our maven repository feed to your top-level build.gradle file when you include our libraries in your app.

Just add the implementation lines as shown above directly to your module-level build.gradle file (see the docs for more info, or explore the package on bintray.com).

New RecyclerView layouts

There are two new layout manager classes in RecyclerView library:

This makes RecyclerView automatically change its behavior depending on screen mode.

Updated samples

The Kotlin samples and app samples repos have been updated to use Jetpack Window Manager – visit GitHub to get the latest versions.

Feedback and resources

The source code for the SDK is available on GitHub if you’re curious about the implementation or wish to contribute. Visit the documentation for more information on all the features in the dual-screen library for Kotlin and Java developers.

Thanks to the team – Bianca Miron, Cesar Valiente, Cristian Verdes, and Sorin Albu – for their work on this release.

We’d love to hear from you and how you plan to incorporate dual-screen enhancements into your apps. Please reach to out using the feedback forum or message us @surfaceduodev on Twitter.


Discussion is closed.

Feedback usabilla icon