Allow determining # of rows/columns for All Apps and Customize at run time
diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java
index c812a46..59ba57b 100644
--- a/src/com/android/launcher2/AllAppsPagedView.java
+++ b/src/com/android/launcher2/AllAppsPagedView.java
@@ -66,6 +66,8 @@
     private final LayoutInflater mInflater;
     private boolean mAllowHardwareLayerCreation;
 
+    private boolean mFirstMeasure = true;
+
     private int mPageContentWidth;
     private boolean mHasMadeSuccessfulDrop;
 
@@ -91,11 +93,6 @@
         Resources r = context.getResources();
         setDragSlopeThreshold(
                 r.getInteger(R.integer.config_appsCustomizeDragSlopeThreshold) / 100.0f);
-
-        // Create a dummy page and set it up to find out the content width (used by our parent)
-        PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
-        setupPage(layout);
-        mPageContentWidth = layout.getContentWidth();
     }
 
     @Override
@@ -104,6 +101,31 @@
         mCenterPagesVertically = false;
     }
 
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+
+        final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
+        final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
+
+        if (mFirstMeasure) {
+            mFirstMeasure = false;
+
+            // TODO: actually calculate mCellCountX/mCellCountY as some function of
+            // widthSize and heightSize
+            //mCellCountX = ?;
+            //mCellCountY = ?;
+
+            // Since mCellCountX/mCellCountY changed, we need to update the pages
+            invalidatePageData();
+
+            // Create a dummy page and set it up to find out the content width (used by our parent)
+            PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
+            setupPage(layout);
+            mPageContentWidth = layout.getContentWidth();
+        }
+    }
+
     void allowHardwareLayerCreation() {
         // This is called after the first time we launch into All Apps. Before that point,
         // there's no need for hardware layers here since there's a hardware layer set on the
@@ -482,6 +504,11 @@
 
     @Override
     public void syncPages() {
+        if (mFirstMeasure) {
+            // We don't know our size yet, which means we haven't calculated cell count x/y;
+            // onMeasure will call us once we figure out our size
+            return;
+        }
         // ensure that we have the right number of pages (min of 1, since we have placeholders)
         int numPages = Math.max(1,
                 (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)));