Class SliderBridge

All Implemented Interfaces:
Animation, Editable, ActionSource, StyleListener, IconHolder, TextHolder

public class SliderBridge extends Slider

Binds a com.codename1.ui.Slider to network progress events so it shows the progress of the current com.codename1.io.ConnectionRequest

Important note: every time that a connectionRequest is retried with the .retry() method, SliderBridge.bindProgress(cr, progress) must be invoked again.

Form hi = new Form("Download Progress", new BorderLayout());
Slider progress = new Slider();
Button download = new Button("Download");
download.addActionListener((e) -> {
    ConnectionRequest cr = new ConnectionRequest("https://www.codenameone.com/img/blog/new_icon.png", false);
    SliderBridge.bindProgress(cr, progress);
    NetworkManager.getInstance().addToQueueAndWait(cr);
    if(cr.getResponseCode() == 200) {
        hi.add(BorderLayout.CENTER, new ScaleImageLabel(EncodedImage.create(cr.getResponseData())));
        hi.revalidate();
    }
});
hi.add(BorderLayout.SOUTH, progress).add(BorderLayout.NORTH, download);
hi.show();
  • Constructor Details

    • SliderBridge

      public SliderBridge()
      Default constructor
    • SliderBridge

      public SliderBridge(ConnectionRequest source)

      Displays progress only for the source object, every other object in the queue before completion will produce an infinite progress. After 100% the progress will no longer move.

      Parameters
      • source: the request whose progress should be followed
    • SliderBridge

      public SliderBridge(ConnectionRequest[] sources)

      Allows displaying progress of multiple requests being sent

      Parameters
      • sources: the requests whose progress should be followed
  • Method Details

    • bindProgress

      public static void bindProgress(ConnectionRequest source, Slider s)

      Allows binding progress to an arbitrary slider

      Parameters
      • source: the source connection request

      • s: the slider

    • bindProgress

      public static void bindProgress(ConnectionRequest[] sources, Slider s)

      Allows binding progress to an arbitrary slider

      Parameters
      • sources: the source connection request (null for all network activity)

      • s: the slider