Search in sources :

Example 61 with Target

use of com.android.launcher3.userevent.nano.LauncherLogProto.Target in project Neo-Launcher by NeoApplications.

the class Folder method onDrop.

@Override
public void onDrop(DragObject d, DragOptions options) {
    // the target location again such that the icon is placed of the final page.
    if (!mContent.rankOnCurrentPage(mEmptyCellRank)) {
        // Reorder again.
        mTargetRank = getTargetRank(d, null);
        // Rearrange items immediately.
        mReorderAlarmListener.onAlarm(mReorderAlarm);
        mOnScrollHintAlarm.cancelAlarm();
        mScrollPauseAlarm.cancelAlarm();
    }
    mContent.completePendingPageChanges();
    PendingAddShortcutInfo pasi = d.dragInfo instanceof PendingAddShortcutInfo ? (PendingAddShortcutInfo) d.dragInfo : null;
    WorkspaceItemInfo pasiSi = pasi != null ? pasi.activityInfo.createWorkspaceItemInfo() : null;
    if (pasi != null && pasiSi == null) {
        // There is no WorkspaceItemInfo, so we have to go through a configuration activity.
        pasi.container = mInfo.id;
        pasi.rank = mEmptyCellRank;
        mLauncher.addPendingItem(pasi, pasi.container, pasi.screenId, null, pasi.spanX, pasi.spanY);
        d.deferDragViewCleanupPostAnimation = false;
        mRearrangeOnClose = true;
    } else {
        final WorkspaceItemInfo si;
        if (pasiSi != null) {
            si = pasiSi;
        } else if (d.dragInfo instanceof AppInfo) {
            // Came from all apps -- make a copy.
            si = ((AppInfo) d.dragInfo).makeWorkspaceItem();
        } else {
            // WorkspaceItemInfo
            si = (WorkspaceItemInfo) d.dragInfo;
        }
        View currentDragView;
        if (mIsExternalDrag) {
            currentDragView = mContent.createAndAddViewForRank(si, mEmptyCellRank);
            // Actually move the item in the database if it was an external drag. Call this
            // before creating the view, so that WorkspaceItemInfo is updated appropriately.
            mLauncher.getModelWriter().addOrMoveItemInDatabase(si, mInfo.id, 0, si.cellX, si.cellY);
            mIsExternalDrag = false;
        } else {
            currentDragView = mCurrentDragView;
            mContent.addViewForRank(currentDragView, si, mEmptyCellRank);
        }
        if (d.dragView.hasDrawn()) {
            // Temporarily reset the scale such that the animation target gets calculated
            // correctly.
            float scaleX = getScaleX();
            float scaleY = getScaleY();
            setScaleX(1.0f);
            setScaleY(1.0f);
            mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, currentDragView, null);
            setScaleX(scaleX);
            setScaleY(scaleY);
        } else {
            d.deferDragViewCleanupPostAnimation = false;
            currentDragView.setVisibility(VISIBLE);
        }
        mItemsInvalidated = true;
        rearrangeChildren();
        // Temporarily suppress the listener, as we did all the work already here.
        try (SuppressInfoChanges s = new SuppressInfoChanges()) {
            mInfo.add(si, mEmptyCellRank, false);
        }
        // #onDropCompleted.
        if (d.dragSource != this) {
            updateItemLocationsInDatabaseBatch();
        }
    }
    // Clear the drag info, as it is no longer being dragged.
    mDragInProgress = false;
    if (mContent.getPageCount() > 1) {
        // The animation has already been shown while opening the folder.
        mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncher.getModelWriter());
    }
    mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
    if (d.stateAnnouncer != null) {
        d.stateAnnouncer.completeAction(R.string.item_moved);
    }
}
Also used : PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) ClipPathView(com.android.launcher3.views.ClipPathView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PagedView(com.android.launcher3.PagedView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) AppInfo(com.android.launcher3.AppInfo)

Example 62 with Target

use of com.android.launcher3.userevent.nano.LauncherLogProto.Target in project Neo-Launcher by NeoApplications.

the class Folder method onDropCompleted.

@Override
public void onDropCompleted(final View target, final DragObject d, final boolean success) {
    if (success) {
        if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon && target != this) {
            replaceFolderWithFinalItem();
        }
    } else {
        // The drag failed, we need to return the item to the folder
        WorkspaceItemInfo info = (WorkspaceItemInfo) d.dragInfo;
        View icon = (mCurrentDragView != null && mCurrentDragView.getTag() == info) ? mCurrentDragView : mContent.createNewView(info);
        ArrayList<View> views = getIconsInReadingOrder();
        views.add(info.rank, icon);
        mContent.arrangeChildren(views);
        mItemsInvalidated = true;
        try (SuppressInfoChanges s = new SuppressInfoChanges()) {
            mFolderIcon.onDrop(d, true);
        }
    }
    if (target != this) {
        if (mOnExitAlarm.alarmPending()) {
            mOnExitAlarm.cancelAlarm();
            if (!success) {
                mSuppressFolderDeletion = true;
            }
            mScrollPauseAlarm.cancelAlarm();
            completeDragExit();
        }
    }
    mDeleteFolderOnDropCompleted = false;
    mDragInProgress = false;
    mItemAddedBackToSelfViaIcon = false;
    mCurrentDragView = null;
    // Reordering may have occured, and we need to save the new item locations. We do this once
    // at the end to prevent unnecessary database operations.
    updateItemLocationsInDatabaseBatch();
    // been refreshed yet.
    if (getItemCount() <= mContent.itemsPerPage()) {
        // Show the animation, next time something is added to the folder.
        mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, false, mLauncher.getModelWriter());
    }
}
Also used : ClipPathView(com.android.launcher3.views.ClipPathView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PagedView(com.android.launcher3.PagedView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

Example 63 with Target

use of com.android.launcher3.userevent.nano.LauncherLogProto.Target in project Neo-Launcher by NeoApplications.

the class FolderPagedView method realTimeReorder.

/**
 * Reorders the items such that the {@param empty} spot moves to {@param target}
 */
public void realTimeReorder(int empty, int target) {
    completePendingPageChanges();
    int delay = 0;
    float delayAmount = START_VIEW_REORDER_DELAY;
    // Animation only happens on the current page.
    int pageToAnimate = getNextPage();
    int maxItemsPerPage = mOrganizer.getMaxItemsPerPage();
    int pageT = target / maxItemsPerPage;
    int pagePosT = target % maxItemsPerPage;
    if (pageT != pageToAnimate) {
        Log.e(TAG, "Cannot animate when the target cell is invisible");
    }
    int pagePosE = empty % maxItemsPerPage;
    int pageE = empty / maxItemsPerPage;
    int startPos, endPos;
    int moveStart, moveEnd;
    int direction;
    if (target == empty) {
        // No animation
        return;
    } else if (target > empty) {
        // Items will move backwards to make room for the empty cell.
        direction = 1;
        // If empty cell is in a different page, move them instantly.
        if (pageE < pageToAnimate) {
            moveStart = empty;
            // Instantly move the first item in the current page.
            moveEnd = pageToAnimate * maxItemsPerPage;
            // Animate the 2nd item in the current page, as the first item was already moved to
            // the last page.
            startPos = 0;
        } else {
            moveStart = moveEnd = -1;
            startPos = pagePosE;
        }
        endPos = pagePosT;
    } else {
        // The items will move forward.
        direction = -1;
        if (pageE > pageToAnimate) {
            // Move the items immediately.
            moveStart = empty;
            // Instantly move the last item in the current page.
            moveEnd = (pageToAnimate + 1) * maxItemsPerPage - 1;
            // Animations start with the second last item in the page
            startPos = maxItemsPerPage - 1;
        } else {
            moveStart = moveEnd = -1;
            startPos = pagePosE;
        }
        endPos = pagePosT;
    }
    // Instant moving views.
    while (moveStart != moveEnd) {
        int rankToMove = moveStart + direction;
        int p = rankToMove / maxItemsPerPage;
        int pagePos = rankToMove % maxItemsPerPage;
        int x = pagePos % mGridCountX;
        int y = pagePos / mGridCountX;
        final CellLayout page = getPageAt(p);
        final View v = page.getChildAt(x, y);
        if (v != null) {
            if (pageToAnimate != p) {
                page.removeView(v);
                addViewForRank(v, (WorkspaceItemInfo) v.getTag(), moveStart);
            } else {
                // Do a fake animation before removing it.
                final int newRank = moveStart;
                final float oldTranslateX = v.getTranslationX();
                Runnable endAction = new Runnable() {

                    @Override
                    public void run() {
                        mPendingAnimations.remove(v);
                        v.setTranslationX(oldTranslateX);
                        ((CellLayout) v.getParent().getParent()).removeView(v);
                        addViewForRank(v, (WorkspaceItemInfo) v.getTag(), newRank);
                    }
                };
                v.animate().translationXBy((direction > 0 ^ mIsRtl) ? -v.getWidth() : v.getWidth()).setDuration(REORDER_ANIMATION_DURATION).setStartDelay(0).withEndAction(endAction);
                mPendingAnimations.put(v, endAction);
            }
        }
        moveStart = rankToMove;
    }
    if ((endPos - startPos) * direction <= 0) {
        // No animation
        return;
    }
    CellLayout page = getPageAt(pageToAnimate);
    for (int i = startPos; i != endPos; i += direction) {
        int nextPos = i + direction;
        View v = page.getChildAt(nextPos % mGridCountX, nextPos / mGridCountX);
        if (page.animateChildToPosition(v, i % mGridCountX, i / mGridCountX, REORDER_ANIMATION_DURATION, delay, true, true)) {
            delay += delayAmount;
            delayAmount *= VIEW_REORDER_DELAY_FACTOR;
        }
    }
}
Also used : CellLayout(com.android.launcher3.CellLayout) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) PagedView(com.android.launcher3.PagedView) SuppressLint(android.annotation.SuppressLint)

Example 64 with Target

use of com.android.launcher3.userevent.nano.LauncherLogProto.Target in project Neo-Launcher by NeoApplications.

the class UserEventDispatcher method fillInLogContainerData.

/**
 * Fills in the container data on the given event if the given view is not null.
 *
 * @return whether container data was added.
 */
public boolean fillInLogContainerData(LauncherLogProto.LauncherEvent event, @Nullable View v) {
    // Fill in grid(x,y), pageIndex of the child and container type of the parent
    LogContainerProvider provider = StatsLogUtils.getLaunchProviderRecursive(v);
    if (v == null || !(v.getTag() instanceof ItemInfo) || provider == null) {
        return false;
    }
    final ItemInfo itemInfo = (ItemInfo) v.getTag();
    final Target target = event.srcTarget[0];
    final Target targetParent = event.srcTarget[1];
    onFillInLogContainerData(itemInfo, target, targetParent);
    provider.fillInLogContainerData(v, itemInfo, target, targetParent);
    return true;
}
Also used : LoggerUtils.newTarget(com.android.launcher3.logging.LoggerUtils.newTarget) Target(com.android.launcher3.userevent.nano.LauncherLogProto.Target) LoggerUtils.newControlTarget(com.android.launcher3.logging.LoggerUtils.newControlTarget) LoggerUtils.newItemTarget(com.android.launcher3.logging.LoggerUtils.newItemTarget) DropTarget(com.android.launcher3.DropTarget) LoggerUtils.newContainerTarget(com.android.launcher3.logging.LoggerUtils.newContainerTarget) LoggerUtils.newDropTarget(com.android.launcher3.logging.LoggerUtils.newDropTarget) ItemInfo(com.android.launcher3.ItemInfo) LogContainerProvider(com.android.launcher3.logging.StatsLogUtils.LogContainerProvider)

Example 65 with Target

use of com.android.launcher3.userevent.nano.LauncherLogProto.Target in project Neo-Launcher by NeoApplications.

the class UserEventDispatcher method logActionOnItem.

/**
 * Creates new {@link LauncherEvent} of ITEM target type with input arguments and dispatches it.
 *
 * @param touchAction ENUM value of {@link LauncherLogProto.Action.Touch} Action
 * @param dir         ENUM value of {@link LauncherLogProto.Action.Direction} Action
 * @param itemType    ENUM value of {@link LauncherLogProto.ItemType}
 * @param gridX       Nullable X coordinate of item's position on the workspace grid
 * @param gridY       Nullable Y coordinate of item's position on the workspace grid
 */
public void logActionOnItem(int touchAction, int dir, int itemType, @Nullable Integer gridX, @Nullable Integer gridY) {
    Target itemTarget = newTarget(Target.Type.ITEM);
    itemTarget.itemType = itemType;
    ofNullable(gridX).ifPresent(value -> itemTarget.gridX = value);
    ofNullable(gridY).ifPresent(value -> itemTarget.gridY = value);
    LauncherEvent event = newLauncherEvent(newTouchAction(touchAction), itemTarget);
    event.action.dir = dir;
    dispatchUserEvent(event, null);
}
Also used : LoggerUtils.newTarget(com.android.launcher3.logging.LoggerUtils.newTarget) Target(com.android.launcher3.userevent.nano.LauncherLogProto.Target) LoggerUtils.newControlTarget(com.android.launcher3.logging.LoggerUtils.newControlTarget) LoggerUtils.newItemTarget(com.android.launcher3.logging.LoggerUtils.newItemTarget) DropTarget(com.android.launcher3.DropTarget) LoggerUtils.newContainerTarget(com.android.launcher3.logging.LoggerUtils.newContainerTarget) LoggerUtils.newDropTarget(com.android.launcher3.logging.LoggerUtils.newDropTarget) LauncherEvent(com.android.launcher3.userevent.nano.LauncherLogProto.LauncherEvent) LoggerUtils.newLauncherEvent(com.android.launcher3.logging.LoggerUtils.newLauncherEvent)

Aggregations

View (android.view.View)85 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)59 Point (android.graphics.Point)42 Rect (android.graphics.Rect)41 AppWidgetHostView (android.appwidget.AppWidgetHostView)40 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)38 ItemInfo (com.android.launcher3.model.data.ItemInfo)37 Animator (android.animation.Animator)35 ValueAnimator (android.animation.ValueAnimator)35 Target (com.android.launcher3.userevent.nano.LauncherLogProto.Target)35 BubbleTextView (com.android.launcher3.BubbleTextView)34 DropTarget (com.android.launcher3.DropTarget)32 DragView (com.android.launcher3.dragndrop.DragView)30 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)30 AnimatorSet (android.animation.AnimatorSet)29 RemoteAnimationTargetCompat (com.android.systemui.shared.system.RemoteAnimationTargetCompat)29 ComponentName (android.content.ComponentName)28 ObjectAnimator (android.animation.ObjectAnimator)27 DraggableView (com.android.launcher3.dragndrop.DraggableView)26 AppInfo (com.android.launcher3.model.data.AppInfo)26