Allow determining # of rows/columns for All Apps and Customize at run time
DO NOT MERGE
Change-Id: I9ba0add8f2b2ffb324468768ad058c8426db6894
diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java
index 87d255e..522f7d7 100644
--- a/src/com/android/launcher2/AllAppsPagedView.java
+++ b/src/com/android/launcher2/AllAppsPagedView.java
@@ -65,6 +65,8 @@
private final LayoutInflater mInflater;
private boolean mAllowHardwareLayerCreation;
+ private boolean mFirstMeasure = true;
+
private int mPageContentWidth;
public AllAppsPagedView(Context context) {
@@ -102,6 +104,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
@@ -459,6 +486,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)));