How to get the Touch point (top and left) irrespective of the views, windows in Titanium


I want that when i click on my MainView, i want to <strong>create new window</strong> just where i have <strong>touched</strong>.

Say for e.g. i have clicked at top:50 left:200 then my <strong>new window</strong> should <strong>start from that point</strong> only.

I want to create something like <strong>Popover</strong> in Titanium for android. Can anyone just guide me?

Thanks in advance.


consider you have a window <strong>win</strong> thats going to fire the click event like that:

win.addEventListener('click',function(e){ var myPopUp = createPopUp({ left: e.x, top: e.y }); myPopUp.open(); });

your popup could be created like that:

createPopUp = function(_args){ var popup = Titanium.UI.createWindow({ backgroundColor: 'red', /* a backgroundImage could be better */ height: '250dp', width: '250dp', top: _args.top, /* manually adjusted */ left: _args.left, opacity: 0.7 /* for a nice transparency*/ }); return popup; };

this works at android and iphone. the top values seems to be a little unprecise but in general it works.


In regards to getting the touch coordinates for the parent view you should attach the event listener to the parent view (or both if you can't get the source and need different actions) because if I'm correct the touch event (or any other for event that matter) should propagate to parent/child views too. Then you can simply get the e.source.top and e.source.left values as you need.


You can place this way <a href="http://developer.android.com/reference/android/widget/PopupWindow.html" rel="nofollow">PopupWindow</a>, using its showAtLocation method.

This allows to place the window in desired position, relative to your main view. And you know where user clicked on your main view.