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();
}
Aggregations