diff options
author | Patrick Dubroy <dubroy@google.com> | 2011-05-23 16:15:09 -0700 |
---|---|---|
committer | Michael Jurka <mikejurka@google.com> | 2011-05-23 20:55:01 -0700 |
commit | 1a0093367d567294eb6b3c82445cb42c305918ae (patch) | |
tree | f442e96e0cb7778797ab62c3225da43be1afafc6 /src/com/android/launcher2/CustomizePagedView.java | |
parent | e72300ee5911df4f5acaa32afda9fc04a391e2a7 (diff) | |
download | packages_apps_trebuchet-1a0093367d567294eb6b3c82445cb42c305918ae.zip packages_apps_trebuchet-1a0093367d567294eb6b3c82445cb42c305918ae.tar.gz packages_apps_trebuchet-1a0093367d567294eb6b3c82445cb42c305918ae.tar.bz2 |
DO NOT MERGE Dynamically determine size of customize tray.
Diffstat (limited to 'src/com/android/launcher2/CustomizePagedView.java')
-rw-r--r-- | src/com/android/launcher2/CustomizePagedView.java | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java index 8d867b6..406d634 100644 --- a/src/com/android/launcher2/CustomizePagedView.java +++ b/src/com/android/launcher2/CustomizePagedView.java @@ -108,6 +108,9 @@ public class CustomizePagedView extends PagedViewWithDraggableItems // The max number of wallpaper cells to take a "page" of wallpaper items private int mMaxWallpaperCellHSpan; + // The maximum number of rows in a paged view. + private int mMaxCellCountY; + // The raw sources of data for each of the different tabs of the customization page private List<AppWidgetProviderInfo> mWidgetList; private List<ResolveInfo> mShortcutList; @@ -143,7 +146,10 @@ public class CustomizePagedView extends PagedViewWithDraggableItems private int[] mDragViewOrigin = new int[2]; - private int mPageContentWidth; + private int mPageContentWidth = -1; + private int mPageContentHeight = -1; + + private AllAppsPagedView mAllAppsPagedView; public CustomizePagedView(Context context) { this(context, null, 0); @@ -162,10 +168,6 @@ public class CustomizePagedView extends PagedViewWithDraggableItems mMaxWallpaperCellHSpan = a.getInt(R.styleable.CustomizePagedView_wallpaperCellCountX, 8); mMaxWidgetsCellHSpan = a.getInt(R.styleable.CustomizePagedView_widgetCellCountX, 8); a.recycle(); - a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0); - mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 7); - mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4); - a.recycle(); mCustomizationType = CustomizationType.WidgetCustomization; mWidgetPages = new ArrayList<ArrayList<AppWidgetProviderInfo>>(); @@ -176,6 +178,8 @@ public class CustomizePagedView extends PagedViewWithDraggableItems setDragSlopeThreshold( r.getInteger(R.integer.config_customizationDrawerDragSlopeThreshold) / 100.0f); + mMaxCellCountY = r.getInteger(R.integer.customization_drawer_contents_maxCellCountY); + setVisibility(View.GONE); setSoundEffectsEnabled(false); setupWorkspaceLayout(); @@ -188,29 +192,44 @@ public class CustomizePagedView extends PagedViewWithDraggableItems } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - - final int widthSize = MeasureSpec.getSize(widthMeasureSpec); - final int heightSize = MeasureSpec.getSize(heightMeasureSpec); + protected void onMeasure(int widthSpec, int heightSpec) { + // Base the size of this control on the size of the All Apps view. + final int cellCountX = mAllAppsPagedView.getCellCountX(); + final int cellCountY = Math.min(mAllAppsPagedView.getCellCountY(), mMaxCellCountY); - 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(); + if (cellCountX != mCellCountX || cellCountY != mCellCountY) { + mCellCountX = cellCountX; + mCellCountY = cellCountY; - // Create a dummy page and set it up to find out the content width (used by our parent) + // Create a dummy page and set it up to determine our size. + // The size is based on the app shortcuts tab having the same dimensions as All Apps. PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); setupPage(layout); mPageContentWidth = layout.getContentWidth(); + mPageContentHeight = layout.getContentHeight(); mMinPageWidth = layout.getWidthBeforeFirstLayout(); } + if (mPageContentHeight > 0) { + // Lock our height to the size of the page content + final int h = mPageContentHeight + mPageLayoutPaddingTop + mPageLayoutPaddingBottom; + heightSpec = MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY); + } + super.onMeasure(widthSpec, heightSpec); + mFirstMeasure = false; + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + if (mFirstLayout) { + invalidatePageData(); + + // invalidatePageData() is what causes the child pages to be created. We need the + // children to be measured before layout, so force a new measure here. + measure(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY)); + } + super.onLayout(changed, left, top, right, bottom); + mFirstLayout = false; } public void setLauncher(Launcher launcher) { @@ -219,6 +238,10 @@ public class CustomizePagedView extends PagedViewWithDraggableItems mPackageManager = context.getPackageManager(); } + public void setAllAppsPagedView(AllAppsPagedView view) { + mAllAppsPagedView = view; + } + /** * Sets the list of applications that launcher has loaded. */ |