harjot-oberai / VectorMaster

Dynamic control over vector drawables!
MIT License
1.59k stars 161 forks source link

Use the RichPath Animator to write less code #2

Closed tarek360 closed 7 years ago

tarek360 commented 7 years ago

Hi @harjot-oberai I have developed a new library called RichPath It gives full Animation Control on Paths and VectorDrawables

It will make the path animation code shorter

for example, the Search-Back animation sample which is in the VectorMaster examples.

Before:

      Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                count++;
                if (count >= 50) {
                    if (searchBackState == 0) {
                        circleTrimEnd -= 1.0f / 20;
                        stemTrimStart += 0.75f / 20;
                        stemTrimEnd += (1 - 0.185f) / 20;
                        arrowHeadBottomTrimEnd += 1.0f / 20;
                        arrowHeadTopTrimEnd += 1.0f / 20;
                        if (circleTrimEnd <= 0) {
                            searchBackState = 1;
                            count = 0;
                        }
                    } else if (searchBackState == 1) {
                        arrowHeadBottomTrimEnd -= 1.0f / 20;
                        arrowHeadTopTrimEnd -= 1.0f / 20;
                        stemTrimStart -= 0.75f / 20;
                        stemTrimEnd -= (1 - 0.185f) / 20;
                        circleTrimEnd += 1.0f / 20;
                        if (circleTrimEnd >= 1) {
                            searchBackState = 0;
                            count = 0;
                        }
                    }

                    searchCircle.setTrimPathEnd(circleTrimEnd);
                    stem.setTrimPathEnd(stemTrimEnd);
                    stem.setTrimPathStart(stemTrimStart);
                    arrowUp.setTrimPathEnd(arrowHeadTopTrimEnd);
                    arrowDown.setTrimPathEnd(arrowHeadBottomTrimEnd);

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            searchBackView.update();
                        }
                    });
                }

            }
        }, 1000, 1000 / 60);

After: (By using the RichPath Animator)

RichPathAnimator.animate(stem)
                    .trimPathStart(0f, 0.75f)
                    .trimPathEnd(0.185f, 1f)
                    .andAnimate(searchCircle)
                    .trimPathEnd(1, 0)
                    .andAnimate(arrowTop, arrowBottom)
                    .trimPathEnd(0, 1)
                    .start();
harjot-oberai commented 7 years ago

@tarek360 : Your library is really good. I have added it to the README under ComplexAnimations and also under Limitations of this library.