WindowSizeClass


public final class WindowSizeClass


WindowSizeClass represents breakpoints for a viewport. The recommended width and height break points are presented through windowWidthSizeClass and windowHeightSizeClass. Designers should design around the different combinations of width and height buckets. Developers should use the different buckets to specify the layouts. Ideally apps will work well in each bucket and by extension work well across multiple devices. If two devices are in similar buckets they should behave similarly.

This class is meant to be a common definition that can be shared across different device types. Application developers can use WindowSizeClass to have standard window buckets and design the UI around those buckets. Library developers can use these buckets to create different UI with respect to each bucket. This will help with consistency across multiple device types.

A library developer use-case can be creating some navigation UI library. For a size class with the WindowWidthSizeClass.EXPANDED width it might be more reasonable to have a side navigation. For a WindowWidthSizeClass.COMPACT width, a bottom navigation might be a better fit.

An application use-case can be applied for apps that use a list-detail pattern. The app can use the WindowWidthSizeClass.MEDIUM to determine if there is enough space to show the list and the detail side by side. If all apps follow this guidance then it will present a very consistent user experience.

In some cases developers or UI systems may decide to create their own break points. A developer might optimize for a window that is smaller than the supported break points or larger. A UI system might find that some break points are better suited than the recommended break points. In these cases developers may wish to specify their own custom break points and match using a when statement.

Summary

Public methods

static final @NonNull WindowSizeClass
compute(float dpWidth, float dpHeight)

Computes the recommended WindowSizeClass for the given width and height in DP.

static final @NonNull WindowSizeClass
@ExperimentalWindowCoreApi
compute(int widthPx, int heightPx, float density)

Computes the WindowSizeClass for the given width and height in pixels with density.

boolean
equals(Object other)
final @NonNull WindowHeightSizeClass

Returns the WindowHeightSizeClass that corresponds to the heightDp of the window.

final @NonNull WindowWidthSizeClass

Returns the WindowWidthSizeClass that corresponds to the widthDp of the window.

int
@NonNull String

Public methods

compute

Added in 1.1.0
public static final @NonNull WindowSizeClass compute(float dpWidth, float dpHeight)

Computes the recommended WindowSizeClass for the given width and height in DP.

Parameters
float dpWidth

width of a window in DP.

float dpHeight

height of a window in DP.

Returns
@NonNull WindowSizeClass

WindowSizeClass that is recommended for the given dimensions.

compute

Added in 1.3.0-beta02
@ExperimentalWindowCoreApi
public static final @NonNull WindowSizeClass compute(int widthPx, int heightPx, float density)

Computes the WindowSizeClass for the given width and height in pixels with density.

Parameters
int widthPx

width of a window in PX.

int heightPx

height of a window in PX.

float density

density of the display where the window is shown.

Returns
@NonNull WindowSizeClass

WindowSizeClass that is recommended for the given dimensions.

equals

public boolean equals(Object other)

getWindowHeightSizeClass

Added in 1.1.0
public final @NonNull WindowHeightSizeClass getWindowHeightSizeClass()

Returns the WindowHeightSizeClass that corresponds to the heightDp of the window.

getWindowWidthSizeClass

Added in 1.1.0
public final @NonNull WindowWidthSizeClass getWindowWidthSizeClass()

Returns the WindowWidthSizeClass that corresponds to the widthDp of the window.

hashCode

public int hashCode()

toString

public @NonNull String toString()