Search in sources :

Example 6 with SnapTarget

use of com.android.internal.policy.DividerSnapAlgorithm.SnapTarget in project platform_frameworks_base by android.

the class TaskStack method snapDockedStackAfterRotation.

/**
     * Snaps the bounds after rotation to the closest snap target for the docked stack.
     */
private void snapDockedStackAfterRotation(Rect outBounds) {
    // Calculate the current position.
    final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
    final int dividerSize = mService.getDefaultDisplayContentLocked().getDockedDividerController().getContentWidth();
    final int dockSide = getDockSide(outBounds);
    final int dividerPosition = DockedDividerUtils.calculatePositionForBounds(outBounds, dockSide, dividerSize);
    final int displayWidth = mDisplayContent.getDisplayInfo().logicalWidth;
    final int displayHeight = mDisplayContent.getDisplayInfo().logicalHeight;
    // Snap the position to a target.
    final int rotation = displayInfo.rotation;
    final int orientation = mService.mCurConfiguration.orientation;
    mService.mPolicy.getStableInsetsLw(rotation, displayWidth, displayHeight, outBounds);
    final DividerSnapAlgorithm algorithm = new DividerSnapAlgorithm(mService.mContext.getResources(), displayWidth, displayHeight, dividerSize, orientation == Configuration.ORIENTATION_PORTRAIT, outBounds);
    final SnapTarget target = algorithm.calculateNonDismissingSnapTarget(dividerPosition);
    // Recalculate the bounds based on the position of the target.
    DockedDividerUtils.calculateBoundsForPosition(target.position, dockSide, outBounds, displayInfo.logicalWidth, displayInfo.logicalHeight, dividerSize);
}
Also used : DisplayInfo(android.view.DisplayInfo) DividerSnapAlgorithm(com.android.internal.policy.DividerSnapAlgorithm) SnapTarget(com.android.internal.policy.DividerSnapAlgorithm.SnapTarget)

Example 7 with SnapTarget

use of com.android.internal.policy.DividerSnapAlgorithm.SnapTarget in project android_frameworks_base by ResurrectionRemix.

the class DividerView method applyDismissingParallax.

/**
     * Applies a parallax to the task when dismissing.
     */
private void applyDismissingParallax(Rect taskRect, int dockSide, SnapTarget snapTarget, int position, int taskPosition) {
    float fraction = Math.min(1, Math.max(0, mSnapAlgorithm.calculateDismissingFraction(position)));
    SnapTarget dismissTarget = null;
    SnapTarget splitTarget = null;
    int start = 0;
    if (position <= mSnapAlgorithm.getLastSplitTarget().position && dockSideTopLeft(dockSide)) {
        dismissTarget = mSnapAlgorithm.getDismissStartTarget();
        splitTarget = mSnapAlgorithm.getFirstSplitTarget();
        start = taskPosition;
    } else if (position >= mSnapAlgorithm.getLastSplitTarget().position && dockSideBottomRight(dockSide)) {
        dismissTarget = mSnapAlgorithm.getDismissEndTarget();
        splitTarget = mSnapAlgorithm.getLastSplitTarget();
        start = splitTarget.position;
    }
    if (dismissTarget != null && fraction > 0f && isDismissing(splitTarget, position, dockSide)) {
        fraction = calculateParallaxDismissingFraction(fraction, dockSide);
        int offsetPosition = (int) (start + fraction * (dismissTarget.position - splitTarget.position));
        int width = taskRect.width();
        int height = taskRect.height();
        switch(dockSide) {
            case WindowManager.DOCKED_LEFT:
                taskRect.left = offsetPosition - width;
                taskRect.right = offsetPosition;
                break;
            case WindowManager.DOCKED_RIGHT:
                taskRect.left = offsetPosition + mDividerSize;
                taskRect.right = offsetPosition + width + mDividerSize;
                break;
            case WindowManager.DOCKED_TOP:
                taskRect.top = offsetPosition - height;
                taskRect.bottom = offsetPosition;
                break;
            case WindowManager.DOCKED_BOTTOM:
                taskRect.top = offsetPosition + mDividerSize;
                taskRect.bottom = offsetPosition + height + mDividerSize;
                break;
        }
    }
}
Also used : SnapTarget(com.android.internal.policy.DividerSnapAlgorithm.SnapTarget)

Example 8 with SnapTarget

use of com.android.internal.policy.DividerSnapAlgorithm.SnapTarget in project android_frameworks_base by ResurrectionRemix.

the class DividerView method fling.

private void fling(int position, float velocity, boolean avoidDismissStart, boolean logMetrics) {
    SnapTarget snapTarget = mSnapAlgorithm.calculateSnapTarget(position, velocity);
    if (avoidDismissStart && snapTarget == mSnapAlgorithm.getDismissStartTarget()) {
        snapTarget = mSnapAlgorithm.getFirstSplitTarget();
    }
    if (logMetrics) {
        logResizeEvent(snapTarget);
    }
    ValueAnimator anim = getFlingAnimator(position, snapTarget, 0);
    mFlingAnimationUtils.apply(anim, position, snapTarget.position, velocity);
    anim.start();
}
Also used : ValueAnimator(android.animation.ValueAnimator) SnapTarget(com.android.internal.policy.DividerSnapAlgorithm.SnapTarget)

Example 9 with SnapTarget

use of com.android.internal.policy.DividerSnapAlgorithm.SnapTarget in project android_frameworks_base by ResurrectionRemix.

the class DividerView method onTouch.

@Override
public boolean onTouch(View v, MotionEvent event) {
    convertToScreenCoordinates(event);
    mGestureDetector.onTouchEvent(event);
    final int action = event.getAction() & MotionEvent.ACTION_MASK;
    switch(action) {
        case MotionEvent.ACTION_DOWN:
            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker.addMovement(event);
            mStartX = (int) event.getX();
            mStartY = (int) event.getY();
            boolean result = startDragging(true, /* animate */
            true);
            if (!result) {
                // Weren't able to start dragging successfully, so cancel it again.
                stopDragging();
            }
            mStartPosition = getCurrentPosition();
            mMoving = false;
            return result;
        case MotionEvent.ACTION_MOVE:
            mVelocityTracker.addMovement(event);
            int x = (int) event.getX();
            int y = (int) event.getY();
            boolean exceededTouchSlop = isHorizontalDivision() && Math.abs(y - mStartY) > mTouchSlop || (!isHorizontalDivision() && Math.abs(x - mStartX) > mTouchSlop);
            if (!mMoving && exceededTouchSlop) {
                mStartX = x;
                mStartY = y;
                mMoving = true;
            }
            if (mMoving && mDockSide != WindowManager.DOCKED_INVALID) {
                SnapTarget snapTarget = mSnapAlgorithm.calculateSnapTarget(mStartPosition, 0, /* velocity */
                false);
                resizeStackDelayed(calculatePosition(x, y), mStartPosition, snapTarget);
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            mVelocityTracker.addMovement(event);
            x = (int) event.getRawX();
            y = (int) event.getRawY();
            mVelocityTracker.computeCurrentVelocity(1000);
            int position = calculatePosition(x, y);
            stopDragging(position, isHorizontalDivision() ? mVelocityTracker.getYVelocity() : mVelocityTracker.getXVelocity(), false, /* avoidDismissStart */
            true);
            mMoving = false;
            break;
    }
    return true;
}
Also used : SnapTarget(com.android.internal.policy.DividerSnapAlgorithm.SnapTarget)

Example 10 with SnapTarget

use of com.android.internal.policy.DividerSnapAlgorithm.SnapTarget in project android_frameworks_base by ResurrectionRemix.

the class DividerView method resizeStack.

public void resizeStack(int position, int taskPosition, SnapTarget taskSnapTarget) {
    calculateBoundsForPosition(position, mDockSide, mDockedRect);
    if (mDockedRect.equals(mLastResizeRect) && !mEntranceAnimationRunning) {
        return;
    }
    // Make sure shadows are updated
    if (mBackground.getZ() > 0f) {
        mBackground.invalidate();
    }
    mLastResizeRect.set(mDockedRect);
    if (mEntranceAnimationRunning && taskPosition != TASK_POSITION_SAME) {
        if (mCurrentAnimator != null) {
            calculateBoundsForPosition(taskPosition, mDockSide, mDockedTaskRect);
        } else {
            calculateBoundsForPosition(isHorizontalDivision() ? mDisplayHeight : mDisplayWidth, mDockSide, mDockedTaskRect);
        }
        calculateBoundsForPosition(taskPosition, DockedDividerUtils.invertDockSide(mDockSide), mOtherTaskRect);
        mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, null, mOtherTaskRect, null);
    } else if (mExitAnimationRunning && taskPosition != TASK_POSITION_SAME) {
        calculateBoundsForPosition(taskPosition, mDockSide, mDockedTaskRect);
        calculateBoundsForPosition(mExitStartPosition, DockedDividerUtils.invertDockSide(mDockSide), mOtherTaskRect);
        mOtherInsetRect.set(mOtherTaskRect);
        applyExitAnimationParallax(mOtherTaskRect, position);
        mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, null, mOtherTaskRect, mOtherInsetRect);
    } else if (taskPosition != TASK_POSITION_SAME) {
        calculateBoundsForPosition(position, DockedDividerUtils.invertDockSide(mDockSide), mOtherRect);
        int dockSideInverted = DockedDividerUtils.invertDockSide(mDockSide);
        int taskPositionDocked = restrictDismissingTaskPosition(taskPosition, mDockSide, taskSnapTarget);
        int taskPositionOther = restrictDismissingTaskPosition(taskPosition, dockSideInverted, taskSnapTarget);
        calculateBoundsForPosition(taskPositionDocked, mDockSide, mDockedTaskRect);
        calculateBoundsForPosition(taskPositionOther, dockSideInverted, mOtherTaskRect);
        mDisplayRect.set(0, 0, mDisplayWidth, mDisplayHeight);
        alignTopLeft(mDockedRect, mDockedTaskRect);
        alignTopLeft(mOtherRect, mOtherTaskRect);
        mDockedInsetRect.set(mDockedTaskRect);
        mOtherInsetRect.set(mOtherTaskRect);
        if (dockSideTopLeft(mDockSide)) {
            alignTopLeft(mDisplayRect, mDockedInsetRect);
            alignBottomRight(mDisplayRect, mOtherInsetRect);
        } else {
            alignBottomRight(mDisplayRect, mDockedInsetRect);
            alignTopLeft(mDisplayRect, mOtherInsetRect);
        }
        applyDismissingParallax(mDockedTaskRect, mDockSide, taskSnapTarget, position, taskPositionDocked);
        applyDismissingParallax(mOtherTaskRect, dockSideInverted, taskSnapTarget, position, taskPositionOther);
        mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, mDockedInsetRect, mOtherTaskRect, mOtherInsetRect);
    } else {
        mWindowManagerProxy.resizeDockedStack(mDockedRect, null, null, null, null);
    }
    SnapTarget closestDismissTarget = mSnapAlgorithm.getClosestDismissTarget(position);
    float dimFraction = getDimFraction(position, closestDismissTarget);
    mWindowManagerProxy.setResizeDimLayer(dimFraction != 0f, getStackIdForDismissTarget(closestDismissTarget), dimFraction);
}
Also used : SnapTarget(com.android.internal.policy.DividerSnapAlgorithm.SnapTarget)

Aggregations

SnapTarget (com.android.internal.policy.DividerSnapAlgorithm.SnapTarget)34 ValueAnimator (android.animation.ValueAnimator)5 Rect (android.graphics.Rect)5 DisplayInfo (android.view.DisplayInfo)4 DividerSnapAlgorithm (com.android.internal.policy.DividerSnapAlgorithm)4