SplitAttributes.SplitType


public final class SplitAttributes.SplitType


The type of parent window split, which defines the proportion of the parent window occupied by the primary and secondary activity containers.

Summary

Public fields

static final @NonNull SplitAttributes.SplitType

A split type in which the primary and secondary containers occupy equal portions of the parent window.

static final @NonNull SplitAttributes.SplitType

A split type in which the primary and secondary activity containers each expand to fill the parent window; the secondary container overlays the primary container.

static final @NonNull SplitAttributes.SplitType

A split type in which the split ratio conforms to the position of a hinge or separating fold in the device display.

Public methods

boolean
equals(Object other)

Determines whether this object is the same type of split as the compared object.

int

Returns a hash code for this split type.

static final @NonNull SplitAttributes.SplitType
ratio(
    @FloatRange(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false) float ratio
)

Creates a split type based on the proportion of the parent window occupied by the primary container of the split.

@NonNull String

A string representation of this split type.

Public fields

SPLIT_TYPE_EQUAL

public static final @NonNull SplitAttributes.SplitType SPLIT_TYPE_EQUAL

A split type in which the primary and secondary containers occupy equal portions of the parent window.

Serves as the default SplitType.

SPLIT_TYPE_EXPAND

public static final @NonNull SplitAttributes.SplitType SPLIT_TYPE_EXPAND

A split type in which the primary and secondary activity containers each expand to fill the parent window; the secondary container overlays the primary container.

It is useful to use this SplitType with the function set in SplitController.setSplitAttributesCalculator to expand the activity containers in some device or window states. The following sample shows how to always fill the parent bounds if the device is in portrait orientation:

import androidx.window.embedding.SplitAttributes
import androidx.window.embedding.SplitAttributes.SplitType.Companion.SPLIT_TYPE_EXPAND
import androidx.window.embedding.SplitController

SplitController.getInstance(context)
    .setSplitAttributesCalculator { params ->
        // A sample to always fill task bounds when the device is in portrait.
        val tag = params.splitRuleTag
        val bounds = params.parentWindowMetrics.bounds
        val defaultSplitAttributes = params.defaultSplitAttributes
        val areDefaultConstraintsSatisfied = params.areDefaultConstraintsSatisfied

        val expandContainersAttrs = SplitAttributes.Builder()
            .setSplitType(SPLIT_TYPE_EXPAND)
            .build()
        if (!areDefaultConstraintsSatisfied) {
            return@setSplitAttributesCalculator expandContainersAttrs
        }
        // Always expand containers for the splitRule tagged as
        // TAG_SPLIT_RULE_EXPAND_IN_PORTRAIT if the device is in portrait
        // even if [areDefaultConstraintsSatisfied] reports true.
        if (bounds.height() > bounds.width() && TAG_SPLIT_RULE_EXPAND_IN_PORTRAIT == tag) {
            return@setSplitAttributesCalculator expandContainersAttrs
        }
        // Otherwise, use the default splitAttributes.
        return@setSplitAttributesCalculator defaultSplitAttributes
    }

SPLIT_TYPE_HINGE

public static final @NonNull SplitAttributes.SplitType SPLIT_TYPE_HINGE

A split type in which the split ratio conforms to the position of a hinge or separating fold in the device display.

The split type works only if:

  • The host task is not in multi-window mode (e.g., split-screen mode or picture-in-picture mode)
  • The device has a hinge or separating fold reported by [androidx.window.layout.FoldingFeature.isSeparating]
  • The hinge or separating fold orientation matches how the parent bounds are split:
    • The hinge or fold orientation is vertical, and the parent bounds are also split vertically (containers are side by side)
    • The hinge or fold orientation is horizontal, and the parent bounds are also split horizontally (containers are top and bottom)

Otherwise, this SplitType fallback to show the split with SPLIT_TYPE_EQUAL.

If the app wants to have another fallback SplitType if SPLIT_TYPE_HINGE cannot be applied. It is suggested to use SplitController.setSplitAttributesCalculator to customize the fallback SplitType.

The following sample shows how to fallback to SPLIT_TYPE_EXPAND if there's no hinge area in the parent window container bounds.

import androidx.window.embedding.SplitAttributes
import androidx.window.embedding.SplitAttributes.SplitType.Companion.SPLIT_TYPE_EXPAND
import androidx.window.embedding.SplitAttributes.SplitType.Companion.SPLIT_TYPE_HINGE
import androidx.window.embedding.SplitController
import androidx.window.layout.FoldingFeature

SplitController.getInstance(context).setSplitAttributesCalculator { params ->
    SplitAttributes.Builder()
        .setSplitType(
            if (params.parentWindowLayoutInfo.displayFeatures
                    .filterIsInstance<FoldingFeature>().isNotEmpty()) {
                SPLIT_TYPE_HINGE
            } else {
                SPLIT_TYPE_EXPAND
            }
        ).build()
}

Public methods

equals

public boolean equals(Object other)

Determines whether this object is the same type of split as the compared object.

Parameters
Object other

The object to compare to this object.

Returns
boolean

True if the objects are the same split type, false otherwise.

hashCode

public int hashCode()

Returns a hash code for this split type.

Returns
int

The hash code for this object.

ratio

Added in 1.1.0
public static final @NonNull SplitAttributes.SplitType ratio(
    @FloatRange(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false) float ratio
)

Creates a split type based on the proportion of the parent window occupied by the primary container of the split.

Values in the non-inclusive range (0.0, 1.0) define the size of the primary container relative to the size of the parent window:

  • 0.5 — Primary container occupies half of the parent window; secondary container, the other half

  • > 0.5 — Primary container occupies a larger proportion of the parent window than the secondary container

  • < 0.5 — Primary container occupies a smaller proportion of the parent window than the secondary container

Parameters
@FloatRange(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false) float ratio

The proportion of the parent window occupied by the primary container of the split.

Returns
@NonNull SplitAttributes.SplitType

An instance of SplitType with the specified ratio.

toString

public @NonNull String toString()

A string representation of this split type.

Returns
@NonNull String

The string representation of the object.