Base class for receiving events related to scanning barcodes.
The following events are 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 | |
BarcodeListener () | |
Default constructor - builds a listener object then enables receipt of events from the driver. | |
BarcodeListener (boolean startEnabled) | |
Constructor - builds a listener object then optionally enables receipt of events from the driver. More... | |
void | cancelEvent () |
Callback which is invoked when a barcode scan is cancelled. More... | |
void | dataEvent (@NonNull BarcodeData data) |
Callback which is invoked when a barcode is successfully scanned. 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... | |
void | errorEvent (@NonNull ErrorCode error) |
Callback which is invoked when a barcode scan fails. More... | |
final void | setDelegate (Delegate newDelegate) |
Set the delegate which will receive event callbacks if default listener behaviour is not overridden. More... | |
void | startEvent () |
Callback which is invoked when a barcode scan is triggered. More... | |
void | stopEvent () |
Callback which is invoked when a barcode scan is stopped, regardless of reason. More... | |
void | timeoutEvent () |
Callback which is invoked when barcode scanning times out. More... | |
BarcodeListener | ( | 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 cancelEvent | ( | ) |
Callback which is invoked when a barcode scan is cancelled.
This method will be triggered by the driver when a barcode scan on a connected Grabba device was cancelled by a call to BarcodeAPI.stopScan(), providing the listener object is enabled. Note that this callback will only trigger in the event that a running operation was cancelled; if stopScan is called but there was no scan active at the time, then no callback will be triggered.
Override this method to receive callbacks when the object is enabled (at construction or via enable()) and the event is triggered.
Implements BarcodeInterface.
void dataEvent | ( | @NonNull BarcodeData | data | ) |
Callback which is invoked when a barcode is successfully scanned.
This method will be triggered by the driver when a connected Grabba device successfully scans a barcode, 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 | Contains the data which was read, along with the ID of the symbology which was detected |
Implements BarcodeInterface.
|
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.
void errorEvent | ( | @NonNull ErrorCode | error | ) |
Callback which is invoked when a barcode scan fails.
This method will be triggered by the driver when a barcode scan on a connected Grabba device fails for any reason other than timeout or cancellation, 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.
error | Error code indicating the reasons for the failure |
Implements BarcodeInterface.
|
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. |
void startEvent | ( | ) |
Callback which is invoked when a barcode scan is triggered.
This method will be triggered by the driver when there is a connected Grabba device with barcode capabilities, BarcodeAPI.startScan() is called, and 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.
Implements BarcodeInterface.
void stopEvent | ( | ) |
Callback which is invoked when a barcode scan is stopped, regardless of reason.
This method will be triggered by the driver when a barcode scan is stopped, regardless of whether it completed successfully, providing the listener object is enabled.
In addition to this callback, one other callback will be triggered, depending on the outcome of the operation:
No guarantees are given as to the order in which the two callbacks are triggered, or whether they will be triggered on the same thread.
Override this method to receive callbacks when the object is enabled (at construction or via enable()) and the event is triggered.
Implements BarcodeInterface.
void timeoutEvent | ( | ) |
Callback which is invoked when barcode scanning times out.
This method will be triggered by the driver when a barcode scan on a connected Grabba device times out, 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.
Implements BarcodeInterface.