diff --git a/lottie-compose/src/test/java/com/airbnb/lottie/compose/LottieClipSpecTest.kt b/lottie-compose/src/test/java/com/airbnb/lottie/compose/LottieClipSpecTest.kt index 346c95d73f..e9a2bdbb4f 100644 --- a/lottie-compose/src/test/java/com/airbnb/lottie/compose/LottieClipSpecTest.kt +++ b/lottie-compose/src/test/java/com/airbnb/lottie/compose/LottieClipSpecTest.kt @@ -139,6 +139,8 @@ class LottieClipSpecTest { SparseArrayCompat(), emptyMap(), markers, + 0, + 0, ) return composition } diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieComposition.java b/lottie/src/main/java/com/airbnb/lottie/LottieComposition.java index c91bbf6732..ac5cd737a0 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieComposition.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieComposition.java @@ -71,12 +71,15 @@ public class LottieComposition { */ private int maskAndMatteCount = 0; + private int unscaledWidth; + private int unscaledHeight; + @RestrictTo(RestrictTo.Scope.LIBRARY) public void init(Rect bounds, float startFrame, float endFrame, float frameRate, List layers, LongSparseArray layerMap, Map> precomps, Map images, float imagesDpScale, SparseArrayCompat characters, Map fonts, - List markers) { + List markers, int unscaledWidth, int unscaledHeight) { this.bounds = bounds; this.startFrame = startFrame; this.endFrame = endFrame; @@ -89,6 +92,8 @@ public void init(Rect bounds, float startFrame, float endFrame, float frameRate, this.characters = characters; this.fonts = fonts; this.markers = markers; + this.unscaledWidth = unscaledWidth; + this.unscaledHeight = unscaledHeight; } @RestrictTo(RestrictTo.Scope.LIBRARY) @@ -232,6 +237,13 @@ public float getDurationFrames() { return endFrame - startFrame; } + public int getUnscaledWidth() { + return unscaledWidth; + } + + public int getUnscaledHeight() { + return unscaledHeight; + } @NonNull @Override diff --git a/lottie/src/main/java/com/airbnb/lottie/parser/LottieCompositionMoshiParser.java b/lottie/src/main/java/com/airbnb/lottie/parser/LottieCompositionMoshiParser.java index ee972df675..ec4abb72ee 100644 --- a/lottie/src/main/java/com/airbnb/lottie/parser/LottieCompositionMoshiParser.java +++ b/lottie/src/main/java/com/airbnb/lottie/parser/LottieCompositionMoshiParser.java @@ -44,8 +44,8 @@ public static LottieComposition parse(JsonReader reader) throws IOException { float frameRate = 0f; final LongSparseArray layerMap = new LongSparseArray<>(); final List layers = new ArrayList<>(); - int width = 0; - int height = 0; + int unscaledWidth = 0; + int unscaledHeight = 0; Map> precomps = new HashMap<>(); Map images = new HashMap<>(); Map fonts = new HashMap<>(); @@ -57,10 +57,10 @@ public static LottieComposition parse(JsonReader reader) throws IOException { while (reader.hasNext()) { switch (reader.selectName(NAMES)) { case 0: - width = reader.nextInt(); + unscaledWidth = reader.nextInt(); break; case 1: - height = reader.nextInt(); + unscaledHeight = reader.nextInt(); break; case 2: startFrame = (float) reader.nextDouble(); @@ -102,12 +102,12 @@ public static LottieComposition parse(JsonReader reader) throws IOException { reader.skipValue(); } } - int scaledWidth = (int) (width * scale); - int scaledHeight = (int) (height * scale); + int scaledWidth = (int) (unscaledWidth * scale); + int scaledHeight = (int) (unscaledHeight * scale); Rect bounds = new Rect(0, 0, scaledWidth, scaledHeight); composition.init(bounds, startFrame, endFrame, frameRate, layers, layerMap, precomps, - images, Utils.dpScale(), characters, fonts, markers); + images, Utils.dpScale(), characters, fonts, markers, unscaledWidth, unscaledHeight); return composition; } diff --git a/lottie/src/test/java/com/airbnb/lottie/LottieDrawableTest.java b/lottie/src/test/java/com/airbnb/lottie/LottieDrawableTest.java index 3e158ec722..9c50952062 100644 --- a/lottie/src/test/java/com/airbnb/lottie/LottieDrawableTest.java +++ b/lottie/src/test/java/com/airbnb/lottie/LottieDrawableTest.java @@ -4,10 +4,6 @@ import android.graphics.Rect; import androidx.collection.LongSparseArray; import androidx.collection.SparseArrayCompat; -import com.airbnb.lottie.model.Font; -import com.airbnb.lottie.model.FontCharacter; -import com.airbnb.lottie.model.Marker; -import com.airbnb.lottie.model.layer.Layer; import org.junit.Before; import org.junit.Test; @@ -16,7 +12,6 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import static junit.framework.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -39,7 +34,7 @@ private LottieComposition createComposition(int startFrame, int endFrame) { composition.init(new Rect(), startFrame, endFrame, 1000, new ArrayList<>(), new LongSparseArray<>(0), new HashMap<>(0), new HashMap<>(0), 1f, new SparseArrayCompat<>(0), - new HashMap<>(0), new ArrayList<>()); + new HashMap<>(0), new ArrayList<>(), 0, 0); return composition; } diff --git a/lottie/src/test/java/com/airbnb/lottie/LottieValueAnimatorUnitTest.java b/lottie/src/test/java/com/airbnb/lottie/LottieValueAnimatorUnitTest.java index 102087b636..a26e4a9c06 100644 --- a/lottie/src/test/java/com/airbnb/lottie/LottieValueAnimatorUnitTest.java +++ b/lottie/src/test/java/com/airbnb/lottie/LottieValueAnimatorUnitTest.java @@ -5,10 +5,6 @@ import android.graphics.Rect; import androidx.collection.LongSparseArray; import androidx.collection.SparseArrayCompat; -import com.airbnb.lottie.model.Font; -import com.airbnb.lottie.model.FontCharacter; -import com.airbnb.lottie.model.Marker; -import com.airbnb.lottie.model.layer.Layer; import com.airbnb.lottie.utils.LottieValueAnimator; import org.junit.Before; import org.junit.Test; @@ -17,7 +13,6 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import static junit.framework.Assert.assertEquals; @@ -63,7 +58,7 @@ private LottieComposition createComposition(int startFrame, int endFrame) { composition.init(new Rect(), startFrame, endFrame, 1000, new ArrayList<>(), new LongSparseArray<>(0), new HashMap<>(0), new HashMap<>(0), 1f, new SparseArrayCompat<>(0), - new HashMap<>(0), new ArrayList<>()); + new HashMap<>(0), new ArrayList<>(), 0, 0); return composition; }