From 1a0093367d567294eb6b3c82445cb42c305918ae Mon Sep 17 00:00:00 2001 From: Patrick Dubroy Date: Mon, 23 May 2011 16:15:09 -0700 Subject: [PATCH] DO NOT MERGE Dynamically determine size of customize tray. --- res/layout-large/customization_drawer.xml | 13 ++-- res/layout-large/launcher.xml | 2 +- res/values-large-land/dimens.xml | 14 ++-- res/values-large-port/dimens.xml | 12 ++-- res/values-large/dimens.xml | 10 +++ .../android/launcher2/AllAppsPagedView.java | 19 +++++- .../android/launcher2/CustomizePagedView.java | 65 +++++++++++++------ .../launcher2/CustomizeTrayTabHost.java | 43 +++++++++--- src/com/android/launcher2/Launcher.java | 1 + .../launcher2/PagedViewCellLayout.java | 12 +++- 10 files changed, 139 insertions(+), 52 deletions(-) diff --git a/res/layout-large/customization_drawer.xml b/res/layout-large/customization_drawer.xml index a8f6ce09ea..2009117b95 100644 --- a/res/layout-large/customization_drawer.xml +++ b/res/layout-large/customization_drawer.xml @@ -40,15 +40,12 @@ launcher:wallpaperCellSpanX="@integer/customization_drawer_contents_wallpaperCellSpanX" launcher:wallpaperCellCountX="@integer/customization_drawer_contents_wallpaperCellCountX" launcher:widgetCellCountX="@integer/customization_drawer_contents_widgetCellCountX" - launcher:cellCountX="@integer/customization_drawer_contents_cellCountX" - launcher:cellCountY="@integer/customization_drawer_contents_cellCountY" launcher:pageLayoutWidthGap="@dimen/customization_drawer_contents_pageLayoutWidthGap" - launcher:pageLayoutHeightGap="12dp" - launcher:pageLayoutPaddingTop="40dp" - launcher:pageLayoutPaddingBottom="25dp" - launcher:pageLayoutPaddingLeft="20dp" - launcher:pageLayoutPaddingRight="20dp" - launcher:pageLayoutMaxHeight="@dimen/customization_drawer_content_height" /> + launcher:pageLayoutHeightGap="@dimen/customization_drawer_contents_pageLayoutHeightGap" + launcher:pageLayoutPaddingTop="@dimen/customization_drawer_contents_pageLayoutPaddingTop" + launcher:pageLayoutPaddingBottom="@dimen/customization_drawer_contents_pageLayoutPaddingBottom" + launcher:pageLayoutPaddingLeft="@dimen/customization_drawer_contents_pageLayoutPaddingLeft" + launcher:pageLayoutPaddingRight="@dimen/customization_drawer_contents_pageLayoutPaddingRight" /> \ No newline at end of file diff --git a/res/layout-large/launcher.xml b/res/layout-large/launcher.xml index 25ef36328e..f95dd4e97d 100644 --- a/res/layout-large/launcher.xml +++ b/res/layout-large/launcher.xml @@ -42,6 +42,6 @@ diff --git a/res/values-large-land/dimens.xml b/res/values-large-land/dimens.xml index 0f7e0eddfc..eeb16f4d42 100644 --- a/res/values-large-land/dimens.xml +++ b/res/values-large-land/dimens.xml @@ -19,9 +19,6 @@ or right while you're dragging. --> 100dip - 480dp - 420dp - 36dp 6dp 20dp @@ -29,10 +26,15 @@ 40dp 40dp + + 32dp + 12dp + 20dp + 20dp + 40dp + 40dp + 3 12 14 - 8 - 3 - 32dp \ No newline at end of file diff --git a/res/values-large-port/dimens.xml b/res/values-large-port/dimens.xml index 2ea9e38758..89f86053e6 100644 --- a/res/values-large-port/dimens.xml +++ b/res/values-large-port/dimens.xml @@ -19,9 +19,6 @@ or right while you're dragging. --> 40dp - 800dp - 420dp - 36dp 36dp 25dp @@ -32,7 +29,12 @@ 3 9 9 - 5 - 3 + + 36dp + 12dp + 25dp + 25dp + 20dp + 20dp \ No newline at end of file diff --git a/res/values-large/dimens.xml b/res/values-large/dimens.xml index 0c0d60e24c..7bc8ec0fad 100644 --- a/res/values-large/dimens.xml +++ b/res/values-large/dimens.xml @@ -82,4 +82,14 @@ 0dp + + + 3 + + + 65 + + + 6 diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java index b4eaa49498..01cf9202f6 100644 --- a/src/com/android/launcher2/AllAppsPagedView.java +++ b/src/com/android/launcher2/AllAppsPagedView.java @@ -70,6 +70,8 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All private int mLastMeasureWidth = -1; private int mLastMeasureHeight = -1; + private int mMaxCellCountY; + public AllAppsPagedView(Context context) { this(context, null); } @@ -87,7 +89,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All 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 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); setupPage(layout); mPageContentWidth = layout.getContentWidth(); + mMaxCellCountY = r.getInteger(R.integer.all_apps_view_maxCellCountY); } @Override @@ -174,7 +177,19 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All 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() { diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java index 8d867b6620..406d634bbf 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 mWidgetList; private List 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>(); @@ -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); + 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); - final int widthSize = MeasureSpec.getSize(widthMeasureSpec); - final int heightSize = MeasureSpec.getSize(heightMeasureSpec); + if (cellCountX != mCellCountX || cellCountY != mCellCountY) { + mCellCountX = cellCountX; + mCellCountY = cellCountY; - 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) + // 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. */ diff --git a/src/com/android/launcher2/CustomizeTrayTabHost.java b/src/com/android/launcher2/CustomizeTrayTabHost.java index 765c41dd2d..b6c55f8b76 100644 --- a/src/com/android/launcher2/CustomizeTrayTabHost.java +++ b/src/com/android/launcher2/CustomizeTrayTabHost.java @@ -41,9 +41,14 @@ public class CustomizeTrayTabHost extends TabHost implements LauncherTransitiona private boolean mFirstLayout = true; + // How much of the vertical space this control should attempt to fill + private float mVerticalFillPercentage; + private final LayoutInflater mInflater; private Context mContext; + private CustomizePagedView mCustomizePagedView; + public CustomizeTrayTabHost(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; @@ -52,15 +57,17 @@ public class CustomizeTrayTabHost extends TabHost implements LauncherTransitiona @Override protected void onFinishInflate() { + final Resources res = getResources(); + setup(); - final CustomizePagedView customizePagedView = + mCustomizePagedView = (CustomizePagedView) findViewById(R.id.customization_drawer_tab_contents); // Configure tabs TabContentFactory contentFactory = new TabContentFactory() { public View createTabContent(String tag) { - return customizePagedView; + return mCustomizePagedView; } }; @@ -82,26 +89,30 @@ public class CustomizeTrayTabHost extends TabHost implements LauncherTransitiona tabView.setText(mContext.getString(R.string.shortcuts_tab_label)); addTab(newTabSpec(SHORTCUTS_TAG) .setIndicator(tabView).setContent(contentFactory)); + + mVerticalFillPercentage = + res.getInteger(R.integer.customization_drawer_verticalFillPercentage) / 100f; + setOnTabChangedListener(new OnTabChangeListener() { public void onTabChanged(String tabId) { final CustomizePagedView.CustomizationType newType = getCustomizeFilterForTabTag(tabId); - if (newType != customizePagedView.getCustomizationFilter()) { + if (newType != mCustomizePagedView.getCustomizationFilter()) { // animate the changing of the tab content by fading pages in and out final Resources res = getResources(); final int duration = res.getInteger(R.integer.config_tabTransitionTime); - final float alpha = customizePagedView.getAlpha(); - ValueAnimator alphaAnim = ObjectAnimator.ofFloat(customizePagedView, + final float alpha = mCustomizePagedView.getAlpha(); + ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mCustomizePagedView, "alpha", alpha, 0.0f); alphaAnim.setDuration(duration); alphaAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { - customizePagedView.setCustomizationFilter(newType); + mCustomizePagedView.setCustomizationFilter(newType); - final float alpha = customizePagedView.getAlpha(); + final float alpha = mCustomizePagedView.getAlpha(); ValueAnimator alphaAnim = ObjectAnimator.ofFloat( - customizePagedView, "alpha", alpha, 1.0f); + mCustomizePagedView, "alpha", alpha, 1.0f); alphaAnim.setDuration(duration); alphaAnim.start(); } @@ -132,6 +143,22 @@ public class CustomizeTrayTabHost extends TabHost implements LauncherTransitiona } } + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + // If there's extra room, try to grow to fill it + if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) { + final int availableHeight = MeasureSpec.getSize(heightMeasureSpec); + final int finalHeight = Math.max(getMeasuredHeight(), + (int) (availableHeight * mVerticalFillPercentage)); + + // Measure a second time with EXACTLY so that we get sized correctly + heightMeasureSpec = MeasureSpec.makeMeasureSpec(finalHeight, MeasureSpec.EXACTLY); + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + } + @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { if (mFirstLayout) { diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index b7f04f7756..1d48407728 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -930,6 +930,7 @@ public final class Launcher extends Activity if (mCustomizePagedView != null) { mCustomizePagedView.setLauncher(this); mCustomizePagedView.setDragController(dragController); + mCustomizePagedView.setAllAppsPagedView(mAllAppsPagedView); } else { ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left); hotseatLeft.setContentDescription(mHotseatLabels[0]); diff --git a/src/com/android/launcher2/PagedViewCellLayout.java b/src/com/android/launcher2/PagedViewCellLayout.java index 655a395e44..1ba5c053b4 100644 --- a/src/com/android/launcher2/PagedViewCellLayout.java +++ b/src/com/android/launcher2/PagedViewCellLayout.java @@ -259,8 +259,18 @@ public class PagedViewCellLayout extends ViewGroup implements Page { return getWidthBeforeFirstLayout() - (mCellWidth - Utilities.getIconContentSize()); } + int getContentHeight() { + if (mCellCountY > 0) { + return mCellCountY * mCellHeight + (mCellCountY - 1) * Math.max(0, mHeightGap); + } + return 0; + } + int getWidthBeforeFirstLayout() { - return mCellCountX * mCellWidth + (mCellCountX - 1) * mWidthGap; + if (mCellCountX > 0) { + return mCellCountX * mCellWidth + (mCellCountX - 1) * Math.max(0, mWidthGap); + } + return 0; } @Override