Search in sources :

Example 61 with PagedOrientationHandler

use of com.android.launcher3.touch.PagedOrientationHandler in project android_packages_apps_404Launcher by P-404.

the class TaskViewTouchController method onDragEnd.

@Override
public void onDragEnd(float velocity) {
    if (mOverrideVelocity != null) {
        velocity = mOverrideVelocity;
        mOverrideVelocity = null;
    }
    // Limit velocity, as very large scalar values make animations play too quickly
    float maxTaskDismissDragVelocity = mTaskBeingDragged.getResources().getDimension(R.dimen.max_task_dismiss_drag_velocity);
    velocity = Utilities.boundToRange(velocity, -maxTaskDismissDragVelocity, maxTaskDismissDragVelocity);
    boolean fling = mDetector.isFling(velocity);
    final boolean goingToEnd;
    boolean blockedFling = fling && mFlingBlockCheck.isBlocked();
    if (blockedFling) {
        fling = false;
    }
    PagedOrientationHandler orientationHandler = mRecentsView.getPagedOrientationHandler();
    boolean goingUp = orientationHandler.isGoingUp(velocity, mIsRtl);
    float progress = mCurrentAnimation.getProgressFraction();
    float interpolatedProgress = mCurrentAnimation.getInterpolatedProgress();
    if (fling) {
        goingToEnd = goingUp == mCurrentAnimationIsGoingUp;
    } else {
        goingToEnd = interpolatedProgress > SUCCESS_TRANSITION_PROGRESS;
    }
    long animationDuration = BaseSwipeDetector.calculateDuration(velocity, goingToEnd ? (1 - progress) : progress);
    if (blockedFling && !goingToEnd) {
        animationDuration *= LauncherAnimUtils.blockedFlingDurationFactor(velocity);
    }
    // Due to very high or low velocity dismissals, animation durations can be inconsistently
    // long or short. Bound the duration for animation of task translations for a more
    // standardized feel.
    animationDuration = Utilities.boundToRange(animationDuration, MIN_TASK_DISMISS_ANIMATION_DURATION, MAX_TASK_DISMISS_ANIMATION_DURATION);
    mCurrentAnimation.setEndAction(this::clearState);
    mCurrentAnimation.startWithVelocity(mActivity, goingToEnd, velocity * orientationHandler.getSecondaryTranslationDirectionFactor(), mEndDisplacement, animationDuration);
    if (goingUp && goingToEnd && !mIsDismissHapticRunning) {
        VibratorWrapper.INSTANCE.get(mActivity).vibrate(TASK_DISMISS_VIBRATION_PRIMITIVE, TASK_DISMISS_VIBRATION_PRIMITIVE_SCALE, TASK_DISMISS_VIBRATION_FALLBACK);
        mIsDismissHapticRunning = true;
    }
}
Also used : PagedOrientationHandler(com.android.launcher3.touch.PagedOrientationHandler)

Example 62 with PagedOrientationHandler

use of com.android.launcher3.touch.PagedOrientationHandler in project android_packages_apps_404Launcher by P-404.

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, false);
        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 63 with PagedOrientationHandler

use of com.android.launcher3.touch.PagedOrientationHandler in project android_packages_apps_404Launcher by P-404.

the class TaskViewTouchController method onDragStart.

@Override
public void onDragStart(boolean start, float startDisplacement) {
    PagedOrientationHandler orientationHandler = mRecentsView.getPagedOrientationHandler();
    if (mCurrentAnimation == null) {
        reInitAnimationController(orientationHandler.isGoingUp(startDisplacement, mIsRtl));
        mDisplacementShift = 0;
    } else {
        mDisplacementShift = mCurrentAnimation.getProgressFraction() / mProgressMultiplier;
        mCurrentAnimation.pause();
    }
    mFlingBlockCheck.unblockFling();
    mOverrideVelocity = null;
}
Also used : PagedOrientationHandler(com.android.launcher3.touch.PagedOrientationHandler)

Example 64 with PagedOrientationHandler

use of com.android.launcher3.touch.PagedOrientationHandler in project android_packages_apps_404Launcher by P-404.

the class TaskViewTouchController method onDrag.

@Override
public boolean onDrag(float displacement) {
    PagedOrientationHandler orientationHandler = mRecentsView.getPagedOrientationHandler();
    float totalDisplacement = displacement + mDisplacementShift;
    boolean isGoingUp = totalDisplacement == 0 ? mCurrentAnimationIsGoingUp : orientationHandler.isGoingUp(totalDisplacement, mIsRtl);
    if (isGoingUp != mCurrentAnimationIsGoingUp) {
        reInitAnimationController(isGoingUp);
        mFlingBlockCheck.blockFling();
    } else {
        mFlingBlockCheck.onEvent();
    }
    if (isGoingUp) {
        if (mCurrentAnimation.getProgressFraction() < ANIMATION_PROGRESS_FRACTION_MIDPOINT) {
            // Halve the value when dismissing, as we are animating the drag across the full
            // length for only the first half of the progress
            mCurrentAnimation.setPlayFraction(Utilities.boundToRange(totalDisplacement * mProgressMultiplier / 2, 0, 1));
        } else {
            // Set mOverrideVelocity to control task dismiss velocity in onDragEnd
            int velocityDimenId = R.dimen.default_task_dismiss_drag_velocity;
            if (mRecentsView.showAsGrid()) {
                if (mTaskBeingDragged.isFocusedTask()) {
                    velocityDimenId = R.dimen.default_task_dismiss_drag_velocity_grid_focus_task;
                } else {
                    velocityDimenId = R.dimen.default_task_dismiss_drag_velocity_grid;
                }
            }
            mOverrideVelocity = -mTaskBeingDragged.getResources().getDimension(velocityDimenId);
            // Once halfway through task dismissal interpolation, switch from reversible
            // dragging-task animation to playing the remaining task translation animations
            final long now = SystemClock.uptimeMillis();
            MotionEvent upAction = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 0.0f, 0.0f, 0);
            mDetector.onTouchEvent(upAction);
            upAction.recycle();
        }
    } else {
        mCurrentAnimation.setPlayFraction(Utilities.boundToRange(totalDisplacement * mProgressMultiplier, 0, 1));
    }
    return true;
}
Also used : PagedOrientationHandler(com.android.launcher3.touch.PagedOrientationHandler) MotionEvent(android.view.MotionEvent)

Example 65 with PagedOrientationHandler

use of com.android.launcher3.touch.PagedOrientationHandler in project android_packages_apps_Launcher3 by crdroidandroid.

the class TaskViewTouchController method onDrag.

@Override
public boolean onDrag(float displacement) {
    PagedOrientationHandler orientationHandler = mRecentsView.getPagedOrientationHandler();
    float totalDisplacement = displacement + mDisplacementShift;
    boolean isGoingUp = totalDisplacement == 0 ? mCurrentAnimationIsGoingUp : orientationHandler.isGoingUp(totalDisplacement, mIsRtl);
    if (isGoingUp != mCurrentAnimationIsGoingUp) {
        reInitAnimationController(isGoingUp);
        mFlingBlockCheck.blockFling();
    } else {
        mFlingBlockCheck.onEvent();
    }
    if (isGoingUp) {
        if (mCurrentAnimation.getProgressFraction() < ANIMATION_PROGRESS_FRACTION_MIDPOINT) {
            // Halve the value when dismissing, as we are animating the drag across the full
            // length for only the first half of the progress
            mCurrentAnimation.setPlayFraction(Utilities.boundToRange(totalDisplacement * mProgressMultiplier / 2, 0, 1));
        } else {
            // Set mOverrideVelocity to control task dismiss velocity in onDragEnd
            int velocityDimenId = R.dimen.default_task_dismiss_drag_velocity;
            if (mRecentsView.showAsGrid()) {
                if (mTaskBeingDragged.isFocusedTask()) {
                    velocityDimenId = R.dimen.default_task_dismiss_drag_velocity_grid_focus_task;
                } else {
                    velocityDimenId = R.dimen.default_task_dismiss_drag_velocity_grid;
                }
            }
            mOverrideVelocity = -mTaskBeingDragged.getResources().getDimension(velocityDimenId);
            // Once halfway through task dismissal interpolation, switch from reversible
            // dragging-task animation to playing the remaining task translation animations
            final long now = SystemClock.uptimeMillis();
            MotionEvent upAction = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 0.0f, 0.0f, 0);
            mDetector.onTouchEvent(upAction);
            upAction.recycle();
        }
    } else {
        mCurrentAnimation.setPlayFraction(Utilities.boundToRange(totalDisplacement * mProgressMultiplier, 0, 1));
    }
    return true;
}
Also used : PagedOrientationHandler(com.android.launcher3.touch.PagedOrientationHandler) MotionEvent(android.view.MotionEvent)

Aggregations

PagedOrientationHandler (com.android.launcher3.touch.PagedOrientationHandler)101 RecentsView (com.android.quickstep.views.RecentsView)25 DeviceProfile (com.android.launcher3.DeviceProfile)22 Rect (android.graphics.Rect)16 PendingAnimation (com.android.launcher3.anim.PendingAnimation)15 FloatProperty (android.util.FloatProperty)14 BaseDragLayer (com.android.launcher3.views.BaseDragLayer)12 PointF (android.graphics.PointF)11 RectF (android.graphics.RectF)11 Point (android.graphics.Point)9 TimeInterpolator (android.animation.TimeInterpolator)6 Matrix (android.graphics.Matrix)6 View (android.view.View)6 Interpolator (android.view.animation.Interpolator)6 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)6 TaskView (com.android.quickstep.views.TaskView)6 Context (android.content.Context)5 ShapeDrawable (android.graphics.drawable.ShapeDrawable)5 RectShape (android.graphics.drawable.shapes.RectShape)5 MotionEvent (android.view.MotionEvent)5