1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 17:59:33 +02:00

jmethodID -> Method class

This commit is contained in:
Nikolay Pultsin 2012-03-30 13:33:51 +01:00
parent 181fbe9997
commit daf77393a2
9 changed files with 41 additions and 27 deletions

View file

@ -98,7 +98,7 @@ void fillLanguageAndEncoding(JNIEnv* env, jobject javaBook, Book &book) {
env->DeleteLocalRef(javaString); env->DeleteLocalRef(javaString);
} }
env->CallBooleanMethod(javaBook, AndroidUtil::MID_Book_save); AndroidUtil::Method_Book_save->call(javaBook);
} }
extern "C" extern "C"

View file

@ -72,15 +72,15 @@ shared_ptr<VoidMethod> AndroidUtil::Method_EncodingConverter_reset;
jmethodID AndroidUtil::SMID_JavaEncodingCollection_Instance; jmethodID AndroidUtil::SMID_JavaEncodingCollection_Instance;
jmethodID AndroidUtil::MID_JavaEncodingCollection_getEncoding_int; jmethodID AndroidUtil::MID_JavaEncodingCollection_getEncoding_int;
jmethodID AndroidUtil::MID_JavaEncodingCollection_getEncoding_String; jmethodID AndroidUtil::MID_JavaEncodingCollection_getEncoding_String;
jmethodID AndroidUtil::MID_JavaEncodingCollection_providesConverterFor; shared_ptr<BooleanMethod> AndroidUtil::Method_JavaEncodingCollection_providesConverterFor;
jmethodID AndroidUtil::SMID_ZLFile_createFileByPath; jmethodID AndroidUtil::SMID_ZLFile_createFileByPath;
jmethodID AndroidUtil::MID_ZLFile_children; jmethodID AndroidUtil::MID_ZLFile_children;
jmethodID AndroidUtil::MID_ZLFile_exists; shared_ptr<BooleanMethod> AndroidUtil::Method_ZLFile_exists;
jmethodID AndroidUtil::MID_ZLFile_getInputStream; jmethodID AndroidUtil::MID_ZLFile_getInputStream;
jmethodID AndroidUtil::MID_ZLFile_getPath; jmethodID AndroidUtil::MID_ZLFile_getPath;
jmethodID AndroidUtil::MID_ZLFile_isDirectory; shared_ptr<BooleanMethod> AndroidUtil::Method_ZLFile_isDirectory;
jmethodID AndroidUtil::MID_ZLFile_size; shared_ptr<LongMethod> AndroidUtil::Method_ZLFile_size;
jmethodID AndroidUtil::MID_ZLFileImage_init; jmethodID AndroidUtil::MID_ZLFileImage_init;
@ -96,7 +96,7 @@ shared_ptr<VoidMethod> AndroidUtil::Method_Book_setLanguage;
shared_ptr<VoidMethod> AndroidUtil::Method_Book_setEncoding; shared_ptr<VoidMethod> AndroidUtil::Method_Book_setEncoding;
shared_ptr<VoidMethod> AndroidUtil::Method_Book_addAuthor; shared_ptr<VoidMethod> AndroidUtil::Method_Book_addAuthor;
shared_ptr<VoidMethod> AndroidUtil::Method_Book_addTag; shared_ptr<VoidMethod> AndroidUtil::Method_Book_addTag;
jmethodID AndroidUtil::MID_Book_save; shared_ptr<BooleanMethod> AndroidUtil::Method_Book_save;
jmethodID AndroidUtil::SMID_Tag_getTag; jmethodID AndroidUtil::SMID_Tag_getTag;
@ -174,17 +174,17 @@ bool AndroidUtil::init(JavaVM* jvm) {
CHECK_NULL( SMID_JavaEncodingCollection_Instance = env->GetStaticMethodID(cls, "Instance", "()Lorg/geometerplus/zlibrary/core/encodings/JavaEncodingCollection;") ); CHECK_NULL( SMID_JavaEncodingCollection_Instance = env->GetStaticMethodID(cls, "Instance", "()Lorg/geometerplus/zlibrary/core/encodings/JavaEncodingCollection;") );
CHECK_NULL( MID_JavaEncodingCollection_getEncoding_String = env->GetMethodID(cls, "getEncoding", "(Ljava/lang/String;)Lorg/geometerplus/zlibrary/core/encodings/Encoding;") ); CHECK_NULL( MID_JavaEncodingCollection_getEncoding_String = env->GetMethodID(cls, "getEncoding", "(Ljava/lang/String;)Lorg/geometerplus/zlibrary/core/encodings/Encoding;") );
CHECK_NULL( MID_JavaEncodingCollection_getEncoding_int = env->GetMethodID(cls, "getEncoding", "(I)Lorg/geometerplus/zlibrary/core/encodings/Encoding;") ); CHECK_NULL( MID_JavaEncodingCollection_getEncoding_int = env->GetMethodID(cls, "getEncoding", "(I)Lorg/geometerplus/zlibrary/core/encodings/Encoding;") );
CHECK_NULL( MID_JavaEncodingCollection_providesConverterFor = env->GetMethodID(cls, "providesConverterFor", "(Ljava/lang/String;)Z") ); Method_JavaEncodingCollection_providesConverterFor = new BooleanMethod(env, cls, "providesConverterFor", "(Ljava/lang/String;)");
env->DeleteLocalRef(cls); env->DeleteLocalRef(cls);
CHECK_NULL( cls = env->FindClass(Class_ZLFile) ); CHECK_NULL( cls = env->FindClass(Class_ZLFile) );
CHECK_NULL( SMID_ZLFile_createFileByPath = env->GetStaticMethodID(cls, "createFileByPath", "(Ljava/lang/String;)Lorg/geometerplus/zlibrary/core/filesystem/ZLFile;") ); CHECK_NULL( SMID_ZLFile_createFileByPath = env->GetStaticMethodID(cls, "createFileByPath", "(Ljava/lang/String;)Lorg/geometerplus/zlibrary/core/filesystem/ZLFile;") );
CHECK_NULL( MID_ZLFile_children = env->GetMethodID(cls, "children", "()Ljava/util/List;") ); CHECK_NULL( MID_ZLFile_children = env->GetMethodID(cls, "children", "()Ljava/util/List;") );
CHECK_NULL( MID_ZLFile_exists = env->GetMethodID(cls, "exists", "()Z") ); Method_ZLFile_exists = new BooleanMethod(env, cls, "exists", "()");
CHECK_NULL( MID_ZLFile_isDirectory = env->GetMethodID(cls, "isDirectory", "()Z") ); Method_ZLFile_isDirectory = new BooleanMethod(env, cls, "isDirectory", "()");
CHECK_NULL( MID_ZLFile_getInputStream = env->GetMethodID(cls, "getInputStream", "()Ljava/io/InputStream;") ); CHECK_NULL( MID_ZLFile_getInputStream = env->GetMethodID(cls, "getInputStream", "()Ljava/io/InputStream;") );
CHECK_NULL( MID_ZLFile_getPath = env->GetMethodID(cls, "getPath", "()Ljava/lang/String;") ); CHECK_NULL( MID_ZLFile_getPath = env->GetMethodID(cls, "getPath", "()Ljava/lang/String;") );
CHECK_NULL( MID_ZLFile_size = env->GetMethodID(cls, "size", "()J") ); Method_ZLFile_size = new LongMethod(env, cls, "size", "()");
env->DeleteLocalRef(cls); env->DeleteLocalRef(cls);
CHECK_NULL( cls = env->FindClass(Class_ZLFileImage) ); CHECK_NULL( cls = env->FindClass(Class_ZLFileImage) );
@ -206,7 +206,7 @@ bool AndroidUtil::init(JavaVM* jvm) {
Method_Book_setEncoding = new VoidMethod(env, cls, "setEncoding", "(Ljava/lang/String;)"); Method_Book_setEncoding = new VoidMethod(env, cls, "setEncoding", "(Ljava/lang/String;)");
Method_Book_addAuthor = new VoidMethod(env, cls, "addAuthor", "(Ljava/lang/String;Ljava/lang/String;)"); Method_Book_addAuthor = new VoidMethod(env, cls, "addAuthor", "(Ljava/lang/String;Ljava/lang/String;)");
Method_Book_addTag = new VoidMethod(env, cls, "addTag", "(Lorg/geometerplus/fbreader/library/Tag;)"); Method_Book_addTag = new VoidMethod(env, cls, "addTag", "(Lorg/geometerplus/fbreader/library/Tag;)");
CHECK_NULL( MID_Book_save = env->GetMethodID(cls, "save", "()Z") ); Method_Book_save = new BooleanMethod(env, cls, "save", "()");
env->DeleteLocalRef(cls); env->DeleteLocalRef(cls);
CHECK_NULL( cls = env->FindClass(Class_Tag) ); CHECK_NULL( cls = env->FindClass(Class_Tag) );

View file

@ -77,11 +77,11 @@ public:
static jmethodID SMID_ZLFile_createFileByPath; static jmethodID SMID_ZLFile_createFileByPath;
static jmethodID MID_ZLFile_children; static jmethodID MID_ZLFile_children;
static jmethodID MID_ZLFile_exists; static shared_ptr<BooleanMethod> Method_ZLFile_exists;
static jmethodID MID_ZLFile_getInputStream; static jmethodID MID_ZLFile_getInputStream;
static jmethodID MID_ZLFile_getPath; static jmethodID MID_ZLFile_getPath;
static jmethodID MID_ZLFile_isDirectory; static shared_ptr<BooleanMethod> Method_ZLFile_isDirectory;
static jmethodID MID_ZLFile_size; static shared_ptr<LongMethod> Method_ZLFile_size;
static jmethodID MID_ZLFileImage_init; static jmethodID MID_ZLFileImage_init;
@ -99,7 +99,7 @@ public:
static jmethodID SMID_JavaEncodingCollection_Instance; static jmethodID SMID_JavaEncodingCollection_Instance;
static jmethodID MID_JavaEncodingCollection_getEncoding_String; static jmethodID MID_JavaEncodingCollection_getEncoding_String;
static jmethodID MID_JavaEncodingCollection_getEncoding_int; static jmethodID MID_JavaEncodingCollection_getEncoding_int;
static jmethodID MID_JavaEncodingCollection_providesConverterFor; static shared_ptr<BooleanMethod> Method_JavaEncodingCollection_providesConverterFor;
static jmethodID SMID_Paths_cacheDirectory; static jmethodID SMID_Paths_cacheDirectory;
@ -113,7 +113,7 @@ public:
static shared_ptr<VoidMethod> Method_Book_setEncoding; static shared_ptr<VoidMethod> Method_Book_setEncoding;
static shared_ptr<VoidMethod> Method_Book_addAuthor; static shared_ptr<VoidMethod> Method_Book_addAuthor;
static shared_ptr<VoidMethod> Method_Book_addTag; static shared_ptr<VoidMethod> Method_Book_addTag;
static jmethodID MID_Book_save; static shared_ptr<BooleanMethod> Method_Book_save;
static jmethodID SMID_Tag_getTag; static jmethodID SMID_Tag_getTag;

View file

@ -56,4 +56,11 @@ public:
jlong call(jobject base, ...); jlong call(jobject base, ...);
}; };
class BooleanMethod : public Method {
public:
BooleanMethod(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature);
jboolean call(jobject base, ...);
};
#endif /* __JNIENVELOPE_H__ */ #endif /* __JNIENVELOPE_H__ */

View file

@ -58,3 +58,14 @@ jlong LongMethod::call(jobject base, ...) {
va_end(lst); va_end(lst);
return result; return result;
} }
BooleanMethod::BooleanMethod(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature) : Method(env, cls, name, signature + "Z") {
}
jboolean BooleanMethod::call(jobject base, ...) {
va_list lst;
va_start(lst, base);
jboolean result = myEnv->CallBooleanMethod(base, myId, lst);
va_end(lst);
return result;
}

View file

@ -52,7 +52,7 @@ bool JavaEncodingConverterProvider::providesConverter(const std::string &encodin
jclass cls = env->FindClass(AndroidUtil::Class_JavaEncodingCollection); jclass cls = env->FindClass(AndroidUtil::Class_JavaEncodingCollection);
jobject collection = env->CallStaticObjectMethod(cls, AndroidUtil::SMID_JavaEncodingCollection_Instance); jobject collection = env->CallStaticObjectMethod(cls, AndroidUtil::SMID_JavaEncodingCollection_Instance);
jstring encodingName = AndroidUtil::createJavaString(env, encoding); jstring encodingName = AndroidUtil::createJavaString(env, encoding);
jboolean result = env->CallBooleanMethod(collection, AndroidUtil::MID_JavaEncodingCollection_providesConverterFor, encodingName); jboolean result = AndroidUtil::Method_JavaEncodingCollection_providesConverterFor->call(collection, encodingName);
env->DeleteLocalRef(encodingName); env->DeleteLocalRef(encodingName);
env->DeleteLocalRef(collection); env->DeleteLocalRef(collection);
env->DeleteLocalRef(cls); env->DeleteLocalRef(cls);

View file

@ -85,9 +85,7 @@ void JavaFSDir::collectChildren(std::vector<std::string> &names, bool filesNotDi
if (index != std::string::npos) { if (index != std::string::npos) {
path.erase(index); path.erase(index);
isdir = true; isdir = true;
} /*else { }
isdir = env->CallBooleanMethod(file, AndroidUtil::MID_ZLFile_isDirectory) != 0;
}*/
if (isdir ^ filesNotDirs) { if (isdir ^ filesNotDirs) {
names.push_back(path.substr(prefixLength)); names.push_back(path.substr(prefixLength));
} }

View file

@ -155,8 +155,7 @@ size_t JavaInputStream::sizeOfOpened() {
if (myJavaInputStream == 0 || myJavaFile == 0) { if (myJavaInputStream == 0 || myJavaFile == 0) {
return 0; return 0;
} }
JNIEnv *env = AndroidUtil::getEnv(); return (size_t)AndroidUtil::Method_ZLFile_size->call(myJavaFile);
return (size_t) env->CallLongMethod(myJavaFile, AndroidUtil::MID_ZLFile_size);
} }
void JavaInputStream::seek(int offset, bool absoluteOffset) { void JavaInputStream::seek(int offset, bool absoluteOffset) {

View file

@ -17,10 +17,9 @@
* 02110-1301, USA. * 02110-1301, USA.
*/ */
#include <jni.h>
#include <ZLStringUtil.h> #include <ZLStringUtil.h>
#include <AndroidUtil.h> #include <AndroidUtil.h>
#include <JniEnvelope.h>
#include "ZLAndroidFSManager.h" #include "ZLAndroidFSManager.h"
@ -89,11 +88,11 @@ ZLFileInfo ZLAndroidFSManager::fileInfo(const std::string &path) const {
return info; return info;
} }
info.IsDirectory = env->CallBooleanMethod(javaFile, AndroidUtil::MID_ZLFile_isDirectory); info.IsDirectory = AndroidUtil::Method_ZLFile_isDirectory->call(javaFile);
const jboolean exists = env->CallBooleanMethod(javaFile, AndroidUtil::MID_ZLFile_exists); const jboolean exists = AndroidUtil::Method_ZLFile_exists->call(javaFile);
if (exists) { if (exists) {
info.Exists = true; info.Exists = true;
info.Size = env->CallLongMethod(javaFile, AndroidUtil::MID_ZLFile_size); info.Size = AndroidUtil::Method_ZLFile_size->call(javaFile);
} }
env->DeleteLocalRef(javaFile); env->DeleteLocalRef(javaFile);