But HierarchyViewer *already* dumps these values, they're called
"absolute_x" and "absolute_y".

On Sat, Jun 20, 2009 at 8:09 AM, Samuel Quiring<sbq...@gmail.com> wrote:
> Hi.  Sorry for not responding earlier -- I don't read this newsgroup daily.
>
> Our app sends DUMP commands to the ViewServer class on the phone over a
> socket and gets back a list of attributes for all views in the view
> hierarchy of a phone app.  The code that actually creates these attributes
> is the class ViewDebug.  Both these classes are in the package android.view
> in the system image.  Our interface to ViewDebug is modelled after the
> HierarchyViewer app that is part of the SDK.
>
> There is a method, View.getLocationOnScreen(), that returns the x and y
> coordinate of the view on the screen, not relative to the Window.  So I
> modified the routine ViewDebug.dumpViewWithProperties() to add these two
> values if they are available as follows:
>
> private static boolean dumpViewWithProperties(Context context, View view,
>         BufferedWriter out, int level) {
>
>     try {
>         for (int i = 0; i < level; i++) {
>             out.write(' ');
>         }
>         out.write(view.getClass().getName());
>         out.write('@');
>         out.write(Integer.toHexString(view.hashCode()));
>         out.write(' ');
>         dumpViewProperties(context, view, out);
>         if(((View) view).mAttachInfo != null) {
>             int screenLocation[] = new int[2];
>             ((View)view).getLocationOnScreen(screenLocation);
>             writeEntry(out, "", "screenX", "",
> Integer.toString(screenLocation[0]));
>             writeEntry(out, "", "screenY", "",
> Integer.toString(screenLocation[1]));
>         }
>
>         out.newLine();
>     } catch (IOException e) {
>
> Our app also computes the X and Y position of each view relative to the
> Window.  We compare the actual screen position with the computed X and Y to
> know when the view is not in its normal position and to know what its actual
> position is.  You can catch the view in a transition period, for example
> suppose the phone app has an EditText view near the bottom of the phone
> window.  If a click happens in that EditText, the entire window containing
> the view will be pushed up to make room for the keyboard and also keep the
> EditText control exposed (since the purpose of the soft keyboard is to enter
> text into the EditText control). if you ask to dump the view just after that
> click, you can catch the view in transition.  Its screenY position will be
> part way between where it was (at the bottom) and where it will be (above
> the soft keyboard).  Of course the reverse is true if you click the BACK key
> to remove the soft keyboard and ask for the dump right after that click.
>
> Hope that helps.  Sorry for not responding earlier.
>
> -Sam
>
>
> On Thu, Jun 18, 2009 at 10:24 PM, tek <tek.bas...@gmail.com> wrote:
>>
>> Please post your solution, I'm interested in this as well.
>>
>>
>> On Jun 13, 2:17 pm, sbq <sbq...@gmail.com> wrote:
>> > Thanks anyway, I found what I'm looking for.
>> >
>> > -Sam
>> >
>> > On Jun 13, 8:34 am, sbq <sbq...@gmail.com> wrote:
>> >
>> >
>> >
>> > > Is there a way to get the window's information from the View?
>> > > I would like to figure out that the window is shifted and by
>> > > how much.
>> >
>> > > On Jun 12, 10:10 pm, Romain Guy <romain...@google.com> wrote:
>> >
>> > > > That's because the window is shifted, not the views within the
>> > > > window.
>> > > > What HierarchyViewer shows is correct.
>> >
>> > > > On Fri, Jun 12, 2009 at 5:56 PM, sbq<sbq...@gmail.com> wrote:
>> >
>> > > > > Greetings,
>> >
>> > > > > I'm interfacing to ViewDebug to get the current position of views
>> > > > > in
>> > > > > the phone window.  I have an Android application with an EditText
>> > > > > box
>> > > > > near the bottom of the phone's window. When I click on that
>> > > > > EditBox,
>> > > > > the soft keyboard is displayed at the bottom of the window and the
>> > > > > EditText box (and everything above it) is pushed up to make room.
>> > > > > Soon after, while the keyboard is still visible, I have a program
>> > > > > that
>> > > > > connects to the phone and makes a DUMP request to ViewDebug.  I
>> > > > > don't
>> > > > > see this shift reflected in either the mTop or mScrollY of any
>> > > > > Views
>> > > > > brought back.
>> >
>> > > > > Is there a way learn about the new position of these Views after
>> > > > > the
>> > > > > soft keyboard is displayed?  Alternatively, is there a way to
>> > > > > learn
>> > > > > that the soft keyboard is currently being displayed and how far
>> > > > > the
>> > > > > phone window was scrolled up -- the amount of scrolling depends on
>> > > > > which EditText control was clicked.
>> >
>> > > > > Since HierarchyViewer uses this same DUMP data, it also does not
>> > > > > show
>> > > > > that the Views have been shifted up and some views are not on the
>> > > > > screen -- the absolute_y positions are what they would be if the
>> > > > > keyboard was not there.
>> >
>> > > > > Thanks for any help.
>> >
>> > > > > -Sam
>> >
>> > > > --
>> > > > Romain Guy
>> > > > Android framework engineer
>> > > > romain...@android.com
>> >
>> > > > Note: please don't send private questions to me, as I don't have
>> > > > time
>> > > > to provide private support.  All such questions should be posted on
>> > > > public forums, where I and others can see and answer them
>>
>
>
> >
>



-- 
Romain Guy
Android framework engineer
romain...@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support.  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-framework" group.
To post to this group, send email to android-framework@googlegroups.com
To unsubscribe from this group, send email to 
android-framework+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/android-framework?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to