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
sunil_garlapati
Posts: 69
Registered: ‎08-25-2008
My Device: Not Specified
Accepted Solution

Problem with Tooltip ?

[ Edited ]

Hi i have created tooltips for bitmapfields and these bimapfields are arranged in HorizontalFieldManager (same as FaceBook).  Iam using PopupScreen for showing tooltips.  But the problem is after i push the popupscreen then it will show tooltip after that i pop the popupscreen so tooltip will close. And the problem is after push the popupscreen, i pop that screen after 2seconds so at that 2 seconds of time iam unable to scroll over bitmapfilelds in horizontalfieldmanager.  So please help me to scroll the bitmapfields even the popupscreen is active also.

 

Iam using below code.

// This is class for my own tooltip which extends popupscreen class ZBBToolTip extends PopupScreen { int _x; int _y; public ZBBToolTip(Manager manager, int x, int y) { super(manager); _x = x; _y = y; } public void sublayout(int width, int height) { super.sublayout(width,height); setPosition(_x,_y); } protected void applyTheme() { System.out.println("Inside applyTheme"); } } //This method will come in main application public void addToolTip(String toolTipValue, int toolTipHPosition) { HorizontalFieldManager manager = new HorizontalFieldManager(Manager.FIELD_VCENTER|Manager.NON_FOCUSABLE) { public void paint(Graphics graphics) { graphics.setColor(Color.WHEAT); graphics.fillRect(0,0,getWidth(),getHeight()); graphics.setColor(Color.BLACK); graphics.drawRect(0,0,getWidth(),getHeight()); super.paint(graphics); } }; toolTip = new ZBBToolTip(manager,toolTipHPosition,50); LabelField label = new LabelField(" "+toolTipValue+" "); Font zbbFont = Font.getDefault().derive(Font.PLAIN, 16); label.setFont(zbbFont); manager.add(label); invokeLater(new Runnable() { public void run() { pushScreen(toolTip); } }); } public void removeToolTip() { synchronized(this.getAppEventLock()) { invokeLater(new Runnable() { public void run() { try{ Thread.sleep(2000); } catch (Exception e){} popScreen(toolTip); } }); } }

 

Message Edited by sunil_garlapati on 12-10-2008 03:53 AM
Message Edited by sunil_garlapati on 12-10-2008 03:54 AM
Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Problem with Tooltip ?

Once you push your popupscreen, it will take the focus.

 

I think you should take a different approach and simply paint the tooltips over your screen. it is a much lighter-weight implementation and will not affect your navigation focus.

 

 

 

 

 

Please use plain text.
Developer
sunil_garlapati
Posts: 69
Registered: ‎08-25-2008
My Device: Not Specified

Re: Problem with Tooltip ?

Thanks RexDoug,

 

I tried this tooltip By overriding the drawFocus() method of bitMapfield iam getting tooltip with in bitmapfield scope, and i need to display tooltip outside scope of bitmapfield.  Now i am trying to paint mainscreen but i dont know the approach how can i paint mainscreen (paint tooltip) while getting focus by bitmpafield.  Please help me to do this.

 

Advaced Thanks for any help.

 

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with Tooltip ?

Just a thought.  When you push the tooltip, do you use pushScreen or pushGlobalScreen.  If you use pushGlobalScreen, you get the opportunity to say that the Screen does not accept input (See next paragraph), and in my testing, if you do this, the underlying screen retains focus.  Sorry don't know if other events in the underlying screen get fired (e.g. onFocus()), but this might be something you can quickly try before going to the trouble of overwriting the Screen bitmap.

 

The method I am talking about is:

public void pushGlobalScreen(Screen screen, int priority, boolean inputRequired)

I appreciate that this method is deprecated, however I can't figure out what options to use on its replacement to do the same thing.  Any ideas?

 

Re how to write over the Screen, this Thread might be useful.

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=9795&query.id=161...

Please use plain text.
Developer
sunil_garlapati
Posts: 69
Registered: ‎08-25-2008
My Device: Not Specified

Re: Problem with Tooltip ?

Thanks peter_strange,

 

as per your suggestion i tried with 'pushGlobalScreen(Screen screen, int priority, boolean inputRequired)' and it is working like how i am expecting but problem is while calling the popScreen(toolTip) it is giving illegalStateException. Tooltip should close after 1 second of time so iam trying to pop the tooltip.  And another approach is paint the tooltip on mainScreen, for this is it needful to draw Bitmap again with tooltip, or draw tooltip only on screen enough?

 

I have strucked here please help me to achieve this.

 

class ZBBToolTip extends PopupScreen
{
    int _x;
    int _y;
    public ZBBToolTip(Manager manager, int x, int y)
    {
        super(manager);
        _x = x;
        _y = y;
     }
    public void sublayout(int width, int height)
    {
        super.sublayout(width,height);
        setPosition(_x,_y);
        System.out.println("!!!!!!!!!!TOOLTIP x::"+_x);
        System.out.println("!!!!!!!!!!TOOLTIP y::"+_y);
    }
                                            
    protected void applyTheme() {
        System.out.println("Inside applyTheme");
    }
} .....

......

 

ZBBToolTip toolTip; public void addToolTip(String toolTipValue, int toolTipHPosition) { HorizontalFieldManager manager = new HorizontalFieldManager(Manager.FIELD_VCENTER|Manager.NON_FOCUSABLE) { public void paint(Graphics graphics) { graphics.setColor(Color.WHEAT); graphics.fillRect(0,0,getWidth(),getHeight()); graphics.setColor(Color.BLACK); graphics.drawRect(0,0,getWidth(),getHeight()); super.paint(graphics); } }; toolTip = new ZBBToolTip(manager,toolTipHPosition,50); LabelField label = new LabelField(" "+toolTipValue+" "); Font zbbFont = Font.getDefault().derive(Font.PLAIN, 16); label.setFont(zbbFont); manager.add(label); invokeLater(new Runnable() { public void run() { pushGlobalScreen(toolTip, 0, false); } }); removeToolTip(); } public void removeToolTip() { synchronized(this.getAppEventLock()) { invokeLater(new Runnable() { public void run() { popScreen(toolTip); } }); } }

 

 

 
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with Tooltip ?

Apologies, yes the way to undo a pushGlobalScreen is the dismissStatus.  In your code, this will mean replacing

popScreen(toolTip);

with

dismissStatus(toolTip);

 

Let me know how you get on with this.

 

Also, can I would recommend that you change the priority in your tooltip from 0 to something larger, otherwise your tooltip may block a real warning Global Screens.  I would use a very large number, like 9999.  You only need it to be in front of your screen, you don't want to block any other Global Screen.  Sorry, I have no rational for the number to choose, but I would definitely not use a very low number. 

Please use plain text.
Developer
sunil_garlapati
Posts: 69
Registered: ‎08-25-2008
My Device: Not Specified

Re: Problem with Tooltip ?

[ Edited ]

Thanks alot peter_strange.

 

It is working properly now with out any exception.

 

and one more thing is after push the tooltip it will disappear after 1 second, for this i tried Thread.sleep(1000) but it is not right way why because while scrolling through the bitmapfields proper scrolling is not happening.  In FaceBook you can see after 1 second tooltip will disappear same behaviour i need to show.  If any body knows this please help me.

Message Edited by sunil_garlapati on 12-10-2008 01:23 PM
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with Tooltip ?

Can you attempt to explain to a luddite like myself who don't/can't install facebook, exactly what is wrong with what you are seeing?

 

Also I noted in your original implementation, that you had the sleep within your invokeLater, which I think means you are executing this while holding the Eventlock.  This is not recommended, basically because while you have the Eventlock, no UI events are processed.  So perhaps your problem is a result of this sleep? 

 

I would rework this processing, so that you start a separate Thread to process your tooltip.  This Thread would synchronize on the Eventlock, push the Global Screen, exit the synchronize, wait 1 second, then sychronize again and dismiss the Global Screen.  For the second it is stalled, it does NOT have the Eventlock, so normal UI processing can take place.  This Thread removes the need for your invokeLater processing. 

 

My suggestion above is not guaranteed to work, it is just the way I would try to do it.  but I suspect something like this is required.

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with Tooltip ?

You might find the following useful.  No warranty, use at your own risk. etc...

 

package ..; /* Display a 'Tooltip" (String) at a specified location for s specified time This Tooltip can also be removed. Note that in my testing, the display time is not consistent. Following example shows it being added and removed using focus events. ButtonField bf = new ButtonField("Test") { MyTooltip _tooltip; protected void onFocus(int direction) { if ( _tooltip != null ) { _tooltip.removeToolTip(); _tooltip = null; } // Display tooltip at 50,50 for 5 seconds _tooltip = MyTooltip.addToolTip(UiApplication.getUiApplication(), "Press to test", 50, 50, 5);; } protected void onUnfocus() { if ( _tooltip != null ) { // We have displayed a Tooltip - remove it _tooltip.removeToolTip(); _tooltip = null; } } }; */ import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.Manager; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.Font; import net.rim.device.api.ui.Screen; import net.rim.device.api.ui.component.LabelField; import net.rim.device.api.ui.container.VerticalFieldManager; import net.rim.device.api.ui.container.PopupScreen; class MyTooltip extends PopupScreen{ int _x; int _y; TooltipThread _tooltipThread; private MyTooltip(Manager manager) { super(manager); } public void sublayout(int width, int height) { super.sublayout(width,height); setPosition(_x,_y); System.out.println("Tooltip x: " + Integer.toString(_x) + ", y: " + Integer.toString(_y)); } protected void applyTheme() { // Overriden to suppress Border etc. } public void removeToolTip() { if ( _tooltipThread != null ) { _tooltipThread.dismiss(); } } private void display(UiApplication uiApp, int x, int y, int displayTime) { _x = x; _y = y; _tooltipThread = new TooltipThread(uiApp, this, displayTime); _tooltipThread.start(); } public static MyTooltip addToolTip(UiApplication uiApp, String toolTipString, int x, int y, int displayTime) { VerticalFieldManager manager = new VerticalFieldManager(Manager.FIELD_VCENTER|Manager.NON_FOCUSABLE) { protected void paint(Graphics graphics) { graphics.setColor(0x00FFFFFF); // White graphics.fillRect(0,0,getWidth(),getHeight()); graphics.setColor(0x00000000); // Black graphics.drawRect(0,0,getWidth(),getHeight()); super.paint(graphics); } }; MyTooltip toolTip = new MyTooltip(manager); LabelField label = new LabelField(' ' + toolTipString + ' ', LabelField.NON_FOCUSABLE); label.setFont(Font.getDefault().derive(Font.PLAIN, 16)); toolTip.add(label); toolTip.display(uiApp, x, y, displayTime); return toolTip; } class TooltipThread extends Thread { 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() { _ourApplication.pushGlobalScreen(_tooltip, 999, false); synchronized(_notifyObject) { try { _notifyObject.wait(_displayTime * 1000); } catch (Exception e) { } }; _ourApplication.dismissStatus(_tooltip); } public void dismiss() { // notify the waiting object to stop the Thread waiting synchronized(_notifyObject) { _notifyObject.notify(); } } } }

 

 

Please use plain text.
Developer
simon_hain
Posts: 16,134
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Problem with Tooltip ?

the undisplay can be done with a timertask (a bit more elegant).
the bad thing about popups is that they are not correctly scrolled (etc).
----------------------------------------------------------
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
Please use plain text.