Some refinements:

- only show the bigtext notification if the device has set extended battery info
- custom icon for the low battery notification (with license information)
- show device name in the notification
- set the notification to high priority
- the battery threshold is now set in GBDevice
live-activity-data
Daniele Gobbetti 2015-08-19 17:36:53 +02:00
parent 57a85e63b0
commit 0d8adeb7f9
10 changed files with 41 additions and 15 deletions

View File

@ -1,10 +1,13 @@
The following artwork is licensed under the following licenses The following artwork is licensed under the following licenses
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0): Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0):
ic_device_pebble.png (by xphnx) ic_device_pebble.png (by 9)
ic_device_miband.png (by xphnx) ic_device_miband.png (by xphnx)
ic_activitytracker.png (by xphnx) ic_activitytracker.png (by xphnx)
ic_watchface.png (by xphnx) ic_watchface.png (by xphnx)
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0): Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0):
"GET IT ON F-Droid" button by Laura Kalbag. Source: https://ind.ie/about/blog/f-droid-button/ "GET IT ON F-Droid" button by Laura Kalbag. Source: https://ind.ie/about/blog/f-droid-button/
Creative Commons Attribution 3.0 Unported license (CC BY-3.0):
ic_notification_battery_low.png by Picol.org. Source: https://commons.wikimedia.org/wiki/File:Battery_1_Picol_icon.svg

View File

@ -4,7 +4,7 @@ package nodomain.freeyourgadget.gadgetbridge.deviceevents;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
public class GBDeviceEventBatteryInfo extends GBDeviceEvent { public class GBDeviceEventBatteryInfo extends GBDeviceEvent {
public GregorianCalendar lastChargeTime; 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 //TODO: I think the string should be deprecated in favor of the Enum above
public String status; public String status;
@ -22,4 +22,11 @@ public class GBDeviceEventBatteryInfo extends GBDeviceEvent {
CHARGE_LOW, CHARGE_LOW,
CHARGING, CHARGING,
} }
public boolean extendedInfoAvailable() {
if (numCharges != -1 && lastChargeTime != null) {
return true;
}
return false;
}
} }

View File

@ -30,6 +30,7 @@ public class GBDevice implements Parcelable {
private static final Logger LOG = LoggerFactory.getLogger(GBDevice.class); private static final Logger LOG = LoggerFactory.getLogger(GBDevice.class);
public static final short RSSI_UNKNOWN = 0; public static final short RSSI_UNKNOWN = 0;
public static final short BATTERY_UNKNOWN = -1; public static final short BATTERY_UNKNOWN = -1;
private static final short BATTERY_THRESHOLD_PERCENT = 10;
public static final String EXTRA_DEVICE = "device"; public static final String EXTRA_DEVICE = "device";
private final String mName; private final String mName;
private final String mAddress; private final String mAddress;
@ -38,6 +39,7 @@ public class GBDevice implements Parcelable {
private String mHardwareVersion = null; private String mHardwareVersion = null;
private State mState = State.NOT_CONNECTED; private State mState = State.NOT_CONNECTED;
private short mBatteryLevel = BATTERY_UNKNOWN; private short mBatteryLevel = BATTERY_UNKNOWN;
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 short mRssi = RSSI_UNKNOWN; private short mRssi = RSSI_UNKNOWN;
@ -293,6 +295,15 @@ public class GBDevice implements Parcelable {
mBatteryStatus = batteryStatus; mBatteryStatus = batteryStatus;
} }
public short getBatteryThresholdPercent() {
return mBatteryThresholdPercent;
}
public void setBatteryThresholdPercent(short batteryThresholdPercent) {
this.mBatteryThresholdPercent = batteryThresholdPercent;
}
@Override @Override
public String toString() { public String toString() {
return "Device " + getName() + ", " + getAddress() + ", " + getStateString(); return "Device " + getName() + ", " + getAddress() + ", " + getStateString();

View File

@ -230,12 +230,13 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
gbDevice.setBatteryLevel(deviceEvent.level); gbDevice.setBatteryLevel(deviceEvent.level);
gbDevice.setBatteryStatus(deviceEvent.status); gbDevice.setBatteryStatus(deviceEvent.status);
if (deviceEvent.level <= gbDevice.getBatteryThresholdPercent()) {
//TODO: maybe switch to a device-dependent threshold GB.updateBatteryNotification(context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), deviceEvent.level),
if (deviceEvent.level < 10) { deviceEvent.extendedInfoAvailable() ?
GB.updateBatteryNotification(deviceEvent.level, context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), deviceEvent.level) + "\n" +
context.getString(R.string.notif_battery_low_bigtext_last_charge_time, DateFormat.getDateTimeInstance().format(deviceEvent.lastChargeTime.getTime()).toString()) + context.getString(R.string.notif_battery_low_bigtext_last_charge_time, DateFormat.getDateTimeInstance().format(deviceEvent.lastChargeTime.getTime()).toString()) +
context.getString(R.string.notif_battery_low_bigtext_number_of_charges, deviceEvent.numCharges) context.getString(R.string.notif_battery_low_bigtext_number_of_charges, deviceEvent.numCharges)
: ""
, context); , context);
} }

View File

@ -300,7 +300,7 @@ public class GB {
nm.notify(NOTIFICATION_ID_INSTALL, notification); nm.notify(NOTIFICATION_ID_INSTALL, notification);
} }
private static Notification createBatteryNotification(int level, String text, Context context) { private static Notification createBatteryNotification(String text, String bigText, Context context) {
Intent notificationIntent = new Intent(context, ControlCenter.class); Intent notificationIntent = new Intent(context, ControlCenter.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK); | Intent.FLAG_ACTIVITY_CLEAR_TASK);
@ -308,18 +308,22 @@ public class GB {
notificationIntent, 0); notificationIntent, 0);
NotificationCompat.Builder nb = new NotificationCompat.Builder(context) NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
.setContentTitle(context.getString(R.string.notif_battery_low_title)) .setContentTitle( context.getString(R.string.notif_battery_low_title))
.setContentText(context.getString(R.string.notif_battery_low_percent, level)) .setContentText(text)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_notification) .setSmallIcon(R.drawable.ic_notification_low_battery)
.setStyle(new NotificationCompat.BigTextStyle().bigText(text)) .setPriority(NotificationCompat.PRIORITY_HIGH)
.setOngoing(false); .setOngoing(false);
if (bigText != null) {
nb.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));
}
return nb.build(); return nb.build();
} }
public static void updateBatteryNotification(int level, String text, Context context) { public static void updateBatteryNotification(String text, String bigText, Context context) {
Notification notification = createBatteryNotification(level, text, context); Notification notification = createBatteryNotification(text, bigText, context);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NOTIFICATION_ID_LOW_BATTERY, notification); nm.notify(NOTIFICATION_ID_LOW_BATTERY, notification);

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

View File

@ -167,7 +167,7 @@
<string name="pbw_install_handler_hw_revision_mismatch">Unable to install the given firmware: it doesn\'t match your Pebble\'s hardware revision.</string> <string name="pbw_install_handler_hw_revision_mismatch">Unable to install the given firmware: it doesn\'t match your Pebble\'s hardware revision.</string>
<string name="installer_activity_wait_while_determining_status">Please wait while determining the installation status...</string> <string name="installer_activity_wait_while_determining_status">Please wait while determining the installation status...</string>
<string name="notif_battery_low_title">Gadget battery Low!</string> <string name="notif_battery_low_title">Gadget battery Low!</string>
<string name="notif_battery_low_percent">Battery left: %s%%</string> <string name="notif_battery_low_percent">%1$s battery left: %2$s%%</string>
<string name="notif_battery_low_bigtext_last_charge_time">Last charge: %s \n</string> <string name="notif_battery_low_bigtext_last_charge_time">Last charge: %s \n</string>
<string name="notif_battery_low_bigtext_number_of_charges">Number of charges: %s</string> <string name="notif_battery_low_bigtext_number_of_charges">Number of charges: %s</string>
</resources> </resources>