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

Commit dec3a908 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Updating the preview generation logic so that it aligns better with

the drag source image

> Using common code for pending item drag (WidgetContainerView and PinItemDragListener)
> Adding a shortcut-circuit in Workspace when a pendingItem can create a shortcut
  directly. Previously the multi-window drop was routing through onActivityResult which
  was causing some state information to be lost.

Bug: 33584624
Change-Id: I0259870032185713caa9bff27092dbae6ce91199
parent 5cfd1158
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -229,7 +229,7 @@ public abstract class ButtonDropTarget extends TextView
            }
        };
        dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f,
                mLauncher.getDragController().isExternalDrag() ? 1 : DRAG_VIEW_DROP_DURATION,
                DRAG_VIEW_DROP_DURATION,
                new DecelerateInterpolator(2),
                new LinearInterpolator(), onAnimationEndRunnable,
                DragLayer.ANIMATION_END_DISAPPEAR, null);
+3 −18
Original line number Diff line number Diff line
@@ -101,7 +101,6 @@ import com.android.launcher3.dragndrop.PinItemDragListener;
import com.android.launcher3.dynamicui.ExtractedColors;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.keyboard.CustomActionsPopup;
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
import com.android.launcher3.logging.FileLog;
@@ -111,7 +110,6 @@ import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.pageindicators.PageIndicator;
import com.android.launcher3.popup.PopupContainerWithArrow;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
@@ -836,7 +834,7 @@ public class Launcher extends BaseActivity
    }

    @Override
    public void onActivityResult(
    protected void onActivityResult(
            final int requestCode, final int resultCode, final Intent data) {
        handleActivityResult(requestCode, resultCode, data);
        if (mLauncherCallbacks != null) {
@@ -1459,21 +1457,8 @@ public class Launcher extends BaseActivity

        ShortcutInfo info = null;
        if (Utilities.isAtLeastO()) {
            PinItemRequestCompat request = PinItemRequestCompat.getPinItemRequest(data);
            // request.accept will initiate a shortcutChanged callback. To ensure that the model is
            // consistent, that callback must be processed by the model, after the ShortcutInfo is
            // added to the model. This is guaranteed here the callback comes on the UI thread, and
            // we will add the shortcut on the UI thread as well.
            if (request != null &&
                    request.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_SHORTCUT &&
                    request.isValid() && request.accept()) {
                ShortcutInfoCompat compat = new ShortcutInfoCompat(request.getShortcutInfo());
                info = new ShortcutInfo(compat, this);
                // Apply the unbadged icon and fetch the actual icon asynchronously.
                info.iconBitmap = LauncherIcons
                        .createShortcutIcon(compat, this, false /* badged */);
                getModel().updateAndBindShortcutInfo(info, compat);
            }
            info = LauncherAppsCompat.createShortcutInfoFromPinItemRequest(
                    this, PinItemRequestCompat.getPinItemRequest(data));
        }

        if (info == null) {
+37 −19
Original line number Diff line number Diff line
@@ -2523,7 +2523,7 @@ public class Workspace extends PagedView
        if (d.dragSource != this) {
            final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0],
                    (int) mDragViewVisualCenter[1] };
            onDropExternal(touchXY, d.dragInfo, dropTargetLayout, d);
            onDropExternal(touchXY, dropTargetLayout, d);
        } else if (mDragInfo != null) {
            final View cell = mDragInfo.cell;
            boolean droppedOnOriginalCellDuringTransition = false;
@@ -3226,8 +3226,7 @@ public class Workspace extends PagedView
     * NOTE: This can also be called when we are outside of a drag event, when we want
     * to add an item to one of the workspace screens.
     */
    private void onDropExternal(final int[] touchXY, final ItemInfo dragInfo,
            final CellLayout cellLayout, DragObject d) {
    private void onDropExternal(final int[] touchXY, final CellLayout cellLayout, DragObject d) {
        final Runnable exitSpringLoadedRunnable = new Runnable() {
            @Override
            public void run() {
@@ -3236,7 +3235,15 @@ public class Workspace extends PagedView
            }
        };

        ItemInfo info = dragInfo;
        if (d.dragInfo instanceof PendingAddShortcutInfo) {
            ShortcutInfo si = ((PendingAddShortcutInfo) d.dragInfo)
                    .activityInfo.createShortcutInfo();
            if (si != null) {
                d.dragInfo = si;
            }
        }

        ItemInfo info = d.dragInfo;
        int spanX = info.spanX;
        int spanY = info.spanY;
        if (mDragInfo != null) {
@@ -3255,7 +3262,7 @@ public class Workspace extends PagedView
        }

        if (info instanceof PendingAddItemInfo) {
            final PendingAddItemInfo pendingInfo = (PendingAddItemInfo) dragInfo;
            final PendingAddItemInfo pendingInfo = (PendingAddItemInfo) info;

            boolean findNearestVacantCell = true;
            if (pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
@@ -3318,7 +3325,7 @@ public class Workspace extends PagedView

            int animationStyle = ANIMATE_INTO_POSITION_AND_DISAPPEAR;
            if (isWidget && ((PendingAddWidgetInfo) pendingInfo).info != null &&
                    ((PendingAddWidgetInfo) pendingInfo).info.configure != null) {
                    ((PendingAddWidgetInfo) pendingInfo).getHandler().needsConfigure()) {
                animationStyle = ANIMATE_INTO_POSITION_AND_REMAIN;
            }
            animateWidgetDrop(info, cellLayout, d.dragView, onAnimationCompleteRunnable,
@@ -3433,21 +3440,32 @@ public class Workspace extends PagedView
                mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(layout, loc, true);
        resetTransitionTransform(layout);

        float dragViewScaleX = 1f;
        float dragViewScaleY = 1f;
        if (scale) {
            dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth();
            dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight();
        }
            float dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth();
            float dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight();

            // 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
                    - Math.ceil(layout.getUnusedHorizontalSpace() / 2f);
            loc[1] -= (dragView.getMeasuredHeight() - cellLayoutScale * r.height()) / 2;

            scaleXY[0] = dragViewScaleX * cellLayoutScale;
            scaleXY[1] = dragViewScaleY * cellLayoutScale;
        } else {
            // Since we are not cross-fading the dragView, align the drag view to the
            // final cell position.
            float dragScale = dragView.getInitialScale() * cellLayoutScale;
            loc[0] += (dragScale - 1) * dragView.getWidth() / 2;
            loc[1] += (dragScale - 1) * dragView.getHeight() / 2;
            scaleXY[0] = scaleXY[1] = dragScale;

            // If a dragRegion was provided, offset the final position accordingly.
            Rect dragRegion = dragView.getDragRegion();
            if (dragRegion != null) {
                loc[0] += cellLayoutScale * dragRegion.left;
                loc[1] += cellLayoutScale * dragRegion.top;
            }
        }
    }

    public void animateWidgetDrop(ItemInfo info, CellLayout cellLayout, final DragView dragView,
+38 −0
Original line number Diff line number Diff line
@@ -23,8 +23,12 @@ import android.content.pm.LauncherActivityInfo;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.UserHandle;
import android.support.annotation.Nullable;

import com.android.launcher3.LauncherAppState;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;

import java.util.List;
@@ -75,4 +79,38 @@ public abstract class LauncherAppsCompat {
    public abstract boolean isActivityEnabledForProfile(ComponentName component,
            UserHandle user);
    public abstract List<ShortcutConfigActivityInfo> getCustomShortcutActivityList();

    /**
     * request.accept() will initiate the following flow:
     *      -> go-to-system-process for actual processing (a)
     *      -> callback-to-launcher on UI thread (b)
     *      -> post callback on the worker thread (c)
     *      -> Update model and unpin (in system) any shortcut not in out model. (d)
     *
     * Note that (b) will take at-least one frame as it involves posting callback from binder
     * thread to UI thread.
     * If (d) happens before we add this shortcut to our model, we will end up unpinning
     * the shortcut in the system.
     * Here its the caller's responsibility to add the newly created ShortcutInfo immediately
     * to the model (which may involves a single post-to-worker-thread). That will guarantee
     * that (d) happens after model is updated.
     */
    @Nullable
    public static ShortcutInfo createShortcutInfoFromPinItemRequest(
            Context context, PinItemRequestCompat request) {
        if (request != null &&
                request.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_SHORTCUT &&
                request.isValid() && request.accept()) {
            ShortcutInfoCompat compat = new ShortcutInfoCompat(request.getShortcutInfo());
            ShortcutInfo info = new ShortcutInfo(compat, context);
            // Apply the unbadged icon and fetch the actual icon asynchronously.
            info.iconBitmap = LauncherIcons
                    .createShortcutIcon(compat, context, false /* badged */);
            LauncherAppState.getInstance(context).getModel()
                    .updateAndBindShortcutInfo(info, compat);
            return info;
        } else {
            return null;
        }
    }
}
+0 −4
Original line number Diff line number Diff line
@@ -94,10 +94,6 @@ public class PinItemRequestCompat implements Parcelable {
        parcel.writeParcelable(mObject, i);
    }

    public Intent toIntent() {
        return new Intent().putExtra(EXTRA_PIN_ITEM_REQUEST, mObject);
    }

    public static final Parcelable.Creator<PinItemRequestCompat> CREATOR =
            new Parcelable.Creator<PinItemRequestCompat>() {
                public PinItemRequestCompat createFromParcel(Parcel source) {
Loading