I've been working on a project which needs to capture keystrokes from an external keyboard (a handheld barcode scanner really) anywhere in the app. Using react-native, this should be trivial, especially with the library react-native-keyevent.
Works perfectly on the initial load. I then navigate to another part of the app (using react-navigation) and try to scan a barcode; nothing happens. I replaced the react-native-keyevent overrides MainActivity.java with some simple Log.d("KeyEvents", "..."), overriding dispatchKeyEvent, onKeyUp, onKeyMultiple and onKeyDown. I only log, then call super.
Same behaviour. Logs fine until I navigate, then it stops. After investigating the Android docs, it seems Views can override key handlers, and thereby 'steal' keystrokes. However I'm stuck finding out which view steals the focus. Also there's really no keyboard handling in react-native by default, so to my understanding, everything should be passed on to the activity.
Wandering hopelessly around in the react-native codebase, I stumbled upon TVEventHandler which I use to log if a view requests focus:
import TVEventHandler from 'react-native/Libraries/Components/AppleTV/TVEventHandler';
(new TVEventHandler).enable('foo', function(){
console.log(arguments);
})
Right before the handlers stop working, this line indeed logs some focus events with a view tag. However, I don't know how to find out which view has a certain tag.
Can someone point me in the right direction where to look?
Related
Alright there's a custom QDialog (class derived from QDialog) , stuff populated from QML, it works it opens just fine it behaves as desired, but then when we want to kill it using
mDialog-> close() or mDialog->hide()
all the animations within the dialog halt, everything within it freezes but.. it doesn't close.
if you wonder how we initiate the destruction process, there's a button within the QML which sends a signal to the C++ back-end, the back-end holds pointer to the dialog and tries to close.
The dialog is opened with showFullScreen so ther's nothing blocking (exec would block)
Ideas?
After many human-work-hours, we stumbled upon a FIX.
Lo and behold. So for this to work we had to
dialog->setAttribute(Qt::WA_DeleteOnClose,true);
before trying to close().
Now there's nothing in documentation suggesting that something like this would be required? Supposedly a BUG, right?
conversely for instance a sequence of:
dialog->close() /// hide()/ reject()
delete dialog;
would result in an exception with QT saying something about its processing queue being pre-occupied and us trying to kill it.
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.
Situation: I have a webview with an html input field in it for typing a location, there is a webview sitting underneath it to display suggestions. There is a keyup handler and an onchange handler on that input field. on keyup there is a message sent out to call an api to populate the suggestion webview.
Problem: After typing one character, the input field loses focus. On android 2.3 the keyboard stays up but continued typing does nothing. on android 4.1 the onchange handler gets triggered (as though the user had hit enter to submit what they had typed instead of seleting a suggestion) and the keyboard and webviews get taken away.
Things I have considered: An external loadURL call could cause this (like 'javascript: var...'), calling 'requestFocus' or 'bringToFront' on some other view could also cause this. Setting a event handler on a view tree listener might help clear things up.
Unfortunately, as far as I have been able to tell, no url change is happening, no other views seem to be requesting focus or are being brought to the front. Putting a handler on the view tree listener did not help--it was triggered after the input field lost focus.
I'm out of ideas to try to find the cause of this focus change.
What can I do to investigate this further and solve this problem?
Is loadUrl being called at all (after the first time)? It turns out that loadUrl automatically closes the keyboard. If you are using loadUrl, I found a workaround! Try https://stackoverflow.com/a/18776064/513038.
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.
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.