From a501d49a6a8b684bc83aa6b536f43247d75bacdf Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Tue, 3 Nov 2015 18:05:01 -0800 Subject: Add appropriate (tiny) offset to widget drops so they land correctly. Also removed some unused parameters I found on the way. Bug: 25191623 Change-Id: Ib9a30db106467c114cc8b54a5b13ed3e88162d56 --- src/com/android/launcher3/CellLayout.java | 17 ++++++++++++----- src/com/android/launcher3/DragLayer.java | 4 ---- src/com/android/launcher3/DragView.java | 8 ++++---- src/com/android/launcher3/Launcher.java | 3 +-- .../launcher3/ShortcutAndWidgetContainer.java | 3 +-- src/com/android/launcher3/Workspace.java | 21 +++++++++------------ 6 files changed, 27 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 0a2a01728..94e3e4141 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -902,9 +902,7 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler { ((LayoutParams) mShortcutsAndWidgets.getChildAt(0).getLayoutParams()).isFullscreen; int left = getPaddingLeft(); if (!isFullscreen) { - int offset = getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - - (mCountX * mCellWidth); - left += (int) Math.ceil(offset / 2f); + left += (int) Math.ceil(getUnusedHorizontalSpace() / 2f); } int top = getPaddingTop(); @@ -916,6 +914,15 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler { top + b - t); } + /** + * Returns the amount of space left over after subtracting padding and cells. This space will be + * very small, a few pixels at most, and is a result of rounding down when calculating the cell + * width in {@link DeviceProfile#calculateCellWidth(int, int)}. + */ + public int getUnusedHorizontalSpace() { + return getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - (mCountX * mCellWidth); + } + @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); @@ -1048,8 +1055,8 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler { return false; } - void visualizeDropLocation(View v, Bitmap dragOutline, int originX, int originY, int cellX, - int cellY, int spanX, int spanY, boolean resize, DropTarget.DragObject dragObject) { + void visualizeDropLocation(View v, Bitmap dragOutline, int cellX, int cellY, int spanX, + int spanY, boolean resize, DropTarget.DragObject dragObject) { final int oldDragCellX = mDragCell[0]; final int oldDragCellY = mDragCell[1]; diff --git a/src/com/android/launcher3/DragLayer.java b/src/com/android/launcher3/DragLayer.java index 1c18747c1..ad9063c25 100644 --- a/src/com/android/launcher3/DragLayer.java +++ b/src/com/android/launcher3/DragLayer.java @@ -565,10 +565,6 @@ public class DragLayer extends InsettableFrameLayout { resizeFrame.snapToWidget(false); } - public void animateViewIntoPosition(DragView dragView, final View child) { - animateViewIntoPosition(dragView, child, null, null); - } - public void animateViewIntoPosition(DragView dragView, final int[] pos, float alpha, float scaleX, float scaleY, int animationEndStyle, Runnable onFinishRunnable, int duration) { diff --git a/src/com/android/launcher3/DragView.java b/src/com/android/launcher3/DragView.java index 2acfc6140..a584667ca 100644 --- a/src/com/android/launcher3/DragView.java +++ b/src/com/android/launcher3/DragView.java @@ -321,10 +321,10 @@ public class DragView extends View { setTranslationY(touchY - mRegistrationY); // Post the animation to skip other expensive work happening on the first frame post(new Runnable() { - public void run() { - mAnim.start(); - } - }); + public void run() { + mAnim.start(); + } + }); } public void cancelAnimation() { diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index a379accd3..9532c3941 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -900,8 +900,7 @@ public class Launcher extends Activity } @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) { - CellLayout cellLayout = - (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId); + CellLayout cellLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId); Runnable onCompleteRunnable = null; int animationType = 0; diff --git a/src/com/android/launcher3/ShortcutAndWidgetContainer.java b/src/com/android/launcher3/ShortcutAndWidgetContainer.java index 56282fe97..21e72e99a 100644 --- a/src/com/android/launcher3/ShortcutAndWidgetContainer.java +++ b/src/com/android/launcher3/ShortcutAndWidgetContainer.java @@ -163,8 +163,7 @@ public class ShortcutAndWidgetContainer extends ViewGroup { lp.height = getMeasuredHeight(); } int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY); - int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(lp.height, - MeasureSpec.EXACTLY); + int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY); child.measure(childWidthMeasureSpec, childheightMeasureSpec); } diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 507390244..0d50c6e0b 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -359,7 +359,7 @@ public class Workspace extends PagedView if (getChildCount() > 0) { // Use the first non-custom page to estimate the child position CellLayout cl = (CellLayout) getChildAt(numCustomPages()); - Rect r = estimateItemPosition(cl, itemInfo, 0, 0, itemInfo.spanX, itemInfo.spanY); + Rect r = estimateItemPosition(cl, 0, 0, itemInfo.spanX, itemInfo.spanY); size[0] = r.width(); size[1] = r.height(); if (springLoaded) { @@ -374,8 +374,7 @@ public class Workspace extends PagedView } } - public Rect estimateItemPosition(CellLayout cl, ItemInfo pendingInfo, - int hCell, int vCell, int hSpan, int vSpan) { + public Rect estimateItemPosition(CellLayout cl, int hCell, int vCell, int hSpan, int vSpan) { Rect r = new Rect(); cl.cellToRect(hCell, vCell, hSpan, vSpan, r); return r; @@ -3251,7 +3250,6 @@ public class Workspace extends PagedView if (!nearestDropOccupied) { mDragTargetLayout.visualizeDropLocation(child, mDragOutline, - (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], mTargetCell[0], mTargetCell[1], item.spanX, item.spanY, false, d); } else if ((mDragMode == DRAG_MODE_NONE || mDragMode == DRAG_MODE_REORDER) && !mReorderAlarm.alarmPending() && (mLastReorderX != reorderX || @@ -3393,7 +3391,6 @@ public class Workspace extends PagedView boolean resize = resultSpan[0] != spanX || resultSpan[1] != spanY; mDragTargetLayout.visualizeDropLocation(child, mDragOutline, - (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], mTargetCell[0], mTargetCell[1], resultSpan[0], resultSpan[1], resize, dragObject); } } @@ -3617,14 +3614,13 @@ public class Workspace extends PagedView } private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY, - DragView dragView, CellLayout layout, ItemInfo info, int[] targetCell, - boolean external, boolean scale) { + DragView dragView, CellLayout layout, ItemInfo info, int[] targetCell, boolean scale) { // Now we animate the dragView, (ie. the widget or shortcut preview) into its final // location and size on the home screen. int spanX = info.spanX; int spanY = info.spanY; - Rect r = estimateItemPosition(layout, info, targetCell[0], targetCell[1], spanX, spanY); + Rect r = estimateItemPosition(layout, targetCell[0], targetCell[1], spanX, spanY); loc[0] = r.left; loc[1] = r.top; @@ -3645,14 +3641,15 @@ public class Workspace extends PagedView // The animation will scale the dragView about its center, so we need to center about // the final location. - loc[0] -= (dragView.getMeasuredWidth() - cellLayoutScale * r.width()) / 2; + loc[0] -= (dragView.getMeasuredWidth() - cellLayoutScale * r.width()) / 2 + - Math.ceil(layout.getUnusedHorizontalSpace() / 2f); loc[1] -= (dragView.getMeasuredHeight() - cellLayoutScale * r.height()) / 2; scaleXY[0] = dragViewScaleX * cellLayoutScale; scaleXY[1] = dragViewScaleY * cellLayoutScale; } - public void animateWidgetDrop(ItemInfo info, CellLayout cellLayout, DragView dragView, + public void animateWidgetDrop(ItemInfo info, CellLayout cellLayout, final DragView dragView, final Runnable onCompleteRunnable, int animationType, final View finalView, boolean external) { Rect from = new Rect(); @@ -3662,7 +3659,7 @@ public class Workspace extends PagedView float scaleXY[] = new float[2]; boolean scalePreview = !(info instanceof PendingAddShortcutInfo); getFinalPositionForDropAnimation(finalPos, scaleXY, dragView, cellLayout, info, mTargetCell, - external, scalePreview); + scalePreview); Resources res = mLauncher.getResources(); final int duration = res.getInteger(R.integer.config_dropAnimMaxDuration) - 200; @@ -3686,7 +3683,7 @@ public class Workspace extends PagedView if (animationType == ANIMATE_INTO_POSITION_AND_REMAIN) { endStyle = DragLayer.ANIMATION_END_REMAIN_VISIBLE; } else { - endStyle = DragLayer.ANIMATION_END_DISAPPEAR;; + endStyle = DragLayer.ANIMATION_END_DISAPPEAR; } Runnable onComplete = new Runnable() { -- cgit v1.2.3