Search in sources :

Example 1 with Utilities.mapRange

use of com.android.launcher3.Utilities.mapRange in project android_packages_apps_Trebuchet by LineageOS.

the class ShelfScrimView method updateColors.

@Override
public void updateColors() {
    super.updateColors();
    mDragHandleOffset = 0;
    if (mDrawingFlatColor) {
        return;
    }
    if (mProgress < mDragHandleProgress) {
        mDragHandleOffset = mShiftRange * (mDragHandleProgress - mProgress);
    }
    if (mProgress >= SCRIM_CATCHUP_THRESHOLD) {
        mShelfTop = mShiftRange * mProgress + mTopOffset;
    } else {
        mShelfTop = Utilities.mapRange(mProgress / SCRIM_CATCHUP_THRESHOLD, -mRadius, mShelfTopAtThreshold);
    }
    if (mProgress >= 1) {
        mRemainingScreenColor = 0;
        mShelfColor = 0;
        LauncherState state = mLauncher.getStateManager().getState();
        if (mSysUINavigationMode == Mode.NO_BUTTON && (state == BACKGROUND_APP || state == QUICK_SWITCH) && mLauncher.getShelfPeekAnim().isPeeking()) {
            // Show the shelf background when peeking during swipe up.
            mShelfColor = setColorAlphaBound(mEndScrim, mMidAlpha);
        }
    } else if (mProgress >= mMidProgress) {
        mRemainingScreenColor = 0;
        int alpha = Math.round(Utilities.mapToRange(mProgress, mMidProgress, 1, mMidAlpha, 0, mBeforeMidProgressColorInterpolator));
        mShelfColor = setColorAlphaBound(mEndScrim, alpha);
    } else {
        // Note that these ranges and interpolators are inverted because progress goes 1 to 0.
        int alpha = Math.round(Utilities.mapToRange(mProgress, (float) 0, mMidProgress, (float) mEndAlpha, (float) mMidAlpha, mAfterMidProgressColorInterpolator));
        mShelfColor = setColorAlphaBound(mEndScrim, alpha);
        int remainingScrimAlpha = Math.round(Utilities.mapToRange(mProgress, (float) 0, mMidProgress, mMaxScrimAlpha, (float) 0, LINEAR));
        mRemainingScreenColor = setColorAlphaBound(mScrimColor, remainingScrimAlpha);
    }
}
Also used : LauncherState(com.android.launcher3.LauncherState)

Example 2 with Utilities.mapRange

use of com.android.launcher3.Utilities.mapRange in project Neo-Launcher by NeoApplications.

the class NoButtonQuickSwitchTouchController method setupOverviewAnimators.

private void setupOverviewAnimators() {
    final LauncherState fromState = QUICK_SWITCH;
    final LauncherState toState = OVERVIEW;
    LauncherState.ScaleAndTranslation fromScaleAndTranslation = fromState.getOverviewScaleAndTranslation(mLauncher);
    LauncherState.ScaleAndTranslation toScaleAndTranslation = toState.getOverviewScaleAndTranslation(mLauncher);
    // Update RecentView's translationX to have it start offscreen.
    LauncherRecentsView recentsView = mLauncher.getOverviewPanel();
    float startScale = Utilities.mapRange(SCALE_DOWN_INTERPOLATOR.getInterpolation(Y_ANIM_MIN_PROGRESS), fromScaleAndTranslation.scale, toScaleAndTranslation.scale);
    fromScaleAndTranslation.translationX = recentsView.getOffscreenTranslationX(startScale);
    // Set RecentView's initial properties.
    recentsView.setScaleX(fromScaleAndTranslation.scale);
    recentsView.setScaleY(fromScaleAndTranslation.scale);
    recentsView.setTranslationX(fromScaleAndTranslation.translationX);
    recentsView.setTranslationY(fromScaleAndTranslation.translationY);
    recentsView.setContentAlpha(1);
    // As we drag right, animate the following properties:
    // - RecentsView translationX
    // - OverviewScrim
    AnimatorSet xOverviewAnim = new AnimatorSet();
    xOverviewAnim.play(ObjectAnimator.ofFloat(recentsView, View.TRANSLATION_X, toScaleAndTranslation.translationX));
    xOverviewAnim.play(ObjectAnimator.ofFloat(mLauncher.getDragLayer().getOverviewScrim(), OverviewScrim.SCRIM_PROGRESS, toState.getOverviewScrimAlpha(mLauncher)));
    long xAccuracy = (long) (mXRange * 2);
    xOverviewAnim.setDuration(xAccuracy);
    mXOverviewAnim = AnimatorPlaybackController.wrap(xOverviewAnim, xAccuracy);
    mXOverviewAnim.dispatchOnStart();
    // As we drag up, animate the following properties:
    // - RecentsView translationY
    // - RecentsView scale
    // - RecentsView fullscreenProgress
    AnimatorSet yAnimation = new AnimatorSet();
    Animator translateYAnim = ObjectAnimator.ofFloat(recentsView, View.TRANSLATION_Y, toScaleAndTranslation.translationY);
    Animator scaleAnim = ObjectAnimator.ofFloat(recentsView, SCALE_PROPERTY, toScaleAndTranslation.scale);
    Animator fullscreenProgressAnim = ObjectAnimator.ofFloat(recentsView, FULLSCREEN_PROGRESS, fromState.getOverviewFullscreenProgress(), toState.getOverviewFullscreenProgress());
    scaleAnim.setInterpolator(SCALE_DOWN_INTERPOLATOR);
    fullscreenProgressAnim.setInterpolator(SCALE_DOWN_INTERPOLATOR);
    yAnimation.play(translateYAnim);
    yAnimation.play(scaleAnim);
    yAnimation.play(fullscreenProgressAnim);
    long yAccuracy = (long) (mYRange * 2);
    yAnimation.setDuration(yAccuracy);
    mYOverviewAnim = AnimatorPlaybackController.wrap(yAnimation, yAccuracy);
    mYOverviewAnim.dispatchOnStart();
}
Also used : LauncherState(com.android.launcher3.LauncherState) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorSet(android.animation.AnimatorSet) LauncherRecentsView(com.android.quickstep.views.LauncherRecentsView)

Example 3 with Utilities.mapRange

use of com.android.launcher3.Utilities.mapRange in project android_packages_apps_Trebuchet by LineageOS.

the class RecentsView method getOffsetSize.

/**
 * Computes the distance to offset the given child such that it is completely offscreen when
 * translating away from the given midpoint.
 * @param offsetProgress From 0 to 1 where 0 means no offset and 1 means offset offscreen.
 */
private float getOffsetSize(int childIndex, int midpointIndex, float offsetProgress) {
    if (offsetProgress == 0) {
        // Don't bother calculating everything below if we won't offset anyway.
        return 0;
    }
    // First, get the position of the task relative to the midpoint. If there is no midpoint
    // then we just use the normal (centered) task position.
    mTempRectF.set(mLastComputedTaskSize);
    RectF taskPosition = mTempRectF;
    float desiredLeft = getWidth();
    float distanceToOffscreen = desiredLeft - taskPosition.left;
    // Used to calculate the scale of the task view based on its new offset.
    float centerToOffscreenProgress = Math.abs(offsetProgress);
    if (midpointIndex > -1) {
        // When there is a midpoint reference task, adjacent tasks have less distance to travel
        // to reach offscreen. Offset the task position to the task's starting point.
        View child = getChildAt(childIndex);
        View midpointChild = getChildAt(midpointIndex);
        int distanceFromMidpoint = Math.abs(mOrientationHandler.getChildStart(child) - mOrientationHandler.getChildStart(midpointChild) + getDisplacementFromScreenCenter(midpointIndex));
        taskPosition.offset(distanceFromMidpoint, 0);
        centerToOffscreenProgress = Utilities.mapRange(centerToOffscreenProgress, distanceFromMidpoint / distanceToOffscreen, 1);
    }
    // Find the task's scale based on its offscreen progress, then see how far it still needs to
    // move to be completely offscreen.
    Utilities.scaleRectFAboutCenter(taskPosition, TaskView.getCurveScaleForInterpolation(centerToOffscreenProgress));
    distanceToOffscreen = desiredLeft - taskPosition.left;
    // moves the task from its desired position, and adjust the computed distance accordingly.
    if (mLastComputedTaskPushOutDistance == null) {
        taskPosition.offsetTo(desiredLeft, 0);
        getMatrix().mapRect(taskPosition);
        mLastComputedTaskPushOutDistance = (taskPosition.left - desiredLeft) / getScaleX();
    }
    distanceToOffscreen -= mLastComputedTaskPushOutDistance;
    return distanceToOffscreen * offsetProgress;
}
Also used : RectF(android.graphics.RectF) View(android.view.View) ListView(android.widget.ListView) PagedView(com.android.launcher3.PagedView) TextPaint(android.text.TextPaint) Point(android.graphics.Point)

Aggregations

LauncherState (com.android.launcher3.LauncherState)2 Animator (android.animation.Animator)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 Point (android.graphics.Point)1 RectF (android.graphics.RectF)1 TextPaint (android.text.TextPaint)1 View (android.view.View)1 ListView (android.widget.ListView)1 PagedView (com.android.launcher3.PagedView)1 LauncherRecentsView (com.android.quickstep.views.LauncherRecentsView)1