Search in sources :

Example 6 with ValueAnimator

use of com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator in project UltimateAndroid by cymcsg.

the class RiseNumberTextView method runFloat.

private void runFloat() {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(fromNumber, number);
    valueAnimator.setDuration(duration);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            setText(fnum.format(Float.parseFloat(valueAnimator.getAnimatedValue().toString())));
            if (valueAnimator.getAnimatedFraction() >= 1) {
                mPlayingState = STOPPED;
                if (mEndListener != null)
                    mEndListener.onEndFinish();
            }
        }
    });
    valueAnimator.start();
}
Also used : ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator)

Example 7 with ValueAnimator

use of com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator in project UltimateAndroid by cymcsg.

the class ViewPropertyAnimatorHC method startAnimation.

/**
     * Starts the underlying Animator for a set of properties. We use a single animator that
     * simply runs from 0 to 1, and then use that fractional value to set each property
     * value accordingly.
     */
private void startAnimation() {
    ValueAnimator animator = ValueAnimator.ofFloat(1.0f);
    ArrayList<NameValuesHolder> nameValueList = (ArrayList<NameValuesHolder>) mPendingAnimations.clone();
    mPendingAnimations.clear();
    int propertyMask = 0;
    int propertyCount = nameValueList.size();
    for (int i = 0; i < propertyCount; ++i) {
        NameValuesHolder nameValuesHolder = nameValueList.get(i);
        propertyMask |= nameValuesHolder.mNameConstant;
    }
    mAnimatorMap.put(animator, new PropertyBundle(propertyMask, nameValueList));
    animator.addUpdateListener(mAnimatorEventListener);
    animator.addListener(mAnimatorEventListener);
    if (mStartDelaySet) {
        animator.setStartDelay(mStartDelay);
    }
    if (mDurationSet) {
        animator.setDuration(mDuration);
    }
    if (mInterpolatorSet) {
        animator.setInterpolator(mInterpolator);
    }
    animator.start();
}
Also used : ArrayList(java.util.ArrayList) ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator)

Example 8 with ValueAnimator

use of com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator in project UltimateAndroid by cymcsg.

the class SwipeDismissListViewTouchListener method performDismiss.

private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.
    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();
    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);
                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }
                mCallbacks.onDismiss(mListView, dismissPositions);
                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;
                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    AnimatorProxy.wrap(pendingDismiss.view).setAlpha(1f);
                    AnimatorProxy.wrap(pendingDismiss.view).setTranslationX(0);
                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalHeight;
                    pendingDismiss.view.setLayoutParams(lp);
                }
                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mListView.dispatchTouchEvent(cancelEvent);
                mPendingDismisses.clear();
            }
        }
    });
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });
    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}
Also used : ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator) Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator)

Example 9 with ValueAnimator

use of com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator in project UltimateAndroid by cymcsg.

the class ContextualUndoAdapter method performRemovalIfNecessary.

private void performRemovalIfNecessary() {
    if (mCurrentRemovedId == -1) {
        return;
    }
    ContextualUndoView currentRemovedView = getCurrentRemovedView(mCurrentRemovedView, mCurrentRemovedId);
    if (currentRemovedView != null) {
        ValueAnimator animator = ValueAnimator.ofInt(currentRemovedView.getHeight(), 1).setDuration(ANIMATION_DURATION);
        RemoveViewAnimatorListenerAdapter listener = new RemoveViewAnimatorListenerAdapter(currentRemovedView, mCurrentRemovedId);
        RemoveViewAnimatorUpdateListener updateListener = new RemoveViewAnimatorUpdateListener(listener);
        animator.addListener(listener);
        animator.addUpdateListener(updateListener);
        animator.start();
    } else {
        // The hard way.
        deleteItemGivenId(mCurrentRemovedId);
    }
    clearCurrentRemovedView();
}
Also used : ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator)

Example 10 with ValueAnimator

use of com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator in project UltimateAndroid by cymcsg.

the class PanningViewAttacher method animate.

private void animate(float start, float end, long duration) {
    Log.d(TAG, "startPanning : " + start + " to " + end + ", in " + duration + "ms");
    mCurrentAnimator = ValueAnimator.ofFloat(start, end);
    mCurrentAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            mMatrix.reset();
            applyScaleOnMatrix();
            if (mIsPortrait) {
                mMatrix.postTranslate(value, 0);
            } else {
                mMatrix.postTranslate(0, value);
            }
            refreshDisplayRect();
            mCurrentPlayTime = animation.getCurrentPlayTime();
            setCurrentImageMatrix();
        }
    });
    mCurrentAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            Log.d(TAG, "animation has finished, startPanning in the other way");
            changeWay();
            animate_();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            Log.d(TAG, "panning animation canceled");
        }
    });
    mCurrentAnimator.setDuration(duration);
    mCurrentAnimator.setInterpolator(mLinearInterpolator);
    mCurrentAnimator.start();
}
Also used : ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator) Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator)

Aggregations

ValueAnimator (com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator)11 Animator (com.marshalchen.common.uimodule.nineoldandroids.animation.Animator)5 AnimatorListenerAdapter (com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter)5 ViewPropertyAnimator (com.marshalchen.common.uimodule.nineoldandroids.view.ViewPropertyAnimator)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AnimatorUpdateListener (com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener)1