Package totalcross.ui

Class Spinner

  • All Implemented Interfaces:
    TimerListener

    public class Spinner
    extends Control
    implements TimerListener
    Spinner is a control that shows an image indicating that something is running in the background. To start the spin call the start method, and to stop it call the stop method. If you try to run a spinner inside a tight loop, be sure to call spinner.update() or the spinner will not be updated. Without this, it will work in Java but not on devices.
    Since:
    TotalCross 1.3
    • Field Detail

      • spinnerType

        public static int spinnerType
        Defines the type of spinner for all instances. Defaults for IPHONE when running in iPhone and ANDROID for all other platforms.
    • Constructor Detail

      • Spinner

        public Spinner()
        Creates a spinner with the defined spinnerType.
      • Spinner

        public Spinner​(int type)
        Creates a spinner of the given type.
      • Spinner

        public Spinner​(Image anim)
        Creates a spinner from an animated GIF. You can download additional animations from: here. Change only the given settings:
        • Image type: GIF
        • Transparent background: Yes
        • Foreground color: FFFFFF if the animation is only black, 000000 if it has fade.
        • Background color: 000000
        • Keep size 128 x 128
        Then press Generate preloader and download the gif file that will appear at the right pane. If the spinner is moving counterclockwise, you can make it go clickwise by changing also, under the Advanced options:
        • Flip image: Hor
        • Reverse animation: Yes
        The image is colorized with the foreground color. If it appears not filled, try selecting the "Invert colors" option, and use 000000 as foreground color.
    • Method Detail

      • setType

        public void setType​(int t)
        Changes the Spinner to one of the predefined types.
      • setImage

        public void setImage​(Image anim)
        Changes the gif image of this Spinner
      • onBoundsChanged

        public void onBoundsChanged​(boolean screenChanged)
        Description copied from class: Control
        Called after a setRect.
        Overrides:
        onBoundsChanged in class Control
        Parameters:
        screenChanged - If the bounds were changed due to a screen change (rotation, collapse)
      • onColorsChanged

        public void onColorsChanged​(boolean changed)
        Description copied from class: Control
        Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled
        Overrides:
        onColorsChanged in class Control
      • onPaint

        public void onPaint​(Graphics g)
        Description copied from class: Control
        Called to draw the control. When this method is called, the graphics object passed has been translated into the coordinate system of the control and the area behind the control has already been painted.
        Overrides:
        onPaint in class Control
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • start

        public void start()
        Starts the spinning thread.
      • stop

        public void stop()
        Stops the spinning thread.
      • isRunning

        public boolean isRunning()
        Returns if the spin is running.
      • update

        @Deprecated
        public void update()
        Deprecated.
        Updates the spinner; call this when using the spinner inside a loop. Deprecated, use the Start() and Stop() methods
      • getTimestep

        public int getTimestep()
        Gets the timestep used to change images
        Returns:
        time in milliseconds
      • setTimestep

        public void setTimestep​(int timestep)
        Sets the timestep used to change images.
        Parameters:
        timestep - time in milliseconds