Xamarin.Forms Handling Custom Event in Custom Renderer - xamarin.android

I have a basic implementation of a custom render I will be using for handling Long Press.. It's all really based from this code http://arteksoftware.com/gesture-recognizers-with-xamarin-forms/
In my "GestureContainerView" I have an event that I called "OnHeldDown",
How do I raise this "OnHeldDown" event if (in my Android) detected a "LongPress" ?
I tried looking up in google but couldn't find an example.
----------- UPDATE ------- (found a solution)
in PCL
in Android

Just create a method which checks if anyone is subscribes to the event handler and invoke it, if anyone is.
For example, create a methode like this:
private void RaiseOnHeldDown()
{
if (OnHeldDown != null)
OnHeldDown(this, EventArgs.Empty);
// Or even do the null propagation way
// OnHeldDown?.Invoke(this, EventArgs.Empty);
}
Of course if you'd like you can supply EventArgs.
Now in the event where you detect the LongPress you just call this method.

Related

programatically adding an on-tap attribute referencing a dart function for a HtmlElement

I have a dart function:
_addSelection(HtmlElement ele){
ele.classes.add("selection");
}
I would either want 1 or 2 things to occur, either A) execute an on-tap and on-track function given the selection class.... OR Dynamically add the on-tap and on-track attributes referencing reflected dart functions.
I have 2 functions:
#reflectable
onTap(CustomEventWrapper cew, params){
//...
}
#reflectable
onTrack(CustomEventWrapper cew, params){
//...
}
I was looking at the HtmlElement class and documentation and I wasnt quite understanding how to do this.
Edit if I were using jQuery and Javascript, I would be doing something as simple as:
$(document).on("tap", function(){});
$(document).on("track", function(){});
Edit2 Added Angular Dart because both designs leverage Dart backend and markup front end.
You could do:
_addSelection(HtmlElement ele) {
ele.classes.add("selection");
ele.onTouchEnd.listen((TouchEvent touch) {
...
});
}
That would give you something close to the tap event. If you wanted to get really fancy you could also listen for onTouchStart and only call your onTap handler when the time between the start and end is small.

Creating notifications with Zend Framework 2

I am trying to learn ZF2. I know that there are better methods to create notifications but as I said this is for learning purpose.
My idea is to save the notifications in the database. This is simple I can do it. My question is about how to show them. I have a partial for the header menu , I want to display them there.
I dont know if i am on the right track i currently have a view helper which i create via factory.
class TestMe extends AbstractHelper
{
protected $html;
public function __invoke($name = 'Unnamed')
{
// if($this->view->hasIdentity()){
// $user = $this->view->identity();
// }
//$this->testJS();
return "$name , this is Zend Framework 2 View Helper";
}
protected function htmlIt(){
}
protected function testJS($loggedIn = false){
$js = '';
$js .= <<<JS
alert('test');
JS;
$view = $this->getView();
$view->inlineScript()->prependScript($js);
}
}
I know this is nothing but I cant understand what is good an wrong. My idea is to pass ot the view helper an array with notifications for the user and display them. So I need a service for making calls to the database or there is another way?
ZF2 already has an Notification Helper Plugin. Have a Look at http://framework.zend.com/manual/current/en/modules/zend.view.helpers.flash-messenger.html
But if you really want to do it on your own, you may want to create an Controller Plugin http://framework.zend.com/manual/current/en/modules/zend.mvc.plugins.html.
There is a nice Tutorial for that here: http://lab.empirio.no/custom-controller-plugin-in-zf2.html

How to trigger a KeyboardEvent in Dart

Like I said in the title, I would like to simulate a keyup event in Dart. The problem is that I have not found how create a new KeyboardEvent object.
The only way that I've found is to use the Event(String type) constructor and then dispatch it on window object. But that doesn't work because of my "keyup" handler who takes a KeyboardEvent in parameter. Example:
window.on.keyUp.add((KeyboardEvent e){
print('keyUp handler');
});
KeyboardEvent e = new Event("KeyboardEvent");
window.on.keyUp.dispatch(e);
Is there a way to create and dispatch a KeyBoardEvent to simulate a "keyup" in Dart?
Also, I should mention that I tried too to trigger the event in JavaScript, thanks to js-interop library, but it only fires the JS handlers.
Try the following code:
window.on.keyUp.add((Event event){
print('keyUp handler');
if(event is KeyboardEvent)
{
KeyboardEvent keyEvent = event as KeyboardEvent;
//do stuff with keyEvent if needed
}
});
window.on.keyUp.dispatch(new Event("keyup"));
I think the parameter on the Event constructor must be the type of the event. Also, you can check if the event is a keyboardEvent, so you can handle KeyIdentifier, for example.
It's possible now to Dispatch a KeyBoardEvent from window, please see discussion on Google Group for more information: https://groups.google.com/a/dartlang.org/d/topic/misc/mgnd1TUGn68/discussion

Luaj - add JButton action listener from Lua

In the application I'm developing in Java SE I use Luaj to implement functionality (this is a data collector application). The Java app reads a COM port of a device and gives the data to Lua event handlers which are written by the user of the application. Part of the user interface is also constructed from Lua, however, I'm having problems adding ActionListener objects (implemented in Lua as well) to Swing components, like JButton.
The code I'm currenty stuck at:
button = luajava.newInstance("javax.swing.JButton","test")
visuals:getPanel():add(button)
This creates a JButton object and puts it on a JPanel component. I'd like to define the action listener for this button in Lua as well.
Any idea how I can do that?
I tried the following, but it obviously does not work.
al = {}
function al.actionPerformed(ev)
print("test")
end
button.addActionListener(al)
I come a bit late, but for the reference, the swingapp.lua script shows how to handle listeners:
button:addActionListener(luajava.createProxy('java.awt.event.ActionListener',
{
actionPerformed = function (e)
print('Action', e)
end,
}))
Tested with Luaj-jse 3.0-alpha1

How to raise custom events in j2me / blackberry?

Just started doing some code porting from .Net CF to Blackberry JDE 4.6.1. But haven't found how to implement custom events.
I have a custom syncManager that raise events in .Net CF so I can update the UI (sort of the observer patron).
Any pointers or help where I can start?
I can recommend the j2me-observer project. It has a liberal license and will give you an implementation of the observer pattern which isn't included in J2ME. It can be used to allow UI changes to happen based on fired events.
you can send custom event using.
//you can use any int value for CUSTOM_EVENT
fieldChangeNotify(CUSTOM_EVENT);
and you can handle that event using
public void fieldChanged(Field field, int context) {
if(cotext == CUSTOM_EVENT){
Dialog.alert("custom event");
}
}
I can recommend the open source project javaEventing. It's available at http://code.google.com/p/javaeventing , and makes it easy to define, register for and trigger custom events, much like in C#.
An example:
Class MyEvent extends EventManager.EventObject {}
EventManager.registerEventListener(new EventManager.GenericEventListener(){
public void eventTriggered(Object sender, Event event) {
// <-- The event is triggered, do something.
}
}, new MyEvent());
EventManager.triggerEvent(this, new MyEvent()); // <-- Trigger the event
bob

Resources