react-native-navigation的迁移库

ValueAnimationOptions.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package com.reactnativenavigation.parse;
  2. import android.animation.Animator;
  3. import android.animation.ObjectAnimator;
  4. import android.util.Property;
  5. import android.view.View;
  6. import com.reactnativenavigation.parse.params.FloatParam;
  7. import com.reactnativenavigation.parse.params.Interpolation;
  8. import com.reactnativenavigation.parse.params.NullFloatParam;
  9. import com.reactnativenavigation.parse.params.NullNumber;
  10. import com.reactnativenavigation.parse.params.Number;
  11. import com.reactnativenavigation.parse.parsers.FloatParser;
  12. import com.reactnativenavigation.parse.parsers.InterpolationParser;
  13. import com.reactnativenavigation.parse.parsers.NumberParser;
  14. import org.json.JSONObject;
  15. public class ValueAnimationOptions {
  16. public static ValueAnimationOptions parse(JSONObject json, Property<View, Float> property) {
  17. ValueAnimationOptions options = new ValueAnimationOptions();
  18. options.animProp = property;
  19. options.from = FloatParser.parse(json, "from");
  20. options.to = FloatParser.parse(json, "to");
  21. options.duration = NumberParser.parse(json, "duration");
  22. options.startDelay = NumberParser.parse(json, "startDelay");
  23. options.interpolation = InterpolationParser.parse(json, "interpolation");
  24. return options;
  25. }
  26. private Property<View, Float> animProp;
  27. private FloatParam from = new NullFloatParam();
  28. private FloatParam to = new NullFloatParam();
  29. private Number duration = new NullNumber();
  30. private Number startDelay = new NullNumber();
  31. private Interpolation interpolation = Interpolation.NO_VALUE;
  32. Animator getAnimation(View view) {
  33. if (!this.from.hasValue() || !this.to.hasValue())
  34. throw new IllegalArgumentException("Params 'from' and 'to' are mandatory");
  35. ObjectAnimator animator = ObjectAnimator.ofFloat(view, animProp, this.from.get(), this.to.get());
  36. animator.setInterpolator(this.interpolation.getInterpolator());
  37. if (this.duration.hasValue())
  38. animator.setDuration(this.duration.get());
  39. if (this.startDelay.hasValue())
  40. animator.setStartDelay(this.startDelay.get());
  41. return animator;
  42. }
  43. @Override
  44. public boolean equals(Object o) {
  45. if (this == o) return true;
  46. if (o == null || getClass() != o.getClass()) return false;
  47. ValueAnimationOptions options = (ValueAnimationOptions) o;
  48. return animProp.equals(options.animProp);
  49. }
  50. @Override
  51. public int hashCode() {
  52. return animProp.hashCode();
  53. }
  54. }