diff options
author | Adam Cohen <adamcohen@google.com> | 2013-07-16 18:13:21 -0700 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2013-07-16 18:14:22 -0700 |
commit | 96d30a165185dc59617e181314f4d22634e22952 (patch) | |
tree | 346bf788729daab97dc2050b5b8e137838b3cdc5 /src/com/android/launcher3 | |
parent | b5da44583957ffe9b0311074eeb77d33e753a9e5 (diff) | |
download | android_packages_apps_Trebuchet-96d30a165185dc59617e181314f4d22634e22952.tar.gz android_packages_apps_Trebuchet-96d30a165185dc59617e181314f4d22634e22952.tar.bz2 android_packages_apps_Trebuchet-96d30a165185dc59617e181314f4d22634e22952.zip |
Adding notion of fullscreen page to PagedView
-> This will be used for appending custom content to the left of the workspace
-> Stripped out a bunch of dead code related to notion of layout scale in PagedView
Change-Id: If4dbe28431cb5fb60dc170f6ee6e55a649dac45e
Diffstat (limited to 'src/com/android/launcher3')
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 23 | ||||
-rw-r--r-- | src/com/android/launcher3/PagedView.java | 148 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 44 |
3 files changed, 99 insertions, 116 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index d1284d85b..57e0cbf2b 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -50,6 +50,7 @@ import android.content.res.Resources; import android.database.ContentObserver; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.drawable.Drawable; @@ -68,16 +69,31 @@ import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.method.TextKeyListener; import android.util.Log; -import android.util.Pair; -import android.view.*; +import android.view.Display; +import android.view.Gravity; +import android.view.HapticFeedbackConstants; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.MotionEvent; +import android.view.Surface; +import android.view.View; import android.view.View.OnLongClickListener; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.view.ViewTreeObserver.OnGlobalLayoutListener; +import android.view.WindowManager; import android.view.accessibility.AccessibilityEvent; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; import android.view.inputmethod.InputMethodManager; -import android.widget.*; +import android.widget.Advanceable; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; import com.android.launcher3.DropTarget.DragObject; @@ -93,7 +109,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index 275195b71..dc04cee74 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -44,6 +44,7 @@ import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.ViewParent; +import android.view.ViewGroup.LayoutParams; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityNodeInfo; @@ -51,6 +52,7 @@ import android.view.animation.AnimationUtils; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; import android.view.animation.LinearInterpolator; +import android.widget.FrameLayout; import android.widget.Scroller; import java.util.ArrayList; @@ -121,7 +123,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc private int mLastScreenCenter = -1; private int[] mChildOffsets; private int[] mChildRelativeOffsets; - private int[] mChildOffsetsWithLayoutScale; protected final static int TOUCH_STATE_REST = 0; protected final static int TOUCH_STATE_SCROLLING = 1; @@ -139,7 +140,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc protected int mTouchSlop; private int mPagingTouchSlop; private int mMaximumVelocity; - private int mMinimumWidth; protected int mPageSpacing; protected int mPageLayoutPaddingTop; protected int mPageLayoutPaddingBottom; @@ -160,9 +160,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc // the screens from continuing to translate beyond the normal bounds. protected int mOverScrollX; - // parameter that adjusts the layout to be optimized for pages with that scale factor - protected float mLayoutScale = 1.0f; - protected static final int INVALID_POINTER = -1; protected int mActivePointerId = INVALID_POINTER; @@ -643,6 +640,31 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc return mTopAlignPageWhenShrinkingForBouncer; } + public static class LayoutParams extends ViewGroup.LayoutParams { + public boolean isFullScreenPage = false; + + /** + * {@inheritDoc} + */ + public LayoutParams(int width, int height) { + super(width, height); + } + + public LayoutParams(ViewGroup.LayoutParams source) { + super(source); + } + } + + protected LayoutParams generateDefaultLayoutParams() { + return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + } + + public void addFullScreenPage(View page, int width, int height) { + LayoutParams lp = generateDefaultLayoutParams(); + lp.isFullScreenPage = true; + super.addView(page, 0, lp); + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (!mIsDataReady || getChildCount() == 0) { @@ -699,24 +721,38 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc final LayoutParams lp = (LayoutParams) child.getLayoutParams(); int childWidthMode; - if (lp.width == LayoutParams.WRAP_CONTENT) { - childWidthMode = MeasureSpec.AT_MOST; - } else { - childWidthMode = MeasureSpec.EXACTLY; - } - int childHeightMode; - if (lp.height == LayoutParams.WRAP_CONTENT) { - childHeightMode = MeasureSpec.AT_MOST; + int childWidth; + int childHeight; + + if (!lp.isFullScreenPage) { + if (lp.width == LayoutParams.WRAP_CONTENT) { + childWidthMode = MeasureSpec.AT_MOST; + } else { + childWidthMode = MeasureSpec.EXACTLY; + } + + if (lp.height == LayoutParams.WRAP_CONTENT) { + childHeightMode = MeasureSpec.AT_MOST; + } else { + childHeightMode = MeasureSpec.EXACTLY; + } + + childWidth = widthSize - horizontalPadding; + childHeight = heightSize - verticalPadding; + } else { + childWidthMode = MeasureSpec.EXACTLY; childHeightMode = MeasureSpec.EXACTLY; + + childWidth = getViewportWidth(); + childHeight = getViewportHeight(); } final int childWidthMeasureSpec = - MeasureSpec.makeMeasureSpec(widthSize - horizontalPadding, childWidthMode); - final int childHeightMeasureSpec = - MeasureSpec.makeMeasureSpec(heightSize - verticalPadding, childHeightMode); - + MeasureSpec.makeMeasureSpec(childWidth, childWidthMode); + final int childHeightMeasureSpec = + MeasureSpec.makeMeasureSpec(childHeight, childHeightMode); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); } setMeasuredDimension(scaledWidthSize, scaledHeightSize); @@ -726,12 +762,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc // ensure that the cache is filled with good values. invalidateCachedOffsets(); - if (mScroller.isFinished() && mChildCountOnLastMeasure != getChildCount() && - !mDeferringForDelete) { - setCurrentPage(getNextPage()); - } - mChildCountOnLastMeasure = getChildCount(); - if (childCount > 0) { if (DEBUG) Log.d(TAG, "getRelativeChildOffset(): " + getViewportWidth() + ", " + getChildWidth(0)); @@ -750,6 +780,12 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } } + if (mScroller.isFinished() && mChildCountOnLastMeasure != getChildCount() && + !mDeferringForDelete) { + setCurrentPage(getNextPage()); + } + mChildCountOnLastMeasure = getChildCount(); + updateScrollingIndicatorPosition(); if (childCount > 0) { @@ -790,12 +826,20 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc int childLeft = offsetX + getRelativeChildOffset(startIndex); for (int i = startIndex; i != endIndex; i += delta) { final View child = getPageAt(i); - int childTop = offsetY + getPaddingTop(); - if (mCenterPagesVertically) { - childTop += ((getViewportHeight() - verticalPadding) - child.getMeasuredHeight()) / 2; + LayoutParams lp = (LayoutParams) child.getLayoutParams(); + int childTop; + + if (lp.isFullScreenPage) { + childTop = offsetY; + } else { + childTop = offsetY + getPaddingTop(); + if (mCenterPagesVertically) { + childTop += ((getViewportHeight() - verticalPadding) - child.getMeasuredHeight()) / 2; + } } + if (child.getVisibility() != View.GONE) { - final int childWidth = getScaledMeasuredWidth(child); + final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); if (DEBUG) Log.d(TAG, "\tlayout-child" + i + ": " + childLeft + ", " + childTop); @@ -838,6 +882,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc // in accordance with any scroll effects. mForceScreenScrolled = true; mRecomputePageSpacing = true; + invalidate(); invalidateCachedOffsets(); } @@ -854,17 +899,14 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc if (count == 0) { mChildOffsets = null; mChildRelativeOffsets = null; - mChildOffsetsWithLayoutScale = null; return; } mChildOffsets = new int[count]; mChildRelativeOffsets = new int[count]; - mChildOffsetsWithLayoutScale = new int[count]; for (int i = 0; i < count; i++) { mChildOffsets[i] = -1; mChildRelativeOffsets[i] = -1; - mChildOffsetsWithLayoutScale[i] = -1; } } @@ -872,8 +914,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc if (index < 0 || index > getChildCount() - 1) return 0; final boolean isRtl = isLayoutRtl(); - int[] childOffsets = Float.compare(mLayoutScale, 1f) == 0 ? - mChildOffsets : mChildOffsetsWithLayoutScale; + int[] childOffsets = mChildOffsets; if (childOffsets != null && childOffsets[index] != -1) { return childOffsets[index]; @@ -881,20 +922,20 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc if (getChildCount() == 0) return 0; - final int startIndex = isRtl ? getChildCount() - 1 : 0; final int endIndex = isRtl ? index : index; final int delta = isRtl ? -1 : 1; int offset = getRelativeChildOffset(startIndex); for (int i = startIndex; i != endIndex; i += delta) { - offset += getScaledMeasuredWidth(getPageAt(i)) + mPageSpacing; + offset += getPageAt(i).getMeasuredWidth() + mPageSpacing; } if (childOffsets != null) { childOffsets[index] = offset; } return offset; } + } protected int getRelativeChildOffset(int index) { @@ -913,15 +954,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } } - protected int getScaledMeasuredWidth(View child) { - // This functions are called enough times that it actually makes a difference in the - // profiler -- so just inline the max() here - final int measuredWidth = child.getMeasuredWidth(); - final int minWidth = mMinimumWidth; - final int maxWidth = (minWidth > measuredWidth) ? minWidth : measuredWidth; - return (int) (maxWidth * mLayoutScale + 0.5f); - } - void boundByReorderablePages(boolean isReordering, int[] range) { // Do nothing } @@ -1354,7 +1386,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc protected float getScrollProgress(int screenCenter, View v, int page) { final int halfScreenSize = getViewportWidth() / 2; - int totalDistance = getScaledMeasuredWidth(v) + mPageSpacing; + int totalDistance = v.getMeasuredWidth() + mPageSpacing; int delta = screenCenter - (getChildOffset(page) - getRelativeChildOffset(page) + halfScreenSize); @@ -1627,7 +1659,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int velocityX = (int) velocityTracker.getXVelocity(activePointerId); final int deltaX = (int) (x - mDownMotionX); - final int pageWidth = getScaledMeasuredWidth(getPageAt(mCurrentPage)); + final int pageWidth = getPageAt(mCurrentPage).getMeasuredWidth(); boolean isSignificantMove = Math.abs(deltaX) > pageWidth * SIGNIFICANT_MOVE_THRESHOLD; @@ -1820,30 +1852,8 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } } - protected int getChildIndexForRelativeOffset(int relativeOffset) { - final boolean isRtl = isLayoutRtl(); - final int childCount = getChildCount(); - int left; - int right; - final int startIndex = isRtl ? childCount - 1 : 0; - final int endIndex = isRtl ? -1 : childCount; - final int delta = isRtl ? -1 : 1; - for (int i = startIndex; i != endIndex; i += delta) { - left = getRelativeChildOffset(i); - right = (left + getScaledMeasuredWidth(getPageAt(i))); - if (left <= relativeOffset && relativeOffset <= right) { - return i; - } - } - return -1; - } - protected int getChildWidth(int index) { - // This functions are called enough times that it actually makes a difference in the - // profiler -- so just inline the max() here - final int measuredWidth = getPageAt(index).getMeasuredWidth(); - final int minWidth = mMinimumWidth; - return (minWidth > measuredWidth) ? minWidth : measuredWidth; + return getPageAt(index).getMeasuredWidth(); } int getPageNearestToPoint(float x) { @@ -1865,7 +1875,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc final int childCount = getChildCount(); for (int i = 0; i < childCount; ++i) { View layout = (View) getPageAt(i); - int childWidth = getScaledMeasuredWidth(layout); + int childWidth = layout.getMeasuredWidth(); int halfChildWidth = (childWidth / 2); int childCenter = getViewportOffsetX() + getChildOffset(i) + halfChildWidth; int distanceFromScreenCenter = Math.abs(childCenter - screenCenter); diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index d9582adfb..1c8636418 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -528,7 +528,6 @@ public class Workspace extends SmoothPagedView mScreenOrder.add(0, CUSTOM_CONTENT_SCREEN_ID); addView(customScreen, 0); - // Ensure that the current page and default page are maintained. mDefaultPage++; setCurrentPage(getCurrentPage() + 1); @@ -691,7 +690,7 @@ public class Workspace extends SmoothPagedView child.setOnKeyListener(new IconKeyEventListener()); } - LayoutParams genericLp = child.getLayoutParams(); + ViewGroup.LayoutParams genericLp = child.getLayoutParams(); CellLayout.LayoutParams lp; if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) { lp = new CellLayout.LayoutParams(x, y, spanX, spanY); @@ -984,17 +983,10 @@ public class Workspace extends SmoothPagedView // Set wallpaper offset steps (1 / (number of screens - 1)) mWallpaperManager.setWallpaperOffsetSteps(1.0f / (getChildCount() - 1), 1.0f); - // For the purposes of computing the scrollRange and overScrollOffset, we assume - // that mLayoutScale is 1. This means that when we're in spring-loaded mode, - // there's no discrepancy between the wallpaper offset for a given page. - float layoutScale = mLayoutScale; - mLayoutScale = 1f; int scrollRange = getScrollRange(); - // Again, we adjust the wallpaper offset to be consistent between values of mLayoutScale float adjustedScrollX = Math.max(0, Math.min(getScrollX(), mMaxScrollX)); adjustedScrollX *= mWallpaperScrollRatio; - mLayoutScale = layoutScale; float scrollProgress = adjustedScrollX / (float) scrollRange; @@ -1048,24 +1040,6 @@ public class Workspace extends SmoothPagedView } } - @Override - protected void updateCurrentPageScroll() { - super.updateCurrentPageScroll(); - computeWallpaperScrollRatio(mCurrentPage); - } - - @Override - protected void snapToPage(int whichPage) { - super.snapToPage(whichPage); - computeWallpaperScrollRatio(whichPage); - } - - @Override - protected void snapToPage(int whichPage, int duration) { - super.snapToPage(whichPage, duration); - computeWallpaperScrollRatio(whichPage); - } - protected void snapToPage(int whichPage, Runnable r) { if (mDelayedSnapToPageRunnable != null) { mDelayedSnapToPageRunnable.run(); @@ -1078,22 +1052,6 @@ public class Workspace extends SmoothPagedView snapToPage(getPageIndexForScreenId(screenId), r); } - private void computeWallpaperScrollRatio(int page) { - // Here, we determine what the desired scroll would be with and without a layout scale, - // and compute a ratio between the two. This allows us to adjust the wallpaper offset - // as though there is no layout scale. - float layoutScale = mLayoutScale; - int scaled = getChildOffset(page) - getRelativeChildOffset(page); - mLayoutScale = 1.0f; - float unscaled = getChildOffset(page) - getRelativeChildOffset(page); - mLayoutScale = layoutScale; - if (scaled > 0) { - mWallpaperScrollRatio = (1.0f * unscaled) / scaled; - } else { - mWallpaperScrollRatio = 1f; - } - } - class WallpaperOffsetInterpolator { float mFinalHorizontalWallpaperOffset = 0.0f; float mFinalVerticalWallpaperOffset = 0.5f; |