How to handle dispatching of touch events with FireMonkey? - android

How can I handle the dispatching of touch events with FireMonkey ?
I need to control the dispatching of touch events to cancel the dispatching if a click callback of a component is already processing. So that only one click callback can be registered/executed at a time.
Some hurried users often click multiple times and this can lead to multiple bugs that would not occur otherly.
The solution used in my project to mitigate this is TComponent->enabled = false; ... TComponent->enabled = true; but isn't always effective, implies to be done on every clickable component and doesn't prevent from clicking other components.
I've found some links on the subject but the 1st doesn't seem to use FireMonkey and the second is only about gestures.
https://www.packtpub.com/mapt/book/application_development/9781783989645/8/ch08lvl1sec93/time-for-action--handling-touch-events
http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Gestures_in_FireMonkey
The TTouchManager class doesn't seem to provide any useful control on this either :
http://docwiki.embarcadero.com/Libraries/Tokyo/en/FMX.Types.TTouchManager

Related

How can i avoid to receive two different events on the same millisecond?

In my app, i have two buttons that send an event with an ID using an event bus (Otto). Depending on this ID, the app goes to a different level of the navigation between differents fragments. Is possible to avoid that the event bus sends the same event (with different ID) in the same millisecond when the user taps over two different button at the same millisecond?. I attach an image in order to show my Logcat.
Thanks!
EDIT 1:
Using syncronized both onClick method as subscribe method, i continue receiving the events in the same millisecond. Now, the myth about "syncronized" has down for me. O_o
There are posts where they explain how avoid very fast clicks, but here, the clicks are in the same millisecond...rare, but you can see the logs.
I attach new images with the method that i am using. Thanks!
Yes, use synchronized keyword with the method which is generating events (or also with the method which receive events).
For example:
public synchronized void genEvent(){
}
See following related links
https://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html
When to use synchronized in Java
Is there an advantage to use a Synchronized Method instead of a Synchronized Block?

View.Activate/Deactivate event listener registered multiple times

I have a simple Apache Flex view based application that runs on Android as follow:
<f:MyView xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/sparks"
activate="activateHandler(event)"
deactivate="deactivateHandler(event)"/>
I expect the activateHandler() should execute only once when the view is activated, however after I pop and then push the same view back the number of activateHandler() execution increased by how many times I did the pop and push operation. Why would this happen and how to force it to operate as expected (i.e only once)?
Expanding on #JileniBouguima's answer, changing activate to creationComplete will resolve this because of how those events work. Your expectation that activateHandler() executes only once is a little off; according to the Activate event documentation, activate fires
every time your application gains operating system focus and becomes active.
By contrast, creationComplete fires once per object, once the component is created.
I am not sure what code exactly is written in the handlers activateHandler and deactivateHandler but in Flex this is a standard practice to remove event listener if you do not need it any more. I am assuming that whenever you pop and push the same view it is adding and removing the listener. I can help you more if you share the handlers code.
Change activate to creationComplete.

Default key event handler in an Android Application

Is there a way in Android where an android application when active will catch and process all key events (and maybe touch events) before they are delivered to the actual view which is supposed to be handling it?
I know that we can have onKeyDown or similar method in Activity to handle the keyevent, but it is fired only if none of its child views handles it internally.
These view are usually ListView, GridView, ScrollView, etc..
I want to find a way that my keyHandler method is called before that keyEvent is delivered to these views.
Implementation in my keyHandler will be very simple. It will just play a tone upon each event, just like keypress tone, and then forward it to be handled the way it was meant to be by those views or Android framework.
Want to know if its possible beacuse I don't want to write onKeyListener to each and every view in every activity as I have lot of activities and lots of views and it will just become difficult to write the same code everywhere. If there is a way, i can implement that in BaseActivity and derive all my activities by that and go on my way of having default key handler.
I don’t try it myself but I think this one will help you: (just scroll a little bit down to the method mentioned in the text)
Input Event: Event Handlers - Activity.dispatchTouchEvent(MotionEvent)
Looks like this is the chance to catch events before they get to the window. Read the detailed Description here.

Jquery mobile multiple click events when go back into page

I have just upgraded jquery mobile to beta 2(from beta 1) and I am now receiving multiple click events if i go back into a page after pressing back, each time I go back in it adds another to the click so the alert fires however many times you go into the page
I have also noticed that clicks/taps seem to go through the current page and clicking on pages hidden by view - seems really strange but I am thinking they are probably linked.
It is as if it is creating multiple versions of the same page and when you go back into it loads a new one causing there to be two click events.
Here is a snippet of the code which is being fired
$('#click_me').live('vclick', function() {
alert('clicked');
});
Hopefully this makes sense and anyone can shed any light on what might be going on?
You've probably solved this by now, but you need to use the pagecreate event.
#Phill's suggestion of:
$('div').live('pageshow',function(event, ui){
$('#click_me').click(function() {
alert('clicked');
});
});
Unfortunately won't help, but you can solve the issue if you change pageshow to pagecreate
$('div').live('pagecreate',function(){
$('#click_me').click(function() {
alert('clicked');
});
});
If you're not using AJAX to load your pages, make sure also to change live to bind.
I had this same issue myself and this has solved it completely for me.
UPDATED:
I think the reason is you have the click event tied to the live event, so evrytime you navigate to that page it triggers the click event. try something like this:
$('div').live('pageshow',function(event, ui){
$('#click_me').click(function() {
alert('clicked');
});
});
or just use the click event
$('#click_me').click(function() {
alert('clicked');
});
When Beta 2 was released they are deprecating vclick
http://jquerymobile.com/blog/2011/08/03/jquery-mobile-beta-2-released/
Backtrack: We’ve switched back from vclick to click for links
In Beta 1, we decided to use our custom vclick event for handling Ajax
links to improve responsiveness and to hide the URL bar on the iPhone
and Android phones. Even though we did quite a bit of testing before
landing this for Beta 1, we began to hear feedback that this change
was causing some significant issues out in the wild including:
Multiple click events causing navigation and form element issue –
In certain situations, when tapping an element, tap/click events seem
to fire twice on links and is due to edge cases where the target of
the touch event and mouse event don’t match due to how the browsers
calculate tolerances for these events. This is most pronounced on
Android 2.1, but affected most WebKit-based browsers to varying
degrees when a tap events occured near the edge of an element.
Click handlers in custom scripts didn’t “work” anymore – if a
script bound only to click events on the document, the global vclick
feature could interfere because the touch events may supercede click
events so it events wouldn’t appear to trigger.

Android: cancelling pending events

I would like to be able to cancel all pending events in my App. How do I do it?
If many events stack up (due to the user "mashing" different areas of the screen repeatedly) I would like to cancel all events except the last one.
This is not the same as stopping the propagation of events further down the view stack (which is done by returning "true" from the event handler (for an example of this see here).

Categories

Resources