Search in sources :

Example 46 with Animation

use of android.view.animation.Animation in project UltimateAndroid by cymcsg.

the class AnimationFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mListView = (QuickReturnListView) getListView();
    mQuickReturnView.setText("Animation");
    mListView.addHeaderView(mHeader);
    String[] array = new String[] { "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android" };
    setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.quick_return_listview_list_item, R.id.text1, array));
    mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            mQuickReturnHeight = mQuickReturnView.getHeight();
            mListView.computeScrollY();
            mCachedVerticalScrollRange = mListView.getListHeight();
        }
    });
    mListView.setOnScrollListener(new OnScrollListener() {

        @SuppressLint("NewApi")
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            mScrollY = 0;
            int translationY = 0;
            if (mListView.scrollYIsComputed()) {
                mScrollY = mListView.getComputedScrollY();
            }
            rawY = mPlaceHolder.getTop() - Math.min(mCachedVerticalScrollRange - mListView.getHeight(), mScrollY);
            switch(mState) {
                case STATE_OFFSCREEN:
                    if (rawY <= mMinRawY) {
                        mMinRawY = rawY;
                    } else {
                        mState = STATE_RETURNING;
                    }
                    translationY = rawY;
                    break;
                case STATE_ONSCREEN:
                    if (rawY < -mQuickReturnHeight) {
                        System.out.println("test3");
                        mState = STATE_OFFSCREEN;
                        mMinRawY = rawY;
                    }
                    translationY = rawY;
                    break;
                case STATE_RETURNING:
                    if (translationY > 0) {
                        translationY = 0;
                        mMinRawY = rawY - mQuickReturnHeight;
                    } else if (rawY > 0) {
                        mState = STATE_ONSCREEN;
                        translationY = rawY;
                    } else if (translationY < -mQuickReturnHeight) {
                        mState = STATE_OFFSCREEN;
                        mMinRawY = rawY;
                    } else if (mQuickReturnView.getTranslationY() != 0 && !noAnimation) {
                        noAnimation = true;
                        anim = new TranslateAnimation(0, 0, -mQuickReturnHeight, 0);
                        anim.setFillAfter(true);
                        anim.setDuration(250);
                        mQuickReturnView.startAnimation(anim);
                        anim.setAnimationListener(new AnimationListener() {

                            @Override
                            public void onAnimationStart(Animation animation) {
                            // TODO Auto-generated method stub
                            }

                            @Override
                            public void onAnimationRepeat(Animation animation) {
                            // TODO Auto-generated method stub
                            }

                            @Override
                            public void onAnimationEnd(Animation animation) {
                                noAnimation = false;
                                mMinRawY = rawY;
                                mState = STATE_EXPANDED;
                            }
                        });
                    }
                    break;
                case STATE_EXPANDED:
                    if (rawY < mMinRawY - 2 && !noAnimation) {
                        noAnimation = true;
                        anim = new TranslateAnimation(0, 0, 0, -mQuickReturnHeight);
                        anim.setFillAfter(true);
                        anim.setDuration(250);
                        anim.setAnimationListener(new AnimationListener() {

                            @Override
                            public void onAnimationStart(Animation animation) {
                            }

                            @Override
                            public void onAnimationRepeat(Animation animation) {
                            }

                            @Override
                            public void onAnimationEnd(Animation animation) {
                                noAnimation = false;
                                mState = STATE_OFFSCREEN;
                            }
                        });
                        mQuickReturnView.startAnimation(anim);
                    } else if (translationY > 0) {
                        translationY = 0;
                        mMinRawY = rawY - mQuickReturnHeight;
                    } else if (rawY > 0) {
                        mState = STATE_ONSCREEN;
                        translationY = rawY;
                    } else if (translationY < -mQuickReturnHeight) {
                        mState = STATE_OFFSCREEN;
                        mMinRawY = rawY;
                    } else {
                        mMinRawY = rawY;
                    }
            }
            /** this can be used if the build is below honeycomb **/
            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
                anim = new TranslateAnimation(0, 0, translationY, translationY);
                anim.setFillAfter(true);
                anim.setDuration(0);
                mQuickReturnView.startAnimation(anim);
            } else {
                mQuickReturnView.setTranslationY(translationY);
            }
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    });
}
Also used : AbsListView(android.widget.AbsListView) TranslateAnimation(android.view.animation.TranslateAnimation) SuppressLint(android.annotation.SuppressLint) OnScrollListener(android.widget.AbsListView.OnScrollListener) SuppressLint(android.annotation.SuppressLint) TranslateAnimation(android.view.animation.TranslateAnimation) Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener) ViewTreeObserver(android.view.ViewTreeObserver)

Example 47 with Animation

use of android.view.animation.Animation in project UltimateAndroid by cymcsg.

the class ArcLayout method bindChildAnimation.

private void bindChildAnimation(final View child, final int index, final long duration) {
    final boolean expanded = mExpanded;
    final int centerX = getWidth() / 2;
    final int centerY = getHeight() / 2;
    final int radius = expanded ? 0 : mRadius;
    final int childCount = getChildCount();
    final float perDegrees = (mToDegrees - mFromDegrees) / (childCount - 1);
    Rect frame = computeChildFrame(centerX, centerY, radius, mFromDegrees + index * perDegrees, mChildSize);
    final int toXDelta = frame.left - child.getLeft();
    final int toYDelta = frame.top - child.getTop();
    Interpolator interpolator = mExpanded ? new AccelerateInterpolator() : new OvershootInterpolator(1.5f);
    final long startOffset = computeStartOffset(childCount, mExpanded, index, 0.1f, duration, interpolator);
    Animation animation = mExpanded ? createShrinkAnimation(0, toXDelta, 0, toYDelta, startOffset, duration, interpolator) : createExpandAnimation(0, toXDelta, 0, toYDelta, startOffset, duration, interpolator);
    final boolean isLast = getTransformedIndex(expanded, childCount, index) == childCount - 1;
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (isLast) {
                postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        onAllAnimationsEnd();
                    }
                }, 0);
            }
        }
    });
    child.setAnimation(animation);
}
Also used : Rect(android.graphics.Rect) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) OvershootInterpolator(android.view.animation.OvershootInterpolator) RotateAnimation(android.view.animation.RotateAnimation) Animation(android.view.animation.Animation) Interpolator(android.view.animation.Interpolator) LinearInterpolator(android.view.animation.LinearInterpolator) OvershootInterpolator(android.view.animation.OvershootInterpolator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) AnimationListener(android.view.animation.Animation.AnimationListener)

Example 48 with Animation

use of android.view.animation.Animation in project UltimateAndroid by cymcsg.

the class ArcLayout method createExpandAnimation.

private static Animation createExpandAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta, long startOffset, long duration, Interpolator interpolator) {
    Animation animation = new RotateAndTranslateAnimation(0, toXDelta, 0, toYDelta, 0, 720);
    animation.setStartOffset(startOffset);
    animation.setDuration(duration);
    animation.setInterpolator(interpolator);
    animation.setFillAfter(true);
    return animation;
}
Also used : RotateAnimation(android.view.animation.RotateAnimation) Animation(android.view.animation.Animation)

Example 49 with Animation

use of android.view.animation.Animation in project UltimateAndroid by cymcsg.

the class ArcLayout method createShrinkAnimation.

private static Animation createShrinkAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta, long startOffset, long duration, Interpolator interpolator) {
    AnimationSet animationSet = new AnimationSet(false);
    animationSet.setFillAfter(true);
    final long preDuration = duration / 2;
    Animation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    rotateAnimation.setStartOffset(startOffset);
    rotateAnimation.setDuration(preDuration);
    rotateAnimation.setInterpolator(new LinearInterpolator());
    rotateAnimation.setFillAfter(true);
    animationSet.addAnimation(rotateAnimation);
    Animation translateAnimation = new RotateAndTranslateAnimation(0, toXDelta, 0, toYDelta, 360, 720);
    translateAnimation.setStartOffset(startOffset + preDuration);
    translateAnimation.setDuration(duration - preDuration);
    translateAnimation.setInterpolator(interpolator);
    translateAnimation.setFillAfter(true);
    animationSet.addAnimation(translateAnimation);
    return animationSet;
}
Also used : RotateAnimation(android.view.animation.RotateAnimation) LinearInterpolator(android.view.animation.LinearInterpolator) RotateAnimation(android.view.animation.RotateAnimation) Animation(android.view.animation.Animation) AnimationSet(android.view.animation.AnimationSet)

Example 50 with Animation

use of android.view.animation.Animation in project UltimateAndroid by cymcsg.

the class ArcMenu method bindItemAnimation.

private Animation bindItemAnimation(final View child, final boolean isClicked, final long duration) {
    Animation animation = createItemDisapperAnimation(duration, isClicked);
    child.setAnimation(animation);
    return animation;
}
Also used : ScaleAnimation(android.view.animation.ScaleAnimation) RotateAnimation(android.view.animation.RotateAnimation) AlphaAnimation(android.view.animation.AlphaAnimation) Animation(android.view.animation.Animation)

Aggregations

Animation (android.view.animation.Animation)943 AlphaAnimation (android.view.animation.AlphaAnimation)241 TranslateAnimation (android.view.animation.TranslateAnimation)190 ScaleAnimation (android.view.animation.ScaleAnimation)146 Transformation (android.view.animation.Transformation)114 View (android.view.View)104 AnimationListener (android.view.animation.Animation.AnimationListener)98 AnimationSet (android.view.animation.AnimationSet)94 RotateAnimation (android.view.animation.RotateAnimation)63 ImageView (android.widget.ImageView)48 TextView (android.widget.TextView)47 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)43 Point (android.graphics.Point)40 WindowAnimation_activityCloseEnterAnimation (com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation)35 WindowAnimation_activityCloseExitAnimation (com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation)35 WindowAnimation_activityOpenEnterAnimation (com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation)35 WindowAnimation_activityOpenExitAnimation (com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation)35 WindowAnimation_taskCloseEnterAnimation (com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation)35 WindowAnimation_taskCloseExitAnimation (com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation)35 WindowAnimation_taskOpenEnterAnimation (com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation)35