public class SwipeableContainer

  1. Object
  2. Component
  3. Container
  4. SwipeableContainer

ImplementsAnimation, Editable, Iterable<Component>, StyleListener

SwipeableContainer allows us to side swipe a component and expose underlying configuration within it. This is useful for editing, ranking of elements within a set of components e.g. in the sample code below we use a ranking widget and swiping to expose the elements:

public void showForm() {
  Form hi = new Form("Swipe", new BoxLayout(BoxLayout.Y_AXIS));
  hi.add(createRankWidget("A Game of Thrones", "1996")).
      add(createRankWidget("A Clash Of Kings", "1998")).
      add(createRankWidget("A Storm Of Swords", "2000")).
      add(createRankWidget("A Feast For Crows", "2005")).
      add(createRankWidget("A Dance With Dragons", "2011")).
      add(createRankWidget("The Winds of Winter", "TBD")).
      add(createRankWidget("A Dream of Spring", "TBD"));
  hi.show();
}

public SwipeableContainer createRankWidget(String title, String year) {
    MultiButton button = new MultiButton(title);
    button.setTextLine2(year);
    return new SwipeableContainer(FlowLayout.encloseCenterMiddle(createStarRankSlider()),
            button);
}

private void initStarRankStyle(Style s, Image star) {
    s.setBackgroundType(Style.BACKGROUND_IMAGE_TILE_BOTH);
    s.setBorder(Border.createEmpty());
    s.setBgImage(star);
    s.setBgTransparency(0);
}

private Slider createStarRankSlider() {
    Slider starRank = new Slider();
    starRank.setEditable(true);
    starRank.setMinValue(0);
    starRank.setMaxValue(10);
    Font fnt = Font.createTrueTypeFont("native:MainLight", "native:MainLight").
            derive(Display.getInstance().convertToPixels(5, true), Font.STYLE_PLAIN);
    Style s = new Style(0xffff33, 0, fnt, (byte)0);
    Image fullStar = FontImage.createMaterial(FontImage.MATERIAL_STAR, s).toImage();
    s.setOpacity(100);
    s.setFgColor(0);
    Image emptyStar = FontImage.createMaterial(FontImage.MATERIAL_STAR, s).toImage();
    initStarRankStyle(starRank.getSliderEmptySelectedStyle(), emptyStar);
    initStarRankStyle(starRank.getSliderEmptyUnselectedStyle(), emptyStar);
    initStarRankStyle(starRank.getSliderFullSelectedStyle(), fullStar);
    initStarRankStyle(starRank.getSliderFullUnselectedStyle(), fullStar);
    starRank.setPreferredSize(new Dimension(fullStar.getWidth() * 5, fullStar.getHeight()));
    return starRank;
}

Constructors

public SwipeableContainer(Component bottomLeft, Component top)Simple Constructor
public SwipeableContainer(Component bottomLeft, Component bottomRight, Component top)Simple Constructor

Methods

protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
protected void initComponent()Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state
public void openToRight()This method will open the top Component to the right if there is a Component to expose on the left.
public void openToLeft()This method will open the top Component to the left if there is a Component to expose on the right.
public void close()Close the top component if it is currently opened.
public Component getComponentAt(int x, int y)Returns a Component at coordinate (x, y).
public boolean animate()Allows the animation to reduce “repaint” calls when it returns false.
public boolean isSwipeActivated()Returns true if swipe is activated
public void setSwipeActivated(boolean swipeActivated)disable/enable dragging of the top Component
public boolean isOpen()Returns true if the top Component is currently opened
public boolean isOpenedToRight()Returns true if the top Component is opened to the right side
public boolean isOpenedToLeft()Returns true if the top Component is opened to the left side
public void addSwipeOpenListener(ActionListener l)Adds a listener to the SwipeableContainer which will cause an event to dispatch once the SwipeableContainer is fully opened
public void removeSwipeOpenListener(ActionListener l)Removes the given listener from the SwipeableContainer
public SwipeableContainer getPreviouslyOpened()returns a previously opened SwipeableContainer that should be automatically closed when starting to open this one.
public void setPreviouslyOpened(SwipeableContainer previouslyOpened)set a previously open SwipeableContainer, it will be closed as soon as the user starts swiping this one.

Inherited fields

Inherited methods

From Container

encloseIn, encloseIn, initLaf, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyPressed, keyReleased, getLayout, setLayout, invalidate, setShouldLayout, setShouldCalcPreferredSize, getLayoutWidth, getLayoutHeight, applyRTL, constrainWidthWhenScrollable, constrainHeightWhenScrollable, addComponent, addComponent, addComponent, addComponent, replaceAndWait, replaceAndWait, replace, replaceAndWait, replace, createReplaceTransition, isEnabled, setEnabled, removeComponent, cancelRepaints, flushReplace, removeAll, revalidateWithAnimationSafety, revalidate, revalidateLater, forceRevalidate, clearClientProperties, paint, paintGlass, layoutContainer, isSafeArea, setSafeArea, isSafeAreaRoot, getSafeAreaRoot, setSafeAreaRoot, getComponentCount, getComponentAt, getComponentIndex, contains, scrollComponentToVisible, getClosestComponentTo, getResponderAt, findDropTargetAt, pointerPressed, calcPreferredSize, paramString, refreshTheme, isScrollableX, setScrollableX, isScrollableY, setScrollableY, getSideGap, getBottomGap, setScrollable, setCellRenderer, getScrollIncrement, setScrollIncrement, findFirstFocusable, dragInitiated, fireClicked, isSelectableInteraction, getGridPosY, paintComponentBackground, getGridPosX, animateHierarchyAndWait, createAnimateHierarchy, animateHierarchy, animateHierarchyFadeAndWait, createAnimateHierarchyFade, animateHierarchyFade, animateLayoutFadeAndWait, createAnimateLayoutFadeAndWait, animateLayoutFade, createAnimateLayoutFade, animateLayoutAndWait, animateLayout, updateTabIndices, createAnimateLayout, drop, createAnimateMotion, morph, morphAndWait, animateUnlayout, animateUnlayoutAndWait, createAnimateUnlayout, getChildrenAsList, iterator, iterator

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Constructor details

SwipeableContainer

public SwipeableContainer(Component bottomLeft, Component top)
Simple Constructor

Parameters

bottomLeft Component
the Component below the top, this Component is exposed when dragging the top to the right
top Component
the component on top.

SwipeableContainer

public SwipeableContainer(Component bottomLeft, Component bottomRight, Component top)
Simple Constructor

Parameters

bottomLeft Component
the Component below the top, this Component is exposed when dragging the top to the right
bottomRight Component
the Component below the top, this Component is exposed when dragging the top to the Left
top Component
the component on top.

Method details

deinitialize

protected void deinitialize()
Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.

initComponent

protected void initComponent()
Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state

openToRight

public void openToRight()
This method will open the top Component to the right if there is a Component to expose on the left.

openToLeft

public void openToLeft()
This method will open the top Component to the left if there is a Component to expose on the right.

close

public void close()
Close the top component if it is currently opened.

getComponentAt

public Component getComponentAt(int x, int y)

Returns a Component at coordinate (x, y).

WARNING: This method may return components that are disabled, or invisible, or that do not respond to pointer events. If you are looking for the top-most component that responds to pointer events, you should use int) as it is guaranteed to return a component with Component#respondsToPointerEvents() true; or null if none is found at the coordinate.

Parameters

x int
absolute screen location
y int
absolute screen location

Returns

a Component if found, null otherwise

animate

public boolean animate()
Allows 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.Display class.

Returns

true if a repaint is desired or false if no repaint is necessary

isSwipeActivated

public boolean isSwipeActivated()
Returns true if swipe is activated

setSwipeActivated

public void setSwipeActivated(boolean swipeActivated)
disable/enable dragging of the top Component

isOpen

public boolean isOpen()
Returns true if the top Component is currently opened

isOpenedToRight

public boolean isOpenedToRight()
Returns true if the top Component is opened to the right side

isOpenedToLeft

public boolean isOpenedToLeft()
Returns true if the top Component is opened to the left side

addSwipeOpenListener

public void addSwipeOpenListener(ActionListener l)
Adds a listener to the SwipeableContainer which will cause an event to dispatch once the SwipeableContainer is fully opened

Parameters

l ActionListener
implementation of the action listener interface

removeSwipeOpenListener

public void removeSwipeOpenListener(ActionListener l)
Removes the given listener from the SwipeableContainer

Parameters

l ActionListener
implementation of the action listener interface

getPreviouslyOpened

public SwipeableContainer getPreviouslyOpened()
returns a previously opened SwipeableContainer that should be automatically closed when starting to open this one. Called as soon as this Swipeable starts opening. One approach is to override this method to return a previously opened SwipeableContainer Can be overridden to return a SwipeableContainer stored outside this container.

Returns

an already open SwipeableContainer that will be closed when opening this one, or null if none

setPreviouslyOpened

public void setPreviouslyOpened(SwipeableContainer previouslyOpened)
set a previously open SwipeableContainer, it will be closed as soon as the user starts swiping this one. Be aware that with a long list of Swipeable containers it may be a better approach to store the previously opened outside the list and simply override getPreviouslyOpened to return it

Parameters

previouslyOpened SwipeableContainer
an already open SwipeableContainer that will be closed if this one is opened