mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-02-03 13:37:32 +01:00
Merge branch 'master' of https://github.com/Freeyourgadget/Gadgetbridge
This commit is contained in:
commit
b391128a56
@ -130,7 +130,7 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(btDeviceAddress);
|
BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(btDeviceAddress);
|
||||||
if (btDevice != null) {
|
if (btDevice != null) {
|
||||||
if (btDevice.getName() == null || btDevice.getName().equals("MI")) { //FIXME: workaround for Miband not being paired
|
if (btDevice.getName() == null || btDevice.getName().equals("MI")) { //FIXME: workaround for Miband not being paired
|
||||||
mGBDevice = new GBDevice(btDeviceAddress, btDevice.getName(), GBDevice.Type.MIBAND);
|
mGBDevice = new GBDevice(btDeviceAddress, "MI", GBDevice.Type.MIBAND);
|
||||||
mDeviceSupport = new MiBandSupport();
|
mDeviceSupport = new MiBandSupport();
|
||||||
} else if (btDevice.getName().indexOf("Pebble") == 0) {
|
} else if (btDevice.getName().indexOf("Pebble") == 0) {
|
||||||
mGBDevice = new GBDevice(btDeviceAddress, btDevice.getName(), GBDevice.Type.PEBBLE);
|
mGBDevice = new GBDevice(btDeviceAddress, btDevice.getName(), GBDevice.Type.PEBBLE);
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge;
|
package nodomain.freeyourgadget.gadgetbridge;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapter;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
@ -19,12 +24,6 @@ import android.widget.ListView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapter;
|
|
||||||
|
|
||||||
public class ControlCenter extends Activity {
|
public class ControlCenter extends Activity {
|
||||||
|
|
||||||
|
|
||||||
@ -50,11 +49,9 @@ public class ControlCenter extends Activity {
|
|||||||
} else if (action.equals(GBDevice.ACTION_DEVICE_CHANGED)) {
|
} else if (action.equals(GBDevice.ACTION_DEVICE_CHANGED)) {
|
||||||
GBDevice dev = intent.getParcelableExtra("device");
|
GBDevice dev = intent.getParcelableExtra("device");
|
||||||
if (dev.getAddress() != null) {
|
if (dev.getAddress() != null) {
|
||||||
for (int i = 0; i < deviceList.size(); i++) {
|
int index = deviceList.indexOf(dev); // search by address
|
||||||
if (dev.equals(deviceList.get(i))) {
|
if (index >= 0) {
|
||||||
deviceList.set(i, dev);
|
deviceList.set(index, dev);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
refreshPairedDevices();
|
refreshPairedDevices();
|
||||||
@ -151,13 +148,14 @@ public class ControlCenter extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refreshPairedDevices() {
|
private void refreshPairedDevices() {
|
||||||
GBDevice connectedDevice = null;
|
boolean connected = false;
|
||||||
|
List<GBDevice> availableDevices = new ArrayList<>();
|
||||||
for (GBDevice device : deviceList) {
|
for (GBDevice device : deviceList) {
|
||||||
if (device.isConnected() || device.isConnecting()) {
|
if (device.isConnected() || device.isConnecting()) {
|
||||||
connectedDevice = device;
|
connected = true;
|
||||||
|
availableDevices.add(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deviceList.clear();
|
|
||||||
|
|
||||||
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
|
||||||
@ -167,29 +165,37 @@ public class ControlCenter extends Activity {
|
|||||||
Toast.makeText(this, "Bluetooth is disabled.", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Bluetooth is disabled.", Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
|
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
|
||||||
for (BluetoothDevice device : pairedDevices) {
|
for (BluetoothDevice pairedDevice : pairedDevices) {
|
||||||
GBDevice.Type deviceType;
|
GBDevice.Type deviceType;
|
||||||
if (device.getName().indexOf("Pebble") == 0) {
|
if (pairedDevice.getName().indexOf("Pebble") == 0) {
|
||||||
deviceType = GBDevice.Type.PEBBLE;
|
deviceType = GBDevice.Type.PEBBLE;
|
||||||
} else if (device.getName().equals("MI")) {
|
} else if (pairedDevice.getName().equals("MI")) {
|
||||||
deviceType = GBDevice.Type.MIBAND;
|
deviceType = GBDevice.Type.MIBAND;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (connectedDevice != null && (device.getAddress().equals(connectedDevice.getAddress()))) {
|
GBDevice device = new GBDevice(pairedDevice.getAddress(), pairedDevice.getName(), deviceType);
|
||||||
deviceList.add(connectedDevice);
|
if (!availableDevices.contains(device)) {
|
||||||
} else {
|
availableDevices.add(device);
|
||||||
deviceList.add(new GBDevice(device.getAddress(), device.getName(), deviceType));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
String miAddr = sharedPrefs.getString("development_miaddr", null);
|
String miAddr = sharedPrefs.getString("development_miaddr", null);
|
||||||
if (miAddr != null && !miAddr.equals("") && (connectedDevice == null || !miAddr.equals(connectedDevice.getAddress()))) {
|
if (miAddr != null && miAddr.length() > 0) {
|
||||||
deviceList.add(new GBDevice(miAddr, "MI", GBDevice.Type.MIBAND));
|
GBDevice miDevice = new GBDevice(miAddr, "MI", GBDevice.Type.MIBAND);
|
||||||
|
if (!availableDevices.contains(miDevice)) {
|
||||||
|
availableDevices.add(miDevice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deviceList.retainAll(availableDevices);
|
||||||
|
for (GBDevice dev : availableDevices) {
|
||||||
|
if (!deviceList.contains(dev)) {
|
||||||
|
deviceList.add(dev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connectedDevice != null) {
|
if (connected) {
|
||||||
hintTextView.setText("tap connected device for App Mananger");
|
hintTextView.setText("tap connected device for App Mananger");
|
||||||
} else if (!deviceList.isEmpty()) {
|
} else if (!deviceList.isEmpty()) {
|
||||||
hintTextView.setText("tap a device to connect");
|
hintTextView.setText("tap a device to connect");
|
||||||
|
@ -10,7 +10,7 @@ import android.util.Log;
|
|||||||
public class GBDevice implements Parcelable {
|
public class GBDevice implements Parcelable {
|
||||||
public static final String ACTION_DEVICE_CHANGED
|
public static final String ACTION_DEVICE_CHANGED
|
||||||
= "nodomain.freeyourgadget.gadgetbride.gbdevice.action.device_changed";
|
= "nodomain.freeyourgadget.gadgetbride.gbdevice.action.device_changed";
|
||||||
public static final Creator CREATOR = new Creator<GBDevice>() {
|
public static final Creator<GBDevice> CREATOR = new Creator<GBDevice>() {
|
||||||
@Override
|
@Override
|
||||||
public GBDevice createFromParcel(Parcel source) {
|
public GBDevice createFromParcel(Parcel source) {
|
||||||
return new GBDevice(source);
|
return new GBDevice(source);
|
||||||
@ -35,6 +35,7 @@ public class GBDevice implements Parcelable {
|
|||||||
mAddress = address;
|
mAddress = address;
|
||||||
mName = name;
|
mName = name;
|
||||||
mType = type;
|
mType = type;
|
||||||
|
validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private GBDevice(Parcel in) {
|
private GBDevice(Parcel in) {
|
||||||
@ -46,6 +47,25 @@ public class GBDevice implements Parcelable {
|
|||||||
mState = State.values()[in.readInt()];
|
mState = State.values()[in.readInt()];
|
||||||
mBatteryLevel = (short) in.readInt();
|
mBatteryLevel = (short) in.readInt();
|
||||||
mBatteryState = in.readString();
|
mBatteryState = in.readString();
|
||||||
|
validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(mName);
|
||||||
|
dest.writeString(mAddress);
|
||||||
|
dest.writeInt(mType.ordinal());
|
||||||
|
dest.writeString(mFirmwareVersion);
|
||||||
|
dest.writeString(mHardwareVersion);
|
||||||
|
dest.writeInt(mState.ordinal());
|
||||||
|
dest.writeInt(mBatteryLevel);
|
||||||
|
dest.writeString(mBatteryState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validate() {
|
||||||
|
if (getAddress() == null) {
|
||||||
|
throw new IllegalArgumentException("address must not be null");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -149,15 +169,8 @@ public class GBDevice implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public int hashCode() {
|
||||||
dest.writeString(mName);
|
return mAddress.hashCode() ^ 37;
|
||||||
dest.writeString(mAddress);
|
|
||||||
dest.writeInt(mType.ordinal());
|
|
||||||
dest.writeString(mFirmwareVersion);
|
|
||||||
dest.writeString(mHardwareVersion);
|
|
||||||
dest.writeInt(mState.ordinal());
|
|
||||||
dest.writeInt(mBatteryLevel);
|
|
||||||
dest.writeString(mBatteryState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
00001800-0000-1000-8000-00805f9b34fb:Generic Access Service
|
||||||
|
- 00002a00-0000-1000-8000-00805f9b34fb:Device Name
|
||||||
|
- 00002a01-0000-1000-8000-00805f9b34fb:Appearance
|
||||||
|
- 00002a02-0000-1000-8000-00805f9b34fb:Peripheral Privacy Flag
|
||||||
|
- 00002a04-0000-1000-8000-00805f9b34fb:Peripheral Preferred Connection Parameters
|
||||||
|
|
||||||
|
00001801-0000-1000-8000-00805f9b34fb:Generic Attribute Service
|
||||||
|
- 00002a05-0000-1000-8000-00805f9b34fb:Service Changed
|
||||||
|
|
||||||
|
0000fee0-0000-1000-8000-00805f9b34fb:MiBand Service
|
||||||
|
- 0000ff01-0000-1000-8000-00805f9b34fb:Device Info
|
||||||
|
- 0000ff02-0000-1000-8000-00805f9b34fb:Device Name
|
||||||
|
- 0000ff03-0000-1000-8000-00805f9b34fb:Notification
|
||||||
|
- 0000ff04-0000-1000-8000-00805f9b34fb:User Info
|
||||||
|
- 0000ff05-0000-1000-8000-00805f9b34fb:Control Point
|
||||||
|
- 0000ff06-0000-1000-8000-00805f9b34fb:Realtime Steps
|
||||||
|
- 0000ff07-0000-1000-8000-00805f9b34fb:Activity Data
|
||||||
|
- 0000ff08-0000-1000-8000-00805f9b34fb:Firmware Data
|
||||||
|
- 0000ff09-0000-1000-8000-00805f9b34fb:LE Params
|
||||||
|
- 0000ff0a-0000-1000-8000-00805f9b34fb:Date/Time
|
||||||
|
- 0000ff0b-0000-1000-8000-00805f9b34fb:Statistics
|
||||||
|
- 0000ff0c-0000-1000-8000-00805f9b34fb:Battery
|
||||||
|
- 0000ff0d-0000-1000-8000-00805f9b34fb:Test
|
||||||
|
- 0000ff0e-0000-1000-8000-00805f9b34fb:Sensor Data
|
||||||
|
|
||||||
|
0000fee1-0000-1000-8000-00805f9b34fb:Unknown service
|
||||||
|
- 0000fedd-0000-1000-8000-00805f9b34fb:Unknown characteristic
|
||||||
|
- 0000fede-0000-1000-8000-00805f9b34fb:Unknown characteristic
|
||||||
|
- 0000fedf-0000-1000-8000-00805f9b34fb:Unknown characteristic
|
||||||
|
|
||||||
|
0000fee7-0000-1000-8000-00805f9b34fb:Unknown service
|
||||||
|
- 0000fec7-0000-1000-8000-00805f9b34fb:Unknown characteristic
|
||||||
|
- 0000fec8-0000-1000-8000-00805f9b34fb:Unknown characteristic
|
||||||
|
- 0000fec9-0000-1000-8000-00805f9b34fb:Unknown characteristic
|
Loading…
x
Reference in New Issue
Block a user