Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Active text field sample app

The active text field sample application shows how a BlackBerry device user can access customized items from the context menu when a pattern is recognized in an active text field. You can create active text fields by using the ActiveAutoTextEditField class and ActiveRichTextField class.

When the BlackBerry device starts, the application, pattern, and associated menu items are registered with the PatternRepository. When text with the matching pattern is found in an active text field, the text is highlighted. When the user clicks highlighted text, the context menu is displayed with the menu items that are associated with the pattern.

In the sample application, when the user types a nine-digit number into an active text field, the user can click this number and a context menu with Status and Location options appears. When the user clicks one of the options, the application displays the requested information.

File name

Description

ActiveTextFieldsDemo.java

  • Contains the entry point for the sample application.
  • Contains the ActiveTextFieldsDemo() constructor that creates and displays the ActiveTextFieldsScreen screen.
  • Contains the inner class ActiveTextFieldsScreen that creates, adds, and displays ActiveAutoTextEditFields and their associated labels.
  • Registers a regular expression with the PatternRepository when the BlackBerry device starts so that context menu items become available when a pattern is found in any active text field in any application on the device.

This sample features the following classes:

net.rim.device.api.ui.component.ActiveAutoTextEditField

This active text field is supplied with a set of string patterns from the PatternRepository.

In the sample application, any nine-digit number that a BlackBerry device user types in the ActiveAutoTextEditField is highlighted and can be clicked to access the Status and Location menu items.

net.rim.device.api.system.ApplicationDescriptor

This class is used to register an ApplicationDescriptor for this application. When an application descriptor is created, it is used to identify this application.

net.rim.blackberry.api.stringpattern.PatternRepository

This class provides the ability to register a pattern with an application. The menu items that are registered with the pattern will become available in the context menu when a String matching the provided pattern is found in any active field.

In the sample application, the Status and Location menu items become available when the user clicks a nine-digit number in any active field in any application.

net.rim.blackberry.api.menuitem.ApplicationMenuItem

In the sample application, menu items are created and stored in an array. This array of menu items, along with a pattern and application descriptor, is passed into PatternRepository.addPattern(), which adds and registers the menu items so that they appear in the context menu when a pattern is found.

Install the sample app

In the BlackBerry Java Development Environment, open the workspace that you want to add the sample application to.

In workspace tree, the right-click the <workspace> icon.

Click Add project to <workspace> .

In the Add project to <workspace> dialog box, browse to the activetextfieldsdemo folder. The default location of the folder is C:\Program Files\Research In Motion\BlackBerry JDE 5.0.0\samples\com\rim\samples\device\activetextfieldsdemo.

Click the ActiveTextFieldsDemo.jdp file.

Click Open.

The sample is also available in github.

Run the sample app

In the workspace where you added the activetextfieldsdemo project, right-click activetextfieldsdemo.

Click Build project.

On the taskbar, click Start > Applications > Research in Motion > BlackBerry JDE 5.0 > Device Simulator.

On the Home screen of the BlackBerry Smartphone Simulator, click the Downloads folder.

Click the Active Text Fields Demo icon.