-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): refactor fullTranscribe jni method
- Loading branch information
Showing
3 changed files
with
115 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <jni.h> | ||
|
||
// ReadableMap utils | ||
|
||
namespace readablemap { | ||
|
||
jboolean hasKey(JNIEnv *env, jobject readableMap, const char *key) { | ||
jclass mapClass = env->GetObjectClass(readableMap); | ||
jmethodID hasKeyMethod = env->GetMethodID(mapClass, "hasKey", "(Ljava/lang/String;)Z"); | ||
jstring jKey = env->NewStringUTF(key); | ||
jboolean result = env->CallBooleanMethod(readableMap, hasKeyMethod, jKey); | ||
env->DeleteLocalRef(jKey); | ||
return result; | ||
} | ||
|
||
jint getInt(JNIEnv *env, jobject readableMap, const char *key, jint defaultValue) { | ||
if (!hasKey(env, readableMap, key)) { | ||
return defaultValue; | ||
} | ||
jclass mapClass = env->GetObjectClass(readableMap); | ||
jmethodID getIntMethod = env->GetMethodID(mapClass, "getInt", "(Ljava/lang/String;)I"); | ||
jstring jKey = env->NewStringUTF(key); | ||
jint result = env->CallIntMethod(readableMap, getIntMethod, jKey); | ||
env->DeleteLocalRef(jKey); | ||
return result; | ||
} | ||
|
||
jboolean getBool(JNIEnv *env, jobject readableMap, const char *key, jboolean defaultValue) { | ||
if (!hasKey(env, readableMap, key)) { | ||
return defaultValue; | ||
} | ||
jclass mapClass = env->GetObjectClass(readableMap); | ||
jmethodID getBoolMethod = env->GetMethodID(mapClass, "getBoolean", "(Ljava/lang/String;)Z"); | ||
jstring jKey = env->NewStringUTF(key); | ||
jboolean result = env->CallBooleanMethod(readableMap, getBoolMethod, jKey); | ||
env->DeleteLocalRef(jKey); | ||
return result; | ||
} | ||
|
||
jlong getLong(JNIEnv *env, jobject readableMap, const char *key, jlong defaultValue) { | ||
if (!hasKey(env, readableMap, key)) { | ||
return defaultValue; | ||
} | ||
jclass mapClass = env->GetObjectClass(readableMap); | ||
jmethodID getLongMethod = env->GetMethodID(mapClass, "getLong", "(Ljava/lang/String;)J"); | ||
jstring jKey = env->NewStringUTF(key); | ||
jlong result = env->CallLongMethod(readableMap, getLongMethod, jKey); | ||
env->DeleteLocalRef(jKey); | ||
return result; | ||
} | ||
|
||
jfloat getFloat(JNIEnv *env, jobject readableMap, const char *key, jfloat defaultValue) { | ||
if (!hasKey(env, readableMap, key)) { | ||
return defaultValue; | ||
} | ||
jclass mapClass = env->GetObjectClass(readableMap); | ||
jmethodID getFloatMethod = env->GetMethodID(mapClass, "getDouble", "(Ljava/lang/String;)D"); | ||
jstring jKey = env->NewStringUTF(key); | ||
jfloat result = env->CallDoubleMethod(readableMap, getFloatMethod, jKey); | ||
env->DeleteLocalRef(jKey); | ||
return result; | ||
} | ||
|
||
jstring getString(JNIEnv *env, jobject readableMap, const char *key, jstring defaultValue) { | ||
if (!hasKey(env, readableMap, key)) { | ||
return defaultValue; | ||
} | ||
jclass mapClass = env->GetObjectClass(readableMap); | ||
jmethodID getStringMethod = env->GetMethodID(mapClass, "getString", "(Ljava/lang/String;)Ljava/lang/String;"); | ||
jstring jKey = env->NewStringUTF(key); | ||
jstring result = (jstring) env->CallObjectMethod(readableMap, getStringMethod, jKey); | ||
env->DeleteLocalRef(jKey); | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters