.png)
[ad_1]

Posted by way of Francesco Romano, Developer Members of the family Engineer on Android
It’s been greater than a 12 months for the reason that free up of the Jetpack WindowManager 1.0 solid model, and plenty of issues have came about within the foldables and massive display area. Many new units have entered the marketplace, and plenty of new use instances had been unlocked!
Jetpack WindowManager is without doubt one of the maximum essential libraries for optimizing your Android app for various shape components. And this free up is a big milestone that incorporates quite a few new options and enhancements.
Let’s recap the entire use instances lined by way of the Jetpack WindowManager library.
Get window metrics (and measurement categories!)
Traditionally, builders relied at the instrument reveal measurement to come to a decision the format in their apps, however with the supply of various shape components (similar to foldables) and reveal modes (similar to multi-window and multi-display) details about the scale of the app window moderately than the instrument reveal has turn into very important.
The Jetpack WindowManager WindowMetricsCalculator interface supplies the supply of reality to measure how a lot display area is lately to be had to your app.
Constructed on best of that, the window measurement categories are a collection of opinionated viewport breakpoints that mean you can design, expand, and check responsive and adaptive software layouts. The breakpoints had been selected particularly to stability format simplicity with the versatility to optimize your app for distinctive instances.
With Jetpack Compose, use window measurement categories by way of uploading them from the androidx.compose.material3 library, which makes use of WindowMetricsCalculator internally.
For View-based app, you’ll use the next code snippet to compute the window measurement categories:
personal a laugh computeWindowSizeClasses() { |
To be told extra, see our Toughen other display sizes developer information.
Make your app fold mindful
Jetpack WindowManager additionally supplies the entire APIs you want to optimize the format for foldable units.
Particularly, use WindowInfoTracker to question FoldingFeature knowledge, similar to:
- state: The folded state of the instrument, FLAT or HALF_OPENED
- orientation: The orientation of the fold or instrument hinge, HORIZONTAL or VERTICAL
- occlusion kind: Whether or not the fold or hinge conceals a part of the reveal, NONE or FULL
- is keeping apart: Whether or not the fold or hinge creates two logical reveal spaces, true or false
- bounds: The bounding rectangle of the function inside the software window (inherited from DisplayFeature)
You’ll be able to get entry to this knowledge via a Go with the flow:
override a laugh onCreate(savedInstanceState: Package deal?) { |
Whenever you accumulate the FoldingFeature data, you’ll use the information to create an optimized format for the present instrument state, as an example, by way of imposing tabletop mode! You’ll be able to see a tabletop mode instance in MediaPlayerActivity.kt.
A great spot to begin studying about foldables is our codelab: Toughen foldable and dual-screen units with Jetpack WindowManager.
Display two Actions aspect by way of aspect
Remaining, however now not least, you’ll use the newest solid Jetpack WindowManager API: exercise embedding.
To be had since Android 12L, exercise embedding permits builders with legacy multi-activiity architectures to reveal a number of actions from the similar software—and even from a number of packages—side-by-side on huge displays.
It’s a good way to put in force list-detail layouts with minimum or no code adjustments.
Word: Trendy Android Building (MAD) recommends the usage of a single-activity structure in response to Jetpack APIs, together with Jetpack Compose. In case your app makes use of fragments, take a look at SlidingPaneLayout. Task embedding is designed for multiple-activity, legacy apps that cannot be simply up to date to MAD. |
It’s also the largest trade within the library, because the exercise embedding APIs at the moment are solid in 1.1!
Now not handiest that, however the API is now richer in options, because it allows you to:
- Adjust the conduct of the break up display (break up ratio, regulations, completing conduct)
- Outline placeholders
- Take a look at (and alter) the break up state at runtime
- Enforce horizontal splits
- Get started a modal in complete window
Fascinated by exploring exercise embedding? We’ve were given you lined with a devoted codelab: Construct a list-detail format with exercise embedding.
Many apps are already the usage of exercise embedding in manufacturing, as an example, WhatsApp:

And ebay!

Imposing list-details layouts with a number of actions isn’t the one use case of exercise embedding!
Ranging from Android 13 (API stage 33), apps can embed actions from different apps.
Move‑software exercise embedding permits visible integration of actions from a number of Android packages. The machine presentations an exercise of the host app and an embedded exercise from any other app on display aspect by way of aspect or best and backside, simply as in single-app exercise embedding.
Host apps put in force cross-app exercise embedding the similar manner they put in force single-app exercise embedding, however the embedded app will have to opt-in for safety causes.
You’ll be able to be informed extra about cross-application embedding within the Task embedding developer information.
Conclusion
Jetpack WindowManager is without doubt one of the maximum essential libraries you must be informed if you wish to optimize your app’s consumer revel in for various shape components.
WindowManager may be including new, fascinating options with each free up, so stay an eye fixed out for what’s coming in model 1.2.
See the Jetpack WindowManager documentation and pattern app to get began with WindowManager these days!
[ad_2]