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

Commit 69a8eecd authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Simplifying color extraction registration logic

> Calulating correct location irrespective of transient
  state (scale/translation)
> Removing extraction pause/resume logic
> Simplifying location calculation and registration (only use one location instead of a list)

Bug: 194732483
Test: Manual
Change-Id: I255d83761bff5e09c9fb0a5e398d0be0c1d0956f
parent 83ba3336
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -217,7 +217,6 @@ public abstract class ButtonDropTarget extends TextView
        final DragView dragView = d.dragView;
        final Rect to = getIconRect(d);
        final float scale = (float) to.width() / dragView.getMeasuredWidth();
        dragView.disableColorExtraction();
        dragView.detachContentView(/* reattachToPreviousParent= */ true);
        mDropTargetBar.deferOnDragEnd();

@@ -225,9 +224,6 @@ public abstract class ButtonDropTarget extends TextView
            completeDrop(d);
            mDropTargetBar.onDragEnd();
            mLauncher.getStateManager().goToState(NORMAL);
            // Only re-enable updates once the workspace is back to normal, which will be after the
            // current frame.
            post(dragView::resumeColorExtraction);
        };

        dragLayer.animateView(d.dragView, to, scale, 0.1f, 0.1f,
+2 −9
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.launcher3;

import static android.animation.ValueAnimator.areAnimatorsEnabled;

import static com.android.launcher3.Utilities.getBoundsForViewInDragLayer;
import static com.android.launcher3.anim.Interpolators.DEACCEL_1_5;

import android.animation.Animator;
@@ -1071,18 +1070,12 @@ public class CellLayout extends ViewGroup {
        // Apply local extracted color if the DragView is an AppWidgetHostViewDrawable.
        View view = dragObject.dragView.getContentView();
        if (view instanceof LauncherAppWidgetHostView) {
            Launcher launcher = Launcher.getLauncher(dragObject.dragView.getContext());
            Launcher launcher = Launcher.getLauncher(getContext());
            Workspace workspace = launcher.getWorkspace();
            int screenId = workspace.getIdForScreen(this);
            int pageId = workspace.getPageIndexForScreenId(screenId);
            cellToRect(targetCell[0], targetCell[1], spanX, spanY, mTempRect);

            // Now get the rect in drag layer coordinates.
            getBoundsForViewInDragLayer(launcher.getDragLayer(), this, mTempRect, true,
                    mTmpFloatArray, mTempRectF);
            Utilities.setRect(mTempRectF, mTempRect);

            ((LauncherAppWidgetHostView) view).handleDrag(mTempRect, pageId);
            ((LauncherAppWidgetHostView) view).handleDrag(mTempRect, this, screenId);
        }
    }

+4 −0
Original line number Diff line number Diff line
@@ -434,6 +434,10 @@ public class DeviceProfile {
        cellLayoutBorderSpacingPx = isScalableGrid ? borderSpacing : 0;
    }

    public Info getDisplayInfo() {
        return mInfo;
    }

    /**
     * We inset the widget padding added by the system and instead rely on the border spacing
     * between cells to create reliable consistency between widgets
+12 −43
Original line number Diff line number Diff line
@@ -198,7 +198,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
    private final int[] mTempXY = new int[2];
    private final float[] mTempFXY = new float[2];
    @Thunk float[] mDragViewVisualCenter = new float[2];
    private final float[] mTempTouchCoordinates = new float[2];

    private SpringLoadedDragController mSpringLoadedDragController;

@@ -208,8 +207,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>

    private boolean mStripScreensOnPageStopMoving = false;

    private DragPreviewProvider mOutlineProvider = null;

    private boolean mWorkspaceFadeInAdjacentScreens;

    final WallpaperOffsetInterpolator mWallpaperOffset;
@@ -494,7 +491,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
        });

        mDragInfo = null;
        mOutlineProvider = null;
        mDragSourceInternal = null;
    }

@@ -1333,11 +1329,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
                position[0], position[1], 0, null);
    }

    public void prepareDragWithProvider(DragPreviewProvider outlineProvider) {
        mOutlineProvider = outlineProvider;
    }

    private void onStartStateTransition(LauncherState state) {
    private void onStartStateTransition() {
        mIsSwitchingState = true;
        mTransitionProgress = 0;

@@ -1358,7 +1350,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
     */
    @Override
    public void setState(LauncherState toState) {
        onStartStateTransition(toState);
        onStartStateTransition();
        mStateTransitionAnimation.setState(toState);
        onEndStateTransition();
    }
@@ -1369,7 +1361,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
    @Override
    public void setStateWithAnimation(
            LauncherState toState, StateAnimationConfig config, PendingAnimation animation) {
        StateTransitionListener listener = new StateTransitionListener(toState);
        StateTransitionListener listener = new StateTransitionListener();
        mStateTransitionAnimation.setStateWithAnimation(toState, config, animation);

        // Invalidate the pages now, so that we have the visible pages before the
@@ -1478,8 +1470,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
            icon.clearPressedBackground();
        }

        mOutlineProvider = previewProvider;

        if (draggableView == null && child instanceof DraggableView) {
            draggableView = (DraggableView) child;
        }
@@ -1791,17 +1781,14 @@ public class Workspace extends PagedView<WorkspacePageIndicator>

        int snapScreen = -1;
        boolean resizeOnDrop = false;
        Runnable onCompleteRunnable = null;
        if (d.dragSource != this || mDragInfo == null) {
            final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0],
                    (int) mDragViewVisualCenter[1] };
            onDropExternal(touchXY, dropTargetLayout, d);
        } else {
            final View cell = mDragInfo.cell;
            final DragView dragView = d.dragView;
            boolean droppedOnOriginalCellDuringTransition = false;
            Runnable onCompleteRunnable = dragView::resumeColorExtraction;

            dragView.disableColorExtraction();

            if (dropTargetLayout != null && !d.cancelled) {
                // Move internally
@@ -1912,9 +1899,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
                        AppWidgetProviderInfo pInfo = hostView.getAppWidgetInfo();
                        if (pInfo != null && pInfo.resizeMode != AppWidgetProviderInfo.RESIZE_NONE
                                && !options.isAccessibleDrag) {
                            final Runnable previousRunnable = onCompleteRunnable;
                            onCompleteRunnable = () -> {
                                previousRunnable.run();
                                if (!isPageInTransition()) {
                                    AppWidgetResizeFrame.showForWidget(hostView, cellLayout);
                                }
@@ -1983,7 +1968,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
            parent.onDropChild(cell);

            mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY,
                    forSuccessCallback(onCompleteRunnable));
                    onCompleteRunnable == null ? null : forSuccessCallback(onCompleteRunnable));
            mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId)
                    .log(LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED);
        }
@@ -2301,25 +2286,16 @@ public class Workspace extends PagedView<WorkspacePageIndicator>

        int nextPage = getNextPage();
        if (layout == null && !isPageInTransition()) {
            // Check if the item is dragged over currentPage - 1 page
            mTempTouchCoordinates[0] = Math.min(centerX, d.x);
            mTempTouchCoordinates[1] = d.y;
            layout = verifyInsidePage(nextPage + (mIsRtl ? 1 : -1), mTempTouchCoordinates);
            layout = verifyInsidePage(nextPage + (mIsRtl ? 1 : -1), Math.min(centerX, d.x), d.y);
        }

        if (layout == null && !isPageInTransition()) {
            // Check if the item is dragged over currentPage + 1 page
            mTempTouchCoordinates[0] = Math.max(centerX, d.x);
            mTempTouchCoordinates[1] = d.y;
            layout = verifyInsidePage(nextPage + (mIsRtl ? -1 : 1), mTempTouchCoordinates);
            layout = verifyInsidePage(nextPage + (mIsRtl ? -1 : 1), Math.max(centerX, d.x), d.y);
        }

        // If two panel is enabled, users can also drag items to currentPage + 2
        if (isTwoPanelEnabled() && layout == null && !isPageInTransition()) {
            // Check if the item is dragged over currentPage + 2 page
            mTempTouchCoordinates[0] = Math.max(centerX, d.x);
            mTempTouchCoordinates[1] = d.y;
            layout = verifyInsidePage(nextPage + (mIsRtl ? -2 : 2), mTempTouchCoordinates);
            layout = verifyInsidePage(nextPage + (mIsRtl ? -2 : 2), Math.max(centerX, d.x), d.y);
        }

        // Always pick the current page.
@@ -2337,12 +2313,11 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
    /**
     * Returns the child CellLayout if the point is inside the page coordinates, null otherwise.
     */
    private CellLayout verifyInsidePage(int pageNo, float[] touchXy)  {
    private CellLayout verifyInsidePage(int pageNo, float x, float y) {
        if (pageNo >= 0 && pageNo < getPageCount()) {
            CellLayout cl = (CellLayout) getChildAt(pageNo);
            mapPointFromSelfToChild(cl, touchXy);
            if (touchXy[0] >= 0 && touchXy[0] <= cl.getWidth() &&
                    touchXy[1] >= 0 && touchXy[1] <= cl.getHeight()) {
            if (x >= cl.getLeft() && x <= cl.getRight()
                    && y >= cl.getTop() && y <= cl.getBottom()) {
                // This point is inside the cell layout
                return cl;
            }
@@ -3341,12 +3316,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
    private class StateTransitionListener extends AnimatorListenerAdapter
            implements AnimatorUpdateListener {

        private final LauncherState mToState;

        StateTransitionListener(LauncherState toState) {
            mToState = toState;
        }

        @Override
        public void onAnimationUpdate(ValueAnimator anim) {
            mTransitionProgress = anim.getAnimatedFraction();
@@ -3354,7 +3323,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>

        @Override
        public void onAnimationStart(Animator animation) {
            onStartStateTransition(mToState);
            onStartStateTransition();
        }

        @Override
+0 −29
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.util.RunnableList;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.BaseDragLayer;
import com.android.launcher3.widget.LauncherAppWidgetHostView;

/** A custom view for rendering an icon, folder, shortcut or widget during drag-n-drop. */
public abstract class DragView<T extends Context & ActivityContext> extends FrameLayout {
@@ -289,16 +288,6 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
        mOnDragStartCallback.executeAllAndDestroy();
    }

    // TODO(b/183609936): This is only for LauncherAppWidgetHostView that is rendered in a drawable.
    // Once LauncherAppWidgetHostView is directly rendered in this view, removes this method.
    @Override
    public void invalidate() {
        super.invalidate();
        if (mContent instanceof ImageView) {
            mContent.invalidate();
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(makeMeasureSpec(mWidth, EXACTLY), makeMeasureSpec(mHeight, EXACTLY));
@@ -473,24 +462,6 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
        }
    }

    /**
     * If the drag view uses color extraction, block it.
     */
    public void disableColorExtraction() {
        if (mContent instanceof LauncherAppWidgetHostView) {
            ((LauncherAppWidgetHostView) mContent).disableColorExtraction();
        }
    }

    /**
     * If the drag view uses color extraction, restores it.
     */
    public void resumeColorExtraction() {
        if (mContent instanceof LauncherAppWidgetHostView) {
            ((LauncherAppWidgetHostView) mContent).enableColorExtraction(/* updateColors= */ false);
        }
    }

    /**
     * Removes this view from the {@link DragLayer}.
     *
Loading