use of carbon.internal.NURBS in project Carbon by ZieIony.
the class PathAnimationActivity method onCreate.
@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initToolbar();
ImageView imageView = findViewById(R.id.image);
imageView.setImageDrawable(new DrawableImageGenerator(this).next());
LinearLayout card = findViewById(R.id.card);
View layout = findViewById(R.id.layout);
layout.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_UP) {
NURBS nurbs = new NURBS();
nurbs.addPoint(new PointF(card.getX() + card.getWidth() / 2, card.getY() + card.getHeight() / 2));
nurbs.addPoint(new PointF(event.getX(), card.getY() + card.getHeight() / 2));
nurbs.addPoint(new PointF(event.getX(), event.getY()));
nurbs.init();
ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
float srcWidth = card.getWidth();
float srcHeight = card.getHeight();
float destWidth = expanded ? getResources().getDimension(R.dimen.carbon_contentSpace) : layout.getWidth();
float destHeight = destWidth * 9.0f / 16;
animator.setDuration(500);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.addUpdateListener(animation -> {
PointF point = nurbs.getPoint((Float) animation.getAnimatedValue());
int w = (int) MathUtils.lerp(srcWidth, destWidth, (Float) animation.getAnimatedValue());
int h = (int) MathUtils.lerp(srcHeight, destHeight, (Float) animation.getAnimatedValue());
int x = (int) point.x - w / 2;
int y = (int) point.y - h / 2;
card.setBounds(x, y, w, h);
});
animator.start();
expanded = !expanded;
}
return true;
});
}
Aggregations