Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
erinliisa
Posts: 17
Registered: 11-02-2009
Accepted Solution

"Get Link" context menu item gone

Why is it that if you register a pattern with the pattern repository that will match on a url, your menu item appears and the default "Get Link" menu item is gone?

 

JDE 4.5

8330 (simulator)

Default CDMA Network

 

 

 

Please use plain text.
Developer
erinliisa
Posts: 17
Registered: 11-02-2009

Re: "Get Link" context menu item gone

Bump.

 

Anyone experience this?

Please use plain text.
Administrator
MSohm
Posts: 11,465
Registered: 07-09-2008
My Carrier: Bell

Re: "Get Link" context menu item gone

BlackBerry smartphones only match one pattern.  Once a match is found others will not be checked.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Please use plain text.
Developer
erinliisa
Posts: 17
Registered: 11-02-2009

Re: "Get Link" context menu item gone

That sure is a short-coming. 

 

So if another app is installed that uses a url pattern to to implement some functionality then most likely it will appear and mine and the system's get link will be gone?

 

I suppose implementing system wide pattern repository functionality isn't recommended that I should stick to string pattern and only implement inside my app?

Please use plain text.
Developer
erinliisa
Posts: 17
Registered: 11-02-2009

Re: "Get Link" context menu item gone

Mark,

Interestingly enough, I found a post which you stated:

Possible bug regarding string patterns


MSohm wrote:
Re: Possible Bug Found Regarding String Patterns
This is a limitation of using StringPatterns.  Multiple matches are supported by the PatternRepository, which is the recommended API to use. Mark Sohm
BlackBerry Development Advisor
www.BlackBerryDeveloper.com

I suppose I find this interesting because I was going to scrap the PatternRepository I am using for the StringPatternRepository but it sounds like it's just as broke when it comes to support for mulitple matches?

 

 

Please use plain text.
Developer
erinliisa
Posts: 17
Registered: 11-02-2009

Re: "Get Link" context menu item gone

So both PatterRepository and StringPatternRepository methods seem to make the "Get Link" system menu option disappear if you register a pattern that recognizes a url.

 

The way I got around this (finally!) is rather simple really: (may not be perfect)

 

1. In your screen class (extends MainScreen) override the method "makeMenu(Menu menu, int instance)".

2. Remove your custom menu item.

3. Figure out what control has focus (if you care about this).

4. Loop through each of the menu items after you call super.makeMenu(menu, instance) and look for a menu item that has the text "Get Link".  (I assume that if "Get Link" is there then this is some sort of url match)

5. Get the underlined/matched text and do something with it like if it matches a particular value or what not, add your menu item.

 

Example (proof of concept):

 

protected void makeMenu(Menu menu, int instance) {
   MenuItem m = null;
   String url = "";

   super.removeMenuItem(_MyCustomUrlDoSomethingMenuItem);
   super.makeMenu(menu, instance);
   
   if (_SomeGlobalVariableForAControl.isFocus()) {
      //if you care about what control has focus
      for (int i = 0; i < menu.getSize(); i++) {
         m = menu.getItem(i);
         if ((m != null) && (m.toString() != null) && (m.toString().trim().toLowerCase().equals("get link"))) {
             //this is the "Get Link" system menu item (I hope!)
             url = _SomeGlobalVariableForAControl.getUnderlinedUrl();
             menu.add(_MyCustomUrlDoSomethingMenuItem);
             return;
         }
      }
   }
}

//to get the underlined text
class CustomControl extends ActiveAutoTextEditField {
   public CustomControl(...) { ... }
   public String getUnderlinedUrl() {
      if (regionHasCookie()) {
         String url = getRegionText(getRegion());
         if (url == null) { return ""; }
         return url;
      } else {
         return "";
      }
   }
}

 

 

 

 

Please use plain text.