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.

[[ Intents ]] Implement OnActivityResultListener #6844

Open
wants to merge 4 commits into
base: develop
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[[ JObjectArray ]] Add List <-> JObjectArray handlers
This patch implements `ListFromJObjectArray` and `ListToJObjectArray` handlers.
  • Loading branch information
montegoulding committed Mar 18, 2020
commit 850cf242211c17ecd7fe82349cd0ce46308309c1
10 changes: 10 additions & 0 deletions 10 docs/lcb/notes/feature-jobjectarray.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# LiveCode Builder Standard Library

## Java Utilities

Syntax for converting between a JObjectArray and a List of JObjects have been
added to the Java utility library.

* The alias `JObjectArray` has been added to aid readability
* `ListToJObjectArray` - converts a List of JObjects to a JObjectArray
* `ListFromJObjectArray` - converts a JObjectArray to a List of JObjects
79 changes: 79 additions & 0 deletions 79 libscript/src/java.lcb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ public type JDouble is Float64
public foreign type JObject binds to "MCJavaObjectTypeInfo"
public type JString is JObject
public type JByteArray is JObject
public type JObjectArray is JObject

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

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

/**
Summary: Convert a java object array into a List of java objects

Parameters:
pObj: The JObjectArray to convert

Example:
__safe foreign handler _JNI_IntentGetStringArrayExtra(in pIntent as JObject, \
in pType as JString) \
returns JObjectArray \
binds to "java:android.content.Intent>getStringArrayExtra(Ljava/lang/String;)[Ljava/lang/String;"

handler OnActivityResultListener(\
in pRequestCode as JObject, \
in pResultCode as JObject, \
in pIntent as optional JObject) returns nothing

if pResultCode is -1 then
variable tArray as JObjectArray
put _JNI_IntentGetStringArrayExtra(pIntent, \
StringToJString("android.intent.extra.MIME_TYPES")) into tArray
variable tList as List
put ListFromJObjectArray(tArray) into tList

variable tStringList as List
variable tString as JObject
repeat for each element tString in tList
push StringFromJObject(tString) onto back of tStringList
end repeat

post "mimeTypes" with [tStringList]
end if

end handler

Description:
Use <ListFromJObjectArray> to convert <pObj> into a List of JObjects.

*/
public handler ListFromJObjectArray(in pObj as JObjectArray) returns optional List
variable tList as optional List
unsafe
MCJavaListFromJObjectArray(pObj, tList)
end unsafe
return tList
end handler

/**
Summary: Convert a List of JObjects into a JObjectArray

Parameters:
pList: The List to convert
pClass: The class name of the JObjects in the List

Returns:
A JObjectArray where each element is a JObject of class pClass

Example:
variable tArray as JObjectArray
put ListToJObjectArray(\
[StringToJString("foo"), StringToJString("bar")], \
"java/lang/String") into tArray

Description:
Use <ListToJObjectArray> to convert <pList> where each element is a JObject
into a JObjectArray. Note all elements of <pList> must conform
to the class <pClass>.
*/
public handler ListToJObjectArray(in pList as List, in pClass as String) returns optional JObjectArray
variable tArray as optional JObjectArray
unsafe
MCJavaListToJObjectArray(pList, pClass, tArray)
end unsafe
return tArray
end handler

end module
Morty Proxy This is a proxified and sanitized view of the page, visit original site.