From 6e2a181bd2f0ba7271521e4d5e72727756542ebc Mon Sep 17 00:00:00 2001 From: Jorge Betancourt Date: Mon, 1 Jul 2024 11:20:39 -0400 Subject: [PATCH] reduce scope of flag API components --- .../airbnb/lottie/compose/LottieAnimation.kt | 4 ++-- .../airbnb/lottie/LottieAnimationView.java | 8 +++---- .../com/airbnb/lottie/LottieDrawable.java | 12 +++++----- .../com/airbnb/lottie/LottieFeatureFlag.java | 18 +++++++++++++++ .../com/airbnb/lottie/LottieFeatureFlags.java | 22 ++++--------------- .../lottie/model/content/MergePaths.java | 4 ++-- 6 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 lottie/src/main/java/com/airbnb/lottie/LottieFeatureFlag.java diff --git a/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimation.kt b/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimation.kt index c6053d4797..4fd1b8284c 100644 --- a/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimation.kt +++ b/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimation.kt @@ -21,7 +21,7 @@ import androidx.compose.ui.unit.IntSize import com.airbnb.lottie.AsyncUpdates import com.airbnb.lottie.LottieComposition import com.airbnb.lottie.LottieDrawable -import com.airbnb.lottie.LottieFeatureFlags +import com.airbnb.lottie.LottieFeatureFlag import com.airbnb.lottie.RenderMode import kotlin.math.roundToInt @@ -115,7 +115,7 @@ fun LottieAnimation( matrix.preTranslate(translation.x.toFloat(), translation.y.toFloat()) matrix.preScale(scale.scaleX, scale.scaleY) - drawable.enableFeatureFlag(LottieFeatureFlags.FeatureFlag.MergePathsApi19, enableMergePaths) + drawable.enableFeatureFlag(LottieFeatureFlag.MergePathsApi19, enableMergePaths) drawable.setSafeMode(safeMode) drawable.renderMode = renderMode drawable.asyncUpdates = asyncUpdates diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java index ce87606430..3f5a5c781d 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java @@ -403,21 +403,21 @@ public void setUseCompositionFrameRate(boolean useCompositionFrameRate) { * instead of using merge paths. */ public void enableMergePathsForKitKatAndAbove(boolean enable) { - lottieDrawable.enableFeatureFlag(LottieFeatureFlags.FeatureFlag.MergePathsApi19, enable); + lottieDrawable.enableFeatureFlag(LottieFeatureFlag.MergePathsApi19, enable); } /** * Returns whether merge paths are enabled for KitKat and above. */ public boolean isMergePathsEnabledForKitKatAndAbove() { - return lottieDrawable.isFeatureFlagEnabled(LottieFeatureFlags.FeatureFlag.MergePathsApi19); + return lottieDrawable.isFeatureFlagEnabled(LottieFeatureFlag.MergePathsApi19); } - public void enableFeatureFlag(LottieFeatureFlags.FeatureFlag flag, boolean enable) { + public void enableFeatureFlag(LottieFeatureFlag flag, boolean enable) { lottieDrawable.enableFeatureFlag(flag, enable); } - public boolean isFeatureFlagEnabled(LottieFeatureFlags.FeatureFlag flag) { + public boolean isFeatureFlagEnabled(LottieFeatureFlag flag) { return lottieDrawable.isFeatureFlagEnabled(flag); } diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java index f61bdd1779..dfcae27c7b 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java @@ -287,7 +287,7 @@ public boolean hasMatte() { @Deprecated public boolean enableMergePathsForKitKatAndAbove() { - return lottieFeatureFlags.isFlagEnabled(LottieFeatureFlags.FeatureFlag.MergePathsApi19); + return lottieFeatureFlags.isFlagEnabled(LottieFeatureFlag.MergePathsApi19); } /** @@ -300,18 +300,18 @@ public boolean enableMergePathsForKitKatAndAbove() { */ @Deprecated public void enableMergePathsForKitKatAndAbove(boolean enable) { - boolean changed = lottieFeatureFlags.enableFlag(LottieFeatureFlags.FeatureFlag.MergePathsApi19, enable); + boolean changed = lottieFeatureFlags.enableFlag(LottieFeatureFlag.MergePathsApi19, enable); if (composition != null && changed) { buildCompositionLayer(); } } /** - * @deprecated Replaced by {@link #enableFeatureFlag(LottieFeatureFlags.FeatureFlag, boolean)} + * @deprecated Replaced by {@link #enableFeatureFlag(LottieFeatureFlag, boolean)} */ @Deprecated public boolean isMergePathsEnabledForKitKatAndAbove() { - return lottieFeatureFlags.isFlagEnabled(LottieFeatureFlags.FeatureFlag.MergePathsApi19); + return lottieFeatureFlags.isFlagEnabled(LottieFeatureFlag.MergePathsApi19); } /** @@ -321,14 +321,14 @@ public boolean isMergePathsEnabledForKitKatAndAbove() { * Please ensure that the animation supported by the enabled feature looks acceptable across all * targeted API levels. */ - public void enableFeatureFlag(LottieFeatureFlags.FeatureFlag flag, boolean enable) { + public void enableFeatureFlag(LottieFeatureFlag flag, boolean enable) { boolean changed = lottieFeatureFlags.enableFlag(flag, enable); if (composition != null && changed) { buildCompositionLayer(); } } - public boolean isFeatureFlagEnabled(LottieFeatureFlags.FeatureFlag flag) { + public boolean isFeatureFlagEnabled(LottieFeatureFlag flag) { return lottieFeatureFlags.isFlagEnabled(flag); } diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieFeatureFlag.java b/lottie/src/main/java/com/airbnb/lottie/LottieFeatureFlag.java new file mode 100644 index 0000000000..228e199882 --- /dev/null +++ b/lottie/src/main/java/com/airbnb/lottie/LottieFeatureFlag.java @@ -0,0 +1,18 @@ +package com.airbnb.lottie; + +import android.os.Build; + +public enum LottieFeatureFlag { + /** + * Merge paths currently don't work if the the operand shape is entirely contained within the + * first shape. If you need to cut out one shape from another shape, use an even-odd fill type + * instead of using merge paths. + */ + MergePathsApi19(Build.VERSION_CODES.KITKAT); + + public final int minRequiredSdkVersion; + + LottieFeatureFlag(int minRequiredSdkVersion) { + this.minRequiredSdkVersion = minRequiredSdkVersion; + } +} diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieFeatureFlags.java b/lottie/src/main/java/com/airbnb/lottie/LottieFeatureFlags.java index 165dc3864b..7e7560a81c 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieFeatureFlags.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieFeatureFlags.java @@ -7,29 +7,15 @@ import java.util.HashSet; -public class LottieFeatureFlags { - public enum FeatureFlag { - /** - * Merge paths currently don't work if the the operand shape is entirely contained within the - * first shape. If you need to cut out one shape from another shape, use an even-odd fill type - * instead of using merge paths. - */ - MergePathsApi19(Build.VERSION_CODES.KITKAT); - - public final int minRequiredSdkVersion; - - FeatureFlag(int minRequiredSdkVersion) { - this.minRequiredSdkVersion = minRequiredSdkVersion; - } - } +class LottieFeatureFlags { - private final HashSet enabledFlags = new HashSet<>(); + private final HashSet enabledFlags = new HashSet<>(); /** * Returns true if the flag was changed. */ @SuppressLint("DefaultLocale") - public boolean enableFlag(FeatureFlag flag, boolean enable) { + public boolean enableFlag(LottieFeatureFlag flag, boolean enable) { if (enable) { if (Build.VERSION.SDK_INT < flag.minRequiredSdkVersion) { Logger.warning(String.format("%s is not supported pre SDK %d", flag.name(), flag.minRequiredSdkVersion)); @@ -41,7 +27,7 @@ public boolean enableFlag(FeatureFlag flag, boolean enable) { } } - public boolean isFlagEnabled(FeatureFlag flag) { + public boolean isFlagEnabled(LottieFeatureFlag flag) { return enabledFlags.contains(flag); } diff --git a/lottie/src/main/java/com/airbnb/lottie/model/content/MergePaths.java b/lottie/src/main/java/com/airbnb/lottie/model/content/MergePaths.java index da2bc89545..00ec362056 100644 --- a/lottie/src/main/java/com/airbnb/lottie/model/content/MergePaths.java +++ b/lottie/src/main/java/com/airbnb/lottie/model/content/MergePaths.java @@ -4,7 +4,7 @@ import com.airbnb.lottie.LottieComposition; import com.airbnb.lottie.LottieDrawable; -import com.airbnb.lottie.LottieFeatureFlags; +import com.airbnb.lottie.LottieFeatureFlag; import com.airbnb.lottie.animation.content.Content; import com.airbnb.lottie.animation.content.MergePathsContent; import com.airbnb.lottie.model.layer.BaseLayer; @@ -61,7 +61,7 @@ public boolean isHidden() { } @Override @Nullable public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) { - if (!drawable.isFeatureFlagEnabled(LottieFeatureFlags.FeatureFlag.MergePathsApi19)) { + if (!drawable.isFeatureFlagEnabled(LottieFeatureFlag.MergePathsApi19)) { Logger.warning("Animation contains merge paths but they are disabled."); return null; }