What’s new in WindowManager 1.1.0-beta01


Posted by Jon Eckenrode, Technical Writer, Software Engineering
blog header with android logos

The Jetpack WindowManager release 1.1.0-beta01 continues the library’s steady progress towards a stable release of version 1.1.0. The beta adds an assortment of new features and capabilities, ready for testing and early adoption today!

We need your feedback so we can make WindowManager work best for you. Add the 1.1.0-beta01 dependency to your app, follow the migration steps below (if you’re already using an earlier version of the library), and let us know what you think!

Embedding activities

androidx.window.embed

Activity embedding allows you to optimize your multi-activity apps for large screens. The 1.1.0-beta01 release improves and restructures the APIs to provide greater versatility, capability, and control when managing task pane splits. We started with experimental APIs in 1.0.0 and will eventually promote them to stable in 1.1.0.

tl;dr

Added a manifest setting so you can inform the system that your app has implemented activity embedding. Refactored split controller be more focused on split properties; extracted split line APIs to RuleController and APIs for embedding activities ActivityEmbeddingController. Added the SplitAttributes class to describe embedding splits. Added the EmbeddingAspectRatio class to set a minimum ratio for applying activity embedding rules. Pixel units changed to display-independent pixels (dp). Split layout customization enabled. Added a tag to rules to allow developers to identify and manage specific rules.

What’s new

PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED

  • Added as boolean property of it tag in the app manifest.

ActivityEmbeddingController

  • Added class for operations related to the Activity or ActivityStack classes.
  • Inclusive isActivityEmbedded() to replace the API SplitController.

RuleController

  • Added class for operations related to the Embedding rule class and subclasses.
  • Contains the following APIs to replace APIs in split controller:
    • addRule() — Adds or updates a rule that has the same tag.
    • removeRule() — Removes a rule from the set of registered rules.
    • setRules() – Defines a set of rules.
    • clearRules() — Deletes all registered rules.
    • parseRules() — Parses lines from XML rule definitions.

SplitAttributes

  • Added class to define split layout.

EmbeddingAspectRatio

  • Added class to define enum-like behavior constants related to screen aspect ratio. Allows you to specify when splits are enabled based on the aspect ratio of the main window.

To see Split line for properties that use the constants.

What has changed

EmbeddingRule

  • Added tag field for split rule identification.

SplitController

  • Refactored APIs to the following modules:
    • ActivityEmbeddingController
      • Moved isActivityEmbedded() Unpleasant ActivityEmbeddingController.
    • RuleController
      • Removed the following APIs and replaced their functionality with RuleController APIs:
        • clearRegisteredRules()
        • getSplitRules()
        • initialize()
        • registerRule()
        • unregisterRule()
  • Deprecated isSplitSupport() method and replace with splitSupportStatus property to provide more detailed information about why the split feature is not available.
  • The getInstance() method now has a Context parameter.

Remark: The getInstance() methods of ActivityEmbeddingController And RuleController also have one Context parameter.

  • Added SplitAttributes calculator functions to customize split layouts:
    • setSplitAttributesCalculator()
    • clearSplitAttributesCalculator()
    • isSplitAttributesCalculatorSupport() to check if the SplitAttributesCalculator APIs are supported on the device.
  • Certain SplitSupportStatus nested class to store state constants for the splitSupportStatus property. Allows you to change app behavior based on whether activity embedding is supported in the current app environment.

SplitRule

  • Added defaultSplitAttributes property that defines the default layout of a split; replaces split ratio And layoutDirection.
  • Added translation of the splitRatio and XML properties splitLayoutDirection Unpleasant defaultSplitAttributes.

  • Changed minimum dimension definitions to use density independent pixels (dp) instead of pixels.

    • altered minWidth Unpleasant minWidthDp with default value 600 dp.
    • altered minSmallestWidth Unpleasant minSmallestWidthDp with default value 600 dp.
    • Added minHeightDp property with default value 600dp.
  • Added maxAspectRatioInHorizontal with default value ALWAYS_ALLOW.
  • Added maxAspectRatioInPortrait with default value 1.4.
  • Certain FinishBehaviour nested class to replace end behavior constants.
  • The property changes applied to the Builder nested class of SplitPairRule And SplitPlaceholderRule.

SplitInfo

  • To replace getSplitRatio() of getSplitAttributes() to provide additional demerger-related information.

Window layout

androidx.window.layout

The window layout library allows you to control app display window characteristics. With release 1.1.0-beta01 you can now work in contexts other than activities.

What has changed

WindowInfoTracker

  • Added idle UI context support in experimental.

WindowMetricsCalculator

  • Added idle UI context support.

Migration steps

Take the next step and upgrade your app from a previous alpha version. And please let us know how we can further facilitate the upgrade process.

PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED

  • To enable activity embedding, apps must add the property to the tag in the app manifest:

< eigenschap android:name="android.window.PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED" android:value="true" />

If the property is set to true, the system can optimize the split behavior for the app early.

SplitInfo

  • Check if the current split is stacked:

SplitInfo.splitAttributes.splitType is SplitAttributes.SplitType.ExpandContainersSplitType

if (SplitInfo.splitAttributes.splitType is SplitAttributes.SplitType.RatioSplitType) { val ratio = splitInfo.splitAttributes.splitType.ratio } else { // Ratio is meaningless for other types. }

SplitController

  • SplitController.getInstance()

SplitController.getInstance(context)

  • SplitController.initialize(Context, @ResId int)

changed to:

RuleController.getInstance(Context) .setRules(RuleController.parse(Context, @ResId int))

  • SplitController.getInstance().isActivityEmbedded(Activity)

changed to:

ActivityEmbeddingController.getInstance(Context) .isActivityEmbedded(Activity)

  • SplitController.getInstance().registerRule(rule)

changed to:

RuleController.getInstance(Context).addRule(rule)

  • SplitController.getInstance().unregisterRule(rule)

changed to:

RuleController.getInstance(Context).removeRule(rule)

  • SplitController.getInstance().clearRegisteredRules()

changed to:

RuleController.getInstance(Context).clearRules()

  • SplitController.getInstance().getSplitRules()

changed to:

RuleController.getInstance(Context).getRules()

SplitRule

  • Change minWidth Unpleasant minWidthDp And minSmallestWidth Unpleasant minSmallestWidthDp
  • minWidthDp And minSmallestWidthDp now use dp units instead of pixels

Apps can use the following call:

TypedValue.applyDimension( COMPLEX_UNIT_DIP, minWidthInPixels, resources.displayMetrics )

or just share minWithInPixels Through displayMetrics#density.

SplitPairRule.Builder

  • SplitPairRule.Builder( filters, minWidth, minSmallestWidth )

changed to:

SplitPairRule.Builder(filters) // Optional if minWidthInDp argument is 600. .setMinWidthDp(minWidthInDp) // Optional if minSmallestWidthInDp argument is 600. .setMinSmallestWidthDp(minSmallestWidthInDp)

  • setLayoutDirection(layoutDirection) and setSplitRatio(ratio)

change to:

setDefaultSplitAttributes(SplitAttributes.Builder() .setLayoutDirection(layoutDirection) .setSplitType(SplitAttributes.SplitType.ratio(ratio)) .build() )

  • setFinishPrimaryWithSecondary And setFinishSecondaryWithPrimary take the FinishBehaviour enum-like constants.

To see Split line migrations for details.

setMaxAspectRatioInPortrait( EmbeddingAspectRatio.ALWAYS_ALLOW )

to show splits on standing devices.

SplitPlaceholder.Builder

  • Has alone filters And placeholderIntent parameters; other properties go to setters.

To see SplitPairRule.Builder migrations for details.

  • setFinishPrimaryWithPlaceholder takes the FinishBehaviour enum-like constants.

For more information, see Complete behavioral migrations.

  • setLayoutDirection(layoutDirection) And setSplitRatio(ratio)

change to

setDefaultSplitAttributes(SplitAttributes.Builder() .setLayoutDirection(layoutDirection) .setSplitType(SplitAttributes.SplitType.ratio(ratio)) .build() )

See layout direction migrations for details.

setMaxAspectRatioInPortrait( EmbeddingAspectRatio.ALWAYS_ALLOW )

to show splits on standing devices.

End behavior

Finish constants must be migrated FinishBehavior enum-like class constants:

  • FINISH_NEVER changed to Complete Behaviour.NEVER
  • FINISH_ALWAYS changed to Complete Behaviour.ALWAYS
  • FINISH_ADJACENT changed to FinishBehavior.ADJACENT

Layout direction

The layout direction must be migrated SplitAttributes.LayoutDirection:

  • ltr changed to SplitAttributes.LayoutDirection.LEFT_TO_RIGHT
  • rtl changed to SplitAttributes.LayoutDirection.RIGHT_TO_LEFT
  • place changed to SplitAttributes.LayoutDirection.LOCALE
  • split ratio migrates to SplitAttributes.SplitType.ratio(splitRatio)

Get started

To get started with WindowManager, add the Google Maven repository to your app settings.gradle or at project level construction.gradle file:

dependencyResolutionManagement {

repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

repositories {

google()

}

}

Next, add the 1.1.0-beta01 dependency to your app’s module-level build.gradle file:

dependencies {

implementation ‘androidx.window:window:1.1.0-beta01’

. . .

}

Happy coding!