Search in sources :

Example 6 with LongSparseArray

use of androidx.collection.LongSparseArray 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

LongSparseArray (androidx.collection.LongSparseArray)6 LottieImageAsset (com.airbnb.lottie.LottieImageAsset)2 Layer (com.airbnb.lottie.model.layer.Layer)2 Point (com.google.maps.android.geometry.Point)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Rect (android.graphics.Rect)1 SparseArray (android.util.SparseArray)1 SparseBooleanArray (android.util.SparseBooleanArray)1 SparseIntArray (android.util.SparseIntArray)1 SparseLongArray (android.util.SparseLongArray)1 SimpleArrayMap (androidx.collection.SimpleArrayMap)1 SparseArrayCompat (androidx.collection.SparseArrayCompat)1 LottieComposition (com.airbnb.lottie.LottieComposition)1 Font (com.airbnb.lottie.model.Font)1 FontCharacter (com.airbnb.lottie.model.FontCharacter)1 Marker (com.airbnb.lottie.model.Marker)1 Cluster (com.google.maps.android.clustering.Cluster)1 SphericalMercatorProjection (com.google.maps.android.projection.SphericalMercatorProjection)1 Field (java.lang.reflect.Field)1