[android-developers] How to simulate a (missing) DPAD
For Android phones that lack a physical d-pad or trackball (e.g.
Alcatel OT-980, Motorola Droid Pro), I am trying to remap the physical
up and down volume keys to simulated up and down d-pad keys using code
like
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
KeyEvent ke = new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_DPAD_UP);
dispatchKeyEvent(ke);
return true;
}
return super.onKeyDown(keyCode, event);
}
Although this works fine with a ListView and with activity views that
become scrollable because they are too large to fit on the physical
screen, it somehow does not work at all for activity views that remain
small enough to fit on the screen. I can test this by increasing the
number of radio buttons in some activity view and then see how the
above key remapping begins to work fine as soon as there are more
controls than fit on the screen. I have tried all sorts of things with
setting focus after making things focusable using setFocusable(true),
setFocusableInTouchMode(true), requestFocus(), requestFocusFromTouch()
and so on, but nothing seems to help. The above onKeyDown() executes
in all relevant cases as shown by my Log.i() output, but it is the
dispatchKeyEvent() that in the described cases does nothing. All my
activity views are surrounded by <ScrollView></ScrollView> in the XML
of their respective layouts. More about the context of this problem at
http://groups.google.com/group/eyes-free-dev/browse_thread/thread/3747abb6f0b9df11
(eyes-free-dev list).
So the above code works "sometimes", but I need a reliable/general
solution. How can one reliably remap physical keys to perform key
functions for which there are no physical keys on the Android device?
Thanks!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home