Search in sources :

Example 1 with GradientFill

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

Aggregations

Path (android.graphics.Path)1 AnimatableGradientColorValue (com.airbnb.lottie.model.animatable.AnimatableGradientColorValue)1 AnimatableIntegerValue (com.airbnb.lottie.model.animatable.AnimatableIntegerValue)1 AnimatablePointValue (com.airbnb.lottie.model.animatable.AnimatablePointValue)1 GradientFill (com.airbnb.lottie.model.content.GradientFill)1 GradientType (com.airbnb.lottie.model.content.GradientType)1 Keyframe (com.airbnb.lottie.value.Keyframe)1