Backend API Description - accessible-virtual-keyboard/backend GitHub Wiki

The backend has been designed to be as modular and reusable as possible so that it should be easy to include the backend and use its functionality in other projects.

All code in the backend make extensive use of interfaces. Default implementations of all the interfaces are provided and should work fine for most usages. If there are some special requirements, custom implementations of the interfaces can be created.

Core interfaces

The main components that makes up the backend are the Keyboard, Layout, InputInterface and Output interfaces.

InputInterface

This interface defines the way input is sent to the backend. Input driver implementations should use this interface to communicate with the backend.

Currently no input implementation is provided in the backend, but an example of a WebSocket implementation can be found in the AViKEYB android project.

OutputDevice

The OutputDevice interfaces defines the way to receive the output from the keyboard. Implementations of this interface should should be registered with the Keyboard to receive the output as the user types. Currently output is only received when the user clicks the send button in the layout, when the send button is selected the OutputDevice will receive the whole content of the Keyboard's output buffer as a String.

A simple console output implementation is provided in the backend.

Keyboard

The Keyboard is responsible for keeping track of the output as user types on the keyboard. The keyboard provides methods to manipulate the current buffered output before it is sent to the output devices. It also keeps track of all output devices. An output devices must register itself with the keyboard using the addOutputDevice() method. All registered output devices will receive the current output buffer when the sendCurrentBuffer() method is called.

The backend provides the CoreKeyboard implementation that should be good enough for most use cases.

Layout

The Layout is responsible for implementing the main typing logic of the keyboard. Currently the Layout also implements the InputInterface and thus will directly receive the input signals coming from the input driver implementations.

An abstract BaseLayout implementation is provides that implements the boilerplate code needed for the layouts. Subclasses only need to implement the onStep() method that is called when a input signal is received.

The layout implementation is responsible for keeping track of the the input signals received and translating these into characters. The layout is responsible for adding the typed output to the Keyboard and letting the user manipulate and send the keyboard's current output buffer.

Several implementations are provided in the backend. A simple example of a layout implementations can be found in the SimpleExampleLayout implementation.

The Layout also defines a LayoutListener interface that can be used to implement a visualisation of the layout. LayoutListener's can register with the Layout implementation and will be notified whenever the internal state of the layout changes. It can then update the visual representation of the layout accordingly. The BaseLayout implements the code necessary for the listener interfaces. The only requirement of the subclasses is to call the notifyListeners() method whenever the internal state of the layout changes.

Extra interfaces

Some interfaces are provide

Dictionary

The Dictionary defines a way to finding suggestions for words matching a given prefix. This can be used to implement word suggestions as the user types on the keyboard.

The DictionaryHandler implementation in the backend is a simple implementation that keeps a list of words in memory and searches for matches using binary search. This should work ok in most cases, if not custom implementations can be created, e.g an implementation that keeps the words in a database).