mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-03 17:02:13 +01:00
Pebble: display progressbar during installation of apps/firmware
This commit is contained in:
parent
b5cf81eedf
commit
e65c492792
@ -1,7 +1,7 @@
|
|||||||
###Changelog
|
###Changelog
|
||||||
####next release
|
####next release
|
||||||
* Pebble: Huge speedup for app/firmware installation.
|
* Pebble: Huge speedup for app/firmware installation.
|
||||||
* Pebble: Use a separate notification for installation procedure
|
* Pebble: Use a separate notification with progress bar for installation procedure
|
||||||
* Pebble: Bugfix for beeing stuck while waiting for a slot, when none is available
|
* Pebble: Bugfix for beeing stuck while waiting for a slot, when none is available
|
||||||
* Mi Band: Display connection status in notification (previously Pebble only)
|
* Mi Band: Display connection status in notification (previously Pebble only)
|
||||||
|
|
||||||
|
@ -75,25 +75,35 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
private int mCurrentInstallableIndex = -1;
|
private int mCurrentInstallableIndex = -1;
|
||||||
private int mInstallSlot = -2;
|
private int mInstallSlot = -2;
|
||||||
private int mCRC = -1;
|
private int mCRC = -1;
|
||||||
|
private int mBinarySize = -1;
|
||||||
|
private int mBytesWritten = -1;
|
||||||
|
|
||||||
public static Notification createInstallNotification(String text, boolean ongoing, Context context) {
|
public static Notification createInstallNotification(String text, boolean ongoing,
|
||||||
|
int percentage, Context context) {
|
||||||
Intent notificationIntent = new Intent(context, AppManagerActivity.class);
|
Intent notificationIntent = new Intent(context, AppManagerActivity.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);
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
|
||||||
notificationIntent, 0);
|
notificationIntent, 0);
|
||||||
|
|
||||||
return new NotificationCompat.Builder(context)
|
NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
|
||||||
.setContentTitle("Gadgetbridge")
|
.setContentTitle("Gadgetbridge")
|
||||||
.setTicker(text)
|
|
||||||
.setContentText(text)
|
.setContentText(text)
|
||||||
|
.setTicker(text)
|
||||||
|
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setContentIntent(pendingIntent)
|
.setContentIntent(pendingIntent)
|
||||||
.setOngoing(ongoing).build();
|
.setOngoing(ongoing);
|
||||||
|
|
||||||
|
if (ongoing) {
|
||||||
|
nb.setProgress(100, percentage, percentage == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nb.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateInstallNotification(String text, boolean ongoing, Context context) {
|
public static void updateInstallNotification(String text, boolean ongoing, int percentage, Context context) {
|
||||||
Notification notification = createInstallNotification(text, ongoing, context);
|
Notification notification = createInstallNotification(text, ongoing, percentage, context);
|
||||||
|
|
||||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
nm.notify(NOTIFICATION_ID, notification);
|
nm.notify(NOTIFICATION_ID, notification);
|
||||||
@ -141,9 +151,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
case APP_WAIT_SLOT:
|
case APP_WAIT_SLOT:
|
||||||
if (mInstallSlot == -1) {
|
if (mInstallSlot == -1) {
|
||||||
finishInstall(true); // no slots available
|
finishInstall(true); // no slots available
|
||||||
}
|
} else if (mInstallSlot >= 0) {
|
||||||
else if (mInstallSlot >= 0) {
|
|
||||||
updateInstallNotification("starting installation", true, getContext());
|
|
||||||
mInstallState = PebbleAppInstallState.APP_START_INSTALL;
|
mInstallState = PebbleAppInstallState.APP_START_INSTALL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -163,8 +171,9 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
PebbleInstallable pi = mPebbleInstallables[mCurrentInstallableIndex];
|
PebbleInstallable pi = mPebbleInstallables[mCurrentInstallableIndex];
|
||||||
mZis = mPBWReader.getInputStreamFile(pi.getFileName());
|
mZis = mPBWReader.getInputStreamFile(pi.getFileName());
|
||||||
mCRC = pi.getCRC();
|
mCRC = pi.getCRC();
|
||||||
int binarySize = pi.getFileSize(); // TODO: use for progressbar
|
mBinarySize = pi.getFileSize();
|
||||||
writeInstallApp(mPebbleProtocol.encodeUploadStart(pi.getType(), (byte) mInstallSlot, binarySize));
|
mBytesWritten = 0;
|
||||||
|
writeInstallApp(mPebbleProtocol.encodeUploadStart(pi.getType(), (byte) mInstallSlot, mBinarySize));
|
||||||
mInstallState = PebbleAppInstallState.APP_WAIT_TOKEN;
|
mInstallState = PebbleAppInstallState.APP_WAIT_TOKEN;
|
||||||
break;
|
break;
|
||||||
case APP_WAIT_TOKEN:
|
case APP_WAIT_TOKEN:
|
||||||
@ -183,7 +192,9 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
} while (bytes < 2000);
|
} while (bytes < 2000);
|
||||||
|
|
||||||
if (bytes > 0) {
|
if (bytes > 0) {
|
||||||
|
updateInstallNotification("installing binary " + (mCurrentInstallableIndex + 1) + "/" + mPebbleInstallables.length, true, (int) (((float) mBytesWritten / mBinarySize) * 100), getContext());
|
||||||
writeInstallApp(mPebbleProtocol.encodeUploadChunk(mAppInstallToken, buffer, bytes));
|
writeInstallApp(mPebbleProtocol.encodeUploadChunk(mAppInstallToken, buffer, bytes));
|
||||||
|
mBytesWritten += bytes;
|
||||||
mAppInstallToken = -1;
|
mAppInstallToken = -1;
|
||||||
mInstallState = PebbleAppInstallState.APP_WAIT_TOKEN;
|
mInstallState = PebbleAppInstallState.APP_WAIT_TOKEN;
|
||||||
} else {
|
} else {
|
||||||
@ -449,9 +460,9 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (hadError) {
|
if (hadError) {
|
||||||
updateInstallNotification("installation failed!", false, getContext());
|
updateInstallNotification("installation failed!", false, 0, getContext());
|
||||||
} else {
|
} else {
|
||||||
updateInstallNotification("installation successful", false, getContext());
|
updateInstallNotification("installation successful", false, 0, getContext());
|
||||||
}
|
}
|
||||||
mInstallState = PebbleAppInstallState.UNKNOWN;
|
mInstallState = PebbleAppInstallState.UNKNOWN;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user