Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e96798e8 authored by Jon Miranda's avatar Jon Miranda
Browse files

Smooth animation when dropping a widget in multi-window mode.

Factored in app widget scaling in methods related to estimating
widget size and positions.
ie. Dropping a widget that needs to be resized to fit in the
workspace.

Bug: 32176631
Change-Id: I106fe12041565a090047f146a07d4bc80a074b4a
parent 8f03c86b
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -951,7 +951,7 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
                lp.tmpCellX = cellX;
                lp.tmpCellY = cellY;
            }
            clc.setupLp(lp);
            clc.setupLp(child);
            lp.isLockedToGrid = false;
            final int newX = lp.x;
            final int newY = lp.y;
@@ -972,7 +972,7 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
            va.addUpdateListener(new AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float r = ((Float) animation.getAnimatedValue()).floatValue();
                    float r = (Float) animation.getAnimatedValue();
                    lp.x = (int) ((1 - r) * oldX + r * newX);
                    lp.y = (int) ((1 - r) * oldY + r * newY);
                    child.requestLayout();
@@ -1027,6 +1027,11 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {

            if (resize) {
                cellToRect(cellX, cellY, spanX, spanY, r);
                if (v instanceof LauncherAppWidgetHostView) {
                    DeviceProfile profile = mLauncher.getDeviceProfile();
                    Utilities.shrinkRectAboutCenter(r, profile.appWidgetScale.x,
                            profile.appWidgetScale.y);
                }
            } else {
                // Find the top left corner of the rect the object will occupy
                final int[] topLeft = mTmpPoint;
@@ -1065,7 +1070,7 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
                r.set(left, top, left + dragOutline.getWidth(), top + dragOutline.getHeight());
            }

            Utilities.scaleRectAboutCenter(r, mChildScale);
            Utilities.shrinkRectAboutCenter(r, mChildScale, mChildScale);
            mDragOutlineAnims[mDragOutlineCurrent].setTag(dragOutline);
            mDragOutlineAnims[mDragOutlineCurrent].animateIn();

@@ -1836,7 +1841,7 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
     * the provided point and the provided cell
     */
    private void computeDirectionVector(float deltaX, float deltaY, int[] result) {
        double angle = Math.atan(((float) deltaY) / deltaX);
        double angle = Math.atan(deltaY / deltaX);

        result[0] = 0;
        result[1] = 0;
@@ -2051,7 +2056,7 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
            va.addUpdateListener(new AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float r = ((Float) animation.getAnimatedValue()).floatValue();
                    float r = (Float) animation.getAnimatedValue();
                    float r1 = (mode == MODE_HINT && repeating) ? 1.0f : r;
                    float x = r1 * finalDeltaX + (1 - r1) * initDeltaX;
                    float y = r1 * finalDeltaY + (1 - r1) * initDeltaY;
+9 −2
Original line number Diff line number Diff line
@@ -86,9 +86,16 @@ public class ShortcutAndWidgetContainer extends ViewGroup {
        }
    }

    public void setupLp(CellLayout.LayoutParams lp) {
    public void setupLp(View child) {
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
        if (child instanceof LauncherAppWidgetHostView) {
            DeviceProfile profile = mLauncher.getDeviceProfile();
            lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX,
                    profile.appWidgetScale.x, profile.appWidgetScale.y);
        } else {
            lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX);
        }
    }

    // Set whether or not to invert the layout horizontally if the layout is in RTL mode.
    public void setInvertIfRtl(boolean invert) {
+11 −12
Original line number Diff line number Diff line
@@ -249,19 +249,18 @@ public final class Utilities {
        return delta;
    }

    public static void scaleRectAboutCenter(Rect r, float scale) {
        if (scale != 1.0f) {
            int cx = r.centerX();
            int cy = r.centerY();
            r.offset(-cx, -cy);
    public static float shrinkRectAboutCenter(Rect r, float scaleX, float scaleY) {
        float scale = Math.min(Math.min(scaleX, scaleY), 1.0f);
        if (scale < 1.0f) {
            int deltaX = (int) (r.width() * (scaleX - scale) * 0.5f);
            r.left += deltaX;
            r.right -= deltaX;

            r.left = (int) (r.left * scale + 0.5f);
            r.top = (int) (r.top * scale + 0.5f);
            r.right = (int) (r.right * scale + 0.5f);
            r.bottom = (int) (r.bottom * scale + 0.5f);

            r.offset(cx, cy);
            int deltaY = (int) (r.height() * (scaleY - scale) * 0.5f);
            r.top += deltaY;
            r.bottom -= deltaY;
        }
        return scale;
    }

    public static void startActivityForResultSafely(
+30 −9
Original line number Diff line number Diff line
@@ -383,17 +383,37 @@ public class Workspace extends PagedView
        mOnStateChangeListener = listener;
    }

    // estimate the size of a widget with spans hSpan, vSpan. return MAX_VALUE for each
    // dimension if unsuccessful
    public int[] estimateItemSize(ItemInfo itemInfo, boolean springLoaded) {
    /**
     * Estimates the size of an item using spans: hSpan, vSpan.
     *
     * @param springLoaded True if we are in spring loaded mode.
     * @param unscaledSize True if caller wants to return the unscaled size
     * @return MAX_VALUE for each dimension if unsuccessful.
     */
    public int[] estimateItemSize(ItemInfo itemInfo, boolean springLoaded, boolean unscaledSize) {
        float shrinkFactor = mLauncher.getDeviceProfile().workspaceSpringLoadShrinkFactor;
        int[] size = new int[2];
        if (getChildCount() > 0) {
            // Use the first non-custom page to estimate the child position
            CellLayout cl = (CellLayout) getChildAt(numCustomPages());
            boolean isWidget = itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;

            Rect r = estimateItemPosition(cl, 0, 0, itemInfo.spanX, itemInfo.spanY);

            float scale = 1;
            if (isWidget) {
                DeviceProfile profile = mLauncher.getDeviceProfile();
                scale = Utilities.shrinkRectAboutCenter(r, profile.appWidgetScale.x,
                        profile.appWidgetScale.y);
            }
            size[0] = r.width();
            size[1] = r.height();

            if (isWidget && unscaledSize) {
                size[0] /= scale;
                size[1] /= scale;
            }

            if (springLoaded) {
                size[0] *= shrinkFactor;
                size[1] *= shrinkFactor;
@@ -3451,7 +3471,7 @@ public class Workspace extends PagedView
    }

    public Bitmap createWidgetBitmap(ItemInfo widgetInfo, View layout) {
        int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(widgetInfo, false);
        int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(widgetInfo, false, true);
        int visibility = layout.getVisibility();
        layout.setVisibility(VISIBLE);

@@ -3477,6 +3497,10 @@ public class Workspace extends PagedView
        int spanY = info.spanY;

        Rect r = estimateItemPosition(layout, targetCell[0], targetCell[1], spanX, spanY);
        if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) {
            DeviceProfile profile = mLauncher.getDeviceProfile();
            Utilities.shrinkRectAboutCenter(r, profile.appWidgetScale.x, profile.appWidgetScale.y);
        }
        loc[0] = r.left;
        loc[1] = r.top;

@@ -3488,11 +3512,8 @@ public class Workspace extends PagedView
        float dragViewScaleX = 1f;
        float dragViewScaleY = 1f;
        if (scale) {
            float width = info.spanX * layout.mCellWidth;
            float height = info.spanY * layout.mCellHeight;

            dragViewScaleX = r.width() / width;
            dragViewScaleY = r.height() / height;
            dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth();
            dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight();
        }

        // The animation will scale the dragView about its center, so we need to center about
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public class ExternalDragPreviewProvider extends DragPreviewProvider {
        mLauncher = launcher;
        mAddInfo = addInfo;

        mOutlineSize = mLauncher.getWorkspace().estimateItemSize(mAddInfo, false);
        mOutlineSize = mLauncher.getWorkspace().estimateItemSize(mAddInfo, false, false);
    }

    public Rect getPreviewBounds() {
Loading