|
| 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