public class Buttons extends EventGenerator
For a specified subset of buttons it holds the elapsed time since the last event occurrence for that button and
supports the optional generation of click and double click events. Note that Buttons pre-configured by the system
normally support these extended features for all their buttons. However, it is implementation dependent whether or
not the features are enabled by default.
This class defines generic button actions : PRESSED
, RELEASED
, LONG
, REPEATED
,
CLICKED
and DOUBLE_CLICKED
.
Buttons allows a button to have at most 256 kind of actions per button. Each Buttons may be associated with at most
256 buttons.
This class also contains a number of static helper methods that return information extracted from an event.
Modifier and Type | Field and Description |
---|---|
static int |
CLICKED
Constant for "clicked" action.
|
static int |
DOUBLE_CLICKED
Constant for "double clicked" action.
|
static int |
EVENT_TYPE
The BUTTON event type returned by
getEventType() . |
static int |
LONG
Constant for "long" action (button pressed for a "long" time).
|
static int |
PRESSED
Constant for "pressed" action.
|
static int |
RELEASED
Constant for "released" action.
|
static int |
REPEATED
Constant for "repeated" action (button held down).
|
Constructor and Description |
---|
Buttons()
Creates a buttons event generator that does not support click, doubleClick nor elapsedTime for any of its
buttons.
|
Buttons(int nbButtons)
Creates a buttons event generator where elapsedTime, click and doubleClick features are supported and enabled for
the first
nbButtons (doubleClick feature is initialized with a 200ms delay). |
Modifier and Type | Method and Description |
---|---|
int |
buildEvent(int action,
int buttonId)
Builds a MicroUI event for the given action on given button.
|
boolean |
clickEnabled(int buttonId)
Returns
true if the generator should send a click event. |
boolean |
doubleClickEnabled(int buttonId)
Returns
true if the generator should send a double click event. |
long |
elapsedTime(int buttonId)
Returns the elapsed time in milliseconds between the two previous
PRESSED events that occurred on the
specified button. |
void |
enableClick(boolean enable,
int buttonId)
For the given button, specify whether the generator should send a click event for each pressed event.
|
void |
enableDoubleClick(boolean enable,
int click,
int buttonId)
For the given button, specify whether the generator should send a double click event.
|
static int |
getAction(int event)
Returns the button's action held by the button event.
|
static int |
getButtonId(int event)
Returns the button's id held by the button event.
|
int |
getEventType()
Returns the MicroUI event type for this button event generator.
|
static boolean |
isClicked(int event)
Tells if an button event is a click event.
|
static boolean |
isDoubleClicked(int event)
Tells if an button event is a double click event.
|
static boolean |
isLong(int event)
Tells if an button event is a long event.
|
static boolean |
isPressed(int event)
Tells if a button event is a press event.
|
static boolean |
isReleased(int event)
Tells if a button event is a release event.
|
static boolean |
isRepeated(int event)
Tells if a button event is a repeat event.
|
void |
send(int action,
int buttonId)
Sends a MicroUI event for the given action on given button to the listener of the Buttons.
|
boolean |
supportsExtendedFeatures(int buttonId)
Returns
true if the button supports the extended features elapsedTime, click and doubleClick
features. |
addToSystemPool, get, get, get, getEventHandler, getId, removeFromSystemPool, sendEvent, setEventHandler
public static final int EVENT_TYPE
getEventType()
.public static final int PRESSED
public static final int RELEASED
public static final int LONG
public static final int REPEATED
public static final int CLICKED
public static final int DOUBLE_CLICKED
public Buttons(int nbButtons)
nbButtons
(doubleClick feature is initialized with a 200ms delay).nbButtons
- the number of buttons that support the extended featuresButtons()
public Buttons()
new Buttons(0)
.public void enableClick(boolean enable, int buttonId)
buttonId
refers to a button that does not have support for click events
(see Buttons(int)
).enable
- true
to enable the click function on the buttonbuttonId
- the buttonpublic void enableDoubleClick(boolean enable, int click, int buttonId)
buttonId
refers to a button that does not have support for doubleClick events (see
Buttons(int)
).enable
- true
to enable the double click function on the button. Click event is also enabled if it
was not.click
- the maximum time elapsed between two clicks (in milliseconds) to generate a double click eventbuttonId
- the buttonpublic boolean supportsExtendedFeatures(int buttonId)
true
if the button supports the extended features elapsedTime, click and doubleClick
features.buttonId
- the buttontrue
if the button supports the extended features. and double click.public boolean clickEnabled(int buttonId)
true
if the generator should send a click event. Note that this method has no effect if
buttonId
refers to a button that does not have support for click events (see Buttons(int)
).buttonId
- the buttontrue
if the generator should send a click event.public boolean doubleClickEnabled(int buttonId)
true
if the generator should send a double click event. Note that this method has no effect
if buttonId
refers to a button that does not have support for double click events (see
Buttons(int)
).buttonId
- the buttontrue
if the generator should send a dooble click event.public int getEventType()
EVENT_TYPE
.getEventType
in class EventGenerator
public static boolean isPressed(int event)
event
- the button event.public static boolean isReleased(int event)
event
- the button event.public static boolean isRepeated(int event)
event
- the button event.public static boolean isLong(int event)
event
- the button event.public static boolean isClicked(int event)
event
- the button event.public static boolean isDoubleClicked(int event)
event
- the button event.public static int getButtonId(int event)
event
- the button event.public static int getAction(int event)
event
- the button event.public long elapsedTime(int buttonId)
PRESSED
events that occurred on the
specified button. The elapsedTime for the very first occurrence has no meaning.buttonId
- the button on which to get the elapsed timebuttonId
refers to a button that does not have support for elapsedTime (see Buttons(int)
)public int buildEvent(int action, int buttonId)
public void send(int action, int buttonId)
CLICKED
and/or DOUBLE_CLICKED
events if the matching button's feature is
enabled.This method is useful when other input mechanisms wish to simulate button actions.