Search in sources :

Example 1 with AnimatableColorValue

use of com.airbnb.lottie.model.animatable.AnimatableColorValue in project lottie-android by airbnb.

the class ShapeFillParser method parse.

static ShapeFill parse(JsonReader reader, LottieComposition composition) throws IOException {
    AnimatableColorValue color = null;
    boolean fillEnabled = false;
    AnimatableIntegerValue opacity = null;
    String name = null;
    int fillTypeInt = 1;
    boolean hidden = false;
    while (reader.hasNext()) {
        switch(reader.selectName(NAMES)) {
            case 0:
                name = reader.nextString();
                break;
            case 1:
                color = AnimatableValueParser.parseColor(reader, composition);
                break;
            case 2:
                opacity = AnimatableValueParser.parseInteger(reader, composition);
                break;
            case 3:
                fillEnabled = reader.nextBoolean();
                break;
            case 4:
                fillTypeInt = reader.nextInt();
                break;
            case 5:
                hidden = reader.nextBoolean();
                break;
            default:
                reader.skipName();
                reader.skipValue();
        }
    }
    // Telegram sometimes omits opacity.
    // https://github.com/airbnb/lottie-android/issues/1600
    opacity = opacity == null ? new AnimatableIntegerValue(Collections.singletonList(new Keyframe<>(100))) : opacity;
    Path.FillType fillType = fillTypeInt == 1 ? Path.FillType.WINDING : Path.FillType.EVEN_ODD;
    return new ShapeFill(name, fillEnabled, fillType, color, opacity, hidden);
}
Also used : Path(android.graphics.Path) ShapeFill(com.airbnb.lottie.model.content.ShapeFill) AnimatableColorValue(com.airbnb.lottie.model.animatable.AnimatableColorValue) Keyframe(com.airbnb.lottie.value.Keyframe) AnimatableIntegerValue(com.airbnb.lottie.model.animatable.AnimatableIntegerValue)

Example 2 with AnimatableColorValue

use of com.airbnb.lottie.model.animatable.AnimatableColorValue in project lottie-android by airbnb.

the class AnimatableTextPropertiesParser method parseAnimatableTextProperties.

private static AnimatableTextProperties parseAnimatableTextProperties(JsonReader reader, LottieComposition composition) throws IOException {
    AnimatableColorValue color = null;
    AnimatableColorValue stroke = null;
    AnimatableFloatValue strokeWidth = null;
    AnimatableFloatValue tracking = null;
    reader.beginObject();
    while (reader.hasNext()) {
        switch(reader.selectName(ANIMATABLE_PROPERTIES_NAMES)) {
            case 0:
                color = AnimatableValueParser.parseColor(reader, composition);
                break;
            case 1:
                stroke = AnimatableValueParser.parseColor(reader, composition);
                break;
            case 2:
                strokeWidth = AnimatableValueParser.parseFloat(reader, composition);
                break;
            case 3:
                tracking = AnimatableValueParser.parseFloat(reader, composition);
                break;
            default:
                reader.skipName();
                reader.skipValue();
        }
    }
    reader.endObject();
    return new AnimatableTextProperties(color, stroke, strokeWidth, tracking);
}
Also used : AnimatableColorValue(com.airbnb.lottie.model.animatable.AnimatableColorValue) AnimatableTextProperties(com.airbnb.lottie.model.animatable.AnimatableTextProperties) AnimatableFloatValue(com.airbnb.lottie.model.animatable.AnimatableFloatValue)

Example 3 with AnimatableColorValue

use of com.airbnb.lottie.model.animatable.AnimatableColorValue in project lottie-android by airbnb.

the class ShapeStrokeParser method parse.

static ShapeStroke parse(JsonReader reader, LottieComposition composition) throws IOException {
    String name = null;
    AnimatableColorValue color = null;
    AnimatableFloatValue width = null;
    AnimatableIntegerValue opacity = null;
    ShapeStroke.LineCapType capType = null;
    ShapeStroke.LineJoinType joinType = null;
    AnimatableFloatValue offset = null;
    float miterLimit = 0f;
    boolean hidden = false;
    List<AnimatableFloatValue> lineDashPattern = new ArrayList<>();
    while (reader.hasNext()) {
        switch(reader.selectName(NAMES)) {
            case 0:
                name = reader.nextString();
                break;
            case 1:
                color = AnimatableValueParser.parseColor(reader, composition);
                break;
            case 2:
                width = AnimatableValueParser.parseFloat(reader, composition);
                break;
            case 3:
                opacity = AnimatableValueParser.parseInteger(reader, composition);
                break;
            case 4:
                capType = ShapeStroke.LineCapType.values()[reader.nextInt() - 1];
                break;
            case 5:
                joinType = ShapeStroke.LineJoinType.values()[reader.nextInt() - 1];
                break;
            case 6:
                miterLimit = (float) reader.nextDouble();
                break;
            case 7:
                hidden = reader.nextBoolean();
                break;
            case 8:
                reader.beginArray();
                while (reader.hasNext()) {
                    String n = null;
                    AnimatableFloatValue val = null;
                    reader.beginObject();
                    while (reader.hasNext()) {
                        switch(reader.selectName(DASH_PATTERN_NAMES)) {
                            case 0:
                                n = reader.nextString();
                                break;
                            case 1:
                                val = AnimatableValueParser.parseFloat(reader, composition);
                                break;
                            default:
                                reader.skipName();
                                reader.skipValue();
                        }
                    }
                    reader.endObject();
                    switch(n) {
                        case "o":
                            offset = val;
                            break;
                        case "d":
                        case "g":
                            composition.setHasDashPattern(true);
                            lineDashPattern.add(val);
                            break;
                    }
                }
                reader.endArray();
                if (lineDashPattern.size() == 1) {
                    // If there is only 1 value then it is assumed to be equal parts on and off.
                    lineDashPattern.add(lineDashPattern.get(0));
                }
                break;
            default:
                reader.skipValue();
        }
    }
    // Telegram sometimes omits opacity.
    // https://github.com/airbnb/lottie-android/issues/1600
    opacity = opacity == null ? new AnimatableIntegerValue(Collections.singletonList(new Keyframe<>(100))) : opacity;
    return new ShapeStroke(name, offset, lineDashPattern, color, opacity, width, capType, joinType, miterLimit, hidden);
}
Also used : AnimatableColorValue(com.airbnb.lottie.model.animatable.AnimatableColorValue) ShapeStroke(com.airbnb.lottie.model.content.ShapeStroke) Keyframe(com.airbnb.lottie.value.Keyframe) AnimatableIntegerValue(com.airbnb.lottie.model.animatable.AnimatableIntegerValue) AnimatableFloatValue(com.airbnb.lottie.model.animatable.AnimatableFloatValue) ArrayList(java.util.ArrayList)

Aggregations

AnimatableColorValue (com.airbnb.lottie.model.animatable.AnimatableColorValue)3 AnimatableFloatValue (com.airbnb.lottie.model.animatable.AnimatableFloatValue)2 AnimatableIntegerValue (com.airbnb.lottie.model.animatable.AnimatableIntegerValue)2 Keyframe (com.airbnb.lottie.value.Keyframe)2 Path (android.graphics.Path)1 AnimatableTextProperties (com.airbnb.lottie.model.animatable.AnimatableTextProperties)1 ShapeFill (com.airbnb.lottie.model.content.ShapeFill)1 ShapeStroke (com.airbnb.lottie.model.content.ShapeStroke)1 ArrayList (java.util.ArrayList)1