ScreenOrientation


class ScreenOrientation


Helper for resolving screen orientations.

Summary

Public functions

java-static Int
getScreenOrientationFromRotation(
    context: @UiContext Context,
    targetRotation: Int
)

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

java-static Boolean
isLandscape(context: @UiContext Context, targetRotation: Int)

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

java-static Boolean
isPortrait(context: @UiContext Context, targetRotation: Int)

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

Public functions

getScreenOrientationFromRotation

java-static fun getScreenOrientationFromRotation(
    context: @UiContext Context,
    targetRotation: Int
): Int

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
context: @UiContext Context

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

targetRotation: Int

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

java-static fun isLandscape(context: @UiContext Context, targetRotation: Int): Boolean

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

Parameters
context: @UiContext Context

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

targetRotation: Int

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

java-static fun isPortrait(context: @UiContext Context, targetRotation: Int): Boolean

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

Parameters
context: @UiContext Context

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

targetRotation: Int

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