Package icyllis.modernui.view

# Class Gravity

java.lang.Object
icyllis.modernui.view.Gravity

public class Gravity extends Object
Standard constants and tools for placing an object within a potentially larger container.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static @interface`
  `Gravity.GravityFlags`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `AXIS_CLIP`
  Raw bit controlling whether the right/bottom edge is clipped to its container, based on the gravity direction being applied.
  `static final int`
  `AXIS_PULL_AFTER`
  Raw bit controlling how the right/bottom edge is placed.
  `static final int`
  `AXIS_PULL_BEFORE`
  Raw bit controlling how the left/top edge is placed.
  `static final int`
  `AXIS_SPECIFIED`
  Raw bit indicating the gravity for an axis has been specified.
  `static final int`
  `AXIS_X_SHIFT`
  Bits defining the horizontal axis.
  `static final int`
  `AXIS_Y_SHIFT`
  Bits defining the vertical axis.
  `static final int`
  `BOTTOM`
  Push object to the bottom of its container, not changing its size.
  `static final int`
  `CENTER`
  Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
  `static final int`
  `CENTER_HORIZONTAL`
  Place object in the horizontal center of its container, not changing its size.
  `static final int`
  `CENTER_VERTICAL`
  Place object in the vertical center of its container, not changing its size.
  `static final int`
  `CLIP_HORIZONTAL`
  Flag to clip the edges of the object to its container along the horizontal axis.
  `static final int`
  `CLIP_VERTICAL`
  Flag to clip the edges of the object to its container along the vertical axis.
  `static final int`
  `DISPLAY_CLIP_HORIZONTAL`
  Special constant to enable clipping to an overall display along the horizontal dimension.
  `static final int`
  `DISPLAY_CLIP_VERTICAL`
  Special constant to enable clipping to an overall display along the vertical dimension.
  `static final int`
  `END`
  Push object to x-axis position at the end of its container, not changing its size.
  `static final int`
  `FILL`
  Grow the horizontal and vertical size of the object if needed so it completely fills its container.
  `static final int`
  `FILL_HORIZONTAL`
  Grow the horizontal size of the object if needed so it completely fills its container.
  `static final int`
  `FILL_VERTICAL`
  Grow the vertical size of the object if needed so it completely fills its container.
  `static final int`
  `HORIZONTAL_GRAVITY_MASK`
  Binary mask to get the absolute horizontal gravity of a gravity.
  `static final int`
  `LEFT`
  Push object to the left of its container, not changing its size.
  `static final int`
  `NO_GRAVITY`
  Constant indicating that no gravity has been set
  `static final int`
  `RELATIVE_HORIZONTAL_GRAVITY_MASK`
  Binary mask for the horizontal gravity and script specific direction bit.
  `static final int`
  `RELATIVE_LAYOUT_DIRECTION`
  Raw bit controlling whether the layout direction is relative or not (START/END instead of absolute LEFT/RIGHT).
  `static final int`
  `RIGHT`
  Push object to the right of its container, not changing its size.
  `static final int`
  `START`
  Push object to x-axis position at the start of its container, not changing its size.
  `static final int`
  `TOP`
  Push object to the top of its container, not changing its size.
  `static final int`
  `VERTICAL_GRAVITY_MASK`
  Binary mask to get the vertical gravity of a gravity.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Gravity()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `apply(int gravity, int w, int h, Rect container, int xAdj, int yAdj, Rect outRect)`
  Apply a gravity constant to an object.
  `static void`
  `apply(int gravity, int w, int h, Rect container, int xAdj, int yAdj, Rect outRect, int layoutDirection)`
  Apply a gravity constant to an object.
  `static void`
  `apply(int gravity, int w, int h, Rect container, Rect outRect)`
  Apply a gravity constant to an object.
  `static void`
  `apply(int gravity, int w, int h, Rect container, Rect outRect, int layoutDirection)`
  Apply a gravity constant to an object and take care if layout direction is RTL or not.
  `static void`
  `applyDisplay(int gravity, Rect display, Rect inoutObj)`
  Apply additional gravity behavior based on the overall "display" that an object exists in.
  `static void`
  `applyDisplay(int gravity, Rect display, Rect inoutObj, int layoutDirection)`
  Apply additional gravity behavior based on the overall "display" that an object exists in.
  `static int`
  `getAbsoluteGravity(int gravity, int layoutDirection)`
  Convert script specific gravity to absolute horizontal value.
  `static boolean`
  `isHorizontal(int gravity)`
  Indicate whether the supplied gravity has an horizontal pull.
  `static boolean`
  `isVertical(int gravity)`
  Indicate whether the supplied gravity has a vertical pull.
  `static String`
  `toString(int gravity)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### NO_GRAVITY

    public static final int NO_GRAVITY
    Constant indicating that no gravity has been set
    See Also:
      - Constant Field Values

  - ### AXIS_SPECIFIED

    public static final int AXIS_SPECIFIED
    Raw bit indicating the gravity for an axis has been specified.
    See Also:
      - Constant Field Values

  - ### AXIS_PULL_BEFORE

    public static final int AXIS_PULL_BEFORE
    Raw bit controlling how the left/top edge is placed.
    See Also:
      - Constant Field Values

  - ### AXIS_PULL_AFTER

    public static final int AXIS_PULL_AFTER
    Raw bit controlling how the right/bottom edge is placed.
    See Also:
      - Constant Field Values

  - ### AXIS_CLIP

    public static final int AXIS_CLIP
    Raw bit controlling whether the right/bottom edge is clipped to its container, based on the gravity direction being applied.
    See Also:
      - Constant Field Values

  - ### AXIS_X_SHIFT

    public static final int AXIS_X_SHIFT
    Bits defining the horizontal axis.
    See Also:
      - Constant Field Values

  - ### AXIS_Y_SHIFT

    public static final int AXIS_Y_SHIFT
    Bits defining the vertical axis.
    See Also:
      - Constant Field Values

  - ### TOP

    public static final int TOP
    Push object to the top of its container, not changing its size.
    See Also:
      - Constant Field Values

  - ### BOTTOM

    public static final int BOTTOM
    Push object to the bottom of its container, not changing its size.
    See Also:
      - Constant Field Values

  - ### LEFT

    public static final int LEFT
    Push object to the left of its container, not changing its size.
    See Also:
      - Constant Field Values

  - ### RIGHT

    public static final int RIGHT
    Push object to the right of its container, not changing its size.
    See Also:
      - Constant Field Values

  - ### CENTER_VERTICAL

    public static final int CENTER_VERTICAL
    Place object in the vertical center of its container, not changing its size.
    See Also:
      - Constant Field Values

  - ### FILL_VERTICAL

    public static final int FILL_VERTICAL
    Grow the vertical size of the object if needed so it completely fills its container.
    See Also:
      - Constant Field Values

  - ### CENTER_HORIZONTAL

    public static final int CENTER_HORIZONTAL
    Place object in the horizontal center of its container, not changing its size.
    See Also:
      - Constant Field Values

  - ### FILL_HORIZONTAL

    public static final int FILL_HORIZONTAL
    Grow the horizontal size of the object if needed so it completely fills its container.
    See Also:
      - Constant Field Values

  - ### CENTER

    public static final int CENTER
    Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
    See Also:
      - Constant Field Values

  - ### FILL

    public static final int FILL
    Grow the horizontal and vertical size of the object if needed so it completely fills its container.
    See Also:
      - Constant Field Values

  - ### CLIP_VERTICAL

    public static final int CLIP_VERTICAL
    Flag to clip the edges of the object to its container along the vertical axis.
    See Also:
      - Constant Field Values

  - ### CLIP_HORIZONTAL

    public static final int CLIP_HORIZONTAL
    Flag to clip the edges of the object to its container along the horizontal axis.
    See Also:
      - Constant Field Values

  - ### RELATIVE_LAYOUT_DIRECTION

    public static final int RELATIVE_LAYOUT_DIRECTION
    Raw bit controlling whether the layout direction is relative or not (START/END instead of absolute LEFT/RIGHT).
    See Also:
      - Constant Field Values

  - ### HORIZONTAL_GRAVITY_MASK

    public static final int HORIZONTAL_GRAVITY_MASK
    Binary mask to get the absolute horizontal gravity of a gravity.
    See Also:
      - Constant Field Values

  - ### VERTICAL_GRAVITY_MASK

    public static final int VERTICAL_GRAVITY_MASK
    Binary mask to get the vertical gravity of a gravity.
    See Also:
      - Constant Field Values

  - ### DISPLAY_CLIP_VERTICAL

    public static final int DISPLAY_CLIP_VERTICAL
    Special constant to enable clipping to an overall display along the vertical dimension. This is not applied by default by `apply(int, int, int, Rect, int, int, Rect)`; you must do so yourself by calling `applyDisplay(int, icyllis.modernui.graphics.Rect, icyllis.modernui.graphics.Rect)`.
    See Also:
      - Constant Field Values

  - ### DISPLAY_CLIP_HORIZONTAL

    public static final int DISPLAY_CLIP_HORIZONTAL
    Special constant to enable clipping to an overall display along the horizontal dimension. This is not applied by default by `apply(int, int, int, Rect, int, int, Rect)`; you must do so yourself by calling `applyDisplay(int, icyllis.modernui.graphics.Rect, icyllis.modernui.graphics.Rect)`.
    See Also:
      - Constant Field Values

  - ### START

    public static final int START
    Push object to x-axis position at the start of its container, not changing its size.
    See Also:
      - Constant Field Values

  - ### END

    public static final int END
    Push object to x-axis position at the end of its container, not changing its size.
    See Also:
      - Constant Field Values

  - ### RELATIVE_HORIZONTAL_GRAVITY_MASK

    public static final int RELATIVE_HORIZONTAL_GRAVITY_MASK
    Binary mask for the horizontal gravity and script specific direction bit.
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### Gravity

    public Gravity()

- ## Method Details

  - ### apply

    public static void apply(int gravity, int w, int h, @NonNull Rect container, @NonNull Rect outRect)
    Apply a gravity constant to an object. This supposes that the layout direction is LTR.
    Parameters:
      `gravity` - The desired placement of the object, as defined by the constants in this class.
      `w` - The horizontal size of the object.
      `h` - The vertical size of the object.
      `container` - The frame of the containing space, in which the object will be placed. Should be large enough to contain the width and height of the object.
      `outRect` - Receives the computed frame of the object in its container.

  - ### apply

    public static void apply(int gravity, int w, int h, @NonNull Rect container, @NonNull Rect outRect, int layoutDirection)
    Apply a gravity constant to an object and take care if layout direction is RTL or not.
    Parameters:
      `gravity` - The desired placement of the object, as defined by the constants in this class.
      `w` - The horizontal size of the object.
      `h` - The vertical size of the object.
      `container` - The frame of the containing space, in which the object will be placed. Should be large enough to contain the width and height of the object.
      `outRect` - Receives the computed frame of the object in its container.
      `layoutDirection` - The layout direction.
    See Also:
      - `View.LAYOUT_DIRECTION_LTR`
      - `View.LAYOUT_DIRECTION_RTL`

  - ### apply

    public static void apply(int gravity, int w, int h, @NonNull Rect container, int xAdj, int yAdj, @NonNull Rect outRect)
    Apply a gravity constant to an object.
    Parameters:
      `gravity` - The desired placement of the object, as defined by the constants in this class.
      `w` - The horizontal size of the object.
      `h` - The vertical size of the object.
      `container` - The frame of the containing space, in which the object will be placed. Should be large enough to contain the width and height of the object.
      `xAdj` - Offset to apply to the X axis. If gravity is LEFT this pushes it to the right; if gravity is RIGHT it pushes it to the left; if gravity is CENTER_HORIZONTAL it pushes it to the right or left; otherwise it is ignored.
      `yAdj` - Offset to apply to the Y axis. If gravity is TOP this pushes it down; if gravity is BOTTOM it pushes it up; if gravity is CENTER_VERTICAL it pushes it down or up; otherwise it is ignored.
      `outRect` - Receives the computed frame of the object in its container.

  - ### apply

    public static void apply(int gravity, int w, int h, @NonNull Rect container, int xAdj, int yAdj, @NonNull Rect outRect, int layoutDirection)
    Apply a gravity constant to an object.
    Parameters:
      `gravity` - The desired placement of the object, as defined by the constants in this class.
      `w` - The horizontal size of the object.
      `h` - The vertical size of the object.
      `container` - The frame of the containing space, in which the object will be placed. Should be large enough to contain the width and height of the object.
      `xAdj` - Offset to apply to the X axis. If gravity is LEFT this pushes it to the right; if gravity is RIGHT it pushes it to the left; if gravity is CENTER_HORIZONTAL it pushes it to the right or left; otherwise it is ignored.
      `yAdj` - Offset to apply to the Y axis. If gravity is TOP this pushes it down; if gravity is BOTTOM it pushes it up; if gravity is CENTER_VERTICAL it pushes it down or up; otherwise it is ignored.
      `outRect` - Receives the computed frame of the object in its container.
      `layoutDirection` - The layout direction.
    See Also:
      - `View.LAYOUT_DIRECTION_LTR`
      - `View.LAYOUT_DIRECTION_RTL`

  - ### applyDisplay

    public static void applyDisplay(int gravity, @NonNull Rect display, @NonNull Rect inoutObj)
    Apply additional gravity behavior based on the overall "display" that an object exists in. This can be used after `apply(int, int, int, Rect, int, int, Rect)` to place the object within a visible display. By default this moves or clips the object to be visible in the display; the gravity flags `DISPLAY_CLIP_HORIZONTAL` and `DISPLAY_CLIP_VERTICAL` can be used to change this behavior.
    Parameters:
      `gravity` - Gravity constants to modify the placement within the display.
      `display` - The rectangle of the display in which the object is being placed.
      `inoutObj` - Supplies the current object position; returns with it modified if needed to fit in the display.

  - ### applyDisplay

    public static void applyDisplay(int gravity, @NonNull Rect display, @NonNull Rect inoutObj, int layoutDirection)
    Apply additional gravity behavior based on the overall "display" that an object exists in. This can be used after `apply(int, int, int, Rect, int, int, Rect)` to place the object within a visible display. By default this moves or clips the object to be visible in the display; the gravity flags `DISPLAY_CLIP_HORIZONTAL` and `DISPLAY_CLIP_VERTICAL` can be used to change this behavior.
    Parameters:
      `gravity` - Gravity constants to modify the placement within the display.
      `display` - The rectangle of the display in which the object is being placed.
      `inoutObj` - Supplies the current object position; returns with it modified if needed to fit in the display.
      `layoutDirection` - The layout direction.
    See Also:
      - `View.LAYOUT_DIRECTION_LTR`
      - `View.LAYOUT_DIRECTION_RTL`

  - ### isVertical

    public static boolean isVertical(int gravity)

    Indicate whether the supplied gravity has a vertical pull.

    Parameters:
      `gravity` - the gravity to check for vertical pull
    Returns:
      true if the supplied gravity has a vertical pull

  - ### isHorizontal

    public static boolean isHorizontal(int gravity)

    Indicate whether the supplied gravity has an horizontal pull.

    Parameters:
      `gravity` - the gravity to check for horizontal pull
    Returns:
      true if the supplied gravity has an horizontal pull

  - ### getAbsoluteGravity

    public static int getAbsoluteGravity(int gravity, int layoutDirection)

    Convert script specific gravity to absolute horizontal value.

    if horizontal direction is LTR, then START will set LEFT and END will set RIGHT. if horizontal direction is RTL, then START will set RIGHT and END will set LEFT.

    Parameters:
      `gravity` - The gravity to convert to absolute (horizontal) values.
      `layoutDirection` - The layout direction.
    Returns:
      gravity converted to absolute (horizontal) values.

  - ### toString

    @Internal public static String toString(int gravity)