Add expand and collapse.

Change-Id: I58ad95c59b2c46d3f25349e137d5624aefc6c6cd
diff --git a/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/CommandQueue.java b/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/CommandQueue.java
index 90f17d5..00ad77c 100644
--- a/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/CommandQueue.java
+++ b/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/CommandQueue.java
@@ -28,7 +28,8 @@
  * This class takes the functions from IStatusBar that come in on
  * binder pool threads and posts messages to get them onto the main
  * thread, and calls onto Callbacks.  It also takes care of
- * coalescing these calls so they don't stack up.
+ * coalescing these calls so they don't stack up.  For the calls
+ * are coalesced, note that they are all idempotent.
  */
 class CommandQueue extends IStatusBar.Stub {
     private static final String TAG = "StatusBar.CommandQueue";
@@ -42,6 +43,10 @@
 
     private static final int MSG_DISABLE = 0x00020000;
 
+    private static final int MSG_SET_VISIBILITY = 0x00030000;
+    private static final int OP_EXPAND = 1;
+    private static final int OP_COLLAPSE = 2;
+
     private StatusBarIconList mList;
     private Callbacks mCallbacks;
     private Handler mHandler = new H();
@@ -55,6 +60,8 @@
                 StatusBarIcon old, StatusBarIcon icon);
         public void removeIcon(String slot, int index, int viewIndex);
         public void disable(int state);
+        public void animateExpand();
+        public void animateCollapse();
     }
 
     public CommandQueue(Callbacks callbacks, StatusBarIconList list) {
@@ -85,9 +92,24 @@
         }
     }
 
+    public void animateExpand() {
+        synchronized (mList) {
+            mHandler.removeMessages(MSG_SET_VISIBILITY);
+            mHandler.obtainMessage(MSG_SET_VISIBILITY, OP_EXPAND, 0, null).sendToTarget();
+        }
+    }
+
+    public void animateCollapse() {
+        synchronized (mList) {
+            mHandler.removeMessages(MSG_SET_VISIBILITY);
+            mHandler.obtainMessage(MSG_SET_VISIBILITY, OP_COLLAPSE, 0, null).sendToTarget();
+        }
+    }
+
     private final class H extends Handler {
         public void handleMessage(Message msg) {
             final int what = msg.what & MSG_MASK;
+            Slog.d(TAG, "handleMessage what=0x" + Integer.toHexString(what) + " arg1=" + msg.arg1);
             switch (what) {
                 case MSG_ICON: {
                     final int index = msg.what & INDEX_MASK;
@@ -116,6 +138,12 @@
                 case MSG_DISABLE:
                     mCallbacks.disable(msg.arg1);
                     break;
+                case MSG_SET_VISIBILITY:
+                    if (msg.arg1 == OP_EXPAND) {
+                        mCallbacks.animateExpand();
+                    } else {
+                        mCallbacks.animateCollapse();
+                    }
             }
         }
     }
diff --git a/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/PhoneStatusBarService.java b/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/PhoneStatusBarService.java
index 6ae632b..86b6889 100644
--- a/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/PhoneStatusBarService.java
+++ b/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/PhoneStatusBarService.java
@@ -71,7 +71,7 @@
 
 
 public class PhoneStatusBarService extends StatusBarService {
-    static final String TAG = "StatusBar";
+    static final String TAG = "PhoneStatusBarService";
     static final boolean SPEW = false;
 
     public static final String ACTION_STATUSBAR_START
@@ -203,10 +203,6 @@
         super.onCreate();
     }
 
-    public void setNotificationCallbacks(NotificationCallbacks listener) {
-        mNotificationCallbacks = listener;
-    }
-
     // ================================================================================
     // Constructing the view
     // ================================================================================
@@ -365,7 +361,7 @@
             }
         }
     }
-    
+
     /**
      * All changes to the status bar and notifications funnel through here and are batched.
      */
@@ -531,7 +527,7 @@
             return;
         }
         mExpandedVisible = true;
-        panelSlightlyVisible(true);
+        visibilityChanged(true);
         
         updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
         mExpandedParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
@@ -545,7 +541,7 @@
         }
     }
     
-    void animateExpand() {
+    public void animateExpand() {
         if (SPEW) Slog.d(TAG, "Animate expand: expanded=" + mExpanded);
         if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) {
             return ;
@@ -558,7 +554,7 @@
         performFling(0, 2000.0f, true);
     }
     
-    void animateCollapse() {
+    public void animateCollapse() {
         if (SPEW) {
             Slog.d(TAG, "animateCollapse(): mExpanded=" + mExpanded
                     + " mExpandedVisible=" + mExpandedVisible
@@ -618,7 +614,7 @@
             return;
         }
         mExpandedVisible = false;
-        panelSlightlyVisible(false);
+        visibilityChanged(false);
         mExpandedParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
         mExpandedParams.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
         mExpandedDialog.getWindow().setAttributes(mExpandedParams);
@@ -1205,7 +1201,7 @@
                 // because the window itself extends below the content view.
                 mExpandedParams.y = -disph;
             }
-            panelSlightlyVisible(visible);
+            visibilityChanged(visible);
             mExpandedDialog.getWindow().setAttributes(mExpandedParams);
         }
 
@@ -1237,16 +1233,13 @@
      * this is what he wants. (see bug 1131461)
      */
     private boolean mPanelSlightlyVisible;
-    void panelSlightlyVisible(boolean visible) {
-        if (true) {
-            // XXX
-            return;
-        }
+    void visibilityChanged(boolean visible) {
         if (mPanelSlightlyVisible != visible) {
             mPanelSlightlyVisible = visible;
-            if (visible) {
-                // tell the notification manager to turn off the lights.
-                mNotificationCallbacks.onPanelRevealed();
+            try {
+                mBarService.visibilityChanged(visible);
+            } catch (RemoteException ex) {
+                // Won't fail unless the world has ended.
             }
         }
     }
@@ -1260,7 +1253,7 @@
         if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) {
             if ((net & StatusBarManager.DISABLE_EXPAND) != 0) {
                 Slog.d(TAG, "DISABLE_EXPAND: yes");
-                //animateCollapse();
+                animateCollapse();
             }
         }
         if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
@@ -1288,7 +1281,7 @@
     private View.OnClickListener mClearButtonListener = new View.OnClickListener() {
         public void onClick(View v) {
             mNotificationCallbacks.onClearAll();
-            //addPendingOp(OP_EXPAND, null, false);
+            animateCollapse();
         }
     };