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.

Touch event injector sample app

The touch event injector sample application demonstrates how to programmatically create, invoke, and handle touch events, such as a click of the screen on a BlackBerry device with a touch screen.

File name

Description

TouchEventInjectorDemo.java

This file contains the application, including the application's entry point. The entry point starts the application, checks if the device has a touch screen, and if it does, the entry point displays the TouchEventInjectorScreen.

TouchEventInjectorScreen.java

This file performs the following actions in the sample application:

  • creates and adds the menu items that create and inject each of the touch events into the application
  • creates and displays a sample ButtonField component, which the application uses to demonstrate how to handle UI component events
  • overrides the touchEvent() method, which captures and handles touch events

This sample features the following classes:

net.rim.device.api.system.EventInjector

This class provides the method invokeEvent() for injecting UI events into a BlackBerry device application.

This class contains the subclasses Event, KeyCodeEvent, KeyEvent, NavigationEvent, TouchEvent and TrackWheelEvent. These subclasses represent different UI events on a BlackBerry device.

The sample application uses the invokeEvent() method to inject the TouchEvent objects that the sample application creates.

net.rim.device.api.system.EventInjector.TouchEvent

This class represents a UI event on a BlackBerry device with a touch screen.

In addition to allowing you to create discrete touch events such as clicking and unclicking the touch screen, this class also provides you with the following methods, which inject a series of touch events when they are invoked:

Method

Description

Sequence of generated events

injectSwipeGesture(int originX, intOriginY, EventInjector.TouchEvent[] moveEvents)

This method simulates the series of events that occur when a user slides a finger on the touch screen starting at the position (originX, originY) and moves along the screen as defined by the moveEvents array.

  1. DOWN at (originX, originY)
  2. MOVE at the position that the first move event in moveEvents array specifies if moveEvents is not null; event occurs for each TouchEvent entry in the moveEvents array
  3. SWIPE event
  4. UP at (originX, originY)

injectTapGesture(int x, int y, int taps)

This method simulates the series of events that occur when a user touches the screen lightly a number of times (specified by the taps parameter) at the position (x, y).

  1. DOWN at (x1, y1)
  2. TAP at (x1, y1); event repeats the number of times that the taps parameter specifies
  3. UP at (x1, y1)
injectTwoFingerTap(int x1, int y1, int x2, int y2, int touchpoint)

This method simulates the series of events that occur when a user simultaneously touches the screen with two fingers. The first finger touches the screen at the position (x1, y1) and the second finger touches the screen at the position (x2, y2).

The touchpoint parameter specifies which finger's position specifies the position of the TAP gesture.

If touchpoint equals 1, the following events occur:

  1. DOWN at (x1, y1)
  2. DOWN at (x2, y2)
  3. TAP at (x1, y1)
  4. UP at (x1, y1)
  5. UP at (x2, y2)

If touchpoint equals 2, the following events occur:

  1. DOWN at (x1, y1)
  2. DOWN at (x2, y2)
  3. TAP at (x2, y2)
  4. UP at (x2, y2)
  5. UP at (x1, y1)
invokeClickThrough(int x1, int y1, int x2, int y2)

This method simulates the series of events that occur when a user clicks the touch screen at the position (x1, y1).

If you specify the position (x1, y1) as (-1, -1), the click occurs at the position (x2, y2).

If (x1, y1) does not equal (-1, -1), the following events occur:

  1. DOWN at (x1, y1)
  2. CLICK at (x1, y1)
  3. UNCLICK at (x1, y1)
  4. UP at (x1, y1)

If (x1, y1) equals (-1, -1), the following events occur:

  1. DOWN at (x2, y2)
  2. CLICK at (x2, y2)
  3. UNCLICK at (x2, y2)
  4. UP at (x2, y2)

Install the sample app

Visit http://www.blackberry.com/go/toucheventinjectorsampleapp to download the sample application.

Extract the toucheventinjectordemo.zip file.

On the taskbar, click Start > Programs > Research In Motion > BlackBerry JDE 5.0 > JDE.

Open the workspace that you want to add the sample application to.

In the workspace tree, right-click the project that you want to add the sample application to.

Click Add project to <workspace directory>.

In the Add project to <workspace> dialog box, browse to the folder where you extracted the sample application.

Click the TouchEventInjectorDemo.jdp file.

Click Open.

The sample app is also available in github.

Run the sample app

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

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 TouchEventInjectorDemo icon.