Search in sources :

Example 81 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Fairphone by Kwamecorp.

the class DragLayer method fadeOutDragView.

private void fadeOutDragView() {
    mFadeOutAnim = new ValueAnimator();
    mFadeOutAnim.setDuration(150);
    mFadeOutAnim.setFloatValues(0f, 1f);
    mFadeOutAnim.removeAllUpdateListeners();
    mFadeOutAnim.addUpdateListener(new AnimatorUpdateListener() {

        public void onAnimationUpdate(ValueAnimator animation) {
            final float percent = (Float) animation.getAnimatedValue();
            float alpha = 1 - percent;
            mDropView.setAlpha(alpha);
        }
    });
    mFadeOutAnim.addListener(new AnimatorListenerAdapter() {

        public void onAnimationEnd(Animator animation) {
            if (mDropView != null) {
                mDragController.onDeferredEndDrag(mDropView);
            }
            mDropView = null;
            invalidate();
        }
    });
    mFadeOutAnim.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 82 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Fairphone by Kwamecorp.

the class DragLayer method animateView.

/**
     * This method animates a view at the end of a drag and drop animation.
     *
     * @param view The view to be animated. This view is drawn directly into DragLayer, and so
     *        doesn't need to be a child of DragLayer.
     * @param from The initial location of the view. Only the left and top parameters are used.
     * @param to The final location of the view. Only the left and top parameters are used. This
     *        location doesn't account for scaling, and so should be centered about the desired
     *        final location (including scaling).
     * @param finalAlpha The final alpha of the view, in case we want it to fade as it animates.
     * @param finalScale The final scale of the view. The view is scaled about its center.
     * @param duration The duration of the animation.
     * @param motionInterpolator The interpolator to use for the location of the view.
     * @param alphaInterpolator The interpolator to use for the alpha of the view.
     * @param onCompleteRunnable Optional runnable to run on animation completion.
     * @param fadeOut Whether or not to fade out the view once the animation completes. If true,
     *        the runnable will execute after the view is faded out.
     * @param anchorView If not null, this represents the view which the animated view stays
     *        anchored to in case scrolling is currently taking place. Note: currently this is
     *        only used for the X dimension for the case of the workspace.
     */
public void animateView(final DragView view, final Rect from, final Rect to, final float finalAlpha, final float initScaleX, final float initScaleY, final float finalScaleX, final float finalScaleY, int duration, final Interpolator motionInterpolator, final Interpolator alphaInterpolator, final Runnable onCompleteRunnable, final int animationEndStyle, View anchorView) {
    // Calculate the duration of the animation based on the object's distance
    final float dist = (float) Math.sqrt(Math.pow(to.left - from.left, 2) + Math.pow(to.top - from.top, 2));
    final Resources res = getResources();
    final float maxDist = (float) res.getInteger(R.integer.config_dropAnimMaxDist);
    // If duration < 0, this is a cue to compute the duration based on the distance
    if (duration < 0) {
        duration = res.getInteger(R.integer.config_dropAnimMaxDuration);
        if (dist < maxDist) {
            duration *= mCubicEaseOutInterpolator.getInterpolation(dist / maxDist);
        }
        duration = Math.max(duration, res.getInteger(R.integer.config_dropAnimMinDuration));
    }
    // Fall back to cubic ease out interpolator for the animation if none is specified
    TimeInterpolator interpolator = null;
    if (alphaInterpolator == null || motionInterpolator == null) {
        interpolator = mCubicEaseOutInterpolator;
    }
    // Animate the view
    final float initAlpha = view.getAlpha();
    final float dropViewScale = view.getScaleX();
    AnimatorUpdateListener updateCb = new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            final float percent = (Float) animation.getAnimatedValue();
            final int width = view.getMeasuredWidth();
            final int height = view.getMeasuredHeight();
            float alphaPercent = alphaInterpolator == null ? percent : alphaInterpolator.getInterpolation(percent);
            float motionPercent = motionInterpolator == null ? percent : motionInterpolator.getInterpolation(percent);
            float initialScaleX = initScaleX * dropViewScale;
            float initialScaleY = initScaleY * dropViewScale;
            float scaleX = finalScaleX * percent + initialScaleX * (1 - percent);
            float scaleY = finalScaleY * percent + initialScaleY * (1 - percent);
            float alpha = finalAlpha * alphaPercent + initAlpha * (1 - alphaPercent);
            float fromLeft = from.left + (initialScaleX - 1f) * width / 2;
            float fromTop = from.top + (initialScaleY - 1f) * height / 2;
            int x = (int) (fromLeft + Math.round(((to.left - fromLeft) * motionPercent)));
            int y = (int) (fromTop + Math.round(((to.top - fromTop) * motionPercent)));
            int xPos = x - mDropView.getScrollX() + (mAnchorView != null ? (mAnchorViewInitialScrollX - mAnchorView.getScrollX()) : 0);
            int yPos = y - mDropView.getScrollY();
            mDropView.setTranslationX(xPos);
            mDropView.setTranslationY(yPos);
            mDropView.setScaleX(scaleX);
            mDropView.setScaleY(scaleY);
            mDropView.setAlpha(alpha);
        }
    };
    animateView(view, updateCb, duration, interpolator, onCompleteRunnable, animationEndStyle, anchorView);
}
Also used : Resources(android.content.res.Resources) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) TimeInterpolator(android.animation.TimeInterpolator)

Example 83 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Fairphone by Kwamecorp.

the class FolderIcon method animateFirstItem.

private void animateFirstItem(final Drawable d, int duration, final boolean reverse, final Runnable onCompleteRunnable) {
    final PreviewItemDrawingParams finalParams = computePreviewItemDrawingParams(0, null);
    final float scale0 = 1.0f;
    final float transX0 = (mAvailableSpaceInPreview - d.getIntrinsicWidth()) / 2;
    final float transY0 = (mAvailableSpaceInPreview - d.getIntrinsicHeight()) / 2;
    mAnimParams.drawable = d;
    ValueAnimator va = LauncherAnimUtils.ofFloat(0f, 1.0f);
    va.addUpdateListener(new AnimatorUpdateListener() {

        public void onAnimationUpdate(ValueAnimator animation) {
            float progress = (Float) animation.getAnimatedValue();
            if (reverse) {
                progress = 1 - progress;
                mPreviewBackground.setAlpha(progress);
            }
            mAnimParams.transX = transX0 + progress * (finalParams.transX - transX0);
            mAnimParams.transY = transY0 + progress * (finalParams.transY - transY0);
            mAnimParams.scale = scale0 + progress * (finalParams.scale - scale0);
            invalidate();
        }
    });
    va.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mAnimating = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mAnimating = false;
            if (onCompleteRunnable != null) {
                onCompleteRunnable.run();
            }
        }
    });
    va.setDuration(duration);
    va.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 84 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Fairphone by Kwamecorp.

the class Workspace method animateBackgroundGradient.

private void animateBackgroundGradient(float finalAlpha, boolean animated) {
    if (mBackground == null)
        return;
    if (mBackgroundFadeInAnimation != null) {
        mBackgroundFadeInAnimation.cancel();
        mBackgroundFadeInAnimation = null;
    }
    if (mBackgroundFadeOutAnimation != null) {
        mBackgroundFadeOutAnimation.cancel();
        mBackgroundFadeOutAnimation = null;
    }
    float startAlpha = getBackgroundAlpha();
    if (finalAlpha != startAlpha) {
        if (animated) {
            mBackgroundFadeOutAnimation = LauncherAnimUtils.ofFloat(startAlpha, finalAlpha);
            mBackgroundFadeOutAnimation.addUpdateListener(new AnimatorUpdateListener() {

                public void onAnimationUpdate(ValueAnimator animation) {
                    setBackgroundAlpha(((Float) animation.getAnimatedValue()).floatValue());
                }
            });
            mBackgroundFadeOutAnimation.setInterpolator(new DecelerateInterpolator(1.5f));
            mBackgroundFadeOutAnimation.setDuration(BACKGROUND_FADE_OUT_DURATION);
            mBackgroundFadeOutAnimation.start();
        } else {
            setBackgroundAlpha(finalAlpha);
        }
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 85 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by DirtyUnicorns.

the class VolumeDialogMotion method startDismiss.

public void startDismiss(final Runnable onComplete) {
    if (D.BUG)
        Log.d(TAG, "startDismiss");
    if (mDismissing)
        return;
    setDismissing(true);
    if (mShowing) {
        mDialogView.animate().cancel();
        if (mContentsPositionAnimator != null) {
            mContentsPositionAnimator.cancel();
        }
        mContents.animate().cancel();
        if (mChevronPositionAnimator != null) {
            mChevronPositionAnimator.cancel();
        }
        mChevron.animate().cancel();
        setShowing(false);
    }
    mDialogView.animate().translationY(-mDialogView.getHeight()).setDuration(scaledDuration(250)).setInterpolator(new LogAccelerateInterpolator()).setUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mContents.setTranslationY(-mDialogView.getTranslationY());
            final int posY = chevronPosY();
            mChevron.setTranslationY(posY + -mDialogView.getTranslationY());
        }
    }).setListener(new AnimatorListenerAdapter() {

        private boolean mCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mCancelled)
                return;
            if (D.BUG)
                Log.d(TAG, "dismiss.onAnimationEnd");
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (D.BUG)
                        Log.d(TAG, "mDialog.dismiss()");
                    mDialog.dismiss();
                    onComplete.run();
                    setDismissing(false);
                }
            }, PRE_DISMISS_DELAY);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (D.BUG)
                Log.d(TAG, "dismiss.onAnimationCancel");
            mCancelled = true;
        }
    }).start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Aggregations

AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)94 ValueAnimator (android.animation.ValueAnimator)88 Animator (android.animation.Animator)65 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)62 ObjectAnimator (android.animation.ObjectAnimator)31 TimeInterpolator (android.animation.TimeInterpolator)14 View (android.view.View)13 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)12 Interpolator (android.view.animation.Interpolator)12 Resources (android.content.res.Resources)9 SuppressLint (android.annotation.SuppressLint)8 AnimatorSet (android.animation.AnimatorSet)7 Rect (android.graphics.Rect)7 ImageView (android.widget.ImageView)7 PropertyValuesHolder (android.animation.PropertyValuesHolder)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)6 Point (android.graphics.Point)6 PointF (android.graphics.PointF)6 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)6 TextView (android.widget.TextView)6