Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class CoachMarks

  1. Object
  2. CoachMarks

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.

Constructors

public CoachMarks(Form form)A tour over a form.

Methods

public CoachMarks add(Component target, String title, String text)Adds a step that lights a component.
public CoachMarks setOnFinish(Runnable onFinish)Runs code when the tour ends, whether it was finished or skipped.
public CoachMarks setSkippable(boolean skippable)Whether the bubble offers “Skip”.
public int getStepCount()The number of steps.
public int getCurrentStep()The step on screen.
public boolean isShowing()Whether the tour is on screen.
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.
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.
public void show()Shows the tour from its first step.
public void next()Moves to the next step, or ends the tour after the last one.
public void dismiss()Ends the tour and runs the code given to #setOnFinish(Runnable).

Inherited methods

Constructor details

CoachMarks

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

Parameters

form 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 Component
the component to light; it must be on the form when its step shows
title String
a short title, or null
text String
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 Runnable
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 boolean
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 String
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 String
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).