Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class SurfaceDynamicText
- Object
- SurfaceNode
- 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.
Fields
public static final int STYLE_TIMER_DOWN = 0 | Counts down to the target date, e.g. 04:59. |
public static final int STYLE_TIMER_UP = 1 | Counts up since the target date, e.g. 12:07. |
public static final int STYLE_TIME = 2 | The target date’s clock time, e.g. 9:41 AM. |
public static final int STYLE_DATE = 3 | The target date’s calendar date, e.g. June 3. |
public static final int STYLE_RELATIVE = 4 | The distance to the target date in words, e.g. in 5 min. |
Constructors
public SurfaceDynamicText(int style, Date date) | Creates a dynamic text node with a fixed target date. |
public SurfaceDynamicText(int style, String dateStateKey) | Creates a dynamic text node whose target date comes from the state map. |
Methods
Inherited methods
Field details
STYLE_TIMER_DOWN
public static final int STYLE_TIMER_DOWN = 004:59. Rendered by Text(date, style: .timer) on
iOS and a countdown Chronometer on Android.STYLE_TIMER_UP
public static final int STYLE_TIMER_UP = 112:07.STYLE_TIME
public static final int STYLE_TIME = 29:41 AM.STYLE_DATE
public static final int STYLE_DATE = 3June 3. Approximated as static text on Android.STYLE_RELATIVE
public static final int STYLE_RELATIVE = 4in 5 min. Approximated as static text on
Android.Constructor details
SurfaceDynamicText
public SurfaceDynamicText(int style, Date date)Parameters
styleint- one of the
STYLE_...constants dateDate- the target date
SurfaceDynamicText
public SurfaceDynamicText(int style, String dateStateKey)Long.Parameters
styleint- one of the
STYLE_...constants dateStateKeyString- the state-map key holding the epoch millis
Method details
setFontSize
public SurfaceDynamicText setFontSize(int fontSize)Parameters
fontSizeint- the size in dips
Returns
setFontWeight
public SurfaceDynamicText setFontWeight(SurfaceFontWeight fontWeight)Parameters
fontWeightSurfaceFontWeight- the weight
Returns
setColor
public SurfaceDynamicText setColor(SurfaceColor color)Parameters
colorSurfaceColor- the color
Returns
getStyle
public int getStyle()STYLE_... constant of this node.getDate
public Date getDate()getDateKey
public String getDateKey()getFontSize
public int getFontSize()getFontWeight
public SurfaceFontWeight getFontWeight()getColor
public SurfaceColor getColor()setPadding
public SurfaceDynamicText setPadding(int all)Parameters
allint- padding in dips
Returns
setPadding
public SurfaceDynamicText setPadding(int top, int right, int bottom, int left)Parameters
topint- top padding in dips
rightint- right padding in dips
bottomint- bottom padding in dips
leftint- left padding in dips
Returns
setBackground
public SurfaceDynamicText setBackground(SurfaceColor background)Parameters
backgroundSurfaceColor- the background color
Returns
setCornerRadius
public SurfaceDynamicText setCornerRadius(int radius)Parameters
radiusint- the corner radius in dips
Returns
setAlignment
public SurfaceDynamicText setAlignment(SurfaceAlignment alignment)SurfaceBox all nine positions apply;
in rows and columns only the cross-axis component is used.Parameters
alignmentSurfaceAlignment- the alignment
Returns
setWeight
public SurfaceDynamicText setWeight(int weight)Parameters
weightint- the relative weight, 0 for natural sizing
Returns
setSize
public SurfaceDynamicText setSize(int widthDips, int heightDips)Parameters
widthDipsint- fixed width in dips, 0 for natural width
heightDipsint- fixed height in dips, 0 for natural height
Returns
setAction
public SurfaceDynamicText setAction(String actionId)Surfaces.setActionHandler(...).
Note that small iOS home-screen widgets only honor the action of the root node.Parameters
actionIdString- the app-defined action identifier
Returns
setAction
public SurfaceDynamicText setAction(String actionId, Map<String, Object> params)String,
Number and Boolean values and is delivered verbatim with the SurfaceActionEvent.Parameters
actionIdString- the app-defined action identifier
paramsMap<String, Object>- parameters delivered with the action, may be null