Search in sources :

Example 1 with AnimatableScaleValue

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

Aggregations

PointF (android.graphics.PointF)1 AnimatableFloatValue (com.airbnb.lottie.model.animatable.AnimatableFloatValue)1 AnimatableIntegerValue (com.airbnb.lottie.model.animatable.AnimatableIntegerValue)1 AnimatablePathValue (com.airbnb.lottie.model.animatable.AnimatablePathValue)1 AnimatableScaleValue (com.airbnb.lottie.model.animatable.AnimatableScaleValue)1 AnimatableTransform (com.airbnb.lottie.model.animatable.AnimatableTransform)1 Keyframe (com.airbnb.lottie.value.Keyframe)1