diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2015-07-08 23:28:51 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2015-07-09 10:13:36 -0700 |
commit | 41d8417678934449c2692a97c0ae7b0d8ac27326 (patch) | |
tree | 224ef658c00c1336df18b5a6eb615d2f51e852a7 /src/com | |
parent | cb037eee8ca863ad99d9cdbacd6a82759295e5a0 (diff) | |
download | android_packages_apps_Trebuchet-41d8417678934449c2692a97c0ae7b0d8ac27326.tar.gz android_packages_apps_Trebuchet-41d8417678934449c2692a97c0ae7b0d8ac27326.tar.bz2 android_packages_apps_Trebuchet-41d8417678934449c2692a97c0ae7b0d8ac27326.zip |
Computing the visible cell layout area without using the current scroll
Bug: 22358433
Change-Id: Ib79d02156b6bfab831fa659637f6113a7f555ba7
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/launcher3/Folder.java | 32 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 42 |
2 files changed, 29 insertions, 45 deletions
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java index f2c5d93f5..2e19f6eba 100644 --- a/src/com/android/launcher3/Folder.java +++ b/src/com/android/launcher3/Folder.java @@ -959,32 +959,22 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList int centerY = (int) (sTempRect.top + sTempRect.height() * scale / 2); int centeredLeft = centerX - width / 2; int centeredTop = centerY - height / 2; - int currentPage = mLauncher.getWorkspace().getNextPage(); - // In case the workspace is scrolling, we need to use the final scroll to compute - // the folders bounds. - mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage); - // We first fetch the currently visible CellLayoutChildren - CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage); - ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets(); - Rect bounds = new Rect(); - parent.getDescendantRectRelativeToSelf(boundingLayout, bounds); - // We reset the workspaces scroll - mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage); - - // We need to bound the folder to the currently visible CellLayoutChildren - int left = Math.min(Math.max(bounds.left, centeredLeft), - bounds.left + bounds.width() - width); - int top = Math.min(Math.max(bounds.top, centeredTop), - bounds.top + bounds.height() - height); + + // We need to bound the folder to the currently visible workspace area + mLauncher.getWorkspace().getPageAreaRelativeToDragLayer(sTempRect); + int left = Math.min(Math.max(sTempRect.left, centeredLeft), + sTempRect.left + sTempRect.width() - width); + int top = Math.min(Math.max(sTempRect.top, centeredTop), + sTempRect.top + sTempRect.height() - height); if (grid.isPhone && (grid.availableWidthPx - width) < grid.iconSizePx) { // Center the folder if it is full (on phones only) left = (grid.availableWidthPx - width) / 2; - } else if (width >= bounds.width()) { + } else if (width >= sTempRect.width()) { // If the folder doesn't fit within the bounds, center it about the desired bounds - left = bounds.left + (bounds.width() - width) / 2; + left = sTempRect.left + (sTempRect.width() - width) / 2; } - if (height >= bounds.height()) { - top = bounds.top + (bounds.height() - height) / 2; + if (height >= sTempRect.height()) { + top = sTempRect.top + (sTempRect.height() - height) / 2; } int folderPivotX = width / 2 + (centeredLeft - left); diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 451f1245e..4a6b90afe 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -28,7 +28,6 @@ import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; import android.content.res.TypedArray; @@ -248,11 +247,6 @@ public class Workspace extends PagedView private SparseArray<Parcelable> mSavedStates; private final ArrayList<Integer> mRestoredPages = new ArrayList<Integer>(); - // These variables are used for storing the initial and final values during workspace animations - private int mSavedScrollX; - private float mSavedRotationY; - private float mSavedTranslationX; - private float mCurrentScale; private float mTransitionProgress; @@ -2762,26 +2756,26 @@ public class Workspace extends PagedView } } - public void setFinalScrollForPageChange(int pageIndex) { - CellLayout cl = (CellLayout) getChildAt(pageIndex); - if (cl != null) { - mSavedScrollX = getScrollX(); - mSavedTranslationX = cl.getTranslationX(); - mSavedRotationY = cl.getRotationY(); - final int newX = getScrollForPage(pageIndex); - setScrollX(newX); - cl.setTranslationX(0f); - cl.setRotationY(0f); + /** + * Computes the area relative to dragLayer which is used to display a page. + */ + public void getPageAreaRelativeToDragLayer(Rect outArea) { + CellLayout child = (CellLayout) getChildAt(getNextPage()); + if (child == null) { + return; } - } + ShortcutAndWidgetContainer boundingLayout = child.getShortcutsAndWidgets(); - public void resetFinalScrollForPageChange(int pageIndex) { - if (pageIndex >= 0) { - CellLayout cl = (CellLayout) getChildAt(pageIndex); - setScrollX(mSavedScrollX); - cl.setTranslationX(mSavedTranslationX); - cl.setRotationY(mSavedRotationY); - } + // Use the absolute left instead of the child left, as we want the visible area + // irrespective of the visible child. Since the view can only scroll horizontally, the + // top position is not affected. + mTempXY[0] = getViewportOffsetX() + getPaddingLeft() + boundingLayout.getLeft(); + mTempXY[1] = child.getTop() + boundingLayout.getTop(); + + float scale = mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempXY); + outArea.set(mTempXY[0], mTempXY[1], + (int) (mTempXY[0] + scale * boundingLayout.getMeasuredWidth()), + (int) (mTempXY[1] + scale * boundingLayout.getMeasuredHeight())); } public void getViewLocationRelativeToSelf(View v, int[] location) { |