summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Jurka <mikejurka@google.com>2011-02-23 11:48:32 -0800
committerMichael Jurka <mikejurka@google.com>2011-05-13 14:35:47 -0700
commit12ac0d60cce75fc002da43ef20290613f069a85f (patch)
treec85de9bd655e7584f8ab3bf7ca92f43f47daf2f5 /src
parent2701ec91e15ff1fa415ec051e46f1f32e3cd53bb (diff)
downloadandroid_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
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/AllAppsPagedView.java23
-rw-r--r--src/com/android/launcher2/AllAppsTabbed.java15
-rw-r--r--src/com/android/launcher2/CustomizePagedView.java11
-rw-r--r--src/com/android/launcher2/CustomizeTrayTabHost.java112
-rw-r--r--src/com/android/launcher2/Launcher.java93
-rw-r--r--src/com/android/launcher2/PagedViewCellLayout.java20
-rw-r--r--src/com/android/launcher2/Utilities.java8
7 files changed, 173 insertions, 109 deletions
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));