Search in sources :

Example 1 with Direction

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

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) ClipPathView(com.android.launcher3.views.ClipPathView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) PagedView(com.android.launcher3.PagedView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) SuppressLint(android.annotation.SuppressLint)

Example 2 with Direction

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

the class KeyboardDragAndDropView method getNextSelection.

/**
 * Focus finding logic:
 * Collect all virtual nodes in reading order (used for forward and backwards).
 * Then find the closest view by comparing the distances spatially. Since it is a move
 * operation. consider all cell sizes to be approximately of the same size.
 */
private VirtualNodeInfo getNextSelection(int direction) {
    // Collect all virtual nodes
    mDelegates.clear();
    mNodes.clear();
    Folder openFolder = Folder.getOpen(mLauncher);
    PagedView pv = openFolder == null ? mLauncher.getWorkspace() : openFolder.getContent();
    int count = pv.getPageCount();
    for (int i = 0; i < count; i++) {
        mDelegates.add(((CellLayout) pv.getChildAt(i)).getDragAndDropAccessibilityDelegate());
    }
    if (openFolder == null) {
        mDelegates.add(pv.getNextPage() + 1, mLauncher.getHotseat().getDragAndDropAccessibilityDelegate());
    }
    mDelegates.forEach(delegate -> {
        mIntList.clear();
        delegate.getVisibleVirtualViews(mIntList);
        mIntList.forEach(id -> mNodes.add(new VirtualNodeInfo(delegate, id)));
    });
    if (mNodes.isEmpty()) {
        return null;
    }
    int index = mNodes.indexOf(mCurrentSelection);
    if (mCurrentSelection == null || index < 0) {
        return null;
    }
    int totalNodes = mNodes.size();
    final ToIntBiFunction<Rect, Rect> majorAxis;
    final ToIntFunction<Rect> minorAxis;
    switch(direction) {
        case View.FOCUS_RIGHT:
            majorAxis = (source, dest) -> dest.left - source.left;
            minorAxis = Rect::centerY;
            break;
        case View.FOCUS_LEFT:
            majorAxis = (source, dest) -> source.left - dest.left;
            minorAxis = Rect::centerY;
            break;
        case View.FOCUS_UP:
            majorAxis = (source, dest) -> source.top - dest.top;
            minorAxis = Rect::centerX;
            break;
        case View.FOCUS_DOWN:
            majorAxis = (source, dest) -> dest.top - source.top;
            minorAxis = Rect::centerX;
            break;
        case View.FOCUS_FORWARD:
            return mNodes.get((index + 1) % totalNodes);
        case View.FOCUS_BACKWARD:
            return mNodes.get((index + totalNodes - 1) % totalNodes);
        default:
            // Unknown direction
            return null;
    }
    mCurrentSelection.populate(mTempNodeInfo).getBoundsInScreen(mTempRect);
    float minWeight = Float.MAX_VALUE;
    VirtualNodeInfo match = null;
    for (int i = 0; i < totalNodes; i++) {
        VirtualNodeInfo node = mNodes.get(i);
        node.populate(mTempNodeInfo).getBoundsInScreen(mTempRect2);
        int majorAxisWeight = majorAxis.applyAsInt(mTempRect, mTempRect2);
        if (majorAxisWeight <= 0) {
            continue;
        }
        int minorAxisWeight = minorAxis.applyAsInt(mTempRect2) - minorAxis.applyAsInt(mTempRect);
        float weight = majorAxisWeight * majorAxisWeight + minorAxisWeight * minorAxisWeight * MINOR_AXIS_WEIGHT;
        if (weight < minWeight) {
            minWeight = weight;
            match = node;
        }
    }
    return match;
}
Also used : Rect(android.graphics.Rect) PagedView(com.android.launcher3.PagedView) Folder(com.android.launcher3.folder.Folder)

Example 3 with Direction

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

the class TaskViewTouchController method reInitAnimationController.

private void reInitAnimationController(boolean goingUp) {
    if (mCurrentAnimation != null && mCurrentAnimationIsGoingUp == goingUp) {
        // No need to init
        return;
    }
    if ((goingUp && !mAllowGoingUp) || (!goingUp && !mAllowGoingDown)) {
        // Trying to re-init in an unsupported direction.
        return;
    }
    if (mCurrentAnimation != null) {
        mCurrentAnimation.setPlayFraction(0);
        mCurrentAnimation.getTarget().removeListener(this);
        mCurrentAnimation.dispatchOnCancel();
    }
    PagedOrientationHandler orientationHandler = mRecentsView.getPagedOrientationHandler();
    mCurrentAnimationIsGoingUp = goingUp;
    BaseDragLayer dl = mActivity.getDragLayer();
    final int secondaryLayerDimension = orientationHandler.getSecondaryDimension(dl);
    long maxDuration = 2 * secondaryLayerDimension;
    int verticalFactor = orientationHandler.getTaskDragDisplacementFactor(mIsRtl);
    int secondaryTaskDimension = orientationHandler.getSecondaryDimension(mTaskBeingDragged);
    // The interpolator controlling the most prominent visual movement. We use this to determine
    // whether we passed SUCCESS_TRANSITION_PROGRESS.
    final Interpolator currentInterpolator;
    PendingAnimation pa;
    if (goingUp) {
        currentInterpolator = Interpolators.LINEAR;
        pa = mRecentsView.createTaskDismissAnimation(mTaskBeingDragged, true, /* animateTaskView */
        true, /* removeTask */
        maxDuration);
        mEndDisplacement = -secondaryTaskDimension;
    } else {
        currentInterpolator = Interpolators.ZOOM_IN;
        pa = mRecentsView.createTaskLaunchAnimation(mTaskBeingDragged, maxDuration, currentInterpolator);
        // Since the thumbnail is what is filling the screen, based the end displacement on it.
        View thumbnailView = mTaskBeingDragged.getThumbnail();
        mTempCords[1] = orientationHandler.getSecondaryDimension(thumbnailView);
        dl.getDescendantCoordRelativeToSelf(thumbnailView, mTempCords);
        mEndDisplacement = secondaryLayerDimension - mTempCords[1];
    }
    mEndDisplacement *= verticalFactor;
    mCurrentAnimation = pa.createPlaybackController();
    // Setting this interpolator doesn't affect the visual motion, but is used to determine
    // whether we successfully reached the target state in onDragEnd().
    mCurrentAnimation.getTarget().setInterpolator(currentInterpolator);
    onUserControlledAnimationCreated(mCurrentAnimation);
    mCurrentAnimation.getTarget().addListener(this);
    mCurrentAnimation.dispatchOnStart();
    mProgressMultiplier = 1 / mEndDisplacement;
}
Also used : BaseDragLayer(com.android.launcher3.views.BaseDragLayer) PendingAnimation(com.android.launcher3.anim.PendingAnimation) PagedOrientationHandler(com.android.launcher3.touch.PagedOrientationHandler) Interpolator(android.view.animation.Interpolator) TaskView(com.android.quickstep.views.TaskView) View(android.view.View) RecentsView(com.android.quickstep.views.RecentsView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView)

Example 4 with Direction

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

the class CellLayout method addViewsToTempLocation.

private boolean addViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop, int[] direction, View dragView, ItemConfiguration currentState) {
    if (views.size() == 0)
        return true;
    boolean success = false;
    Rect boundingRect = new Rect();
    // We construct a rect which represents the entire group of views passed in
    currentState.getBoundingRectForViews(views, boundingRect);
    // Mark the occupied state as false for the group of views we want to move.
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        mTmpOccupied.markCells(c, false);
    }
    GridOccupancy blockOccupied = new GridOccupancy(boundingRect.width(), boundingRect.height());
    int top = boundingRect.top;
    int left = boundingRect.left;
    // for interlocking.
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        blockOccupied.markCells(c.cellX - left, c.cellY - top, c.spanX, c.spanY, true);
    }
    mTmpOccupied.markCells(rectOccupiedByPotentialDrop, true);
    findNearestArea(boundingRect.left, boundingRect.top, boundingRect.width(), boundingRect.height(), direction, mTmpOccupied.cells, blockOccupied.cells, mTempLocation);
    // If we successfuly found a location by pushing the block of views, we commit it
    if (mTempLocation[0] >= 0 && mTempLocation[1] >= 0) {
        int deltaX = mTempLocation[0] - boundingRect.left;
        int deltaY = mTempLocation[1] - boundingRect.top;
        for (View v : views) {
            CellAndSpan c = currentState.map.get(v);
            c.cellX += deltaX;
            c.cellY += deltaY;
        }
        success = true;
    }
    // In either case, we set the occupied array as marked for the location of the views
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        mTmpOccupied.markCells(c, true);
    }
    return success;
}
Also used : Rect(android.graphics.Rect) CellAndSpan(com.android.launcher3.util.CellAndSpan) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) GridOccupancy(com.android.launcher3.util.GridOccupancy) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 5 with Direction

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

the class CellLayout method pushViewsToTempLocation.

private boolean pushViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop, int[] direction, View dragView, ItemConfiguration currentState) {
    ViewCluster cluster = new ViewCluster(views, currentState);
    Rect clusterRect = cluster.getBoundingRect();
    int whichEdge;
    int pushDistance;
    boolean fail = false;
    // the cluster must be shifted.
    if (direction[0] < 0) {
        whichEdge = ViewCluster.LEFT;
        pushDistance = clusterRect.right - rectOccupiedByPotentialDrop.left;
    } else if (direction[0] > 0) {
        whichEdge = ViewCluster.RIGHT;
        pushDistance = rectOccupiedByPotentialDrop.right - clusterRect.left;
    } else if (direction[1] < 0) {
        whichEdge = ViewCluster.TOP;
        pushDistance = clusterRect.bottom - rectOccupiedByPotentialDrop.top;
    } else {
        whichEdge = ViewCluster.BOTTOM;
        pushDistance = rectOccupiedByPotentialDrop.bottom - clusterRect.top;
    }
    // Break early for invalid push distance.
    if (pushDistance <= 0) {
        return false;
    }
    // Mark the occupied state as false for the group of views we want to move.
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        mTmpOccupied.markCells(c, false);
    }
    // We save the current configuration -- if we fail to find a solution we will revert
    // to the initial state. The process of finding a solution modifies the configuration
    // in place, hence the need for revert in the failure case.
    currentState.save();
    // The pushing algorithm is simplified by considering the views in the order in which
    // they would be pushed by the cluster. For example, if the cluster is leading with its
    // left edge, we consider sort the views by their right edge, from right to left.
    cluster.sortConfigurationForEdgePush(whichEdge);
    while (pushDistance > 0 && !fail) {
        for (View v : currentState.sortedViews) {
            // cluster.
            if (!cluster.views.contains(v) && v != dragView) {
                if (cluster.isViewTouchingEdge(v, whichEdge)) {
                    LayoutParams lp = (LayoutParams) v.getLayoutParams();
                    if (!lp.canReorder) {
                        // The push solution includes the all apps button, this is not viable.
                        fail = true;
                        break;
                    }
                    cluster.addView(v);
                    CellAndSpan c = currentState.map.get(v);
                    // Adding view to cluster, mark it as not occupied.
                    mTmpOccupied.markCells(c, false);
                }
            }
        }
        pushDistance--;
        // The cluster has been completed, now we move the whole thing over in the appropriate
        // direction.
        cluster.shift(whichEdge, 1);
    }
    boolean foundSolution = false;
    clusterRect = cluster.getBoundingRect();
    // is to ensure that completed shifted cluster lies completely within the cell layout.
    if (!fail && clusterRect.left >= 0 && clusterRect.right <= mCountX && clusterRect.top >= 0 && clusterRect.bottom <= mCountY) {
        foundSolution = true;
    } else {
        currentState.restore();
    }
    // In either case, we set the occupied array as marked for the location of the views
    for (View v : cluster.views) {
        CellAndSpan c = currentState.map.get(v);
        mTmpOccupied.markCells(c, true);
    }
    return foundSolution;
}
Also used : Rect(android.graphics.Rect) CellAndSpan(com.android.launcher3.util.CellAndSpan) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

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