Class SlideToConfirm

java.lang.Object
com.codename1.ui.Component
com.codename1.components.SlideToConfirm
All Implemented Interfaces:
Animation, Editable, StyleListener

public class SlideToConfirm extends Component

A track with a knob the user drags to the end to confirm an action, so a stray tap cannot trigger it.

SlideToConfirm pay = new SlideToConfirm("Slide to pay");
pay.addActionListener(e -> Log.p("Paid"));

Letting go before the end slides the knob back. Once confirmed it stays at the end, and further drags do nothing, until reset(). The track uses the UIID SlideToConfirm: its accent colour fills the part passed and the knob.

  • Constructor Details

    • SlideToConfirm

      public SlideToConfirm(String text)

      A slider with the given hint text.

      Parameters
      • text: the hint shown on the track
  • Method Details

    • getText

      public String getText()
      The hint text.
    • setText

      public void setText(String text)

      Sets the hint text.

      Parameters
      • text: the text
    • isConfirmed

      public boolean isConfirmed()
      True once the knob reached the end.
    • getPosition

      public float getPosition()
      How far the knob is, from 0 at the start to 1 at the end.
    • reset

      public void reset()
      Moves the knob back to the start and allows another confirmation.
    • addActionListener

      public void addActionListener(ActionListener l)

      Adds a listener told when the user confirms.

      Parameters
      • l: the listener
    • removeActionListener

      public void removeActionListener(ActionListener l)

      Removes a listener.

      Parameters
      • l: the listener
    • pointerPressed

      public void pointerPressed(int x, int y)
      Description copied from class: Component

      If this Component is focused, the pointer pressed event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerPressed in class Component
    • pointerDragged

      public void pointerDragged(int x, int y)
      Description copied from class: Component

      If this Component is focused, the pointer dragged event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerDragged in class Component
    • pointerReleased

      public void pointerReleased(int x, int y)
      Description copied from class: Component

      If this Component is focused, the pointer released event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerReleased in class Component
    • isStickyDrag

      protected boolean isStickyDrag()
      Description copied from class: Component

      Returns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries. This is useful for spinners etc. where the motion might continue beyond the size of the component

      Returns

      false by default

      Overrides:
      isStickyDrag in class Component
    • calcPreferredSize

      protected Dimension calcPreferredSize()
      Description copied from class: Component

      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

      Overrides:
      calcPreferredSize in class Component
    • paint

      public void paint(Graphics g)
      Description copied from class: Component

      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: the component graphics
      Specified by:
      paint in interface Animation
      Overrides:
      paint in class Component