Skip to content

Commit 741eb01

Browse files
committed
feat: add 2.x proto support for matte.
1 parent 3f06512 commit 741eb01

File tree

10 files changed

+47
-18
lines changed

10 files changed

+47
-18
lines changed

app/src/main/assets/matteRect.svga

623 Bytes
Binary file not shown.

app/src/main/java/com/example/ponycui_home/svgaplayer/AnimationFromAssetsActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void onClick(View view) {
3737

3838
private void loadAnimation() {
3939
SVGAParser parser = new SVGAParser(this);
40-
parser.decodeFromAssets(this.randomSample(), new SVGAParser.ParseCompletion() {
40+
parser.decodeFromAssets("matteRect.svga", new SVGAParser.ParseCompletion() {
4141
@Override
4242
public void onComplete(@NotNull SVGAVideoEntity videoItem) {
4343
animationView.setVideoItem(videoItem);

library/src/main/java/com/opensource/svgaplayer/entities/SVGAVideoSpriteEntity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import org.json.JSONObject
88
*/
99
internal class SVGAVideoSpriteEntity {
1010

11-
val matteKey: String?
12-
1311
val imageKey: String?
1412

13+
val matteKey: String?
14+
1515
val frames: List<SVGAVideoSpriteFrameEntity>
1616

1717
constructor(obj: JSONObject) {
18-
this.matteKey = obj.optString("matteKey")
1918
this.imageKey = obj.optString("imageKey")
19+
this.matteKey = obj.optString("matteKey")
2020
val mutableFrames: MutableList<SVGAVideoSpriteFrameEntity> = mutableListOf()
2121
obj.optJSONArray("frames")?.let {
2222
for (i in 0 until it.length()) {
@@ -37,8 +37,8 @@ internal class SVGAVideoSpriteEntity {
3737
}
3838

3939
constructor(obj: SpriteEntity) {
40-
this.matteKey = obj.imageKey
4140
this.imageKey = obj.imageKey
41+
this.matteKey = obj.matteKey
4242
var lastFrame: SVGAVideoSpriteFrameEntity? = null
4343
frames = obj.frames?.map {
4444
val frameItem = SVGAVideoSpriteFrameEntity(it)

library/src/main/java/com/opensource/svgaplayer/proto/AudioEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Code generated by Wire protocol buffer compiler, do not edit.
2-
// Source file: svga.proto at 18:1
2+
// Source file: svga.proto at 19:1
33
package com.opensource.svgaplayer.proto;
44

55
import com.squareup.wire.FieldEncoding;

library/src/main/java/com/opensource/svgaplayer/proto/FrameEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Code generated by Wire protocol buffer compiler, do not edit.
2-
// Source file: svga.proto at 114:1
2+
// Source file: svga.proto at 115:1
33
package com.opensource.svgaplayer.proto;
44

55
import com.squareup.wire.FieldEncoding;

library/src/main/java/com/opensource/svgaplayer/proto/Layout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Code generated by Wire protocol buffer compiler, do not edit.
2-
// Source file: svga.proto at 26:1
2+
// Source file: svga.proto at 27:1
33
package com.opensource.svgaplayer.proto;
44

55
import com.squareup.wire.FieldEncoding;

library/src/main/java/com/opensource/svgaplayer/proto/MovieEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Code generated by Wire protocol buffer compiler, do not edit.
2-
// Source file: svga.proto at 122:1
2+
// Source file: svga.proto at 123:1
33
package com.opensource.svgaplayer.proto;
44

55
import com.squareup.wire.FieldEncoding;

library/src/main/java/com/opensource/svgaplayer/proto/ShapeEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Code generated by Wire protocol buffer compiler, do not edit.
2-
// Source file: svga.proto at 42:1
2+
// Source file: svga.proto at 43:1
33
package com.opensource.svgaplayer.proto;
44

55
import com.squareup.wire.FieldEncoding;

library/src/main/java/com/opensource/svgaplayer/proto/SpriteEntity.java

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ public final class SpriteEntity extends Message<SpriteEntity, SpriteEntity.Build
2424

2525
public static final String DEFAULT_IMAGEKEY = "";
2626

27+
public static final String DEFAULT_MATTEKEY = "";
28+
2729
/**
28-
* 元件所对应的位图键名, 如果 imageKey 含有 .vector 后缀,该 sprite 为矢量图层。
30+
* 元件所对应的位图键名, 如果 imageKey 含有 .vector 后缀,该 sprite 为矢量图层 含有 .matte 后缀,该 sprite 为遮罩图层
2931
*/
3032
@WireField(
3133
tag = 1,
@@ -43,21 +45,32 @@ public final class SpriteEntity extends Message<SpriteEntity, SpriteEntity.Build
4345
)
4446
public final List<FrameEntity> frames;
4547

46-
public SpriteEntity(String imageKey, List<FrameEntity> frames) {
47-
this(imageKey, frames, ByteString.EMPTY);
48+
/**
49+
* 被遮罩图层的 matteKey 对应的是其遮罩图层的 imageKey.
50+
*/
51+
@WireField(
52+
tag = 3,
53+
adapter = "com.squareup.wire.ProtoAdapter#STRING"
54+
)
55+
public final String matteKey;
56+
57+
public SpriteEntity(String imageKey, List<FrameEntity> frames, String matteKey) {
58+
this(imageKey, frames, matteKey, ByteString.EMPTY);
4859
}
4960

50-
public SpriteEntity(String imageKey, List<FrameEntity> frames, ByteString unknownFields) {
61+
public SpriteEntity(String imageKey, List<FrameEntity> frames, String matteKey, ByteString unknownFields) {
5162
super(ADAPTER, unknownFields);
5263
this.imageKey = imageKey;
5364
this.frames = Internal.immutableCopyOf("frames", frames);
65+
this.matteKey = matteKey;
5466
}
5567

5668
@Override
5769
public Builder newBuilder() {
5870
Builder builder = new Builder();
5971
builder.imageKey = imageKey;
6072
builder.frames = Internal.copyOf("frames", frames);
73+
builder.matteKey = matteKey;
6174
builder.addUnknownFields(unknownFields());
6275
return builder;
6376
}
@@ -69,7 +82,8 @@ public boolean equals(Object other) {
6982
SpriteEntity o = (SpriteEntity) other;
7083
return unknownFields().equals(o.unknownFields())
7184
&& Internal.equals(imageKey, o.imageKey)
72-
&& frames.equals(o.frames);
85+
&& frames.equals(o.frames)
86+
&& Internal.equals(matteKey, o.matteKey);
7387
}
7488

7589
@Override
@@ -79,6 +93,7 @@ public int hashCode() {
7993
result = unknownFields().hashCode();
8094
result = result * 37 + (imageKey != null ? imageKey.hashCode() : 0);
8195
result = result * 37 + frames.hashCode();
96+
result = result * 37 + (matteKey != null ? matteKey.hashCode() : 0);
8297
super.hashCode = result;
8398
}
8499
return result;
@@ -89,6 +104,7 @@ public String toString() {
89104
StringBuilder builder = new StringBuilder();
90105
if (imageKey != null) builder.append(", imageKey=").append(imageKey);
91106
if (!frames.isEmpty()) builder.append(", frames=").append(frames);
107+
if (matteKey != null) builder.append(", matteKey=").append(matteKey);
92108
return builder.replace(0, 2, "SpriteEntity{").append('}').toString();
93109
}
94110

@@ -97,12 +113,14 @@ public static final class Builder extends Message.Builder<SpriteEntity, Builder>
97113

98114
public List<FrameEntity> frames;
99115

116+
public String matteKey;
117+
100118
public Builder() {
101119
frames = Internal.newMutableList();
102120
}
103121

104122
/**
105-
* 元件所对应的位图键名, 如果 imageKey 含有 .vector 后缀,该 sprite 为矢量图层。
123+
* 元件所对应的位图键名, 如果 imageKey 含有 .vector 后缀,该 sprite 为矢量图层 含有 .matte 后缀,该 sprite 为遮罩图层
106124
*/
107125
public Builder imageKey(String imageKey) {
108126
this.imageKey = imageKey;
@@ -118,9 +136,17 @@ public Builder frames(List<FrameEntity> frames) {
118136
return this;
119137
}
120138

139+
/**
140+
* 被遮罩图层的 matteKey 对应的是其遮罩图层的 imageKey.
141+
*/
142+
public Builder matteKey(String matteKey) {
143+
this.matteKey = matteKey;
144+
return this;
145+
}
146+
121147
@Override
122148
public SpriteEntity build() {
123-
return new SpriteEntity(imageKey, frames, super.buildUnknownFields());
149+
return new SpriteEntity(imageKey, frames, matteKey, super.buildUnknownFields());
124150
}
125151
}
126152

@@ -133,13 +159,15 @@ private static final class ProtoAdapter_SpriteEntity extends ProtoAdapter<Sprite
133159
public int encodedSize(SpriteEntity value) {
134160
return (value.imageKey != null ? ProtoAdapter.STRING.encodedSizeWithTag(1, value.imageKey) : 0)
135161
+ FrameEntity.ADAPTER.asRepeated().encodedSizeWithTag(2, value.frames)
162+
+ (value.matteKey != null ? ProtoAdapter.STRING.encodedSizeWithTag(3, value.matteKey) : 0)
136163
+ value.unknownFields().size();
137164
}
138165

139166
@Override
140167
public void encode(ProtoWriter writer, SpriteEntity value) throws IOException {
141168
if (value.imageKey != null) ProtoAdapter.STRING.encodeWithTag(writer, 1, value.imageKey);
142169
FrameEntity.ADAPTER.asRepeated().encodeWithTag(writer, 2, value.frames);
170+
if (value.matteKey != null) ProtoAdapter.STRING.encodeWithTag(writer, 3, value.matteKey);
143171
writer.writeBytes(value.unknownFields());
144172
}
145173

@@ -151,6 +179,7 @@ public SpriteEntity decode(ProtoReader reader) throws IOException {
151179
switch (tag) {
152180
case 1: builder.imageKey(ProtoAdapter.STRING.decode(reader)); break;
153181
case 2: builder.frames.add(FrameEntity.ADAPTER.decode(reader)); break;
182+
case 3: builder.matteKey(ProtoAdapter.STRING.decode(reader)); break;
154183
default: {
155184
FieldEncoding fieldEncoding = reader.peekFieldEncoding();
156185
Object value = fieldEncoding.rawProtoAdapter().decode(reader);

library/src/main/java/com/opensource/svgaplayer/proto/Transform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Code generated by Wire protocol buffer compiler, do not edit.
2-
// Source file: svga.proto at 33:1
2+
// Source file: svga.proto at 34:1
33
package com.opensource.svgaplayer.proto;
44

55
import com.squareup.wire.FieldEncoding;

0 commit comments

Comments
 (0)