# SplitAttributes.SplitType

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

*** ** * ** ***


```
public final class SplitAttributes.SplitType
```

<br />

*** ** * ** ***

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 @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType` | `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType#SPLIT_TYPE_EQUAL()` A split type in which the primary and secondary containers occupy equal portions of the parent window. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType` | `https://developer.android.com/reference/androidx/window/embedding/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. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType` | `https://developer.android.com/reference/androidx/window/embedding/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. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` Determines whether this object is the same type of split as the compared object. |
| `int` | `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType#hashCode()()` Returns a hash code for this split type. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType` | `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType#ratio(kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/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. |
| `@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/SplitAttributes.SplitType#toString()()` 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 `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.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 `https://developer.android.com/reference/androidx/window/embedding/SplitController#setSplitAttributesCalculator(kotlin.Function1)` 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:

```kotlin
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 `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType#SPLIT_TYPE_EQUAL()`.

If the app wants to have another fallback `SplitType` if `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType#SPLIT_TYPE_HINGE()` cannot be applied. It is suggested to use `https://developer.android.com/reference/androidx/window/embedding/SplitController#setSplitAttributesCalculator(kotlin.Function1)` to customize the fallback `SplitType`.

The following sample shows how to fallback to `https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType#SPLIT_TYPE_EXPAND()` if there's no hinge area in the parent window container bounds.

```kotlin
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 |
|---|---|
| `https://developer.android.com/reference/java/lang/Object.html 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](https://developer.android.com/jetpack/androidx/releases/window#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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType` | An instance of `SplitType` with the specified ratio. |

### toString

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

A string representation of this split type.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | The string representation of the object. |