Search in sources :

Example 31 with AnimationListener

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

the class RayLayout method bindChildAnimation.

private void bindChildAnimation(final View child, final int index, final long duration) {
    final boolean expanded = mExpanded;
    final int childCount = getChildCount();
    Rect frame = computeChildFrame(!expanded, mLeftHolderWidth, index, mChildGap, 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 32 with AnimationListener

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

the class RayMenu method getItemClickListener.

private OnClickListener getItemClickListener(final OnClickListener listener) {
    return new OnClickListener() {

        @Override
        public void onClick(final View viewClicked) {
            Animation animation = bindItemAnimation(viewClicked, true, 400);
            animation.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

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

                        @Override
                        public void run() {
                            itemDidDisappear();
                        }
                    }, 0);
                }
            });
            final int itemCount = mRayLayout.getChildCount();
            for (int i = 0; i < itemCount; i++) {
                View item = mRayLayout.getChildAt(i);
                if (viewClicked != item) {
                    bindItemAnimation(item, false, 300);
                }
            }
            mRayLayout.invalidate();
            mHintView.startAnimation(createHintSwitchAnimation(true));
            if (listener != null) {
                listener.onClick(viewClicked);
            }
        }
    };
}
Also used : ScaleAnimation(android.view.animation.ScaleAnimation) RotateAnimation(android.view.animation.RotateAnimation) AlphaAnimation(android.view.animation.AlphaAnimation) Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener) ImageView(android.widget.ImageView) View(android.view.View)

Example 33 with AnimationListener

use of android.view.animation.Animation.AnimationListener in project android_frameworks_base by ParanoidAndroid.

the class SlidingTab method startAnimating.

void startAnimating(final boolean holdAfter) {
    mAnimating = true;
    final Animation trans1;
    final Animation trans2;
    final Slider slider = mCurrentSlider;
    final Slider other = mOtherSlider;
    final int dx;
    final int dy;
    if (isHorizontal()) {
        int right = slider.tab.getRight();
        int width = slider.tab.getWidth();
        int left = slider.tab.getLeft();
        int viewWidth = getWidth();
        // how much of tab to show at the end of anim
        int holdOffset = holdAfter ? 0 : width;
        dx = slider == mRightSlider ? -(right + viewWidth - holdOffset) : (viewWidth - left) + viewWidth - holdOffset;
        dy = 0;
    } else {
        int top = slider.tab.getTop();
        int bottom = slider.tab.getBottom();
        int height = slider.tab.getHeight();
        int viewHeight = getHeight();
        // how much of tab to show at end of anim
        int holdOffset = holdAfter ? 0 : height;
        dx = 0;
        dy = slider == mRightSlider ? (top + viewHeight - holdOffset) : -((viewHeight - bottom) + viewHeight - holdOffset);
    }
    trans1 = new TranslateAnimation(0, dx, 0, dy);
    trans1.setDuration(ANIM_DURATION);
    trans1.setInterpolator(new LinearInterpolator());
    trans1.setFillAfter(true);
    trans2 = new TranslateAnimation(0, dx, 0, dy);
    trans2.setDuration(ANIM_DURATION);
    trans2.setInterpolator(new LinearInterpolator());
    trans2.setFillAfter(true);
    trans1.setAnimationListener(new AnimationListener() {

        public void onAnimationEnd(Animation animation) {
            Animation anim;
            if (holdAfter) {
                anim = new TranslateAnimation(dx, dx, dy, dy);
                // plenty of time for transitions
                anim.setDuration(1000);
                mAnimating = false;
            } else {
                anim = new AlphaAnimation(0.5f, 1.0f);
                anim.setDuration(ANIM_DURATION);
                resetView();
            }
            anim.setAnimationListener(mAnimationDoneListener);
            /* Animation can be the same for these since the animation just holds */
            mLeftSlider.startAnimation(anim, anim);
            mRightSlider.startAnimation(anim, anim);
        }

        public void onAnimationRepeat(Animation animation) {
        }

        public void onAnimationStart(Animation animation) {
        }
    });
    slider.hideTarget();
    slider.startAnimation(trans1, trans2);
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) TranslateAnimation(android.view.animation.TranslateAnimation) AlphaAnimation(android.view.animation.AlphaAnimation) Animation(android.view.animation.Animation) TranslateAnimation(android.view.animation.TranslateAnimation) AnimationListener(android.view.animation.Animation.AnimationListener) AlphaAnimation(android.view.animation.AlphaAnimation)

Example 34 with AnimationListener

use of android.view.animation.Animation.AnimationListener in project Roundr by MohammadAdib.

the class StandOutWindow method hide.

/**
	 * Hide a window corresponding to the id. Show a notification for the hidden
	 * window.
	 * 
	 * @param id
	 *            The id of the window.
	 */
public final synchronized void hide(int id) {
    // get the view corresponding to the id
    final Window window = getWindow(id);
    if (window == null) {
        throw new IllegalArgumentException("Tried to hide(" + id + ") a null window.");
    }
    if (window.visibility == Window.VISIBILITY_GONE) {
        throw new IllegalStateException("Tried to hide(" + id + ") a window that is not shown.");
    }
    // alert callbacks and cancel if instructed
    if (onHide(id, window)) {
        Log.w(TAG, "Window " + id + " hide cancelled by implementation.");
        return;
    }
    // check if hide enabled
    if (Utils.isSet(window.flags, StandOutFlags.FLAG_WINDOW_HIDE_ENABLE)) {
        window.visibility = Window.VISIBILITY_TRANSITION;
        // get the hidden notification for this view
        Notification notification = getHiddenNotification(id);
        // get animation
        Animation animation = getHideAnimation(id);
        try {
            // animate
            if (animation != null) {
                animation.setAnimationListener(new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        // remove the window from the window manager
                        mWindowManager.removeView(window);
                        window.visibility = Window.VISIBILITY_GONE;
                    }
                });
                window.getChildAt(0).startAnimation(animation);
            } else {
                // remove the window from the window manager
                mWindowManager.removeView(window);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        // display the notification
        notification.flags = notification.flags | Notification.FLAG_NO_CLEAR | Notification.FLAG_AUTO_CANCEL;
        mNotificationManager.notify(getClass().hashCode() + id, notification);
    } else {
        // if hide not enabled, close window
        close(id);
    }
}
Also used : Window(wei.mark.standout.ui.Window) PopupWindow(android.widget.PopupWindow) Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener) Notification(android.app.Notification)

Example 35 with AnimationListener

use of android.view.animation.Animation.AnimationListener in project ThinkAndroid by white-cat.

the class SplashActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    // TANetworkStateReceiver.registerNetworkStateReceiver(this);
    final View view = View.inflate(this, R.layout.splash, null);
    setContentView(view);
    // 渐变展示启动屏
    AlphaAnimation aa = new AlphaAnimation(0.5f, 1.0f);
    aa.setDuration(5000);
    view.startAnimation(aa);
    aa.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationEnd(Animation arg0) {
            startMain();
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationStart(Animation animation) {
        }
    });
}
Also used : AlphaAnimation(android.view.animation.AlphaAnimation) Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener) View(android.view.View) AlphaAnimation(android.view.animation.AlphaAnimation)

Aggregations

Animation (android.view.animation.Animation)80 AnimationListener (android.view.animation.Animation.AnimationListener)80 AlphaAnimation (android.view.animation.AlphaAnimation)25 TranslateAnimation (android.view.animation.TranslateAnimation)20 View (android.view.View)14 LinearInterpolator (android.view.animation.LinearInterpolator)12 RotateAnimation (android.view.animation.RotateAnimation)10 ScaleAnimation (android.view.animation.ScaleAnimation)10 ImageView (android.widget.ImageView)10 Rect (android.graphics.Rect)7 PopupWindow (android.widget.PopupWindow)6 Window (wei.mark.standout.ui.Window)6 ViewGroup (android.view.ViewGroup)5 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)5 SuppressLint (android.annotation.SuppressLint)4 Interpolator (android.view.animation.Interpolator)4 OvershootInterpolator (android.view.animation.OvershootInterpolator)4 TextView (android.widget.TextView)4 Notification (android.app.Notification)3 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)3