Search in sources :

Example 66 with AnimatorUpdateListener

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

the class PagedView method onFlingToDelete.

public void onFlingToDelete(PointF vel) {
    final long startTime = AnimationUtils.currentAnimationTimeMillis();
    // NOTE: Because it takes time for the first frame of animation to actually be
    // called and we expect the animation to be a continuation of the fling, we have
    // to account for the time that has elapsed since the fling finished.  And since
    // we don't have a startDelay, we will always get call to update when we call
    // start() (which we want to ignore).
    final TimeInterpolator tInterpolator = new TimeInterpolator() {

        private int mCount = -1;

        private long mStartTime;

        private float mOffset;

        /* Anonymous inner class ctor */
        {
            mStartTime = startTime;
        }

        @Override
        public float getInterpolation(float t) {
            if (mCount < 0) {
                mCount++;
            } else if (mCount == 0) {
                mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION);
                mCount++;
            }
            return Math.min(1f, mOffset + t);
        }
    };
    final Rect from = new Rect();
    final View dragView = mDragView;
    from.left = (int) dragView.getTranslationX();
    from.top = (int) dragView.getTranslationY();
    AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION);
    final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView);
    // Create and start the animation
    ValueAnimator mDropAnim = new ValueAnimator();
    mDropAnim.setInterpolator(tInterpolator);
    mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION);
    mDropAnim.setFloatValues(0f, 1f);
    mDropAnim.addUpdateListener(updateCb);
    mDropAnim.addListener(new AnimatorListenerAdapter() {

        public void onAnimationEnd(Animator animation) {
            onAnimationEndRunnable.run();
        }
    });
    mDropAnim.start();
    mDeferringForDelete = true;
}
Also used : Rect(android.graphics.Rect) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) TimeInterpolator(android.animation.TimeInterpolator) View(android.view.View)

Example 67 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project MPAndroidChart by PhilJay.

the class Chart method init.

/**
     * initialize all paints and stuff
     */
protected void init() {
    setWillNotDraw(false);
    if (android.os.Build.VERSION.SDK_INT < 11)
        mAnimator = new ChartAnimator();
    else
        mAnimator = new ChartAnimator(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                // ViewCompat.postInvalidateOnAnimation(Chart.this);
                postInvalidate();
            }
        });
    // initialize the utils
    Utils.init(getContext());
    mMaxHighlightDistance = Utils.convertDpToPixel(500f);
    mDescription = new Description();
    mLegend = new Legend();
    mLegendRenderer = new LegendRenderer(mViewPortHandler, mLegend);
    mXAxis = new XAxis();
    mDescPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mInfoPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    // orange
    mInfoPaint.setColor(Color.rgb(247, 189, 51));
    mInfoPaint.setTextAlign(Align.CENTER);
    mInfoPaint.setTextSize(Utils.convertDpToPixel(12f));
    if (mLogEnabled)
        Log.i("", "Chart.init()");
}
Also used : Legend(com.github.mikephil.charting.components.Legend) Description(com.github.mikephil.charting.components.Description) LegendRenderer(com.github.mikephil.charting.renderer.LegendRenderer) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) Paint(android.graphics.Paint) ValueAnimator(android.animation.ValueAnimator) ChartAnimator(com.github.mikephil.charting.animation.ChartAnimator) XAxis(com.github.mikephil.charting.components.XAxis)

Example 68 with AnimatorUpdateListener

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

the class DeleteDropTarget method createFlingToTrashAnimatorListener.

/**
     * Creates an animation from the current drag view to the delete trash icon.
     */
private AnimatorUpdateListener createFlingToTrashAnimatorListener(final DragLayer dragLayer, DragObject d, PointF vel, ViewConfiguration config) {
    final Rect to = getIconRect(d.dragView.getMeasuredWidth(), d.dragView.getMeasuredHeight(), mCurrentDrawable.getIntrinsicWidth(), mCurrentDrawable.getIntrinsicHeight());
    final Rect from = new Rect();
    dragLayer.getViewRectRelativeToSelf(d.dragView, from);
    // Calculate how far along the velocity vector we should put the intermediate point on
    // the bezier curve
    float velocity = Math.abs(vel.length());
    float vp = Math.min(1f, velocity / (config.getScaledMaximumFlingVelocity() / 2f));
    int offsetY = (int) (-from.top * vp);
    int offsetX = (int) (offsetY / (vel.y / vel.x));
    // intermediate t/l
    final float y2 = from.top + offsetY;
    final float x2 = from.left + offsetX;
    // drag view t/l
    final float x1 = from.left;
    final float y1 = from.top;
    // delete target t/l
    final float x3 = to.left;
    final float y3 = to.top;
    final TimeInterpolator scaleAlphaInterpolator = new TimeInterpolator() {

        @Override
        public float getInterpolation(float t) {
            return t * t * t * t * t * t * t * t;
        }
    };
    return new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            final DragView dragView = (DragView) dragLayer.getAnimatedView();
            float t = ((Float) animation.getAnimatedValue()).floatValue();
            float tp = scaleAlphaInterpolator.getInterpolation(t);
            float initialScale = dragView.getInitialScale();
            float finalAlpha = 0.5f;
            float scale = dragView.getScaleX();
            float x1o = ((1f - scale) * dragView.getMeasuredWidth()) / 2f;
            float y1o = ((1f - scale) * dragView.getMeasuredHeight()) / 2f;
            float x = (1f - t) * (1f - t) * (x1 - x1o) + 2 * (1f - t) * t * (x2 - x1o) + (t * t) * x3;
            float y = (1f - t) * (1f - t) * (y1 - y1o) + 2 * (1f - t) * t * (y2 - x1o) + (t * t) * y3;
            dragView.setTranslationX(x);
            dragView.setTranslationY(y);
            dragView.setScaleX(initialScale * (1f - tp));
            dragView.setScaleY(initialScale * (1f - tp));
            dragView.setAlpha(finalAlpha + (1f - finalAlpha) * (1f - tp));
        }
    };
}
Also used : Rect(android.graphics.Rect) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) TimeInterpolator(android.animation.TimeInterpolator)

Example 69 with AnimatorUpdateListener

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

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(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 : Animator(android.animation.Animator) FolderRingAnimator(org.fairphone.launcher.FolderIcon.FolderRingAnimator) 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 70 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)

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