Search in sources :

Example 1 with AnimatableIntegerValue

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

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

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

the class GradientFillParser method parse.

static GradientFill 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;
    Path.FillType fillType = Path.FillType.WINDING;
    boolean hidden = false;
    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:
                fillType = reader.nextInt() == 1 ? Path.FillType.WINDING : Path.FillType.EVEN_ODD;
                break;
            case 7:
                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;
    return new GradientFill(name, gradientType, fillType, color, opacity, startPoint, endPoint, null, null, hidden);
}
Also used : Path(android.graphics.Path) Keyframe(com.airbnb.lottie.value.Keyframe) AnimatableIntegerValue(com.airbnb.lottie.model.animatable.AnimatableIntegerValue) AnimatablePointValue(com.airbnb.lottie.model.animatable.AnimatablePointValue) GradientType(com.airbnb.lottie.model.content.GradientType) GradientFill(com.airbnb.lottie.model.content.GradientFill) AnimatableGradientColorValue(com.airbnb.lottie.model.animatable.AnimatableGradientColorValue)

Example 4 with AnimatableIntegerValue

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

the class MaskParser method parse.

static Mask parse(JsonReader reader, LottieComposition composition) throws IOException {
    Mask.MaskMode maskMode = null;
    AnimatableShapeValue maskPath = null;
    AnimatableIntegerValue opacity = null;
    boolean inverted = false;
    reader.beginObject();
    while (reader.hasNext()) {
        String mode = reader.nextName();
        switch(mode) {
            case "mode":
                switch(reader.nextString()) {
                    case "a":
                        maskMode = Mask.MaskMode.MASK_MODE_ADD;
                        break;
                    case "s":
                        maskMode = Mask.MaskMode.MASK_MODE_SUBTRACT;
                        break;
                    case "n":
                        maskMode = Mask.MaskMode.MASK_MODE_NONE;
                        break;
                    case "i":
                        composition.addWarning("Animation contains intersect masks. They are not supported but will be treated like add masks.");
                        maskMode = Mask.MaskMode.MASK_MODE_INTERSECT;
                        break;
                    default:
                        Logger.warning("Unknown mask mode " + mode + ". Defaulting to Add.");
                        maskMode = Mask.MaskMode.MASK_MODE_ADD;
                }
                break;
            case "pt":
                maskPath = AnimatableValueParser.parseShapeData(reader, composition);
                break;
            case "o":
                opacity = AnimatableValueParser.parseInteger(reader, composition);
                break;
            case "inv":
                inverted = reader.nextBoolean();
                break;
            default:
                reader.skipValue();
        }
    }
    reader.endObject();
    return new Mask(maskMode, maskPath, opacity, inverted);
}
Also used : AnimatableIntegerValue(com.airbnb.lottie.model.animatable.AnimatableIntegerValue) Mask(com.airbnb.lottie.model.content.Mask) AnimatableShapeValue(com.airbnb.lottie.model.animatable.AnimatableShapeValue)

Example 5 with AnimatableIntegerValue

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

Aggregations

AnimatableIntegerValue (com.airbnb.lottie.model.animatable.AnimatableIntegerValue)6 Keyframe (com.airbnb.lottie.value.Keyframe)5 AnimatableFloatValue (com.airbnb.lottie.model.animatable.AnimatableFloatValue)3 Path (android.graphics.Path)2 AnimatableColorValue (com.airbnb.lottie.model.animatable.AnimatableColorValue)2 AnimatableGradientColorValue (com.airbnb.lottie.model.animatable.AnimatableGradientColorValue)2 AnimatablePointValue (com.airbnb.lottie.model.animatable.AnimatablePointValue)2 GradientType (com.airbnb.lottie.model.content.GradientType)2 ShapeStroke (com.airbnb.lottie.model.content.ShapeStroke)2 ArrayList (java.util.ArrayList)2 PointF (android.graphics.PointF)1 AnimatablePathValue (com.airbnb.lottie.model.animatable.AnimatablePathValue)1 AnimatableScaleValue (com.airbnb.lottie.model.animatable.AnimatableScaleValue)1 AnimatableShapeValue (com.airbnb.lottie.model.animatable.AnimatableShapeValue)1 AnimatableTransform (com.airbnb.lottie.model.animatable.AnimatableTransform)1 GradientFill (com.airbnb.lottie.model.content.GradientFill)1 GradientStroke (com.airbnb.lottie.model.content.GradientStroke)1 Mask (com.airbnb.lottie.model.content.Mask)1 ShapeFill (com.airbnb.lottie.model.content.ShapeFill)1