Further improvements:
- append a string on the control center when the device is charging - battery status string is no more, welcome battery state enum - the notification will not be shown when the device is charging, even if the level is below threshold
This commit is contained in:
parent
a6b28a804c
commit
eb39ce9367
|
@ -11,6 +11,7 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
|
||||||
|
@ -59,6 +60,11 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
|
||||||
short batteryLevel = device.getBatteryLevel();
|
short batteryLevel = device.getBatteryLevel();
|
||||||
if (batteryLevel != GBDevice.BATTERY_UNKNOWN) {
|
if (batteryLevel != GBDevice.BATTERY_UNKNOWN) {
|
||||||
batteryStatusLabel.setText("BAT: " + device.getBatteryLevel() + "%");
|
batteryStatusLabel.setText("BAT: " + device.getBatteryLevel() + "%");
|
||||||
|
GBDeviceEventBatteryInfo.BatteryState batteryState = device.getBatteryState();
|
||||||
|
if (GBDeviceEventBatteryInfo.BatteryState.BATTERY_CHARGING.equals(batteryState) ||
|
||||||
|
GBDeviceEventBatteryInfo.BatteryState.BATTERY_CHARGING_FULL.equals(batteryState)) {
|
||||||
|
batteryStatusLabel.append(" CHG");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
batteryStatusLabel.setText("");
|
batteryStatusLabel.setText("");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,6 @@ import java.util.GregorianCalendar;
|
||||||
public class GBDeviceEventBatteryInfo extends GBDeviceEvent {
|
public class GBDeviceEventBatteryInfo extends GBDeviceEvent {
|
||||||
public GregorianCalendar lastChargeTime= null;
|
public GregorianCalendar lastChargeTime= null;
|
||||||
public BatteryState state = BatteryState.UNKNOWN;
|
public BatteryState state = BatteryState.UNKNOWN;
|
||||||
//TODO: I think the string should be deprecated in favor of the Enum above
|
|
||||||
public String status;
|
|
||||||
public short level = 50;
|
public short level = 50;
|
||||||
public int numCharges = -1;
|
public int numCharges = -1;
|
||||||
|
|
||||||
|
@ -17,10 +15,11 @@ public class GBDeviceEventBatteryInfo extends GBDeviceEvent {
|
||||||
|
|
||||||
public enum BatteryState {
|
public enum BatteryState {
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
CHARGE_FULL,
|
BATTERY_NORMAL,
|
||||||
CHARGE_MEDIUM,
|
BATTERY_LOW,
|
||||||
CHARGE_LOW,
|
BATTERY_CHARGING,
|
||||||
CHARGING,
|
BATTERY_CHARGING_FULL,
|
||||||
|
BATTERY_NOT_CHARGING_FULL
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean extendedInfoAvailable() {
|
public boolean extendedInfoAvailable() {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.support.v4.content.LocalBroadcastManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo.BatteryState;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
@ -42,6 +43,7 @@ public class GBDevice implements Parcelable {
|
||||||
private short mBatteryThresholdPercent = BATTERY_THRESHOLD_PERCENT;
|
private short mBatteryThresholdPercent = BATTERY_THRESHOLD_PERCENT;
|
||||||
//TODO: get rid of String mBatteryStatus in favor of Enum mBatteryState
|
//TODO: get rid of String mBatteryStatus in favor of Enum mBatteryState
|
||||||
private String mBatteryStatus;
|
private String mBatteryStatus;
|
||||||
|
private BatteryState mBatteryState;
|
||||||
private short mRssi = RSSI_UNKNOWN;
|
private short mRssi = RSSI_UNKNOWN;
|
||||||
private String mBusyTask;
|
private String mBusyTask;
|
||||||
|
|
||||||
|
@ -180,7 +182,7 @@ public class GBDevice implements Parcelable {
|
||||||
|
|
||||||
private void unsetDynamicState() {
|
private void unsetDynamicState() {
|
||||||
setBatteryLevel(BATTERY_UNKNOWN);
|
setBatteryLevel(BATTERY_UNKNOWN);
|
||||||
setBatteryStatus(null);
|
setBatteryState(BatteryState.UNKNOWN);
|
||||||
setFirmwareVersion(null);
|
setFirmwareVersion(null);
|
||||||
setRssi(RSSI_UNKNOWN);
|
setRssi(RSSI_UNKNOWN);
|
||||||
if (mBusyTask != null) {
|
if (mBusyTask != null) {
|
||||||
|
@ -284,18 +286,14 @@ public class GBDevice implements Parcelable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public BatteryState getBatteryState() {
|
||||||
* Returns a string representation of the battery state.
|
return mBatteryState;
|
||||||
*/
|
|
||||||
public String getBatteryStatus() {
|
|
||||||
return mBatteryStatus != null ? mBatteryStatus : GBApplication.getContext().getString(R.string._unknown_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBatteryStatus(String batteryStatus) {
|
public void setBatteryState(BatteryState mBatteryState) {
|
||||||
mBatteryStatus = batteryStatus;
|
this.mBatteryState = mBatteryState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public short getBatteryThresholdPercent() {
|
public short getBatteryThresholdPercent() {
|
||||||
return mBatteryThresholdPercent;
|
return mBatteryThresholdPercent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,9 +228,13 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
LOG.info("Got BATTERY_INFO device event");
|
LOG.info("Got BATTERY_INFO device event");
|
||||||
gbDevice.setBatteryLevel(deviceEvent.level);
|
gbDevice.setBatteryLevel(deviceEvent.level);
|
||||||
gbDevice.setBatteryStatus(deviceEvent.status);
|
gbDevice.setBatteryState(deviceEvent.state);
|
||||||
|
|
||||||
if (deviceEvent.level <= gbDevice.getBatteryThresholdPercent()) {
|
//show the notification if the battery level is below threshold and only if not connected to charger
|
||||||
|
if (deviceEvent.level <= gbDevice.getBatteryThresholdPercent() &&
|
||||||
|
(GBDeviceEventBatteryInfo.BatteryState.BATTERY_LOW.equals(deviceEvent.state) ||
|
||||||
|
GBDeviceEventBatteryInfo.BatteryState.BATTERY_NORMAL.equals(deviceEvent.state))
|
||||||
|
) {
|
||||||
GB.updateBatteryNotification(context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), deviceEvent.level),
|
GB.updateBatteryNotification(context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), deviceEvent.level),
|
||||||
deviceEvent.extendedInfoAvailable() ?
|
deviceEvent.extendedInfoAvailable() ?
|
||||||
context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), deviceEvent.level) + "\n" +
|
context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), deviceEvent.level) + "\n" +
|
||||||
|
|
|
@ -3,10 +3,15 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.miband;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo.BatteryState;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
||||||
|
|
||||||
public class BatteryInfo extends AbstractInfo {
|
public class BatteryInfo extends AbstractInfo {
|
||||||
|
public static final byte DEVICE_BATTERY_NORMAL = 0;
|
||||||
|
public static final byte DEVICE_BATTERY_LOW = 1;
|
||||||
|
public static final byte DEVICE_BATTERY_CHARGING = 2;
|
||||||
|
public static final byte DEVICE_BATTERY_CHARGING_FULL = 3;
|
||||||
|
public static final byte DEVICE_BATTERY_CHARGE_OFF = 4;
|
||||||
|
|
||||||
public BatteryInfo(byte[] data) {
|
public BatteryInfo(byte[] data) {
|
||||||
super(data);
|
super(data);
|
||||||
}
|
}
|
||||||
|
@ -18,21 +23,23 @@ public class BatteryInfo extends AbstractInfo {
|
||||||
return 50; // actually unknown
|
return 50; // actually unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatus() {
|
public BatteryState getState() {
|
||||||
if (mData.length >= 10) {
|
if (mData.length >= 10) {
|
||||||
int value = mData[9];
|
int value = mData[9];
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 1:
|
case DEVICE_BATTERY_NORMAL:
|
||||||
return GBApplication.getContext().getString(R.string.battery_low);
|
return BatteryState.BATTERY_NORMAL;
|
||||||
case 2:
|
case DEVICE_BATTERY_LOW:
|
||||||
return GBApplication.getContext().getString(R.string.battery_medium);
|
return BatteryState.BATTERY_LOW;
|
||||||
case 3:
|
case DEVICE_BATTERY_CHARGING:
|
||||||
return GBApplication.getContext().getString(R.string.battery_full);
|
return BatteryState.BATTERY_CHARGING;
|
||||||
case 4:
|
case DEVICE_BATTERY_CHARGING_FULL:
|
||||||
return GBApplication.getContext().getString(R.string.battery_not_charging);
|
return BatteryState.BATTERY_CHARGING_FULL;
|
||||||
|
case DEVICE_BATTERY_CHARGE_OFF:
|
||||||
|
return BatteryState.BATTERY_NOT_CHARGING_FULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return GBApplication.getContext().getString(R.string._unknown_);
|
return BatteryState.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GregorianCalendar getLastChargeTime() {
|
public GregorianCalendar getLastChargeTime() {
|
||||||
|
|
|
@ -737,6 +737,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||||
BatteryInfo info = new BatteryInfo(value);
|
BatteryInfo info = new BatteryInfo(value);
|
||||||
batteryCmd.level = ((short) info.getLevelInPercent());
|
batteryCmd.level = ((short) info.getLevelInPercent());
|
||||||
|
batteryCmd.state = info.getState();
|
||||||
batteryCmd.lastChargeTime = info.getLastChargeTime();
|
batteryCmd.lastChargeTime = info.getLastChargeTime();
|
||||||
batteryCmd.numCharges = info.getNumCharges();
|
batteryCmd.numCharges = info.getNumCharges();
|
||||||
handleGBDeviceEvent(batteryCmd);
|
handleGBDeviceEvent(batteryCmd);
|
||||||
|
|
|
@ -74,10 +74,6 @@
|
||||||
<string name="tap_a_device_to_connect">tap a device to connect</string>
|
<string name="tap_a_device_to_connect">tap a device to connect</string>
|
||||||
<string name="cannot_connect_bt_address_invalid_">Cannot connect. BT address invalid?</string>
|
<string name="cannot_connect_bt_address_invalid_">Cannot connect. BT address invalid?</string>
|
||||||
<string name="gadgetbridge_running">Gadgetbridge running</string>
|
<string name="gadgetbridge_running">Gadgetbridge running</string>
|
||||||
<string name="battery_low">low</string>
|
|
||||||
<string name="battery_medium">medium</string>
|
|
||||||
<string name="battery_full">full</string>
|
|
||||||
<string name="battery_not_charging">not charging</string>
|
|
||||||
<string name="installing_binary_d_d">installing binary %1$d/%2$d</string>
|
<string name="installing_binary_d_d">installing binary %1$d/%2$d</string>
|
||||||
<string name="installation_failed_">installation failed!</string>
|
<string name="installation_failed_">installation failed!</string>
|
||||||
<string name="installation_successful">installation successful</string>
|
<string name="installation_successful">installation successful</string>
|
||||||
|
|
Loading…
Reference in New Issue