Search in sources :

Example 1 with Utilities.mapToRange

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

the class AllAppsEduView method playAnimation.

private void playAnimation() {
    if (mAnimation != null) {
        return;
    }
    mAnimation = new AnimatorSet();
    final Rect circleBoundsOg = new Rect(mCircle.getBounds());
    final Rect gradientBoundsOg = new Rect(mGradient.getBounds());
    final Rect temp = new Rect();
    final float transY = mMaxHeightPx - mCircleSizePx - mPaddingPx;
    // 1st: Circle alpha/scale
    int firstPart = 600;
    // 2nd: Circle animates upwards, Gradient alpha fades in, Gradient grows, All Apps hint
    int secondPart = 1200;
    int introDuration = firstPart + secondPart;
    StateAnimationConfig config = new StateAnimationConfig();
    config.setInterpolator(ANIM_ALL_APPS_FADE, Interpolators.clampToProgress(ACCEL, 0, 0.08f));
    config.duration = secondPart;
    config.userControlled = false;
    AnimatorPlaybackController stateAnimationController = mLauncher.getStateManager().createAnimationToNewWorkspace(ALL_APPS, config);
    float maxAllAppsProgress = mLauncher.getDeviceProfile().isLandscape ? 0.35f : 0.15f;
    AllAppsTransitionController allAppsController = mLauncher.getAllAppsController();
    PendingAnimation allAppsAlpha = new PendingAnimation(config.duration);
    allAppsController.setAlphas(ALL_APPS, config, allAppsAlpha);
    mAnimation.play(allAppsAlpha.buildAnim());
    ValueAnimator intro = ValueAnimator.ofFloat(0, 1f);
    intro.setInterpolator(LINEAR);
    intro.setDuration(introDuration);
    intro.addUpdateListener((new MultiValueUpdateListener() {

        FloatProp mCircleAlpha = new FloatProp(0, 255, 0, firstPart, LINEAR);

        FloatProp mCircleScale = new FloatProp(2f, 1f, 0, firstPart, OVERSHOOT_1_7);

        FloatProp mDeltaY = new FloatProp(0, transY, firstPart, secondPart, FAST_OUT_SLOW_IN);

        FloatProp mGradientAlpha = new FloatProp(0, 255, firstPart, secondPart * 0.3f, LINEAR);

        @Override
        public void onUpdate(float progress) {
            temp.set(circleBoundsOg);
            temp.offset(0, (int) -mDeltaY.value);
            Utilities.scaleRectAboutCenter(temp, mCircleScale.value);
            mCircle.setBounds(temp);
            mCircle.setAlpha((int) mCircleAlpha.value);
            mGradient.setAlpha((int) mGradientAlpha.value);
            temp.set(gradientBoundsOg);
            temp.top -= mDeltaY.value;
            mGradient.setBounds(temp);
            invalidate();
            float stateProgress = Utilities.mapToRange(mDeltaY.value, 0, transY, 0, maxAllAppsProgress, LINEAR);
            stateAnimationController.setPlayFraction(stateProgress);
        }
    }));
    intro.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mCircle.setAlpha(0);
            mGradient.setAlpha(0);
        }
    });
    mAnimation.play(intro);
    ValueAnimator closeAllApps = ValueAnimator.ofFloat(maxAllAppsProgress, 0f);
    closeAllApps.addUpdateListener(valueAnimator -> {
        stateAnimationController.setPlayFraction((float) valueAnimator.getAnimatedValue());
    });
    closeAllApps.setInterpolator(FAST_OUT_SLOW_IN);
    closeAllApps.setStartDelay(introDuration);
    closeAllApps.setDuration(250);
    mAnimation.play(closeAllApps);
    mAnimation.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mAnimation = null;
            // Handles cancelling the animation used to hint towards All Apps.
            mLauncher.getStateManager().goToState(NORMAL, false);
            handleClose(false);
        }
    });
    mAnimation.start();
}
Also used : PendingAnimation(com.android.launcher3.anim.PendingAnimation) Rect(android.graphics.Rect) StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig) AnimatorPlaybackController(com.android.launcher3.anim.AnimatorPlaybackController) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) MultiValueUpdateListener(com.android.quickstep.util.MultiValueUpdateListener) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AllAppsTransitionController(com.android.launcher3.allapps.AllAppsTransitionController) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 2 with Utilities.mapToRange

use of com.android.launcher3.Utilities.mapToRange 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 3 with Utilities.mapToRange

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

the class BaseSwipeUpHandler method createWindowAnimationToHome.

/**
 * Creates an animation that transforms the current app window into the home app.
 * @param startProgress The progress of {@link #mCurrentShift} to start the window from.
 * @param homeAnimationFactory The home animation factory.
 */
protected RectFSpringAnim createWindowAnimationToHome(float startProgress, HomeAnimationFactory homeAnimationFactory) {
    final RemoteAnimationTargetSet targetSet = mRecentsAnimationWrapper.targetSet;
    final RectF startRect = new RectF(mClipAnimationHelper.applyTransform(targetSet, mTransformParams.setProgress(startProgress), false));
    final RectF targetRect = homeAnimationFactory.getWindowTargetRect();
    final View floatingView = homeAnimationFactory.getFloatingView();
    final boolean isFloatingIconView = floatingView instanceof FloatingIconView;
    RectFSpringAnim anim = new RectFSpringAnim(startRect, targetRect, mContext.getResources());
    if (isFloatingIconView) {
        FloatingIconView fiv = (FloatingIconView) floatingView;
        anim.addAnimatorListener(fiv);
        fiv.setOnTargetChangeListener(anim::onTargetPositionChanged);
    }
    AnimatorPlaybackController homeAnim = homeAnimationFactory.createActivityAnimationToHome();
    // End on a "round-enough" radius so that the shape reveal doesn't have to do too much
    // rounding at the end of the animation.
    float startRadius = mClipAnimationHelper.getCurrentCornerRadius();
    float endRadius = startRect.width() / 6f;
    // We want the window alpha to be 0 once this threshold is met, so that the
    // FolderIconView can be seen morphing into the icon shape.
    final float windowAlphaThreshold = isFloatingIconView ? 1f - SHAPE_PROGRESS_DURATION : 1f;
    anim.addOnUpdateListener(new RectFSpringAnim.OnUpdateListener() {

        // Alpha interpolates between [1, 0] between progress values [start, end]
        final float start = 0f;

        final float end = 0.85f;

        private float getWindowAlpha(float progress) {
            if (progress <= start) {
                return 1f;
            }
            if (progress >= end) {
                return 0f;
            }
            return Utilities.mapToRange(progress, start, end, 1, 0, ACCEL_1_5);
        }

        @Override
        public void onUpdate(RectF currentRect, float progress) {
            homeAnim.setPlayFraction(progress);
            mTransformParams.setProgress(progress).setCurrentRectAndTargetAlpha(currentRect, getWindowAlpha(progress));
            if (isFloatingIconView) {
                mTransformParams.setCornerRadius(endRadius * progress + startRadius * (1f - progress));
            }
            mClipAnimationHelper.applyTransform(targetSet, mTransformParams, false);
            if (isFloatingIconView) {
                ((FloatingIconView) floatingView).update(currentRect, 1f, progress, windowAlphaThreshold, mClipAnimationHelper.getCurrentCornerRadius(), false);
            }
        }

        @Override
        public void onCancel() {
            if (isFloatingIconView) {
                ((FloatingIconView) floatingView).fastFinish();
            }
        }
    });
    anim.addAnimatorListener(new AnimationSuccessListener() {

        @Override
        public void onAnimationStart(Animator animation) {
            homeAnim.dispatchOnStart();
        }

        @Override
        public void onAnimationSuccess(Animator animator) {
            homeAnim.getAnimationPlayer().end();
        }
    });
    return anim;
}
Also used : FloatingIconView(com.android.launcher3.views.FloatingIconView) AnimatorPlaybackController(com.android.launcher3.anim.AnimatorPlaybackController) View(android.view.View) FloatingIconView(com.android.launcher3.views.FloatingIconView) TaskView(com.android.quickstep.views.TaskView) RecentsView(com.android.quickstep.views.RecentsView) RemoteAnimationTargetSet(com.android.quickstep.util.RemoteAnimationTargetSet) RectF(android.graphics.RectF) RectFSpringAnim(com.android.quickstep.util.RectFSpringAnim) Animator(android.animation.Animator) AnimationSuccessListener(com.android.launcher3.anim.AnimationSuccessListener)

Example 4 with Utilities.mapToRange

use of com.android.launcher3.Utilities.mapToRange in project android_packages_apps_Launcher3 by ArrowOS.

the class AllAppsEduView method playAnimation.

private void playAnimation() {
    if (mAnimation != null) {
        return;
    }
    mAnimation = new AnimatorSet();
    final Rect circleBoundsOg = new Rect(mCircle.getBounds());
    final Rect gradientBoundsOg = new Rect(mGradient.getBounds());
    final Rect temp = new Rect();
    final float transY = mMaxHeightPx - mCircleSizePx - mPaddingPx;
    // 1st: Circle alpha/scale
    int firstPart = 600;
    // 2nd: Circle animates upwards, Gradient alpha fades in, Gradient grows, All Apps hint
    int secondPart = 1200;
    int introDuration = firstPart + secondPart;
    AnimatorPlaybackController stateAnimationController = mTouchController.initAllAppsAnimation();
    float maxAllAppsProgress = 0.75f;
    ValueAnimator intro = ValueAnimator.ofFloat(0, 1f);
    intro.setInterpolator(LINEAR);
    intro.setDuration(introDuration);
    intro.addUpdateListener((new MultiValueUpdateListener() {

        FloatProp mCircleAlpha = new FloatProp(0, 255, 0, firstPart, LINEAR);

        FloatProp mCircleScale = new FloatProp(2f, 1f, 0, firstPart, OVERSHOOT_1_7);

        FloatProp mDeltaY = new FloatProp(0, transY, firstPart, secondPart, FAST_OUT_SLOW_IN);

        FloatProp mGradientAlpha = new FloatProp(0, 255, firstPart, secondPart * 0.3f, LINEAR);

        @Override
        public void onUpdate(float progress, boolean initOnly) {
            temp.set(circleBoundsOg);
            temp.offset(0, (int) -mDeltaY.value);
            Utilities.scaleRectAboutCenter(temp, mCircleScale.value);
            mCircle.setBounds(temp);
            mCircle.setAlpha((int) mCircleAlpha.value);
            mGradient.setAlpha((int) mGradientAlpha.value);
            temp.set(gradientBoundsOg);
            temp.top -= mDeltaY.value;
            mGradient.setBounds(temp);
            invalidate();
            float stateProgress = Utilities.mapToRange(mDeltaY.value, 0, transY, 0, maxAllAppsProgress, LINEAR);
            stateAnimationController.setPlayFraction(stateProgress);
        }
    }));
    intro.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mCircle.setAlpha(0);
            mGradient.setAlpha(0);
        }
    });
    mLauncher.getAppsView().setVisibility(View.VISIBLE);
    mAnimation.play(intro);
    ValueAnimator closeAllApps = ValueAnimator.ofFloat(maxAllAppsProgress, 0f);
    closeAllApps.addUpdateListener(valueAnimator -> {
        stateAnimationController.setPlayFraction((float) valueAnimator.getAnimatedValue());
    });
    closeAllApps.setInterpolator(FAST_OUT_SLOW_IN);
    closeAllApps.setStartDelay(introDuration);
    closeAllApps.setDuration(250);
    mAnimation.play(closeAllApps);
    mAnimation.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mAnimation = null;
            // Handles cancelling the animation used to hint towards All Apps.
            mLauncher.getStateManager().goToState(NORMAL, false);
            handleClose(false);
        }
    });
    mAnimation.start();
}
Also used : Rect(android.graphics.Rect) MultiValueUpdateListener(com.android.quickstep.util.MultiValueUpdateListener) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorPlaybackController(com.android.launcher3.anim.AnimatorPlaybackController) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator)

Example 5 with Utilities.mapToRange

use of com.android.launcher3.Utilities.mapToRange in project android_packages_apps_Launcher3 by ProtonAOSP.

the class AllAppsEduView method playAnimation.

private void playAnimation() {
    if (mAnimation != null) {
        return;
    }
    mAnimation = new AnimatorSet();
    final Rect circleBoundsOg = new Rect(mCircle.getBounds());
    final Rect gradientBoundsOg = new Rect(mGradient.getBounds());
    final Rect temp = new Rect();
    final float transY = mMaxHeightPx - mCircleSizePx - mPaddingPx;
    // 1st: Circle alpha/scale
    int firstPart = 600;
    // 2nd: Circle animates upwards, Gradient alpha fades in, Gradient grows, All Apps hint
    int secondPart = 1200;
    int introDuration = firstPart + secondPart;
    AnimatorPlaybackController stateAnimationController = mTouchController.initAllAppsAnimation();
    float maxAllAppsProgress = 0.75f;
    ValueAnimator intro = ValueAnimator.ofFloat(0, 1f);
    intro.setInterpolator(LINEAR);
    intro.setDuration(introDuration);
    intro.addUpdateListener((new MultiValueUpdateListener() {

        FloatProp mCircleAlpha = new FloatProp(0, 255, 0, firstPart, LINEAR);

        FloatProp mCircleScale = new FloatProp(2f, 1f, 0, firstPart, OVERSHOOT_1_7);

        FloatProp mDeltaY = new FloatProp(0, transY, firstPart, secondPart, FAST_OUT_SLOW_IN);

        FloatProp mGradientAlpha = new FloatProp(0, 255, firstPart, secondPart * 0.3f, LINEAR);

        @Override
        public void onUpdate(float progress, boolean initOnly) {
            temp.set(circleBoundsOg);
            temp.offset(0, (int) -mDeltaY.value);
            Utilities.scaleRectAboutCenter(temp, mCircleScale.value);
            mCircle.setBounds(temp);
            mCircle.setAlpha((int) mCircleAlpha.value);
            mGradient.setAlpha((int) mGradientAlpha.value);
            temp.set(gradientBoundsOg);
            temp.top -= mDeltaY.value;
            mGradient.setBounds(temp);
            invalidate();
            float stateProgress = Utilities.mapToRange(mDeltaY.value, 0, transY, 0, maxAllAppsProgress, LINEAR);
            stateAnimationController.setPlayFraction(stateProgress);
        }
    }));
    intro.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mCircle.setAlpha(0);
            mGradient.setAlpha(0);
        }
    });
    mLauncher.getAppsView().setVisibility(View.VISIBLE);
    mAnimation.play(intro);
    ValueAnimator closeAllApps = ValueAnimator.ofFloat(maxAllAppsProgress, 0f);
    closeAllApps.addUpdateListener(valueAnimator -> {
        stateAnimationController.setPlayFraction((float) valueAnimator.getAnimatedValue());
    });
    closeAllApps.setInterpolator(FAST_OUT_SLOW_IN);
    closeAllApps.setStartDelay(introDuration);
    closeAllApps.setDuration(250);
    mAnimation.play(closeAllApps);
    mAnimation.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mAnimation = null;
            // Handles cancelling the animation used to hint towards All Apps.
            mLauncher.getStateManager().goToState(NORMAL, false);
            handleClose(false);
        }
    });
    mAnimation.start();
}
Also used : Rect(android.graphics.Rect) MultiValueUpdateListener(com.android.quickstep.util.MultiValueUpdateListener) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorPlaybackController(com.android.launcher3.anim.AnimatorPlaybackController) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator)

Aggregations

Animator (android.animation.Animator)7 AnimatorPlaybackController (com.android.launcher3.anim.AnimatorPlaybackController)7 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)6 AnimatorSet (android.animation.AnimatorSet)6 ValueAnimator (android.animation.ValueAnimator)6 Rect (android.graphics.Rect)6 MultiValueUpdateListener (com.android.quickstep.util.MultiValueUpdateListener)6 RectF (android.graphics.RectF)1 View (android.view.View)1 LauncherState (com.android.launcher3.LauncherState)1 AllAppsTransitionController (com.android.launcher3.allapps.AllAppsTransitionController)1 AnimationSuccessListener (com.android.launcher3.anim.AnimationSuccessListener)1 PendingAnimation (com.android.launcher3.anim.PendingAnimation)1 StateAnimationConfig (com.android.launcher3.states.StateAnimationConfig)1 FloatingIconView (com.android.launcher3.views.FloatingIconView)1 RectFSpringAnim (com.android.quickstep.util.RectFSpringAnim)1 RemoteAnimationTargetSet (com.android.quickstep.util.RemoteAnimationTargetSet)1 RecentsView (com.android.quickstep.views.RecentsView)1 TaskView (com.android.quickstep.views.TaskView)1