Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
feat: add 2.x proto support for matte.
Browse files Browse the repository at this point in the history
  • Loading branch information
errnull committed Jun 17, 2019
1 parent 3f06512 commit 741eb01
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 18 deletions.
Binary file added app/src/main/assets/matteRect.svga
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void onClick(View view) {

private void loadAnimation() {
SVGAParser parser = new SVGAParser(this);
parser.decodeFromAssets(this.randomSample(), new SVGAParser.ParseCompletion() {
parser.decodeFromAssets("matteRect.svga", new SVGAParser.ParseCompletion() {
@Override
public void onComplete(@NotNull SVGAVideoEntity videoItem) {
animationView.setVideoItem(videoItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import org.json.JSONObject
*/
internal class SVGAVideoSpriteEntity {

val matteKey: String?

val imageKey: String?

val matteKey: String?

val frames: List<SVGAVideoSpriteFrameEntity>

constructor(obj: JSONObject) {
this.matteKey = obj.optString("matteKey")
this.imageKey = obj.optString("imageKey")
this.matteKey = obj.optString("matteKey")
val mutableFrames: MutableList<SVGAVideoSpriteFrameEntity> = mutableListOf()
obj.optJSONArray("frames")?.let {
for (i in 0 until it.length()) {
Expand All @@ -37,8 +37,8 @@ internal class SVGAVideoSpriteEntity {
}

constructor(obj: SpriteEntity) {
this.matteKey = obj.imageKey
this.imageKey = obj.imageKey
this.matteKey = obj.matteKey
var lastFrame: SVGAVideoSpriteFrameEntity? = null
frames = obj.frames?.map {
val frameItem = SVGAVideoSpriteFrameEntity(it)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Code generated by Wire protocol buffer compiler, do not edit.
// Source file: svga.proto at 18:1
// Source file: svga.proto at 19:1
package com.opensource.svgaplayer.proto;

import com.squareup.wire.FieldEncoding;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Code generated by Wire protocol buffer compiler, do not edit.
// Source file: svga.proto at 114:1
// Source file: svga.proto at 115:1
package com.opensource.svgaplayer.proto;

import com.squareup.wire.FieldEncoding;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Code generated by Wire protocol buffer compiler, do not edit.
// Source file: svga.proto at 26:1
// Source file: svga.proto at 27:1
package com.opensource.svgaplayer.proto;

import com.squareup.wire.FieldEncoding;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Code generated by Wire protocol buffer compiler, do not edit.
// Source file: svga.proto at 122:1
// Source file: svga.proto at 123:1
package com.opensource.svgaplayer.proto;

import com.squareup.wire.FieldEncoding;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Code generated by Wire protocol buffer compiler, do not edit.
// Source file: svga.proto at 42:1
// Source file: svga.proto at 43:1
package com.opensource.svgaplayer.proto;

import com.squareup.wire.FieldEncoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public final class SpriteEntity extends Message<SpriteEntity, SpriteEntity.Build

public static final String DEFAULT_IMAGEKEY = "";

public static final String DEFAULT_MATTEKEY = "";

/**
* 元件所对应的位图键名, 如果 imageKey 含有 .vector 后缀,该 sprite 为矢量图层。
* 元件所对应的位图键名, 如果 imageKey 含有 .vector 后缀,该 sprite 为矢量图层 含有 .matte 后缀,该 sprite 为遮罩图层
*/
@WireField(
tag = 1,
Expand All @@ -43,21 +45,32 @@ public final class SpriteEntity extends Message<SpriteEntity, SpriteEntity.Build
)
public final List<FrameEntity> frames;

public SpriteEntity(String imageKey, List<FrameEntity> frames) {
this(imageKey, frames, ByteString.EMPTY);
/**
* 被遮罩图层的 matteKey 对应的是其遮罩图层的 imageKey.
*/
@WireField(
tag = 3,
adapter = "com.squareup.wire.ProtoAdapter#STRING"
)
public final String matteKey;

public SpriteEntity(String imageKey, List<FrameEntity> frames, String matteKey) {
this(imageKey, frames, matteKey, ByteString.EMPTY);
}

public SpriteEntity(String imageKey, List<FrameEntity> frames, ByteString unknownFields) {
public SpriteEntity(String imageKey, List<FrameEntity> frames, String matteKey, ByteString unknownFields) {
super(ADAPTER, unknownFields);
this.imageKey = imageKey;
this.frames = Internal.immutableCopyOf("frames", frames);
this.matteKey = matteKey;
}

@Override
public Builder newBuilder() {
Builder builder = new Builder();
builder.imageKey = imageKey;
builder.frames = Internal.copyOf("frames", frames);
builder.matteKey = matteKey;
builder.addUnknownFields(unknownFields());
return builder;
}
Expand All @@ -69,7 +82,8 @@ public boolean equals(Object other) {
SpriteEntity o = (SpriteEntity) other;
return unknownFields().equals(o.unknownFields())
&& Internal.equals(imageKey, o.imageKey)
&& frames.equals(o.frames);
&& frames.equals(o.frames)
&& Internal.equals(matteKey, o.matteKey);
}

@Override
Expand All @@ -79,6 +93,7 @@ public int hashCode() {
result = unknownFields().hashCode();
result = result * 37 + (imageKey != null ? imageKey.hashCode() : 0);
result = result * 37 + frames.hashCode();
result = result * 37 + (matteKey != null ? matteKey.hashCode() : 0);
super.hashCode = result;
}
return result;
Expand All @@ -89,6 +104,7 @@ public String toString() {
StringBuilder builder = new StringBuilder();
if (imageKey != null) builder.append(", imageKey=").append(imageKey);
if (!frames.isEmpty()) builder.append(", frames=").append(frames);
if (matteKey != null) builder.append(", matteKey=").append(matteKey);
return builder.replace(0, 2, "SpriteEntity{").append('}').toString();
}

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

public List<FrameEntity> frames;

public String matteKey;

public Builder() {
frames = Internal.newMutableList();
}

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

/**
* 被遮罩图层的 matteKey 对应的是其遮罩图层的 imageKey.
*/
public Builder matteKey(String matteKey) {
this.matteKey = matteKey;
return this;
}

@Override
public SpriteEntity build() {
return new SpriteEntity(imageKey, frames, super.buildUnknownFields());
return new SpriteEntity(imageKey, frames, matteKey, super.buildUnknownFields());
}
}

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

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

Expand All @@ -151,6 +179,7 @@ public SpriteEntity decode(ProtoReader reader) throws IOException {
switch (tag) {
case 1: builder.imageKey(ProtoAdapter.STRING.decode(reader)); break;
case 2: builder.frames.add(FrameEntity.ADAPTER.decode(reader)); break;
case 3: builder.matteKey(ProtoAdapter.STRING.decode(reader)); break;
default: {
FieldEncoding fieldEncoding = reader.peekFieldEncoding();
Object value = fieldEncoding.rawProtoAdapter().decode(reader);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Code generated by Wire protocol buffer compiler, do not edit.
// Source file: svga.proto at 33:1
// Source file: svga.proto at 34:1
package com.opensource.svgaplayer.proto;

import com.squareup.wire.FieldEncoding;
Expand Down

0 comments on commit 741eb01

Please sign in to comment.