Class DevicePosture

java.lang.Object
com.codename1.ui.DevicePosture

public final class DevicePosture extends Object

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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The hinge runs horizontally, splitting the display into a top and a bottom half.
    static final int
    There is no fold separating the display.
    static final int
    The hinge runs vertically, splitting the display into a left and a right half.
    static final int
    The device is folded shut.
    static final int
    The device is open and flat (a continuous surface).
    static final int
    The device is half opened, forming a laptop, book or tabletop posture with the hinge between roughly 30 and 150 degrees.
    static final int
    The posture could not be determined, typically because the device is not foldable.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the bounds of the region occluded by the hinge in display coordinates, or null when there is no separating fold.
    int
    The orientation of the fold, one of the FOLD_ORIENTATION_* constants.
    int
    The current hinge angle in degrees between 0 (closed) and 180 (flat), or -1 when the device does not report a hinge angle.
    Returns the shared device posture instance.
    int
    The current posture, one of the POSTURE_* constants.
    boolean
    True if the device is a foldable or dual screen device.
    boolean
    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.
    boolean
    True if the device is in a tabletop or book posture (half opened and separating the display).

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • POSTURE_UNKNOWN

      public static final int POSTURE_UNKNOWN
      The posture could not be determined, typically because the device is not foldable.
      See Also:
    • POSTURE_FLAT

      public static final int POSTURE_FLAT
      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.
      See Also:
    • POSTURE_HALF_OPENED

      public static final int POSTURE_HALF_OPENED
      The 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_CLOSED
      The device is folded shut.
      See Also:
    • FOLD_ORIENTATION_NONE

      public static final int FOLD_ORIENTATION_NONE
      There is no fold separating the display.
      See Also:
    • FOLD_ORIENTATION_VERTICAL

      public static final int FOLD_ORIENTATION_VERTICAL
      The hinge runs vertically, splitting the display into a left and a right half.
      See Also:
    • FOLD_ORIENTATION_HORIZONTAL

      public static final int FOLD_ORIENTATION_HORIZONTAL
      The hinge runs horizontally, splitting the display into a top and a bottom half.
      See Also:
  • 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: 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