Class SurfaceDynamicText
A date-driven text node the operating system animates natively -- the headline feature for timers, delivery ETAs and elapsed-time displays: a countdown keeps ticking every second on the widget or Dynamic Island even though the app process is not running.
// counts down to the ETA the OS-native way, no app wakeups needed
new SurfaceDynamicText(SurfaceDynamicText.STYLE_TIMER_DOWN, "eta")
.setFontSize(22).setFontWeight(SurfaceFontWeight.BOLD)
The target date is either fixed at build time or referenced from the state map by key (the
state value is the epoch time in milliseconds as a Long), so a live-activity update can move
the ETA without republishing the layout.
Rendering: iOS uses Text(date, style:), Android uses Chronometer / TextClock. On Android
the STYLE_DATE and STYLE_RELATIVE styles are approximated -- they render as static text
computed when the widget last refreshed.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe target date's calendar date, e.g.static final intThe distance to the target date in words, e.g.static final intThe target date's clock time, e.g.static final intCounts down to the target date, e.g.static final intCounts up since the target date, e.g. -
Constructor Summary
ConstructorsConstructorDescriptionSurfaceDynamicText(int style, String dateStateKey) Creates a dynamic text node whose target date comes from the state map.SurfaceDynamicText(int style, Date date) Creates a dynamic text node with a fixed target date. -
Method Summary
Modifier and TypeMethodDescriptiongetColor()Returns the text color, or null for the platform default.getDate()Returns the fixed target date, or null when the date comes from the state map.Returns the state-map key of the target date, or null when the date is fixed.intReturns the font size in dips, 0 for the platform default.Returns the font weight, or null for the platform default.intgetStyle()Returns theSTYLE_...constant of this node.Assigns a tap action to this node.Assigns a tap action with parameters to this node.setAlignment(SurfaceAlignment alignment) Sets this node's alignment within its parent.setBackground(SurfaceColor background) Sets the background color of this node.setColor(SurfaceColor color) Sets the text color.setCornerRadius(int radius) Sets the corner radius applied to the node's background.setFontSize(int fontSize) Sets the font size.setFontWeight(SurfaceFontWeight fontWeight) Sets the font weight.setPadding(int all) Sets the same padding on all four sides.setPadding(int top, int right, int bottom, int left) Sets the padding of each side individually.setSize(int widthDips, int heightDips) Sets a fixed size for this node.setWeight(int weight) Sets the flexible-space weight of this node within a row or column.Methods inherited from class SurfaceNode
getActionId, getActionParams, getAlignment, getBackground, getCornerRadius, getHeightDips, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getWeight, getWidthDips
-
Field Details
-
STYLE_TIMER_DOWN
public static final int STYLE_TIMER_DOWNCounts down to the target date, e.g.04:59. Rendered byText(date, style: .timer)on iOS and a countdownChronometeron Android.- See Also:
-
STYLE_TIMER_UP
public static final int STYLE_TIMER_UPCounts up since the target date, e.g.12:07.- See Also:
-
STYLE_TIME
public static final int STYLE_TIMEThe target date's clock time, e.g.9:41 AM.- See Also:
-
STYLE_DATE
public static final int STYLE_DATEThe target date's calendar date, e.g.June 3. Approximated as static text on Android.- See Also:
-
STYLE_RELATIVE
public static final int STYLE_RELATIVEThe distance to the target date in words, e.g.in 5 min. Approximated as static text on Android.- See Also:
-
-
Constructor Details
-
SurfaceDynamicText
Creates a dynamic text node with a fixed target date.
Parameters
style: one of theSTYLE_...constantsdate: the target date
-
SurfaceDynamicText
Creates a dynamic text node whose target date comes from the state map. The state value is the epoch time in milliseconds as a
Long.Parameters
style: one of theSTYLE_...constantsdateStateKey: the state-map key holding the epoch millis
-
-
Method Details
-
setFontSize
Sets the font size.
Parameters
fontSize: the size in dips
Returns
this node, for chaining
-
setFontWeight
Sets the font weight.
Parameters
fontWeight: the weight
Returns
this node, for chaining
-
setColor
Sets the text color.
Parameters
color: the color
Returns
this node, for chaining
-
getStyle
public int getStyle()Returns theSTYLE_...constant of this node. -
getDate
Returns the fixed target date, or null when the date comes from the state map. -
getDateKey
Returns the state-map key of the target date, or null when the date is fixed. -
getFontSize
public int getFontSize()Returns the font size in dips, 0 for the platform default. -
getFontWeight
Returns the font weight, or null for the platform default. -
getColor
Returns the text color, or null for the platform default. -
setPadding
Description copied from class:SurfaceNodeSets the same padding on all four sides.
Parameters
all: padding in dips
Returns
this node, for chaining
- Overrides:
setPaddingin classSurfaceNode
-
setPadding
Description copied from class:SurfaceNodeSets the padding of each side individually.
Parameters
top: top padding in dipsright: right padding in dipsbottom: bottom padding in dipsleft: left padding in dips
Returns
this node, for chaining
- Overrides:
setPaddingin classSurfaceNode
-
setBackground
Description copied from class:SurfaceNodeSets the background color of this node.
Parameters
color: the background color
Returns
this node, for chaining
- Overrides:
setBackgroundin classSurfaceNode
-
setCornerRadius
Description copied from class:SurfaceNodeSets the corner radius applied to the node's background. May render square on Android versions below 12.
Parameters
radius: the corner radius in dips
Returns
this node, for chaining
- Overrides:
setCornerRadiusin classSurfaceNode
-
setAlignment
Description copied from class:SurfaceNodeSets this node's alignment within its parent. In a
SurfaceBoxall nine positions apply; in rows and columns only the cross-axis component is used.Parameters
alignment: the alignment
Returns
this node, for chaining
- Overrides:
setAlignmentin classSurfaceNode
-
setWeight
Description copied from class:SurfaceNodeSets 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: the relative weight, 0 for natural sizing
Returns
this node, for chaining
- Overrides:
setWeightin classSurfaceNode
-
setSize
Description copied from class:SurfaceNodeSets a fixed size for this node. A value of 0 (the default) keeps the natural size of the respective axis.
Parameters
widthDips: fixed width in dips, 0 for natural widthheightDips: fixed height in dips, 0 for natural height
Returns
this node, for chaining
- Overrides:
setSizein classSurfaceNode
-
setAction
Description copied from class:SurfaceNodeAssigns 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: the app-defined action identifier
Returns
this node, for chaining
- Overrides:
setActionin classSurfaceNode
-
setAction
Description copied from class:SurfaceNodeAssigns a tap action with parameters to this node. The parameter map may contain
String,NumberandBooleanvalues and is delivered verbatim with theSurfaceActionEvent.Parameters
actionId: the app-defined action identifierparams: parameters delivered with the action, may be null
Returns
this node, for chaining
- Overrides:
setActionin classSurfaceNode
-