-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
81 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 6 additions & 9 deletions
15
common/src/main/java/com/platypii/baseline/bluetooth/BluetoothDeviceComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
package com.platypii.baseline.bluetooth; | ||
|
||
import android.bluetooth.BluetoothDevice; | ||
import androidx.annotation.NonNull; | ||
import java.util.Comparator; | ||
|
||
import static com.platypii.baseline.bluetooth.BluetoothUtil.getDeviceName; | ||
|
||
/** | ||
* Used to put GPS at top of device list | ||
*/ | ||
public class BluetoothDeviceComparator implements Comparator<BluetoothDevice> { | ||
public class BluetoothDeviceComparator implements Comparator<BluetoothItem> { | ||
@Override | ||
public int compare(@NonNull BluetoothDevice device1, @NonNull BluetoothDevice device2) { | ||
public int compare(@NonNull BluetoothItem device1, @NonNull BluetoothItem device2) { | ||
return score(device2) - score(device1); | ||
} | ||
|
||
private int score(@NonNull BluetoothDevice device) { | ||
final String name = getDeviceName(device); | ||
if (name.startsWith("Mohawk")) return 2; | ||
else if (name.contains("GPS")) return 1; | ||
private int score(@NonNull BluetoothItem device) { | ||
if (device.name.startsWith("Mohawk")) return 2; | ||
else if (device.name.startsWith("RaceBox")) return 1; | ||
else if (device.name.contains("GPS")) return 1; | ||
else return 0; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
common/src/main/java/com/platypii/baseline/bluetooth/BluetoothItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.platypii.baseline.bluetooth; | ||
|
||
import com.platypii.baseline.util.Exceptions; | ||
|
||
import android.bluetooth.BluetoothDevice; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import static com.platypii.baseline.bluetooth.BluetoothUtil.getDeviceName; | ||
|
||
public class BluetoothItem { | ||
public final String name; | ||
public final String address; | ||
public boolean ble; | ||
|
||
public BluetoothItem(@NonNull BluetoothDevice device) { | ||
name = getDeviceName(device); | ||
address = device.getAddress(); | ||
ble = false; | ||
try { | ||
ble = device.getType() != BluetoothDevice.DEVICE_TYPE_CLASSIC; | ||
} catch (SecurityException e) { | ||
Exceptions.report(e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(@Nullable Object obj) { | ||
return (obj instanceof BluetoothItem) && ((BluetoothItem) obj).address.equals(address); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return address.hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.