Android: cancelling pending events - android

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

Related

How to handle dispatching of touch events with FireMonkey?

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

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.

How can I check programmatically that user has an interaction with their Android phone?

How can I check programmatically to see if the user has interacted with an Android Phone's touch screen or keypad? Interaction may be a touch or key press event. Will creating a service for this will help me or not ? How can I do this?
If you are talking about doing this in Activity.. then you can override onUserInteraction() method of the Activity. Following is the java doc of the method:
Called whenever a key, touch, or trackball event is dispatched to the
activity. Implement this method if you wish to know that the user has
interacted with the device in some way while your activity is running.
This callback and onUserLeaveHint() are intended to help activities
manage status bar notifications intelligently; specifically, for
helping activities determine the proper time to cancel a notfication.
All calls to your activity's onUserLeaveHint() callback will be
accompanied by calls to onUserInteraction(). This ensures that your
activity will be told of relevant user activity such as pulling down
the notification pane and touching an item there.
Note that this callback will be invoked for the touch down action that
begins a touch gesture, but may not be invoked for the touch-moved and
touch-up actions that follow.
there are so much methods for completing this purpose. You can override on touch event, onclick event on the View instance.

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.

ViewFlipper, onClick events not delivered

I have my own implementation of the ViewFlipper (that exactly mocks the Android code, I wrote it before I realized this), the only difference being the fact that I hardcoded an inAnimation and an outAnimation in mine.
One side of the ViewFlipper has a 'flip' button which flips. The other side has a 'save' and 'cancel' button which flips it back. The 'save' performs a DB operation.
When the save or cancel, it flips the card correctly. If I perform the following operation: flip->cancel->flip->cancel..., it works fine. But when I perform: flip->save->flip, the last flip is non-response and logcat shows me that the touch operation was not delivered because of a timeout. The first thing I checked and ensured was that the database operation was not holding off the UI thread, and it was not!
I use the content of the ViewFlipper (using the View.getContent()) to perform DB operations, throw Toasts, build Alert Dialogs and the like. Might this create issues?
I've read a post somewhere saying that there was an issue with the ViewFlipper with animations and onClick() events not being delivered (the discussion ended with no solution). Am I a victim of this?
Try doing the save operation in a thread even though you are sure its not blocking the UI thread.
If that does not work, then set onTouch listener to the save view.

Categories

Resources