Display HR firmware version
Hide fw,hw,hr versions by default and show them on demand with an info button.
This commit is contained in:
parent
4aaf3dd162
commit
e26e6d7b24
|
@ -8,14 +8,19 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ListView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.text.Collator;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.ItemWithDetails;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter for displaying GBDevice instances.
|
* Adapter for displaying GBDevice instances.
|
||||||
|
@ -32,7 +37,7 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View view, ViewGroup parent) {
|
public View getView(int position, View view, ViewGroup parent) {
|
||||||
GBDevice device = getItem(position);
|
final GBDevice device = getItem(position);
|
||||||
|
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
LayoutInflater inflater = (LayoutInflater) context
|
LayoutInflater inflater = (LayoutInflater) context
|
||||||
|
@ -42,37 +47,59 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
|
||||||
}
|
}
|
||||||
TextView deviceStatusLabel = (TextView) view.findViewById(R.id.device_status);
|
TextView deviceStatusLabel = (TextView) view.findViewById(R.id.device_status);
|
||||||
TextView deviceNameLabel = (TextView) view.findViewById(R.id.device_name);
|
TextView deviceNameLabel = (TextView) view.findViewById(R.id.device_name);
|
||||||
TextView deviceInfo1Label = (TextView) view.findViewById(R.id.device_info1);
|
final ListView deviceInfoList = (ListView) view.findViewById(R.id.device_item_infos);
|
||||||
TextView deviceInfo2Label = (TextView) view.findViewById(R.id.device_info2);
|
ItemWithDetailsAdapter infoAdapter = new ItemWithDetailsAdapter(context, device.getDeviceInfos());
|
||||||
|
infoAdapter.setHorizontalAlignment(true);
|
||||||
|
deviceInfoList.setAdapter(infoAdapter);
|
||||||
|
TextView batteryLabel = (TextView) view.findViewById(R.id.battery_label);
|
||||||
TextView batteryStatusLabel = (TextView) view.findViewById(R.id.battery_status);
|
TextView batteryStatusLabel = (TextView) view.findViewById(R.id.battery_status);
|
||||||
ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image);
|
final ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image);
|
||||||
|
ImageView deviceInfoView = (ImageView) view.findViewById(R.id.device_info_image);
|
||||||
ProgressBar busyIndicator = (ProgressBar) view.findViewById(R.id.device_busy_indicator);
|
ProgressBar busyIndicator = (ProgressBar) view.findViewById(R.id.device_busy_indicator);
|
||||||
|
|
||||||
deviceNameLabel.setText(getUniqueDeviceName(device));
|
deviceNameLabel.setText(getUniqueDeviceName(device));
|
||||||
deviceInfo1Label.setText(device.getHWInfoString());
|
|
||||||
deviceInfo2Label.setText(device.getInfoString());
|
|
||||||
|
|
||||||
if (device.isBusy()) {
|
if (device.isBusy()) {
|
||||||
deviceStatusLabel.setText(device.getBusyTask());
|
deviceStatusLabel.setText(device.getBusyTask());
|
||||||
busyIndicator.setVisibility(View.VISIBLE);
|
busyIndicator.setVisibility(View.VISIBLE);
|
||||||
|
batteryLabel.setVisibility(View.GONE);
|
||||||
batteryStatusLabel.setVisibility(View.GONE);
|
batteryStatusLabel.setVisibility(View.GONE);
|
||||||
deviceInfo1Label.setVisibility(View.GONE);
|
|
||||||
deviceInfo2Label.setVisibility(View.GONE);
|
|
||||||
} else {
|
} else {
|
||||||
deviceStatusLabel.setText(device.getStateString());
|
deviceStatusLabel.setText(device.getStateString());
|
||||||
busyIndicator.setVisibility(View.GONE);
|
busyIndicator.setVisibility(View.GONE);
|
||||||
|
batteryLabel.setVisibility(View.VISIBLE);
|
||||||
batteryStatusLabel.setVisibility(View.VISIBLE);
|
batteryStatusLabel.setVisibility(View.VISIBLE);
|
||||||
deviceInfo1Label.setVisibility(View.VISIBLE);
|
|
||||||
deviceInfo2Label.setVisibility(View.VISIBLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean showInfoIcon = device.hasDeviceInfos() && !device.isBusy();
|
||||||
|
deviceInfoView.setVisibility(showInfoIcon ? View.VISIBLE : View.GONE);
|
||||||
|
deviceInfoView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (deviceInfoList.getVisibility() == View.VISIBLE) {
|
||||||
|
deviceInfoList.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
ArrayAdapter adapter = (ArrayAdapter) deviceInfoList.getAdapter();
|
||||||
|
adapter.clear();
|
||||||
|
List<ItemWithDetails> infos = device.getDeviceInfos();
|
||||||
|
Collections.sort(infos);
|
||||||
|
adapter.addAll(infos);
|
||||||
|
justifyListViewHeightBasedOnChildren(deviceInfoList);
|
||||||
|
deviceInfoList.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
short batteryLevel = device.getBatteryLevel();
|
short batteryLevel = device.getBatteryLevel();
|
||||||
if (batteryLevel != GBDevice.BATTERY_UNKNOWN) {
|
if (batteryLevel != GBDevice.BATTERY_UNKNOWN) {
|
||||||
batteryStatusLabel.setText("BAT: " + device.getBatteryLevel() + "%");
|
batteryLabel.setText("BAT:");
|
||||||
|
batteryStatusLabel.setText(device.getBatteryLevel() + "%");
|
||||||
BatteryState batteryState = device.getBatteryState();
|
BatteryState batteryState = device.getBatteryState();
|
||||||
if (BatteryState.BATTERY_LOW.equals(batteryState)) {
|
if (BatteryState.BATTERY_LOW.equals(batteryState)) {
|
||||||
|
batteryLabel.setTextColor(Color.RED);
|
||||||
batteryStatusLabel.setTextColor(Color.RED);
|
batteryStatusLabel.setTextColor(Color.RED);
|
||||||
} else {
|
} else {
|
||||||
|
batteryLabel.setTextColor(ContextCompat.getColor(getContext(), R.color.secondarytext));
|
||||||
batteryStatusLabel.setTextColor(ContextCompat.getColor(getContext(), R.color.secondarytext));
|
batteryStatusLabel.setTextColor(ContextCompat.getColor(getContext(), R.color.secondarytext));
|
||||||
|
|
||||||
if (BatteryState.BATTERY_CHARGING.equals(batteryState) ||
|
if (BatteryState.BATTERY_CHARGING.equals(batteryState) ||
|
||||||
|
@ -81,6 +108,7 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
batteryLabel.setText("");
|
||||||
batteryStatusLabel.setText("");
|
batteryStatusLabel.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,11 +126,35 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void justifyListViewHeightBasedOnChildren (ListView listView) {
|
||||||
|
ArrayAdapter adapter = (ArrayAdapter) listView.getAdapter();
|
||||||
|
|
||||||
|
if (adapter == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ViewGroup vg = listView;
|
||||||
|
int totalHeight = 0;
|
||||||
|
for (int i = 0; i < adapter.getCount(); i++) {
|
||||||
|
View listItem = adapter.getView(i, null, vg);
|
||||||
|
listItem.measure(0, 0);
|
||||||
|
totalHeight += listItem.getMeasuredHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewGroup.LayoutParams par = listView.getLayoutParams();
|
||||||
|
par.height = totalHeight + (listView.getDividerHeight() * (adapter.getCount() - 1));
|
||||||
|
listView.setLayoutParams(par);
|
||||||
|
listView.requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
private String getUniqueDeviceName(GBDevice device) {
|
private String getUniqueDeviceName(GBDevice device) {
|
||||||
String deviceName = device.getName();
|
String deviceName = device.getName();
|
||||||
if (!isUniqueDeviceName(device, deviceName)) {
|
if (!isUniqueDeviceName(device, deviceName)) {
|
||||||
deviceName = deviceName + " " + device.getHardwareVersion();
|
if (device.getHardwareVersion() != null) {
|
||||||
if (!isUniqueDeviceName(device, deviceName)) {
|
deviceName = deviceName + " " + device.getHardwareVersion();
|
||||||
|
if (!isUniqueDeviceName(device, deviceName)) {
|
||||||
|
deviceName = deviceName + " " + device.getShortAddress();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
deviceName = deviceName + " " + device.getShortAddress();
|
deviceName = deviceName + " " + device.getShortAddress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ItemWithDetails;
|
||||||
public class ItemWithDetailsAdapter extends ArrayAdapter<ItemWithDetails> {
|
public class ItemWithDetailsAdapter extends ArrayAdapter<ItemWithDetails> {
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
private boolean horizontalAlignment;
|
||||||
|
|
||||||
public ItemWithDetailsAdapter(Context context, List<ItemWithDetails> items) {
|
public ItemWithDetailsAdapter(Context context, List<ItemWithDetails> items) {
|
||||||
super(context, 0, items);
|
super(context, 0, items);
|
||||||
|
@ -26,6 +27,9 @@ public class ItemWithDetailsAdapter extends ArrayAdapter<ItemWithDetails> {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHorizontalAlignment(boolean horizontalAlignment) {
|
||||||
|
this.horizontalAlignment = horizontalAlignment;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View view, ViewGroup parent) {
|
public View getView(int position, View view, ViewGroup parent) {
|
||||||
ItemWithDetails item = getItem(position);
|
ItemWithDetails item = getItem(position);
|
||||||
|
@ -34,7 +38,11 @@ public class ItemWithDetailsAdapter extends ArrayAdapter<ItemWithDetails> {
|
||||||
LayoutInflater inflater = (LayoutInflater) context
|
LayoutInflater inflater = (LayoutInflater) context
|
||||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
|
||||||
view = inflater.inflate(R.layout.item_with_details, parent, false);
|
if (horizontalAlignment) {
|
||||||
|
view = inflater.inflate(R.layout.item_with_details_horizontal, parent, false);
|
||||||
|
} else {
|
||||||
|
view = inflater.inflate(R.layout.item_with_details, parent, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ImageView iconView = (ImageView) view.findViewById(R.id.item_image);
|
ImageView iconView = (ImageView) view.findViewById(R.id.item_image);
|
||||||
TextView nameView = (TextView) view.findViewById(R.id.item_name);
|
TextView nameView = (TextView) view.findViewById(R.id.item_name);
|
||||||
|
|
|
@ -10,10 +10,15 @@ import android.support.v4.content.LocalBroadcastManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.ItemWithDetails;
|
||||||
|
|
||||||
public class GBDevice implements Parcelable {
|
public class GBDevice implements Parcelable {
|
||||||
public static final String ACTION_DEVICE_CHANGED
|
public static final String ACTION_DEVICE_CHANGED
|
||||||
|
@ -34,6 +39,8 @@ public class GBDevice implements Parcelable {
|
||||||
public static final short BATTERY_UNKNOWN = -1;
|
public static final short BATTERY_UNKNOWN = -1;
|
||||||
private static final short BATTERY_THRESHOLD_PERCENT = 10;
|
private static final short BATTERY_THRESHOLD_PERCENT = 10;
|
||||||
public static final String EXTRA_DEVICE = "device";
|
public static final String EXTRA_DEVICE = "device";
|
||||||
|
private static final String DEVINFO_HW_VER = "HW: ";
|
||||||
|
private static final String DEVINFO_FW_VER = "FW: ";
|
||||||
private final String mName;
|
private final String mName;
|
||||||
private final String mAddress;
|
private final String mAddress;
|
||||||
private final DeviceType mDeviceType;
|
private final DeviceType mDeviceType;
|
||||||
|
@ -45,6 +52,8 @@ public class GBDevice implements Parcelable {
|
||||||
private BatteryState mBatteryState;
|
private BatteryState mBatteryState;
|
||||||
private short mRssi = RSSI_UNKNOWN;
|
private short mRssi = RSSI_UNKNOWN;
|
||||||
private String mBusyTask;
|
private String mBusyTask;
|
||||||
|
private String infoString;
|
||||||
|
private List<ItemWithDetails> mDeviceInfos;
|
||||||
|
|
||||||
public GBDevice(String address, String name, DeviceType deviceType) {
|
public GBDevice(String address, String name, DeviceType deviceType) {
|
||||||
mAddress = address;
|
mAddress = address;
|
||||||
|
@ -65,6 +74,7 @@ public class GBDevice implements Parcelable {
|
||||||
mBatteryState = (BatteryState) in.readSerializable();
|
mBatteryState = (BatteryState) in.readSerializable();
|
||||||
mRssi = (short) in.readInt();
|
mRssi = (short) in.readInt();
|
||||||
mBusyTask = in.readString();
|
mBusyTask = in.readString();
|
||||||
|
mDeviceInfos = in.readArrayList(getClass().getClassLoader());
|
||||||
|
|
||||||
validate();
|
validate();
|
||||||
}
|
}
|
||||||
|
@ -82,6 +92,7 @@ public class GBDevice implements Parcelable {
|
||||||
dest.writeSerializable(mBatteryState);
|
dest.writeSerializable(mBatteryState);
|
||||||
dest.writeInt(mRssi);
|
dest.writeInt(mRssi);
|
||||||
dest.writeString(mBusyTask);
|
dest.writeString(mBusyTask);
|
||||||
|
dest.writeList(mDeviceInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validate() {
|
private void validate() {
|
||||||
|
@ -213,18 +224,6 @@ public class GBDevice implements Parcelable {
|
||||||
return GBApplication.getContext().getString(R.string.unknown_state);
|
return GBApplication.getContext().getString(R.string.unknown_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getInfoString() {
|
|
||||||
if (mFirmwareVersion != null) {
|
|
||||||
if (mHardwareVersion != null) {
|
|
||||||
return GBApplication.getContext().getString(R.string.connectionstate_hw_fw, mHardwareVersion, mFirmwareVersion);
|
|
||||||
}
|
|
||||||
return GBApplication.getContext().getString(R.string.connectionstate_fw, mFirmwareVersion);
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeviceType getType() {
|
public DeviceType getType() {
|
||||||
return mDeviceType;
|
return mDeviceType;
|
||||||
}
|
}
|
||||||
|
@ -330,6 +329,48 @@ public class GBDevice implements Parcelable {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasDeviceInfos() {
|
||||||
|
return getDeviceInfos().size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ItemWithDetails> getDeviceInfos() {
|
||||||
|
List<ItemWithDetails> result = new ArrayList<>();
|
||||||
|
if (mDeviceInfos != null) {
|
||||||
|
result.addAll(mDeviceInfos);
|
||||||
|
}
|
||||||
|
if (mHardwareVersion != null) {
|
||||||
|
result.add(new GenericItem(DEVINFO_HW_VER, mHardwareVersion));
|
||||||
|
}
|
||||||
|
if (mFirmwareVersion != null) {
|
||||||
|
result.add(new GenericItem(DEVINFO_FW_VER, mFirmwareVersion));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceInfos(List<ItemWithDetails> deviceInfos) {
|
||||||
|
this.mDeviceInfos = deviceInfos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDeviceInfo(ItemWithDetails info) {
|
||||||
|
if (mDeviceInfos == null) {
|
||||||
|
mDeviceInfos = new ArrayList<>();
|
||||||
|
} else {
|
||||||
|
int index = mDeviceInfos.indexOf(info);
|
||||||
|
if (index >= 0) {
|
||||||
|
mDeviceInfos.set(index, info); // replace item with new one
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mDeviceInfos.add(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeDeviceInfo(ItemWithDetails info) {
|
||||||
|
if (mDeviceInfos == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return mDeviceInfos.remove(info);
|
||||||
|
}
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
// Note: the order is important!
|
// Note: the order is important!
|
||||||
NOT_CONNECTED,
|
NOT_CONNECTED,
|
||||||
|
|
|
@ -1,10 +1,31 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import java.text.Collator;
|
||||||
|
|
||||||
public class GenericItem implements ItemWithDetails {
|
public class GenericItem implements ItemWithDetails {
|
||||||
private String name;
|
private String name;
|
||||||
private String details;
|
private String details;
|
||||||
private int icon;
|
private int icon;
|
||||||
|
|
||||||
|
public static final Parcelable.Creator CREATOR = new Parcelable.Creator<GenericItem>() {
|
||||||
|
@Override
|
||||||
|
public GenericItem createFromParcel(Parcel source) {
|
||||||
|
GenericItem item = new GenericItem();
|
||||||
|
item.setName(source.readString());
|
||||||
|
item.setDetails(source.readString());
|
||||||
|
item.setIcon(source.readInt());
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GenericItem[] newArray(int size) {
|
||||||
|
return new GenericItem[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public GenericItem(String name, String details) {
|
public GenericItem(String name, String details) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.details = details;
|
this.details = details;
|
||||||
|
@ -17,6 +38,13 @@ public class GenericItem implements ItemWithDetails {
|
||||||
public GenericItem() {
|
public GenericItem() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(getName());
|
||||||
|
dest.writeString(getDetails());
|
||||||
|
dest.writeInt(getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
@ -43,4 +71,38 @@ public class GenericItem implements ItemWithDetails {
|
||||||
public int getIcon() {
|
public int getIcon() {
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
GenericItem that = (GenericItem) o;
|
||||||
|
|
||||||
|
return !(getName() != null ? !getName().equals(that.getName()) : that.getName() != null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return getName() != null ? getName().hashCode() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(ItemWithDetails another) {
|
||||||
|
if (getName() == another.getName()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (getName() == null) {
|
||||||
|
return +1;
|
||||||
|
} else if (another.getName() == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return Collator.getInstance().compare(getName(), another.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||||
|
|
||||||
public interface ItemWithDetails {
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
public interface ItemWithDetails extends Parcelable, Comparable<ItemWithDetails> {
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
String getDetails();
|
String getDetails();
|
||||||
|
|
||||||
int getIcon();
|
int getIcon();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Equality is based on #getName() only.
|
||||||
|
* @param other
|
||||||
|
*/
|
||||||
|
boolean equals(Object other);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,14 +67,6 @@ public class DeviceInfo extends AbstractInfo {
|
||||||
return getInt(data, from, 4);
|
return getInt(data, from, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHumanFirmwareVersion() {
|
|
||||||
return MiBandFWHelper.formatFirmwareVersion(fwVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHumanFirmware2Version() {
|
|
||||||
return MiBandFWHelper.formatFirmwareVersion(fw2Version);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getFirmwareVersion() {
|
public int getFirmwareVersion() {
|
||||||
return fwVersion;
|
return fwVersion;
|
||||||
}
|
}
|
||||||
|
@ -83,6 +75,10 @@ public class DeviceInfo extends AbstractInfo {
|
||||||
return fw2Version;
|
return fw2Version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean supportsHeartrate() {
|
||||||
|
return isMilli1S();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "DeviceInfo{" +
|
return "DeviceInfo{" +
|
||||||
|
@ -117,8 +113,7 @@ public class DeviceInfo extends AbstractInfo {
|
||||||
return MiBandConst.MI_1A;
|
return MiBandConst.MI_1A;
|
||||||
}
|
}
|
||||||
if (isMilli1S()) {
|
if (isMilli1S()) {
|
||||||
return getHumanFirmware2Version();
|
return MiBandConst.MI_1S;
|
||||||
// return MiBandConst.MI_1S;
|
|
||||||
}
|
}
|
||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.State;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents;
|
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
||||||
|
@ -551,7 +552,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supportsHeartRate() {
|
public boolean supportsHeartRate() {
|
||||||
return getDeviceInfo() != null && getDeviceInfo().isMilli1S();
|
return getDeviceInfo() != null && getDeviceInfo().supportsHeartrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -815,9 +816,12 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||||
private void handleDeviceInfo(byte[] value, int status) {
|
private void handleDeviceInfo(byte[] value, int status) {
|
||||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||||
mDeviceInfo = new DeviceInfo(value);
|
mDeviceInfo = new DeviceInfo(value);
|
||||||
|
if (getDeviceInfo().supportsHeartrate()) {
|
||||||
|
getDevice().addDeviceInfo(new GenericItem("HR:", MiBandFWHelper.formatFirmwareVersion(mDeviceInfo.getHeartrateFirmwareVersion())));
|
||||||
|
}
|
||||||
LOG.warn("Device info: " + mDeviceInfo);
|
LOG.warn("Device info: " + mDeviceInfo);
|
||||||
versionCmd.hwVersion = mDeviceInfo.getHwVersion();
|
versionCmd.hwVersion = mDeviceInfo.getHwVersion();
|
||||||
versionCmd.fwVersion = mDeviceInfo.getHumanFirmwareVersion();
|
versionCmd.fwVersion = MiBandFWHelper.formatFirmwareVersion(mDeviceInfo.getFirmwareVersion());
|
||||||
handleGBDeviceEvent(versionCmd);
|
handleGBDeviceEvent(versionCmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -936,7 +940,6 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||||
List<CalendarEvents.CalendarEvent> mEvents = upcomingEvents.getCalendarEventList(getContext());
|
List<CalendarEvents.CalendarEvent> mEvents = upcomingEvents.getCalendarEventList(getContext());
|
||||||
|
|
||||||
int iteration = 0;
|
int iteration = 0;
|
||||||
ArrayList<GBAlarm> alarmList = new ArrayList<>();
|
|
||||||
for (CalendarEvents.CalendarEvent mEvt : mEvents) {
|
for (CalendarEvents.CalendarEvent mEvt : mEvents) {
|
||||||
if (iteration >= availableSlots || iteration > 2) {
|
if (iteration >= availableSlots || iteration > 2) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -137,7 +137,7 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
|
||||||
|
|
||||||
public FetchActivityOperation(MiBandSupport support) {
|
public FetchActivityOperation(MiBandSupport support) {
|
||||||
super(support);
|
super(support);
|
||||||
hasExtendedActivityData = support.getDeviceInfo().isMilli1S();
|
hasExtendedActivityData = support.getDeviceInfo().supportsHeartrate();
|
||||||
activityDataHolderSize = getBytesPerMinuteOfActivityData() * 60 * 4; // 4h
|
activityDataHolderSize = getBytesPerMinuteOfActivityData() * 60 * 4; // 4h
|
||||||
activityStruct = new ActivityStruct(activityDataHolderSize);
|
activityStruct = new ActivityStruct(activityDataHolderSize);
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 619 B |
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
|
@ -0,0 +1,8 @@
|
||||||
|
<!-- drawable/information-outline.xml -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:height="24dp"
|
||||||
|
android:width="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path android:fillColor="#000" android:pathData="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z" />
|
||||||
|
</vector>
|
|
@ -1,75 +1,93 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<GridLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?android:attr/activatedBackgroundIndicator"
|
android:background="?android:attr/activatedBackgroundIndicator"
|
||||||
|
android:columnCount="2"
|
||||||
android:padding="8dp">
|
android:padding="8dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/device_image"
|
android:id="@+id/device_image"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:contentDescription="@string/candidate_item_device_image" />
|
android:contentDescription="@string/candidate_item_device_image" />
|
||||||
|
|
||||||
|
<GridLayout
|
||||||
|
android:background="?android:attr/activatedBackgroundIndicator"
|
||||||
|
android:paddingBottom="2dp"
|
||||||
|
android:columnCount="5"
|
||||||
|
android:layout_gravity="fill_horizontal"
|
||||||
|
android:paddingTop="3dp">
|
||||||
|
|
||||||
<RelativeLayout
|
<TextView
|
||||||
android:layout_width="fill_parent"
|
android:id="@+id/device_name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerVertical="true"
|
android:singleLine="true"
|
||||||
android:layout_toEndOf="@+id/device_image"
|
android:typeface="sans" />
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingStart="8dp">
|
|
||||||
|
|
||||||
<TextView
|
<ProgressBar
|
||||||
android:id="@+id/device_name"
|
android:id="@+id/device_busy_indicator"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignStart="@+id/statuswrapper"
|
android:visibility="gone"
|
||||||
android:layout_toStartOf="@+id/device_info"
|
android:layout_rowSpan="2"
|
||||||
android:singleLine="true"
|
android:indeterminate="true" />
|
||||||
android:typeface="sans" />
|
|
||||||
|
|
||||||
<ProgressBar
|
<android.support.v4.widget.Space
|
||||||
android:id="@+id/device_busy_indicator"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_rowSpan="2" />
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:indeterminate="true" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<TextView
|
||||||
android:id="@+id/statuswrapper"
|
android:id="@+id/battery_label"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/device_name"
|
android:textColor="@color/secondarytext"
|
||||||
android:orientation="horizontal"
|
android:textStyle="bold"
|
||||||
android:paddingTop="3dp">
|
android:paddingLeft="7sp"
|
||||||
|
android:paddingRight="7sp" />
|
||||||
|
|
||||||
<TextView
|
<ImageView
|
||||||
android:id="@+id/device_status"
|
android:src="@drawable/ic_information_outline_grey600_24dp"
|
||||||
android:layout_width="wrap_content"
|
android:id="@+id/device_info_image"
|
||||||
android:layout_height="fill_parent"
|
android:layout_width="32dp"
|
||||||
android:gravity="start"
|
android:layout_height="32dp"
|
||||||
android:textStyle="bold" />
|
android:layout_rowSpan="2"
|
||||||
|
android:scaleType="centerInside"
|
||||||
|
android:contentDescription="@string/candidate_item_device_image"
|
||||||
|
android:clickable="true"
|
||||||
|
android:layout_gravity="center_vertical" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/battery_status"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:gravity="end"
|
|
||||||
android:textColor="@color/secondarytext"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/device_info"
|
android:id="@+id/device_status"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_alignBaseline="@+id/device_name"
|
android:gravity="start|bottom"
|
||||||
android:layout_alignParentEnd="true"
|
android:textStyle="bold"
|
||||||
android:gravity="end"
|
android:layout_gravity="fill_horizontal" />
|
||||||
android:textColor="@color/secondarytext"
|
|
||||||
android:textSize="12sp" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
<TextView
|
||||||
</RelativeLayout>
|
android:id="@+id/battery_status"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="start|bottom"
|
||||||
|
android:textColor="@color/secondarytext"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
android:paddingRight="7sp"
|
||||||
|
android:paddingLeft="7sp" />
|
||||||
|
</GridLayout>
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/device_item_infos"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/widget_margin"
|
||||||
|
android:gravity="fill_horizontal"
|
||||||
|
android:layout_columnSpan="2"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_gravity="fill"
|
||||||
|
android:paddingLeft="36dp" />
|
||||||
|
</GridLayout>
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?android:attr/activatedBackgroundIndicator"
|
||||||
|
android:paddingStart="1dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/item_image"
|
||||||
|
android:layout_width="8dp"
|
||||||
|
android:layout_height="8dp"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:contentDescription="@string/candidate_item_device_image" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_toEndOf="@+id/item_image"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="2dp"
|
||||||
|
android:paddingEnd="2dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/item_name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:scrollHorizontally="false"
|
||||||
|
android:textColor="@color/secondarytext"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:text="Item Name"
|
||||||
|
android:singleLine="true" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/item_details"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/secondarytext"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:text="Item Description"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
|
@ -231,5 +231,7 @@
|
||||||
<string name="add_widget">Add widget</string>
|
<string name="add_widget">Add widget</string>
|
||||||
<string name="activity_prefs_sleep_duration">Preferred sleep duration in hours</string>
|
<string name="activity_prefs_sleep_duration">Preferred sleep duration in hours</string>
|
||||||
<string name="appwidget_alarms_set">An alarm was set for %1$02d:%2$02d</string>
|
<string name="appwidget_alarms_set">An alarm was set for %1$02d:%2$02d</string>
|
||||||
|
<string name="device_hw">HW: %1$s</string>
|
||||||
|
<string name="device_fw">FW: %1$s</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue