com.stollmann.terminalIO
Class TIOManager

java.lang.Object
  extended by com.stollmann.terminalIO.TIOManager

public class TIOManager
extends java.lang.Object

The TIOManager is the fundamental class to provide TerminalIO functionality towards the application. It exists as one instance only per application (singleton), encapsulating the TerminalIO Bluetooth Low Energy functionality and supplying its listener TIOManagerCallback with TerminalIO relevant events.


Method Summary
 TIOPeripheral findPeripheralByAddress(java.lang.String address)
          Retrieves the TIOPeripheral instance with the specified address.
 Context getApplicationContext()
          Gets the application context passed to TIOManager in the call to initialize().
 TIOPeripheral[] getPeripherals()
          Gets all TIOPeripheral instances representing the currently known TerminalIO peripherals.
static void initialize(Context applicationContext)
          Create the singleton TIOManager instance - including the tying up to the Android BluetoothAdapter - and loads the list of know peripherals.
 boolean isBluetoothEnabled()
          Gets the current Bluetooth enabled state.
 void loadPeripherals()
          Loads TIOPeripherals previously saved with savePeripherals().
 void removeAllPeripherals()
          Removes all peripherals from the TIOManager's peripheral list.
 void removePeripheral(TIOPeripheral peripheral)
          Removes the specified peripheral from the TIOManager's peripheral list.
 void savePeripherals()
          Serializes a list of known peripheral Bluetooth addresses to a persistent file in the application directory.
 void setListener(TIOManagerCallback listener)
          Sets the listener for TerminalIO scan events.
static TIOManager sharedInstance()
          Returns the singleton TIOManager instance.
 void startScan()
          Starts a Bluetooth Low Energy scan procedure.
 void stopScan()
          Stops a currently running scan procedure.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

findPeripheralByAddress

public TIOPeripheral findPeripheralByAddress(java.lang.String address)
Retrieves the TIOPeripheral instance with the specified address. Applications may use this method to retrieve an object instance in cases where the Bluetooth address string has been transmitted within a message, e.g. a broadcast or an intent.

Parameters:
address - A Bluetooth address string to retrieve a TIOPeripheral instance for; format is [00:11:22:AA:BB:CC].
Returns:
The requested TIOPeripheral instance, or null, if no matching instance could be found.

getApplicationContext

public Context getApplicationContext()
Gets the application context passed to TIOManager in the call to initialize().

Returns:
The application context passed to TIOManager in the call to initialize().

getPeripherals

public TIOPeripheral[] getPeripherals()
Gets all TIOPeripheral instances representing the currently known TerminalIO peripherals.

Returns:
An array of TIOPeripheral instances representing all currently known TerminalIO peripherals.

initialize

public static void initialize(Context applicationContext)
Create the singleton TIOManager instance - including the tying up to the Android BluetoothAdapter - and loads the list of know peripherals. It is therefore recommended to call this message at an early state of application startup, e.g. within the appliction's onCreate() override. No TIOManager operations shall be performed before this method has been called.


isBluetoothEnabled

public boolean isBluetoothEnabled()
Gets the current Bluetooth enabled state.

Returns:
true if Bluetooth is enabled on the Smart Phone, false otherwise.

loadPeripherals

public void loadPeripherals()
Loads TIOPeripherals previously saved with savePeripherals(). Populates the TIOManager's peripherals list with TIOPeripheral instances created from a serialized list of Bluetooth addresses. This method is called implicitly during initialization via initialize(). The reconstructed TIOPeripheral instances do not contain any advertisement information. If Bluetooth has been switched off, also the name information will be lost. If any advertisement information (e.g. local name, TIOPeripheralOperationMode) or name information is required, call startScan() in order to refresh the advertisement information of peripherals within radio range.


removeAllPeripherals

public void removeAllPeripherals()
Removes all peripherals from the TIOManager's peripheral list.


removePeripheral

public void removePeripheral(TIOPeripheral peripheral)
Removes the specified peripheral from the TIOManager's peripheral list.


savePeripherals

public void savePeripherals()
Serializes a list of known peripheral Bluetooth addresses to a persistent file in the application directory.


setListener

public void setListener(TIOManagerCallback listener)
Sets the listener for TerminalIO scan events. If listener extends Activity, TIOManager invokes all TIOManagerCallback methods on the UI thread.

Parameters:
listener - The listener to receive TIOManagerCallback events.

sharedInstance

public static final TIOManager sharedInstance()
Returns the singleton TIOManager instance.

Returns:
The singleton TIOManager instance.

startScan

public void startScan()
Starts a Bluetooth Low Energy scan procedure. Discovered TerminalIO peripherals will be reported via the TIOManager.Callback#tioManagerDidDiscoverPeripheral()) method. Call stopScan to stop the scan procedure and save battery power.


stopScan

public void stopScan()
Stops a currently running scan procedure.