03 huhtikuuta 2023
The 1.1.0-beta01 release of Jetpack WindowManager continues the library’s steady progress toward stable release of version 1.1.0. The beta adds an assortment of new features and capabilities, which are 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 a previous version of the library), and let us know what you think!
androidx.window.embedding
Activity embedding enables you to optimize your multi-activity apps for large screens. The 1.1.0-beta01 release augments and refactors the APIs to provide greater versatility, capability, and control in managing task window splits. We started with experimental APIs in 1.0.0 and are promoting them ultimately to stable in 1.1.0.
Added a manifest setting so you can inform the system your app has implemented activity embedding. Refactored SplitController to be more focused on split properties; extracted split rule APIs to RuleController and activity embedding APIs to ActivityEmbeddingController. Added the SplitAttributes class to describe embedding splits. Added the EmbeddingAspectRatio class to set a minimum ratio for applying activity embedding rules. Changed pixels units to display-independent pixels (dp). Enabled customization of split layouts. Added a tag to rules so that developers can identify and manage specific rules.
androidx.window.layout
The window layout library lets you determine features of app display windows. With the 1.1.0-beta01 release, you can now work in contexts other than just activities.
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
android:name="android.window.PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED" android:value="true">
When the property is set to true, the system can optimize split behavior for the app early.
if (SplitInfo.splitAttributes.splitType is SplitAttributes.SplitType.RatioSplitType) {
val ratio = splitInfo.splitAttributes.splitType.ratio
} else {
// Ratio is meaningless for other types.
}
COMPLEX_UNIT_DIP,
minWidthInPixels,
resources.displayMetrics
)
or simply divide minWithInPixels by displayMetrics#density.
SplitPairRule.Builder(
filters, minWidth, minSmallestWidth
)
changes 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)
setDefaultSplitAttributes(SplitAttributes.Builder()
.setLayoutDirection(layoutDirection)
.setSplitType(SplitAttributes.SplitType.ratio(ratio))
.build()
)
setFinishPrimaryWithSecondary and setFinishSecondaryWithPrimary take the FinishBehavior enum-like constants.
See SplitRule migrations for details.
Use:
setMaxAspectRatioInPortrait(
EmbeddingAspectRatio.ALWAYS_ALLOW
)
to show splits on portrait devices.Has only filters and placeholderIntent parameters; other properties move to setters.
See SplitPairRule.Builder migrations for details.
setFinishPrimaryWithPlaceholder takes the FinishBehavior enum-like constants.
See finish behavior migrations for details.
setLayoutDirection(layoutDirection)and setSplitRatio(ratio)
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 portrait devices.FINISH_NEVER changes to FinishBehavior.NEVER
FINISH_ALWAYS changes to FinishBehavior.ALWAYS
FINISH_ADJACENT changes to FinishBehavior.ADJACENT
Layout direction must be migrated to SplitAttributes.LayoutDirection:
ltr changes to SplitAttributes.LayoutDirection.LEFT_TO_RIGHT
rtl changes to SplitAttributes.LayoutDirection.RIGHT_TO_LEFT
locale changes to SplitAttributes.LayoutDirection.LOCALE
splitRatio migrates to SplitAttributes.SplitType.ratio(splitRatio)
To get started with WindowManager, add the Google Maven repository to your app’s settings.gradle or project-level build.gradle file:
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() } }
dependencies { implementation 'androidx.window:window:1.1.0-beta01' . . . }
Happy coding!