Search code examples
tabris

How to set animated image (gif) in a SWT widget using Tabris Framework


I need to display an animated gif image in the app. In the following code example, I set the setImage property of a Label widget. This works fine in the browser (rap), but mobile app only displays static image without animation. Is there a way to display animated image using Tabris framework?

private void openDialog() {
    this.display = getUI().getDisplay();
    this.shell = new Shell( this.display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL );
this.shell.setLayout( new GridLayout() );        

    Image image = createImage( this.display, "resources/loading.gif" );
    Label label = new Label( this.shell, SWT.NONE );
    label.setImage( image );

    this.shell.open();
}


private Image createImage( Display display, String resourceName ) {
    ClassLoader classLoader = getClass().getClassLoader();
    InputStream inputStream = classLoader.getResourceAsStream( resourceName );
    if( inputStream == null ) {
        throw new IllegalArgumentException( "Resource not found: " + resourceName );
    }
    try {
        return new Image( display, inputStream );
    } finally {
        try {
            inputStream.close();
        } catch( IOException exception ) {
            // TODO handle exception
        }
    }
}

Solution

  • Currently it is not possible to display an animated gif. Tabris will improve support for image display so that feature could be added in the future.