Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 76eb6bc

Browse filesBrowse files
committed
[[ JObjectArray ]] Add List <-> JObjectArray handlers
This patch implements `ListFromJObjectArray` and `ListToJObjectArray` handlers.
1 parent f1e6555 commit 76eb6bc
Copy full SHA for 76eb6bc

File tree

2 files changed

+89
-0
lines changed
Filter options

2 files changed

+89
-0
lines changed
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# LiveCode Builder Standard Library
2+
3+
## Java Utilities
4+
5+
Syntax for converting between a JObjectArray and a List of JObjects have been
6+
added to the Java utility library.
7+
8+
* The alias `JObjectArray` has been added to aid readability
9+
* `ListToJObjectArray` - converts a List of JObjects to a JObjectArray
10+
* `ListFromJObjectArray` - converts a JObjectArray to a List of JObjects

‎libscript/src/java.lcb

Copy file name to clipboardExpand all lines: libscript/src/java.lcb
+79Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ public type JDouble is Float64
4646
public foreign type JObject binds to "MCJavaObjectTypeInfo"
4747
public type JString is JObject
4848
public type JByteArray is JObject
49+
public type JObjectArray is JObject
4950

5051
foreign handler MCJavaStringFromJString(in pString as JObject, out rString as String) returns nothing binds to "<builtin>"
5152
foreign handler MCJavaStringToJString(in pString as String, out rString as JObject) returns nothing binds to "<builtin>"
5253
foreign handler MCJavaDataFromJByteArray(in pByteArray as JObject, out rData as Data) returns nothing binds to "<builtin>"
5354
foreign handler MCJavaDataToJByteArray(in pData as Data, out rByteArray as JObject) returns nothing binds to "<builtin>"
55+
foreign handler MCJavaListToJObjectArray(in pList as List, in pClassName as String, out rObjectArray as JObjectArray) returns nothing binds to "<builtin>"
56+
foreign handler MCJavaListFromJObjectArray(in pObjectArray as JObjectArray, out rList as List) returns nothing binds to "<builtin>"
5457

5558
foreign handler MCJavaGetClassName(in pObject as JObject, out rName as String) returns nothing binds to "<builtin>"
5659
foreign handler MCJavaUnwrapJObject(in pObject as JObject, out rPointer as Pointer) returns nothing binds to "<builtin>"
@@ -245,4 +248,80 @@ public handler PointerToJObject(in pPointer as Pointer) returns JObject
245248
return tObj
246249
end handler
247250

251+
/**
252+
Summary: Convert a java object array into a List of java objects
253+
254+
Parameters:
255+
pObj: The JObjectArray to convert
256+
257+
Example:
258+
__safe foreign handler _JNI_IntentGetStringArrayExtra(in pIntent as JObject, \
259+
in pType as JString) \
260+
returns JObjectArray \
261+
binds to "java:android.content.Intent>getStringArrayExtra(Ljava/lang/String;)[Ljava/lang/String;"
262+
263+
handler OnActivityResultListener(\
264+
in pRequestCode as JObject, \
265+
in pResultCode as JObject, \
266+
in pIntent as optional JObject) returns nothing
267+
268+
if pResultCode is -1 then
269+
variable tArray as JObjectArray
270+
put _JNI_IntentGetStringArrayExtra(pIntent, \
271+
StringToJString("android.intent.extra.MIME_TYPES")) into tArray
272+
variable tList as List
273+
put ListFromJObjectArray(tArray) into tList
274+
275+
variable tStringList as List
276+
variable tString as JObject
277+
repeat for each element tString in tList
278+
push StringFromJObject(tString) onto back of tStringList
279+
end repeat
280+
281+
post "mimeTypes" with [tStringList]
282+
end if
283+
284+
end handler
285+
286+
Description:
287+
Use <ListFromJObjectArray> to convert <pObj> into a List of JObjects.
288+
289+
*/
290+
public handler ListFromJObjectArray(in pObj as JObjectArray) returns String
291+
variable tList as List
292+
unsafe
293+
MCJavaListFromJObjectArray(pObj, tList)
294+
end unsafe
295+
return tList
296+
end handler
297+
298+
/**
299+
Summary: Convert a List of JObjects into a JObjectArray
300+
301+
Parameters:
302+
pList: The List to convert
303+
pClass: The class name of the JObjects in the List
304+
305+
Returns:
306+
A JObjectArray where each element is a JObject of class pClass
307+
308+
Example:
309+
variable tArray as JObjectArray
310+
put ListToJObjectArray(\
311+
[StringToJString("foo"), StringToJString("bar")], \
312+
"java/lang/String") into tArray
313+
314+
Description:
315+
Use <ListToJObjectArray> to convert <pList> where each element is a JObject
316+
into a JObjectArray. Note all elements of <pList> must conform
317+
to the class <pClass>.
318+
*/
319+
public handler ListToJObjectArray(in pList as List, in pClass as String) returns JObjectArray
320+
variable tArray as JObjectArray
321+
unsafe
322+
MCJavaListToJObjectArray(pList, pClass, tArray)
323+
end unsafe
324+
return tArray
325+
end handler
326+
248327
end module

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.