Search in sources :

Example 1 with AnimatableFloatValue

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

the class RepeaterParser method parse.

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

Example 2 with AnimatableFloatValue

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

the class AnimatablePathValueParser method parseSplitPath.

/**
 * Returns either an {@link AnimatablePathValue} or an {@link AnimatableSplitDimensionPathValue}.
 */
static AnimatableValue<PointF, PointF> parseSplitPath(JsonReader reader, LottieComposition composition) throws IOException {
    AnimatablePathValue pathAnimation = null;
    AnimatableFloatValue xAnimation = null;
    AnimatableFloatValue yAnimation = null;
    boolean hasExpressions = false;
    reader.beginObject();
    while (reader.peek() != JsonReader.Token.END_OBJECT) {
        switch(reader.selectName(NAMES)) {
            case 0:
                pathAnimation = AnimatablePathValueParser.parse(reader, composition);
                break;
            case 1:
                if (reader.peek() == JsonReader.Token.STRING) {
                    hasExpressions = true;
                    reader.skipValue();
                } else {
                    xAnimation = AnimatableValueParser.parseFloat(reader, composition);
                }
                break;
            case 2:
                if (reader.peek() == JsonReader.Token.STRING) {
                    hasExpressions = true;
                    reader.skipValue();
                } else {
                    yAnimation = AnimatableValueParser.parseFloat(reader, composition);
                }
                break;
            default:
                reader.skipName();
                reader.skipValue();
        }
    }
    reader.endObject();
    if (hasExpressions) {
        composition.addWarning("Lottie doesn't support expressions.");
    }
    if (pathAnimation != null) {
        return pathAnimation;
    }
    return new AnimatableSplitDimensionPathValue(xAnimation, yAnimation);
}
Also used : AnimatableSplitDimensionPathValue(com.airbnb.lottie.model.animatable.AnimatableSplitDimensionPathValue) AnimatableFloatValue(com.airbnb.lottie.model.animatable.AnimatableFloatValue) AnimatablePathValue(com.airbnb.lottie.model.animatable.AnimatablePathValue)

Example 3 with AnimatableFloatValue

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

the class AnimatableTransformParser method parse.

public static AnimatableTransform parse(JsonReader reader, LottieComposition composition) throws IOException {
    AnimatablePathValue anchorPoint = null;
    AnimatableValue<PointF, PointF> position = null;
    AnimatableScaleValue scale = null;
    AnimatableFloatValue rotation = null;
    AnimatableIntegerValue opacity = null;
    AnimatableFloatValue startOpacity = null;
    AnimatableFloatValue endOpacity = null;
    AnimatableFloatValue skew = null;
    AnimatableFloatValue skewAngle = null;
    boolean isObject = reader.peek() == JsonReader.Token.BEGIN_OBJECT;
    if (isObject) {
        reader.beginObject();
    }
    while (reader.hasNext()) {
        switch(reader.selectName(NAMES)) {
            case // a
            0:
                reader.beginObject();
                while (reader.hasNext()) {
                    switch(reader.selectName(ANIMATABLE_NAMES)) {
                        case 0:
                            anchorPoint = AnimatablePathValueParser.parse(reader, composition);
                            break;
                        default:
                            reader.skipName();
                            reader.skipValue();
                    }
                }
                reader.endObject();
                break;
            case // p
            1:
                position = AnimatablePathValueParser.parseSplitPath(reader, composition);
                break;
            case // s
            2:
                scale = AnimatableValueParser.parseScale(reader, composition);
                break;
            case // rz
            3:
                composition.addWarning("Lottie doesn't support 3D layers.");
            case // r
            4:
                /*
           * Sometimes split path rotation gets exported like:
           *         "rz": {
           *           "a": 1,
           *           "k": [
           *             {}
           *           ]
           *         },
           * which doesn't parse to a real keyframe.
           */
                rotation = AnimatableValueParser.parseFloat(reader, composition, false);
                if (rotation.getKeyframes().isEmpty()) {
                    rotation.getKeyframes().add(new Keyframe<>(composition, 0f, 0f, null, 0f, composition.getEndFrame()));
                } else if (rotation.getKeyframes().get(0).startValue == null) {
                    rotation.getKeyframes().set(0, new Keyframe<>(composition, 0f, 0f, null, 0f, composition.getEndFrame()));
                }
                break;
            case // o
            5:
                opacity = AnimatableValueParser.parseInteger(reader, composition);
                break;
            case // so
            6:
                startOpacity = AnimatableValueParser.parseFloat(reader, composition, false);
                break;
            case // eo
            7:
                endOpacity = AnimatableValueParser.parseFloat(reader, composition, false);
                break;
            case // sk
            8:
                skew = AnimatableValueParser.parseFloat(reader, composition, false);
                break;
            case // sa
            9:
                skewAngle = AnimatableValueParser.parseFloat(reader, composition, false);
                break;
            default:
                reader.skipName();
                reader.skipValue();
        }
    }
    if (isObject) {
        reader.endObject();
    }
    if (isAnchorPointIdentity(anchorPoint)) {
        anchorPoint = null;
    }
    if (isPositionIdentity(position)) {
        position = null;
    }
    if (isRotationIdentity(rotation)) {
        rotation = null;
    }
    if (isScaleIdentity(scale)) {
        scale = null;
    }
    if (isSkewIdentity(skew)) {
        skew = null;
    }
    if (isSkewAngleIdentity(skewAngle)) {
        skewAngle = null;
    }
    return new AnimatableTransform(anchorPoint, position, scale, rotation, opacity, startOpacity, endOpacity, skew, skewAngle);
}
Also used : Keyframe(com.airbnb.lottie.value.Keyframe) AnimatableIntegerValue(com.airbnb.lottie.model.animatable.AnimatableIntegerValue) AnimatableTransform(com.airbnb.lottie.model.animatable.AnimatableTransform) PointF(android.graphics.PointF) AnimatableScaleValue(com.airbnb.lottie.model.animatable.AnimatableScaleValue) AnimatableFloatValue(com.airbnb.lottie.model.animatable.AnimatableFloatValue) AnimatablePathValue(com.airbnb.lottie.model.animatable.AnimatablePathValue)

Example 4 with AnimatableFloatValue

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

the class RectangleShapeParser method parse.

static RectangleShape parse(JsonReader reader, LottieComposition composition) throws IOException {
    String name = null;
    AnimatableValue<PointF, PointF> position = null;
    AnimatableValue<PointF, PointF> size = null;
    AnimatableFloatValue roundedness = null;
    boolean hidden = false;
    while (reader.hasNext()) {
        switch(reader.selectName(NAMES)) {
            case 0:
                name = reader.nextString();
                break;
            case 1:
                position = AnimatablePathValueParser.parseSplitPath(reader, composition);
                break;
            case 2:
                size = AnimatableValueParser.parsePoint(reader, composition);
                break;
            case 3:
                roundedness = AnimatableValueParser.parseFloat(reader, composition);
                break;
            case 4:
                hidden = reader.nextBoolean();
                break;
            default:
                reader.skipValue();
        }
    }
    return new RectangleShape(name, position, size, roundedness, hidden);
}
Also used : RectangleShape(com.airbnb.lottie.model.content.RectangleShape) PointF(android.graphics.PointF) AnimatableFloatValue(com.airbnb.lottie.model.animatable.AnimatableFloatValue)

Example 5 with AnimatableFloatValue

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

the class PolystarShapeParser method parse.

static PolystarShape parse(JsonReader reader, LottieComposition composition, int d) throws IOException {
    String name = null;
    PolystarShape.Type type = null;
    AnimatableFloatValue points = null;
    AnimatableValue<PointF, PointF> position = null;
    AnimatableFloatValue rotation = null;
    AnimatableFloatValue outerRadius = null;
    AnimatableFloatValue outerRoundedness = null;
    AnimatableFloatValue innerRadius = null;
    AnimatableFloatValue innerRoundedness = null;
    boolean hidden = false;
    boolean reversed = d == 3;
    while (reader.hasNext()) {
        switch(reader.selectName(NAMES)) {
            case 0:
                name = reader.nextString();
                break;
            case 1:
                type = PolystarShape.Type.forValue(reader.nextInt());
                break;
            case 2:
                points = AnimatableValueParser.parseFloat(reader, composition, false);
                break;
            case 3:
                position = AnimatablePathValueParser.parseSplitPath(reader, composition);
                break;
            case 4:
                rotation = AnimatableValueParser.parseFloat(reader, composition, false);
                break;
            case 5:
                outerRadius = AnimatableValueParser.parseFloat(reader, composition);
                break;
            case 6:
                outerRoundedness = AnimatableValueParser.parseFloat(reader, composition, false);
                break;
            case 7:
                innerRadius = AnimatableValueParser.parseFloat(reader, composition);
                break;
            case 8:
                innerRoundedness = AnimatableValueParser.parseFloat(reader, composition, false);
                break;
            case 9:
                hidden = reader.nextBoolean();
                break;
            case 10:
                // "d" is 2 for normal and 3 for reversed.
                reversed = reader.nextInt() == 3;
                break;
            default:
                reader.skipName();
                reader.skipValue();
        }
    }
    return new PolystarShape(name, type, points, position, rotation, innerRadius, outerRadius, innerRoundedness, outerRoundedness, hidden, reversed);
}
Also used : AnimatableFloatValue(com.airbnb.lottie.model.animatable.AnimatableFloatValue) PointF(android.graphics.PointF) PolystarShape(com.airbnb.lottie.model.content.PolystarShape)

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