当前位置: 首页>>代码示例>>Java>>正文


Java JsonToken.BEGIN_ARRAY属性代码示例

本文整理汇总了Java中android.util.JsonToken.BEGIN_ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Java JsonToken.BEGIN_ARRAY属性的具体用法?Java JsonToken.BEGIN_ARRAY怎么用?Java JsonToken.BEGIN_ARRAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.util.JsonToken的用法示例。


在下文中一共展示了JsonToken.BEGIN_ARRAY属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

@Override public Integer parse(JsonReader reader, float scale) throws IOException {
  boolean isArray = reader.peek() == JsonToken.BEGIN_ARRAY;
  if (isArray) {
    reader.beginArray();
  }
  double r = reader.nextDouble();
  double g = reader.nextDouble();
  double b = reader.nextDouble();
  double a = reader.nextDouble();
  if (isArray) {
    reader.endArray();
  }

  if (r <= 1 && g <= 1 && b <= 1 && a <= 1) {
    r *= 255;
    g *= 255;
    b *= 255;
    a *= 255;
  }

  return Color.argb((int) a, (int) r, (int) g, (int) b);
}
 
开发者ID:airbnb,项目名称:lottie-android,代码行数:22,代码来源:ColorParser.java

示例2: parse

@Override public PointF parse(JsonReader reader, float scale) throws IOException {
  JsonToken token = reader.peek();
  if (token == JsonToken.BEGIN_ARRAY) {
    return JsonUtils.jsonToPoint(reader, scale);
  } else if (token == JsonToken.BEGIN_OBJECT) {
    return JsonUtils.jsonToPoint(reader, scale);
  } else if (token == JsonToken.NUMBER) {
    // This is the case where the static value for a property is an array of numbers.
    // We begin the array to see if we have an array of keyframes but it's just an array
    // of static numbers instead.
    PointF point = new PointF((float) reader.nextDouble() * scale, (float) reader.nextDouble() * scale);
    while (reader.hasNext()) {
      reader.skipValue();
    }
    return point;
  } else {
    throw new IllegalArgumentException("Cannot convert json to point. Next token is " + token);
  }
}
 
开发者ID:airbnb,项目名称:lottie-android,代码行数:19,代码来源:PointFParser.java

示例3: inflate

/***
 * This method called in the background, here
 * need to parse given {@code json}
 *
 * @param reader Widget configuration
 */
protected void inflate(ConfigurationWidget widget, JsonReader reader) throws IOException {
    Bundle options = new Bundle();
    Bundle configs = widget.getConfigurations();
    JsonToken token = reader.peek();
    if(token == JsonToken.BEGIN_OBJECT){
        appendViewInLayout(createView(this, configs, options, reader));
    }else if (token == JsonToken.BEGIN_ARRAY){
        reader.beginArray();
        while(reader.peek() != JsonToken.END_ARRAY){
            appendViewInLayout(createView(this, configs, options, reader));
            options.clear(); // recycle configurations
        }
        reader.endArray();
    }else{
        throw new RuntimeException("Unsupported token exception: " + reader.toString());
    }
    options.clear();
}
 
开发者ID:ozodrukh,项目名称:Green,代码行数:24,代码来源:ConfigCard.java

示例4: parse

static <T> List<Keyframe<T>> parse(JsonReader reader,
    LottieComposition composition, float scale, ValueParser<T> valueParser)
    throws IOException {
  List<Keyframe<T>> keyframes = new ArrayList<>();

  if (reader.peek() == JsonToken.STRING) {
    composition.addWarning("Lottie doesn't support expressions.");
    return keyframes;
  }

  reader.beginObject();
  while (reader.hasNext()) {
    switch (reader.nextName()) {
      case "k":
        if (reader.peek() == JsonToken.BEGIN_ARRAY) {
          reader.beginArray();

          if (reader.peek() == JsonToken.NUMBER) {
            // For properties in which the static value is an array of numbers.
            keyframes.add(
                KeyframeParser.parse(reader, composition, scale, valueParser, false));
          } else {
            while (reader.hasNext()) {
              keyframes.add(KeyframeParser.parse(reader, composition, scale, valueParser, true));
            }
          }
          reader.endArray();
        } else {
          keyframes.add(KeyframeParser.parse(reader, composition, scale, valueParser, false));
        }
        break;
      default:
        reader.skipValue();
    }
  }
  reader.endObject();

  setEndFrames(keyframes);
  return keyframes;
}
 
开发者ID:airbnb,项目名称:lottie-android,代码行数:40,代码来源:KeyframesParser.java

示例5: parse

@Override public ScaleXY parse(JsonReader reader, float scale) throws IOException {
  boolean isArray = reader.peek() == JsonToken.BEGIN_ARRAY;
  if (isArray) {
    reader.beginArray();
  }
  float sx = (float) reader.nextDouble();
  float sy = (float) reader.nextDouble();
  while (reader.hasNext()) {
    reader.skipValue();
  }
  if (isArray) {
    reader.endArray();
  }
  return new ScaleXY(sx / 100f * scale, sy / 100f * scale);
}
 
开发者ID:airbnb,项目名称:lottie-android,代码行数:15,代码来源:ScaleXYParser.java

示例6: jsonToPoints

static List<PointF> jsonToPoints(JsonReader reader, float scale) throws IOException {
  List<PointF> points = new ArrayList<>();

  reader.beginArray();
  while (reader.peek() == JsonToken.BEGIN_ARRAY) {
    reader.beginArray();
    points.add(jsonToPoint(reader, scale));
    reader.endArray();
  }
  reader.endArray();
  return points;
}
 
开发者ID:airbnb,项目名称:lottie-android,代码行数:12,代码来源:JsonUtils.java

示例7: parse

public static AnimatablePathValue parse(
    JsonReader reader, LottieComposition composition) throws IOException {
  List<Keyframe<PointF>> keyframes = new ArrayList<>();
  if (reader.peek() == JsonToken.BEGIN_ARRAY) {
    reader.beginArray();
    while (reader.hasNext()) {
      keyframes.add(PathKeyframeParser.parse(reader, composition));
    }
    reader.endArray();
    KeyframesParser.setEndFrames(keyframes);
  } else {
    keyframes.add(new Keyframe<>(JsonUtils.jsonToPoint(reader, Utils.dpScale())));
  }
  return new AnimatablePathValue(keyframes);
}
 
开发者ID:airbnb,项目名称:lottie-android,代码行数:15,代码来源:AnimatablePathValueParser.java

示例8: parse

/**
 * Both the color stops and opacity stops are in the same array.
 * There are {@link #colorPoints} colors sequentially as:
 * [
 *     ...,
 *     position,
 *     red,
 *     green,
 *     blue,
 *     ...
 * ]
 *
 * The remainder of the array is the opacity stops sequentially as:
 * [
 *     ...,
 *     position,
 *     opacity,
 *     ...
 * ]
 */
@Override public GradientColor parse(JsonReader reader, float scale)
    throws IOException {
  List<Float> array = new ArrayList<>();
  // The array was started by Keyframe because it thought that this may be an array of keyframes
  // but peek returned a number so it considered it a static array of numbers.
  boolean isArray = reader.peek() == JsonToken.BEGIN_ARRAY;
  if (isArray) {
    reader.beginArray();
  }
  while (reader.hasNext()) {
    array.add((float) reader.nextDouble());
  }
  if(isArray) {
    reader.endArray();
  }
  if (colorPoints == -1) {
    colorPoints = array.size() / 4;
  }

  float[] positions = new float[colorPoints];
  int[] colors = new int[colorPoints];

  int r = 0;
  int g = 0;
  if (array.size() != colorPoints * 4) {
    Log.w(L.TAG, "Unexpected gradient length: " + array.size() +
        ". Expected " + (colorPoints * 4) + ". This may affect the appearance of the gradient. " +
        "Make sure to save your After Effects file before exporting an animation with " +
        "gradients.");
  }
  for (int i = 0; i < colorPoints * 4; i++) {
    int colorIndex = i / 4;
    double value = array.get(i);
    switch (i % 4) {
      case 0:
        // position
        positions[colorIndex] = (float) value;
        break;
      case 1:
        r = (int) (value * 255);
        break;
      case 2:
        g = (int) (value * 255);
        break;
      case 3:
        int b = (int) (value * 255);
        colors[colorIndex] = Color.argb(255, r, g, b);
        break;
    }
  }

  GradientColor gradientColor = new GradientColor(positions, colors);
  addOpacityStopsToGradientIfNeeded(gradientColor, array);
  return gradientColor;
}
 
开发者ID:airbnb,项目名称:lottie-android,代码行数:75,代码来源:GradientColorParser.java


注:本文中的android.util.JsonToken.BEGIN_ARRAY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。