DO NOT MERGE Dynamically determine size of customize tray.
diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java
index b4eaa49..01cf920 100644
--- a/src/com/android/launcher2/AllAppsPagedView.java
+++ b/src/com/android/launcher2/AllAppsPagedView.java
@@ -70,6 +70,8 @@
     private int mLastMeasureWidth = -1;
     private int mLastMeasureHeight = -1;
 
+    private int mMaxCellCountY;
+
     public AllAppsPagedView(Context context) {
         this(context, null);
     }
@@ -87,7 +89,7 @@
         a.recycle();
         setSoundEffectsEnabled(false);
 
-        Resources r = context.getResources();
+        final Resources r = context.getResources();
         setDragSlopeThreshold(
                 r.getInteger(R.integer.config_allAppsDrawerDragSlopeThreshold) / 100.0f);
 
@@ -95,6 +97,7 @@
         PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
         setupPage(layout);
         mPageContentWidth = layout.getContentWidth();
+        mMaxCellCountY = r.getInteger(R.integer.all_apps_view_maxCellCountY);
     }
 
     @Override
@@ -174,7 +177,19 @@
         availableHeight -= mPageLayoutPaddingTop + mPageLayoutPaddingBottom;
         availableHeight -= cellHeight; // Assume at least one row
         availableHeight -= screenHeight * 0.16f;
-        return (1 + availableHeight / (cellHeight + mPageLayoutHeightGap));
+        if (availableHeight > 0) {
+            return Math.min(mMaxCellCountY,
+                    1 + availableHeight / (cellHeight + mPageLayoutHeightGap));
+        }
+        return 0;
+    }
+
+    int getCellCountX() {
+        return mCellCountX;
+    }
+
+    int getCellCountY() {
+        return mCellCountY;
     }
 
     void allowHardwareLayerCreation() {