From 1a0093367d567294eb6b3c82445cb42c305918ae Mon Sep 17 00:00:00 2001 From: Patrick Dubroy Date: Mon, 23 May 2011 16:15:09 -0700 Subject: DO NOT MERGE Dynamically determine size of customize tray. --- .../android/launcher2/CustomizeTrayTabHost.java | 43 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'src/com/android/launcher2/CustomizeTrayTabHost.java') diff --git a/src/com/android/launcher2/CustomizeTrayTabHost.java b/src/com/android/launcher2/CustomizeTrayTabHost.java index 765c41dd2..b6c55f8b7 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) { -- cgit v1.2.3