0

I have created a CustomToolTip with reference to earlier questions i asked on stack

Custom pop Up

and

Dialog creation

Now , i have created a CustomisedToolTip like as follows But the issue is the whole screen gets displayed or occupied the space i need such that the TextField on the previous screen be Active for that moment

The code for Customised Tool Tip i generated is as follows

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;


public class ToolTip extends PopupScreen{

     protected void applyTheme() {

        }

    private static VerticalFieldManager vfm=new VerticalFieldManager(Manager.NON_FOCUSABLE|Manager.FIELD_HCENTER){


        protected void paint(Graphics graphics) {

            graphics.setColor(0x00FFFFFF); 
            graphics.fillRect(0,0,getWidth(),getHeight());
            graphics.setColor(0x00000000);
            graphics.drawRect(0,0,getWidth(),getHeight());
            super.paint(graphics);

        }   


    };

    private LabelField lbl;
    private static int xPosition;
    private static int yPosition;
    private String message;
    private static Bitmap toolTipImg;
    private static BitmapField toolTipBmpFld;
    private static ButtonField button;
    public ToolTip(final String message,int xPos,int yPos,final Bitmap toolTipImg){
        super(vfm);
        this.xPosition=xPos;
        this.yPosition=yPos;
        this.message=message;
        this.toolTipImg=toolTipImg;


        button=new ButtonField(message,ButtonField.NON_FOCUSABLE){
            protected void paint(Graphics graphics) {
                graphics.drawBitmap(0,0, toolTipImg.getWidth(), toolTipImg.getHeight(), toolTipImg, 0, 0);
                super.paint(graphics);
            }
            protected void layout(int width, int height) {
                super.layout(width, height);
                setExtent( toolTipImg.getWidth(),  toolTipImg.getHeight());

            }
        };

        vfm.add(button);
    }

    protected void sublayout(int width, int height) {
        super.sublayout(width, height);
        setPosition(xPosition, yPosition);


    }

    protected boolean keyChar(char c, int status, int time) {
        // TODO Auto-generated method stub
        if(c==Characters.ESCAPE)
        {
            UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
        }
        return super.keyChar(c, status, time);
    }


}

Can i get a pop up like this in Blackberry

Tool Tip Image

4
  • I have not executed your code, but as i understand you might required to override getPreferredWidth() and getPreferredHeight() method.
    – Nilanchala
    Jun 15, 2012 at 8:37
  • For the class ToolTip ??/ But it extends PopupScreen and not Field Class
    – Yatin
    Jun 15, 2012 at 9:44
  • can i have even the images or the complete project. i could try ??
    – Nilanchala
    Jun 15, 2012 at 11:22
  • Yes ... you can try even with images. No problem But can it overlap over other fields is a problem to be seen as it acts as a field
    – Yatin
    Jun 15, 2012 at 11:32

2 Answers 2

2

Overriding the protected void paint(Graphics graphics) method of MainScreen can be helpful in this case.

When a Field get focus, you can tell the MainScreen (parent screen) to draw a tooltip on specified position after it completes it own drawing. And when the Field lost focus, you can avoid tooltip painting. Also a timer can be introduced for removing the tooltip after some time.

Check following implementation. The implementation needs to be improved, currently it's only represents my idea.

public final class MyScreen extends MainScreen implements TooltipProtocol {

    private TooltipProtocol tooltipProtocolInstance;
    public MyScreen() {
        tooltipProtocolInstance = this;
        ButtonField bfOne = getButtonField("ButtonField One", "Tooltip One", 200, 20);
        ButtonField bfTwo = getButtonField("ButtonField Two", "Tooltip Two", 200, 60);
        add(bfOne);
        add(bfTwo);
    }

    private ButtonField getButtonField(String text, final String tooltiptext, final int x, final int y) {
        ButtonField bf = new ButtonField(text) {
            protected void onFocus(int direction) {
                tooltipProtocolInstance.showToolTipText(tooltiptext, x, y);
                super.onFocus(direction);
            }
            protected void onUnfocus() {
                tooltipProtocolInstance.hideToolTipText();
                super.onUnfocus();
            }
        };
        return bf;
    }

    private String toolTipText;
    private int xTooptip;
    private int yTooptip;
    private Timer tooltipTimer;


    public void showToolTipText(String text, int x, int y) {
        toolTipText = text;
        xTooptip = x;
        yTooptip = y;
        if (tooltipTimer != null) {
            tooltipTimer.cancel();
            tooltipTimer = null;
        }
        tooltipTimer = new Timer();
        tooltipTimer.schedule(new TimerTask() {
            public void run() {
                hideToolTipText();
            }
        }, 2000);

        invalidate();
    }

    public void hideToolTipText() {
        toolTipText = null;
        invalidate();
    }

    protected void paint(Graphics graphics) {
        super.paint(graphics);
        if (toolTipText != null) {
            int oldColor = graphics.getColor();
            graphics.setColor(Color.GREEN);
            graphics.drawText(toolTipText, xTooptip, yTooptip);
            graphics.setColor(oldColor);
        }
    }
}

interface TooltipProtocol {
    public void showToolTipText(String text, int x, int y);
    public void hideToolTipText();
}



Following are output of the above code:

  • When first button got focus



  • When first button lost focus, second button got focus



  • When timer hides tooltip of the second button



1
  • Good example... nearly to what i want just that i need to implement it on EditField in Blackberry.. Hope it works I just need to make the works related to focus inside navigationalClick of Button which checks out the parameters of EditField and then depending on condition i will override the paint method of EditField ... i guess
    – Yatin
    Jun 18, 2012 at 13:47
0

As far I understand the question, you want to create a tool tip kind popup screen, but you want user to interact with your LoginScreen UI elements without blocking the whole screen by the tool tip.

This cannot be achievable in Blackberry. PropupScreen acts like a dialog. As we are pushing the instance of the popup screen to the screen stack to make it visually appear, it always block the delegate screen. Unless you remove the popup from the screen stack you cannot interact with your LoginScreen UI components, though they are visually available.

Visit Blackberry java docs for more details: http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/ui/container/PopupScreen.html

Edit:1

You can create a ToolTip screen giving the timer. You can google around and i am sure you will get many code samples. I have listed one link below.

http://v4ks1n.wordpress.com/2011/01/28/tooltips-class-for-blackberry/

12
  • So ?? i did not get your answer you just clarified my question a little bit or just rephrased my question
    – Yatin
    Jun 15, 2012 at 11:57
  • @YatinK. i said clearly this cannot be achievable in Blackberry.
    – Nilanchala
    Jun 15, 2012 at 12:27
  • Hmm ... can't this be done by overiding the paint() method too ?? Since, this application is being done in Andriod Or would you like to suggest any alternative
    – Yatin
    Jun 15, 2012 at 12:33
  • @YatinK. Paint method helps you for customization for the code. But hence this is nothing to do with the customization of your tooltip. Here the behavior of Blackberry screen stack is once a screen/propup screen pushed to current display then you cannot interact with the previous screen which was below. I mean for your requirement you can create a popup screen, and once it disappears after certain time period you just popout the ToolTip screen from the stack. That is only suggestible alternative for it.
    – Nilanchala
    Jun 15, 2012 at 12:40
  • I feel this is one of the enhancements that Blackberry have to make one
    – Yatin
    Jun 15, 2012 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.