1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-09 15:11:34 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceCandidate.java

89 lines
2.4 KiB
Java
Raw Normal View History

package nodomain.freeyourgadget.gadgetbridge.impl;
import android.bluetooth.BluetoothDevice;
import android.os.Parcel;
import android.os.Parcelable;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
/**
2015-10-26 23:32:03 +01:00
* A device candidate is a Bluetooth device that is not yet managed by
* Gadgetbridge. Only if a DeviceCoordinator steps up and confirms to
* support this candidate, will the candidate be promoted to a GBDevice.
*/
public class GBDeviceCandidate implements Parcelable {
private BluetoothDevice device;
private short rssi;
private DeviceType deviceType = DeviceType.UNKNOWN;
public GBDeviceCandidate(BluetoothDevice device, short rssi) {
this.device = device;
this.rssi = rssi;
}
private GBDeviceCandidate(Parcel in) {
device = in.readParcelable(getClass().getClassLoader());
rssi = (short) in.readInt();
deviceType = DeviceType.valueOf(in.readString());
if (device == null || deviceType == null) {
throw new IllegalStateException("Unable to read state from Parcel");
}
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(device, 0);
dest.writeInt(rssi);
dest.writeString(deviceType.name());
}
public DeviceType getDeviceType() {
return deviceType;
}
public String getMacAddress() {
return device != null ? device.getAddress() : GBApplication.getContext().getString(R.string._unknown_);
}
public String getName() {
String name = null;
if (device != null) {
name = device.getName();
}
if (name == null || name.length() == 0) {
name = GBApplication.getContext().getString(R.string._unknown_);
}
return name;
}
public short getRssi() {
return rssi;
}
@Override
public int describeContents() {
return 0;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
GBDeviceCandidate that = (GBDeviceCandidate) o;
return device.getAddress().equals(that.device.getAddress());
}
@Override
public int hashCode() {
return device.getAddress().hashCode() ^ 37;
}
}