save code

This commit is contained in:
xsl
2025-12-19 13:47:16 +08:00
parent e38da96e37
commit 6bbbb3c3ef
8 changed files with 137 additions and 102 deletions
+4 -4
View File
@@ -165,7 +165,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
return JNI_VERSION_1_6;
}
void CppCallback(const string& motion_type)
void CppCallback()
{
JNIEnv* env = nullptr;
bool needDetach = false;
@@ -205,7 +205,7 @@ void CppCallback(const string& motion_type)
}
// 3. 构造 jstring 参数
jstring jResult = env->NewStringUTF(motion_type.c_str());
jstring jResult = env->NewStringUTF("ok");
// 4. 调用 Java 回调
env->CallVoidMethod(g_callback, methodId, jResult);
@@ -309,7 +309,7 @@ Java_com_hmwl_face_1sdk_FaceActivity_PreReadAction(JNIEnv *env, jobject thiz, js
aout << "ArgLen to long:" << len << std::endl;
}
std::string ret = g_Application->preReadyMotion(nativeString, CppCallback);
std::string ret = g_Application->preLoadMotionList(nativeString, CppCallback);
return env->NewStringUTF(ret.c_str());
}
@@ -336,6 +336,6 @@ Java_com_hmwl_face_1sdk_FaceActivity_ChangeMotionCpp(JNIEnv *env, jobject thiz,
if(g_Application->isInited())
{
g_Application->changeMotion(nativeString, CppAnimationFinishedCallback, loop);
g_Application->changeMotionList(CppAnimationFinishedCallback, loop);
}
}
@@ -0,0 +1,27 @@
package com.hmwl.face_sdk;
import org.json.JSONObject;
public class Frame {
public String name;
public float x;
public float y;
public Frame(String name, float x, float y)
{
this.name = name;
this.x = x;
this.y = y;
}
public JSONObject toJsonObject(){
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", name);
jsonObject.put("x", x);
jsonObject.put("y", y);
return jsonObject;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
+13 -16
View File
@@ -5,32 +5,29 @@ import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class Motion {
public String type = "no";
public List<String> png_names = new ArrayList<>();
public String name = "no";
public List<Frame> frames = new ArrayList<>();
public Motion(String name, List<Frame> frames)
{
this.name = name;
this.frames = frames;
}
public JSONObject toJsonObject() {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("type", type);
JSONArray ja = new JSONArray();
for(int i = 0; i < png_names.size(); ++i){
ja.put(png_names.get(i));
jsonObject.put("name", name);
JSONObject jframes = new JSONObject();
for(int i = 0; i < frames.size(); ++i){
jframes.put(frames.get(i).name, frames.get(i).toJsonObject());
}
jsonObject.put("png_names", ja);
jsonObject.put("frames", jframes);
return jsonObject;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public String toJson() {
try {
return toJsonObject().toString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
};
@@ -0,0 +1,28 @@
package com.hmwl.face_sdk;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class MotionList {
public List<Motion> motions = new ArrayList<>();
public JSONObject toJsonObject() {
try {
JSONObject jsonObject = new JSONObject();
JSONArray jMotions = new JSONArray();
for(int i = 0; i < motions.size(); ++i){
jMotions.put(motions.get(i).toJsonObject());
}
jsonObject.put("motions", jMotions);
return jsonObject;
} catch (Exception e) {
e.printStackTrace();
return new JSONObject();
}
}
public String toJsonString(){
return toJsonObject().toString();
}
}