3

I am writing a class in JAVA to port a library from Android to Harmony OS. In the Android code given below for the method onSelectedY(boolean, float, int), it requires a constructor of the class AccelerateInterpolator to be added to a method

private void onSelectedY(final boolean isTop, float exitX, int duration)
{
        ....
        ....

        this.frame.animate()
                .setDuration(duration)
                .setInterpolator(new AccelerateInterpolator())
                .x(exitX)
                .y(exitY)
                .setListener(new AnimatorListenerAdapter()
                {
                    @Override
                    public void onAnimationEnd(Animator animation)
                    {
                        if(isTop)
                        {
                            mFlingListener.onCardExited();
                            mFlingListener.topExit(dataObject);
                        }
                        else
                        {
                            mFlingListener.onCardExited();
                            mFlingListener.bottomExit(dataObject);
                        }
                        isAnimationRunning = false;
                    }
                })
                .rotation(getVerticalExitRotation(isTop));
}

For equivalent Harmony OS component of class AccelerateInterpolator, there is an interface named Animator.TimelineCurve. But the issue with it being an interface is that it doesn't have a constructor, which is needed in this case. If I directly use the interface, I would have to override the interface here itself, but that can't be done as there is nothing to override manually.

Same goes for OvershootInterpolator.

What could be the work-around for this case?

Regards, Subham

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108

2 Answers2

2

ohos.agp.animation.Animator.CurveType is equivalent API for Interpolators in Android. You have to make use of setCurveType(int) API, and for AccelerateInterpolator you have to use Animator.CurveType.ACCELERATE. For OvershootInterpolator use Animator.CurveType.OVERSHOOT,

Usage:

    animator.setCurveType(Animator.CurveType.ACCELERATE);
Gowtham GS
  • 478
  • 2
  • 5
2

You could look at the this development documentation to see if it helps.

In addition, there are two implementations of the TimelineCurve class: CubicBezierCurve and SpringCurve.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108