OSDN Git Service

Update notification in Transfer history manually when BT if off
authorLixin Yue <L.X.YUE@motorola.com>
Mon, 15 Mar 2010 02:45:42 +0000 (10:45 +0800)
committerJaikumar Ganesh <jaikumar@google.com>
Wed, 17 Mar 2010 16:44:44 +0000 (09:44 -0700)
src/com/android/bluetooth/opp/BluetoothOppNotification.java
src/com/android/bluetooth/opp/BluetoothOppTransferHistory.java

index e72ef3e..3a034c8 100644 (file)
@@ -99,10 +99,6 @@ class BluetoothOppNotification {
 
     private int mActiveNotificationId = 0;
 
-    private Notification mOutNoti = null;
-
-    private Notification mInNoti = null;
-
     /**
      * This inner class is used to describe some properties for one transfer.
      */
@@ -348,21 +344,20 @@ class BluetoothOppNotification {
         outboundNum = outboundSuccNumber + outboundFailNumber;
         // create the outbound notification
         if (outboundNum > 0) {
-            mOutNoti = new Notification();
-            mOutNoti.icon = android.R.drawable.stat_sys_upload_done;
+            Notification outNoti = new Notification();
+            outNoti.icon = android.R.drawable.stat_sys_upload_done;
             title = mContext.getString(R.string.outbound_noti_title);
             caption = mContext.getString(R.string.noti_caption, outboundSuccNumber,
                     outboundFailNumber);
             intent = new Intent(Constants.ACTION_OPEN_OUTBOUND_TRANSFER);
             intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
-            mOutNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
+            outNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
                     mContext, 0, intent, 0));
-            mOutNoti.when = timeStamp;
-            mNotificationMgr.notify(NOTIFICATION_ID_OUTBOUND, mOutNoti);
+            outNoti.when = timeStamp;
+            mNotificationMgr.notify(NOTIFICATION_ID_OUTBOUND, outNoti);
         } else {
-            if (mNotificationMgr != null && mOutNoti != null) {
+            if (mNotificationMgr != null) {
                 mNotificationMgr.cancel(NOTIFICATION_ID_OUTBOUND);
-                mOutNoti = null;
                 if (V) Log.v(TAG, "outbound notification was removed.");
             }
         }
@@ -393,21 +388,20 @@ class BluetoothOppNotification {
         inboundNum = inboundSuccNumber + inboundFailNumber;
         // create the inbound notification
         if (inboundNum > 0) {
-            mInNoti = new Notification();
-            mInNoti.icon = android.R.drawable.stat_sys_download_done;
+            Notification inNoti = new Notification();
+            inNoti.icon = android.R.drawable.stat_sys_download_done;
             title = mContext.getString(R.string.inbound_noti_title);
             caption = mContext.getString(R.string.noti_caption, inboundSuccNumber,
                     inboundFailNumber);
             intent = new Intent(Constants.ACTION_OPEN_INBOUND_TRANSFER);
             intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
-            mInNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
+            inNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
                     mContext, 0, intent, 0));
-            mInNoti.when = timeStamp;
-            mNotificationMgr.notify(NOTIFICATION_ID_INBOUND, mInNoti);
+            inNoti.when = timeStamp;
+            mNotificationMgr.notify(NOTIFICATION_ID_INBOUND, inNoti);
         } else {
-            if (mNotificationMgr != null && mInNoti != null) {
+            if (mNotificationMgr != null) {
                 mNotificationMgr.cancel(NOTIFICATION_ID_INBOUND);
-                mInNoti = null;
                 if (V) Log.v(TAG, "inbound notification was removed.");
             }
         }
index 591d556..1f5d9d9 100644 (file)
@@ -36,6 +36,7 @@ import com.android.bluetooth.R;
 
 import android.app.Activity;
 import android.app.AlertDialog;
+import android.bluetooth.BluetoothAdapter;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.database.Cursor;
@@ -75,6 +76,9 @@ public class BluetoothOppTransferHistory extends Activity implements
 
     private int mContextMenuPosition;
 
+    /** Class to handle Notification Manager updates */
+    private BluetoothOppNotification mNotifier;
+
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -117,6 +121,8 @@ public class BluetoothOppTransferHistory extends Activity implements
             mListView.setOnCreateContextMenuListener(this);
             mListView.setOnItemClickListener(this);
         }
+
+        mNotifier = new BluetoothOppNotification(this);
     }
 
     @Override
@@ -151,12 +157,14 @@ public class BluetoothOppTransferHistory extends Activity implements
         switch (item.getItemId()) {
             case R.id.transfer_menu_open:
                 openCompleteTransfer();
+                updateNotificationWhenBtDisabled();
                 return true;
 
             case R.id.transfer_menu_clear:
                 int sessionId = mTransferCursor.getInt(mIdColumnId);
                 Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + sessionId);
                 BluetoothOppUtility.updateVisibilityToHidden(this, contentUri);
+                updateNotificationWhenBtDisabled();
                 return true;
         }
         return false;
@@ -224,6 +232,7 @@ public class BluetoothOppTransferHistory extends Activity implements
 
                 mTransferCursor.moveToNext();
             }
+            updateNotificationWhenBtDisabled();
         }
     }
 
@@ -237,6 +246,7 @@ public class BluetoothOppTransferHistory extends Activity implements
         // Open the selected item
         mTransferCursor.moveToPosition(position);
         openCompleteTransfer();
+        updateNotificationWhenBtDisabled();
     }
 
     /**
@@ -265,4 +275,17 @@ public class BluetoothOppTransferHistory extends Activity implements
             this.startActivity(in);
         }
     }
+
+    /**
+     * When Bluetooth is disabled, notification can not be updated by
+     * ContentObserver in OppService, so need update manually.
+     */
+    private void updateNotificationWhenBtDisabled() {
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        if (!adapter.isEnabled()) {
+            if (V) Log.v(TAG, "Bluetooth is not enabled, update notification manually.");
+            mNotifier.updateNotification();
+            mNotifier.finishNotification();
+        }
+    }
 }