diff options
author | Michael Jurka <mikejurka@google.com> | 2011-02-23 11:48:32 -0800 |
---|---|---|
committer | Michael Jurka <mikejurka@google.com> | 2011-05-13 14:35:47 -0700 |
commit | 12ac0d60cce75fc002da43ef20290613f069a85f (patch) | |
tree | c85de9bd655e7584f8ab3bf7ca92f43f47daf2f5 | |
parent | 2701ec91e15ff1fa415ec051e46f1f32e3cd53bb (diff) | |
download | android_packages_apps_Trebuchet-12ac0d60cce75fc002da43ef20290613f069a85f.tar.gz android_packages_apps_Trebuchet-12ac0d60cce75fc002da43ef20290613f069a85f.tar.bz2 android_packages_apps_Trebuchet-12ac0d60cce75fc002da43ef20290613f069a85f.zip |
Setting tab bar widths automatically
- will make launcher adapt better to different screen sizes
- also, moved customization tray tab setup code from Launcher to CustomizeTrayTabHost
-rw-r--r-- | res/layout-xlarge-land/customization_drawer_tab_contents.xml | 32 | ||||
-rw-r--r-- | res/layout-xlarge-port/customization_drawer_tab_contents.xml | 32 | ||||
-rw-r--r-- | res/layout-xlarge/all_apps_tabbed.xml | 5 | ||||
-rw-r--r-- | res/layout-xlarge/customization_drawer.xml | 25 | ||||
-rw-r--r-- | res/values-xlarge-land/dimens.xml | 8 | ||||
-rw-r--r-- | res/values-xlarge-port/dimens.xml | 8 | ||||
-rw-r--r-- | res/values-xlarge/dimens.xml | 3 | ||||
-rw-r--r-- | src/com/android/launcher2/AllAppsPagedView.java | 23 | ||||
-rw-r--r-- | src/com/android/launcher2/AllAppsTabbed.java | 15 | ||||
-rw-r--r-- | src/com/android/launcher2/CustomizePagedView.java | 11 | ||||
-rw-r--r-- | src/com/android/launcher2/CustomizeTrayTabHost.java | 112 | ||||
-rw-r--r-- | src/com/android/launcher2/Launcher.java | 93 | ||||
-rw-r--r-- | src/com/android/launcher2/PagedViewCellLayout.java | 20 | ||||
-rw-r--r-- | src/com/android/launcher2/Utilities.java | 8 |
14 files changed, 216 insertions, 179 deletions
diff --git a/res/layout-xlarge-land/customization_drawer_tab_contents.xml b/res/layout-xlarge-land/customization_drawer_tab_contents.xml deleted file mode 100644 index 50e7b6621..000000000 --- a/res/layout-xlarge-land/customization_drawer_tab_contents.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2010 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<com.android.launcher2.CustomizePagedView - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher" - - android:layout_width="match_parent" - android:layout_height="match_parent" - launcher:wallpaperCellSpanX="3" - launcher:wallpaperCellCountX="12" - launcher:widgetCellCountX="14" - launcher:cellCountX="8" - launcher:cellCountY="3" - launcher:pageLayoutWidthGap="32dp" - launcher:pageLayoutHeightGap="12dp" - launcher:pageLayoutPaddingTop="40dp" - launcher:pageLayoutPaddingBottom="25dp" - launcher:pageLayoutPaddingLeft="20dp" - launcher:pageLayoutPaddingRight="20dp" />
\ No newline at end of file diff --git a/res/layout-xlarge-port/customization_drawer_tab_contents.xml b/res/layout-xlarge-port/customization_drawer_tab_contents.xml deleted file mode 100644 index 0381be0aa..000000000 --- a/res/layout-xlarge-port/customization_drawer_tab_contents.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2010 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<com.android.launcher2.CustomizePagedView - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher" - - android:layout_width="match_parent" - android:layout_height="match_parent" - launcher:wallpaperCellSpanX="3" - launcher:wallpaperCellCountX="9" - launcher:widgetCellCountX="9" - launcher:cellCountX="5" - launcher:cellCountY="3" - launcher:pageLayoutWidthGap="36dp" - launcher:pageLayoutHeightGap="12dp" - launcher:pageLayoutPaddingTop="40dp" - launcher:pageLayoutPaddingBottom="25dp" - launcher:pageLayoutPaddingLeft="20dp" - launcher:pageLayoutPaddingRight="20dp" /> diff --git a/res/layout-xlarge/all_apps_tabbed.xml b/res/layout-xlarge/all_apps_tabbed.xml index 2710b3214..993733821 100644 --- a/res/layout-xlarge/all_apps_tabbed.xml +++ b/res/layout-xlarge/all_apps_tabbed.xml @@ -24,8 +24,11 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> + <!-- The layout_width of this RelativeLayout gets overwritten in + AllAppsTabbed.onFinishInflate --> <RelativeLayout - android:layout_width="@dimen/all_apps_tabbed_width" + android:id="@+id/all_apps_tab_bar" + android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:background="@drawable/tab_unselected_holo"> diff --git a/res/layout-xlarge/customization_drawer.xml b/res/layout-xlarge/customization_drawer.xml index dd1234c02..98fc9d963 100644 --- a/res/layout-xlarge/customization_drawer.xml +++ b/res/layout-xlarge/customization_drawer.xml @@ -13,14 +13,18 @@ See the License for the specific language governing permissions and limitations under the License. --> -<TabHost xmlns:android="http://schemas.android.com/apk/res/android"> +<com.android.launcher2.CustomizeTrayTabHost + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> + <!-- The layout_width of this RelativeLayout gets overwritten in + CustomizeTrayTabHost.onFinishInflate --> <TabWidget android:id="@android:id/tabs" - android:layout_width="@dimen/customization_drawer_tab_widget_width" + android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:background="@drawable/tab_unselected_holo" @@ -29,6 +33,21 @@ android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="@dimen/customization_drawer_content_height"> + <com.android.launcher2.CustomizePagedView + android:id="@+id/customization_drawer_tab_contents" + android:layout_width="match_parent" + android:layout_height="match_parent" + 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" /> </FrameLayout> </LinearLayout> -</TabHost>
\ No newline at end of file +</com.android.launcher2.CustomizeTrayTabHost>
\ No newline at end of file diff --git a/res/values-xlarge-land/dimens.xml b/res/values-xlarge-land/dimens.xml index 27db522dc..b44a94a0d 100644 --- a/res/values-xlarge-land/dimens.xml +++ b/res/values-xlarge-land/dimens.xml @@ -30,7 +30,6 @@ <dimen name="customization_drawer_content_min_width">952dp</dimen> <dimen name="customization_drawer_tab_widget_width">952dp</dimen> - <dimen name="all_apps_tabbed_width">952dp</dimen> <integer name="all_apps_view_cellCountX">7</integer> <integer name="all_apps_view_cellCountY">5</integer> <dimen name="all_apps_view_pageLayoutWidthGap">36dp</dimen> @@ -39,4 +38,11 @@ <dimen name="all_apps_view_pageLayoutPaddingBottom">14dp</dimen> <dimen name="all_apps_view_pageLayoutPaddingLeft">40dp</dimen> <dimen name="all_apps_view_pageLayoutPaddingRight">40dp</dimen> + + <integer name="customization_drawer_contents_wallpaperCellSpanX">3</integer> + <integer name="customization_drawer_contents_wallpaperCellCountX">12</integer> + <integer name="customization_drawer_contents_widgetCellCountX">14</integer> + <integer name="customization_drawer_contents_cellCountX">8</integer> + <integer name="customization_drawer_contents_cellCountY">3</integer> + <dimen name="customization_drawer_contents_pageLayoutWidthGap">32dp</dimen> </resources>
\ No newline at end of file diff --git a/res/values-xlarge-port/dimens.xml b/res/values-xlarge-port/dimens.xml index 72f6d8aa2..bb410b199 100644 --- a/res/values-xlarge-port/dimens.xml +++ b/res/values-xlarge-port/dimens.xml @@ -30,7 +30,6 @@ <dimen name="customization_drawer_content_min_width">640dp</dimen> <dimen name="customization_drawer_tab_widget_width">700dp</dimen> - <dimen name="all_apps_tabbed_width">700dp</dimen> <integer name="all_apps_view_cellCountX">5</integer> <integer name="all_apps_view_cellCountY">7</integer> <dimen name="all_apps_view_pageLayoutWidthGap">36dp</dimen> @@ -39,4 +38,11 @@ <dimen name="all_apps_view_pageLayoutPaddingBottom">10dp</dimen> <dimen name="all_apps_view_pageLayoutPaddingLeft">20dp</dimen> <dimen name="all_apps_view_pageLayoutPaddingRight">20dp</dimen> + + <integer name="customization_drawer_contents_wallpaperCellSpanX">3</integer> + <integer name="customization_drawer_contents_wallpaperCellCountX">9</integer> + <integer name="customization_drawer_contents_widgetCellCountX">9</integer> + <integer name="customization_drawer_contents_cellCountX">5</integer> + <integer name="customization_drawer_contents_cellCountY">3</integer> + <dimen name="customization_drawer_contents_pageLayoutWidthGap">36dp</dimen> </resources>
\ No newline at end of file diff --git a/res/values-xlarge/dimens.xml b/res/values-xlarge/dimens.xml index 421c9e389..2b9769716 100644 --- a/res/values-xlarge/dimens.xml +++ b/res/values-xlarge/dimens.xml @@ -28,6 +28,9 @@ <!-- Size of icons in workspace --> <dimen name="app_icon_size">72dp</dimen> + <!-- Size of content of icons in workspace, as specified by the android icon guidelines --> + <dimen name="app_icon_content_size">60dp</dimen> + <!-- extra horizontal spacing between mini screen thumbnails ie. in all apps and in customization mode --> <dimen name="smallScreenExtraSpacing">0dip</dimen> diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java index b9b38c3d6..87d255e60 100644 --- a/src/com/android/launcher2/AllAppsPagedView.java +++ b/src/com/android/launcher2/AllAppsPagedView.java @@ -65,6 +65,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All private final LayoutInflater mInflater; private boolean mAllowHardwareLayerCreation; + private int mPageContentWidth; public AllAppsPagedView(Context context) { this(context, null); @@ -88,6 +89,11 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All Resources r = context.getResources(); setDragSlopeThreshold( r.getInteger(R.integer.config_allAppsDrawerDragSlopeThreshold) / 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 @@ -318,6 +324,10 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All mLauncher.unlockScreenOrientation(); } + int getPageContentWidth() { + return mPageContentWidth; + } + @Override public boolean isVisible() { return mZoom > 0.001f; @@ -440,6 +450,13 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All // do nothing? } + private void setupPage(PagedViewCellLayout layout) { + layout.setCellCount(mCellCountX, mCellCountY); + layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, mPageLayoutPaddingRight, + mPageLayoutPaddingBottom); + layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap); + } + @Override public void syncPages() { // ensure that we have the right number of pages (min of 1, since we have placeholders) @@ -449,7 +466,6 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All // remove any extra pages after the "last" page int extraPageDiff = curNumPages - numPages; for (int i = 0; i < extraPageDiff; ++i) { - PagedViewCellLayout page = (PagedViewCellLayout) getChildAt(numPages); removeViewAt(numPages); } // add any necessary pages @@ -458,10 +474,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All if (mAllowHardwareLayerCreation) { layout.allowHardwareLayerCreation(); } - layout.setCellCount(mCellCountX, mCellCountY); - layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, - mPageLayoutPaddingRight, mPageLayoutPaddingBottom); - layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap); + setupPage(layout); addView(layout); } diff --git a/src/com/android/launcher2/AllAppsTabbed.java b/src/com/android/launcher2/AllAppsTabbed.java index 0dd56acff..ee7bfc056 100644 --- a/src/com/android/launcher2/AllAppsTabbed.java +++ b/src/com/android/launcher2/AllAppsTabbed.java @@ -29,12 +29,9 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; -import android.view.ViewGroup; import android.widget.TabHost; import android.widget.TabWidget; import android.widget.TextView; -import android.widget.TabHost.OnTabChangeListener; -import android.widget.TabHost.TabContentFactory; import java.util.ArrayList; @@ -82,6 +79,7 @@ public class AllAppsTabbed extends TabHost implements AllAppsView, LauncherTrans } }; + // Create the tabs and wire them up properly TextView tabView; TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs); tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); @@ -119,6 +117,17 @@ 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. setVisibility(INVISIBLE); diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java index 5c61b0b4a..36a638bc5 100644 --- a/src/com/android/launcher2/CustomizePagedView.java +++ b/src/com/android/launcher2/CustomizePagedView.java @@ -140,6 +140,8 @@ public class CustomizePagedView extends PagedViewWithDraggableItems private int[] mDragViewOrigin = new int[2]; + private int mPageContentWidth; + public CustomizePagedView(Context context) { this(context, null, 0); } @@ -172,6 +174,11 @@ public class CustomizePagedView extends PagedViewWithDraggableItems r.getInteger(R.integer.config_customizationDrawerDragSlopeThreshold) / 100.0f); mMinPageWidth = r.getDimensionPixelSize(R.dimen.customization_drawer_content_min_width); + // 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(); + setVisibility(View.GONE); setSoundEffectsEnabled(false); setupWorkspaceLayout(); @@ -1161,6 +1168,10 @@ public class CustomizePagedView extends PagedViewWithDraggableItems } } + int getPageContentWidth() { + return mPageContentWidth; + } + @Override protected int getAssociatedLowerPageBound(int page) { return 0; diff --git a/src/com/android/launcher2/CustomizeTrayTabHost.java b/src/com/android/launcher2/CustomizeTrayTabHost.java index 76cfc84e8..3e0402509 100644 --- a/src/com/android/launcher2/CustomizeTrayTabHost.java +++ b/src/com/android/launcher2/CustomizeTrayTabHost.java @@ -16,20 +16,111 @@ package com.android.launcher2; +import com.android.launcher.R; +import com.android.launcher2.CustomizePagedView.CustomizationType; + import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.ObjectAnimator; +import android.animation.ValueAnimator; import android.content.Context; +import android.content.res.Resources; import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; import android.widget.TabHost; +import android.widget.TabWidget; +import android.widget.TextView; + +public class CustomizeTrayTabHost extends TabHost implements LauncherTransitionable { + // tags for the customization tabs + private static final String WIDGETS_TAG = "widgets"; + private static final String APPLICATIONS_TAG = "applications"; + private static final String SHORTCUTS_TAG = "shortcuts"; + private static final String WALLPAPERS_TAG = "wallpapers"; -public class CustomizeTrayTabHost extends TabHost implements LauncherTransitionable { private boolean mFirstLayout = true; - public CustomizeTrayTabHost(Context context) { - super(context); - } + private final LayoutInflater mInflater; + private Context mContext; public CustomizeTrayTabHost(Context context, AttributeSet attrs) { super(context, attrs); + mContext = context; + mInflater = LayoutInflater.from(context); + } + + @Override + protected void onFinishInflate() { + setup(); + + final CustomizePagedView customizePagedView = + (CustomizePagedView) findViewById(R.id.customization_drawer_tab_contents); + + // Configure tabs + TabContentFactory contentFactory = new TabContentFactory() { + public View createTabContent(String tag) { + return customizePagedView; + } + }; + + TextView tabView; + TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs); + + tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); + tabView.setText(mContext.getString(R.string.widgets_tab_label)); + addTab(newTabSpec(WIDGETS_TAG).setIndicator(tabView).setContent(contentFactory)); + tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); + tabView.setText(mContext.getString(R.string.applications_tab_label)); + addTab(newTabSpec(APPLICATIONS_TAG) + .setIndicator(tabView).setContent(contentFactory)); + tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); + tabView.setText(mContext.getString(R.string.wallpapers_tab_label)); + addTab(newTabSpec(WALLPAPERS_TAG) + .setIndicator(tabView).setContent(contentFactory)); + tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); + tabView.setText(mContext.getString(R.string.shortcuts_tab_label)); + addTab(newTabSpec(SHORTCUTS_TAG) + .setIndicator(tabView).setContent(contentFactory)); + setOnTabChangedListener(new OnTabChangeListener() { + public void onTabChanged(String tabId) { + final CustomizePagedView.CustomizationType newType = + getCustomizeFilterForTabTag(tabId); + if (newType != customizePagedView.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, + "alpha", alpha, 0.0f); + alphaAnim.setDuration(duration); + alphaAnim.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + customizePagedView.setCustomizationFilter(newType); + + final float alpha = customizePagedView.getAlpha(); + ValueAnimator alphaAnim = ObjectAnimator.ofFloat( + customizePagedView, "alpha", alpha, 1.0f); + alphaAnim.setDuration(duration); + alphaAnim.start(); + } + }); + alphaAnim.start(); + } + } + }); + + // 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 @@ -57,4 +148,17 @@ public class CustomizeTrayTabHost extends TabHost implements LauncherTransitiona mFirstLayout = false; super.onLayout(changed, l, t, r, b); } + + CustomizationType getCustomizeFilterForTabTag(String tag) { + if (tag.equals(WIDGETS_TAG)) { + return CustomizationType.WidgetCustomization; + } else if (tag.equals(APPLICATIONS_TAG)) { + return CustomizationType.ApplicationCustomization; + } else if (tag.equals(WALLPAPERS_TAG)) { + return CustomizePagedView.CustomizationType.WallpaperCustomization; + } else if (tag.equals(SHORTCUTS_TAG)) { + return CustomizePagedView.CustomizationType.ShortcutCustomization; + } + return CustomizationType.WidgetCustomization; + } } diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index d7a360df6..b7f04f775 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -19,13 +19,11 @@ package com.android.launcher2; import com.android.common.Search; import com.android.launcher.R; -import com.android.launcher2.CustomizePagedView.CustomizationType; import com.android.launcher2.Workspace.ShrinkState; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; -import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.app.Activity; @@ -98,11 +96,8 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.TabHost; -import android.widget.TabWidget; import android.widget.TextView; import android.widget.Toast; -import android.widget.TabHost.OnTabChangeListener; -import android.widget.TabHost.TabContentFactory; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -172,12 +167,6 @@ public final class Launcher extends Activity // Type: long private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id"; - // tags for the customization tabs - private static final String WIDGETS_TAG = "widgets"; - private static final String APPLICATIONS_TAG = "applications"; - private static final String SHORTCUTS_TAG = "shortcuts"; - private static final String WALLPAPERS_TAG = "wallpapers"; - private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; /** The different states that Launcher can be in. */ @@ -214,7 +203,7 @@ public final class Launcher extends Activity private DeleteZone mDeleteZone; private HandleView mHandleView; private AllAppsView mAllAppsGrid; - private TabHost mHomeCustomizationDrawer; + private CustomizeTrayTabHost mHomeCustomizationDrawer; private boolean mAutoAdvanceRunning = false; private View mButtonCluster; @@ -293,19 +282,6 @@ public final class Launcher extends Activity int cellY; } - private CustomizationType getCustomizeFilterForTabTag(String tag) { - if (tag.equals(WIDGETS_TAG)) { - return CustomizationType.WidgetCustomization; - } else if (tag.equals(APPLICATIONS_TAG)) { - return CustomizationType.ApplicationCustomization; - } else if (tag.equals(WALLPAPERS_TAG)) { - return CustomizePagedView.CustomizationType.WallpaperCustomization; - } else if (tag.equals(SHORTCUTS_TAG)) { - return CustomizePagedView.CustomizationType.ShortcutCustomization; - } - return CustomizationType.WidgetCustomization; - } - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -334,68 +310,12 @@ public final class Launcher extends Activity loadHotseats(); checkForLocaleChange(); setContentView(R.layout.launcher); - mHomeCustomizationDrawer = (TabHost) findViewById(R.id.customization_drawer); + mHomeCustomizationDrawer = (CustomizeTrayTabHost) findViewById(R.id.customization_drawer); if (mHomeCustomizationDrawer != null) { - mHomeCustomizationDrawer.setup(); - // share the same customization workspace across all the tabs - mCustomizePagedView = (CustomizePagedView) mInflater.inflate( - R.layout.customization_drawer_tab_contents, mHomeCustomizationDrawer, false); - TabContentFactory contentFactory = new TabContentFactory() { - public View createTabContent(String tag) { - return mCustomizePagedView; - } - }; - - - TextView tabView; - TabWidget tabWidget = (TabWidget) - mHomeCustomizationDrawer.findViewById(com.android.internal.R.id.tabs); - - tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); - tabView.setText(getString(R.string.widgets_tab_label)); - mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG) - .setIndicator(tabView).setContent(contentFactory)); - tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); - tabView.setText(getString(R.string.applications_tab_label)); - mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG) - .setIndicator(tabView).setContent(contentFactory)); - tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); - tabView.setText(getString(R.string.wallpapers_tab_label)); - mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG) - .setIndicator(tabView).setContent(contentFactory)); - tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); - tabView.setText(getString(R.string.shortcuts_tab_label)); - mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG) - .setIndicator(tabView).setContent(contentFactory)); - mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() { - public void onTabChanged(String tabId) { - final CustomizePagedView.CustomizationType newType = - getCustomizeFilterForTabTag(tabId); - 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 = mCustomizePagedView.getAlpha(); - ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mCustomizePagedView, - "alpha", alpha, 0.0f); - alphaAnim.setDuration(duration); - alphaAnim.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - mCustomizePagedView.setCustomizationFilter(newType); - - final float alpha = mCustomizePagedView.getAlpha(); - ValueAnimator alphaAnim = ObjectAnimator.ofFloat( - mCustomizePagedView, "alpha", alpha, 1.0f); - alphaAnim.setDuration(duration); - alphaAnim.start(); - } - }); - alphaAnim.start(); - } - } - }); + mCustomizePagedView = (CustomizePagedView) findViewById( + R.id.customization_drawer_tab_contents); + } setupViews(); @@ -957,7 +877,8 @@ public final class Launcher extends Activity String curTab = savedState.getString("customize_currentTab"); if (curTab != null) { // We set this directly so that there is no delay before the tab is set - mCustomizePagedView.setCustomizationFilter(getCustomizeFilterForTabTag(curTab)); + mCustomizePagedView.setCustomizationFilter( + mHomeCustomizationDrawer.getCustomizeFilterForTabTag(curTab)); mHomeCustomizationDrawer.setCurrentTabByTag(curTab); } diff --git a/src/com/android/launcher2/PagedViewCellLayout.java b/src/com/android/launcher2/PagedViewCellLayout.java index 28bb78b9a..53657e5cb 100644 --- a/src/com/android/launcher2/PagedViewCellLayout.java +++ b/src/com/android/launcher2/PagedViewCellLayout.java @@ -243,6 +243,15 @@ public class PagedViewCellLayout extends ViewGroup implements Page { setMeasuredDimension(newWidth, newHeight); } + int getContentWidth() { + // Return the distance from the left edge of the content of the leftmost icon to + // the right edge of the content of the rightmost icon + + // icons are centered within cells, find out how much offset that accounts for + int iconHorizontalOffset = (mCellWidth - Utilities.getIconContentSize()); + return mCellCountX * mCellWidth + (mCellCountX - 1) * mWidthGap - iconHorizontalOffset; + } + @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int count = getChildCount(); @@ -281,17 +290,6 @@ public class PagedViewCellLayout extends ViewGroup implements Page { mHolographicChildren.setGap(widthGap, heightGap); } - public void setCellDimensions(int width, int height) { - mCellWidth = width; - mCellHeight = height; - mChildren.setCellDimensions(width, height); - mHolographicChildren.setCellDimensions(width, height); - } - - public int getDefaultCellDimensions() { - return sDefaultCellDimensions; - } - public int[] getCellCountForDimensions(int width, int height) { // Always assume we're working with the smallest span to make sure we // reserve enough space in both orientations diff --git a/src/com/android/launcher2/Utilities.java b/src/com/android/launcher2/Utilities.java index 60f71f575..8ab22ebc8 100644 --- a/src/com/android/launcher2/Utilities.java +++ b/src/com/android/launcher2/Utilities.java @@ -51,6 +51,7 @@ final class Utilities { private static int sIconWidth = -1; private static int sIconHeight = -1; + private static int sIconContentSize = -1; private static int sIconTextureWidth = -1; private static int sIconTextureHeight = -1; @@ -90,6 +91,10 @@ final class Utilities { static int sColors[] = { 0xffff0000, 0xff00ff00, 0xff0000ff }; static int sColorIndex = 0; + static int getIconContentSize() { + return sIconContentSize; + } + /** * Returns a bitmap suitable for the all apps view. The bitmap will be a power * of two sized ARGB_8888 bitmap that can be used as a gl texture. @@ -236,6 +241,9 @@ final class Utilities { final float density = metrics.density; sIconWidth = sIconHeight = (int) resources.getDimension(R.dimen.app_icon_size); + if (LauncherApplication.isScreenXLarge()) { + sIconContentSize = (int) resources.getDimension(R.dimen.app_icon_content_size); + } sIconTextureWidth = sIconTextureHeight = sIconWidth + 2; sBlurPaint.setMaskFilter(new BlurMaskFilter(5 * density, BlurMaskFilter.Blur.NORMAL)); |