Search in sources :

Example 11 with ValueAnimator

use of android.animation.ValueAnimator in project Launcher3 by chislon.

the class CellLayout method animateChildToPosition.

public boolean animateChildToPosition(final View child, int cellX, int cellY, int duration, int delay, boolean permanent, boolean adjustOccupied) {
    ShortcutAndWidgetContainer clc = getShortcutsAndWidgets();
    boolean[][] occupied = mOccupied;
    if (!permanent) {
        occupied = mTmpOccupied;
    }
    if (clc.indexOfChild(child) != -1) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        final ItemInfo info = (ItemInfo) child.getTag();
        // We cancel any existing animations
        if (mReorderAnimators.containsKey(lp)) {
            mReorderAnimators.get(lp).cancel();
            mReorderAnimators.remove(lp);
        }
        final int oldX = lp.x;
        final int oldY = lp.y;
        if (adjustOccupied) {
            occupied[lp.cellX][lp.cellY] = false;
            occupied[cellX][cellY] = true;
        }
        lp.isLockedToGrid = true;
        if (permanent) {
            lp.cellX = info.cellX = cellX;
            lp.cellY = info.cellY = cellY;
        } else {
            lp.tmpCellX = cellX;
            lp.tmpCellY = cellY;
        }
        clc.setupLp(lp);
        lp.isLockedToGrid = false;
        final int newX = lp.x;
        final int newY = lp.y;
        lp.x = oldX;
        lp.y = oldY;
        // Exit early if we're not actually moving the view
        if (oldX == newX && oldY == newY) {
            lp.isLockedToGrid = true;
            return true;
        }
        ValueAnimator va = LauncherAnimUtils.ofFloat(child, 0f, 1f);
        va.setDuration(duration);
        mReorderAnimators.put(lp, va);
        va.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float r = ((Float) animation.getAnimatedValue()).floatValue();
                lp.x = (int) ((1 - r) * oldX + r * newX);
                lp.y = (int) ((1 - r) * oldY + r * newY);
                child.requestLayout();
            }
        });
        va.addListener(new AnimatorListenerAdapter() {

            boolean cancelled = false;

            public void onAnimationEnd(Animator animation) {
                // place just yet.
                if (!cancelled) {
                    lp.isLockedToGrid = true;
                    child.requestLayout();
                }
                if (mReorderAnimators.containsKey(lp)) {
                    mReorderAnimators.remove(lp);
                }
            }

            public void onAnimationCancel(Animator animation) {
                cancelled = true;
            }
        });
        va.setStartDelay(delay);
        va.start();
        return true;
    }
    return false;
}
Also used : FolderRingAnimator(com.android.launcher3.FolderIcon.FolderRingAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 12 with ValueAnimator

use of android.animation.ValueAnimator in project Launcher3 by chislon.

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 13 with ValueAnimator

use of android.animation.ValueAnimator in project Launcher3 by chislon.

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 14 with ValueAnimator

use of android.animation.ValueAnimator in project UltimateRecyclerView by cymcsg.

the class parent method rotationExpandIcon.

@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void rotationExpandIcon(float from, float to) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(from, to);
        valueAnimator.setDuration(150);
        valueAnimator.setInterpolator(new LinearOutSlowInInterpolator());
        valueAnimator.addUpdateListener(this);
        valueAnimator.start();
    }
}
Also used : LinearOutSlowInInterpolator(android.support.v4.view.animation.LinearOutSlowInInterpolator) ValueAnimator(android.animation.ValueAnimator) TargetApi(android.annotation.TargetApi)

Example 15 with ValueAnimator

use of android.animation.ValueAnimator in project SogoLoading by dengshiwei.

the class SoGouBrowserLoading method playAnimator.

//动画执行
private void playAnimator() {
    //我们只需要取Y轴方向上的变化即可
    ValueAnimator valueAnimator = ValueAnimator.ofInt(startY, endY);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            currentY = (Integer) animation.getAnimatedValue();
            invalidate();
        }
    });
    valueAnimator.setInterpolator(new AccelerateInterpolator(1.2f));
    valueAnimator.setRepeatCount(-1);
    valueAnimator.setRepeatMode(2);
    valueAnimator.setDuration(500);
    valueAnimator.start();
}
Also used : AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ValueAnimator(android.animation.ValueAnimator)

Aggregations

ValueAnimator (android.animation.ValueAnimator)710 Animator (android.animation.Animator)374 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)306 ObjectAnimator (android.animation.ObjectAnimator)141 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)88 ArrayList (java.util.ArrayList)75 Paint (android.graphics.Paint)66 AnimatorSet (android.animation.AnimatorSet)57 LinearInterpolator (android.view.animation.LinearInterpolator)50 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)49 View (android.view.View)47 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)40 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)32 PropertyValuesHolder (android.animation.PropertyValuesHolder)31 ViewGroup (android.view.ViewGroup)30 ArgbEvaluator (android.animation.ArgbEvaluator)28 Interpolator (android.view.animation.Interpolator)26 TextView (android.widget.TextView)25 RenderNodeAnimator (android.view.RenderNodeAnimator)20 Rect (android.graphics.Rect)19