diff options
author | Michael Jurka <mikejurka@google.com> | 2011-05-17 18:21:03 -0700 |
---|---|---|
committer | Michael Jurka <mikejurka@google.com> | 2011-05-18 14:24:52 -0700 |
commit | 4c6016fab10685eea750c092f1ffa3e862c85df2 (patch) | |
tree | e14cba7d3f84490aae7e3fbc0a35c18d4a795af2 | |
parent | d1d48a68409c5f0777e608f83950b41a2306f3f3 (diff) | |
download | packages_apps_trebuchet-4c6016fab10685eea750c092f1ffa3e862c85df2.zip packages_apps_trebuchet-4c6016fab10685eea750c092f1ffa3e862c85df2.tar.gz packages_apps_trebuchet-4c6016fab10685eea750c092f1ffa3e862c85df2.tar.bz2 |
Allow determining # of rows/columns for All Apps and Customize at run time
-rw-r--r-- | src/com/android/launcher2/AllAppsPagedView.java | 37 | ||||
-rw-r--r-- | src/com/android/launcher2/AllAppsTabbed.java | 26 | ||||
-rw-r--r-- | src/com/android/launcher2/CustomizePagedView.java | 33 | ||||
-rw-r--r-- | src/com/android/launcher2/CustomizeTrayTabHost.java | 29 |
4 files changed, 96 insertions, 29 deletions
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 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All private final LayoutInflater mInflater; private boolean mAllowHardwareLayerCreation; + private boolean mFirstMeasure = true; + private int mPageContentWidth; private boolean mHasMadeSuccessfulDrop; @@ -91,11 +93,6 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All 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 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All 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 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All @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))); diff --git a/src/com/android/launcher2/AllAppsTabbed.java b/src/com/android/launcher2/AllAppsTabbed.java index 96de5a7..a2f10f5 100644 --- a/src/com/android/launcher2/AllAppsTabbed.java +++ b/src/com/android/launcher2/AllAppsTabbed.java @@ -35,7 +35,6 @@ import android.widget.TabWidget; import android.widget.TextView; import java.util.ArrayList; -import java.util.Random; /** * Implements a tabbed version of AllApps2D. @@ -126,16 +125,6 @@ public class AllAppsTabbed extends TabHost implements AllAppsView, LauncherTrans } }); - // Set the width of the tab bar properly - int pageWidth = mAllApps.getPageContentWidth(); - View allAppsTabBar = (View) findViewById(R.id.all_apps_tab_bar); - if (allAppsTabBar == null) throw new Resources.NotFoundException(); - int tabWidgetPadding = 0; - final int childCount = tabWidget.getChildCount(); - if (childCount > 0) { - tabWidgetPadding += tabWidget.getChildAt(0).getPaddingLeft() * 2; - } - allAppsTabBar.getLayoutParams().width = pageWidth + tabWidgetPadding; // It needs to be INVISIBLE so that it will be measured in the layout. // Otherwise the animations is messed up when we show it for the first time. @@ -175,7 +164,20 @@ public class AllAppsTabbed extends TabHost implements AllAppsView, LauncherTrans @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { - mFirstLayout = false; + if (mFirstLayout) { + mFirstLayout = false; + // Set the width of the tab bar properly + int pageWidth = mAllApps.getPageContentWidth(); + TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs); + View allAppsTabBar = (View) findViewById(R.id.all_apps_tab_bar); + if (allAppsTabBar == null) throw new Resources.NotFoundException(); + int tabWidgetPadding = 0; + final int childCount = tabWidget.getChildCount(); + if (childCount > 0) { + tabWidgetPadding += tabWidget.getChildAt(0).getPaddingLeft() * 2; + } + allAppsTabBar.getLayoutParams().width = pageWidth + tabWidgetPadding; + } super.onLayout(changed, l, t, r, b); } diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java index b2e308d..cdae80c 100644 --- a/src/com/android/launcher2/CustomizePagedView.java +++ b/src/com/android/launcher2/CustomizePagedView.java @@ -54,6 +54,7 @@ import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.View.MeasureSpec; import android.view.animation.DecelerateInterpolator; import android.view.animation.LinearInterpolator; import android.widget.Checkable; @@ -124,6 +125,8 @@ public class CustomizePagedView extends PagedViewWithDraggableItems private final Canvas mCanvas = new Canvas(); private final LayoutInflater mInflater; + private boolean mFirstMeasure = true; + private final float mTmpFloatPos[] = new float[2]; private final float ANIMATION_SCALE = 0.5f; @@ -190,6 +193,31 @@ public class CustomizePagedView extends PagedViewWithDraggableItems 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(); + } + } + public void setLauncher(Launcher launcher) { Context context = getContext(); mLauncher = launcher; @@ -1093,6 +1121,11 @@ public class CustomizePagedView extends PagedViewWithDraggableItems @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; + } boolean enforceMinimumPagedWidths = false; boolean centerPagedViewCellLayouts = false; switch (mCustomizationType) { diff --git a/src/com/android/launcher2/CustomizeTrayTabHost.java b/src/com/android/launcher2/CustomizeTrayTabHost.java index 2c47895..ab50cf1 100644 --- a/src/com/android/launcher2/CustomizeTrayTabHost.java +++ b/src/com/android/launcher2/CustomizeTrayTabHost.java @@ -115,17 +115,6 @@ public class CustomizeTrayTabHost extends TabHost implements LauncherTransitiona } } }); - - // Set the width of the tab bar properly - int pageWidth = customizePagedView.getPageContentWidth(); - TabWidget customizeTabBar = (TabWidget) findViewById(com.android.internal.R.id.tabs); - if (customizeTabBar == null) throw new Resources.NotFoundException(); - int tabWidgetPadding = 0; - final int childCount = tabWidget.getChildCount(); - if (childCount > 0) { - tabWidgetPadding += tabWidget.getChildAt(0).getPaddingLeft() * 2; - } - customizeTabBar.getLayoutParams().width = pageWidth + tabWidgetPadding; } @Override @@ -150,7 +139,23 @@ public class CustomizeTrayTabHost extends TabHost implements LauncherTransitiona @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { - mFirstLayout = false; + if (mFirstLayout) { + mFirstLayout = false; + + final CustomizePagedView customizePagedView = + (CustomizePagedView) findViewById(R.id.customization_drawer_tab_contents); + TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs); + // Set the width of the tab bar properly + int pageWidth = customizePagedView.getPageContentWidth(); + TabWidget customizeTabBar = (TabWidget) findViewById(com.android.internal.R.id.tabs); + if (customizeTabBar == null) throw new Resources.NotFoundException(); + int tabWidgetPadding = 0; + final int childCount = tabWidget.getChildCount(); + if (childCount > 0) { + tabWidgetPadding += tabWidget.getChildAt(0).getPaddingLeft() * 2; + } + customizeTabBar.getLayoutParams().width = pageWidth + tabWidgetPadding; + } super.onLayout(changed, l, t, r, b); } |