Search in sources :

Example 6 with Animator

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

the class SwipeDismissListViewTouchListener method performDismiss.

protected void performDismiss(final PendingDismissData data) {
    // Animate the dismissed list item to zero-height and fire the
    // dismiss callback when all dismissed list item animations have
    // completed.
    final ViewGroup.LayoutParams lp = data.view.getLayoutParams();
    final int originalHeight = data.view.getHeight();
    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(final ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            data.view.setLayoutParams(lp);
        }
    });
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(final Animator animation) {
            finalizeDismiss();
        }
    });
    animator.start();
}
Also used : ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator) Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) ViewPropertyAnimator(com.marshalchen.common.uimodule.nineoldandroids.view.ViewPropertyAnimator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator) SuppressLint(android.annotation.SuppressLint)

Example 7 with Animator

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

the class FilckerAnimationListView method animatePreLayout.

/**
	 * Animate items that are deleted entirely and items that move out of
	 * bounds.
	 */
private void animatePreLayout(final float durationUnit, final Animator.AnimatorListener listener) {
    final AnimatorSet animatorSet = new AnimatorSet();
    final int firstVisiblePosition = getFirstVisiblePosition();
    final int childCount = getChildCount();
    for (final Iterator<Entry<Long, Float>> iter = yMap.entrySet().iterator(); iter.hasNext(); ) {
        final Entry<Long, Float> entry = iter.next();
        final long id = entry.getKey();
        final int oldPos = positionMap.get(id);
        final View child = getChildAt(oldPos - firstVisiblePosition);
        final int newPos = getPositionForId(id);
        // fade out items that disappear
        if (newPos == -1) {
            final ObjectAnimator anim = animateAlpha(child, false);
            animatorSet.play(anim);
            iter.remove();
            positionMap.remove(id);
            continue;
        }
        // translate items that move out of bounds
        if (newPos < firstVisiblePosition || newPos > firstVisiblePosition + childCount) {
            final float offset;
            if (newPos < firstVisiblePosition) {
                offset = -getHeight();
            } else {
                offset = getHeight();
            }
            final AnimatorProxy proxy = AnimatorProxy.wrap(child);
            final ObjectAnimator anim = ObjectAnimator.ofFloat(proxy, "translationY", 0f, offset);
            final int finalDuration = getDuration(0, getHeight() / 2, durationUnit);
            anim.setInterpolator(new AccelerateInterpolator());
            anim.setDuration((long) (finalDuration * animationDurationFactor));
            animatorSet.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(final Animator animation) {
                    child.post(new Runnable() {

                        @Override
                        public void run() {
                            proxy.setTranslationY(0f);
                        }
                    });
                }
            });
            animatorSet.play(anim);
            iter.remove();
            positionMap.remove(id);
            continue;
        }
    }
    if (!animatorSet.getChildAnimations().isEmpty()) {
        animatorSet.addListener(listener);
        animatorSet.start();
    } else {
        listener.onAnimationEnd(animatorSet);
    }
}
Also used : AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) AnimatorSet(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorSet) View(android.view.View) ListView(android.widget.ListView) Entry(java.util.Map.Entry) Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter) AnimatorProxy(com.marshalchen.common.uimodule.nineoldandroids.view.animation.AnimatorProxy)

Example 8 with Animator

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

the class FilckerAnimationListView method animatePostLayout.

/**
	 * Animate items that just appeared and items that move within the screen.
	 */
private void animatePostLayout(final float durationUnit) {
    final AnimatorSet animatorSet = new AnimatorSet();
    for (int i = 0; i < getChildCount(); i++) {
        final View child = getChildAt(i);
        final long id = getItemIdAtPosition(getFirstVisiblePosition() + i);
        ObjectAnimator anim = null;
        ViewHelper.setAlpha(child, 1f);
        if (yMap.containsKey(id)) {
            // moved within visible area
            // log("Moved within visible area id: " + id);
            final float oldY = yMap.remove(id);
            final float newY = ViewHelper.getY(child);
            if (oldY != newY) {
                anim = animateY(child, oldY, newY, durationUnit);
            }
        } else {
            if (beforeVisible.contains(id)) {
                // moved from top
                final float newY = ViewHelper.getY(child);
                final float oldY = -child.getHeight();
                anim = animateY(child, oldY, newY, durationUnit);
            } else if (afterVisible.contains(id)) {
                // moved from bottom
                final float newY = ViewHelper.getY(child);
                final float oldY = getHeight();
                anim = animateY(child, oldY, newY, durationUnit);
            } else {
                // entirely new
                ViewHelper.setAlpha(child, 0f);
                anim = animateAlpha(child, true);
                anim.setStartDelay(MIN_ANIM_DURATION);
            }
        }
        if (anim != null) {
            animatorSet.play(anim);
        }
    }
    animatorSet.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(final Animator animation) {
            finishAnimation();
        }

        ;
    });
    animatorSet.start();
}
Also used : Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter) AnimatorSet(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorSet) View(android.view.View) ListView(android.widget.ListView)

Example 9 with Animator

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

the class Titanic method start.

public void start(final TitanicTextView textView) {
    final Runnable animate = new Runnable() {

        @Override
        public void run() {
            textView.setSinking(true);
            // horizontal animation. 200 = wave.png width
            ObjectAnimator maskXAnimator = ObjectAnimator.ofFloat(textView, "maskX", 0, 200);
            maskXAnimator.setRepeatCount(ValueAnimator.INFINITE);
            maskXAnimator.setDuration(1000);
            maskXAnimator.setStartDelay(0);
            int h = textView.getHeight();
            // vertical animation
            // maskY = 0 -> wave vertically centered
            // repeat mode REVERSE to go back and forth
            ObjectAnimator maskYAnimator = ObjectAnimator.ofFloat(textView, "maskY", h / 2, -h / 2);
            maskYAnimator.setRepeatCount(ValueAnimator.INFINITE);
            maskYAnimator.setRepeatMode(ValueAnimator.REVERSE);
            maskYAnimator.setDuration(10000);
            maskYAnimator.setStartDelay(0);
            // now play both animations together
            animatorSet = new AnimatorSet();
            animatorSet.playTogether(maskXAnimator, maskYAnimator);
            animatorSet.setInterpolator(new LinearInterpolator());
            animatorSet.addListener(new Animator.AnimatorListener() {

                @Override
                public void onAnimationStart(Animator animation) {
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    textView.setSinking(false);
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                        textView.postInvalidate();
                    } else {
                        textView.postInvalidateOnAnimation();
                    }
                    animatorSet = null;
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                }

                @Override
                public void onAnimationRepeat(Animator animation) {
                }
            });
            if (animatorListener != null) {
                animatorSet.addListener(animatorListener);
            }
            animatorSet.start();
        }
    };
    if (!textView.isSetUp()) {
        textView.setAnimationSetupCallback(new TitanicTextView.AnimationSetupCallback() {

            @Override
            public void onSetupAnimation(final TitanicTextView target) {
                animate.run();
            }
        });
    } else {
        animate.run();
    }
}
Also used : ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) LinearInterpolator(android.view.animation.LinearInterpolator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) AnimatorSet(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorSet)

Example 10 with Animator

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

the class AndroidAnimationsDemoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.android_animations_activity);
    mListView = (ListView) findViewById(R.id.list_items);
    mTarget = findViewById(R.id.hello_world);
    mAdapter = new EffectAdapter(this);
    mListView.setAdapter(mAdapter);
    // after start,just click mTarget view, rope is not init
    rope = YoYo.with(Techniques.FadeIn).duration(1000).playOn(mTarget);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Techniques technique = (Techniques) view.getTag();
            rope = YoYo.with(technique).duration(1200).interpolate(new AccelerateDecelerateInterpolator()).withListener(new Animator.AnimatorListener() {

                @Override
                public void onAnimationStart(Animator animation) {
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    Toast.makeText(AndroidAnimationsDemoActivity.this, "canceled", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onAnimationRepeat(Animator animation) {
                }
            }).playOn(mTarget);
        }
    });
    findViewById(R.id.hello_world).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (rope != null) {
                rope.stop(true);
            }
        }
    });
}
Also used : Techniques(com.marshalchen.common.uimodule.androidanimations.Techniques) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) AdapterView(android.widget.AdapterView)

Aggregations

Animator (com.marshalchen.common.uimodule.nineoldandroids.animation.Animator)24 ValueAnimator (com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator)15 AnimatorListenerAdapter (com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter)14 View (android.view.View)8 ObjectAnimator (com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator)8 AnimatorSet (com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorSet)5 ListView (android.widget.ListView)4 ViewPropertyAnimator (com.marshalchen.common.uimodule.nineoldandroids.view.ViewPropertyAnimator)4 SuppressLint (android.annotation.SuppressLint)3 HashMap (java.util.HashMap)2 Rect (android.graphics.Rect)1 ViewGroup (android.view.ViewGroup)1 OnPreDrawListener (android.view.ViewTreeObserver.OnPreDrawListener)1 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)1 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)1 LinearInterpolator (android.view.animation.LinearInterpolator)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 Techniques (com.marshalchen.common.uimodule.androidanimations.Techniques)1 AnimatorUpdateListener (com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener)1