11-04-2009 11:33 PM
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
Solved! Go to Solution.
11-16-2009 10:50 AM
Bump.
Anyone experience this?
11-18-2009 02:29 PM
BlackBerry smartphones only match one pattern. Once a match is found others will not be checked.
11-18-2009 03:36 PM
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?
11-18-2009 10:22 PM
Mark,
Interestingly enough, I found a post which you stated:
Possible bug regarding string patterns
MSohm wrote:Re: Possible Bug Found Regarding String Patterns12-05-2008 12:17 PM
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?
11-20-2009 12:47 PM
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(_MyCustomUrlDoSomethingMenuIt em);
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 "";
}
}
}