public abstract class SurfaceNode

  1. Object
  2. SurfaceNode

Known subtypesSurfaceContainer, SurfaceDynamicText, SurfaceImage, SurfaceProgress, SurfaceSpacer, SurfaceText, SurfaceVector

The base class of all surface layout nodes. A surface descriptor is a small tree of nodes (columns, rows, boxes, text, images, progress indicators) that every platform can render natively while the app process is not running – so a node is pure data: there are no listeners, no theme lookups and no live Image references in the serialized form.

All nodes share the styling in this class: padding, background color, corner radius, alignment within the parent, flexible weight, an optional fixed size and an optional action. An action is a plain string id (plus optional parameters) delivered to the handler registered with Surfaces.setActionHandler(...) when the user taps the node – see SurfaceActionEvent.

All dimensions are in display-independent pixels (dips).

Constructors

public SurfaceNode()

Methods

public SurfaceNode setPadding(int all)Sets the same padding on all four sides.
public SurfaceNode setPadding(int top, int right, int bottom, int left)Sets the padding of each side individually.
public SurfaceNode setBackground(SurfaceColor color)Sets the background color of this node.
public SurfaceNode setCornerRadius(int radius)Sets the corner radius applied to the node’s background.
public SurfaceNode setAlignment(SurfaceAlignment alignment)Sets this node’s alignment within its parent.
public SurfaceNode setWeight(int weight)Sets the flexible-space weight of this node within a row or column.
public SurfaceNode setSize(int widthDips, int heightDips)Sets a fixed size for this node.
public SurfaceNode setAction(String actionId)Assigns a tap action to this node.
public SurfaceNode setAction(String actionId, Map<String, Object> params)Assigns a tap action with parameters to this node.
public int getPaddingTop()Returns the top padding in dips.
public int getPaddingRight()Returns the right padding in dips.
public int getPaddingBottom()Returns the bottom padding in dips.
public int getPaddingLeft()Returns the left padding in dips.
public SurfaceColor getBackground()Returns the background color, or null.
public int getCornerRadius()Returns the corner radius in dips.
public SurfaceAlignment getAlignment()Returns the alignment within the parent, or null for the platform default.
public int getWeight()Returns the flexible-space weight, 0 when naturally sized.
public int getWidthDips()Returns the fixed width in dips, 0 when naturally sized.
public int getHeightDips()Returns the fixed height in dips, 0 when naturally sized.
public String getActionId()Returns the tap action id, or null.
public Map<String, Object> getActionParams()Returns the tap action parameters, or null.

Inherited methods

Constructor details

SurfaceNode

public SurfaceNode()

Method details

setPadding

public SurfaceNode setPadding(int all)
Sets the same padding on all four sides.

Parameters

all int
padding in dips

Returns

this node, for chaining

setPadding

public SurfaceNode setPadding(int top, int right, int bottom, int left)
Sets the padding of each side individually.

Parameters

top int
top padding in dips
right int
right padding in dips
bottom int
bottom padding in dips
left int
left padding in dips

Returns

this node, for chaining

setBackground

public SurfaceNode setBackground(SurfaceColor color)
Sets the background color of this node.

Parameters

color SurfaceColor
the background color

Returns

this node, for chaining

setCornerRadius

public SurfaceNode setCornerRadius(int radius)
Sets the corner radius applied to the node’s background. May render square on Android versions below 12.

Parameters

radius int
the corner radius in dips

Returns

this node, for chaining

setAlignment

public SurfaceNode setAlignment(SurfaceAlignment alignment)
Sets this node’s alignment within its parent. In a SurfaceBox all nine positions apply; in rows and columns only the cross-axis component is used.

Parameters

alignment SurfaceAlignment
the alignment

Returns

this node, for chaining

setWeight

public SurfaceNode setWeight(int weight)
Sets the flexible-space weight of this node within a row or column. Nodes with a weight share the leftover space of the parent proportionally; a weight of 0 (the default) sizes the node to its natural size.

Parameters

weight int
the relative weight, 0 for natural sizing

Returns

this node, for chaining

setSize

public SurfaceNode setSize(int widthDips, int heightDips)
Sets a fixed size for this node. A value of 0 (the default) keeps the natural size of the respective axis.

Parameters

widthDips int
fixed width in dips, 0 for natural width
heightDips int
fixed height in dips, 0 for natural height

Returns

this node, for chaining

setAction

public SurfaceNode setAction(String actionId)
Assigns a tap action to this node. Tapping the node opens (or foregrounds) the app and delivers the action id to the handler registered with Surfaces.setActionHandler(...). Note that small iOS home-screen widgets only honor the action of the root node.

Parameters

actionId String
the app-defined action identifier

Returns

this node, for chaining

setAction

public SurfaceNode setAction(String actionId, Map<String, Object> params)
Assigns a tap action with parameters to this node. The parameter map may contain String, Number and Boolean values and is delivered verbatim with the SurfaceActionEvent.

Parameters

actionId String
the app-defined action identifier
params Map<String, Object>
parameters delivered with the action, may be null

Returns

this node, for chaining

getPaddingTop

public int getPaddingTop()
Returns the top padding in dips.

getPaddingRight

public int getPaddingRight()
Returns the right padding in dips.

getPaddingBottom

public int getPaddingBottom()
Returns the bottom padding in dips.

getPaddingLeft

public int getPaddingLeft()
Returns the left padding in dips.

getBackground

public SurfaceColor getBackground()
Returns the background color, or null.

getCornerRadius

public int getCornerRadius()
Returns the corner radius in dips.

getAlignment

public SurfaceAlignment getAlignment()
Returns the alignment within the parent, or null for the platform default.

getWeight

public int getWeight()
Returns the flexible-space weight, 0 when naturally sized.

getWidthDips

public int getWidthDips()
Returns the fixed width in dips, 0 when naturally sized.

getHeightDips

public int getHeightDips()
Returns the fixed height in dips, 0 when naturally sized.

getActionId

public String getActionId()
Returns the tap action id, or null.

getActionParams

public Map<String, Object> getActionParams()
Returns the tap action parameters, or null.