Jetpack WindowManager 1.4 is stable

Jetpack WindowManager 1.4 is stable

Home » News » Jetpack WindowManager 1.4 is stable
Table of Contents

Posted by Xiaodao Wu – Developer Relations Engineer

Jetpack WindowManager retains getting higher. WindowManager offers you instruments to construct adaptive apps that work seamlessly throughout all types of enormous display units. Model 1.4, which is secure now, introduces new options that make multi-window experiences much more highly effective and versatile. Whereas Jetpack Compose remains to be one of the simplest ways to create app layouts for various display sizes, 1.4 makes some massive enhancements to exercise embedding, together with exercise stack spinning, pane enlargement, and dialog full-screen dim. Multi-activity apps can simply make the most of all these nice options.

WindowManager 1.4 introduces a spread of enhancements. Listed here are a number of the highlights.

WindowSizeClass

We’ve up to date the WindowSizeClass API to assist customized values. We modified the API form to make it simple and extensible to assist customized values and add new values sooner or later. The excessive degree adjustments are as follows:

    • Opened the constructor to soak up minWidthDp and minHeightDp parameters so you possibly can create your personal window dimension lessons
    • Added comfort strategies for checking breakpoint validity
    • Deprecated WindowWidthSizeClass and WindowHeightSizeClass in favor of WindowSizeClass#isWidthAtLeastBreakpoint() and WindowSizeClass#isHeightAtLeastBreakpoint() respectively

Right here’s a migration instance:

// outdated 

val sizeClass = WindowSizeClass.compute(widthDp, heightDp)
when (sizeClass.widthSizeClass) {
  COMPACT -> doCompact()
  MEDIUM -> doMedium()
  EXPANDED -> doExpanded()
  else -> doDefault()
}

// new
val sizeClass = WindowSizeClass.BREAKPOINTS_V1
                               .computeWindowSizeClass(widthDp, heightDp)

when {
  sizeClass.isWidthAtLeastBreakpoint(WIDTH_DP_EXPANDED_LOWER_BOUND) -> {
    doExpanded()
  }
  sizeClass.isWidthAtLeastBreakpoint(WIDTH_DP_MEDIUM_LOWER_BOUND) -> {
    doMedium()
  }
  else -> {
    doCompact()
  }
}

Some issues to notice within the new API:

    • The order of the when branches ought to go from largest to smallest to assist customized values from builders or new values sooner or later
    • The default department ought to be handled because the smallest window dimension class

Exercise embedding

Exercise stack pinning

Exercise stack pinning gives a technique to maintain an exercise stack at all times on display, it doesn’t matter what else is occurring in your app. This new characteristic enables you to pin an exercise stack to a particular window, so the highest exercise stays seen even when the person navigates to different components of the app in a special window. That is excellent for issues like stay chats or video gamers that you simply wish to carry on display whereas customers discover different content material.

personal enjoyable pinActivityStackExample(taskId: Int) {
 val splitAttributes: SplitAttributes = SplitAttributes.Builder()
   .setSplitType(SplitAttributes.SplitType.ratio(0.66f))
   .setLayoutDirection(SplitAttributes.LayoutDirection.LEFT_TO_RIGHT)
   .construct()

 val pinSplitRule = SplitPinRule.Builder()
   .setDefaultSplitAttributes(splitAttributes)
   .construct()

 SplitController.getInstance(applicationContext).pinTopActivityStack(taskId, pinSplitRule)
}

Pane enlargement

The brand new pane enlargement characteristic, also referred to as interactive divider, enables you to create a visible separation between two actions in split-screen mode. You can also make the pane divider draggable so customers can resize the panes – and the actions within the panes – on the fly. This offers customers management over how they wish to view the app’s content material.

val splitAttributesBuilder: SplitAttributes.Builder = SplitAttributes.Builder()
   .setSplitType(SplitAttributes.SplitType.ratio(0.33f))
   .setLayoutDirection(SplitAttributes.LayoutDirection.LEFT_TO_RIGHT)

if (WindowSdkExtensions.getInstance().extensionVersion >= 6) {
   splitAttributesBuilder.setDividerAttributes(
       DividerAttributes.DraggableDividerAttributes.Builder()
           .setColor(getColor(context, R.coloration.divider_color))
           .setWidthDp(4)
           .setDragRange(
               DividerAttributes.DragRange.DRAG_RANGE_SYSTEM_DEFAULT)
           .construct()
   )
}
val splitAttributes: SplitAttributes = splitAttributesBuilder.construct()

Dialog full-screen dim

WindowManager 1.4 offers you extra management over how dialogs dim the background. With dialog full-screen dim, you possibly can select to dim simply the container the place the dialog seems or the complete process window for a unified UI expertise. Your entire app window dims by default when a dialog opens (see EmbeddingConfiguration.DimAreaBehavior.ON_TASK).To dim solely the container of the exercise that opened the dialog, use EmbeddingConfiguration.DimAreaBehavior.ON_ACTIVITY_STACK. This offers you extra flexibility in designing dialogs and makes for a smoother, extra coherent person expertise. Temu is among the many first builders to combine this characteristic, the full-screen dialog dim has lowered display invalid touches by about 5%.

Customised shopping cart reminder with dialog full-screen dim in the Temu app

Customised buying cart reminder with dialog full-screen dim in Temu.

Enhanced posture assist

WindowManager 1.4 makes constructing apps that work flawlessly on foldables easy by offering extra details about the bodily capabilities of the system. The brand new WindowInfoTracker#supportedPostures API lets you recognize if a tool helps tabletop mode, so you possibly can optimize your app’s format and options accordingly.

val currentSdkVersion = WindowSdkExtensions.getInstance().extensionVersion
val message =
if (currentSdkVersion >= 6) {
  val supportedPostures = WindowInfoTracker.getOrCreate(LocalContext.present).supportedPostures
  buildString {
    append(supportedPostures.isNotEmpty())
    if (supportedPostures.isNotEmpty()) {
      append(" ")
      append(
      supportedPostures.joinToString(
      separator = ",", prefix = "(", postfix = ")"))
    }
  }
} else {
  "N/A (WindowSDK model 6 is required, present model is $currentSdkVersion)"
}

Different API adjustments

WindowManager 1.4 consists of a number of API adjustments and additions to assist the brand new options. Notable adjustments embody:

    • Steady and not experimental APIs:
      • ActivityEmbeddingController#invalidateVisibleActivityStacks
      • ActivityEmbeddingController#getActivityStack
      • SplitController#updateSplitAttributes
    • API added to set exercise embedding animation background:
      • SplitAttributes.Builder#setAnimationParams
    • API to get up to date WindowMetrics info:
      • ActivityEmbeddingController#embeddedActivityWindowInfo
    • API to complete all actions in an exercise stack:
      • ActivityEmbeddingController#finishActivityStack

The best way to get began

To start out utilizing Jetpack WindowManager 1.4 in your Android tasks, replace your app dependencies in construct.gradle.kts to the newest secure model:

dependencies {
    implementation("androidx.window:window:1.4.0") 
    // or, should you're utilizing the WindowManager testing library:
    testImplementation("androidx.window:window-testing:1.4.0")
}

Pleased coding!

Supply hyperlink

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 
share this article.

related posts .

Enjoying my articles?

Sign up to get new content delivered straight to your inbox.

Please enable JavaScript in your browser to complete this form.
Name