diff options
-rw-r--r-- | res/layout-xlarge/launcher.xml | 3 | ||||
-rw-r--r-- | res/values/attrs.xml | 2 | ||||
-rw-r--r-- | src/com/android/launcher2/AllAppsPagedView.java | 15 | ||||
-rw-r--r-- | src/com/android/launcher2/CellLayout.java | 6 | ||||
-rw-r--r-- | src/com/android/launcher2/CustomizePagedView.java | 15 | ||||
-rw-r--r-- | src/com/android/launcher2/PagedView.java | 37 | ||||
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 14 |
7 files changed, 47 insertions, 45 deletions
diff --git a/res/layout-xlarge/launcher.xml b/res/layout-xlarge/launcher.xml index 2b43442..65f29df 100644 --- a/res/layout-xlarge/launcher.xml +++ b/res/layout-xlarge/launcher.xml @@ -37,7 +37,8 @@ android:paddingTop="?android:attr/actionBarSize" launcher:defaultScreen="2" launcher:cellCountX="8" - launcher:cellCountY="7"> + launcher:cellCountY="7" + launcher:pageSpacing="64dip"> <include android:id="@+id/cell1" layout="@layout/workspace_screen" /> <include android:id="@+id/cell2" layout="@layout/workspace_screen" /> diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 3e2a8e9..14a5e98 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -89,6 +89,8 @@ <attr name="pageLayoutPaddingBottom" format="dimension" /> <attr name="pageLayoutPaddingLeft" format="dimension" /> <attr name="pageLayoutPaddingRight" format="dimension" /> + <!-- The space between adjacent pages of the PagedView. --> + <attr name="pageSpacing" format="dimension" /> </declare-styleable> <!-- CustomizePagedView specific attributes. These attributes are used to customize diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java index 3fb1679..b392959 100644 --- a/src/com/android/launcher2/AllAppsPagedView.java +++ b/src/com/android/launcher2/AllAppsPagedView.java @@ -66,13 +66,6 @@ public class AllAppsPagedView extends PagedView static final int ALL_APPS_FLAG = -1; private int mAppFilter = ALL_APPS_FLAG; - private int mCellCountX; - private int mCellCountY; - private int mPageLayoutPaddingTop; - private int mPageLayoutPaddingBottom; - private int mPageLayoutPaddingLeft; - private int mPageLayoutPaddingRight; - private final LayoutInflater mInflater; private ViewGroup mOrigInfoButtonParent; @@ -94,14 +87,6 @@ public class AllAppsPagedView extends PagedView TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0); mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6); mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4); - mPageLayoutPaddingTop = a.getDimensionPixelSize( - R.styleable.PagedView_pageLayoutPaddingTop, 10); - mPageLayoutPaddingBottom = a.getDimensionPixelSize( - R.styleable.PagedView_pageLayoutPaddingBottom, 10); - mPageLayoutPaddingLeft = a.getDimensionPixelSize( - R.styleable.PagedView_pageLayoutPaddingLeft, 10); - mPageLayoutPaddingRight = a.getDimensionPixelSize( - R.styleable.PagedView_pageLayoutPaddingRight, 10); mInflater = LayoutInflater.from(context); a.recycle(); setSoundEffectsEnabled(false); diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 0f1d469..7da6612 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -226,8 +226,10 @@ public class CellLayout extends ViewGroup implements Dimmable { } else { bg = mBackground; } - bg.setAlpha((int) (mBackgroundAlpha * 255)); - bg.draw(canvas); + if (bg != null) { + bg.setAlpha((int) (mBackgroundAlpha * 255)); + bg.draw(canvas); + } } super.dispatchDraw(canvas); } diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java index 62e5496..b7e5dcd 100644 --- a/src/com/android/launcher2/CustomizePagedView.java +++ b/src/com/android/launcher2/CustomizePagedView.java @@ -115,12 +115,6 @@ public class CustomizePagedView extends PagedView private List<ResolveInfo> mWallpaperList; private List<ApplicationInfo> mApps; - private int mCellCountX; - private int mCellCountY; - private int mPageLayoutPaddingTop; - private int mPageLayoutPaddingBottom; - private int mPageLayoutPaddingLeft; - private int mPageLayoutPaddingRight; private static final int sMinWidgetCellHSpan = 2; private static final int sMaxWidgetCellHSpan = 4; @@ -151,14 +145,7 @@ public class CustomizePagedView extends PagedView 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); - mPageLayoutPaddingTop = a.getDimensionPixelSize( - R.styleable.PagedView_pageLayoutPaddingTop, 10); - mPageLayoutPaddingBottom = a.getDimensionPixelSize( - R.styleable.PagedView_pageLayoutPaddingBottom, 10); - mPageLayoutPaddingLeft = a.getDimensionPixelSize( - R.styleable.PagedView_pageLayoutPaddingLeft, 10); - mPageLayoutPaddingRight = a.getDimensionPixelSize( - R.styleable.PagedView_pageLayoutPaddingRight, 10); + a.recycle(); mCustomizationType = CustomizationType.WidgetCustomization; mWidgetPages = new ArrayList<ArrayList<AppWidgetProviderInfo>>(); diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java index a1b1e08..732bfbd 100644 --- a/src/com/android/launcher2/PagedView.java +++ b/src/com/android/launcher2/PagedView.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.HashMap; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Rect; @@ -90,6 +91,13 @@ public abstract class PagedView extends ViewGroup { private int mTouchSlop; private int mPagingTouchSlop; private int mMaximumVelocity; + protected int mPageSpacing; + protected int mPageLayoutPaddingTop; + protected int mPageLayoutPaddingBottom; + protected int mPageLayoutPaddingLeft; + protected int mPageLayoutPaddingRight; + protected int mCellCountX; + protected int mCellCountY; protected static final int INVALID_POINTER = -1; @@ -168,6 +176,19 @@ public abstract class PagedView extends ViewGroup { super(context, attrs, defStyle); mChoiceMode = CHOICE_MODE_NONE; + TypedArray a = context.obtainStyledAttributes(attrs, + R.styleable.PagedView, defStyle, 0); + mPageSpacing = a.getDimensionPixelSize(R.styleable.PagedView_pageSpacing, 0); + mPageLayoutPaddingTop = a.getDimensionPixelSize( + R.styleable.PagedView_pageLayoutPaddingTop, 10); + mPageLayoutPaddingBottom = a.getDimensionPixelSize( + R.styleable.PagedView_pageLayoutPaddingBottom, 10); + mPageLayoutPaddingLeft = a.getDimensionPixelSize( + R.styleable.PagedView_pageLayoutPaddingLeft, 10); + mPageLayoutPaddingRight = a.getDimensionPixelSize( + R.styleable.PagedView_pageLayoutPaddingRight, 10); + a.recycle(); + setHapticFeedbackEnabled(false); init(); } @@ -359,7 +380,7 @@ public abstract class PagedView extends ViewGroup { final int childHeight = (getMeasuredHeight() - child.getMeasuredHeight()) / 2; child.layout(childLeft, childHeight, childLeft + childWidth, childHeight + child.getMeasuredHeight()); - childLeft += childWidth; + childLeft += childWidth + mPageSpacing; } } } @@ -387,6 +408,7 @@ public abstract class PagedView extends ViewGroup { d += getChildAt(i + 1).getMeasuredWidth() / 2; } } + d += mPageSpacing; float dimAlpha = (float) (Math.abs(distanceFromScreenCenter)) / d; dimAlpha = Math.max(0.0f, Math.min(1.0f, (dimAlpha * dimAlpha))); @@ -433,7 +455,7 @@ public abstract class PagedView extends ViewGroup { int rightScreen = 0; while (x <= mScrollX) { leftScreen++; - x += pageWidth; + x += pageWidth + mPageSpacing; // replace above line with this if you don't assume all pages have same width as 0th // page: // x += getChildAt(leftScreen).getMeasuredWidth(); @@ -441,7 +463,7 @@ public abstract class PagedView extends ViewGroup { rightScreen = leftScreen; while (x < mScrollX + screenWidth) { rightScreen++; - x += pageWidth; + x += pageWidth + mPageSpacing; // replace above line with this if you don't assume all pages have same width as 0th // page: //if (rightScreen < pageCount) { @@ -874,13 +896,14 @@ public abstract class PagedView extends ViewGroup { protected int getChildIndexForRelativeOffset(int relativeOffset) { final int childCount = getChildCount(); - int left = getRelativeChildOffset(0); + int left; + int right; for (int i = 0; i < childCount; ++i) { - final int right = (left + getChildAt(i).getMeasuredWidth()); + left = getRelativeChildOffset(i); + right = (left + getChildAt(i).getMeasuredWidth()); if (left <= relativeOffset && relativeOffset <= right) { return i; } - left = right; } return -1; } @@ -895,7 +918,7 @@ public abstract class PagedView extends ViewGroup { int offset = getRelativeChildOffset(0); for (int i = 0; i < index; ++i) { - offset += getChildAt(i).getMeasuredWidth(); + offset += getChildAt(i).getMeasuredWidth() + mPageSpacing; } return offset; } diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index eeb496d..47e172f 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -475,9 +475,9 @@ public class Workspace extends SmoothPagedView @Override protected void screenScrolled(int screenCenter) { - View cur = getChildAt(mCurrentPage); - View toRight = getChildAt(mCurrentPage + 1); - View toLeft = getChildAt(mCurrentPage - 1); + CellLayout cur = (CellLayout) getChildAt(mCurrentPage); + CellLayout toRight = (CellLayout) getChildAt(mCurrentPage + 1); + CellLayout toLeft = (CellLayout) getChildAt(mCurrentPage - 1); for (int i = 0; i < mCurrentPage - 1; i++) { View v = getChildAt(i); @@ -494,11 +494,12 @@ public class Workspace extends SmoothPagedView } } + int halfScreenSize = getMeasuredWidth() / 2; int pageWidth = cur.getMeasuredWidth(); - int delta = screenCenter - (mCurrentPage * pageWidth + pageWidth / 2 + - getRelativeChildOffset(0)); + int delta = screenCenter - (getChildOffset(mCurrentPage) - + getRelativeChildOffset(mCurrentPage) + halfScreenSize); - float scrollProgress = Math.abs(delta/(pageWidth*1.0f)); + float scrollProgress = Math.abs(delta/(pageWidth*1.0f + mPageSpacing)); int scrollDirection = delta > 0 ? SCROLL_LEFT : SCROLL_RIGHT; float rotation; @@ -507,6 +508,7 @@ public class Workspace extends SmoothPagedView rotation = -scrollProgress * WORKSPACE_ROTATION; cur.setRotationY(rotation); cur.setScaleX(getScaleXForRotation(rotation)); + if (toLeft != null) { rotation = WORKSPACE_ROTATION * (1 - scrollProgress); toLeft.setRotationY(rotation); |