Search in sources :

Example 1 with AnimatorListenerImpl

use of com.nu.art.cyborg.common.implementors.AnimatorListenerImpl in project cyborg-core by nu-art.

the class FloatingViewTransitionAnimator method renderFromTo.

private void renderFromTo(View fromParent, final View viewToAnimateFrom, final View viewToAnimateTo, Bitmap imageToAnimate, int duration, final AnimationListener listener) {
    final FrameLayout rootView = (FrameLayout) fromParent.getRootView().findViewById(android.R.id.content);
    Context context = rootView.getContext();
    final RelativeLayout renderingLayer = new RelativeLayout(context);
    renderingLayer.setClipChildren(false);
    rootView.addView(renderingLayer);
    final ImageView imageView = new ImageView(context);
    imageView.setImageBitmap(imageToAnimate);
    renderingLayer.addView(imageView);
    AnimatorSet animationSet = new AnimatorSet();
    animationSet.addListener(new AnimatorListenerImpl() {

        @Override
        public void onAnimationStart(Animator animator) {
            // the origin view should remain a bit longer to avoid the transition hiccup between the original view and the image to be animated...
            viewToAnimateFrom.post(new Runnable() {

                @Override
                public void run() {
                    viewToAnimateFrom.setVisibility(View.INVISIBLE);
                }
            });
            // the target view should be hidden from the get go!
            viewToAnimateTo.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            rootView.removeView(renderingLayer);
            viewToAnimateTo.setVisibility(View.VISIBLE);
            if (listener != null)
                listener.onAnimationEnd(null);
        }
    });
    // extract the view real area's on screen
    Rect originRect = Tools.getViewRealRect(viewToAnimateFrom);
    Rect targetRect = Tools.getViewRealRect(viewToAnimateTo);
    imageView.setTranslationX(originRect.left);
    imageView.setTranslationY(originRect.top);
    Animator translateX = ObjectAnimator.ofFloat(imageView, "translationX", targetRect.left);
    Animator translateY = ObjectAnimator.ofFloat(imageView, "translationY", targetRect.top);
    Animator animateW = ValueAnimator.ofObject(new WidthEvaluator(imageView), originRect.width(), targetRect.width());
    Animator animateH = ValueAnimator.ofObject(new HeightEvaluator(imageView), originRect.height(), targetRect.height());
    animationSet.setDuration(duration);
    animationSet.playTogether(translateX, translateY, animateW, animateH);
    animationSet.start();
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) StackTransitionAnimator(com.nu.art.cyborg.core.CyborgStackController.StackTransitionAnimator) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) FrameLayout(android.widget.FrameLayout) AnimatorListenerImpl(com.nu.art.cyborg.common.implementors.AnimatorListenerImpl) RelativeLayout(android.widget.RelativeLayout) AnimatorSet(android.animation.AnimatorSet) ImageView(android.widget.ImageView)

Aggregations

Animator (android.animation.Animator)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 Context (android.content.Context)1 Rect (android.graphics.Rect)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 RelativeLayout (android.widget.RelativeLayout)1 AnimatorListenerImpl (com.nu.art.cyborg.common.implementors.AnimatorListenerImpl)1 StackTransitionAnimator (com.nu.art.cyborg.core.CyborgStackController.StackTransitionAnimator)1