mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
synchronization with native branch
This commit is contained in:
parent
27595d6429
commit
072a506dc0
6 changed files with 415 additions and 1 deletions
|
@ -23,11 +23,64 @@ JavaVM *AndroidUtil::ourJavaVM = 0;
|
|||
|
||||
const char * const AndroidUtil::Class_NativeFormatPlugin = "org/geometerplus/fbreader/formats/NativeFormatPlugin";
|
||||
const char * const AndroidUtil::Class_PluginCollection = "org/geometerplus/fbreader/formats/PluginCollection";
|
||||
const char * const AndroidUtil::Class_ZLFile = "org/geometerplus/zlibrary/core/filesystem/ZLFile";
|
||||
const char * const AndroidUtil::Class_Book = "org/geometerplus/fbreader/library/Book";
|
||||
const char * const AndroidUtil::Class_Tag = "org/geometerplus/fbreader/library/Tag";
|
||||
|
||||
jmethodID AndroidUtil::SMID_PluginCollection_Instance;
|
||||
|
||||
jmethodID AndroidUtil::MID_ZLFile_getPath;
|
||||
|
||||
jfieldID AndroidUtil::FID_Book_File;
|
||||
jfieldID AndroidUtil::FID_Book_Title;
|
||||
jfieldID AndroidUtil::FID_Book_Language;
|
||||
jfieldID AndroidUtil::FID_Book_Encoding;
|
||||
|
||||
jmethodID AndroidUtil::SMID_Tag_getTag;
|
||||
|
||||
JNIEnv *AndroidUtil::getEnv() {
|
||||
JNIEnv *env;
|
||||
ourJavaVM->GetEnv((void **)&env, JNI_VERSION_1_2);
|
||||
return env;
|
||||
}
|
||||
|
||||
#define CHECK_NULL(value) if ((value) == 0) { return false; }
|
||||
|
||||
bool AndroidUtil::init(JavaVM* jvm) {
|
||||
ourJavaVM = jvm;
|
||||
|
||||
JNIEnv *env = getEnv();
|
||||
jclass cls;
|
||||
|
||||
CHECK_NULL( cls = env->FindClass(Class_ZLFile) );
|
||||
CHECK_NULL( MID_ZLFile_getPath = env->GetMethodID(cls, "getPath", "()Ljava/lang/String;") );
|
||||
env->DeleteLocalRef(cls);
|
||||
|
||||
CHECK_NULL( cls = env->FindClass(Class_Book) );
|
||||
CHECK_NULL( FID_Book_File = env->GetFieldID(cls, "File", "Lorg/geometerplus/zlibrary/core/filesystem/ZLFile;") );
|
||||
CHECK_NULL( FID_Book_Title = env->GetFieldID(cls, "myTitle", "Ljava/lang/String;") );
|
||||
CHECK_NULL( FID_Book_Language = env->GetFieldID(cls, "myLanguage", "Ljava/lang/String;") );
|
||||
CHECK_NULL( FID_Book_Encoding = env->GetFieldID(cls, "myEncoding", "Ljava/lang/String;") );
|
||||
env->DeleteLocalRef(cls);
|
||||
|
||||
CHECK_NULL( cls = env->FindClass(Class_Tag) );
|
||||
CHECK_NULL( SMID_Tag_getTag = env->GetStaticMethodID(cls, "getTag", "(Lorg/geometerplus/fbreader/library/Tag;Ljava/lang/String;)Lorg/geometerplus/fbreader/library/Tag;") );
|
||||
env->DeleteLocalRef(cls);
|
||||
}
|
||||
|
||||
bool AndroidUtil::extractJavaString(JNIEnv *env, jstring from, std::string &to) {
|
||||
if (from == 0) {
|
||||
return false;
|
||||
}
|
||||
const char *data = env->GetStringUTFChars(from, 0);
|
||||
to.assign(data);
|
||||
env->ReleaseStringUTFChars(from, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
jstring AndroidUtil::createJavaString(JNIEnv* env, const std::string &str) {
|
||||
if (str.empty()) {
|
||||
return 0;
|
||||
}
|
||||
return env->NewStringUTF(str.c_str());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue