Yatin
Yatin

Reputation: 3120

ToolTip Customisation

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

Upvotes: 0

Views: 581

Answers (2)

Rupak
Rupak

Reputation: 3674

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



Upvotes: 2

Nilanchala
Nilanchala

Reputation: 5941

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/

Upvotes: 0

Related Questions