-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull out LottieComposition factory methods into inner class (#137)
This is part of issue #3. Pulled static factory methods out of LottieComposition into a static inner class. Made all fields final and initialized them all in the constructor. This will make it easier for follow up refactors where we'll modularize the parsing logic and make it pluggable. Also upgraded the Espresso tests to JUnit 4 so it no longer uses the deprecated ActivityInstrumentationTestCase2
- Loading branch information
Showing
15 changed files
with
295 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 42 additions & 39 deletions
81
LottieSample/src/androidTest/java/com/airbnb/lottie/LottieTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,55 @@ | ||
package com.airbnb.lottie; | ||
|
||
|
||
import android.test.ActivityInstrumentationTestCase2; | ||
import android.support.test.filters.LargeTest; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import com.airbnb.lottie.samples.MainActivity; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Run these with: ./gradlew --daemon recordMode screenshotTests | ||
* If you run that command, it completes successfully, and nothing shows up in git, then you haven't broken anything! | ||
* Run these with: ./gradlew recordMode screenshotTests | ||
* If you run that command, it completes successfully, and nothing shows up in git, then you | ||
* haven't broken anything! | ||
*/ | ||
public class LottieTest extends ActivityInstrumentationTestCase2<MainActivity> { | ||
|
||
public LottieTest() { | ||
super(MainActivity.class); | ||
} | ||
@RunWith(AndroidJUnit4.class) | ||
@LargeTest | ||
public class LottieTest { | ||
@Rule public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule<>( | ||
MainActivity.class); | ||
|
||
@Test | ||
public void testAll() { | ||
TestRobot.testAnimation(getActivity(), "9squares-AlBoardman.json"); | ||
TestRobot.testAnimation(getActivity(), "EmptyState.json"); | ||
TestRobot.testAnimation(getActivity(), "HamburgerArrow.json"); | ||
TestRobot.testAnimation(getActivity(), "LottieLogo1.json"); | ||
TestRobot.testAnimation(getActivity(), "LottieLogo2.json"); | ||
TestRobot.testAnimation(getActivity(), "MotionCorpse-Jrcanest.json"); | ||
TestRobot.testAnimation(getActivity(), "PinJump.json"); | ||
TestRobot.testAnimation(getActivity(), "TwitterHeart.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/Hosts.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/LightBulb.json", null, | ||
@Test public void testAll() { | ||
TestRobot.testAnimation(activityRule.getActivity(), "9squares-AlBoardman.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "EmptyState.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "HamburgerArrow.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "LottieLogo1.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "LottieLogo2.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "MotionCorpse-Jrcanest.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "PinJump.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "TwitterHeart.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/Hosts.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/LightBulb.json", null, | ||
new float[]{0f, 0.05f, 0.10f, 0.2f, 0.3f, 0.4f, 0.5f, 1f}); | ||
TestRobot.testAnimation(getActivity(), "Tests/LoopPlayOnce.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/Alarm.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/CheckSwitch.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/EllipseTrimPath.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/SplitDimensions.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/TrimPathsFull.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/Laugh4.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/Star.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/Polygon.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/AllSet.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/City.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/PreCompMadness.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/MatteParentPrecomp.json"); | ||
TestRobot.testAnimation(getActivity(), "Tests/Image.json", "Tests/weaccept"); | ||
TestRobot.testStatic(getActivity(), "Tests/TrimPathFill.json"); | ||
TestRobot.testStatic(getActivity(), "Tests/Mask_26.json"); | ||
TestRobot.testStatic(getActivity(), "Tests/MatteInv.json"); | ||
TestRobot.testStatic(getActivity(), "Tests/MaskInv.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/LoopPlayOnce.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/Alarm.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/CheckSwitch.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/EllipseTrimPath.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/SplitDimensions.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/TrimPathsFull.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/Laugh4.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/Star.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/Polygon.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/AllSet.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/City.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/PreCompMadness.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/MatteParentPrecomp.json"); | ||
TestRobot.testAnimation(activityRule.getActivity(), "Tests/Image.json", "Tests/weaccept"); | ||
TestRobot.testStatic(activityRule.getActivity(), "Tests/TrimPathFill.json"); | ||
TestRobot.testStatic(activityRule.getActivity(), "Tests/Mask_26.json"); | ||
TestRobot.testStatic(activityRule.getActivity(), "Tests/MatteInv.json"); | ||
TestRobot.testStatic(activityRule.getActivity(), "Tests/MaskInv.json"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
LottieSample/src/androidTest/java/com/airbnb/lottie/TestRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
package com.airbnb.lottie; | ||
|
||
import android.os.Bundle; | ||
import android.support.test.runner.AndroidJUnitRunner; | ||
|
||
import com.facebook.testing.screenshot.ScreenshotRunner; | ||
|
||
public class TestRunner extends AndroidJUnitRunner { | ||
@Override public void onCreate(Bundle arguments) { | ||
ScreenshotRunner.onCreate(this, arguments); | ||
super.onCreate(arguments); | ||
} | ||
|
||
@Override public void finish(int resultCode, Bundle results) { | ||
ScreenshotRunner.onDestroy(); | ||
super.finish(resultCode, results); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.airbnb.lottie; | ||
|
||
interface Cancellable { | ||
void cancel(); | ||
} |
10 changes: 10 additions & 0 deletions
10
lottie/src/main/java/com/airbnb/lottie/CompositionLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.airbnb.lottie; | ||
|
||
import android.os.AsyncTask; | ||
|
||
abstract class CompositionLoader<Params> extends AsyncTask<Params, Void, LottieComposition> | ||
implements Cancellable { | ||
@Override public void cancel() { | ||
cancel(true); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
lottie/src/main/java/com/airbnb/lottie/FileCompositionLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.airbnb.lottie; | ||
|
||
import android.content.res.Resources; | ||
|
||
import java.io.InputStream; | ||
|
||
final class FileCompositionLoader extends CompositionLoader<InputStream> { | ||
private final Resources res; | ||
private final OnCompositionLoadedListener loadedListener; | ||
|
||
FileCompositionLoader(Resources res, OnCompositionLoadedListener loadedListener) { | ||
this.res = res; | ||
this.loadedListener = loadedListener; | ||
} | ||
|
||
@Override protected LottieComposition doInBackground(InputStream... params) { | ||
return LottieComposition.Factory.fromInputStream(res, params[0]); | ||
} | ||
|
||
@Override protected void onPostExecute(LottieComposition composition) { | ||
loadedListener.onCompositionLoaded(composition); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
lottie/src/main/java/com/airbnb/lottie/JsonCompositionLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.airbnb.lottie; | ||
|
||
import android.content.res.Resources; | ||
|
||
import org.json.JSONObject; | ||
|
||
final class JsonCompositionLoader extends CompositionLoader<JSONObject> { | ||
private final Resources res; | ||
private final OnCompositionLoadedListener loadedListener; | ||
|
||
JsonCompositionLoader(Resources res, OnCompositionLoadedListener loadedListener) { | ||
this.res = res; | ||
this.loadedListener = loadedListener; | ||
} | ||
|
||
@Override protected LottieComposition doInBackground(JSONObject... params) { | ||
return LottieComposition.Factory.fromJsonSync(res, params[0]); | ||
} | ||
|
||
@Override protected void onPostExecute(LottieComposition composition) { | ||
loadedListener.onCompositionLoaded(composition); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.