Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN

menubar paint issue because of tooltip thread

Hello everyone ,

Please i seem to be having an issue with my mobile app , i have a horizontal menu bar at the top of my screen and below i have a scrollable verticalfieldmanager that is updated at intervals lets say 5 minutes with feeds from my php server , now my problem is when the app is launched , i can easily scroll horizontally on the bar and on each focus of my fields in the meny bar i see my tooltip like this

top_menu.PNG

now after my feeds are being loaded (to the bottom verticalfieldmanager )for the next 30 mins  at 5 mins interval , i get a funny behaviour from my menubar above , i find it difficult to gain focus on the buttons and the top menu bar with the image above starts behaving funny any tips , here is my tooltip code 

 

//Code Listing 1 

Tooltip.jva 

public class Tooltip extends PopupScreen
{
int _x;
int _y;
//TooltipThread _tooltipThread;
private Timer tooltipTimer = new Timer();
private TooltipThread _tooltipThread;

private Tooltip()
{
super(new VerticalFieldManager());
}
public void sublayout(int width, int height)
{
super.sublayout(width,height);
setPosition(_x,_y);

}

public void removeToolTip()
{
if ( _tooltipThread != null ) {
_tooltipThread.dismiss();
_tooltipThread.cancel();
}
}
private void display(UiApplication uiApp, int x, int y, int displayTime)
{
_x = x;
_y = y;
_tooltipThread = new TooltipThread(uiApp, this, displayTime);
tooltipTimer.schedule(_tooltipThread, 2000);
}

public static Tooltip addToolTip(UiApplication uiApp, String toolTipString, int x, int y, int displayTime)
{

Tooltip toolTip = new Tooltip();
LabelField label = new LabelField(toolTipString , LabelField.NON_FOCUSABLE)
{

protected void paint(Graphics g)
{

g.setColor(Color.WHITE);
super.paint(g);
}
};
label.setFont(Font.getDefault().derive(Font.PLAIN, 6, Ui.UNITS_pt));

toolTip.add(label);
toolTip.display(uiApp, x, y, displayTime);
return toolTip;
}

/**
*
* tooltipthread to simulate the tooltip when component is on focus
* @author insolsoft-lab
*
*/
private class TooltipThread extends TimerTask
{

Object _notifyObject = new Object(); // Used to allow user to dismiss this Tooltip
PopupScreen _tooltip; // Screen we are going to display
UiApplication _ourApplication; // access to pushGlobalScreen and dismissStatus from our Application
int _displayTime; // in seconds

public TooltipThread(UiApplication ourApplication, PopupScreen tooltip, int displayTime)
{
_tooltip = tooltip;
_ourApplication = ourApplication;
_displayTime = displayTime;
}

public void run()
{
synchronized(Application.getEventLock())
{
_ourApplication.pushGlobalScreen(_tooltip, 999, false);
}
synchronized(_notifyObject) {
try {
_notifyObject.wait(_displayTime * 1000);
} catch (Exception e) {
}
};
_ourApplication.dismissStatus(_tooltip);
// _ourApplication.popScreen(_tooltip);
}

public void dismiss() {
// notify the waiting object to stop the Thread waiting
synchronized(_notifyObject)
{
_notifyObject.notify();
}
}

}

}

 

// Code Listing the menu bar 

this is how i invoke the toop tip 

// calendar properties
final ImageButtonField calendar = new ImageButtonField(Bitmap.getBitmapResource("calender.png"),0, "Calendar")
{

protected void onFocus(int direction)
{
this.setBorder(on_focus_border);
if ( _tooltip != null ) {
_tooltip.removeToolTip();
_tooltip = null;
}
this.getManager().getScreen().getFocusRect(rc);
// Display tooltip at 50,50 for 5 seconds
_tooltip = Tooltip.addToolTip(UiApplication.getUiApplication(), this.getTooltip(),rc.x -11 , rc.y+ this.getHeight()+6, 5);
}
protected void onUnfocus() {
this.setBorder(null);
if ( _tooltip != null ) {
// We have displayed a Tooltip - remove it
_tooltip.removeToolTip();
_tooltip = null;
}
}
};

Developer
Posts: 16,780
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: menubar paint issue because of tooltip thread

a popupscreen gets the control inputs from the user (click, scroll), so unless you shuffle them downward they get lost to your application.

that is the main reason our tooltips don't use popupscreens but are drawn directly on the screen by overwriting the screens paint method.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN

Re: menubar paint issue because of tooltip thread

so are you suggesting that i draw directly to the screen ? , but i observed that the twitter app uses a popupscreen .

Developer
Posts: 16,780
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: menubar paint issue because of tooltip thread

maybe they tunnel the inputs to the main application. or it just looks like a popupscreen, i don't know the app.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN

Re: menubar paint issue because of tooltip thread

i will use the paint approach and see if i would still have performance issues 

Developer
Posts: 16,780
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: menubar paint issue because of tooltip thread

we start a timertask with 500ms delay at onFocus, and cancel it onUnFocus. This avoids a lot of processing, especially when scrolling quickly.

the code you use has also several issues, for example a timertask is not a thread, and calling sleep on it is discouraged specifically in the API. using a global push for a tooltip is also incorrect as it blocks the whole device, not only your application.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter