public final class DevicePosture

  1. Object
  2. DevicePosture

Describes the physical fold posture of a foldable or dual screen device such as a Galaxy Fold, Galaxy Flip, Pixel Fold or Surface Duo.

Obtain the live posture with DevicePosture#getInstance(). The returned object reads the current posture on demand, so a single instance can be kept and queried whenever needed; it is never null. On devices that are not foldable, or platforms that do not report fold information, the posture is POSTURE_UNKNOWN, #isFoldable() is false and #getFoldBounds(Rectangle) returns null.

To be notified when the device is folded, unfolded or changes posture register a listener with com.codename1.ui.Display#addPostureListener(com.codename1.ui.events.ActionListener).

When the fold separates the screen into two logical areas (book or tabletop posture) the hinge rectangle returned by #getFoldBounds(Rectangle) reports the region the hinge occludes, similar to the way com.codename1.ui.Form#getSafeArea() reports the area obscured by a notch. Lay out interactive content to avoid that region, or split a master and detail experience across the two halves.

Fields

public static final int POSTURE_UNKNOWN = 0The posture could not be determined, typically because the device is not foldable.
public static final int POSTURE_FLAT = 1The device is open and flat (a continuous surface).
public static final int POSTURE_HALF_OPENED = 2The device is half opened, forming a laptop, book or tabletop posture with the hinge between roughly 30 and 150 degrees.
public static final int POSTURE_CLOSED = 3The device is folded shut.
public static final int FOLD_ORIENTATION_NONE = 0There is no fold separating the display.
public static final int FOLD_ORIENTATION_VERTICAL = 1The hinge runs vertically, splitting the display into a left and a right half.
public static final int FOLD_ORIENTATION_HORIZONTAL = 2The hinge runs horizontally, splitting the display into a top and a bottom half.

Methods

public static DevicePosture getInstance()Returns the shared device posture instance.
public boolean isFoldable()True if the device is a foldable or dual screen device.
public int getPosture()The current posture, one of the POSTURE_* constants.
public int getHingeAngle()The current hinge angle in degrees between 0 (closed) and 180 (flat), or -1 when the device does not report a hinge angle.
public int getFoldOrientation()The orientation of the fold, one of the FOLD_ORIENTATION_* constants.
public boolean isSeparating()True if the fold currently separates the display into two distinct logical areas (a book or tabletop posture) rather than presenting a single continuous surface.
public boolean isTableTop()True if the device is in a tabletop or book posture (half opened and separating the display).
public Rectangle getFoldBounds(Rectangle rect)Returns the bounds of the region occluded by the hinge in display coordinates, or null when there is no separating fold.

Inherited methods

Field details

POSTURE_UNKNOWN

public static final int POSTURE_UNKNOWN = 0
The posture could not be determined, typically because the device is not foldable.

POSTURE_FLAT

public static final int POSTURE_FLAT = 1
The device is open and flat (a continuous surface). This is the normal posture of an unfolded device and the only posture reported by non-foldable devices that still report fold state.

POSTURE_HALF_OPENED

public static final int POSTURE_HALF_OPENED = 2
The device is half opened, forming a laptop, book or tabletop posture with the hinge between roughly 30 and 150 degrees.

POSTURE_CLOSED

public static final int POSTURE_CLOSED = 3
The device is folded shut.

FOLD_ORIENTATION_NONE

public static final int FOLD_ORIENTATION_NONE = 0
There is no fold separating the display.

FOLD_ORIENTATION_VERTICAL

public static final int FOLD_ORIENTATION_VERTICAL = 1
The hinge runs vertically, splitting the display into a left and a right half.

FOLD_ORIENTATION_HORIZONTAL

public static final int FOLD_ORIENTATION_HORIZONTAL = 2
The hinge runs horizontally, splitting the display into a top and a bottom half.

Method details

getInstance

public static DevicePosture getInstance()
Returns the shared device posture instance. The returned object reads live posture data, so the same instance reflects the current posture every time it is queried.

Returns

the shared device posture, never null

isFoldable

public boolean isFoldable()
True if the device is a foldable or dual screen device.

getPosture

public int getPosture()
The current posture, one of the POSTURE_* constants.

getHingeAngle

public int getHingeAngle()
The current hinge angle in degrees between 0 (closed) and 180 (flat), or -1 when the device does not report a hinge angle.

getFoldOrientation

public int getFoldOrientation()
The orientation of the fold, one of the FOLD_ORIENTATION_* constants.

isSeparating

public boolean isSeparating()
True if the fold currently separates the display into two distinct logical areas (a book or tabletop posture) rather than presenting a single continuous surface.

isTableTop

public boolean isTableTop()
True if the device is in a tabletop or book posture (half opened and separating the display).

getFoldBounds

public Rectangle getFoldBounds(Rectangle rect)
Returns the bounds of the region occluded by the hinge in display coordinates, or null when there is no separating fold. When the fold is a thin crease the rectangle has zero width or height along the hinge.

Parameters

rect Rectangle
a rectangle to populate and return, or null to allocate a new one

Returns

the hinge bounds, or null when there is no separating fold