@@ -102,8 +102,12 @@ public abstract class PartialFlashingBaseService extends IntentService {
102
102
@ Override
103
103
public void onCreate () {
104
104
super .onCreate ();
105
+
106
+ final IntentFilter intentFilter = new IntentFilter ();
107
+ intentFilter .addAction (PartialFlashingBaseService .BROADCAST_ACTION );
105
108
106
109
final LocalBroadcastManager manager = LocalBroadcastManager .getInstance (this );
110
+ manager .registerReceiver (broadcastReceiver , intentFilter );
107
111
}
108
112
109
113
// Various callback methods defined by the BLE API.
@@ -220,6 +224,27 @@ public PartialFlashingBaseService() {
220
224
super (TAG );
221
225
}
222
226
227
+ public static final String BROADCAST_PROGRESS = "org.microbit.android.partialflashing.broadcast.BROADCAST_PROGRESS" ;
228
+ public static final String EXTRA_PROGRESS = "org.microbit.android.partialflashing.extra.EXTRA_PROGRESS" ;
229
+
230
+ private void sendProgressBroadcast (final int progress ) {
231
+
232
+ Log .v (TAG , "Sending progress broadcast: " + progress + "%" );
233
+
234
+ final Intent broadcast = new Intent (BROADCAST_PROGRESS );
235
+ broadcast .putExtra (EXTRA_PROGRESS , progress );
236
+
237
+ LocalBroadcastManager .getInstance (this ).sendBroadcast (broadcast );
238
+ }
239
+
240
+ // private void sendErrorBroadcast(final int error) {
241
+ //
242
+ // final Intent broadcast = new Intent(BROADCAST_ERROR);
243
+ //
244
+ // broadcast.putExtra(EXTRA_DEVICE_ADDRESS, mDeviceAddress);
245
+ // LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
246
+ // }
247
+
223
248
// Write to BLE Flash Characteristic
224
249
public Boolean writePartialFlash (byte data []){
225
250
@@ -319,7 +344,10 @@ public Boolean attemptPartialFlash(String filePath) {
319
344
if (packetState == PACKET_STATE_RETRANSMIT ) {
320
345
lineCount = lineCount - 4 ;
321
346
} else {
322
- // TODO update UI
347
+ // send progress update
348
+ Log .v (TAG , "LC: " + lineCount + ", NL: " + numOfLines );
349
+ int percent = Math .round ((float )100 * ((float )(lineCount ) / (float )(numOfLines )));
350
+ sendProgressBroadcast (percent );
323
351
}
324
352
325
353
// Increment packet #
@@ -334,6 +362,7 @@ public Boolean attemptPartialFlash(String filePath) {
334
362
335
363
// Finished Writing
336
364
Log .v (TAG , "Flash Complete" );
365
+ sendProgressBroadcast (100 );
337
366
338
367
// Time execution
339
368
long endTime = SystemClock .elapsedRealtime ();
0 commit comments