Grabba Driver for Android
Unified driver for Grabba devices on the Android operating system
KeyboardListener Class Reference

Description

Base class for receiving events suitable for keyboard wedge implementations.

Objects which inherit from this class can receive callbacks for generating 'virtual keystrokes' in response to receipt of barcode, magstripe, MRZ or proxcard data. This is handled via a single event, textEvent, which provides a string of text to be transformed into virtual keystrokes.

Behaviour of this listener is controlled by KeyboardAPI; refer to the functions there (particularly KeyboardAPI.selectTechnologies()) for details on how to configure which events are generated and what data is passed to them.

Each event may invoke callbacks in two ways:

  • Subclassing - the relevant event methods (e.g. textEvent) are called directly
    • This approach is recommended wherever feasible, due to its simplicity.
    • To use it, create an object of a suitable subclass, which overrides the desired event method(s).
  • Delegation - event methods trigger method calls for a delegate object
    • This approach is only recommended when the callback handler must inherit from a different base class
    • To use it, create an object of this class, create an object of a class which implements KeyboardInterface, then call setDelegate() to provide the necessary linkage.
Note
Delegation will be disabled for an event if that event's method is subclassed, unless the subclass calls the superclass' equivalent method from within its override thereof.

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:

  • If setDelegate() has not been called, then take no action
  • If the last call to setDelegate() accepted a null reference, then take no action
  • If the last call to setDelegate() accepted a non-null object reference, then delegate to that object

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.

See also
KeyboardAPI for related API functions
Inheritance diagram for KeyboardListener:
Listener< KeyboardInterface > KeyboardInterface

Public Member Functions

 KeyboardListener ()
 Default constructor - builds a listener object then enables receipt of events from the driver.
 
 KeyboardListener (boolean startEnabled)
 Constructor - builds a listener object then optionally enables receipt of events from the driver. 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...
 
void textEvent (String text)
 Callback which is invoked when additional keyboard output is to be generated. More...
 

Constructor & Destructor Documentation

◆ KeyboardListener()

KeyboardListener ( boolean  startEnabled)

Constructor - builds a listener object then optionally enables receipt of events from the driver.

Parameters
startEnabledIf set, the listener object is enabled immediately (equivalent of default constructor), otherwise it is disabled until the first call to enable()

Member Function Documentation

◆ disable()

final void disable ( )
inherited

Disable receipt of events from the driver by this object.

This has no effect if the object was already disabled.

◆ enable()

final void enable ( )
inherited

Enable receipt of events from the driver by this object.

This has no effect if the object was already enabled.

◆ setDelegate()

final void setDelegate ( Delegate  newDelegate)
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.

Parameters
newDelegateIf null, disables delegation; if non-null, enables delegation and sets the delegate to the supplied object.

◆ textEvent()

void textEvent ( String  text)

Callback which is invoked when additional keyboard output is to be generated.

This is triggered when suitable data (e.g. a barcode scan) has been received from a connected Grabba device and the relevant technology has been enabled for keyboard output via KeyboardAPI.selectTechnologies(). Subclasses are expected to override this method with a 'virtual keyboard' implementation, e.g. via InputConnection.sendKeyEvent on Android.

Override this method to receive callbacks when the object is enabled (at construction or via enable()) and the event is triggered.

Note
Overrides of this method are required to be thread-safe; no guarantees are made about which thread(s) they will be called from.
Parameters
textUTF-8 string to convert to virtual keystrokes; may include line-ending delimiters

Implements KeyboardInterface.