ioio.lib.util.android
Class IOIOActivity
java.lang.Object
Activity
ioio.lib.util.android.IOIOActivity
- All Implemented Interfaces:
- IOIOLooperProvider
public abstract class IOIOActivity
- extends Activity
- implements IOIOLooperProvider
A convenience class for easy creation of IOIO-based activities.
It is used by creating a concrete Activity
in your application, which
extends this class. This class then takes care of proper creation and
abortion of the IOIO connection and of a dedicated thread for IOIO
communication.
In the basic usage the client should extend this class and implement
createIOIOLooper()
, which should return an implementation of the
IOIOLooper
interface. In this implementation, the client implements
the IOIOLooper.setup(ioio.lib.api.IOIO)
method, which gets called as
soon as communication with the IOIO is established, and the
IOIOLooper.loop()
method, which gets called repetitively as long as
the IOIO is connected.
In addition, the IOIOLooper.disconnected()
method may be overridden
in order to execute logic as soon as a disconnection occurs for whichever
reason. The IOIOLooper.incompatible()
method may be overridden in
order to take action in case where a IOIO whose firmware is incompatible with
the IOIOLib version that application is built with.
In a more advanced use case, more than one IOIO is available. In this case, a
thread will be created for each IOIO, whose semantics are as defined above.
If the client needs to be able to distinguish between them, it is possible to
override createIOIOLooper(String, Object)
instead of
createIOIOLooper()
. The first argument provided will contain the
connection class name, such as ioio.lib.impl.SocketIOIOConnection for a
connection established over a TCP socket (which is used over ADB). The second
argument will contain information specific to the connection type. For
example, in the case of SocketIOIOConnection
, the second argument
will contain an Integer
representing the local port number.
Method Summary |
IOIOLooper |
createIOIOLooper(java.lang.String connectionType,
java.lang.Object extra)
Subclasses should implement this method by returning an implementation of
IOIOLooper . |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
IOIOActivity
public IOIOActivity()
createIOIOLooper
public IOIOLooper createIOIOLooper(java.lang.String connectionType,
java.lang.Object extra)
- Description copied from interface:
IOIOLooperProvider
- Subclasses should implement this method by returning an implementation of
IOIOLooper
. The caller provide enough information to uniquely
identify the connection, through the parameters. null
may be
returned if the client is not interested to create a thread for this
IOIO. This can be used in order to filter out unwanted connections, for
example if the application is only intended for wireless connection, any
wired connection attempts may be rejected, thus saving resources used for
listening for incoming wired connections.
- Specified by:
createIOIOLooper
in interface IOIOLooperProvider
- Parameters:
connectionType
- A unique name of the connection type. Typically, the
fully-qualified name of the connection class used to connect
to the IOIO.extra
- A connection-type-specific object with extra information on
the specific connection. Should provide information that
enables distinguishing between different IOIO instances using
the same connection class. For example, a Bluetooth connection
type, might have the remote IOIO's Bluetooth name as extra.
- Returns:
- An implementation of
IOIOLooper
, or null
to
skip.