If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
Contributor
donwany1
Posts: 13
Registered: ‎01-01-2013
My Device: BlackBerry Torch 9810
My Carrier: simple mobile
Accepted Solution

LINKS in blackberry dev

CAN ANYONE HELP ME  CREATE A LINK WHERE USERS CLICK ON IT AND THEN SENDS THEM TO ANOTHER WEB SITE OR A NEW SCREEN JUST AS IN ( <a href ="google.com">continue</a> )

 

 

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

Re: LINKS in blackberry dev

[ Edited ]

Just to confirm, you want to do this and display the short form on the BBOS device and have the user click on that and it will take them to the other web site.  I presume also this will be included along with other 'text'. 

 

ActiveTextFields will do that but you have to put the full URL in them.

 

The only way to get the abbreviated text displayed for is to add a BrowserFieldI would not recommend doing that unless you intended to use a BrowserField for the whole screen

 

You can create other hot links in ActiveTextFields using the pattern matching, see here:

http://supportforums.blackberry.com/t5/Java-Development/Leverage-pattern-matching-in-BlackBerry-smar...

Please use plain text.
Regular Contributor
amr3434
Posts: 81
Registered: ‎01-16-2012
My Device: BOLD 9650 + developer
My Carrier: Vodafone

Re: LINKS in blackberry dev

you can use 
HyperlinkButtonField  in the third party API 

exp:

HyperlinkButtonField  testHyperLink=

new HyperlinkButtonField("test txt", 0x0000FF, 0xFFFFFF, 0x0000FF, 0,
0, FIELD_HCENTER);

testHyperLink.setChangeListener(new FieldChangeListener() {

public void fieldChanged(Field field, int context) {
//do logic 
Browser.getDefaultSession().displayPage(url);
}
});

notes : url must be full path  :smileyhappy:




Please use plain text.
Contributor
donwany1
Posts: 13
Registered: ‎01-01-2013
My Device: BlackBerry Torch 9810
My Carrier: simple mobile

Re: LINKS in blackberry dev

How so I reference the third party api ?

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

Re: LINKS in blackberry dev

Please use plain text.
Regular Contributor
amr3434
Posts: 81
Registered: ‎01-16-2012
My Device: BOLD 9650 + developer
My Carrier: Vodafone

Re: LINKS in blackberry dev

/*
 * HyperlinkButtonField.java
 */

import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.LabelField;

public class HyperlinkButtonField extends LabelField {
	// text color
	private int textColour;
	// text focus color
	private int textColourFocus;
	// highlight color
	private int highlightColour;

	private int menuOrdinal;
	private int menuPriority;

	private XYRect tmpRect = new XYRect();

	public HyperlinkButtonField(String text, int textColour,
			int highlightColour, int menuOrdinal, int menuPriority) {
		this(text, textColour, textColour, highlightColour, menuOrdinal,
				menuPriority);
	}

	public HyperlinkButtonField(String text, int textColour,
			int textColourFocus, int highlightColour, int menuOrdinal,
			int menuPriority) {
		this(text, textColour, textColourFocus, highlightColour, menuOrdinal,
				menuPriority, 0);
	}

	public HyperlinkButtonField(String text, int textColour,
			int textColourFocus, int highlightColour, int menuOrdinal,
			int menuPriority, long style) {
		super(text, Field.FOCUSABLE | style);

		this.textColour = textColour;
		this.textColourFocus = textColourFocus;
		this.highlightColour = highlightColour;
		this.menuOrdinal = menuOrdinal;
		this.menuPriority = menuPriority;
	}

	public HyperlinkButtonField(String text, int textColour,
			int textColourFocus, int highlightColour, long style) {
		super(text, Field.FOCUSABLE | style);

		this.textColour = textColour;
		this.textColourFocus = textColourFocus;
		this.highlightColour = highlightColour;
		this.menuOrdinal = 0;
		this.menuPriority = 0;
	}

	public HyperlinkButtonField(String text, int textColour,
			int textColourFocus, int highlightColour) {
		super(text, Field.FOCUSABLE);

		this.textColour = textColour;
		this.textColourFocus = textColourFocus;
		this.highlightColour = highlightColour;
		this.menuOrdinal = 0;
		this.menuPriority = 0;
	}

	public void applyFont() {
		Font underlineFont = getFont().derive(Font.UNDERLINED);
		setFont(underlineFont);
	}

	protected void paint(Graphics g) {
		int oldColour = g.getColor();
		try {
			if (g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) {
				g.setColor(textColourFocus);
			} else {
				g.setColor(textColour);
			}
			super.paint(g);
		} finally {
			g.setColor(oldColour);
		}
	}

	protected void drawFocus(Graphics g, boolean on) {
		getFocusRect(tmpRect);

		boolean oldDrawStyleFocus = g
				.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS);
		int oldBackgroundColour = g.getBackgroundColor();

		boolean notEmpty = g.pushContext(tmpRect.x, tmpRect.y, tmpRect.width,
				tmpRect.height, 0, 0);
		try {
			if (notEmpty) {
				if (on) {
					g.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true);
					g.setBackgroundColor(highlightColour);
				}
				g.clear();
				paint(g);
			}
		} finally {
			g.popContext();
			g.setBackgroundColor(oldBackgroundColour);
			g.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, oldDrawStyleFocus);
		}
	}

	protected boolean keyChar(char character, int status, int time) {
		if (character == Characters.ENTER) {
			fieldChangeNotify(0);
			return true;
		}
		return super.keyChar(character, status, time);
	}

	protected boolean trackwheelClick(int status, int time) {
		keyChar(Characters.ENTER, status, time);
		return true;
	}

	protected boolean invokeAction(int action) {
		switch (action) {
		case ACTION_INVOKE: {
			fieldChangeNotify(0);
			return true;
		}
		}
		return super.invokeAction(action);
	}

	public void setDirty(boolean dirty) {
		// We never want to be dirty or muddy
	}

	public void setMuddy(boolean muddy) {
		// We never want to be dirty or muddy
	}

	public String getMenuText() {
		return getText();
	}

	/**
	 * Returns a MenuItem that could be used to invoke this link.
	 */
	public MenuItem getMenuItem() {
		if (menuOrdinal < 0 || menuPriority < 0) {
			return null;
		}
		return new MenuItem(getMenuText(), menuOrdinal, menuPriority) {
			public void run() {
				fieldChangeNotify(0);
			}
		};
	}

}

 enjoy it .. and u can find third party resource if u search here  
it's rich GUI 

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

Re: LINKS in blackberry dev

Please use plain text.