2015-05-05 00:48:02 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.discovery;
|
|
|
|
|
|
|
|
import android.bluetooth.BluetoothDevice;
|
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.DeviceType;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
public class DeviceCandidate implements Parcelable {
|
|
|
|
private BluetoothDevice device;
|
|
|
|
private short rssi;
|
|
|
|
private DeviceType deviceType = DeviceType.UNKNOWN;
|
|
|
|
|
|
|
|
public DeviceCandidate(BluetoothDevice device, short rssi) {
|
|
|
|
this.device = device;
|
|
|
|
this.rssi = rssi;
|
|
|
|
}
|
|
|
|
|
|
|
|
private DeviceCandidate(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;
|
|
|
|
}
|
2015-05-05 01:08:30 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (this == o) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (o == null || getClass() != o.getClass()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceCandidate that = (DeviceCandidate) o;
|
|
|
|
return device.getAddress().equals(that.device.getAddress());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return device.getAddress().hashCode() ^ 37;
|
|
|
|
}
|
2015-05-05 00:48:02 +02:00
|
|
|
}
|