Class 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe hinge runs horizontally, splitting the display into a top and a bottom half.static final intThere is no fold separating the display.static final intThe hinge runs vertically, splitting the display into a left and a right half.static final intThe device is folded shut.static final intThe device is open and flat (a continuous surface).static final intThe device is half opened, forming a laptop, book or tabletop posture with the hinge between roughly 30 and 150 degrees.static final intThe posture could not be determined, typically because the device is not foldable. -
Method Summary
Modifier and TypeMethodDescriptiongetFoldBounds(Rectangle rect) Returns the bounds of the region occluded by the hinge in display coordinates, or null when there is no separating fold.intThe orientation of the fold, one of theFOLD_ORIENTATION_*constants.intThe current hinge angle in degrees between0(closed) and180(flat), or-1when the device does not report a hinge angle.static DevicePostureReturns the shared device posture instance.intThe current posture, one of thePOSTURE_*constants.booleanTrue if the device is a foldable or dual screen device.booleanTrue if the fold currently separates the display into two distinct logical areas (a book or tabletop posture) rather than presenting a single continuous surface.booleanTrue if the device is in a tabletop or book posture (half opened and separating the display).
-
Field Details
-
POSTURE_UNKNOWN
public static final int POSTURE_UNKNOWNThe posture could not be determined, typically because the device is not foldable.- See Also:
-
POSTURE_FLAT
public static final int POSTURE_FLATThe 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.- See Also:
-
POSTURE_HALF_OPENED
public static final int POSTURE_HALF_OPENEDThe device is half opened, forming a laptop, book or tabletop posture with the hinge between roughly 30 and 150 degrees.- See Also:
-
POSTURE_CLOSED
public static final int POSTURE_CLOSEDThe device is folded shut.- See Also:
-
FOLD_ORIENTATION_NONE
public static final int FOLD_ORIENTATION_NONEThere is no fold separating the display.- See Also:
-
FOLD_ORIENTATION_VERTICAL
public static final int FOLD_ORIENTATION_VERTICALThe hinge runs vertically, splitting the display into a left and a right half.- See Also:
-
FOLD_ORIENTATION_HORIZONTAL
public static final int FOLD_ORIENTATION_HORIZONTALThe hinge runs horizontally, splitting the display into a top and a bottom half.- See Also:
-
-
Method Details
-
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 thePOSTURE_*constants. -
getHingeAngle
public int getHingeAngle()The current hinge angle in degrees between0(closed) and180(flat), or-1when the device does not report a hinge angle. -
getFoldOrientation
public int getFoldOrientation()The orientation of the fold, one of theFOLD_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
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: 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
-