Dual-screen library update with Jetpack Window Manager
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:
The rest of the modules all behave identically, regardless of which ScreenManager has been used, including:
- SurfaceDuoLayout and FrameLayout
- RecyclerView helper classes (new)
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:
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.
New RecyclerView layouts
There are two new layout manager classes in RecyclerView library:
This makes RecyclerView automatically change its behavior depending on screen mode.
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.