mirror of https://github.com/kivy/pyjnius.git
convert list of integer, float and long to their equivalent Java Array object
This commit is contained in:
parent
20b4bd5d62
commit
4a6945accd
|
@ -224,6 +224,21 @@ cdef jobject convert_pyarray_to_java(JNIEnv *j_env, definition, pyarray) except
|
|||
cdef JavaObject jo
|
||||
cdef JavaClass jc
|
||||
|
||||
if definition == 'Ljava/lang/Object;' and len(pyarray) > 0:
|
||||
# then the method will accept any array type as param
|
||||
# let's be as precise as we can
|
||||
conversions = {
|
||||
int: 'I',
|
||||
bool: 'Z',
|
||||
long: 'J',
|
||||
float: 'F',
|
||||
basestring: 'Ljava/lang/String;',
|
||||
}
|
||||
for type, override in conversions.iteritems():
|
||||
if isinstance(pyarray[0], type):
|
||||
definition = override
|
||||
break
|
||||
|
||||
if definition == 'Z':
|
||||
ret = j_env[0].NewBooleanArray(j_env, array_size)
|
||||
for i in range(array_size):
|
||||
|
|
|
@ -82,3 +82,15 @@ class BasicsTest(unittest.TestCase):
|
|||
test = autoclass('org.jnius.BasicsTest')()
|
||||
self.assertEquals(test.methodParamsObject([
|
||||
'hello', 'world']), True)
|
||||
|
||||
def test_instances_methods_params_object_list_int(self):
|
||||
test = autoclass('org.jnius.BasicsTest')()
|
||||
self.assertEquals(test.methodParamsObject([1, 2]), True)
|
||||
|
||||
def test_instances_methods_params_object_list_float(self):
|
||||
test = autoclass('org.jnius.BasicsTest')()
|
||||
self.assertEquals(test.methodParamsObject([3.14, 1.61]), True)
|
||||
|
||||
def test_instances_methods_params_object_list_long(self):
|
||||
test = autoclass('org.jnius.BasicsTest')()
|
||||
self.assertEquals(test.methodParamsObject([1L, 2L]), True)
|
||||
|
|
Loading…
Reference in New Issue