Keyframe.java 文件源码

java
阅读 30 收藏 0 点赞 0 评论 0

项目:atlas 作者:
static <T> Keyframe<T> newInstance(JSONObject json, LottieComposition composition, float scale,
    AnimatableValue.Factory<T> valueFactory) {
  PointF cp1 = null;
  PointF cp2 = null;
  float startFrame = 0;
  T startValue = null;
  T endValue = null;
  Interpolator interpolator = null;

  if (json.has("t")) {
    startFrame = (float) json.optDouble("t", 0);
    Object startValueJson = json.opt("s");
    if (startValueJson != null) {
      startValue = valueFactory.valueFromObject(startValueJson, scale);
    }

    Object endValueJson = json.opt("e");
    if (endValueJson != null) {
      endValue = valueFactory.valueFromObject(endValueJson, scale);
    }

    JSONObject cp1Json = json.optJSONObject("o");
    JSONObject cp2Json = json.optJSONObject("i");
    if (cp1Json != null && cp2Json != null) {
      cp1 = JsonUtils.pointFromJsonObject(cp1Json, scale);
      cp2 = JsonUtils.pointFromJsonObject(cp2Json, scale);
    }

    boolean hold = json.optInt("h", 0) == 1;

    if (hold) {
      endValue = startValue;
      // TODO: create a HoldInterpolator so progress changes don't invalidate.
      interpolator = LINEAR_INTERPOLATOR;
    } else if (cp1 != null) {
      interpolator = PathInterpolatorCompat.create(
          cp1.x / scale, cp1.y / scale, cp2.x / scale, cp2.y / scale);
    } else {
      interpolator = LINEAR_INTERPOLATOR;
    }
  } else {
    startValue = valueFactory.valueFromObject(json, scale);
    endValue = startValue;
  }
  return new Keyframe<>(composition, startValue, endValue, interpolator, startFrame, null);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号