Re: [android-developers] How to simulate a (missing) DPAD

2010-12-17 Thread Dianne Hackborn
I doubt you will get this to work correctly, because you are doing this
after parts of the framework that deal with things like going in and out of
touch mode have seen the events.

Why are you doing this?  If a device doesn't have a DPAD, the user isn't
going to think to use the volume keys to navigate focus(!!).  You should be
giving them a good touch-based UI.

On Fri, Dec 17, 2010 at 12:38 AM, blindfold wrote:

> 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  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+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How to simulate a (missing) DPAD

2010-12-17 Thread blindfold
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  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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en