Search in sources :

Example 6 with Layer

use of com.airbnb.lottie.model.layer.Layer in project lottie-android by airbnb.

the class LottieCompositionMoshiParser method parseAssets.

private static void parseAssets(JsonReader reader, LottieComposition composition, Map<String, List<Layer>> precomps, Map<String, LottieImageAsset> images) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        String id = null;
        // For precomps
        List<Layer> layers = new ArrayList<>();
        LongSparseArray<Layer> layerMap = new LongSparseArray<>();
        // For images
        int width = 0;
        int height = 0;
        String imageFileName = null;
        String relativeFolder = null;
        reader.beginObject();
        while (reader.hasNext()) {
            switch(reader.selectName(ASSETS_NAMES)) {
                case 0:
                    id = reader.nextString();
                    break;
                case 1:
                    reader.beginArray();
                    while (reader.hasNext()) {
                        Layer layer = LayerParser.parse(reader, composition);
                        layerMap.put(layer.getId(), layer);
                        layers.add(layer);
                    }
                    reader.endArray();
                    break;
                case 2:
                    width = reader.nextInt();
                    break;
                case 3:
                    height = reader.nextInt();
                    break;
                case 4:
                    imageFileName = reader.nextString();
                    break;
                case 5:
                    relativeFolder = reader.nextString();
                    break;
                default:
                    reader.skipName();
                    reader.skipValue();
            }
        }
        reader.endObject();
        if (imageFileName != null) {
            LottieImageAsset image = new LottieImageAsset(width, height, id, imageFileName, relativeFolder);
            images.put(image.getId(), image);
        } else {
            precomps.put(id, layers);
        }
    }
    reader.endArray();
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) LottieImageAsset(com.airbnb.lottie.LottieImageAsset) ArrayList(java.util.ArrayList) Layer(com.airbnb.lottie.model.layer.Layer)

Aggregations

Layer (com.airbnb.lottie.model.layer.Layer)6 ArrayList (java.util.ArrayList)5 Rect (android.graphics.Rect)3 Font (com.airbnb.lottie.model.Font)3 FontCharacter (com.airbnb.lottie.model.FontCharacter)3 Marker (com.airbnb.lottie.model.Marker)3 List (java.util.List)3 LongSparseArray (androidx.collection.LongSparseArray)2 LottieImageAsset (com.airbnb.lottie.LottieImageAsset)2 SparseArrayCompat (androidx.collection.SparseArrayCompat)1 LottieComposition (com.airbnb.lottie.LottieComposition)1 AnimatableFloatValue (com.airbnb.lottie.model.animatable.AnimatableFloatValue)1 AnimatableTextFrame (com.airbnb.lottie.model.animatable.AnimatableTextFrame)1 AnimatableTextProperties (com.airbnb.lottie.model.animatable.AnimatableTextProperties)1 AnimatableTransform (com.airbnb.lottie.model.animatable.AnimatableTransform)1 BlurEffect (com.airbnb.lottie.model.content.BlurEffect)1 ContentModel (com.airbnb.lottie.model.content.ContentModel)1 Mask (com.airbnb.lottie.model.content.Mask)1 Keyframe (com.airbnb.lottie.value.Keyframe)1 HashMap (java.util.HashMap)1