0

I'm trying to animate between two values using BigInteger instead of int like I was using before. So far I have not found a way to do this, is it possible?

final ValueAnimator amountAnimation = ValueAnimator.ofInt(initialValue, finalValue);

Of course, BigInteger is not accepted there... Thank you

zngb
  • 601
  • 1
  • 7
  • 24

1 Answers1

1

You can use any type in ValueAnimator, as long as You provide your own TypeEvaluator (somehow pseudocode example):

public class BigIntegerEvaluator implements TypeEvaluator<BigInteger>{
    @Override
    public BigInteger evaluate(float v, BigInteger start, BigInteger end) {
        //todo: implement this
        return start + v * (end - start);
    }
}

Then provide it into general valueAnimator:

final ValueAnimator amountAnimation = ValueAnimator.ofObject(new BigIntegerEvaluator(), initialValue, finalValue);

But I'm not sure about animating on type BigInteger itself since Evaluator is called on each frame with new fraction, are you sure long type is not enough for your use case?

Pawel
  • 15,548
  • 3
  • 36
  • 36
  • Possible implementation (assumes 'v' is a proportion - would have to check for v==0 and return start): start.add((end.subtract(start).divide(new BigInteger(Integer.toString((int)(1F/v)))))); –  Mar 13 '18 at 03:04