Class CoachMarks

java.lang.Object
com.codename1.components.CoachMarks

public class CoachMarks extends Object

Coach marks (also called a feature tour, product walkthrough, onboarding overlay, spotlight or showcase view): the screen is dimmed, one component at a time is lit through a cut-out, and a bubble next to it says what it does.

Form form = new Form("Orders", BoxLayout.y());
Button search = new Button("Search");
Button filter = new Button("Filter");
Button add = new Button("New order");
form.add(FlowLayout.encloseIn(search, filter, add));
form.show();
new CoachMarks(form)
        .add(search, "Search", "Find any order by number or name.")
        .add(filter, "Filters", "Narrow the list to what is still open.")
        .add(add, "New order", "Start an order from here.")
        .showOnce("orders-tour");

A tap on the dim or on "Next" moves to the next step, "Skip" ends the tour, and the last step's button reads "Done". #showOnce(String) shows the tour the first time only and remembers that in Preferences, which is what an onboarding tour usually wants; #show() shows it every time. A tour of one step is a single feature highlight.

While the tour is up, touches go to it and not to the form under it. Each step is announced to screen readers.

UIIDs: CoachMarkOverlay (its background colour and transparency are the dim), CoachMarkBubble, CoachMarkTitle, CoachMarkText, CoachMarkStep and CoachMarkButton. A theme that does not style them gets a light or dark bubble to match the platform's appearance. The button labels are localized through the keys CoachMarkNext, CoachMarkDone and CoachMarkSkip.

This replaces the deprecated GlassTutorial.

  • Constructor Details

    • CoachMarks

      public CoachMarks(Form form)

      A tour over a form. Add steps with #add(Component, String, String).

      Parameters
      • form: the form whose components the steps point at
  • Method Details

    • add

      public CoachMarks add(Component target, String title, String text)

      Adds a step that lights a component.

      Parameters
      • target: the component to light; it must be on the form when its step shows

      • title: a short title, or null

      • text: what the component does

      Returns

      this, for chaining

    • setOnFinish

      public CoachMarks setOnFinish(Runnable onFinish)

      Runs code when the tour ends, whether it was finished or skipped.

      Parameters
      • onFinish: the code to run, or null
      Returns

      this, for chaining

    • setSkippable

      public CoachMarks setSkippable(boolean skippable)

      Whether the bubble offers "Skip". On by default.

      Parameters
      • skippable: false to hide the skip button
      Returns

      this, for chaining

    • getStepCount

      public int getStepCount()

      The number of steps.

      Returns

      the step count

    • getCurrentStep

      public int getCurrentStep()

      The step on screen.

      Returns

      the zero based step, or -1 when the tour is not showing

    • isShowing

      public boolean isShowing()

      Whether the tour is on screen.

      Returns

      true while it is showing

    • showOnce

      public boolean showOnce(String key)

      Shows the tour the first time this is called with a key, and does nothing on later calls, across restarts of the app. The key is stored when the tour starts, so a tour that is skipped is not shown again either.

      Parameters
      • key: a name for this tour, unique within the app
      Returns

      true if the tour was shown

    • resetShowOnce

      public static void resetShowOnce(String key)

      Forgets that a tour was shown by #showOnce(String), so it shows again, for a "show the tips again" setting.

      Parameters
      • key: the key the tour was shown with
    • show

      public void show()
      Shows the tour from its first step. Does nothing if it has no steps or is already showing.
    • next

      public void next()
      Moves to the next step, or ends the tour after the last one.
    • dismiss

      public void dismiss()
      Ends the tour and runs the code given to #setOnFinish(Runnable).