ScreenOrientation


public final class ScreenOrientation


Helper for resolving screen orientations.

Summary

Public methods

static int
getScreenOrientationFromRotation(
    @NonNull @UiContext Context context,
    int targetRotation
)

Resolves a raw rotation angle into one of the four 4-way screen orientations relative to the specified UI Context.

static boolean
isLandscape(@NonNull @UiContext Context context, int targetRotation)

Resolves a raw rotation angle for the specified UI Context and returns whether the resulting visual orientation is landscape (landscape or reverse landscape).

static boolean
isPortrait(@NonNull @UiContext Context context, int targetRotation)

Resolves a raw rotation angle for the specified UI Context and returns whether the resulting visual orientation is portrait (portrait or reverse portrait).

Public methods

getScreenOrientationFromRotation

public static int getScreenOrientationFromRotation(
    @NonNull @UiContext Context context,
    int targetRotation
)

Resolves a raw rotation angle into one of the four 4-way screen orientations relative to the specified UI Context.

Raw rotation values (such as those from rotation sensors or getRotation) do not always map directly to standard screen orientations. For example, on landscape-natural devices (such as many tablets and foldables), ROTATION_0 corresponds to landscape rather than portrait, and devices with reverse-default rotation configurations invert 90-degree and 270-degree rotation directions.

Note: For general static layout decisions, applications should rely directly on orientation via context.getResources().getConfiguration().orientation. Use this method when converting rotation angles into ActivityInfo screen orientation constants.

Parameters
@NonNull @UiContext Context context

the visual UI Context (e.g., Activity or WindowContext)

int targetRotation

the rotation angle to evaluate, defined by Surface constants (e.g., ROTATION_0, ROTATION_90, ROTATION_180, or ROTATION_270)

Value is one of the following:

  • Surface.ROTATION_0
  • Surface.ROTATION_90
  • Surface.ROTATION_180
  • Surface.ROTATION_270

isLandscape

public static boolean isLandscape(@NonNull @UiContext Context context, int targetRotation)

Resolves a raw rotation angle for the specified UI Context and returns whether the resulting visual orientation is landscape (landscape or reverse landscape).

Parameters
@NonNull @UiContext Context context

the visual UI Context (e.g., Activity or WindowContext)

int targetRotation

the rotation angle to evaluate, defined by Surface constants (e.g., ROTATION_0, ROTATION_90, ROTATION_180, or ROTATION_270)

Value is one of the following:

  • Surface.ROTATION_0
  • Surface.ROTATION_90
  • Surface.ROTATION_180
  • Surface.ROTATION_270

Returns
boolean

true if the target rotation maps to a landscape screen orientation; false otherwise

isPortrait

public static boolean isPortrait(@NonNull @UiContext Context context, int targetRotation)

Resolves a raw rotation angle for the specified UI Context and returns whether the resulting visual orientation is portrait (portrait or reverse portrait).

Parameters
@NonNull @UiContext Context context

the visual UI Context (e.g., Activity or WindowContext)

int targetRotation

the rotation angle to evaluate, defined by Surface constants (e.g., ROTATION_0, ROTATION_90, ROTATION_180, or ROTATION_270)

Value is one of the following:

  • Surface.ROTATION_0
  • Surface.ROTATION_90
  • Surface.ROTATION_180
  • Surface.ROTATION_270

Returns
boolean

true if the target rotation maps to a portrait screen orientation; false otherwise