Touching the blue glow should close the system and notification panels.

Bug: 3029373
Change-Id: I96760656dcda20ab238305900f9964083a8e5273
diff --git a/packages/SystemUI/res/layout-xlarge/sysbar_panel_notifications.xml b/packages/SystemUI/res/layout-xlarge/sysbar_panel_notifications.xml
index 2671e178..80c9a49 100644
--- a/packages/SystemUI/res/layout-xlarge/sysbar_panel_notifications.xml
+++ b/packages/SystemUI/res/layout-xlarge/sysbar_panel_notifications.xml
@@ -19,7 +19,7 @@
 -->
 
 <!--    android:background="@drawable/status_bar_closed_default_background" -->
-<LinearLayout
+<com.android.systemui.statusbar.tablet.NotificationPanel
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_height="wrap_content"
     android:layout_width="match_parent"
@@ -46,4 +46,4 @@
             >
         </LinearLayout>
     </ScrollView>
-</LinearLayout>
+</com.android.systemui.statusbar.tablet.NotificationPanel>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPanel.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPanel.java
new file mode 100644
index 0000000..eee0a16
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPanel.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.tablet;
+
+import android.content.Context;
+import android.widget.LinearLayout;
+import android.util.AttributeSet;
+
+public class NotificationPanel extends LinearLayout implements StatusBarPanel {
+
+    public NotificationPanel(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public NotificationPanel(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    public boolean isInContentArea(int x, int y) {
+        final int l = getPaddingLeft();
+        final int r = getWidth() - getPaddingRight();
+        final int t = getPaddingTop();
+        final int b = getHeight() - getPaddingBottom();
+        return x >= l && x < r && y >= t && y < b;
+    }
+}
+
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/StatusBarPanel.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/StatusBarPanel.java
new file mode 100644
index 0000000..8fa01d5
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/StatusBarPanel.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.tablet;
+
+public interface StatusBarPanel {
+    public boolean isInContentArea(int x, int y);
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SystemPanel.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SystemPanel.java
index 491ef1d..a0f5be6 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SystemPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SystemPanel.java
@@ -77,7 +77,7 @@
 import com.android.systemui.statusbar.*;
 import com.android.systemui.R;
 
-public class SystemPanel extends LinearLayout {
+public class SystemPanel extends LinearLayout implements StatusBarPanel {
     private static final String TAG = "SystemPanel";
     private static final boolean DEBUG = TabletStatusBarService.DEBUG;
     private static final boolean DEBUG_SIGNAL = false;
@@ -122,6 +122,14 @@
     boolean mDataEnabled, mDataConnected, mDataRoaming;
     int mDataLevel;
 
+    public boolean isInContentArea(int x, int y) {
+        final int l = getPaddingLeft();
+        final int r = getWidth() - getPaddingRight();
+        final int t = getPaddingTop();
+        final int b = getHeight() - getPaddingBottom();
+        return x >= l && x < r && y >= t && y < b;
+    }
+
     private BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarService.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarService.java
index de939a4..d6f5cf0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarService.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarService.java
@@ -79,7 +79,7 @@
     View mNotificationButtons;
     View mSystemInfo;
 
-    View mNotificationPanel;
+    NotificationPanel mNotificationPanel;
     SystemPanel mSystemPanel;
 
     ViewGroup mPile;
@@ -110,10 +110,11 @@
         final int barHeight= res.getDimensionPixelSize(
             com.android.internal.R.dimen.status_bar_height);
 
-        mNotificationPanel = View.inflate(this, R.layout.sysbar_panel_notifications, null);
+        mNotificationPanel = (NotificationPanel)View.inflate(this,
+                R.layout.sysbar_panel_notifications, null);
         mNotificationPanel.setVisibility(View.GONE);
         mNotificationPanel.setOnTouchListener(
-                new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PANEL));
+                new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PANEL, mNotificationPanel));
 
         mStatusBarView.setIgnoreChildren(0, mNotificationTrigger, mNotificationPanel);
 
@@ -135,7 +136,8 @@
 
         mSystemPanel = (SystemPanel) View.inflate(this, R.layout.sysbar_panel_system, null);
         mSystemPanel.setVisibility(View.GONE);
-        mSystemPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_SYSTEM_PANEL));
+        mSystemPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_SYSTEM_PANEL,
+                    mSystemPanel));
 
         mStatusBarView.setIgnoreChildren(1, mSystemInfo, mSystemPanel);
 
@@ -787,13 +789,18 @@
 
     public class TouchOutsideListener implements View.OnTouchListener {
         private int mMsg;
+        private StatusBarPanel mPanel;
 
-        public TouchOutsideListener(int msg) {
+        public TouchOutsideListener(int msg, StatusBarPanel panel) {
             mMsg = msg;
+            mPanel = panel;
         }
 
         public boolean onTouch(View v, MotionEvent ev) {
-            if (ev.getAction() == MotionEvent.ACTION_OUTSIDE) {
+            final int action = ev.getAction();
+            if (action == MotionEvent.ACTION_OUTSIDE
+                    || (action == MotionEvent.ACTION_DOWN
+                        && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) {
                 mHandler.removeMessages(mMsg);
                 mHandler.sendEmptyMessage(mMsg);
                 return true;
diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
index 7b6e2d2..2d7ee13 100644
--- a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
+++ b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
@@ -206,12 +206,16 @@
         new Test("Layout") {
             public void run()
             {
+                Notification n;
 
-                mNM.notify(1, new Notification(NotificationTestList.this,
+                n = new Notification(NotificationTestList.this,
                             R.drawable.ic_statusbar_missedcall,
                             null, System.currentTimeMillis()-(1000*60*60*24),
                             "(453) 123-2328",
-                            "", null));
+                            "", null);
+                n.flags |= Notification.FLAG_ONGOING_EVENT;
+
+                mNM.notify(1, n);
 
                 mNM.notify(2, new Notification(NotificationTestList.this,
                             R.drawable.ic_statusbar_email,