# SplitRule

Artifact: [androidx.window:window](https://developer.android.com/jetpack/androidx/releases/window) [View Source](https://cs.android.com/search?q=file:androidx/window/embedding/SplitRule.kt+class:androidx.window.embedding.SplitRule) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/window#1.0.0)

*** ** * ** ***

<br />

```
public class SplitRule extends EmbeddingRule
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.window.embedding.EmbeddingRule](https://developer.android.com/reference/androidx/window/embedding/EmbeddingRule) ||
|   | ↳ | [androidx.window.embedding.SplitRule](https://developer.android.com/reference/androidx/window/embedding/SplitRule) |

Known direct subclasses [SplitPairRule](https://developer.android.com/reference/androidx/window/embedding/SplitPairRule), [SplitPinRule](https://developer.android.com/reference/androidx/window/embedding/SplitPinRule), [SplitPlaceholderRule](https://developer.android.com/reference/androidx/window/embedding/SplitPlaceholderRule)

|---|---|
| `https://developer.android.com/reference/androidx/window/embedding/SplitPairRule` | Split configuration rules for activity pairs. |
| `https://developer.android.com/reference/androidx/window/embedding/SplitPinRule` | Split configuration rules for pinning an `https://developer.android.com/reference/androidx/window/embedding/ActivityStack`. |
| `https://developer.android.com/reference/androidx/window/embedding/SplitPlaceholderRule` | Configuration rules for split placeholders. |

*** ** * ** ***

Split configuration rules for activities that are launched to side in a split. Define the visual properties of the split. Can be set either via `https://developer.android.com/reference/androidx/window/embedding/RuleController#setRules(kotlin.collections.Set)` or via `https://developer.android.com/reference/androidx/window/embedding/RuleController#addRule(androidx.window.embedding.EmbeddingRule)`. The rules are always applied only to activities that will be started after the rules were set.

Note that regardless of whether the minimal requirements (`https://developer.android.com/reference/androidx/window/embedding/SplitRule#minWidthDp()`, `https://developer.android.com/reference/androidx/window/embedding/SplitRule#minHeightDp()` and `https://developer.android.com/reference/androidx/window/embedding/SplitRule#minSmallestWidthDp()`) are met or not, the callback set in `https://developer.android.com/reference/androidx/window/embedding/SplitController#setSplitAttributesCalculator(kotlin.Function1)` will still be called for the rule if the calculator is registered via `https://developer.android.com/reference/androidx/window/embedding/SplitController#setSplitAttributesCalculator(kotlin.Function1)`. Whether this `https://developer.android.com/reference/androidx/window/embedding/SplitRule`'s minimum requirements are satisfied is dispatched in `https://developer.android.com/reference/androidx/window/embedding/SplitAttributesCalculatorParams#areDefaultConstraintsSatisfied()` instead. The width and height could be verified in the `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes` calculator callback as the sample linked below shows.

It is useful if this `https://developer.android.com/reference/androidx/window/embedding/SplitRule` is supported to split the parent container in different directions with different device states.

```kotlin
import androidx.window.embedding.EmbeddingAnimationBackground
import androidx.window.embedding.EmbeddingAnimationParams
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 split with the dimension that larger than 600 DP. If there's no dimension
    // larger than 600 DP, show the presentation to fill the task bounds.
    val parentConfiguration = params.parentConfiguration
    val builder = SplitAttributes.Builder()
    return@setSplitAttributesCalculator if (parentConfiguration.screenWidthDp >= 600) {
        builder
            .setLayoutDirection(SplitAttributes.LayoutDirection.LOCALE)
            // Optionally set the animation background and change transition animation to use
            // when switching between vertical and horizontal
            .setAnimationParams(
                EmbeddingAnimationParams.Builder()
                    .setAnimationBackground(
                        EmbeddingAnimationBackground.createColorBackground(Color.GRAY)
                    )
                    .setChangeAnimation(EmbeddingAnimationParams.AnimationSpec.JUMP_CUT)
                    .build()
            )
            .build()
    } else if (parentConfiguration.screenHeightDp >= 600) {
        builder
            .setLayoutDirection(SplitAttributes.LayoutDirection.TOP_TO_BOTTOM)
            // Optionally set the animation background and change transition animation to use
            // when switching between vertical and horizontal
            .setAnimationParams(
                EmbeddingAnimationParams.Builder()
                    .setAnimationBackground(
                        EmbeddingAnimationBackground.createColorBackground(Color.GRAY)
                    )
                    .setChangeAnimation(EmbeddingAnimationParams.AnimationSpec.JUMP_CUT)
                    .build()
            )
            .build()
    } else {
        // Fallback to expand the secondary container
        builder.setSplitType(SPLIT_TYPE_EXPAND).build()
    }
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/window/embedding/SplitPairRule` |   |
| `https://developer.android.com/reference/androidx/window/embedding/SplitPlaceholderRule` |   |

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/window/embedding/SplitRule.FinishBehavior` Determines what happens with the associated container when all activities are finished in one of the containers in a split. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_ALWAYS_ALLOW() = 0` When the min dimension is set to this value, it means to always allow split. |
| `static final int` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_DP_DEFAULT() = 600` The default min dimension in DP for allowing split if it is not set by apps. |

| ### Public fields |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/EmbeddingAspectRatio` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#SPLIT_MAX_ASPECT_RATIO_LANDSCAPE_DEFAULT()` The default max aspect ratio for allowing split when the parent window is in landscape. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/EmbeddingAspectRatio` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#SPLIT_MAX_ASPECT_RATIO_PORTRAIT_DEFAULT()` The default max aspect ratio for allowing split when the parent window is in portrait. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/SplitAttributes` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#getDefaultSplitAttributes()()` The default `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes` to apply on the activity containers pair when the host task bounds satisfy `https://developer.android.com/reference/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)`, `https://developer.android.com/reference/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)`, `https://developer.android.com/reference/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)`, `https://developer.android.com/reference/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)` and `https://developer.android.com/reference/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)` requirements. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/EmbeddingAspectRatio` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#getMaxAspectRatioInLandscape()()` The largest value of the aspect ratio, expressed as `width / height` in decimal form, of the parent window bounds in landscape when the split should be used. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/EmbeddingAspectRatio` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#getMaxAspectRatioInPortrait()()` The largest value of the aspect ratio, expressed as `height / width` in decimal form, of the parent window bounds in portrait when the split should be used. |
| `final int` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#getMinHeightDp()()` The smallest value of height of the parent task window when the split should be used, in DP. |
| `final int` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#getMinSmallestWidthDp()()` The smallest value of the smallest possible width of the parent task window in any rotation when the split should be used, in DP. |
| `final int` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#getMinWidthDp()()` The smallest value of width of the parent task window when the split should be used, in DP. |
| `int` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#hashCode()()` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/window/embedding/SplitRule#toString()()` |

### Inherited methods

From [androidx.window.embedding.EmbeddingRule](https://developer.android.com/reference/androidx/window/embedding/EmbeddingRule) `final https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/androidx/window/embedding/EmbeddingRule#getTag()()`

A unique string to identify this `https://developer.android.com/reference/androidx/window/embedding/EmbeddingRule`, which defaults to `null`.

## Constants

### SPLIT_MIN_DIMENSION_ALWAYS_ALLOW

```
public static final int SPLIT_MIN_DIMENSION_ALWAYS_ALLOW = 0
```

When the min dimension is set to this value, it means to always allow split.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/window/embedding/SplitRule#minWidthDp()` |   |
| `https://developer.android.com/reference/androidx/window/embedding/SplitRule#minSmallestWidthDp()` |   |

### SPLIT_MIN_DIMENSION_DP_DEFAULT

```
public static final int SPLIT_MIN_DIMENSION_DP_DEFAULT = 600
```

The default min dimension in DP for allowing split if it is not set by apps. The value reflects `https://developer.android.com/reference/androidx/window/core/layout/WindowWidthSizeClass#MEDIUM()`.

## Public fields

### SPLIT_MAX_ASPECT_RATIO_LANDSCAPE_DEFAULT

```
public static final @NonNull EmbeddingAspectRatio SPLIT_MAX_ASPECT_RATIO_LANDSCAPE_DEFAULT
```

The default max aspect ratio for allowing split when the parent window is in landscape.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/window/embedding/SplitRule#maxAspectRatioInLandscape()` |   |

### SPLIT_MAX_ASPECT_RATIO_PORTRAIT_DEFAULT

```
public static final @NonNull EmbeddingAspectRatio SPLIT_MAX_ASPECT_RATIO_PORTRAIT_DEFAULT
```

The default max aspect ratio for allowing split when the parent window is in portrait.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/window/embedding/SplitRule#maxAspectRatioInPortrait()` |   |

## Public methods

### equals

```
public boolean equals(Object other)
```

### getDefaultSplitAttributes

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/window#1.1.0)

```
public final @NonNull SplitAttributes getDefaultSplitAttributes()
```

The default `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes` to apply on the activity containers pair when the host task bounds satisfy `https://developer.android.com/reference/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)`, `https://developer.android.com/reference/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)`, `https://developer.android.com/reference/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)`, `https://developer.android.com/reference/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)` and `https://developer.android.com/reference/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)` requirements.

It is set to split the host parent task vertically and equally by default.

### getMaxAspectRatioInLandscape

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/window#1.1.0)

```
public final @NonNull EmbeddingAspectRatio getMaxAspectRatioInLandscape()
```

The largest value of the aspect ratio, expressed as `width / height` in decimal form, of the parent window bounds in landscape when the split should be used. When the window aspect ratio is greater than requested here, activities in the secondary container will be stacked on top of the activities in the primary one, completely overlapping them.

This value is only used when the parent window is in landscape (width \> height).

The default is `https://developer.android.com/reference/androidx/window/embedding/SplitRule#SPLIT_MAX_ASPECT_RATIO_LANDSCAPE_DEFAULT()`, which is the recommend value to always allow split when the parent window is in landscape.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/window/embedding/EmbeddingAspectRatio#ratio(kotlin.Float)` |   |
| `https://developer.android.com/reference/androidx/window/embedding/EmbeddingAspectRatio#ALWAYS_ALLOW()` |   |
| `https://developer.android.com/reference/androidx/window/embedding/EmbeddingAspectRatio#ALWAYS_DISALLOW()` |   |

### getMaxAspectRatioInPortrait

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/window#1.1.0)

```
public final @NonNull EmbeddingAspectRatio getMaxAspectRatioInPortrait()
```

The largest value of the aspect ratio, expressed as `height / width` in decimal form, of the parent window bounds in portrait when the split should be used. When the window aspect ratio is greater than requested here, activities in the secondary container will be stacked on top of the activities in the primary one, completely overlapping them.

This value is only used when the parent window is in portrait (height \>= width).

The default is `https://developer.android.com/reference/androidx/window/embedding/SplitRule#SPLIT_MAX_ASPECT_RATIO_PORTRAIT_DEFAULT()`, which is the recommend value to only allow split when the parent window is not too stretched in portrait.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/window/embedding/EmbeddingAspectRatio#ratio(kotlin.Float)` |   |
| `https://developer.android.com/reference/androidx/window/embedding/EmbeddingAspectRatio#ALWAYS_ALLOW()` |   |
| `https://developer.android.com/reference/androidx/window/embedding/EmbeddingAspectRatio#ALWAYS_DISALLOW()` |   |

### getMinHeightDp

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/window#1.1.0)

```
public final int getMinHeightDp()
```

The smallest value of height of the parent task window when the split should be used, in DP. When the window size is smaller than requested here, activities in the secondary container will be stacked on top of the activities in the primary one, completely overlapping them. It is useful if it's necessary to split the parent window horizontally for this `https://developer.android.com/reference/androidx/window/embedding/SplitRule`.

The default is `https://developer.android.com/reference/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_DP_DEFAULT()` if the app doesn't set. `https://developer.android.com/reference/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_ALWAYS_ALLOW()` means to always allow split.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.LayoutDirection#TOP_TO_BOTTOM()` |   |
| `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.LayoutDirection#BOTTOM_TO_TOP()` |   |

### getMinSmallestWidthDp

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/window#1.1.0)

```
public final int getMinSmallestWidthDp()
```

The smallest value of the smallest possible width of the parent task window in any rotation when the split should be used, in DP. When the window size is smaller than requested here, activities in the secondary container will be stacked on top of the activities in the primary one, completely overlapping them.

The default is `https://developer.android.com/reference/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_DP_DEFAULT()` if the app doesn't set. `https://developer.android.com/reference/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_ALWAYS_ALLOW()` means to always allow split.

### getMinWidthDp

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/window#1.1.0)

```
public final int getMinWidthDp()
```

The smallest value of width of the parent task window when the split should be used, in DP. When the window size is smaller than requested here, activities in the secondary container will be stacked on top of the activities in the primary one, completely overlapping them.

The default is `https://developer.android.com/reference/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_DP_DEFAULT()` if the app doesn't set. `https://developer.android.com/reference/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_ALWAYS_ALLOW()` means to always allow split.

### hashCode

```
public int hashCode()
```

### toString

```
public @NonNull String toString()
```