# WidthSizeClass.Companion

Artifact: [androidx.test.espresso:espresso-device](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/device/sizeclass/WidthSizeClass.kt+class:androidx.test.espresso.device.sizeclass.WidthSizeClass.Companion)

*** ** * ** ***


```
public static class WidthSizeClass.Companion
```

<br />

*** ** * ** ***

## Summary

| ### Nested types |
|---|
| `public enum https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum extends https://developer.android.com/reference/java/lang/Enum.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum>` |

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass` | `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass#compute(kotlin.Int)(int dpWidth)` Returns a recommended `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass` for the width of a window given the width in DP. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum` | `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass#getEnum(androidx.test.espresso.device.sizeclass.WidthSizeClass)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass sizeClass)` Returns a `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum` given the `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass`. |
| `static final int` | `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass#getWidthDpInSizeClass(androidx.test.espresso.device.sizeclass.WidthSizeClass)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass sizeClass)` Returns a recommended width of a window in DP given the `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass`. |

## Public methods

### compute

```
public static final @NonNull WidthSizeClass compute(int dpWidth)
```

Returns a recommended `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass` for the width of a window given the width in DP.

| Parameters |
|---|---|
| `int dpWidth` | the width of the window in DP |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass` | A recommended size class for the width |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the width is negative |

### getEnum

```
public static final @NonNull WidthSizeClass.Companion.WidthSizeClassEnum getEnum(@NonNull WidthSizeClass sizeClass)
```

Returns a `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum` given the `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass sizeClass` | the size class |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum` | the relevant WidthSizeClassEnum |

### getWidthDpInSizeClass

```
public static final int getWidthDpInSizeClass(@NonNull WidthSizeClass sizeClass)
```

Returns a recommended width of a window in DP given the `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass sizeClass` | the size class |

| Returns |
|---|---|
| `int` | A recommended width in DP in this size class |