WindowSizeClass


public final class WindowSizeClass


WindowSizeClass represents breakpoints for a viewport. 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 WindowSizeClass.WIDTH_DP_EXPANDED_LOWER_BOUND width it might be more reasonable to have a side navigation.

An application use-case can be applied for apps that use a list-detail pattern. The app can use the WindowSizeClass.WIDTH_DP_MEDIUM_LOWER_BOUND 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.

To process a WindowSizeClass use the methods isAtLeastBreakpoint, isWidthAtLeastBreakpoint, isHeightAtLeastBreakpoint methods. Note these methods are order dependent as the smaller minWidthDp and minHeightDp would match all the breakpoints that are larger. Therefore when processing the selection should normally be ordered from larger to smaller breakpoints.

Summary

Constants

static final int

A lower bound for a size class with Expanded height in dp.

static final int

A lower bound for a size class with Medium height in dp.

static final int

A lower bound for a size class with Expanded width in dp.

static final int

A lower bound for a size class with Medium width in dp.

Public fields

static final @NonNull Set<@NonNull WindowSizeClass>

Public constructors

WindowSizeClass(int minWidthDp, int minHeightDp)
WindowSizeClass(float widthDp, float heightDp)

A convenience constructor that will truncate to ints.

Public methods

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

This method is deprecated. Use computeWindowSizeClass instead.

boolean
equals(Object other)
final int

Returns the lower bound for the height of the size class in dp.

final int

Returns the lower bound for the width of the size class in dp.

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
final boolean
isAtLeastBreakpoint(int widthDpBreakpoint, int heightDpBreakpoint)

Returns true when minWidthDp is greater than or equal to widthDpBreakpoint and minHeightDp is greater than or equal to heightDpBreakpoint, false otherwise.

final boolean
isHeightAtLeastBreakpoint(int heightDpBreakpoint)

Returns true when minHeightDp is greater than or equal to heightDpBreakpoint, false otherwise.

final boolean
isWidthAtLeastBreakpoint(int widthDpBreakpoint)

Returns true when minWidthDp is greater than or equal to widthDpBreakpoint, false otherwise.

@NonNull String

Constants

HEIGHT_DP_EXPANDED_LOWER_BOUND

public static final int HEIGHT_DP_EXPANDED_LOWER_BOUND = 900

A lower bound for a size class with Expanded height in dp.

HEIGHT_DP_MEDIUM_LOWER_BOUND

public static final int HEIGHT_DP_MEDIUM_LOWER_BOUND = 480

A lower bound for a size class with Medium height in dp.

WIDTH_DP_EXPANDED_LOWER_BOUND

public static final int WIDTH_DP_EXPANDED_LOWER_BOUND = 840

A lower bound for a size class with Expanded width in dp.

WIDTH_DP_MEDIUM_LOWER_BOUND

public static final int WIDTH_DP_MEDIUM_LOWER_BOUND = 600

A lower bound for a size class with Medium width in dp.

Public fields

BREAKPOINTS_V1

public static final @NonNull Set<@NonNull WindowSizeClassBREAKPOINTS_V1

Public constructors

WindowSizeClass

Added in 1.4.0-alpha05
public WindowSizeClass(int minWidthDp, int minHeightDp)

WindowSizeClass

Added in 1.4.0-alpha05
public WindowSizeClass(float widthDp, float heightDp)

A convenience constructor that will truncate to ints.

Public methods

compute

Added in 1.1.0
Deprecated in 1.4.0-alpha05
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.

equals

public boolean equals(Object other)

getMinHeightDp

Added in 1.4.0-alpha05
public final int getMinHeightDp()

Returns the lower bound for the height of the size class in dp.

getMinWidthDp

Added in 1.4.0-alpha05
public final int getMinWidthDp()

Returns the lower bound for the width of the size class in dp.

getWindowHeightSizeClass

Added in 1.1.0
Deprecated in 1.4.0-alpha05
public final @NonNull WindowHeightSizeClass getWindowHeightSizeClass()

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

getWindowWidthSizeClass

Added in 1.1.0
Deprecated in 1.4.0-alpha05
public final @NonNull WindowWidthSizeClass getWindowWidthSizeClass()

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

hashCode

public int hashCode()

isAtLeastBreakpoint

Added in 1.4.0-alpha05
public final boolean isAtLeastBreakpoint(int widthDpBreakpoint, int heightDpBreakpoint)

Returns true when minWidthDp is greater than or equal to widthDpBreakpoint and minHeightDp is greater than or equal to heightDpBreakpoint, false otherwise. When processing a WindowSizeClass note that this method is order dependent. Selection should go from largest to smallest breakpoints.

isHeightAtLeastBreakpoint

Added in 1.4.0-alpha05
public final boolean isHeightAtLeastBreakpoint(int heightDpBreakpoint)

Returns true when minHeightDp is greater than or equal to heightDpBreakpoint, false otherwise. When processing a WindowSizeClass note that this method is order dependent. Selection should go from largest to smallest breakpoints.

isWidthAtLeastBreakpoint

Added in 1.4.0-alpha05
public final boolean isWidthAtLeastBreakpoint(int widthDpBreakpoint)

Returns true when minWidthDp is greater than or equal to widthDpBreakpoint, false otherwise. When processing a WindowSizeClass note that this method is order dependent. Selection should go from largest to smallest breakpoints.

toString

public @NonNull String toString()