Tuesday, April 14, 2009
Get coordinates where to show Tooltip on blackberry screen aware of vertical Offset or Horizontal Offset
On a complex UI screen we have multiple managers for our UI controls. So to get the actual x, y coordinates of the control we need to ask the top manager in our hierarchy of managers. The top manager has the actual x, y coordinates of controls with respect to screen. Here is the code below:
private XYPoint getAbsoluteLocation(){
Manager manager, parentManager = getManager();
XYPoint XY = new XYPoint(getLeft(),getTop());
while (parentManager!=null) {
manager = parentManager;
XY.translate(manager.getLeft(),manager.getTop());
parentManager = manager.getManager();
}
return XY;
}
If you have the vertical scroller on that screen. You need to calculate the offset of the vertical scroll and
adjust that with the absoluote location. Here is the code below to adjust the vertical offset:
private XYPoint getAbsoluteLocation(){
Manager manager, parentManager = getManager();
XYPoint XY = new XYPoint(getLeft(),getTop());
int scrollAdjustment = 0;
while (parentManager!=null) {
manager = parentManager;
if(manager.getVerticalScroll() != 0){
scrollAdjustment = manager.getVerticalScroll()/3;
}
XY.translate(manager.getLeft(),manager.getTop() - scrollAdjustment);
parentManager = manager.getManager();
}
return XY;
}
If you have the horizontal scroller on that screen. You need to calculate the offset of the horizontal scroll and adjust that with the absoluote location. Here is the code below to adjust the vertical offset:
private XYPoint getAbsoluteLocation(){
Manager manager, parentManager = getManager();
XYPoint XY = new XYPoint(getLeft(),getTop());
int scrollAdjustment = 0;
while (parentManager!=null) {
manager = parentManager;
if(manager.getHorizontalScroll() != 0){
scrollAdjustment = manager.getHorizontalScroll()/3;
}
XY.translate(manager.getLeft() - getHorizontalScroll() ,manager.getTop());
parentManager = manager.getManager();
}
return XY;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment