Search in sources :

Example 6 with Keyframe

use of com.airbnb.lottie.value.Keyframe 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 7 with Keyframe

use of com.airbnb.lottie.value.Keyframe 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

Keyframe (com.airbnb.lottie.value.Keyframe)7 AnimatableIntegerValue (com.airbnb.lottie.model.animatable.AnimatableIntegerValue)5 AnimatableFloatValue (com.airbnb.lottie.model.animatable.AnimatableFloatValue)4 ArrayList (java.util.ArrayList)3 Path (android.graphics.Path)2 PointF (android.graphics.PointF)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 AnimatableTransform (com.airbnb.lottie.model.animatable.AnimatableTransform)2 GradientType (com.airbnb.lottie.model.content.GradientType)2 ShapeStroke (com.airbnb.lottie.model.content.ShapeStroke)2 Interpolator (android.view.animation.Interpolator)1 LinearInterpolator (android.view.animation.LinearInterpolator)1 AnimatablePathValue (com.airbnb.lottie.model.animatable.AnimatablePathValue)1 AnimatableScaleValue (com.airbnb.lottie.model.animatable.AnimatableScaleValue)1 AnimatableTextFrame (com.airbnb.lottie.model.animatable.AnimatableTextFrame)1 AnimatableTextProperties (com.airbnb.lottie.model.animatable.AnimatableTextProperties)1 BlurEffect (com.airbnb.lottie.model.content.BlurEffect)1 ContentModel (com.airbnb.lottie.model.content.ContentModel)1