public final class DevicePosture
- Object
- 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 = 0 | The posture could not be determined, typically because the device is not foldable. |
public static final int POSTURE_FLAT = 1 | The device is open and flat (a continuous surface). |
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. |
public static final int POSTURE_CLOSED = 3 | The device is folded shut. |
public static final int FOLD_ORIENTATION_NONE = 0 | There is no fold separating the display. |
public static final int FOLD_ORIENTATION_VERTICAL = 1 | The hinge runs vertically, splitting the display into a left and a right half. |
public static final int FOLD_ORIENTATION_HORIZONTAL = 2 | The 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 = 0POSTURE_FLAT
public static final int POSTURE_FLAT = 1POSTURE_HALF_OPENED
public static final int POSTURE_HALF_OPENED = 2POSTURE_CLOSED
public static final int POSTURE_CLOSED = 3FOLD_ORIENTATION_NONE
public static final int FOLD_ORIENTATION_NONE = 0FOLD_ORIENTATION_VERTICAL
public static final int FOLD_ORIENTATION_VERTICAL = 1FOLD_ORIENTATION_HORIZONTAL
public static final int FOLD_ORIENTATION_HORIZONTAL = 2Method details
getInstance
public static DevicePosture getInstance()Returns
isFoldable
public boolean isFoldable()getPosture
public int getPosture()POSTURE_* constants.getHingeAngle
public int getHingeAngle()0 (closed) and 180 (flat), or -1 when the
device does not report a hinge angle.getFoldOrientation
public int getFoldOrientation()FOLD_ORIENTATION_* constants.isSeparating
public boolean isSeparating()isTableTop
public boolean isTableTop()getFoldBounds
public Rectangle getFoldBounds(Rectangle rect)Parameters
rectRectangle- a rectangle to populate and return, or null to allocate a new one