ims.devicemanager
Class BluetoothConnectThread

java.lang.Object
  extended by java.lang.Thread
      extended by ims.devicemanager.BluetoothConnectThread
All Implemented Interfaces:
java.lang.Runnable

public class BluetoothConnectThread
extends java.lang.Thread

If a Bluetooth-Device is selected from the device list this class is called. It opens sockets to connect with the device and manages the connection (calls the BluetoothDataManager class if the connection stands) until shutdown.

Copyright © 2014 by Daniela Blum

This file is part of GPSChildFinder.
GPSChildFinder is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses.

Author:
Daniela Blum

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static boolean DEVICE_CONNECTED
          true if a device is connected via Bluetooth or rather a Bluetooth socket is connected to a remote device
static boolean GETTING_GPS_INPUT
          true if the phone receives GPS input from the GPS-Bluetooth-device, false otherwise
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
 void cancel(boolean triggered)
          Called when something goes wrong with the Bluetooth-connection or the user want's to disconnect the device from the phone.
static BluetoothConnectThread getInstance(android.content.Context context, android.bluetooth.BluetoothDevice device, android.app.Activity currentActivity)
           
 void run()
          Tries to connect the Bluetooth socket with the Bluetooth device when no device is connected so far.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEVICE_CONNECTED

public static boolean DEVICE_CONNECTED
true if a device is connected via Bluetooth or rather a Bluetooth socket is connected to a remote device


GETTING_GPS_INPUT

public static boolean GETTING_GPS_INPUT
true if the phone receives GPS input from the GPS-Bluetooth-device, false otherwise

Method Detail

getInstance

public static BluetoothConnectThread getInstance(android.content.Context context,
                                                 android.bluetooth.BluetoothDevice device,
                                                 android.app.Activity currentActivity)

run

public void run()
Tries to connect the Bluetooth socket with the Bluetooth device when no device is connected so far. If the connect dialog gets cancelled the process gets canceled.

If the device is connected, BluetoothDataManager.readNMEASentences() is called to handle the incomming sentences from the device.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

cancel

public void cancel(boolean triggered)
Called when something goes wrong with the Bluetooth-connection or the user want's to disconnect the device from the phone.
Cancels the connection of the socket and the Bluetooth device, calls the DeviceHandler.cleanUp() method, cleans out the values and updates the screen if necessary.

Parameters:
triggered - true if the user triggered the cancellation of the connection, false otherwise