Search in sources :

Example 6 with AnimatableFloatValue

use of com.airbnb.lottie.model.animatable.AnimatableFloatValue 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 7 with AnimatableFloatValue

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

the class LayerParser method parse.

public static Layer parse(JsonReader reader, LottieComposition composition) throws IOException {
    // This should always be set by After Effects. However, if somebody wants to minify
    // and optimize their json, the name isn't critical for most cases so it can be removed.
    String layerName = "UNSET";
    Layer.LayerType layerType = null;
    String refId = null;
    long layerId = 0;
    int solidWidth = 0;
    int solidHeight = 0;
    int solidColor = 0;
    int preCompWidth = 0;
    int preCompHeight = 0;
    long parentId = -1;
    float timeStretch = 1f;
    float startFrame = 0f;
    float inFrame = 0f;
    float outFrame = 0f;
    String cl = null;
    boolean hidden = false;
    BlurEffect blurEffect = null;
    DropShadowEffect dropShadowEffect = null;
    Layer.MatteType matteType = Layer.MatteType.NONE;
    AnimatableTransform transform = null;
    AnimatableTextFrame text = null;
    AnimatableTextProperties textProperties = null;
    AnimatableFloatValue timeRemapping = null;
    List<Mask> masks = new ArrayList<>();
    List<ContentModel> shapes = new ArrayList<>();
    reader.beginObject();
    while (reader.hasNext()) {
        switch(reader.selectName(NAMES)) {
            case 0:
                layerName = reader.nextString();
                break;
            case 1:
                layerId = reader.nextInt();
                break;
            case 2:
                refId = reader.nextString();
                break;
            case 3:
                int layerTypeInt = reader.nextInt();
                if (layerTypeInt < Layer.LayerType.UNKNOWN.ordinal()) {
                    layerType = Layer.LayerType.values()[layerTypeInt];
                } else {
                    layerType = Layer.LayerType.UNKNOWN;
                }
                break;
            case 4:
                parentId = reader.nextInt();
                break;
            case 5:
                solidWidth = (int) (reader.nextInt() * Utils.dpScale());
                break;
            case 6:
                solidHeight = (int) (reader.nextInt() * Utils.dpScale());
                break;
            case 7:
                solidColor = Color.parseColor(reader.nextString());
                break;
            case 8:
                transform = AnimatableTransformParser.parse(reader, composition);
                break;
            case 9:
                int matteTypeIndex = reader.nextInt();
                if (matteTypeIndex >= Layer.MatteType.values().length) {
                    composition.addWarning("Unsupported matte type: " + matteTypeIndex);
                    break;
                }
                matteType = Layer.MatteType.values()[matteTypeIndex];
                switch(matteType) {
                    case LUMA:
                        composition.addWarning("Unsupported matte type: Luma");
                        break;
                    case LUMA_INVERTED:
                        composition.addWarning("Unsupported matte type: Luma Inverted");
                        break;
                }
                composition.incrementMatteOrMaskCount(1);
                break;
            case 10:
                reader.beginArray();
                while (reader.hasNext()) {
                    masks.add(MaskParser.parse(reader, composition));
                }
                composition.incrementMatteOrMaskCount(masks.size());
                reader.endArray();
                break;
            case 11:
                reader.beginArray();
                while (reader.hasNext()) {
                    ContentModel shape = ContentModelParser.parse(reader, composition);
                    if (shape != null) {
                        shapes.add(shape);
                    }
                }
                reader.endArray();
                break;
            case 12:
                reader.beginObject();
                while (reader.hasNext()) {
                    switch(reader.selectName(TEXT_NAMES)) {
                        case 0:
                            text = AnimatableValueParser.parseDocumentData(reader, composition);
                            break;
                        case 1:
                            reader.beginArray();
                            if (reader.hasNext()) {
                                textProperties = AnimatableTextPropertiesParser.parse(reader, composition);
                            }
                            while (reader.hasNext()) {
                                reader.skipValue();
                            }
                            reader.endArray();
                            break;
                        default:
                            reader.skipName();
                            reader.skipValue();
                    }
                }
                reader.endObject();
                break;
            case 13:
                reader.beginArray();
                List<String> effectNames = new ArrayList<>();
                while (reader.hasNext()) {
                    reader.beginObject();
                    while (reader.hasNext()) {
                        switch(reader.selectName(EFFECTS_NAMES)) {
                            case 0:
                                int type = reader.nextInt();
                                if (type == 29) {
                                    blurEffect = BlurEffectParser.parse(reader, composition);
                                } else if (type == 25) {
                                    dropShadowEffect = new DropShadowEffectParser().parse(reader, composition);
                                }
                                break;
                            case 1:
                                String effectName = reader.nextString();
                                effectNames.add(effectName);
                                break;
                            default:
                                reader.skipName();
                                reader.skipValue();
                        }
                    }
                    reader.endObject();
                }
                reader.endArray();
                composition.addWarning("Lottie doesn't support layer effects. If you are using them for " + " fills, strokes, trim paths etc. then try adding them directly as contents " + " in your shape. Found: " + effectNames);
                break;
            case 14:
                timeStretch = (float) reader.nextDouble();
                break;
            case 15:
                startFrame = (float) reader.nextDouble();
                break;
            case 16:
                preCompWidth = (int) (reader.nextInt() * Utils.dpScale());
                break;
            case 17:
                preCompHeight = (int) (reader.nextInt() * Utils.dpScale());
                break;
            case 18:
                inFrame = (float) reader.nextDouble();
                break;
            case 19:
                outFrame = (float) reader.nextDouble();
                break;
            case 20:
                timeRemapping = AnimatableValueParser.parseFloat(reader, composition, false);
                break;
            case 21:
                cl = reader.nextString();
                break;
            case 22:
                hidden = reader.nextBoolean();
                break;
            default:
                reader.skipName();
                reader.skipValue();
        }
    }
    reader.endObject();
    List<Keyframe<Float>> inOutKeyframes = new ArrayList<>();
    // Before the in frame
    if (inFrame > 0) {
        Keyframe<Float> preKeyframe = new Keyframe<>(composition, 0f, 0f, null, 0f, inFrame);
        inOutKeyframes.add(preKeyframe);
    }
    // The + 1 is because the animation should be visible on the out frame itself.
    outFrame = (outFrame > 0 ? outFrame : composition.getEndFrame());
    Keyframe<Float> visibleKeyframe = new Keyframe<>(composition, 1f, 1f, null, inFrame, outFrame);
    inOutKeyframes.add(visibleKeyframe);
    Keyframe<Float> outKeyframe = new Keyframe<>(composition, 0f, 0f, null, outFrame, Float.MAX_VALUE);
    inOutKeyframes.add(outKeyframe);
    if (layerName.endsWith(".ai") || "ai".equals(cl)) {
        composition.addWarning("Convert your Illustrator layers to shape layers.");
    }
    return new Layer(shapes, composition, layerName, layerId, layerType, parentId, refId, masks, transform, solidWidth, solidHeight, solidColor, timeStretch, startFrame, preCompWidth, preCompHeight, text, textProperties, inOutKeyframes, matteType, timeRemapping, hidden, blurEffect, dropShadowEffect);
}
Also used : AnimatableTextProperties(com.airbnb.lottie.model.animatable.AnimatableTextProperties) ArrayList(java.util.ArrayList) AnimatableTextFrame(com.airbnb.lottie.model.animatable.AnimatableTextFrame) Keyframe(com.airbnb.lottie.value.Keyframe) AnimatableTransform(com.airbnb.lottie.model.animatable.AnimatableTransform) AnimatableFloatValue(com.airbnb.lottie.model.animatable.AnimatableFloatValue) Mask(com.airbnb.lottie.model.content.Mask) Layer(com.airbnb.lottie.model.layer.Layer) ContentModel(com.airbnb.lottie.model.content.ContentModel) BlurEffect(com.airbnb.lottie.model.content.BlurEffect)

Example 8 with AnimatableFloatValue

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

the class GradientStrokeParser method parse.

static GradientStroke parse(JsonReader reader, LottieComposition composition) throws IOException {
    String name = null;
    AnimatableGradientColorValue color = null;
    AnimatableIntegerValue opacity = null;
    GradientType gradientType = null;
    AnimatablePointValue startPoint = null;
    AnimatablePointValue endPoint = null;
    AnimatableFloatValue width = 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:
                int points = -1;
                reader.beginObject();
                while (reader.hasNext()) {
                    switch(reader.selectName(GRADIENT_NAMES)) {
                        case 0:
                            points = reader.nextInt();
                            break;
                        case 1:
                            color = AnimatableValueParser.parseGradientColor(reader, composition, points);
                            break;
                        default:
                            reader.skipName();
                            reader.skipValue();
                    }
                }
                reader.endObject();
                break;
            case 2:
                opacity = AnimatableValueParser.parseInteger(reader, composition);
                break;
            case 3:
                gradientType = reader.nextInt() == 1 ? GradientType.LINEAR : GradientType.RADIAL;
                break;
            case 4:
                startPoint = AnimatableValueParser.parsePoint(reader, composition);
                break;
            case 5:
                endPoint = AnimatableValueParser.parsePoint(reader, composition);
                break;
            case 6:
                width = AnimatableValueParser.parseFloat(reader, composition);
                break;
            case 7:
                capType = ShapeStroke.LineCapType.values()[reader.nextInt() - 1];
                break;
            case 8:
                joinType = ShapeStroke.LineJoinType.values()[reader.nextInt() - 1];
                break;
            case 9:
                miterLimit = (float) reader.nextDouble();
                break;
            case 10:
                hidden = reader.nextBoolean();
                break;
            case 11:
                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();
                    if (n.equals("o")) {
                        offset = val;
                    } else if (n.equals("d") || n.equals("g")) {
                        composition.setHasDashPattern(true);
                        lineDashPattern.add(val);
                    }
                }
                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.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;
    return new GradientStroke(name, gradientType, color, opacity, startPoint, endPoint, width, capType, joinType, miterLimit, lineDashPattern, offset, hidden);
}
Also used : ShapeStroke(com.airbnb.lottie.model.content.ShapeStroke) AnimatableIntegerValue(com.airbnb.lottie.model.animatable.AnimatableIntegerValue) AnimatableFloatValue(com.airbnb.lottie.model.animatable.AnimatableFloatValue) GradientStroke(com.airbnb.lottie.model.content.GradientStroke) ArrayList(java.util.ArrayList) Keyframe(com.airbnb.lottie.value.Keyframe) AnimatablePointValue(com.airbnb.lottie.model.animatable.AnimatablePointValue) GradientType(com.airbnb.lottie.model.content.GradientType) AnimatableGradientColorValue(com.airbnb.lottie.model.animatable.AnimatableGradientColorValue)

Example 9 with AnimatableFloatValue

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

the class ShapeTrimPathParser method parse.

static ShapeTrimPath parse(JsonReader reader, LottieComposition composition) throws IOException {
    String name = null;
    ShapeTrimPath.Type type = null;
    AnimatableFloatValue start = null;
    AnimatableFloatValue end = null;
    AnimatableFloatValue offset = null;
    boolean hidden = false;
    while (reader.hasNext()) {
        switch(reader.selectName(NAMES)) {
            case 0:
                start = AnimatableValueParser.parseFloat(reader, composition, false);
                break;
            case 1:
                end = AnimatableValueParser.parseFloat(reader, composition, false);
                break;
            case 2:
                offset = AnimatableValueParser.parseFloat(reader, composition, false);
                break;
            case 3:
                name = reader.nextString();
                break;
            case 4:
                type = ShapeTrimPath.Type.forId(reader.nextInt());
                break;
            case 5:
                hidden = reader.nextBoolean();
                break;
            default:
                reader.skipValue();
        }
    }
    return new ShapeTrimPath(name, type, start, end, offset, hidden);
}
Also used : ShapeTrimPath(com.airbnb.lottie.model.content.ShapeTrimPath) AnimatableFloatValue(com.airbnb.lottie.model.animatable.AnimatableFloatValue)

Example 10 with AnimatableFloatValue

use of com.airbnb.lottie.model.animatable.AnimatableFloatValue 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

AnimatableFloatValue (com.airbnb.lottie.model.animatable.AnimatableFloatValue)10 Keyframe (com.airbnb.lottie.value.Keyframe)4 PointF (android.graphics.PointF)3 AnimatableIntegerValue (com.airbnb.lottie.model.animatable.AnimatableIntegerValue)3 AnimatableTransform (com.airbnb.lottie.model.animatable.AnimatableTransform)3 ArrayList (java.util.ArrayList)3 AnimatableColorValue (com.airbnb.lottie.model.animatable.AnimatableColorValue)2 AnimatablePathValue (com.airbnb.lottie.model.animatable.AnimatablePathValue)2 AnimatableTextProperties (com.airbnb.lottie.model.animatable.AnimatableTextProperties)2 ShapeStroke (com.airbnb.lottie.model.content.ShapeStroke)2 AnimatableGradientColorValue (com.airbnb.lottie.model.animatable.AnimatableGradientColorValue)1 AnimatablePointValue (com.airbnb.lottie.model.animatable.AnimatablePointValue)1 AnimatableScaleValue (com.airbnb.lottie.model.animatable.AnimatableScaleValue)1 AnimatableSplitDimensionPathValue (com.airbnb.lottie.model.animatable.AnimatableSplitDimensionPathValue)1 AnimatableTextFrame (com.airbnb.lottie.model.animatable.AnimatableTextFrame)1 BlurEffect (com.airbnb.lottie.model.content.BlurEffect)1 ContentModel (com.airbnb.lottie.model.content.ContentModel)1 GradientStroke (com.airbnb.lottie.model.content.GradientStroke)1 GradientType (com.airbnb.lottie.model.content.GradientType)1 Mask (com.airbnb.lottie.model.content.Mask)1