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

Commit 25e37a85 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Correct color extraction on App Widget drop." into sc-dev

parents eead98d4 43e17301
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -20,15 +20,12 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;

import static com.android.launcher3.LauncherState.NORMAL;

import android.animation.AnimatorSet;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Property;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@@ -40,6 +37,7 @@ import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.model.data.ItemInfo;

/**
@@ -212,18 +210,23 @@ public abstract class ButtonDropTarget extends TextView
            return;
        }
        final DragLayer dragLayer = mLauncher.getDragLayer();
        final DragView dragView = d.dragView;
        final Rect from = new Rect();
        dragLayer.getViewRectRelativeToSelf(d.dragView, from);

        final Rect to = getIconRect(d);
        final float scale = (float) to.width() / from.width();
        d.dragView.detachContentView(/* reattachToPreviousParent= */ true);
        dragView.disableColorExtraction();
        dragView.detachContentView(/* reattachToPreviousParent= */ true);
        mDropTargetBar.deferOnDragEnd();

        Runnable onAnimationEndRunnable = () -> {
            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, from, to, scale, 1f, 1f, 0.1f, 0.1f,
+7 −2
Original line number Diff line number Diff line
@@ -1786,8 +1786,11 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
            onDropExternal(touchXY, dropTargetLayout, d);
        } else {
            final View cell = mDragInfo.cell;
            final DragView dragView = d.dragView;
            boolean droppedOnOriginalCellDuringTransition = false;
            Runnable onCompleteRunnable = null;
            Runnable onCompleteRunnable = dragView::resumeColorExtraction;

            dragView.disableColorExtraction();

            if (dropTargetLayout != null && !d.cancelled) {
                // Move internally
@@ -1898,7 +1901,9 @@ 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);
                                }
@@ -1967,7 +1972,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
            parent.onDropChild(cell);

            mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY,
                    onCompleteRunnable == null ? null : forSuccessCallback(onCompleteRunnable));
                    forSuccessCallback(onCompleteRunnable));
            mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId)
                    .log(LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED);
        }
+19 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import com.android.launcher3.statemanager.StateManager.StateListener;
import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.Thunk;
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 class DragView extends FrameLayout implements StateListener<LauncherState> {
@@ -490,6 +491,24 @@ public class DragView extends FrameLayout implements StateListener<LauncherState
        }
    }

    /**
     * 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}.
     *
+35 −7
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
    private long mDeferUpdatesUntilMillis = 0;
    private RemoteViews mDeferredRemoteViews;
    private Optional<SparseIntArray> mDeferredColorChange = Optional.empty();
    private boolean mEnableColorExtraction = true;

    public LauncherAppWidgetHostView(Context context) {
        super(context);
@@ -342,13 +343,7 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
        }

        mIsScrollable = checkScrollableRecursively(this);
        if (!mIsInDragMode && getTag() instanceof LauncherAppWidgetInfo) {

            LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) getTag();
            mDragLayerRelativeCoordinateHelper.viewToRect(this, mCurrentWidgetSize);
            updateColorExtraction(mCurrentWidgetSize,
                    mWorkspace.getPageIndexForScreenId(info.screenId));
        }
        updateColorExtraction();

        enforceRoundedCorners();
    }
@@ -377,6 +372,7 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
     * @param pageId The workspace page the widget is on.
     */
    private void updateColorExtraction(Rect rectInDragLayer, int pageId) {
        if (!mEnableColorExtraction) return;
        mColorExtractor.getExtractedRectForViewRect(mLauncher, pageId, rectInDragLayer, mTempRectF);

        if (mTempRectF.isEmpty()) {
@@ -391,6 +387,38 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
        }
    }

    /**
     * Update the color extraction, using the current position of the app widget.
     */
    private void updateColorExtraction() {
        if (!mIsInDragMode && getTag() instanceof LauncherAppWidgetInfo) {
            LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) getTag();
            mDragLayerRelativeCoordinateHelper.viewToRect(this, mCurrentWidgetSize);
            updateColorExtraction(mCurrentWidgetSize,
                    mWorkspace.getPageIndexForScreenId(info.screenId));
        }
    }

    /**
     * Enables the local color extraction.
     *
     * @param updateColors If true, this will update the color extraction using the current location
     *                    of the App Widget.
     */
    public void enableColorExtraction(boolean updateColors) {
        mEnableColorExtraction = true;
        if (updateColors) {
            updateColorExtraction();
        }
    }

    /**
     * Disables the local color extraction.
     */
    public void disableColorExtraction() {
        mEnableColorExtraction = false;
    }

    // Compare two location rectangles. Locations are always in the [0;1] range.
    private static boolean isSameLocation(@NonNull RectF rect1, @Nullable RectF rect2,
            float epsilon) {