mirror of https://github.com/kivy/pyjnius.git
some clarifications for java classes extended support
This commit is contained in:
parent
5d143331a8
commit
9b758a81c3
|
@ -63,7 +63,8 @@ class MetaJavaClass(type):
|
|||
interfaces[n] = jcs.j_env[0].FindClass(jcs.j_env, <char*>i)
|
||||
|
||||
getProxyClass = jcs.j_env[0].GetStaticMethodID(
|
||||
jcs.j_env, Proxy, "getProxyClass", "(Ljava/lang/ClassLoader,[Ljava/lang/Class;)Ljava/lang/Class;")
|
||||
jcs.j_env, Proxy, "getProxyClass",
|
||||
"(Ljava/lang/ClassLoader,[Ljava/lang/Class;)Ljava/lang/Class;")
|
||||
|
||||
getClassLoader = jcs.j_env[0].GetStaticMethodID(
|
||||
jcs.j_env, baseclass, "getClassLoader", "()Ljava/lang/Class;")
|
||||
|
|
|
@ -616,6 +616,23 @@ cdef class GenericNativeWrapper(object):
|
|||
|
||||
# return self.callback(*args)
|
||||
|
||||
cdef class PythonJavaClass(object):
|
||||
'''
|
||||
base class to create a java class from python
|
||||
'''
|
||||
cdef JNIEnv *j_env
|
||||
cdef jclass j_cls
|
||||
cdef LocalRef j_self
|
||||
|
||||
def __cinit__(self, *args):
|
||||
self.j_env = NULL
|
||||
self.j_cls = NULL
|
||||
self.j_self = NULL
|
||||
pass
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.j_self = create_proxy_instance()
|
||||
|
||||
cdef jobject invoke0(
|
||||
JNIEnv *j_env,
|
||||
jobject this,
|
||||
|
@ -624,8 +641,7 @@ cdef jobject invoke0(
|
|||
|
||||
cdef jfieldID ptrField = j_env[0].GetFieldID(j_env.GetObjectClass(this), "ptr", "J")
|
||||
cdef jlong jptr = j_env.GetLongField(this, ptrField)
|
||||
cdef NativeInvocationHandler *h = reinterpret_cast<NativeInvocationHandler>(jptr)
|
||||
return h.Invoke(env, method, args);
|
||||
return h.fnPtr(env, method, args);
|
||||
|
||||
|
||||
# now we need to create a proxy and pass it an invocation handler
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import java.lang.reflect.InvocationHandler;
|
||||
|
||||
package jnius;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class NativeInvocationHandler implements InvocationHandler {
|
||||
public NativeInvocationHandler(long ptr) {
|
||||
this.ptr = ptr;
|
||||
|
@ -14,9 +15,3 @@ public class NativeInvocationHandler implements InvocationHandler {
|
|||
|
||||
private long ptr;
|
||||
}
|
||||
|
||||
class NativeInvocationHandler {
|
||||
public:
|
||||
virtual ~NativeInvocationHandler();
|
||||
virtual jobject Invoke(JNIEnv *, jobject method, jobjectArray args) = 0;
|
||||
};
|
Loading…
Reference in New Issue