WindowManager 1.1.0-beta01 new features in detail

b189475b4d4ddc62c63386f90318af27.png

Author/Technical Writer and Software Engineer Jon Eckenrode

The 1.1.0-beta01 release of the Jetpack WindowManager library is continuing to progress steadily towards the 1.1.0 stable release. The Beta version adds many new features and functions, you are welcome to test it immediately and experience it first!

We need your feedback to optimize the functionality of WindowManager to provide you with a better experience. If you are already using a previous version of the library, you can add the 1.1.0-beta01 dependency to your app and follow the migration steps below. Also, we look forward to hearing your thoughts!

5ca3860bd698f39f19de30ca95328bdb.png

Activity embedded

androidx.window.embeddin

Optimize multi-activity applications on large-screen devices with Activity embedding . Version 1.1.0-beta01 enhances and refactors the API to provide greater versatility, functionality, and control when managing task window splits. We started with the experimental API of 1.0.0 and will eventually implement the above features in version 1.1.0.

7e7907b1fbd4492c51c1279ae3ef094b.png

overview

We've added a manifest setting that lets you notify the system that your app has implemented Activity embedding. Refactored SplitController to focus more on split properties; extracted Split Rules API to RuleController and Activity Embedding API to ActivityEmbeddingController. The SplitAttributes class has been added to describe embedded splits. The EmbeddingAspectRatio class has been added to set the minimum ratio for applying Activity embedding rules. Changed pixel units to display independent pixels (dp). Split layout customization enabled. Add tags to rules to help developers identify and manage specific rules.

a7f7dc83090f7446d9f85f28fcf3068c.png

new function

PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED

  • A boolean attribute has been added to the <application> tag in the application manifest.

ActivityEmbeddingController

  • Classes have been added for operations related to the Activity or ActivityStack classes.

  • This includes replacing the API in SplitController with isActivityEmbedded().

RuleController

  • Added classes for operations related to the EmbeddingRule class and subclasses.

  • The following APIs are included to replace the APIs in SplitController:

    • addRule() — add a rule or update a rule with the same label.

    • removeRule() — removes a rule from the set of registered rules.

    • setRules() — builds a set of rules.

    • clearRules() — removes all registered rules.

    • parseRules() — parses rules from XML rule definitions.

SplitAttributes

  • Classes have been added for defining split layouts.

EmbeddingAspectRatio

  • Added a class to define constants for display aspect ratio-related enum-like behavior. Allows you to specify when splitting is enabled based on the aspect ratio of the parent window.

You can refer to SplitRule for properties that use these constants.

785d8dd2264c4330ae9d7c44c35f774b.png

Specific changes

EmbeddingRule

  • A label field has been added to identify split rules.

SplitController

  • The API of the following modules has been refactored:

    • ActivityEmbeddingController

      • Moved isActivityEmbedded() to ActivityEmbeddingController.

    • RuleController

      • The following APIs have been removed and their functionality replaced with the RuleController API:

        • clearRegisteredRules()

        • getSplitRules()

        • initialize()

        • registerRule()

        • unregisterRule()

  • The isSplitSupported() method has been deprecated and replaced with the splitSupportStatus property to provide more details that split functionality is not available.

  • The getInstance() method now has a Context parameter.

    Please note : The getInstance() method of ActivityEmbeddingController and RuleController also has a Context parameter.

  • The following SplitAttributes calculator functions have been added for custom split layouts:

    • setSplitAttributesCalculator()

    • clearSplitAttributesCalculator()

    • isSplitAttributesCalculatorSupported(), used to check whether this device supports the SplitAttributesCalculator API.

  • The SplitSupportStatus nested class has been defined to provide status constants for the splitSupportStatus property. Enables you to modify the application behavior according to whether the activity embedding split is supported in the current application environment.

SplitRule

  • A defaultSplitAttributes attribute has been added that defines the default layout for splits; supersedes splitRatio and layoutDirection.

  • Added conversion of XML attributes splitRatio and splitLayoutDirection to defaultSplitAttributes.

  • Changed minimum size definition to use density independent pixels (dp) instead of normal pixels.

    • Changed minWidth to minWidthDp which defaults to 600dp.

    • Changed minSmallestWidth to minSmallestWidthDp which defaults to 600dp.

    • A minHeightDp property with a default value of 600dp has been added.

  • Added maxAspectRatioInHorizontal with default value of ALWAYS_ALLOW.

  • Added maxAspectRatioInPortrait with a default value of 1.4.

  • The FinishBehavior nested class has been defined to replace the finish behavior constant.

  • Property changes were made to the Builder nested classes for SplitPairRule and SplitPlaceholderRule.

SplitInfo

  • Replaced getSplitRatio() with getSplitAttributes() to provide extra information about splits.

8ab98e0a9351f934e6ddfd98ad07e482.png

window layout

androidx.window.layout

You can use the window layout library to determine the characteristics of your application's display windows. In version 1.1.0-beta01, you can work in contexts outside of the Activity.

2e7e55a3dfd43e56efe2cbb6a85f1962.png

Specific changes

WindowInfoTracker

  • Inactive interface context support has been added in an experimental release.

WindowMetricsCalculator

  • Added non-Activity interface context support.

bb8dad85e96bd627e1375af5418b04a3.png

migration steps

Next, upgrade your previous alpha version. In addition, you are welcome to tell us how we can help you further optimize the upgrade process.

PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED

  • To enable activity embedding in your application, you must add the following attribute to the <application> tag in your application manifest:

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

When this property is set to true, the system can optimize the splitting behavior for the application in advance.

SplitInfo

  • Check if the current split is stacked:

    SplitInfo.splitAttributes.splitType is SplitAttributes.SplitType.ExpandContainersSplitType

  • To view the current ratio:

    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) 更改为:  RuleController.getInstance(Context) .setRules(RuleController.parse(Context, @ResId int))

  • SplitController.getInstance().isActivityEmbedded(Activity) 更改为:  ActivityEmbeddingController.getInstance(Context) .isActivityEmbedded(Activity)

  • SplitController.getInstance().registerRule(rule) 更改为: RuleController.getInstance(Context).addRule(rule)

  • SplitController.getInstance().unregisterRule(rule) 更改为: RuleController.getInstance(Context).removeRule(rule)

  • SplitController.getInstance().clearRegisteredRules() 更改为: RuleController.getInstance(Context).clearRules()

  • SplitController.getInstance().getSplitRules() 更改为: RuleController.getInstance(Context).getRules()

SplitRule

  • Change minWidth to minWidthDp and minSmallestWidth to minSmallestWidthDp

  • minWidthDp and minSmallestWidthDp can now use dp units instead of pixels, the application can use the following call: TypedValue.applyDimension( COMPLEX_UNIT_DIP, minWidthInPixels, resources.displayMetrics ) or you can directly divide minWithInPixels according to displayMetrics#density.

SplitPairRule.Builder

  • SplitPairRule.Builder( filters, minWidth, minSmallestWidth ) 更改为:  SplitPairRule.Builder(filters) // Optional if minWidthInDp argument is 600. .setMinWidthDp(minWidthInDp) // Optional if minSmallestWidthInDp argument is 600. .setMinSmallestWidthDp(minSmallestWidthInDp)

  • setLayoutDirection(layoutDirection) and setSplitRatio(ratio) 更改为: setDefaultSplitAttributes(SplitAttributes.Builder() .setLayoutDirection(layoutDirection) .setSplitType(SplitAttributes.SplitType.ratio(ratio)) .build() )

  • setFinishPrimaryWithSecondary and setFinishSecondaryWithPrimary take constants similar to the FinishBehavior enum.

For more information, you can refer to SplitRule Migration.

  • Use: setMaxAspectRatioInPortrait( EmbeddingAspectRatio.ALWAYS_ALLOW ) to show splits on devices in portrait orientation.

SplitPlaceholder.Builder

  • Only the filters and placeholderIntent parameters; other properties moved to setters. For details, you can refer to SplitPairRule.Builder.

  • setFinishPrimaryWithPlaceholder expects constants like the FinishBehavior enum.

For more information, you can see Completing Behavior Migration.

  • setLayoutDirection(layoutDirection) 和 setSplitRatio(ratio) 更改为 setDefaultSplitAttributes(SplitAttributes.Builder() .setLayoutDirection(layoutDirection) .setSplitType(SplitAttributes.SplitType.ratio(ratio)) .build() )

For more information, you can refer to Layout direction migration.

  • Use: setMaxAspectRatioInPortrait( EmbeddingAspectRatio.ALWAYS_ALLOW ) to show splits on devices in portrait orientation.

complete the act

Finish behavior constants must be migrated to FinishBehavior enum-like constants:

  • FINISH_NEVER changed to FinishBehavior.NEVER

  • FINISH_ALWAYS changed to FinishBehavior.ALWAYS

  • FINISH_ADJACENT changed to FinishBehavior.ADJACENT

layout direction

The layout direction must be migrated to SplitAttributes.LayoutDirection:

  • Change ltr to SplitAttributes.LayoutDirection.LEFT_TO_RIGHT

  • Change rtl to SplitAttributes.LayoutDirection.RIGHT_TO_LEFT

  • Change locale to SplitAttributes.LayoutDirection.LOCALE

  • Migrate splitRatio to SplitAttributes.SplitType.ratio(splitRatio)

2efdd52ad91a8512c535e8e67f37f658.png

Getting Started

To start using WindowManager, you can add the Google Maven repository to your application's settings.gradle or project-level build.gradle file:

dependencyResolutionManagement {


    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)


    repositories {


        google()


    }


}

Then 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'


    . . .


}

Good luck authoring with WindowManager! You are also welcome to continue to pay attention to the "Android Developer" WeChat official account to learn more about development technologies and product updates in a timely manner.

ede3955a55f6cdda0eea2a1db47f6448.gif

recommended reading

If the page does not load, please refresh and try again

9a24327d1aeaebd8845c13ac5e1111cb.gif Click at the end of the screen read the original text  |  learn more about WindowManager immediately 


4f639065cc7d24a8344dd6c8afe6bb1e.png

Guess you like

Origin blog.csdn.net/m0_57546986/article/details/130818402