# WindowMetricsCalculatorRule

Artifact: [androidx.window:window-testing](https://developer.android.com/jetpack/androidx/releases/window) [View Source](https://cs.android.com/search?q=file:androidx/window/testing/layout/WindowMetricsCalculatorRule.kt+class:androidx.window.testing.layout.WindowMetricsCalculatorRule) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/window#1.2.0)

*** ** * ** ***


```
class WindowMetricsCalculatorRule : TestRule
```

<br />

*** ** * ** ***

A `https://junit.org/junit4/javadoc/latest/org/junit/rules/TestRule.html` that will sub out the actual `https://developer.android.com/reference/kotlin/androidx/window/layout/WindowMetricsCalculator` with a more simple one that will support testing independent of the current platform. The fake `https://developer.android.com/reference/kotlin/androidx/window/layout/WindowMetricsCalculator` that is used will return the width and height from the `https://developer.android.com/reference/android/util/DisplayMetrics.html` associated to an `https://developer.android.com/reference/android/app/Activity.html`. The result of `https://developer.android.com/reference/kotlin/androidx/window/layout/WindowMetricsCalculator#computeCurrentWindowMetrics(android.app.Activity)` and `https://developer.android.com/reference/kotlin/androidx/window/layout/WindowMetricsCalculator#computeMaximumWindowMetrics(android.app.Activity)` will be the same. For accurate results use the Espresso Test framework with an actual `https://developer.android.com/reference/android/app/Activity.html` and use the actual `https://developer.android.com/reference/kotlin/androidx/window/layout/WindowMetricsCalculator`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/window/testing/layout/WindowMetricsCalculatorRule#WindowMetricsCalculatorRule()()` |

| ### Public functions |
|---|---|
| `open https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html` | `https://developer.android.com/reference/kotlin/androidx/window/testing/layout/WindowMetricsCalculatorRule#apply(org.junit.runners.model.Statement,org.junit.runner.Description)(base: https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html, description: https://junit.org/junit4/javadoc/latest/org/junit/runner/Description.html)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/testing/layout/WindowMetricsCalculatorRule#overrideCurrentWindowBounds(androidx.window.layout.WindowMetrics)(windowMetrics: https://developer.android.com/reference/kotlin/androidx/window/layout/WindowMetrics)` Overrides the window bounds with a new `https://developer.android.com/reference/kotlin/androidx/window/layout/WindowMetrics`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/testing/layout/WindowMetricsCalculatorRule#overrideCurrentWindowBounds(kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int)(left: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, top: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, right: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bottom: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Overrides the window bounds with a new rectangle defined by the specified coordinates. |

## Public constructors

### WindowMetricsCalculatorRule

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

```
WindowMetricsCalculatorRule()
```

## Public functions

### apply

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

```
open fun apply(base: Statement, description: Description): Statement
```

### overrideCurrentWindowBounds

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

```
fun overrideCurrentWindowBounds(windowMetrics: WindowMetrics): Unit
```

Overrides the window bounds with a new `https://developer.android.com/reference/kotlin/androidx/window/layout/WindowMetrics`.

### overrideCurrentWindowBounds

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

```
fun overrideCurrentWindowBounds(left: Int, top: Int, right: Int, bottom: Int): Unit
```

Overrides the window bounds with a new rectangle defined by the specified coordinates.