How To Get Real Screen Coordinates in Android

3,032 views
Skip to first unread message

Santosh Kadam

unread,
May 19, 2010, 11:07:27 AM5/19/10
to android-ndk
Hi There -

I would like to get the real screen coordinates from an android device
screen. The adb-framebuffer gives me a size of 320x240 ....but
getevent shows a click at coordinates with the screen - 1024x1024.

How to get the real coordinates or the corrective precision
programatically ? I tried to use MotionEvent class and obtain raw x-y
coordinates. But those calls return the same values for me..

any help ?

thanks and regards,
Santosh

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

mic _

unread,
May 19, 2010, 12:23:59 PM5/19/10
to andro...@googlegroups.com
So you know both the actual resolution (320x240) and the virtual one (1024x1024)?
Can't you just scale your coordinates by the quota between those two resolutions then? Or did I misunderstand which values you already have available?

/Michael

Dianne Hackborn

unread,
May 19, 2010, 2:04:43 PM5/19/10
to andro...@googlegroups.com
The events returned by getevent are not in any kind of screen coordinate, they are in virtual coordinates of the touch screen.  They must be scaled to the screen coordinates by interrogating the device for the range it reports.  Of course, nobody actually needs to know this, because the framework takes care of reading the events and scaling them appropriately.  (And MotionEvent coordinates are floats so you don't lose precision in the data being received.)
--
Dianne Hackborn
Android framework engineer
hac...@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.

Santosh Kadam

unread,
May 20, 2010, 5:16:37 AM5/20/10
to android-ndk
Hi Dianne ,

I agree that getevent may not be returning screen coordinates ....But
then what's the scaling logic to map them to the actual screen
coordinates ? Any dopes on this ?

Thanks and Regards,
Santosh

On May 19, 11:04 pm, Dianne Hackborn <hack...@android.com> wrote:
> The events returned by getevent are not in any kind of screen coordinate,
> they are in virtual coordinates of the touch screen.  They must be scaled to
> the screen coordinates by interrogating the device for the range it reports.
>  Of course, nobody actually needs to know this, because the framework takes
> care of reading the events and scaling them appropriately.  (And MotionEvent
> coordinates are floats so you don't lose precision in the data being
> received.)
>
>
>
>
>
> On Wed, May 19, 2010 at 8:07 AM, Santosh Kadam <sanma...@gmail.com> wrote:
> > Hi There -
>
> > I would like to get the real screen coordinates from an android device
> > screen. The adb-framebuffer gives me a size of 320x240 ....but
> > getevent shows a click at coordinates with the screen - 1024x1024.
>
> > How to get the real coordinates or the corrective precision
> > programatically ? I tried to use MotionEvent class and obtain raw x-y
> > coordinates. But those calls return the same values for me..
>
> > any help ?
>
> > thanks and regards,
> > Santosh
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr­oups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-ndk?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-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/android-ndk?hl=en.- Hide quoted text -
>
> - Show quoted text -

Santosh Kadam

unread,
May 20, 2010, 5:18:01 AM5/20/10
to android-ndk
Hi Michael -

I tried to do a linear conversion of coordinates. It does not seem to
work :(

Regards,
Santosh

On May 19, 9:23 pm, mic _ <micol...@gmail.com> wrote:
> So you know both the actual resolution (320x240) and the virtual one
> (1024x1024)?
> Can't you just scale your coordinates by the quota between those two
> resolutions then? Or did I misunderstand which values you already have
> available?
>
> /Michael
>
>
>
>
>
> On Wed, May 19, 2010 at 5:07 PM, Santosh Kadam <sanma...@gmail.com> wrote:
> > Hi There -
>
> > I would like to get the real screen coordinates from an android device
> > screen. The adb-framebuffer gives me a size of 320x240 ....but
> > getevent shows a click at coordinates with the screen - 1024x1024.
>
> > How to get the real coordinates or the corrective precision
> > programatically ? I tried to use MotionEvent class and obtain raw x-y
> > coordinates. But those calls return the same values for me..
>
> > any help ?
>
> > thanks and regards,
> > Santosh
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr­oups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-ndk?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/android-ndk?hl=en.- Hide quoted text -
>
> - Show quoted text -

Santosh Kadam

unread,
May 20, 2010, 10:56:14 AM5/20/10
to android-ndk
Hello Dianne -

I could obtain the display DisplayMetrics values for my tatto - but I
am not really able to figure out - how 320x240 is mapped to
1024x1024...Can u put some light on this please -

thanks in advance -

Regards,
Santosh

On May 19, 11:04 pm, Dianne Hackborn <hack...@android.com> wrote:
> The events returned by getevent are not in any kind of screen coordinate,
> they are in virtual coordinates of the touch screen.  They must be scaled to
> the screen coordinates by interrogating the device for the range it reports.
>  Of course, nobody actually needs to know this, because the framework takes
> care of reading the events and scaling them appropriately.  (And MotionEvent
> coordinates are floats so you don't lose precision in the data being
> received.)
>
>
>
>
>
> On Wed, May 19, 2010 at 8:07 AM, Santosh Kadam <sanma...@gmail.com> wrote:
> > Hi There -
>
> > I would like to get the real screen coordinates from an android device
> > screen. The adb-framebuffer gives me a size of 320x240 ....but
> > getevent shows a click at coordinates with the screen - 1024x1024.
>
> > How to get the real coordinates or the corrective precision
> > programatically ? I tried to use MotionEvent class and obtain raw x-y
> > coordinates. But those calls return the same values for me..
>
> > any help ?
>
> > thanks and regards,
> > Santosh
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr­oups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-ndk?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-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/android-ndk?hl=en.- Hide quoted text -
>
> - Show quoted text -

laurent mallet

unread,
May 20, 2010, 4:41:43 PM5/20/10
to android-ndk
Warning, on some device, there are touch buttons. So you need to ajust
your range by a test:
- click upleft corner
- click downright corner
With these values you can define the mapping between the two system
coordinates.

It is better to use Java API.
> > For more options, visit this group athttp://groups.google.com/group/android-ndk?hl=en.-Hide quoted text -
Reply all
Reply to author
Forward
0 new messages