Base class for receiving events related to the magstripe reader on a Grabba device.
At present, only one event is supported by this class:
Each event may invoke callbacks in two ways:
By default, each listener object will receive event notifications from the driver for its entire lifetime; the enable() and disable() methods may be used if control is required over whether notifications are received.
The default behaviour for each event, if not overridden, on an enabled listener object is as follows:
Overrides need not call the superclass' equivalent method unless it is necessary to preserve the delegation (i.e. to support both subclassing and delegation from a single object).
Thread safety: This class is intended to be thread-safe; any classes deriving from it should ensure that the relevant methods are callable from any thread.
Public Member Functions | |
MagstripeListener () | |
Default constructor - builds a listener object then enables receipt of events from the driver. | |
MagstripeListener (boolean startEnabled) | |
Constructor - builds a listener object then optionally enables receipt of events from the driver. More... | |
void | dataEvent (@NonNull MagstripeData data) |
Callback which is invoked when one or more tracks are successfully read from a magstripe card. More... | |
final void | disable () |
Disable receipt of events from the driver by this object. More... | |
final void | enable () |
Enable receipt of events from the driver by this object. More... | |
final void | setDelegate (Delegate newDelegate) |
Set the delegate which will receive event callbacks if default listener behaviour is not overridden. More... | |
MagstripeListener | ( | boolean | startEnabled | ) |
Constructor - builds a listener object then optionally enables receipt of events from the driver.
startEnabled | If set, the listener object is enabled immediately (equivalent of default constructor), otherwise it is disabled until the first call to enable() |
void dataEvent | ( | @NonNull MagstripeData | data | ) |
Callback which is invoked when one or more tracks are successfully read from a magstripe card.
This method will be triggered after a successful swipe of a magstripe card through the Grabba device's reading slot, providing the listener object is enabled.
Override this method to receive callbacks when the object is enabled (at construction or via enable()) and the event is triggered.
data | The data which was read from the magnetic stripe; see MagstripeData for details |
Implements MagstripeInterface.
|
inherited |
Disable receipt of events from the driver by this object.
This has no effect if the object was already disabled.
|
inherited |
Enable receipt of events from the driver by this object.
This has no effect if the object was already enabled.
|
inherited |
Set the delegate which will receive event callbacks if default listener behaviour is not overridden.
Delegation may alternatively be disabled by providing a null reference here.
newDelegate | If null, disables delegation; if non-null, enables delegation and sets the delegate to the supplied object. |