Class SurfaceImage
An image node. Because surfaces render while the app process may be dead, images are shipped as
named PNG blobs beside the descriptor rather than passed by reference: constructing the node
from a com.codename1.ui.Image encodes it to PNG at publish time and names it by content hash
(identical art re-published later ships no new bytes). A node can also reference a name that
was already shipped with a previous publish.
Keep surface art small -- widget renderers run under tight memory budgets (about 30mb for the whole iOS widget extension) and Android parcels the rendered widget over a 1mb binder transaction.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intCenters the image without scaling.static final intScales the image to fill the node bounds, preserving aspect ratio and cropping overflow.static final intScales the image to fit inside the node bounds, preserving aspect ratio. -
Constructor Summary
ConstructorsConstructorDescriptionSurfaceImage(Image image) Creates an image node from an image.SurfaceImage(String registeredName) Creates an image node referencing an image name shipped with an earlier publish to the same surface. -
Method Summary
Modifier and TypeMethodDescriptiongetImage()Returns the source image, or null when this node references a registered name.Returns the referenced registered name, or null when this node ships its own image.intReturns the scale mode, one ofSCALE_FIT,SCALE_FILL,SCALE_CENTER.getTint()Returns the tint color, or null.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.setCornerRadius(int radius) Sets the corner radius applied to the node's background.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.setScaleMode(int scaleMode) Sets how the image scales within the node bounds.setSize(int widthDips, int heightDips) Sets a fixed size for this node.setTint(SurfaceColor tint) Tints the image with the supplied color, template-image style: the image's alpha channel is kept and its color replaced.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
-
SCALE_FIT
public static final int SCALE_FITScales the image to fit inside the node bounds, preserving aspect ratio.- See Also:
-
SCALE_FILL
public static final int SCALE_FILLScales the image to fill the node bounds, preserving aspect ratio and cropping overflow.- See Also:
-
SCALE_CENTER
public static final int SCALE_CENTERCenters the image without scaling.- See Also:
-
-
Constructor Details
-
SurfaceImage
Creates an image node from an image. The image is encoded to PNG when the descriptor is published.
Parameters
image: the image to ship with the descriptor
-
SurfaceImage
Creates an image node referencing an image name shipped with an earlier publish to the same surface.
Parameters
registeredName: the previously registered image name
-
-
Method Details
-
setScaleMode
Sets how the image scales within the node bounds.
Parameters
scaleMode: one ofSCALE_FIT,SCALE_FILL,SCALE_CENTER
Returns
this image node, for chaining
-
setTint
Tints the image with the supplied color, template-image style: the image's alpha channel is kept and its color replaced.
Parameters
tint: the tint color
Returns
this image node, for chaining
-
getImage
Returns the source image, or null when this node references a registered name. -
getRegisteredName
Returns the referenced registered name, or null when this node ships its own image. -
getScaleMode
public int getScaleMode()Returns the scale mode, one ofSCALE_FIT,SCALE_FILL,SCALE_CENTER. -
getTint
Returns the tint color, or null. -
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
-