Merge into jb-mr1-dev

Change-Id: Iaee05ce2bc5103c46fe9a148ad166f694c246c2f
diff --git a/packages/SystemUI/res/values-sw600dp/dimens.xml b/packages/SystemUI/res/values-sw600dp/dimens.xml
index b6faff3..a6875718 100644
--- a/packages/SystemUI/res/values-sw600dp/dimens.xml
+++ b/packages/SystemUI/res/values-sw600dp/dimens.xml
@@ -40,4 +40,8 @@
     <!-- Size of application thumbnail -->
     <dimen name="status_bar_recents_thumbnail_width">200dp</dimen>
     <dimen name="status_bar_recents_thumbnail_height">177dp</dimen>
+
+    <!-- On tablet-sized devices, we allocate the rightmost third(ish) of the draggable status bar
+         to quick settings. -->
+    <item type="dimen" name="settings_panel_dragzone_fraction">35%</item>
 </resources>
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index e93e857..13cda3a 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -166,8 +166,13 @@
     <integer name="notification_panel_layout_gravity">0x37</integer>
     <integer name="settings_panel_layout_gravity">0x37</integer>
 
-    <!-- Quick settings panels minimum fling open target width. -->
-    <dimen name="settings_panel_fling_gutter">90dp</dimen>
+    <!-- Fraction of the status bar that, when dragged, will produce the quick settings panel
+         instead of the notification panel. See also @dimen/settings_panel_dragzone_min.
+         If zero, the settings panel will not be directly draggable from the status bar. -->
+    <item type="dimen" name="settings_panel_dragzone_fraction">0%</item>
+
+    <!-- Quick settings dragzone, if used, should be at least this big (may be zero). -->
+    <dimen name="settings_panel_dragzone_min">100dp</dimen>
 
     <!-- Height of the carrier/wifi name label -->
     <dimen name="carrier_label_height">24dp</dimen>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
index 95b618a..6517e7c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
@@ -21,6 +21,7 @@
 import android.content.Context;
 import android.content.res.Configuration;
 import android.content.res.Resources;
+import android.content.res.Resources.NotFoundException;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Rect;
@@ -46,8 +47,9 @@
 
     PhoneStatusBar mBar;
     int mScrimColor;
-    float mMinFlingGutter;
-    float mNotificationWidth;
+    float mSettingsPanelDragzoneFrac;
+    float mSettingsPanelDragzoneMin;
+
     boolean mFullWidthNotifications;
     PanelView mFadingPanel = null;
     PanelView mNotificationPanel, mSettingsPanel;
@@ -64,13 +66,14 @@
     public void onAttachedToWindow() {
         Resources res = getContext().getResources();
         mScrimColor = res.getColor(R.color.notification_panel_scrim_color);
-        mMinFlingGutter = res.getDimension(R.dimen.settings_panel_fling_gutter);
-        mFullWidthNotifications = false;
+        mSettingsPanelDragzoneMin = res.getDimension(R.dimen.settings_panel_dragzone_min);
         try {
-            mNotificationWidth = res.getDimension(R.dimen.notification_panel_width);
-        } catch (Resources.NotFoundException ex) {
-            mFullWidthNotifications = true;
+            mSettingsPanelDragzoneFrac = res.getFraction(R.dimen.settings_panel_dragzone_fraction, 1, 1);
+        } catch (NotFoundException ex) {
+            mSettingsPanelDragzoneFrac = 0f;
         }
+
+        mFullWidthNotifications = mSettingsPanelDragzoneFrac <= 0f;
     }
 
     @Override
@@ -105,19 +108,30 @@
 
     @Override
     public PanelView selectPanelForTouchX(float x) {
-        // We split the status bar into thirds: the left 2/3 are for notifications, and the 
+        if (mFullWidthNotifications) {
+            if (DEBUG) {
+                Slog.v(TAG, "notif frac=" + mNotificationPanel.getExpandedFraction());
+            }
+            return (mNotificationPanel.getExpandedFraction() == 1.0f)
+                ? mSettingsPanel : mNotificationPanel;
+        }
+
+        // We split the status bar into thirds: the left 2/3 are for notifications, and the
         // right 1/3 for quick settings. If you pull the status bar down a second time you'll
         // toggle panels no matter where you pull it down.
+
         final float w = (float) getMeasuredWidth();
-        final float gutter = w - mNotificationWidth;
-        final boolean useGutter = !mFullWidthNotifications && gutter > mMinFlingGutter;
-        final float threshold = 1.0f - (gutter / w);
-        final float f = x / w;
-        if ((useGutter && f > threshold && mSettingsPanel.getExpandedFraction() != 1.0f) ||
-            mNotificationPanel.getExpandedFraction() == 1.0f) {
-            return mSettingsPanel;
+        float region = (w * mSettingsPanelDragzoneFrac);
+
+        if (DEBUG) {
+            Slog.v(TAG, String.format(
+                "w=%.1f frac=%.3f region=%.1f min=%.1f x=%.1f w-x=%.1f",
+                w, mSettingsPanelDragzoneFrac, region, mSettingsPanelDragzoneMin, x, (w-x)));
         }
-        return mNotificationPanel;
+
+        if (region < mSettingsPanelDragzoneMin) region = mSettingsPanelDragzoneMin;
+
+        return (w - x < region) ? mSettingsPanel : mNotificationPanel;
     }
 
     @Override
@@ -159,7 +173,7 @@
             Slog.v(TAG, "panelExpansionChanged: f=" + frac);
         }
 
-        if (mFadingPanel == pv 
+        if (mFadingPanel == pv
                 && mScrimColor != 0 && ActivityManager.isHighEndGfx()) {
             // woo, special effects
             final float k = (float)(1f-0.5f*(1f-Math.cos(3.14159f * Math.pow(1f-frac, 2.2f))));