Search in sources :

Example 1 with NURBS

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;
    });
}
Also used : DrawableImageGenerator(tk.zielony.randomdata.common.DrawableImageGenerator) PointF(android.graphics.PointF) FastOutSlowInInterpolator(androidx.interpolator.view.animation.FastOutSlowInInterpolator) ImageView(carbon.widget.ImageView) ValueAnimator(android.animation.ValueAnimator) View(android.view.View) ImageView(carbon.widget.ImageView) LinearLayout(carbon.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint) NURBS(carbon.internal.NURBS) SuppressLint(android.annotation.SuppressLint)

Aggregations

ValueAnimator (android.animation.ValueAnimator)1 SuppressLint (android.annotation.SuppressLint)1 PointF (android.graphics.PointF)1 View (android.view.View)1 FastOutSlowInInterpolator (androidx.interpolator.view.animation.FastOutSlowInInterpolator)1 NURBS (carbon.internal.NURBS)1 ImageView (carbon.widget.ImageView)1 LinearLayout (carbon.widget.LinearLayout)1 DrawableImageGenerator (tk.zielony.randomdata.common.DrawableImageGenerator)1