forked from upstream-mirrors/OpenTracks
Added disconnect toast message.
This commit is contained in:
+9
-12
@@ -23,9 +23,7 @@ import android.bluetooth.BluetoothGattCharacteristic;
|
|||||||
import android.bluetooth.BluetoothGattDescriptor;
|
import android.bluetooth.BluetoothGattDescriptor;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -42,10 +40,10 @@ import de.dennisguse.opentracks.content.sensor.SensorState;
|
|||||||
public class BluetoothConnectionManager {
|
public class BluetoothConnectionManager {
|
||||||
|
|
||||||
// Message types sent to handler
|
// Message types sent to handler
|
||||||
static final int MESSAGE_DEVICE_NAME = 1;
|
static final int MESSAGE_CONNECTING = 1;
|
||||||
static final int MESSAGE_READ = 2;
|
static final int MESSAGE_CONNECTED = 2;
|
||||||
|
static final int MESSAGE_READ = 3;
|
||||||
static final String KEY_DEVICE_NAME = "device_name";
|
static final int MESSAGE_DISCONNECTED = 4;
|
||||||
|
|
||||||
private static final UUID HEART_RATE_SERVICE_UUID = new UUID(0x180D00001000L, 0x800000805f9b34fbL);
|
private static final UUID HEART_RATE_SERVICE_UUID = new UUID(0x180D00001000L, 0x800000805f9b34fbL);
|
||||||
private static final UUID HEART_RATE_MEASUREMENT_CHAR_UUID = new UUID(0x2A3700001000L, 0x800000805f9b34fbL);
|
private static final UUID HEART_RATE_MEASUREMENT_CHAR_UUID = new UUID(0x2A3700001000L, 0x800000805f9b34fbL);
|
||||||
@@ -68,18 +66,15 @@ public class BluetoothConnectionManager {
|
|||||||
case BluetoothProfile.STATE_CONNECTING:
|
case BluetoothProfile.STATE_CONNECTING:
|
||||||
Log.d(TAG, "Connecting to sensor: " + gatt.getDevice());
|
Log.d(TAG, "Connecting to sensor: " + gatt.getDevice());
|
||||||
setState(SensorState.CONNECTING);
|
setState(SensorState.CONNECTING);
|
||||||
|
|
||||||
|
handler.obtainMessage(MESSAGE_CONNECTING, gatt.getDevice().getName()).sendToTarget();
|
||||||
case BluetoothProfile.STATE_CONNECTED:
|
case BluetoothProfile.STATE_CONNECTED:
|
||||||
Log.d(TAG, "Connected to sensor: " + gatt.getDevice());
|
Log.d(TAG, "Connected to sensor: " + gatt.getDevice());
|
||||||
setState(SensorState.CONNECTED);
|
setState(SensorState.CONNECTED);
|
||||||
|
|
||||||
gatt.discoverServices();
|
gatt.discoverServices();
|
||||||
|
|
||||||
//Inform about status change
|
handler.obtainMessage(MESSAGE_CONNECTED, gatt.getDevice().getName()).sendToTarget();
|
||||||
Message message = handler.obtainMessage(MESSAGE_DEVICE_NAME);
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString(KEY_DEVICE_NAME, gatt.getDevice().getName());
|
|
||||||
message.setData(bundle);
|
|
||||||
handler.sendMessage(message);
|
|
||||||
break;
|
break;
|
||||||
case BluetoothProfile.STATE_DISCONNECTING:
|
case BluetoothProfile.STATE_DISCONNECTING:
|
||||||
Log.d(TAG, "Disconnecting from sensor: " + gatt.getDevice());
|
Log.d(TAG, "Disconnecting from sensor: " + gatt.getDevice());
|
||||||
@@ -88,6 +83,8 @@ public class BluetoothConnectionManager {
|
|||||||
case BluetoothProfile.STATE_DISCONNECTED:
|
case BluetoothProfile.STATE_DISCONNECTED:
|
||||||
Log.d(TAG, "Disconnected from sensor: " + gatt.getDevice());
|
Log.d(TAG, "Disconnected from sensor: " + gatt.getDevice());
|
||||||
setState(SensorState.DISCONNECTED);
|
setState(SensorState.DISCONNECTED);
|
||||||
|
|
||||||
|
handler.obtainMessage(MESSAGE_DISCONNECTED, gatt.getDevice().getName()).sendToTarget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-3
@@ -49,10 +49,13 @@ public class BluetoothRemoteSensorManager extends RemoteSensorManager {
|
|||||||
private final Handler messageHandler = new Handler(Looper.getMainLooper()) {
|
private final Handler messageHandler = new Handler(Looper.getMainLooper()) {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
|
String toastMessage;
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case BluetoothConnectionManager.MESSAGE_DEVICE_NAME:
|
case BluetoothConnectionManager.MESSAGE_CONNECTING:
|
||||||
String deviceName = message.getData().getString(BluetoothConnectionManager.KEY_DEVICE_NAME);
|
//Ignore for now.
|
||||||
String toastMessage = context.getString(R.string.settings_sensor_connected, deviceName);
|
break;
|
||||||
|
case BluetoothConnectionManager.MESSAGE_CONNECTED:
|
||||||
|
toastMessage = context.getString(R.string.settings_sensor_connected, message.obj);
|
||||||
Toast.makeText(context, toastMessage, Toast.LENGTH_LONG).show();
|
Toast.makeText(context, toastMessage, Toast.LENGTH_LONG).show();
|
||||||
break;
|
break;
|
||||||
case BluetoothConnectionManager.MESSAGE_READ:
|
case BluetoothConnectionManager.MESSAGE_READ:
|
||||||
@@ -63,7 +66,12 @@ public class BluetoothRemoteSensorManager extends RemoteSensorManager {
|
|||||||
sensorDataSet = (SensorDataSet) message.obj;
|
sensorDataSet = (SensorDataSet) message.obj;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case BluetoothConnectionManager.MESSAGE_DISCONNECTED:
|
||||||
|
toastMessage = context.getString(R.string.settings_sensor_disconnected, message.obj);
|
||||||
|
Toast.makeText(context, toastMessage, Toast.LENGTH_LONG).show();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
Log.e(TAG, "Got an undefined case. Please check.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1278,6 +1278,11 @@ limitations under the License.
|
|||||||
%1$s sensor name. E.g., 'Polar Bluetooth'.">
|
%1$s sensor name. E.g., 'Polar Bluetooth'.">
|
||||||
Connected to %1$s
|
Connected to %1$s
|
||||||
</string>
|
</string>
|
||||||
|
<string name="settings_sensor_disconnected" translation_description="A message when a sensor is connected.
|
||||||
|
|
||||||
|
%1$s sensor name. E.g., 'Polar Bluetooth'.">
|
||||||
|
Disconnected from %1$s
|
||||||
|
</string>
|
||||||
|
|
||||||
<!-- Settings Stats -->
|
<!-- Settings Stats -->
|
||||||
<string name="settings_stats_coordinate" translation_description="In the 'Stats settings, the option to show latitude and longitude.
|
<string name="settings_stats_coordinate" translation_description="In the 'Stats settings, the option to show latitude and longitude.
|
||||||
|
|||||||
Reference in New Issue
Block a user