diff options
author | Adam Cohen <adamcohen@google.com> | 2013-07-17 18:24:45 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-07-17 18:24:46 +0000 |
commit | 02b3a8ca1f9dac40677dcdee2fc88307b99cc15d (patch) | |
tree | 04efda8d53b828902abf88a6dac7fa0b2ce30777 /src | |
parent | d2be381d36485059d0108ae89cfe57a30a7a8499 (diff) | |
parent | 96d30a165185dc59617e181314f4d22634e22952 (diff) | |
download | android_packages_apps_Trebuchet-02b3a8ca1f9dac40677dcdee2fc88307b99cc15d.tar.gz android_packages_apps_Trebuchet-02b3a8ca1f9dac40677dcdee2fc88307b99cc15d.tar.bz2 android_packages_apps_Trebuchet-02b3a8ca1f9dac40677dcdee2fc88307b99cc15d.zip |
Merge "Adding notion of fullscreen page to PagedView" into jb-ub-gel-agar
Diffstat (limited to 'src')
-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 d46deb2cb..561bd16ff 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 81a842e35..c0c65eaae 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; @@ -646,6 +643,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) { @@ -702,24 +724,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); @@ -729,12 +765,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)); @@ -753,6 +783,12 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } } + if (mScroller.isFinished() && mChildCountOnLastMeasure != getChildCount() && + !mDeferringForDelete) { + setCurrentPage(getNextPage()); + } + mChildCountOnLastMeasure = getChildCount(); + if (childCount > 0) { final int index = isLayoutRtl() ? 0 : childCount - 1; mMaxScrollX = getChildOffset(index) - getRelativeChildOffset(index); @@ -791,12 +827,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); @@ -842,6 +886,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc // in accordance with any scroll effects. mForceScreenScrolled = true; mRecomputePageSpacing = true; + invalidate(); invalidateCachedOffsets(); } @@ -898,17 +943,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; } } @@ -916,8 +958,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]; @@ -925,20 +966,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) { @@ -957,15 +998,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 } @@ -1398,7 +1430,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); @@ -1672,7 +1704,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; @@ -1865,30 +1897,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) { @@ -1910,7 +1920,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 47d8ec8c7..ebf761936 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -529,7 +529,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); @@ -692,7 +691,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); @@ -977,17 +976,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; @@ -1041,24 +1033,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(); @@ -1071,22 +1045,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; |