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