Class Skeleton
- All Implemented Interfaces:
Animation, Editable, StyleListener
A skeleton screen placeholder (also called a shimmer loader, content placeholder or ghost element): the grey outline of content that is still loading, with a light band sweeping across it.
Show one where content will land, so the screen says "loading" without a spinner and does not jump when the content arrives:
Form form = new Form("Orders", new BorderLayout());
Container list = new Container(BoxLayout.y());
list.add(Skeleton.rows(4));
form.add(BorderLayout.CENTER, list);
form.show();
// Stands in for a network call that answers after 2 seconds.
UITimer.timer(2000, false, form, () -> {
list.removeAll();
for (String order : new String[] {"Order #101", "Order #102"}) {
list.add(new MultiButton(order));
}
list.animateLayout(200);
});
Or mask a component that already exists until its data is ready:
Form form = new Form("Profile", BoxLayout.y());
SpanLabel bio = new SpanLabel();
form.add(bio);
form.show();
Skeleton.show(bio, Skeleton.text(3));
UITimer.timer(2000, false, form, () -> {
bio.setText("Builds mobile apps in Java.");
Skeleton.hide(bio, CommonTransitions.createFade(200));
});
The shapes are drawn in the foreground colour of the Skeleton UIID. A
theme that does not style that UIID gets the theme's text colour at a low
opacity, which suits light and dark themes alike. Restyle the UIID, or pass
your own with setUIID, to change the colour, padding or margin. The shimmer runs only while
the placeholder is on screen; turn it off with #shimmer(boolean).
Skeleton is a CommonProgressAnimations.ProgressAnimation, so it also works
with CommonProgressAnimations.ProgressAnimation#markComponentLoading.
See also InfiniteProgress for a blocking spinner and EmptyState for what
to show when loading finished with nothing to show.
-
Field Summary
Fields inherited from class CommonProgressAnimations.ProgressAnimation
cmpFields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleananimate()Allows the animation to reduce "repaint" calls when it returns false.protected DimensionCalculates the preferred size based on component content.static Skeletoncard()A card: an image across the top, then a title and two lines of text.static Skeletoncircle(float diameterMM) A circle, for an avatar or an icon.static voidPuts a component masked by#show(Component)back in its place.static voidhide(Component cmp, Transition t) Puts a component masked by#show(Component)back in its place with a transition, such as a fade.protected voidAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component stateprotected voidinitUnselectedStyle(Style unselectedStyle) Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.booleanWhether the shimmer band is on.voidThis method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.static Skeletonrect(float widthMM, float heightMM) A rounded rectangle, for an image, a button or a chart.static Skeletonrows(int rows) The outline of a list: per row, a round icon, a title, a shorter second line and a value at the far end.shimmer(boolean shimmer) Turns the moving shimmer band on or off.static SkeletonReplaces a component in its parent with a block placeholder of the same preferred size until#hide(Component)is called.static SkeletonReplaces a component in its parent with the given placeholder until#hide(Component)is called, for instanceSkeleton.text(3)in place of aSpanLabel.static Skeletontext(int lines) Lines of text, the last one shorter, as a paragraph would end.Sets the UIID, for chaining:Skeleton.rows(5).uiid("MySkeleton").Methods inherited from class CommonProgressAnimations.ProgressAnimation
deinitialize, getProgressAnimation, markComponentLoading, markComponentLoading, markComponentReady, markComponentReadyMethods inherited from class Component
accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addNativeDragOverListener, addNativeDropListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, canAcceptNativeDrop, cancelRepaints, clearClientProperties, consumesRawTextInput, contains, containsOrOwns, createNativeDragOperation, createStyleAnimation, deinitializeCustomStyle, deregisterFromAnimation, dragEnter, dragExit, dragFinished, draggingOver, dragInitiated, drawDraggedImage, drop, fireClicked, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAcceptedDropActions, getAcceptedDropMimeTypes, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBottomGap, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getContextMenuCommands, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getGridPosX, getGridPosY, getHeight, getHoverStyle, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeDragOperation, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getSideGap, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getTopLevelContainer, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initLaf, initPressedStyle, initSelectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHovered, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isNativeDragSource, isNativeDropTarget, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSelectableInteraction, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyPressed, keyReleased, keyRepeated, laidOut, longKeyPress, longPointerPress, mouseWheel, nativeDragEnter, nativeDragExit, nativeDragOver, nativeDrop, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, paramString, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, refreshTheme, registerForAnimation, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removeNativeDragOverListener, removeNativeDropListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAcceptedDropActions, setAcceptedDropMimeTypes, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setContextMenuCommands, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setHovered, setHoverStyle, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNativeDragOperation, setNativeDragSource, setNativeDropTarget, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stopScrollMomentum, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains
-
Constructor Details
-
Skeleton
public Skeleton()A placeholder block that fills whatever size it is given. This is the shape#show(Component)uses to mask a component.
-
-
Method Details
-
initUnselectedStyle
Description copied from class:ComponentCan be overridden by subclasses to perform initialization when the unselected style is set to a new value.
Parameters
unselectedStyle: The unselected style.
- Overrides:
initUnselectedStylein classComponent
-
rows
The outline of a list: per row, a round icon, a title, a shorter second line and a value at the far end.
Parameters
rows: how many rows to outline
Returns
the placeholder
-
text
Lines of text, the last one shorter, as a paragraph would end.
Parameters
lines: how many lines
Returns
the placeholder
-
circle
A circle, for an avatar or an icon.
Parameters
diameterMM: the diameter in millimetres
Returns
the placeholder
-
rect
A rounded rectangle, for an image, a button or a chart.
Parameters
-
widthMM: the width in millimetres; 0 or less takes the full width -
heightMM: the height in millimetres
Returns
the placeholder
-
-
card
A card: an image across the top, then a title and two lines of text.
Returns
the placeholder
-
shimmer
Turns the moving shimmer band on or off. It is on by default; off, the placeholder is a still outline.
Parameters
shimmer: true for the moving band
Returns
this, for chaining
-
uiid
-
isShimmer
public boolean isShimmer()Whether the shimmer band is on.
Returns
true if the band moves across the placeholder
-
show
Replaces a component in its parent with a block placeholder of the same preferred size until
#hide(Component)is called. Calling it again while the component is masked returns the placeholder already showing.Parameters
cmp: a component that has a parent
Returns
the placeholder that took its place
-
show
Replaces a component in its parent with the given placeholder until
#hide(Component)is called, for instanceSkeleton.text(3)in place of aSpanLabel.Parameters
-
cmp: a component that has a parent -
placeholder: what to show in its place
Returns
the placeholder showing; when the component was already masked by a
Skeleton, that one; null when another kind of progress animation already masks it -
-
hide
Puts a component masked by
#show(Component)back in its place. Does nothing if it is not masked.Parameters
cmp: the component to restore
-
hide
Puts a component masked by
#show(Component)back in its place with a transition, such as a fade. Does nothing if it is not masked.Parameters
-
cmp: the component to restore -
t: the transition, or null to swap at once
-
-
initComponent
protected void initComponent()Description copied from class:ComponentAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component state- Overrides:
initComponentin classCommonProgressAnimations.ProgressAnimation
-
animate
public boolean animate()Description copied from class:ComponentAllows the animation to reduce "repaint" calls when it returns false. It is called once for every frame. Frames are defined by the
com.codename1.ui.Displayclass.Returns
true if a repaint is desired or false if no repaint is necessary
-
calcPreferredSize
Description copied from class:ComponentCalculates the preferred size based on component content. This method is invoked lazily by getPreferred size.
Returns
the calculated preferred size based on component content
- Overrides:
calcPreferredSizein classComponent
-
paint
Description copied from class:ComponentThis method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.
Parameters
g: the component graphics
-