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
Highlighted
New Developer
Posts: 8
Registered: ‎10-30-2008
My Device: Not Specified

On a browser field, how to enable RETURN key to handle "Get Link" command

[ Edited ]

I have an application using the browser field to display web pages. When a hyperlink on the page is highlighted, the menu item "Get link" gets added which can pull in the link. However, clicking the "Enter" key (on the simulator) does not invoke the link (which it does on the regular BB browser) - similarly, cpressing the trackball also does not invoke the link as it does in the regular BB browser. How to enable this feature.

 

Also, is it possible to change the cursor to a "pointed hand" cursor when the cursor is on a hyperlink (like it does on a regular BB browser)?

 

Thanks

Message Edited by anurosh on 11-05-2008 10:28 AM
New Developer
Posts: 8
Registered: ‎10-30-2008
My Device: Not Specified

Re: On a browser field, how to enable RETURN key to handle "Get Link" command

This is not an elegant solution, but currently I have this working as:

 

 

public boolean keyChar(char arg0, int arg1, int arg2) { if(arg0==Characters.ENTER) { Menu menu = this.getMenu(0); int size = menu.getSize(); for(int i=0; i<size; i++) { MenuItem item = menu.getItem(i); String label = item.toString(); if(label.equals("Get Link")) { item.run(); } } } }

Obviously, one major limitation is the code label.equals("Get Link"), "Get Link" may be in another language, or changed in the future. Is it possible to get this menu item in a language neutral way?

 

 

New Developer
Posts: 5
Registered: ‎12-10-2008
My Device: Not Specified

Re: On a browser field, how to enable RETURN key to handle "Get Link" command

HI

 

I need code example of blackberry browser,

I get it from book but it cant run

can you send it to me 3 files of that one on my mail id : bhaumik_svit@yahoo.com

 

thanks

 

 

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: On a browser field, how to enable RETURN key to handle "Get Link" command

It turns out this IDEA may not be that klugey in that if you just take the default selection

and run that, it will I would guess do what was intended while avoiding the intermediate menu.

I too test for the "Get Link" option but it seems a lot of other defaults

could be selected at this time. I also noticed a rather funny thing

in that if the default is "Email" or "Call" it includes the target

in the string, possible usage as spyware and something to know about maybe.

 

New Developer
Posts: 19
Registered: ‎12-11-2009
My Device: Not Specified

Re: On a browser field, how to enable RETURN key to handle "Get Link" command

 


Hey, I have the very same problem and the solution posed here  appears fairly acceptable.

In what class do I override the public void keyChar(char key, int status, int time), because the Field that is returned from

the following:

 

browserContent.getDisplayableContent()

 

returns the generic type Field, which is an abstract class. It would make no sense to implement the keyChar in any of the parent-classes, as they don't have the focus, nor the links, and I cannot subclass the inner HttpBrowserField that getDisplayableContent() returns.

 

Could you tell me this little detail?

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: On a browser field, how to enable RETURN key to handle "Get Link" command

Normally I add to a screen and do the key char thing from the screen class. Alternatively, I'm not sure if it will make it past security but I guess if you know what class is being returned, print the class name from the debugger or real app, you could stub it out to fool the compiler and cast to that type but I'm not sure what jvm would do on a real device- may work or could be catastophic dunno.

 

New Developer
Posts: 19
Registered: ‎12-11-2009
My Device: Not Specified

Re: On a browser field, how to enable RETURN key to handle "Get Link" command

 

Nice thinking outside the box, mate.

I found that that is a requirement in order to work with the Blackberry API.

Things are not always... as easy as on other platforms.

 

I solved this one by overriding the makeMenu-function in the class that extends the MainScreen, and overriding the onMenu(int instance) to return false and run the menu-item that I want through MenuItem.run().

 

Thanks for the response.

 

 

New Developer
Posts: 19
Registered: ‎12-11-2009
My Device: Not Specified

Re: On a browser field, how to enable RETURN key to handle "Get Link" command

For those of you with the same problem:

you cannot use the keychar-functionality to disable this popup, because it is not a traditional Context Menu, and it is not handled in the MainScreen or Screen class, but rather (I suspect) in the BrowserField itself.

 

So what you CAN do is stop all context-menu's from ever popping up by overriding the aforementioned functions, so that only the main menu will work, and then getting the appropriate MenuItem and running that.

New Developer
Posts: 1
Registered: ‎12-30-2009
My Device: Not Specified

Re: On a browser field, how to enable RETURN key to handle "Get Link" command

Jasper - Could you provide an example of exactly what you mean?  I'm a bit of a BB newb and would appreciate a few more pointers about exactly which elements  you're recommending we alter.

New Developer
Posts: 19
Registered: ‎12-11-2009
My Device: Not Specified

Re: On a browser field, how to enable RETURN key to handle "Get Link" command

[ Edited ]

Happy new year, mate Smiley Happy

 

If you mean to ask what to change in order for this to work:

Override the following two functions in your Screen -class (you should have a class that extends Screen, implements RenderingApplication and contains or uses a RenderingSession object to display the content):

  • onMenu(int instance)
    You can use the instance to detect wether it is a context menu or the main menu. The context menu is the popup I was trying to block. Once you detect it is a context menu, check if you want to block it or not and open the link manually
  • makeMenu(Menu menu, int instance)
    Override this if you want to customize the position, remove and add elements to the menu. I suppose you could do it in different positions in the code, but it will contain new menu-items if you don't override this, which might make it confusing if you iterate over the menu at a different point in the process. If you want to keep those new items, call the super.makeMenu(Menu menu, int instance).