Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major refactor of observables and parenting #18

Merged
merged 1 commit into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified LottieSample/screenshots/LoopPlayOnce 100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions LottieSample/src/main/assets/AParenting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"assets":[],"layers":[{"ddd":0,"ind":0,"ty":4,"nm":"Shape Layer 2","parent":1,"ks":{"o":{"k":100},"r":{"k":0},"p":{"k":[100,3,0]},"a":{"k":[0,0,0]},"s":{"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"k":[67.102,70.805]},"p":{"k":[0,0]},"r":{"k":0},"nm":"Rectangle Path 1"},{"ty":"st","fillEnabled":true,"c":{"k":[1,1,1,1]},"o":{"k":100},"w":{"k":2},"lc":1,"lj":1,"ml":4,"nm":"Stroke 1"},{"ty":"fl","fillEnabled":true,"c":{"k":[0,1,0.23,1]},"o":{"k":100},"nm":"Fill 1"},{"ty":"tr","p":{"k":[0,0],"ix":2},"a":{"k":[0,0],"ix":1},"s":{"k":[100,100],"ix":3},"r":{"k":0,"ix":6},"o":{"k":100,"ix":7},"sk":{"k":0,"ix":4},"sa":{"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 1"}],"ip":0,"op":120,"st":0,"bm":0,"sr":1},{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 1","ks":{"o":{"k":100},"r":{"k":0},"p":{"k":[48,102,0]},"a":{"k":[0,0,0]},"s":{"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"k":[67.102,70.805]},"p":{"k":[0,0]},"r":{"k":0},"nm":"Rectangle Path 1"},{"ty":"st","fillEnabled":true,"c":{"k":[1,1,1,1]},"o":{"k":100},"w":{"k":2},"lc":1,"lj":1,"ml":4,"nm":"Stroke 1"},{"ty":"fl","fillEnabled":true,"c":{"k":[1,0,0,1]},"o":{"k":100},"nm":"Fill 1"},{"ty":"tr","p":{"k":[0,0],"ix":2},"a":{"k":[0,0],"ix":1},"s":{"k":[100,100],"ix":3},"r":{"k":0,"ix":6},"o":{"k":100,"ix":7},"sk":{"k":0,"ix":4},"sa":{"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 1"}],"ip":0,"op":120,"st":0,"bm":0,"sr":1}],"v":"4.4.26","ddd":0,"ip":0,"op":120,"fr":60,"w":200,"h":200}
1 change: 1 addition & 0 deletions LottieSample/src/main/assets/Amelie_A.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"assets":[],"layers":[{"ddd":0,"ind":0,"ty":4,"nm":"Shape Layer 3","ks":{"o":{"k":100},"r":{"k":0},"p":{"k":[275,325,0]},"a":{"k":[0,0,0]},"s":{"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"k":[{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"n":"0p833_1_0p167_0","t":5,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-5,118],[-0.5,117.5],[4,118]],"c":false}],"e":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-2,118],[-0.5,117.5],[2,118]],"c":false}]},{"i":{"x":0.34,"y":1},"o":{"x":0.333,"y":0},"n":"0p34_1_0p333_0","t":6,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-2,118],[-0.5,117.5],[2,118]],"c":false}],"e":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-0.5,118],[-0.5,-136.579],[-0.5,118]],"c":false}]},{"i":{"x":0.468,"y":1},"o":{"x":0.583,"y":0},"n":"0p468_1_0p583_0","t":11,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-0.5,118],[-0.5,-136.579],[-0.5,118]],"c":false}],"e":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-108.5,118],[-0.5,-107.539],[108.5,118]],"c":false}]},{"i":{"x":0.115,"y":1},"o":{"x":0.504,"y":0},"n":"0p115_1_0p504_0","t":17,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-108.5,118],[-0.5,-107.539],[108.5,118]],"c":false}],"e":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-101,118],[-0.5,-115.5],[101,118]],"c":false}]},{"t":25}]},"nm":"Path 1"},{"ty":"st","fillEnabled":true,"c":{"k":[0.15,0.8,0.55,1]},"o":{"k":100},"w":{"k":20},"lc":2,"lj":2,"nm":"Stroke 1"},{"ty":"tr","p":{"k":[0,0],"ix":2},"a":{"k":[0,0],"ix":1},"s":{"k":[100,100],"ix":3},"r":{"k":0,"ix":6},"o":{"k":100,"ix":7},"sk":{"k":0,"ix":4},"sa":{"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1"}],"ip":5,"op":51,"st":-1,"bm":0,"sr":1},{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 1","ks":{"o":{"k":100},"r":{"k":0},"p":{"k":[275,355,0]},"a":{"k":[0,0,0]},"s":{"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":12,"s":[{"i":[[0,0],[2.385,-18]],"o":[[0,0],[-60,0]],"v":[[2.385,24.5],[-3.135,24.5]],"c":false}],"e":[{"i":[[0,0],[14.777,-8]],"o":[[0,0],[-60,0]],"v":[[12.027,24.5],[-12.777,24.5]],"c":false}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":13,"s":[{"i":[[0,0],[14.777,-8]],"o":[[0,0],[-60,0]],"v":[[12.027,24.5],[-12.777,24.5]],"c":false}],"e":[{"i":[[0,0],[73.412,-0.5]],"o":[[0,0],[-60,0]],"v":[[34.162,24.5],[-34.412,24.5]],"c":false}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":14,"s":[{"i":[[0,0],[73.412,-0.5]],"o":[[0,0],[-60,0]],"v":[[34.162,24.5],[-34.412,24.5]],"c":false}],"e":[{"i":[[0,0],[72.346,10.21]],"o":[[0,0],[-60,0]],"v":[[62.096,24.5],[-62.346,24.5]],"c":false}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":15,"s":[{"i":[[0,0],[72.346,10.21]],"o":[[0,0],[-60,0]],"v":[[62.096,24.5],[-62.346,24.5]],"c":false}],"e":[{"i":[[0,0],[71.879,17.097]],"o":[[0,0],[-60,0]],"v":[[74.129,24.5],[-74.629,24.5]],"c":false}]},{"i":{"x":0.362,"y":1},"o":{"x":0.167,"y":0.167},"n":"0p362_1_0p167_0p167","t":16,"s":[{"i":[[0,0],[71.879,17.097]],"o":[[0,0],[-60,0]],"v":[[74.129,24.5],[-74.629,24.5]],"c":false}],"e":[{"i":[[0,0],[71.75,19]],"o":[[0,0],[-60,0]],"v":[[77.25,24.5],[-77.75,24.5]],"c":false}]},{"i":{"x":0.31,"y":1},"o":{"x":0.333,"y":0},"n":"0p31_1_0p333_0","t":17,"s":[{"i":[[0,0],[71.75,19]],"o":[[0,0],[-60,0]],"v":[[77.25,24.5],[-77.75,24.5]],"c":false}],"e":[{"i":[[0,0],[75.75,0]],"o":[[0,0],[-60,0]],"v":[[71.5,24.5],[-72.75,24.5]],"c":false}]},{"t":25}]},"nm":"Path 1"},{"ty":"st","fillEnabled":true,"c":{"k":[0.15,0.8,0.55,1]},"o":{"k":100},"w":{"k":10},"lc":2,"lj":2,"nm":"Stroke 1"},{"ty":"tr","p":{"k":[0,0],"ix":2},"a":{"k":[0,0],"ix":1},"s":{"k":[100,100],"ix":3},"r":{"k":0,"ix":6},"o":{"k":100,"ix":7},"sk":{"k":0,"ix":4},"sa":{"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1"}],"ip":12,"op":51,"st":-7,"bm":0,"sr":1},{"ddd":0,"ind":2,"ty":4,"nm":"shoot 2","ks":{"o":{"k":100},"r":{"k":0},"p":{"k":[274.75,441.25,0]},"a":{"k":[68,81,0]},"s":{"k":[-100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"k":{"i":[[0,0],[22.25,-151]],"o":[[0,0],[0,0]],"v":[[68,81.5],[-32,81.25]],"c":false}},"nm":"Path 1"},{"ty":"st","fillEnabled":true,"c":{"k":[0.95,0.57,0,1]},"o":{"k":100},"w":{"k":10},"lc":2,"lj":2,"nm":"Stroke 1"},{"ty":"tr","p":{"k":[0,0],"ix":2},"a":{"k":[0,0],"ix":1},"s":{"k":[100,100],"ix":3},"r":{"k":0,"ix":6},"o":{"k":100,"ix":7},"sk":{"k":0,"ix":4},"sa":{"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1"},{"ty":"tm","s":{"k":[{"i":{"x":[0.139],"y":[1]},"o":{"x":[0.333],"y":[0]},"n":["0p139_1_0p333_0"],"t":7,"s":[0],"e":[100]},{"t":14}],"ix":1},"e":{"k":[{"i":{"x":[0.214],"y":[1]},"o":{"x":[0.098],"y":[0]},"n":["0p214_1_0p098_0"],"t":5,"s":[0],"e":[100]},{"t":14}],"ix":2},"o":{"k":0,"ix":3},"m":1,"ix":2,"nm":"Trim Paths 1"}],"ip":5,"op":14,"st":0,"bm":0,"sr":1},{"ddd":0,"ind":3,"ty":4,"nm":"shoot 1","ks":{"o":{"k":100},"r":{"k":0},"p":{"k":[274.75,441.25,0]},"a":{"k":[68,81,0]},"s":{"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"k":{"i":[[0,0],[22.25,-151]],"o":[[0,0],[0,0]],"v":[[68,81.5],[-32,81.25]],"c":false}},"nm":"Path 1"},{"ty":"st","fillEnabled":true,"c":{"k":[0.95,0.57,0,1]},"o":{"k":100},"w":{"k":10},"lc":2,"lj":2,"nm":"Stroke 1"},{"ty":"tr","p":{"k":[0,0],"ix":2},"a":{"k":[0,0],"ix":1},"s":{"k":[100,100],"ix":3},"r":{"k":0,"ix":6},"o":{"k":100,"ix":7},"sk":{"k":0,"ix":4},"sa":{"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1"},{"ty":"tm","s":{"k":[{"i":{"x":[0.139],"y":[1]},"o":{"x":[0.333],"y":[0]},"n":["0p139_1_0p333_0"],"t":7,"s":[0],"e":[100]},{"t":14}],"ix":1},"e":{"k":[{"i":{"x":[0.214],"y":[1]},"o":{"x":[0.098],"y":[0]},"n":["0p214_1_0p098_0"],"t":5,"s":[0],"e":[100]},{"t":14}],"ix":2},"o":{"k":0,"ix":3},"m":1,"ix":2,"nm":"Trim Paths 1"}],"ip":5,"op":14,"st":0,"bm":0,"sr":1},{"ddd":0,"ind":4,"ty":4,"nm":"drop line 2","ks":{"o":{"k":100},"r":{"k":0},"p":{"k":[275,351,0]},"a":{"k":[0,0,0]},"s":{"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[0,114.667],[0,-214.667]],"c":false}},"nm":"Path 1"},{"ty":"st","fillEnabled":true,"c":{"k":[0.95,0.57,0,1]},"o":{"k":100},"w":{"k":10},"lc":2,"lj":2,"nm":"Stroke 1"},{"ty":"tm","s":{"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"n":["0p667_1_0p333_0"],"t":0,"s":[100],"e":[0]},{"t":6}],"ix":1},"e":{"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"n":["0p667_1_0p333_0"],"t":1,"s":[100],"e":[0]},{"t":6}],"ix":2},"o":{"k":0,"ix":3},"m":1,"ix":3,"nm":"Trim Paths 1"},{"ty":"tr","p":{"k":[0,0],"ix":2},"a":{"k":[0,0],"ix":1},"s":{"k":[100,100],"ix":3},"r":{"k":0,"ix":6},"o":{"k":100,"ix":7},"sk":{"k":0,"ix":4},"sa":{"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1"}],"ip":0,"op":6,"st":-5,"bm":0,"sr":1}],"v":"4.4.26","ddd":0,"ip":0,"op":51,"fr":25,"w":550,"h":650}
1 change: 1 addition & 0 deletions LottieSample/src/main/assets/Mobilo_C3.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lottie/src/main/java/com/airbnb/lottie/L.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.airbnb.lottie;

public class L {
public static final boolean DBG = false;
public static final boolean DBG = true;
}
46 changes: 32 additions & 14 deletions lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.util.LongSparseArray;
import android.widget.ImageView;

Expand All @@ -27,7 +28,7 @@

import org.json.JSONObject;

import java.util.Collections;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -41,7 +42,7 @@
* You may manually set the progress of the animation with {@link #setProgress(float)}
*/
public class LottieAnimationView extends ImageView {

private static final String TAG = LottieAnimationView.class.getSimpleName();

/**
* Returns a {@link LottieAnimationView} that will allow it to be used without being attached to a window.
Expand All @@ -62,7 +63,6 @@ public void onCompositionLoaded(LottieComposition composition) {
}
};

private final LongSparseArray<LayerView> layerMap = new LongSparseArray<>();
private final RootLayer rootLayer = new RootLayer(this);
@FloatRange(from=0f, to=1f) private float progress;
private String animationName;
Expand Down Expand Up @@ -231,6 +231,10 @@ public void setComposition(@NonNull LottieComposition composition) {
return;
}

if (L.DBG) {
Log.v(TAG, "Set Composition \n" + composition);
}

isAnimationLoading = false;

clearComposition();
Expand All @@ -245,7 +249,7 @@ public void setComposition(@NonNull LottieComposition composition) {
this.composition = composition;
rootLayer.setCompDuration(composition.getDuration());
rootLayer.setBounds(0, 0, composition.getBounds().width(), composition.getBounds().height());
buildSubviewsForComposition();
buildLayersForComposition();
requestLayout();
setImageDrawable(rootLayer);

Expand All @@ -255,11 +259,10 @@ public void setComposition(@NonNull LottieComposition composition) {
}
}

private void buildSubviewsForComposition() {
//noinspection ConstantConditions
List<Layer> reversedLayers = composition.getLayers();
Collections.reverse(reversedLayers);

private void buildLayersForComposition() {
if (composition == null) {
throw new IllegalStateException("Composition is null");
}
Rect bounds = composition.getBounds();
if (composition.hasMasks() || composition.hasMattes()) {
mainBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
Expand All @@ -270,9 +273,11 @@ private void buildSubviewsForComposition() {
if (composition.hasMattes()) {
matteBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
}
LongSparseArray<LayerView> layerMap = new LongSparseArray<>(composition.getLayers().size());
List<LayerView> layers = new ArrayList<>(composition.getLayers().size());
LayerView maskedLayer = null;
for (int i = 0; i < reversedLayers.size(); i++) {
Layer layer = reversedLayers.get(i);
for (int i = composition.getLayers().size() - 1; i >= 0; i--) {
Layer layer = composition.getLayers().get(i);
LayerView layerView;
if (maskedLayer == null) {
layerView = new LayerView(layer, composition, this, mainBitmap, maskBitmap, matteBitmap);
Expand All @@ -288,13 +293,27 @@ private void buildSubviewsForComposition() {
}
layerMap.put(layerView.getId(), layerView);
if (maskedLayer != null) {
maskedLayer.setMatte(layerView);
maskedLayer.setMatteLayer(layerView);
maskedLayer = null;
} else {
layers.add(layerView);
if (layer.getMatteType() == Layer.MatteType.Add) {
maskedLayer = layerView;
}
rootLayer.addLayer(layerView);
}
}

for (int i = 0; i < layers.size(); i++) {
LayerView layerView = layers.get(i);
rootLayer.addLayer(layerView);
}

for (int i = 0; i < layerMap.size(); i++) {
long key = layerMap.keyAt(i);
LayerView layerView = layerMap.get(key);
LayerView parentLayer = layerMap.get(layerView.getLayerModel().getParentId());
if (parentLayer != null) {
layerView.setParentLayer(parentLayer);
}
}
}
Expand All @@ -303,7 +322,6 @@ private void clearComposition() {
composition = null;
recycleBitmaps();
rootLayer.clearLayers();
layerMap.clear();
}


Expand Down
11 changes: 6 additions & 5 deletions lottie/src/main/java/com/airbnb/lottie/LottieViewAnimator.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static LottieViewAnimator of(Context context, String fileName, View... vi
return new LottieViewAnimator(context, fileName, views);
}

@SuppressWarnings("FieldCanBeLocal")
private final LottieComposition.OnCompositionLoadedListener loadedListener = new LottieComposition.OnCompositionLoadedListener() {
@Override
public void onCompositionLoaded(LottieComposition composition) {
Expand Down Expand Up @@ -66,13 +67,13 @@ private void setComposition(LottieComposition composition) {
animator.setDuration(composition.getDuration());

for (final Layer layer : composition.getLayers()) {
final View view = viewsMap.get(layer.getLayerName());
final View view = viewsMap.get(layer.getName());
if (view == null) {
continue;
}

if (layer.getPosition().hasAnimation()) {
KeyframeAnimation<PointF> position = layer.getPosition().animationForKeyPath();
KeyframeAnimation<PointF> position = layer.getPosition().createAnimation();
position.addUpdateListener(new KeyframeAnimation.AnimationListener<PointF>() {
@Override
public void onValueChanged(PointF progress) {
Expand All @@ -87,7 +88,7 @@ public void onValueChanged(PointF progress) {
view.setTranslationY(initialPosition.y);

if (layer.getScale().hasAnimation()) {
KeyframeAnimation<ScaleXY> scale = layer.getScale().animationForKeyPath();
KeyframeAnimation<ScaleXY> scale = layer.getScale().createAnimation();
scale.addUpdateListener(new KeyframeAnimation.AnimationListener<ScaleXY>() {
@Override
public void onValueChanged(ScaleXY scale) {
Expand All @@ -102,7 +103,7 @@ public void onValueChanged(ScaleXY scale) {
view.setScaleY(initialScale.getScaleY());

if (layer.getRotation().hasAnimation()) {
KeyframeAnimation<Float> rotation = layer.getRotation().animationForKeyPath();
KeyframeAnimation<Float> rotation = layer.getRotation().createAnimation();
rotation.addUpdateListener(new KeyframeAnimation.AnimationListener<Float>() {
@Override
public void onValueChanged(Float rotation) {
Expand All @@ -114,7 +115,7 @@ public void onValueChanged(Float rotation) {
view.setRotation(layer.getRotation().getInitialValue());

if (layer.getAnchor().hasAnimation()) {
KeyframeAnimation<PointF> anchor = layer.getAnchor().animationForKeyPath();
KeyframeAnimation<PointF> anchor = layer.getAnchor().createAnimation();
anchor.addUpdateListener(new KeyframeAnimation.AnimationListener<PointF>() {
@Override
public void onValueChanged(PointF anchor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.airbnb.lottie.animation.ColorKeyframeAnimation;
import com.airbnb.lottie.animation.KeyframeAnimation;
import com.airbnb.lottie.animation.StaticKeyframeAnimation;
import com.airbnb.lottie.model.LottieComposition;

import org.json.JSONArray;
Expand Down Expand Up @@ -40,18 +41,12 @@ protected Integer valueFromObject(Object object, float scale) throws JSONExcepti


@Override
public KeyframeAnimation animationForKeyPath() {
public KeyframeAnimation<Integer> createAnimation() {
if (!hasAnimation()) {
return null;
return new StaticKeyframeAnimation<>(initialValue);
}
ColorKeyframeAnimation animation = new ColorKeyframeAnimation(duration, composition, keyTimes, keyValues, interpolators);
animation.setStartDelay(delay);
animation.addUpdateListener(new KeyframeAnimation.AnimationListener<Integer>() {
@Override
public void onValueChanged(Integer progress) {
observable.setValue(progress);
}
});
return animation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.airbnb.lottie.animation.KeyframeAnimation;
import com.airbnb.lottie.animation.NumberKeyframeAnimation;
import com.airbnb.lottie.animation.StaticKeyframeAnimation;
import com.airbnb.lottie.model.LottieComposition;

import org.json.JSONArray;
Expand Down Expand Up @@ -34,15 +35,13 @@ protected Float valueFromObject(Object object, float scale) throws JSONException
}

@Override
public KeyframeAnimation<Float> animationForKeyPath() {
public KeyframeAnimation<Float> createAnimation() {
if (!hasAnimation()) {
return new StaticKeyframeAnimation<>(initialValue);
}

KeyframeAnimation<Float> animation = new NumberKeyframeAnimation<>(duration, composition, keyTimes, Float.class, keyValues, interpolators);
animation.setStartDelay(delay);
animation.addUpdateListener(new KeyframeAnimation.AnimationListener<Float>() {
@Override
public void onValueChanged(Float progress) {
observable.setValue(progress);
}
});
return animation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.airbnb.lottie.animation.KeyframeAnimation;
import com.airbnb.lottie.animation.NumberKeyframeAnimation;
import com.airbnb.lottie.animation.StaticKeyframeAnimation;
import com.airbnb.lottie.model.LottieComposition;

import org.json.JSONArray;
Expand All @@ -15,7 +16,6 @@ public AnimatableIntegerValue(JSONObject json, int frameRate, LottieComposition
super(json, frameRate, composition, isDp);
if (remap100To255) {
initialValue = initialValue * 255 / 100;
getObservable().setValue(initialValue);
for (int i = 0; i < keyValues.size(); i++) {
keyValues.set(i, keyValues.get(i) * 255 / 100);
}
Expand All @@ -33,15 +33,13 @@ protected Integer valueFromObject(Object object, float scale) throws JSONExcepti
}

@Override
public KeyframeAnimation animationForKeyPath() {
public KeyframeAnimation<Integer> createAnimation() {
if (!hasAnimation()) {
return new StaticKeyframeAnimation<>(initialValue);
}

KeyframeAnimation<Integer> animation = new NumberKeyframeAnimation<>(duration, composition, keyTimes, Integer.class, keyValues, interpolators);
animation.setStartDelay(delay);
animation.addUpdateListener(new KeyframeAnimation.AnimationListener<Integer>() {
@Override
public void onValueChanged(Integer progress) {
observable.setValue(progress);
}
});
return animation;
}

Expand Down
Loading