diff --git a/LICENSE.artwork b/LICENSE.artwork
index 3d8766bea..5fa78b05c 100644
--- a/LICENSE.artwork
+++ b/LICENSE.artwork
@@ -1,10 +1,13 @@
The following artwork is licensed under the following licenses
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_activitytracker.png (by xphnx)
ic_watchface.png (by xphnx)
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/
+
+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
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/deviceevents/GBDeviceEventBatteryInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/deviceevents/GBDeviceEventBatteryInfo.java
index 2bc311afb..78c315916 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/deviceevents/GBDeviceEventBatteryInfo.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/deviceevents/GBDeviceEventBatteryInfo.java
@@ -4,7 +4,7 @@ package nodomain.freeyourgadget.gadgetbridge.deviceevents;
import java.util.GregorianCalendar;
public class GBDeviceEventBatteryInfo extends GBDeviceEvent {
- public GregorianCalendar lastChargeTime;
+ public GregorianCalendar lastChargeTime= null;
public BatteryState state = BatteryState.UNKNOWN;
//TODO: I think the string should be deprecated in favor of the Enum above
public String status;
@@ -22,4 +22,11 @@ public class GBDeviceEventBatteryInfo extends GBDeviceEvent {
CHARGE_LOW,
CHARGING,
}
+
+ public boolean extendedInfoAvailable() {
+ if (numCharges != -1 && lastChargeTime != null) {
+ return true;
+ }
+ return false;
+ }
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java
index bf2e213e8..5c7a346e1 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java
@@ -30,6 +30,7 @@ public class GBDevice implements Parcelable {
private static final Logger LOG = LoggerFactory.getLogger(GBDevice.class);
public static final short RSSI_UNKNOWN = 0;
public static final short BATTERY_UNKNOWN = -1;
+ private static final short BATTERY_THRESHOLD_PERCENT = 10;
public static final String EXTRA_DEVICE = "device";
private final String mName;
private final String mAddress;
@@ -38,6 +39,7 @@ public class GBDevice implements Parcelable {
private String mHardwareVersion = null;
private State mState = State.NOT_CONNECTED;
private short mBatteryLevel = BATTERY_UNKNOWN;
+ private short mBatteryThresholdPercent = BATTERY_THRESHOLD_PERCENT;
//TODO: get rid of String mBatteryStatus in favor of Enum mBatteryState
private String mBatteryStatus;
private short mRssi = RSSI_UNKNOWN;
@@ -293,6 +295,15 @@ public class GBDevice implements Parcelable {
mBatteryStatus = batteryStatus;
}
+
+ public short getBatteryThresholdPercent() {
+ return mBatteryThresholdPercent;
+ }
+
+ public void setBatteryThresholdPercent(short batteryThresholdPercent) {
+ this.mBatteryThresholdPercent = batteryThresholdPercent;
+ }
+
@Override
public String toString() {
return "Device " + getName() + ", " + getAddress() + ", " + getStateString();
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java
index 5783aec31..037a12f2d 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java
@@ -230,12 +230,13 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
gbDevice.setBatteryLevel(deviceEvent.level);
gbDevice.setBatteryStatus(deviceEvent.status);
-
- //TODO: maybe switch to a device-dependent threshold
- if (deviceEvent.level < 10) {
- GB.updateBatteryNotification(deviceEvent.level,
- context.getString(R.string.notif_battery_low_bigtext_last_charge_time, DateFormat.getDateTimeInstance().format(deviceEvent.lastChargeTime.getTime()).toString()) +
+ if (deviceEvent.level <= gbDevice.getBatteryThresholdPercent()) {
+ GB.updateBatteryNotification(context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), deviceEvent.level),
+ deviceEvent.extendedInfoAvailable() ?
+ 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_number_of_charges, deviceEvent.numCharges)
+ : ""
, context);
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java
index 4d624121b..fb1f4bca9 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java
@@ -300,7 +300,7 @@ public class GB {
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);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
@@ -308,18 +308,22 @@ public class GB {
notificationIntent, 0);
NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
- .setContentTitle(context.getString(R.string.notif_battery_low_title))
- .setContentText(context.getString(R.string.notif_battery_low_percent, level))
+ .setContentTitle( context.getString(R.string.notif_battery_low_title))
+ .setContentText(text)
.setContentIntent(pendingIntent)
- .setSmallIcon(R.drawable.ic_notification)
- .setStyle(new NotificationCompat.BigTextStyle().bigText(text))
+ .setSmallIcon(R.drawable.ic_notification_low_battery)
+ .setPriority(NotificationCompat.PRIORITY_HIGH)
.setOngoing(false);
+ if (bigText != null) {
+ nb.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));
+ }
+
return nb.build();
}
- public static void updateBatteryNotification(int level, String text, Context context) {
- Notification notification = createBatteryNotification(level, text, context);
+ public static void updateBatteryNotification(String text, String bigText, Context context) {
+ Notification notification = createBatteryNotification(text, bigText, context);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NOTIFICATION_ID_LOW_BATTERY, notification);
diff --git a/app/src/main/res/drawable-hdpi/ic_notification_low_battery.png b/app/src/main/res/drawable-hdpi/ic_notification_low_battery.png
new file mode 100644
index 000000000..dad13ba6e
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_notification_low_battery.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_notification_low_battery.png b/app/src/main/res/drawable-mdpi/ic_notification_low_battery.png
new file mode 100644
index 000000000..32c4393f4
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_notification_low_battery.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_notification_low_battery.png b/app/src/main/res/drawable-xhdpi/ic_notification_low_battery.png
new file mode 100644
index 000000000..f1aff36a3
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_notification_low_battery.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_notification_low_battery.png b/app/src/main/res/drawable-xxhdpi/ic_notification_low_battery.png
new file mode 100644
index 000000000..60dacdf78
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_notification_low_battery.png differ
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7132259be..4bd5358b0 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -167,7 +167,7 @@
Unable to install the given firmware: it doesn\'t match your Pebble\'s hardware revision.
Please wait while determining the installation status...
Gadget battery Low!
- Battery left: %s%%
+ %1$s battery left: %2$s%%
Last charge: %s \n
Number of charges: %s