Skip to content

Commit b5b5171

Browse files
committed
[[ AndroidListeners ]] Add docs and release note
1 parent eb8e2ce commit b5b5171

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

docs/guides/LiveCode Builder Language Reference.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,64 @@ includes the specification of function signature, according to the
575575
[standard rules for forming these](http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/method.html)
576576
when calling the JNI.
577577

578+
The function `interface` may be used on Android to create an interface
579+
proxy - that is an instance of a generic Proxy class for a given
580+
interface. This effectively allows LCB handlers to be registered as the
581+
targets for java interface callbacks, such as event listeners.
582+
583+
The foreign handler binding to such a function takes a value that should
584+
either be a `Handler` or an `Array` - if it is a `Handler`, the handler
585+
will be called for all callbacks from the specified listener. An array
586+
can be used to assign different handlers to differently named callbacks
587+
to the specified listener.
588+
589+
For example:
590+
591+
handler type ClickCallback(in pView as JObject)
592+
593+
foreign handler _JNI_OnClickListener(in pHandler as ClickCallback) returns JObject binds to "java:android.view.View$OnClickListener>interface()"
594+
595+
foreign handler _JNI_SetOnClickListener(in pButton as JObject, in pListener as JObject) returns nothing binds to "java:android.view.View>setOnClickListener(Landroid/view/View$OnClickListener;)V"
596+
597+
public handler ButtonClicked(in pView as JObject)
598+
-- do something on button click
599+
end handler
600+
601+
public handler SetOnClickListenerCallback(in pButton as JObject)
602+
unsafe
603+
variable tListener as JObject
604+
put _JNI_OnClickListener(ButtonClicked) into tListener
605+
_JNI_SetOnClickListener(pButton, tListener)
606+
end unsafe
607+
end handler
608+
609+
or
610+
611+
handler type MouseEventCallback(in pMouseEvent as JObject)
612+
613+
foreign handler _JNI_MouseListener(in pCallbacks as Array) returns JObject binds to "java:java.awt.event.MouseListener>interface()"
614+
615+
foreign handler _JNI_SetMouseListener(in pJButton as JObject, in pListener as JObject) returns nothing binds to "java:java.awt.Component>addMouseListener(Ljava/awt/event/MouseListener;)V"
616+
617+
public handler MouseEntered(in pEvent as JObject)
618+
-- do something on mouse entter
619+
end handler
620+
621+
public handler MouseExited(in pEvent as JObject)
622+
-- do something on mouse entter
623+
end handler
624+
625+
public handler SetMouseListenerCallbacks(in pJButton as JObject)
626+
variable tArray as Array
627+
put MouseEntered into tArray["mouseEntered"]
628+
put MouseExited into tArray["mouseExited"]
629+
unsafe
630+
variable tListener as JObject
631+
put _JNI_MouseListener(tArray) into tListener
632+
_JNI_SetMouseListener(pJButton, tListener)
633+
end unsafe
634+
end handler
635+
578636
Here *calling* specifies the calling convention which can be one of:
579637

580638
- `instance`
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# LiveCode Builder Language
2+
## Android Listener support
3+
An binding string variant has been added which allows the user to
4+
create an interface proxy - that is an instance of a generic
5+
Proxy class for a given interface.
6+
7+
This effectively allows LCB handlers to be registered as the targets
8+
for java interface callbacks, such as event listeners.
9+
10+
The syntax is as follows:
11+
12+
foreign handler _JNI_CreateListener(in pMapping) returns JObject binds to "java:listener.class.path>interface()"
13+
14+
The foreign handler binding to such a function takes a value that should
15+
either be a `Handler` or an `Array` - if it is a `Handler`, the handler
16+
will be called for all callbacks from the specified listener. An array
17+
can be used to assign different handlers to differently named callbacks
18+
to the specified listener.
19+
20+
For example:
21+
22+
handler type ClickCallback(in pView as JObject)
23+
24+
foreign handler _JNI_OnClickListener(in pHandler as ClickCallback) returns JObject binds to "java:android.view.View$OnClickListener>interface()"
25+
26+
foreign handler _JNI_SetOnClickListener(in pButton as JObject, in pListener as JObject) returns nothing binds to "java:android.view.View>setOnClickListener(Landroid/view/View$OnClickListener;)V"
27+
28+
public handler ButtonClicked(in pView as JObject)
29+
-- do something on button click
30+
end handler
31+
32+
public handler SetOnClickListenerCallback(in pButton as JObject)
33+
unsafe
34+
variable tListener as JObject
35+
put _JNI_OnClickListener(ButtonClicked) into tListener
36+
_JNI_SetOnClickListener(pButton, tListener)
37+
end unsafe
38+
end handler
39+
40+
or
41+
42+
handler type MouseEventCallback(in pMouseEvent as JObject)
43+
44+
foreign handler _JNI_MouseListener(in pCallbacks as Array) returns JObject binds to "java:java.awt.event.MouseListener>interface()"
45+
46+
foreign handler _JNI_SetMouseListener(in pJButton as JObject, in pListener as JObject) returns nothing binds to "java:java.awt.Component>addMouseListener(Ljava/awt/event/MouseListener;)V"
47+
48+
public handler MouseEntered(in pEvent as JObject)
49+
-- do something on mouse entter
50+
end handler
51+
52+
public handler MouseExited(in pEvent as JObject)
53+
-- do something on mouse entter
54+
end handler
55+
56+
public handler SetMouseListenerCallbacks(in pJButton as JObject)
57+
variable tArray as Array
58+
put MouseEntered into tArray["mouseEntered"]
59+
put MouseExited into tArray["mouseExited"]
60+
unsafe
61+
variable tListener as JObject
62+
put _JNI_MouseListener(tArray) into tListener
63+
_JNI_SetMouseListener(pJButton, tListener)
64+
end unsafe
65+
end handler

0 commit comments

Comments
 (0)