Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into featureFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeta51 committed Jun 18, 2024
2 parents 2fd82b1 + 99b0683 commit db03fee
Show file tree
Hide file tree
Showing 25 changed files with 14,405 additions and 108 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 6.4.1
### Bugs Fixed
* Scale base64 encoded bitmaps ([#2501](https://github.com/airbnb/lottie-android/pull/2501))
* Prevent systrace strings from getting created when systrace is off ([#2493](https://github.com/airbnb/lottie-android/pull/2493))
* Allow missing end values for integer animations ([#2487](https://github.com/airbnb/lottie-android/pull/2487))
* Add an extra null check in BaseKeyframeAnimation ([#2486](https://github.com/airbnb/lottie-android/pull/2486))

# 6.4.0
### New Features
* Add support for reduced motion marker names ([#2451](https://github.com/airbnb/lottie-android/pull/2451))
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG_COMPOSE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 6.4.1
### New Features
* Add support for tgs files ([#2501](https://github.com/airbnb/lottie-android/pull/2501))

# 6.4.0
### New Features
* Add safe mode ([#2455](https://github.com/airbnb/lottie-android/pull/2455))
Expand Down
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Releasing
1. Change the version in top level `gradle.properties` to a non-SNAPSHOT verson.
2. Update the `CHANGELOG.md` for the impending release.
3. Update the `README.md` with the new version.
4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version)
4. `git commit -am "Prepare for release X.Y.Z"` (where X.Y.Z is the new version)
5. `./gradlew clean uploadArchives`.
6. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact.
7. `git tag -a X.Y.X -m "Version X.Y.Z"` (where X.Y.Z is the new version)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=6.4.1-SNAPSHOT
VERSION_NAME=6.4.2-SNAPSHOT
GROUP=com.airbnb.android

POM_DESCRIPTION=Lottie is an animation library that renders Adobe After Effects animations natively in realtime.
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ mockito-kotlin = "org.mockito:mockito-android:_"
mpandroidchart = "com.github.PhilJay:MPAndroidChart:_"
nullaway = "com.uber.nullaway:nullaway:_"
okhttp = "com.squareup.okhttp3:okhttp:_"
okhttp-tls = "com.squareup.okhttp3:okhttp-tls:_"
okio = "com.squareup.okio:okio:_"
profileinstaller = "androidx.profileinstaller:profileinstaller:_"
qrcodereaderview = "com.dlazaro66.qrcodereaderview:qrcodereaderview:_"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import java.io.FileInputStream
import java.io.IOException
import java.util.zip.GZIPInputStream
import java.util.zip.ZipInputStream
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
Expand Down Expand Up @@ -157,14 +158,19 @@ private fun lottieTask(
null
} else {
val fis = FileInputStream(spec.fileName)
val actualCacheKey = if (cacheKey == DefaultCacheKey) spec.fileName else cacheKey
when {
spec.fileName.endsWith("zip") -> LottieCompositionFactory.fromZipStream(
ZipInputStream(fis),
if (cacheKey == DefaultCacheKey) spec.fileName else cacheKey,
actualCacheKey,
)
spec.fileName.endsWith("tgs") -> LottieCompositionFactory.fromJsonInputStream(
GZIPInputStream(fis),
actualCacheKey,
)
else -> LottieCompositionFactory.fromJsonInputStream(
fis,
if (cacheKey == DefaultCacheKey) spec.fileName else cacheKey,
actualCacheKey,
)
}
}
Expand All @@ -181,8 +187,22 @@ private fun lottieTask(
LottieCompositionFactory.fromJsonString(spec.jsonString, jsonStringCacheKey)
}
is LottieCompositionSpec.ContentProvider -> {
val inputStream = context.contentResolver.openInputStream(spec.uri)
LottieCompositionFactory.fromJsonInputStream(inputStream, if (cacheKey == DefaultCacheKey) spec.uri.toString() else cacheKey)
val fis = context.contentResolver.openInputStream(spec.uri)
val actualCacheKey = if (cacheKey == DefaultCacheKey) spec.uri.toString() else cacheKey
when {
spec.uri.toString().endsWith("zip") -> LottieCompositionFactory.fromZipStream(
ZipInputStream(fis),
actualCacheKey,
)
spec.uri.toString().endsWith("tgs") -> LottieCompositionFactory.fromJsonInputStream(
GZIPInputStream(fis),
actualCacheKey,
)
else -> LottieCompositionFactory.fromJsonInputStream(
fis,
actualCacheKey,
)
}
}
}
}
Expand Down Expand Up @@ -310,4 +330,4 @@ private fun String.ensureLeadingPeriod(): String = when {
isBlank() -> this
startsWith(".") -> this
else -> ".$this"
}
}
2 changes: 1 addition & 1 deletion lottie/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ baselineProfile {
}

dependencies {
implementation libs.androidx.appcompat
api libs.androidx.appcompat
// Do not upgrade to 2.0 because it will bring in Kotlin as a transitive dependency.
//noinspection GradleDependency
implementation libs.okio
Expand Down
4 changes: 4 additions & 0 deletions lottie/src/main/java/com/airbnb/lottie/L.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public static void setTraceEnabled(boolean enabled) {
}
}

public static boolean isTraceEnabled(){
return traceEnabled;
}

public static void setNetworkCacheEnabled(boolean enabled) {
networkCacheEnabled = enabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,9 @@ private static LottieResult<LottieComposition> fromZipStreamSyncInternal(Context
Logger.warning("data URL did not have correct base64 format.", e);
return null;
}
asset.setBitmap(BitmapFactory.decodeByteArray(data, 0, data.length, opts));
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, opts);
bitmap = Utils.resizeBitmapIfNeeded(bitmap, asset.getWidth(), asset.getHeight());
asset.setBitmap(bitmap);
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,9 @@ public void draw(@NonNull Canvas canvas) {
if (asyncUpdatesEnabled) {
setProgressDrawLock.acquire();
}
L.beginSection("Drawable#draw");
if (L.isTraceEnabled()) {
L.beginSection("Drawable#draw");
}

if (asyncUpdatesEnabled && shouldSetProgressBeforeDrawing()) {
setProgress(animator.getAnimatedValueAbsolute());
Expand Down Expand Up @@ -720,7 +722,9 @@ public void draw(@NonNull Canvas canvas) {
} catch (InterruptedException e) {
// Do nothing.
} finally {
L.endSection("Drawable#draw");
if (L.isTraceEnabled()) {
L.endSection("Drawable#draw");
}
if (asyncUpdatesEnabled) {
setProgressDrawLock.release();
if (compositionLayer.getProgress() != animator.getAnimatedValueAbsolute()) {
Expand Down Expand Up @@ -1142,9 +1146,13 @@ public void setProgress(@FloatRange(from = 0f, to = 1f) final float progress) {
lazyCompositionTasks.add(c -> setProgress(progress));
return;
}
L.beginSection("Drawable#setProgress");
if (L.isTraceEnabled()) {
L.beginSection("Drawable#setProgress");
}
animator.setFrame(composition.getFrameForProgress(progress));
L.endSection("Drawable#setProgress");
if (L.isTraceEnabled()) {
L.endSection("Drawable#setProgress");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,23 @@ public abstract class BaseStrokeContent
}

@Override public void draw(Canvas canvas, Matrix parentMatrix, int parentAlpha) {
L.beginSection("StrokeContent#draw");
if (L.isTraceEnabled()) {
L.beginSection("StrokeContent#draw");
}
if (Utils.hasZeroScaleAxis(parentMatrix)) {
L.endSection("StrokeContent#draw");
if (L.isTraceEnabled()) {
L.endSection("StrokeContent#draw");
}
return;
}
int alpha = (int) ((parentAlpha / 255f * ((IntegerKeyframeAnimation) opacityAnimation).getIntValue() / 100f) * 255);
paint.setAlpha(clamp(alpha, 0, 255));
paint.setStrokeWidth(((FloatKeyframeAnimation) widthAnimation).getFloatValue() * Utils.getScale(parentMatrix));
if (paint.getStrokeWidth() <= 0) {
// Android draws a hairline stroke for 0, After Effects doesn't.
L.endSection("StrokeContent#draw");
if (L.isTraceEnabled()) {
L.endSection("StrokeContent#draw");
}
return;
}
applyDashPatternIfNeeded(parentMatrix);
Expand Down Expand Up @@ -195,24 +201,36 @@ public abstract class BaseStrokeContent
if (pathGroup.trimPath != null) {
applyTrimPath(canvas, pathGroup, parentMatrix);
} else {
L.beginSection("StrokeContent#buildPath");
if (L.isTraceEnabled()) {
L.beginSection("StrokeContent#buildPath");
}
path.reset();
for (int j = pathGroup.paths.size() - 1; j >= 0; j--) {
path.addPath(pathGroup.paths.get(j).getPath(), parentMatrix);
}
L.endSection("StrokeContent#buildPath");
L.beginSection("StrokeContent#drawPath");
if (L.isTraceEnabled()) {
L.endSection("StrokeContent#buildPath");
L.beginSection("StrokeContent#drawPath");
}
canvas.drawPath(path, paint);
L.endSection("StrokeContent#drawPath");
if (L.isTraceEnabled()) {
L.endSection("StrokeContent#drawPath");
}
}
}
L.endSection("StrokeContent#draw");
if (L.isTraceEnabled()) {
L.endSection("StrokeContent#draw");
}
}

private void applyTrimPath(Canvas canvas, PathGroup pathGroup, Matrix parentMatrix) {
L.beginSection("StrokeContent#applyTrimPath");
if (L.isTraceEnabled()) {
L.beginSection("StrokeContent#applyTrimPath");
}
if (pathGroup.trimPath == null) {
L.endSection("StrokeContent#applyTrimPath");
if (L.isTraceEnabled()) {
L.endSection("StrokeContent#applyTrimPath");
}
return;
}
path.reset();
Expand All @@ -226,7 +244,9 @@ private void applyTrimPath(Canvas canvas, PathGroup pathGroup, Matrix parentMatr
// If the start-end is ~100, consider it to be the full path.
if (animStartValue < 0.01f && animEndValue > 0.99f) {
canvas.drawPath(path, paint);
L.endSection("StrokeContent#applyTrimPath");
if (L.isTraceEnabled()) {
L.endSection("StrokeContent#applyTrimPath");
}
return;
}

Expand Down Expand Up @@ -282,11 +302,15 @@ private void applyTrimPath(Canvas canvas, PathGroup pathGroup, Matrix parentMatr
}
currentLength += length;
}
L.endSection("StrokeContent#applyTrimPath");
if (L.isTraceEnabled()) {
L.endSection("StrokeContent#applyTrimPath");
}
}

@Override public void getBounds(RectF outBounds, Matrix parentMatrix, boolean applyParents) {
L.beginSection("StrokeContent#getBounds");
if (L.isTraceEnabled()) {
L.beginSection("StrokeContent#getBounds");
}
path.reset();
for (int i = 0; i < pathGroups.size(); i++) {
PathGroup pathGroup = pathGroups.get(i);
Expand All @@ -307,13 +331,19 @@ private void applyTrimPath(Canvas canvas, PathGroup pathGroup, Matrix parentMatr
outBounds.right + 1,
outBounds.bottom + 1
);
L.endSection("StrokeContent#getBounds");
if (L.isTraceEnabled()) {
L.endSection("StrokeContent#getBounds");
}
}

private void applyDashPatternIfNeeded(Matrix parentMatrix) {
L.beginSection("StrokeContent#applyDashPattern");
if (L.isTraceEnabled()) {
L.beginSection("StrokeContent#applyDashPattern");
}
if (dashPatternAnimations.isEmpty()) {
L.endSection("StrokeContent#applyDashPattern");
if (L.isTraceEnabled()) {
L.endSection("StrokeContent#applyDashPattern");
}
return;
}

Expand All @@ -337,7 +367,9 @@ private void applyDashPatternIfNeeded(Matrix parentMatrix) {
}
float offset = dashPatternOffsetAnimation == null ? 0f : dashPatternOffsetAnimation.getValue() * scale;
paint.setPathEffect(new DashPathEffect(dashPatternValues, offset));
L.endSection("StrokeContent#applyDashPattern");
if (L.isTraceEnabled()) {
L.endSection("StrokeContent#applyDashPattern");
}
}

@Override public void resolveKeyPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public FillContent(final LottieDrawable lottieDrawable, BaseLayer layer, ShapeFi
if (hidden) {
return;
}
L.beginSection("FillContent#draw");
if (L.isTraceEnabled()) {
L.beginSection("FillContent#draw");
}
int color = ((ColorKeyframeAnimation) this.colorAnimation).getIntValue();
int alpha = (int) ((parentAlpha / 255f * opacityAnimation.getValue() / 100f) * 255);
paint.setColor((clamp(alpha, 0, 255) << 24) | (color & 0xFFFFFF));
Expand Down Expand Up @@ -131,7 +133,9 @@ public FillContent(final LottieDrawable lottieDrawable, BaseLayer layer, ShapeFi

canvas.drawPath(path, paint);

L.endSection("FillContent#draw");
if (L.isTraceEnabled()) {
L.endSection("FillContent#draw");
}
}

@Override public void getBounds(RectF outBounds, Matrix parentMatrix, boolean applyParents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public GradientFillContent(final LottieDrawable lottieDrawable, LottieCompositio
if (hidden) {
return;
}
L.beginSection("GradientFillContent#draw");
if (L.isTraceEnabled()) {
L.beginSection("GradientFillContent#draw");
}
path.reset();
for (int i = 0; i < paths.size(); i++) {
path.addPath(paths.get(i).getPath(), parentMatrix);
Expand Down Expand Up @@ -156,7 +158,9 @@ public GradientFillContent(final LottieDrawable lottieDrawable, LottieCompositio
paint.setAlpha(clamp(alpha, 0, 255));

canvas.drawPath(path, paint);
L.endSection("GradientFillContent#draw");
if (L.isTraceEnabled()) {
L.endSection("GradientFillContent#draw");
}
}

@Override public void getBounds(RectF outBounds, Matrix parentMatrix, boolean applyParents) {
Expand Down
Loading

0 comments on commit db03fee

Please sign in to comment.