• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.airbnb.lottie.model.layer;
2 
3 import androidx.annotation.Nullable;
4 
5 import com.airbnb.lottie.LottieComposition;
6 import com.airbnb.lottie.model.animatable.AnimatableFloatValue;
7 import com.airbnb.lottie.model.animatable.AnimatableTextFrame;
8 import com.airbnb.lottie.model.animatable.AnimatableTextProperties;
9 import com.airbnb.lottie.model.animatable.AnimatableTransform;
10 import com.airbnb.lottie.model.content.BlurEffect;
11 import com.airbnb.lottie.model.content.ContentModel;
12 import com.airbnb.lottie.model.content.LBlendMode;
13 import com.airbnb.lottie.model.content.Mask;
14 import com.airbnb.lottie.parser.DropShadowEffect;
15 import com.airbnb.lottie.value.Keyframe;
16 
17 import java.util.List;
18 import java.util.Locale;
19 
20 public class Layer {
21 
22   public enum LayerType {
23     PRE_COMP,
24     SOLID,
25     IMAGE,
26     NULL,
27     SHAPE,
28     TEXT,
29     UNKNOWN
30   }
31 
32   public enum MatteType {
33     NONE,
34     ADD,
35     INVERT,
36     LUMA,
37     LUMA_INVERTED,
38     UNKNOWN
39   }
40 
41   private final List<ContentModel> shapes;
42   private final LottieComposition composition;
43   private final String layerName;
44   private final long layerId;
45   private final LayerType layerType;
46   private final long parentId;
47   @Nullable private final String refId;
48   private final List<Mask> masks;
49   private final AnimatableTransform transform;
50   private final int solidWidth;
51   private final int solidHeight;
52   private final int solidColor;
53   private final float timeStretch;
54   private final float startFrame;
55   private final float preCompWidth;
56   private final float preCompHeight;
57   @Nullable private final AnimatableTextFrame text;
58   @Nullable private final AnimatableTextProperties textProperties;
59   @Nullable private final AnimatableFloatValue timeRemapping;
60   private final List<Keyframe<Float>> inOutKeyframes;
61   private final MatteType matteType;
62   private final boolean hidden;
63   @Nullable private final BlurEffect blurEffect;
64   @Nullable private final DropShadowEffect dropShadowEffect;
65   private final LBlendMode blendMode;
66 
67 
Layer(List<ContentModel> shapes, LottieComposition composition, String layerName, long layerId, LayerType layerType, long parentId, @Nullable String refId, List<Mask> masks, AnimatableTransform transform, int solidWidth, int solidHeight, int solidColor, float timeStretch, float startFrame, float preCompWidth, float preCompHeight, @Nullable AnimatableTextFrame text, @Nullable AnimatableTextProperties textProperties, List<Keyframe<Float>> inOutKeyframes, MatteType matteType, @Nullable AnimatableFloatValue timeRemapping, boolean hidden, @Nullable BlurEffect blurEffect, @Nullable DropShadowEffect dropShadowEffect, LBlendMode blendMode)68   public Layer(List<ContentModel> shapes, LottieComposition composition, String layerName, long layerId,
69       LayerType layerType, long parentId, @Nullable String refId, List<Mask> masks,
70       AnimatableTransform transform, int solidWidth, int solidHeight, int solidColor,
71       float timeStretch, float startFrame, float preCompWidth, float preCompHeight,
72       @Nullable AnimatableTextFrame text, @Nullable AnimatableTextProperties textProperties,
73       List<Keyframe<Float>> inOutKeyframes, MatteType matteType,
74       @Nullable AnimatableFloatValue timeRemapping, boolean hidden, @Nullable BlurEffect blurEffect,
75       @Nullable DropShadowEffect dropShadowEffect, LBlendMode blendMode) {
76     this.shapes = shapes;
77     this.composition = composition;
78     this.layerName = layerName;
79     this.layerId = layerId;
80     this.layerType = layerType;
81     this.parentId = parentId;
82     this.refId = refId;
83     this.masks = masks;
84     this.transform = transform;
85     this.solidWidth = solidWidth;
86     this.solidHeight = solidHeight;
87     this.solidColor = solidColor;
88     this.timeStretch = timeStretch;
89     this.startFrame = startFrame;
90     this.preCompWidth = preCompWidth;
91     this.preCompHeight = preCompHeight;
92     this.text = text;
93     this.textProperties = textProperties;
94     this.inOutKeyframes = inOutKeyframes;
95     this.matteType = matteType;
96     this.timeRemapping = timeRemapping;
97     this.hidden = hidden;
98     this.blurEffect = blurEffect;
99     this.dropShadowEffect = dropShadowEffect;
100     this.blendMode = blendMode;
101   }
102 
getComposition()103   LottieComposition getComposition() {
104     return composition;
105   }
106 
getTimeStretch()107   float getTimeStretch() {
108     return timeStretch;
109   }
110 
getStartProgress()111   float getStartProgress() {
112     return startFrame / composition.getDurationFrames();
113   }
114 
getInOutKeyframes()115   List<Keyframe<Float>> getInOutKeyframes() {
116     return inOutKeyframes;
117   }
118 
getId()119   public long getId() {
120     return layerId;
121   }
122 
getName()123   public String getName() {
124     return layerName;
125   }
126 
getRefId()127   public @Nullable String getRefId() {
128     return refId;
129   }
130 
getPreCompWidth()131   float getPreCompWidth() {
132     return preCompWidth;
133   }
134 
getPreCompHeight()135   float getPreCompHeight() {
136     return preCompHeight;
137   }
138 
getMasks()139   List<Mask> getMasks() {
140     return masks;
141   }
142 
getLayerType()143   public LayerType getLayerType() {
144     return layerType;
145   }
146 
getMatteType()147   MatteType getMatteType() {
148     return matteType;
149   }
150 
getParentId()151   long getParentId() {
152     return parentId;
153   }
154 
getShapes()155   List<ContentModel> getShapes() {
156     return shapes;
157   }
158 
getTransform()159   AnimatableTransform getTransform() {
160     return transform;
161   }
162 
getSolidColor()163   int getSolidColor() {
164     return solidColor;
165   }
166 
getSolidHeight()167   int getSolidHeight() {
168     return solidHeight;
169   }
170 
getSolidWidth()171   int getSolidWidth() {
172     return solidWidth;
173   }
174 
getText()175   @Nullable AnimatableTextFrame getText() {
176     return text;
177   }
178 
getTextProperties()179   @Nullable AnimatableTextProperties getTextProperties() {
180     return textProperties;
181   }
182 
getTimeRemapping()183   @Nullable AnimatableFloatValue getTimeRemapping() {
184     return timeRemapping;
185   }
186 
toString()187   @Override public String toString() {
188     return toString("");
189   }
190 
isHidden()191   public boolean isHidden() {
192     return hidden;
193   }
194 
195   @Nullable
getBlendMode()196   public LBlendMode getBlendMode() {
197     return blendMode;
198   }
199 
getBlurEffect()200   @Nullable public BlurEffect getBlurEffect() {
201     return blurEffect;
202   }
203 
getDropShadowEffect()204   @Nullable public DropShadowEffect getDropShadowEffect() {
205     return dropShadowEffect;
206   }
207 
toString(String prefix)208   public String toString(String prefix) {
209     StringBuilder sb = new StringBuilder();
210     sb.append(prefix).append(getName()).append("\n");
211     Layer parent = composition.layerModelForId(getParentId());
212     if (parent != null) {
213       sb.append("\t\tParents: ").append(parent.getName());
214       parent = composition.layerModelForId(parent.getParentId());
215       while (parent != null) {
216         sb.append("->").append(parent.getName());
217         parent = composition.layerModelForId(parent.getParentId());
218       }
219       sb.append(prefix).append("\n");
220     }
221     if (!getMasks().isEmpty()) {
222       sb.append(prefix).append("\tMasks: ").append(getMasks().size()).append("\n");
223     }
224     if (getSolidWidth() != 0 && getSolidHeight() != 0) {
225       sb.append(prefix).append("\tBackground: ").append(String
226           .format(Locale.US, "%dx%d %X\n", getSolidWidth(), getSolidHeight(), getSolidColor()));
227     }
228     if (!shapes.isEmpty()) {
229       sb.append(prefix).append("\tShapes:\n");
230       for (Object shape : shapes) {
231         sb.append(prefix).append("\t\t").append(shape).append("\n");
232       }
233     }
234     return sb.toString();
235   }
236 }
237