Search in sources :

Example 6 with PagedOrientationHandler

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

the class TaskView method setOrientationState.

public void setOrientationState(RecentsOrientedState orientationState) {
    PagedOrientationHandler orientationHandler = orientationState.getOrientationHandler();
    boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
    LayoutParams snapshotParams = (LayoutParams) mSnapshotView.getLayoutParams();
    DeviceProfile deviceProfile = mActivity.getDeviceProfile();
    snapshotParams.topMargin = deviceProfile.overviewTaskThumbnailTopMarginPx;
    int taskIconMargin = deviceProfile.overviewTaskMarginPx;
    int taskIconHeight = deviceProfile.overviewTaskIconSizePx;
    LayoutParams iconParams = (LayoutParams) mIconView.getLayoutParams();
    switch(orientationHandler.getRotation()) {
        case ROTATION_90:
            iconParams.gravity = (isRtl ? START : END) | CENTER_VERTICAL;
            iconParams.rightMargin = -taskIconHeight - taskIconMargin / 2;
            iconParams.leftMargin = 0;
            iconParams.topMargin = snapshotParams.topMargin / 2;
            break;
        case ROTATION_180:
            iconParams.gravity = BOTTOM | CENTER_HORIZONTAL;
            iconParams.bottomMargin = -snapshotParams.topMargin;
            iconParams.leftMargin = iconParams.rightMargin = 0;
            iconParams.topMargin = taskIconMargin;
            break;
        case ROTATION_270:
            iconParams.gravity = (isRtl ? END : START) | CENTER_VERTICAL;
            iconParams.leftMargin = -taskIconHeight - taskIconMargin / 2;
            iconParams.rightMargin = 0;
            iconParams.topMargin = snapshotParams.topMargin / 2;
            break;
        case Surface.ROTATION_0:
        default:
            iconParams.gravity = TOP | CENTER_HORIZONTAL;
            iconParams.leftMargin = iconParams.rightMargin = 0;
            iconParams.topMargin = taskIconMargin;
            break;
    }
    mSnapshotView.setLayoutParams(snapshotParams);
    iconParams.width = iconParams.height = taskIconHeight;
    mIconView.setLayoutParams(iconParams);
    mIconView.setRotation(orientationHandler.getDegreesRotated());
    snapshotParams.topMargin = deviceProfile.overviewTaskThumbnailTopMarginPx;
    mSnapshotView.setLayoutParams(snapshotParams);
    getThumbnail().getTaskOverlay().updateOrientationState(orientationState);
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) PagedOrientationHandler(com.android.launcher3.touch.PagedOrientationHandler)

Example 7 with PagedOrientationHandler

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

the class AnimatorControllerWithResistance method createRecentsResistanceAnim.

/**
 * Creates the resistance animation for {@link #createForRecents}, or can be used separately
 * when starting from recents, i.e. {@link #createRecentsResistanceFromOverviewAnim}.
 */
public static <SCALE, TRANSLATION> PendingAnimation createRecentsResistanceAnim(RecentsParams<SCALE, TRANSLATION> params) {
    Rect startRect = new Rect();
    PagedOrientationHandler orientationHandler = params.recentsOrientedState.getOrientationHandler();
    LauncherActivityInterface.INSTANCE.calculateTaskSize(params.context, params.dp, startRect, orientationHandler);
    long distanceToCover = startRect.bottom;
    PendingAnimation resistAnim = params.resistAnim != null ? params.resistAnim : new PendingAnimation(distanceToCover * 2);
    PointF pivot = new PointF();
    float fullscreenScale = params.recentsOrientedState.getFullScreenScaleAndPivot(startRect, params.dp, pivot);
    float prevScaleRate = (fullscreenScale - params.startScale) / (params.dp.heightPx - startRect.bottom);
    // This is what the scale would be at the end of the drag if we didn't apply resistance.
    float endScale = params.startScale - prevScaleRate * distanceToCover;
    // Create an interpolator that resists the scale so the scale doesn't get smaller than
    // RECENTS_SCALE_MAX_RESIST.
    float startResist = Utilities.getProgress(params.resistanceParams.scaleStartResist, params.startScale, endScale);
    float maxResist = Utilities.getProgress(params.resistanceParams.scaleMaxResist, params.startScale, endScale);
    final TimeInterpolator scaleInterpolator = t -> {
        if (t < startResist) {
            return t;
        }
        float resistProgress = Utilities.getProgress(t, startResist, 1);
        resistProgress = RECENTS_SCALE_RESIST_INTERPOLATOR.getInterpolation(resistProgress);
        return startResist + resistProgress * (maxResist - startResist);
    };
    resistAnim.addFloat(params.scaleTarget, params.scaleProperty, params.startScale, endScale, scaleInterpolator);
    // Compute where the task view would be based on the end scale.
    RectF endRectF = new RectF(startRect);
    Matrix temp = new Matrix();
    temp.setScale(params.resistanceParams.scaleMaxResist, params.resistanceParams.scaleMaxResist, pivot.x, pivot.y);
    temp.mapRect(endRectF);
    // Translate such that the task view touches the top of the screen when drag does.
    float endTranslation = endRectF.top * orientationHandler.getSecondaryTranslationDirectionFactor() * params.resistanceParams.translationFactor;
    resistAnim.addFloat(params.translationTarget, params.translationProperty, params.startTranslation, endTranslation, RECENTS_TRANSLATE_RESIST_INTERPOLATOR);
    return resistAnim;
}
Also used : RectF(android.graphics.RectF) Utilities(com.android.launcher3.Utilities) Context(android.content.Context) Rect(android.graphics.Rect) TimeInterpolator(android.animation.TimeInterpolator) PointF(android.graphics.PointF) Launcher(com.android.launcher3.Launcher) DEACCEL(com.android.launcher3.anim.Interpolators.DEACCEL) FloatProperty(android.util.FloatProperty) AnimatorPlaybackController(com.android.launcher3.anim.AnimatorPlaybackController) DeviceProfile(com.android.launcher3.DeviceProfile) LINEAR(com.android.launcher3.anim.Interpolators.LINEAR) RECENTS_SCALE_PROPERTY(com.android.quickstep.views.RecentsView.RECENTS_SCALE_PROPERTY) Nullable(androidx.annotation.Nullable) LauncherActivityInterface(com.android.quickstep.LauncherActivityInterface) RecentsView(com.android.quickstep.views.RecentsView) TASK_SECONDARY_TRANSLATION(com.android.quickstep.views.RecentsView.TASK_SECONDARY_TRANSLATION) Matrix(android.graphics.Matrix) PagedOrientationHandler(com.android.launcher3.touch.PagedOrientationHandler) PendingAnimation(com.android.launcher3.anim.PendingAnimation) RectF(android.graphics.RectF) PendingAnimation(com.android.launcher3.anim.PendingAnimation) Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) PagedOrientationHandler(com.android.launcher3.touch.PagedOrientationHandler) PointF(android.graphics.PointF) TimeInterpolator(android.animation.TimeInterpolator)

Example 8 with PagedOrientationHandler

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

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 9 with PagedOrientationHandler

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

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 10 with PagedOrientationHandler

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

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)

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