Abort action added in the notification.

git-svn-id: http://svn.nordicsemi.no/applications/mobile/android/DFULibrary/trunk@6105 94a72e49-5737-764a-8bf3-0d5ceb61e552
This commit is contained in:
alno 2014-07-04 12:39:14 +00:00
parent f929cadd41
commit a1f4dd503d
6 changed files with 16 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

View File

Before

Width:  |  Height:  |  Size: 993 B

After

Width:  |  Height:  |  Size: 993 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 415 B

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -2,6 +2,8 @@
<string name="dfu_unknown_name">unnamed device</string>
<string name="dfu_action_abort">Abort</string>
<string name="dfu_status_initializing">Initializing&#8230;</string>
<string name="dfu_status_connecting">Connecting&#8230;</string>
<string name="dfu_status_starting">Starting DFU&#8230;</string>

View File

@ -583,7 +583,10 @@ public abstract class DfuBaseService extends IntentService {
initialize();
final LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
manager.registerReceiver(mDfuActionReceiver, makeDfuActionIntentFilter());
final IntentFilter actionFilter = makeDfuActionIntentFilter();
manager.registerReceiver(mDfuActionReceiver, actionFilter);
// We must register this as a non-local receiver to get broadcasts from the notification action
registerReceiver(mDfuActionReceiver, actionFilter);
final IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
@ -597,6 +600,7 @@ public abstract class DfuBaseService extends IntentService {
final LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
manager.unregisterReceiver(mDfuActionReceiver);
unregisterReceiver(mDfuActionReceiver);
unregisterReceiver(mConnectionStateBroadcastReceiver);
}
@ -1595,7 +1599,7 @@ public abstract class DfuBaseService extends IntentService {
final String deviceAddress = mDeviceAddress;
final String deviceName = mDeviceName != null ? mDeviceName : getString(R.string.dfu_unknown_name);
final Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.stat_dfu);
final Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_notify_dfu);
final Notification.Builder builder = new Notification.Builder(this).setSmallIcon(android.R.drawable.stat_sys_upload).setOnlyAlertOnce(true).setLargeIcon(largeIcon);
switch (progress) {
@ -1646,6 +1650,14 @@ public abstract class DfuBaseService extends IntentService {
final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
// Add Abort action to the notification
if (progress != PROGRESS_ABORTED && progress != PROGRESS_COMPLETED) {
final Intent abortIntent = new Intent(BROADCAST_ACTION);
abortIntent.putExtra(EXTRA_ACTION, ACTION_ABORT);
final PendingIntent pendingAbortIntent = PendingIntent.getBroadcast(this, 1, abortIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.ic_action_notify_cancel, getString(R.string.dfu_action_abort), pendingAbortIntent);
}
final NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(NOTIFICATION_ID, builder.build());
}