public class ImageViewer

  1. Object
  2. Component
  3. ImageViewer

ImplementsAnimation, Editable, StyleListener

ImageViewer allows zooming/panning an image and potentially flicking between multiple images within a list of images.

E.g. the trivial usage works like this:

Form hi = new Form("ImageViewer", new BorderLayout());
Image duke = FontImage.createMaterial(FontImage.MATERIAL_INFO, "Label", 3.0f);
ImageViewer iv = new ImageViewer(duke);
hi.add(BorderLayout.CENTER, iv);
hi.show();

You can simulate pinch to zoom on the simulator by dragging the right button away from the top left corner to zoom in and towards the top left corner to zoom out. On Mac touchpads you can drag two fingers to achieve that.

A more elaborate usage includes flicking between multiple images e.g.:

Form hi = new Form("ImageViewer", new BorderLayout());

Image red = Image.createImage(100, 100, 0xffff0000);
Image green = Image.createImage(100, 100, 0xff00ff00);
Image blue = Image.createImage(100, 100, 0xff0000ff);
Image gray = Image.createImage(100, 100, 0xffcccccc);

ImageViewer iv = new ImageViewer(red);
iv.setImageList(new DefaultListModel<>(red, green, blue, gray));
hi.add(BorderLayout.CENTER, iv);

Optional navigation affordances can be enabled when using an image list:

iv.setNavigationArrowsVisible(true);
iv.setThumbnailsVisible(true);
iv.setThumbnailBarHeight(6f);

These options can also be configured globally using theme constants:

  • imageviewerNavigationArrowsBool
  • imageviewerThumbnailsBool
  • imageviewerThumbnailBarHeightMM

You can even download image URL’s dynamically into the ImageViewer thanks to the usage of the com.codename1.ui.list.ListModel. E.g. in this model book cover images are downloaded dynamically:

Form hi = new Form("ImageViewer", new BorderLayout());
final EncodedImage placeholder = EncodedImage.createFromImage(
        FontImage.createMaterial(FontImage.MATERIAL_SYNC, s).
                scaled(300, 300), false);

class ImageList implements ListModel {
    private int selection;
    private String[] imageURLs = {
        "http://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/300px-AGameOfThrones.jpg",
        "http://awoiaf.westeros.org/images/thumb/3/39/AClashOfKings.jpg/300px-AClashOfKings.jpg",
        "http://awoiaf.westeros.org/images/thumb/2/24/AStormOfSwords.jpg/300px-AStormOfSwords.jpg",
        "http://awoiaf.westeros.org/images/thumb/a/a3/AFeastForCrows.jpg/300px-AFeastForCrows.jpg",
        "http://awoiaf.westeros.org/images/7/79/ADanceWithDragons.jpg"
    };
    private Image[] images;
    private EventDispatcher listeners = new EventDispatcher();

    public ImageList() {
        this.images = new EncodedImage[imageURLs.length];
    }

    public Image getItemAt(final int index) {
        if(images[index] == null) {
            images[index] = placeholder;
            Util.downloadUrlToStorageInBackground(imageURLs[index], "list" + index, (e) -> {
                    try {
                        images[index] = EncodedImage.create(Storage.getInstance().createInputStream("list" + index));
                        listeners.fireDataChangeEvent(index, DataChangedListener.CHANGED);
                    } catch(IOException err) {
                        err.printStackTrace();
                    }
            });
        }
        return images[index];
    }

    public int getSize() {
        return imageURLs.length;
    }

    public int getSelectedIndex() {
        return selection;
    }

    public void setSelectedIndex(int index) {
        selection = index;
    }

    public void addDataChangedListener(DataChangedListener l) {
        listeners.addListener(l);
    }

    public void removeDataChangedListener(DataChangedListener l) {
        listeners.removeListener(l);
    }

    public void addSelectionListener(SelectionListener l) {
    }

    public void removeSelectionListener(SelectionListener l) {
    }

    public void addItem(Image item) {
    }

    public void removeItem(int index) {
    }
};

ImageList imodel = new ImageList();

ImageViewer iv = new ImageViewer(imodel.getItemAt(0));
iv.setImageList(imodel);
hi.add(BorderLayout.CENTER, iv);

Fields

public static final int IMAGE_FIT = 0Indicates the initial position of the image in the viewer to FIT to the component size
public static final int IMAGE_FILL = 1Indicates the initial position of the image in the viewer to FILL the component size.

Constructors

public ImageViewer()Default constructor
public ImageViewer(Image i)Initializes the component with an image

Methods

protected void resetFocusable()Restores the state of the focusable flag to its default state
public String[] getPropertyNames()A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code
protected boolean shouldBlockSideSwipe()A component that might need side swipe such as the slider could block it from being used for some other purpose when on top of said component.
public Class[] getPropertyTypes()Matches the property names method (see that method for further details).
public String[] getPropertyTypeNames()This method is here to workaround an XMLVM array type bug where property types aren’t identified properly, it returns the names of the types using the following type names: String,int,double,long,byte,short,char,String[],String[][],byte[],I…
public Object getPropertyValue(String name)Returns the current value of the property name, this method is used by the GUI builder
public String setPropertyValue(String name, Object value)Sets a new value to the given property, returns an error message if failed and null if successful.
public void initComponent()Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state
public int getImageX()Returns the x position of the image viewport which can be useful when it is being panned by the user
public int getImageY()Returns the y position of the image viewport which can be useful when it is being panned by the user
public void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
public void keyReleased(int key)If this Component is focused, the key released event will call this method
public void pointerPressed(int x, int y)If this Component is focused, the pointer pressed event will call this method
protected void dragFinished(int x, int y)Callback indicating that the drag has finished either via drop or by releasing the component
public void pointerReleased(int x, int y)If this Component is focused, the pointer released event will call this method
protected void pinchReleased(int x, int y)To be implemented by subclasses interested in being notified when a pinch zoom has ended (i.e the user has removed one of their fingers, but is still dragging).
protected boolean mouseWheel(WheelEvent ev)Handles a scroll wheel or trackpad scroll over this component, before its listeners and before anything above it in the hierarchy.
public void pointerDragged(int x, int y)If this Component is focused, the pointer dragged event will call this method
protected void laidOut()This is a callback method to inform the Component when it’s been laidout on the parent Container
protected boolean pinch(float scale)Invoked by subclasses interested in handling pinch to zoom events, if true is returned other drag events will not be broadcast
public Image getCroppedImage(int backgroundColor)Gets the current image cropped using the current pan and zoom state.
public Image getCroppedImage(int width, int height, int backgroundColor)Gets the current image cropped using the current pan and zoom state.
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.
public boolean animate()Allows the animation to reduce “repaint” calls when it returns false.
public boolean isAllowScaleDown()Allows the image to scale down when image initial position is set to fit this is off by default since the UX isn’t great
public void setAllowScaleDown(boolean allowScaleDown)Allows the image to scale down when image initial position is set to fit this is off by default since the UX isn’t great
public void paint(Graphics g)This 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.
protected void paintBackground(Graphics g)This method paints the Component background, it should be overriden by subclasses to perform custom background drawing.
public Image getImage()Returns the currently showing image
public final void setImage(Image image)Sets the currently showing image
public void setImageNoReposition(Image image)Sets the current image without any changes to the panning/scaling
public ListModel<Image> getImageList()Returns the list model containing the images in the we can swipe through
public void setImageList(ListModel<Image> model)By providing this optional list of images you can allows swiping between multiple images
public void setAnimateZoom(boolean animateZoom)Indicates if the zoom should bee animated.
public boolean isAnimatedZoom()Indicates if the zoom should bee animated.
public boolean isNavigationArrowsVisible()Indicates if side navigation arrows should be painted for moving between images.
public void setNavigationArrowsVisible(boolean navigationArrowsVisible)Enables side navigation arrows (material font icons) for moving between images.
public boolean isThumbnailsVisible()Indicates if thumbnails should be painted in a strip at the bottom for direct image selection.
public void setThumbnailsVisible(boolean thumbnailsVisible)Enables a bottom thumbnail strip for direct image selection.
public float getThumbnailBarHeight()Gets the thumbnail strip height in millimeters.
public void setThumbnailBarHeight(float thumbnailBarHeight)Sets the thumbnail strip height in millimeters.
public float getZoom()Manipulate the zoom level of the application
public void setZoom(float zoom)Manipulate the zoom level of the application
public void setZoom(float zoom, float panPositionX, float panPositionY)Manipulate the zoom level of the application
public Image getSwipePlaceholder()This image is shown briefly during swiping while the full size image is loaded
public void setSwipePlaceholder(Image swipePlaceholder)This image is shown briefly during swiping while the full size image is loaded
public boolean isEagerLock()Eager locking effectively locks the right/left images as well as the main image, as a result more heap is taken
public void setEagerLock(boolean eagerLock)Eager locking effectively locks the right/left images as well as the main image, as a result more heap is taken
public boolean isCycleLeft()By default the ImageViewer cycles from the beginning to the end of the list when going to the left, setting this to false prevents this behaviour
public void setCycleLeft(boolean cycleLeft)By default the ImageViewer cycles from the beginning to the end of the list when going to the left, setting this to false prevents this behaviour
public boolean isCycleRight()By default the ImageViewer cycles from the end to the beginning of the list when going to the right, setting this to false prevents this behaviour
public void setCycleRight(boolean cycleRight)By default the ImageViewer cycles from the end to the beginning of the list when going to the right, setting this to false prevents this behaviour
public float getSwipeThreshold()The swipe threshold is a number between 0 and 1 that indicates the threshold after which the swiped image moves to the next image.
public void setSwipeThreshold(float swipeThreshold)The swipe threshold is a number between 0 and 1 that indicates the threshold after which the swiped image moves to the next image.
public void setImageInitialPosition(int imageInitialPosition)Sets the viewer initial image position to fill or to fit.

Inherited fields

Inherited methods

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, initLaf, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, 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, fireClicked, isSelectableInteraction, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyPressed, 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, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, dragInitiated, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, 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, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, 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, paramString, refreshTheme, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, cancelRepaints, 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

Field details

IMAGE_FIT

public static final int IMAGE_FIT = 0
Indicates the initial position of the image in the viewer to FIT to the component size

IMAGE_FILL

public static final int IMAGE_FILL = 1
Indicates the initial position of the image in the viewer to FILL the component size. Notice this type might drop edges of the images in order to stretch the image to the full size of the Component.

Constructor details

ImageViewer

public ImageViewer()
Default constructor

ImageViewer

public ImageViewer(Image i)
Initializes the component with an image

Parameters

i Image
image to show

Method details

resetFocusable

protected void resetFocusable()
Restores the state of the focusable flag to its default state

getPropertyNames

public String[] getPropertyNames()
A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code

Returns

the property names allowing mutation

shouldBlockSideSwipe

protected boolean shouldBlockSideSwipe()
A component that might need side swipe such as the slider could block it from being used for some other purpose when on top of said component.

getPropertyTypes

public Class[] getPropertyTypes()
Matches the property names method (see that method for further details).

Returns

the types of the properties

getPropertyTypeNames

public String[] getPropertyTypeNames()
This method is here to workaround an XMLVM array type bug where property types aren’t identified properly, it returns the names of the types using the following type names: String,int,double,long,byte,short,char,String[],String[][],byte[],Image,Image[],Object[],ListModel,ListCellRenderer

Returns

Array of type names

getPropertyValue

public Object getPropertyValue(String name)
Returns the current value of the property name, this method is used by the GUI builder

Parameters

name String
the name of the property

Returns

the value of said property

setPropertyValue

public String setPropertyValue(String name, Object value)
Sets a new value to the given property, returns an error message if failed and null if successful. Notice that some builtin properties such as “$designMode” might be sent to components to indicate application state.

Parameters

name String
the name of the property
value Object
new value for the property

Returns

error message or null

initComponent

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

getImageX

public int getImageX()
Returns the x position of the image viewport which can be useful when it is being panned by the user

Returns

x position within the image for the top left corner

getImageY

public int getImageY()
Returns the y position of the image viewport which can be useful when it is being panned by the user

Returns

y position within the image for the top left corner

deinitialize

public 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.

keyReleased

public void keyReleased(int key)
If this Component is focused, the key released event will call this method

Parameters

key int
the key code value to indicate a physical key.

pointerPressed

public void pointerPressed(int x, int y)
If this Component is focused, the pointer pressed event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

dragFinished

protected void dragFinished(int x, int y)
Callback indicating that the drag has finished either via drop or by releasing the component

Parameters

x int
the x location
y int
the y location

pointerReleased

public void pointerReleased(int x, int y)
If this Component is focused, the pointer released event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pinchReleased

protected void pinchReleased(int x, int y)
To be implemented by subclasses interested in being notified when a pinch zoom has ended (i.e the user has removed one of their fingers, but is still dragging).

Parameters

x int
The x-coordinate of the remaining finger in the drag. (Absolute)
y int
The y-coordinate of the remaining finger in the drag. (Absolute)

mouseWheel

protected boolean mouseWheel(WheelEvent ev)

Handles a scroll wheel or trackpad scroll over this component, before its listeners and before anything above it in the hierarchy.

A component that moves its own content – an editor that scrolls itself, a viewer that pans – implements this. Everything else leaves it alone and the wheel scrolls the nearest scrollable ancestor, which is what a wheel means.

This exists because a wheel used to arrive as a synthetic press, drag and release played into the component tree: a component that wanted the wheel got it by handling pointer events, and so did every component that did not want it. The events are gone and this is what replaces them, for the few components that have something of their own to move.

A wheel pans a zoomed image, which is what a wheel over a picture means on a desktop, and leaves an unzoomed one alone so the page it sits on scrolls instead. Zoom is the wheel with a modifier, which the ports already deliver as a magnify gesture – see #pinch(float).

Parameters

ev WheelEvent
the wheel event, carrying the scroll deltas in display pixels

Returns

true when this component handled the wheel and nothing else should act on it

pointerDragged

public void pointerDragged(int x, int y)
If this Component is focused, the pointer dragged event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

laidOut

protected void laidOut()
This is a callback method to inform the Component when it’s been laidout on the parent Container

pinch

protected boolean pinch(float scale)
Invoked by subclasses interested in handling pinch to zoom events, if true is returned other drag events will not be broadcast

Parameters

scale float
the scaling of the pinch operation a number larger than 1 means scaling up and smaller than 1 means scaling down. It is recommended that code would threshold the number (so a change between 1.0 and 1.02 shouldn’t necessarily trigger zoom). Notice that this number is relevant to current zoom levels and unaware of them so you should also enforce limits of maximum/minimum zoom levels.

Returns

false by default

getCroppedImage

public Image getCroppedImage(int backgroundColor)
Gets the current image cropped using the current pan and zoom state. The cropped image dimensions will be the result of cropping the full-sized image with the current pan/zoom state. The aspect ratio will match the aspect ratio of the ImageViewer - not the source image itself.

Parameters

backgroundColor int
The background color, visible for letterboxing.

Returns

The cropped image.

getCroppedImage

public Image getCroppedImage(int width, int height, int backgroundColor)
Gets the current image cropped using the current pan and zoom state.

Parameters

width int
The width of the cropped image. Use -1 to match aspect ratio of the ImageViewer component. Either height or width must be positive.
height int
The height of the cropped image. Use -1 to match aspect ratio of the ImageViewer component. Either height or width must be positive.
backgroundColor int
Background color to use for letterboxing.

Returns

Cropped image in specified dimensions.

calcPreferredSize

protected Dimension calcPreferredSize()
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Returns

the calculated preferred size based on component content

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

isAllowScaleDown

public boolean isAllowScaleDown()
Allows the image to scale down when image initial position is set to fit this is off by default since the UX isn’t great

Returns

the allowScaleDown

setAllowScaleDown

public void setAllowScaleDown(boolean allowScaleDown)
Allows the image to scale down when image initial position is set to fit this is off by default since the UX isn’t great

Parameters

allowScaleDown boolean
the allowScaleDown to set

paint

public void paint(Graphics g)
This 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 Graphics
the component graphics

paintBackground

protected void paintBackground(Graphics g)
This method paints the Component background, it should be overriden by subclasses to perform custom background drawing.

Parameters

g Graphics
the component graphics

getImage

public Image getImage()
Returns the currently showing image

Returns

the image

setImage

public final void setImage(Image image)
Sets the currently showing image

Parameters

image Image
the image to set

setImageNoReposition

public void setImageNoReposition(Image image)
Sets the current image without any changes to the panning/scaling

Parameters

image Image
new image instance

getImageList

public ListModel<Image> getImageList()
Returns the list model containing the images in the we can swipe through

Returns

the list model

setImageList

public void setImageList(ListModel<Image> model)
By providing this optional list of images you can allows swiping between multiple images

Parameters

model ListModel<Image>
a list of images

setAnimateZoom

public void setAnimateZoom(boolean animateZoom)
Indicates if the zoom should bee animated. It’s true by default

Parameters

animateZoom boolean
true if zoom is animated

isAnimatedZoom

public boolean isAnimatedZoom()
Indicates if the zoom should bee animated. It’s true by default

Returns

true if zoom is animated

isNavigationArrowsVisible

public boolean isNavigationArrowsVisible()
Indicates if side navigation arrows should be painted for moving between images.

Returns

true if side navigation arrows are visible.

setNavigationArrowsVisible

public void setNavigationArrowsVisible(boolean navigationArrowsVisible)
Enables side navigation arrows (material font icons) for moving between images.

Parameters

navigationArrowsVisible boolean
true to show side navigation arrows.

isThumbnailsVisible

public boolean isThumbnailsVisible()
Indicates if thumbnails should be painted in a strip at the bottom for direct image selection.

Returns

true if the thumbnail strip is visible.

setThumbnailsVisible

public void setThumbnailsVisible(boolean thumbnailsVisible)
Enables a bottom thumbnail strip for direct image selection.

Parameters

thumbnailsVisible boolean
true to show thumbnails.

getThumbnailBarHeight

public float getThumbnailBarHeight()
Gets the thumbnail strip height in millimeters.

Returns

Height of the thumbnail strip in millimeters.

setThumbnailBarHeight

public void setThumbnailBarHeight(float thumbnailBarHeight)
Sets the thumbnail strip height in millimeters.

Parameters

thumbnailBarHeight float
Height of the thumbnail strip in millimeters.

getZoom

public float getZoom()
Manipulate the zoom level of the application

Returns

the zoom

setZoom

public void setZoom(float zoom)
Manipulate the zoom level of the application

Parameters

zoom float
the zoom to set

setZoom

public void setZoom(float zoom, float panPositionX, float panPositionY)
Manipulate the zoom level of the application

Parameters

zoom float
the zoom to set
panPositionX float
A float value between 0 and 1 to set the image x position
panPositionY float
A float value between 0 and 1 to set the image y position

getSwipePlaceholder

public Image getSwipePlaceholder()
This image is shown briefly during swiping while the full size image is loaded

Returns

the swipePlaceholder

setSwipePlaceholder

public void setSwipePlaceholder(Image swipePlaceholder)
This image is shown briefly during swiping while the full size image is loaded

Parameters

swipePlaceholder Image
the swipePlaceholder to set

isEagerLock

public boolean isEagerLock()
Eager locking effectively locks the right/left images as well as the main image, as a result more heap is taken

Returns

the eagerLock

setEagerLock

public void setEagerLock(boolean eagerLock)
Eager locking effectively locks the right/left images as well as the main image, as a result more heap is taken

Parameters

eagerLock boolean
the eagerLock to set

isCycleLeft

public boolean isCycleLeft()
By default the ImageViewer cycles from the beginning to the end of the list when going to the left, setting this to false prevents this behaviour

Returns

true if it should cycle left from beginning

setCycleLeft

public void setCycleLeft(boolean cycleLeft)
By default the ImageViewer cycles from the beginning to the end of the list when going to the left, setting this to false prevents this behaviour

Parameters

cycleLeft boolean
the cycle left to set

isCycleRight

public boolean isCycleRight()
By default the ImageViewer cycles from the end to the beginning of the list when going to the right, setting this to false prevents this behaviour

Returns

true if it should cycle right from the end

setCycleRight

public void setCycleRight(boolean cycleRight)
By default the ImageViewer cycles from the end to the beginning of the list when going to the right, setting this to false prevents this behaviour

Parameters

cycleRight boolean
the cycle right to set

getSwipeThreshold

public float getSwipeThreshold()
The swipe threshold is a number between 0 and 1 that indicates the threshold after which the swiped image moves to the next image. Below that number the image will bounce back

Returns

the threshold

setSwipeThreshold

public void setSwipeThreshold(float swipeThreshold)
The swipe threshold is a number between 0 and 1 that indicates the threshold after which the swiped image moves to the next image. Below that number the image will bounce back

Parameters

swipeThreshold float
the swipeThreshold to set

setImageInitialPosition

public void setImageInitialPosition(int imageInitialPosition)
Sets the viewer initial image position to fill or to fit.

Parameters

imageInitialPosition int
values can be IMAGE_FILL or IMAGE_FIT