Search in sources :

Example 36 with Direction

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction in project android_packages_apps_Launcher3 by crdroidandroid.

the class CellLayout method rearrangementExists.

private boolean rearrangementExists(int cellX, int cellY, int spanX, int spanY, int[] direction, View ignoreView, ItemConfiguration solution) {
    // Return early if get invalid cell positions
    if (cellX < 0 || cellY < 0)
        return false;
    mIntersectingViews.clear();
    mOccupiedRect.set(cellX, cellY, cellX + spanX, cellY + spanY);
    // Mark the desired location of the view currently being dragged.
    if (ignoreView != null) {
        CellAndSpan c = solution.map.get(ignoreView);
        if (c != null) {
            c.cellX = cellX;
            c.cellY = cellY;
        }
    }
    Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY);
    Rect r1 = new Rect();
    for (View child : solution.map.keySet()) {
        if (child == ignoreView)
            continue;
        CellAndSpan c = solution.map.get(child);
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        r1.set(c.cellX, c.cellY, c.cellX + c.spanX, c.cellY + c.spanY);
        if (Rect.intersects(r0, r1)) {
            if (!lp.canReorder) {
                return false;
            }
            mIntersectingViews.add(child);
        }
    }
    solution.intersectingViews = new ArrayList<>(mIntersectingViews);
    // without also displacing that item.
    if (attemptPushInDirection(mIntersectingViews, mOccupiedRect, direction, ignoreView, solution)) {
        return true;
    }
    // Next we try moving the views as a block, but without requiring the push mechanic.
    if (addViewsToTempLocation(mIntersectingViews, mOccupiedRect, direction, ignoreView, solution)) {
        return true;
    }
    // Ok, they couldn't move as a block, let's move them individually
    for (View v : mIntersectingViews) {
        if (!addViewToTempLocation(v, mOccupiedRect, direction, solution)) {
            return false;
        }
    }
    return true;
}
Also used : Rect(android.graphics.Rect) CellAndSpan(com.android.launcher3.util.CellAndSpan) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView)

Example 37 with Direction

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction in project android_packages_apps_Launcher3 by crdroidandroid.

the class CellLayout method addViewToTempLocation.

private boolean addViewToTempLocation(View v, Rect rectOccupiedByPotentialDrop, int[] direction, ItemConfiguration currentState) {
    CellAndSpan c = currentState.map.get(v);
    boolean success = false;
    mTmpOccupied.markCells(c, false);
    mTmpOccupied.markCells(rectOccupiedByPotentialDrop, true);
    findNearestArea(c.cellX, c.cellY, c.spanX, c.spanY, direction, mTmpOccupied.cells, null, mTempLocation);
    if (mTempLocation[0] >= 0 && mTempLocation[1] >= 0) {
        c.cellX = mTempLocation[0];
        c.cellY = mTempLocation[1];
        success = true;
    }
    mTmpOccupied.markCells(c, true);
    return success;
}
Also used : CellAndSpan(com.android.launcher3.util.CellAndSpan)

Example 38 with Direction

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

the class CellLayout method rearrangementExists.

private boolean rearrangementExists(int cellX, int cellY, int spanX, int spanY, int[] direction, View ignoreView, ItemConfiguration solution) {
    // Return early if get invalid cell positions
    if (cellX < 0 || cellY < 0)
        return false;
    mIntersectingViews.clear();
    mOccupiedRect.set(cellX, cellY, cellX + spanX, cellY + spanY);
    // Mark the desired location of the view currently being dragged.
    if (ignoreView != null) {
        CellAndSpan c = solution.map.get(ignoreView);
        if (c != null) {
            c.cellX = cellX;
            c.cellY = cellY;
        }
    }
    Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY);
    Rect r1 = new Rect();
    for (View child : solution.map.keySet()) {
        if (child == ignoreView)
            continue;
        CellAndSpan c = solution.map.get(child);
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        r1.set(c.cellX, c.cellY, c.cellX + c.spanX, c.cellY + c.spanY);
        if (Rect.intersects(r0, r1)) {
            if (!lp.canReorder) {
                return false;
            }
            mIntersectingViews.add(child);
        }
    }
    solution.intersectingViews = new ArrayList<>(mIntersectingViews);
    // without also displacing that item.
    if (attemptPushInDirection(mIntersectingViews, mOccupiedRect, direction, ignoreView, solution)) {
        return true;
    }
    // Next we try moving the views as a block, but without requiring the push mechanic.
    if (addViewsToTempLocation(mIntersectingViews, mOccupiedRect, direction, ignoreView, solution)) {
        return true;
    }
    // Ok, they couldn't move as a block, let's move them individually
    for (View v : mIntersectingViews) {
        if (!addViewToTempLocation(v, mOccupiedRect, direction, solution)) {
            return false;
        }
    }
    return true;
}
Also used : Rect(android.graphics.Rect) CellAndSpan(com.android.launcher3.util.CellAndSpan) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView)

Example 39 with Direction

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

the class UserEventDispatcher method logTaskLaunchOrDismiss.

@Deprecated
public void logTaskLaunchOrDismiss(int action, int direction, int taskIndex, ComponentKey componentKey) {
    LauncherEvent event = newLauncherEvent(// TAP or SWIPE or FLING
    newTouchAction(action), newTarget(Target.Type.ITEM));
    if (action == Action.Touch.SWIPE || action == Action.Touch.FLING) {
        // Direction DOWN means the task was launched, UP means it was dismissed.
        event.action.dir = direction;
    }
    event.srcTarget[0].itemType = LauncherLogProto.ItemType.TASK;
    event.srcTarget[0].pageIndex = taskIndex;
    fillComponentInfo(event.srcTarget[0], componentKey.componentName);
    dispatchUserEvent(event, null);
    mAppOrTaskLaunch = true;
}
Also used : LauncherEvent(com.android.launcher3.userevent.nano.LauncherLogProto.LauncherEvent) LoggerUtils.newLauncherEvent(com.android.launcher3.logging.LoggerUtils.newLauncherEvent)

Example 40 with Direction

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction in project android_packages_apps_Trebuchet by LineageOS.

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) {
    if (!mViewsBound) {
        return;
    }
    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) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) SuppressLint(android.annotation.SuppressLint)

Aggregations

View (android.view.View)34 CellAndSpan (com.android.launcher3.util.CellAndSpan)28 Rect (android.graphics.Rect)26 SuppressLint (android.annotation.SuppressLint)25 Point (android.graphics.Point)18 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)18 DraggableView (com.android.launcher3.dragndrop.DraggableView)15 Paint (android.graphics.Paint)14 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)12 PagedView (com.android.launcher3.PagedView)12 PagedOrientationHandler (com.android.launcher3.touch.PagedOrientationHandler)11 BubbleTextView (com.android.launcher3.BubbleTextView)7 CellLayout (com.android.launcher3.CellLayout)7 GridOccupancy (com.android.launcher3.util.GridOccupancy)7 BaseDragLayer (com.android.launcher3.views.BaseDragLayer)7 RecentsView (com.android.quickstep.views.RecentsView)7 Interpolator (android.view.animation.Interpolator)6 TaskView (com.android.quickstep.views.TaskView)6 PendingAnimation (com.android.launcher3.anim.PendingAnimation)5 Folder (com.android.launcher3.folder.Folder)5