1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 18:15:49 +01:00

Add a progress notification for the activity data transfer.

This commit is contained in:
Daniele Gobbetti 2015-09-24 14:03:01 +02:00
parent 5578691321
commit e1ea8270ca
2 changed files with 44 additions and 0 deletions

View File

@ -195,8 +195,11 @@ public class FetchActivityOperation extends AbstractBTLEOperation<MiBandSupport>
}
LOG.debug("activity data: length: " + value.length + ", remaining bytes: " + activityStruct.activityDataRemainingBytes);
GB.updateTransferNotification(getContext().getString(R.string.busy_task_fetch_activity_data), true, (int)(((float) (activityStruct.activityDataUntilNextHeader - activityStruct.activityDataRemainingBytes)) / activityStruct.activityDataUntilNextHeader * 100), getContext());
if (activityStruct.isBlockFinished()) {
sendAckDataTransfer(activityStruct.activityDataTimestampToAck, activityStruct.activityDataUntilNextHeader);
GB.updateTransferNotification("", false, 100, getContext());
}
}

View File

@ -40,6 +40,7 @@ public class GB {
public static final int NOTIFICATION_ID = 1;
public static final int NOTIFICATION_ID_INSTALL = 2;
public static final int NOTIFICATION_ID_LOW_BATTERY = 3;
public static final int NOTIFICATION_ID_TRANSFER = 4;
private static final Logger LOG = LoggerFactory.getLogger(GB.class);
public static final int INFO = 1;
@ -80,6 +81,11 @@ public class GB {
nm.notify(id, notification);
}
private static void removeNotification(int id, Context context) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(id);
}
public static void setReceiversEnableState(boolean enable, Context context) {
LOG.info("Setting broadcast receivers to: " + enable);
final Class<?>[] receiverClasses = {
@ -275,6 +281,41 @@ public class GB {
}
}
private static Notification createTransferNotification(String text, boolean ongoing,
int percentage, Context context) {
Intent notificationIntent = new Intent(context, ControlCenter.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(text)
.setContentIntent(pendingIntent)
.setOngoing(ongoing);
if (ongoing) {
nb.setProgress(100, percentage, percentage == 0);
nb.setSmallIcon(android.R.drawable.stat_sys_download);
} else {
nb.setProgress(0, 0, false);
nb.setSmallIcon(android.R.drawable.stat_sys_download_done);
}
return nb.build();
}
public static void updateTransferNotification(String text, boolean ongoing, int percentage, Context context) {
if(percentage == 100) {
removeNotification(NOTIFICATION_ID_TRANSFER, context);
} else {
Notification notification = createTransferNotification(text, ongoing, percentage, context);
updateNotification(notification, NOTIFICATION_ID_TRANSFER, context);
}
}
private static Notification createInstallNotification(String text, boolean ongoing,
int percentage, Context context) {
Intent notificationIntent = new Intent(context, ControlCenter.class);