/
L.java
146 lines (120 loc) · 4.07 KB
/
L.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.airbnb.lottie;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import com.airbnb.lottie.network.DefaultLottieNetworkFetcher;
import com.airbnb.lottie.network.LottieNetworkCacheProvider;
import com.airbnb.lottie.network.LottieNetworkFetcher;
import com.airbnb.lottie.network.NetworkCache;
import com.airbnb.lottie.network.NetworkFetcher;
import com.airbnb.lottie.utils.LottieTrace;
import java.io.File;
@RestrictTo(RestrictTo.Scope.LIBRARY)
public class L {
public static boolean DBG = false;
public static final String TAG = "LOTTIE";
private static boolean traceEnabled = false;
private static boolean networkCacheEnabled = true;
private static boolean disablePathInterpolatorCache = true;
private static AsyncUpdates defaultAsyncUpdates = AsyncUpdates.AUTOMATIC;
private static LottieNetworkFetcher fetcher;
private static LottieNetworkCacheProvider cacheProvider;
private static volatile NetworkFetcher networkFetcher;
private static volatile NetworkCache networkCache;
private static ThreadLocal<LottieTrace> lottieTrace;
private L() {
}
public static void setTraceEnabled(boolean enabled) {
if (traceEnabled == enabled) {
return;
}
traceEnabled = enabled;
if (traceEnabled && lottieTrace == null) {
lottieTrace = new ThreadLocal<>();
}
}
public static boolean isTraceEnabled(){
return traceEnabled;
}
public static void setNetworkCacheEnabled(boolean enabled) {
networkCacheEnabled = enabled;
}
public static void beginSection(String section) {
if (!traceEnabled) {
return;
}
getTrace().beginSection(section);
}
public static float endSection(String section) {
if (!traceEnabled) {
return 0;
}
return getTrace().endSection(section);
}
private static LottieTrace getTrace() {
LottieTrace trace = lottieTrace.get();
if (trace == null) {
trace = new LottieTrace();
lottieTrace.set(trace);
}
return trace;
}
public static void setFetcher(LottieNetworkFetcher customFetcher) {
if ((fetcher == null && customFetcher == null) || (fetcher != null && fetcher.equals(customFetcher))) {
return;
}
fetcher = customFetcher;
networkFetcher = null;
}
public static void setCacheProvider(LottieNetworkCacheProvider customProvider) {
if ((cacheProvider == null && customProvider == null) || (cacheProvider != null && cacheProvider.equals(customProvider))) {
return;
}
cacheProvider = customProvider;
networkCache = null;
}
@NonNull
public static NetworkFetcher networkFetcher(@NonNull Context context) {
NetworkFetcher local = networkFetcher;
if (local == null) {
synchronized (NetworkFetcher.class) {
local = networkFetcher;
if (local == null) {
networkFetcher = local = new NetworkFetcher(networkCache(context), fetcher != null ? fetcher : new DefaultLottieNetworkFetcher());
}
}
}
return local;
}
@Nullable
public static NetworkCache networkCache(@NonNull final Context context) {
if (!networkCacheEnabled) {
return null;
}
final Context appContext = context.getApplicationContext();
NetworkCache local = networkCache;
if (local == null) {
synchronized (NetworkCache.class) {
local = networkCache;
if (local == null) {
networkCache = local = new NetworkCache(cacheProvider != null ? cacheProvider :
() -> new File(appContext.getCacheDir(), "lottie_network_cache"));
}
}
}
return local;
}
public static void setDisablePathInterpolatorCache(boolean disablePathInterpolatorCache) {
L.disablePathInterpolatorCache = disablePathInterpolatorCache;
}
public static boolean getDisablePathInterpolatorCache() {
return disablePathInterpolatorCache;
}
public static void setDefaultAsyncUpdates(AsyncUpdates asyncUpdates) {
L.defaultAsyncUpdates = asyncUpdates;
}
public static AsyncUpdates getDefaultAsyncUpdates() {
return L.defaultAsyncUpdates;
}
}