yy1717
2019-12-30 b98224fe56ead2b92f0cc41fe24e4c77d1188dff
修改speaker
3个文件已修改
46 ■■■■ 已修改文件
lib/src/main/cpp/native-lib.cpp 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lib/src/main/cpp/native-lib.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
lib/src/main/java/com/anyun/exam/lib/RemoteService.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lib/src/main/cpp/native-lib.cpp
@@ -326,7 +326,7 @@
void TextOsd(int type, const char *text)
{
    JNIEnv *env;
/*    JNIEnv *env;
    bool ready_in_java_env = false;
    if (sg_jvm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) {
@@ -351,7 +351,7 @@
        if (sg_jvm->DetachCurrentThread() != JNI_OK) {
            LOGE("%s: DetachCurrentThread() failed", __FUNCTION__);
        }
    }
    }*/
}
void DrawScreen(const Polygon *map, const Polygon *car)
@@ -412,44 +412,12 @@
    DEBUG("DisplayText: %s", string);
}
void CCL(int who)
{
    JNIEnv *env;
    bool ready_in_java_env = false;
    static int c[2] = {0};
    if (sg_jvm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) {
        // Attach主线程
        if (sg_jvm->AttachCurrentThread(&env, NULL) != JNI_OK) {
            LOGE("%s: AttachCurrentThread() failed", __FUNCTION__);
            return;
        }
    } else {
        ready_in_java_env = true;
    }
    jclass cls = env->GetObjectClass(sg_obj);
    jmethodID fun = env->GetMethodID(cls, "CCL", "(II)V");
    env->CallVoidMethod(sg_obj, fun, c[who], who);
    c[who] = !c[who];
    env->DeleteLocalRef(cls);
    if (!ready_in_java_env) {
        //Detach主线程
        if (sg_jvm->DetachCurrentThread() != JNI_OK) {
            LOGE("%s: DetachCurrentThread() failed", __FUNCTION__);
        }
    }
}
extern "C"
JNIEXPORT void JNICALL
Java_com_anyun_exam_lib_RemoteService_startNative(JNIEnv *env, jobject thiz) {
    // TODO: implement startNative()
    // 保存全局JVM以便在子线程中使用
    DEBUG("启动Native");
    env->GetJavaVM(&sg_jvm);
    // 不能直接赋值(g_obj = ojb)
    sg_obj = env->NewGlobalRef(thiz);
lib/src/main/cpp/native-lib.h
@@ -22,7 +22,7 @@
void TextSpeak(const char *text);
void TextOsd(int type, const char *text);
void DrawScreen(const Polygon *map, const Polygon *car);
void CCL(int who);
void DisplayText(const char *string);
#endif //RTKBASESTATION_NATIVE_LIB_H
lib/src/main/java/com/anyun/exam/lib/RemoteService.java
@@ -162,6 +162,12 @@
        return sharedPreferences.getInt(key, 0);
    }
    public void TextSpeak(String text) {
/*        if (speaker != null) {
            speaker.speak(text);
        }*/
    }
    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");