background image

    Dialog.alert("First finger touched/moved");

   }

   if(message.getX(2) > 0 && message.getY(2) > 0) {

    Dialog.alert("Second finger touched/moved");

   }

   return true;

  }

  return false;

}              

Keyboard on a BlackBerry device with a touch screen

A BlackBerry device application can have more that one 

Screen

. Each 

Screen

 has one touch screen keyboard.

Change the state of the keyboard on a BlackBerry device with a touch screen

1.

Import the following classes:

net.rim.device.api.ui.VirtualKeyboard

• a 

screen

 class, such as 

net.rim.device.api.ui.container.MainScreen

2.

Create an instance of 

VirtualKeyboard

.

VirtualKeyboard virtKbd;

3.

Store an instance of a 

Screen

 class.

MainScreen _screen = new MainScreen( MainScreen.VERTICAL_SCROLL );

4.

Invoke 

getVirtualKeyboard()

 and store the return value in the 

VirtualKeyboard

 variable.

virtKbd = _screen.getVirtualKeyboard();

5.

Perform one of the following tasks:

Task

Steps

Retrieve the state of the touch screen
keyboard.

Invoke 

VirtualKeyboard.getVisibility()

.

Change the state of the touch screen
keyboard.

Invoke 

VirtualKeyboard.setVisibility(int)

.

Inherit the state of the touch screen
keyboard.

Invoke 

VirtualKeyboard.setVisibility

(Virtual Keyboard.IGNORE)

.

Display the keyboard on a BlackBerry device with a touch screen

1.

Import the following classes:

Development Guide

Keyboard on a BlackBerry device with a touch screen

40

Summary of Contents for JAVA DEVELOPMENT ENVIRONMENT

Page 1: ...BlackBerry Java Development Environment Version 4 7 0 Development Guide...

Page 2: ...SWD 549284 1212112738 001...

Page 3: ...ckBerry device 12 Types of accelerometer data 12 Accelerometer 12 Retrieve accelerometer data at specific intervals 13 Query the accelerometer when the application is in the foreground 13 Query the ac...

Page 4: ...on 28 Register a menu item 28 Arrange UI components 29 Create a layout manager 29 Align a field to a line of text 30 UI events 30 Respond to UI navigation events 30 Determine the type of input method...

Page 5: ...collection listener that notifies the system when a collection changes 50 Notify the system when a collection changes 51 Runtime storage 51 Retrieve the runtime store 51 Add an object in the runtime s...

Page 6: ...5 4 Managing applications 66 Application manager 66 Retrieve information about a BlackBerry Java Application 66 Communicate with another BlackBerry Java Applications 66 Determine the services that are...

Page 7: ...ignatures 82 Request a code signature 83 Register a signature key using a proxy server 83 Sign an application using a proxy server 84 View the signature status for an application 84 Using keys to prot...

Page 8: ...ith the BlackBerry Desktop Software 93 Elements in BlackBerry device application alx file 93 Properties of BlackBerry device application jad files 98 Application distribution through a computer connec...

Page 9: ...omplex input methods such as international keyboards For seamless integration of the different input methods extend Field or one of its subclasses Do not use Screen objects for typing text For knowled...

Page 10: ...lays a screen it pushes the screen to the top of the stack When a BlackBerry Java Application closes a screen it removes the screen off the top of the stack and displays the next screen on the stack r...

Page 11: ...e then create a rectangular clipping region by creating an XYRect object using the XYPoint objects We invoke Graphics pushContext to push the rectangular clipping region to the context stack We invoke...

Page 12: ...d where the left right top bottom front or back of the device are furthest from the ground Direction refers to the top of the drawing area of the screen relative to the location of the BlackBerry logo...

Page 13: ...when a drawable area of the touch screen changes 1 Import the javax microedition lcdui Canvas class 2 Extend javax microedition lcdui Canvas 3 Override Canvas sizeChanged int int protected void sizeC...

Page 14: ...eleration The acceleration of the rotation of the BlackBerry device For more information about types of data from the accelerometer see the API reference for the BlackBerry Java Development Environmen...

Page 15: ...with three elements short xyz new short 3 4 Create a thread while running 5 Invoke Channel getLastAccelerationData short to retrieve data from the accelerometer rawDataChannel getLastAccelerationData...

Page 16: ...channelConfig 5 Invoke Thread sleep to specify the interval between queries to the accelerometer in milliseconds short xyz new short 3 while running channel getLastAccelerationData xyz Thread sleep 50...

Page 17: ...ometerData getXAccHistory AccelerometerData getYAccHistory and AccelerometerData getZAccHistory to retrieve accelerometer data from the buffer for each axis short xAccel accData getXAccHistory short y...

Page 18: ...PopupScreen manageLayout Creat a bitmap 1 Import the net rim device api ui component BitmapField class 2 Create an instance of a BitmapField BitmapField myBitmapField new BitmapField Create a button 1...

Page 19: ...io InputStream net rim device api io LineReader java lang String 2 Import the net rim device api ui component KeywordProvider interface 3 Create variables In the following code sample CountryList exte...

Page 20: ...der new LineReader stream 14 Read data from the input stream one line at a time until you reach the end of file flag Each line is parsed to extract data that is used to construct Country objects for O...

Page 21: ...im device api ui component RadioButtonField 2 Create an instance of a RadioButtonGroup RadioButtonGroup rbGroup new RadioButtonGroup 3 Create an instance of a RadioButtonField for each option you want...

Page 22: ...SE Create an editable text field that allows special characters 1 Import the net rim device api ui component EditField class 2 Create an instance of an EditField EditField edit new EditField EditField...

Page 23: ...belField title new LabelField UI Component Sample LabelField ELLIPSIS Create a list from which users can select multiple items 1 Import the following classes java lang String net rim device api ui com...

Page 24: ...api ui component TreeFieldCallback interface 3 Implement the TreeFieldCallback interface 4 Invoke TreeField setExpanded on the TreeField object to specify whether a folder is collapsible In the follo...

Page 25: ...eld net rim device api ui container MainScreen 2 Create an instance of a UI component CheckboxField myCheckbox new CheckboxField First checkbox true 3 Add the UI component to your extension of a Scree...

Page 26: ...rmine how the field arranges its contents in the available space In the following code sample we invoke Math min to return the smaller of the specified width and height and the preferred width and hei...

Page 27: ...labelHeight 1 else return _labelWidth case RECTANGLE return _labelHeight 4 case OCTAGON return getPreferredWidth return 0 8 Implement paint The manager of a field invokes paint to redraw the field whe...

Page 28: ...ics drawLine 0 x x 0 graphics drawLine 0 x2 x x3 graphics drawLine x2 0 x3 x graphics drawLine x2 x3 x3 x2 textWidth Math min _labelWidth w 6 textX w textWidth 1 textY w _labelHeight 1 break case RECT...

Page 29: ...A higher number means that the menu item appears lower in the menu SampleMenuItem super 20 5 Implement toString to specify the menu item text In the following code sample we implement toString to disp...

Page 30: ...m contactsDemoMenuItem new ContactsDemoMenuItem 3 Invoke ApplicationMenuItemRepository getInstance to retrieve the BlackBerry device application repository ApplicationMenuItemRepository repository App...

Page 31: ...en net rim device api ui Manager net rim device api ui container VerticalFieldManager net rim device api ui component BitmapField net rim device api ui container HorizontalFieldManager net rim device...

Page 32: ...ckwheelListener If your existing BlackBerry device application implements the TrackwheelListener update your BlackBerry device application to use the new Screen navigation methods 1 Import the net rim...

Page 33: ...s see the API reference for the class net rim device api system KeypadListener Respond to BlackBerry device user interaction 1 Import the net rim device api ui Screen class 2 Use the Screen class and...

Page 34: ...SWIPE_SOUTH Sliding a finger up quickly displays the next screen Sliding a finger down quickly displays the previous screen When the keyboard appears sliding a finger down quickly hides the keyboard a...

Page 35: ...im device api ui Field net rim device api ui Manager net rim device api ui Screen 2 Create a class that extends the Manager class the Screen class the Field class or one of the Field subclasses public...

Page 36: ...n TouchGesture SWIPE_NORTH Dialog alert Upward swipe occurred return true return false Respond to a user sliding a finger down quickly on the screen 1 Import the following classes net rim device api u...

Page 37: ...at extends the Manager class the Screen class the Field class or one of the Field subclasses public class newButtonField extends ButtonField 3 In your implementation of the touchEvent TouchEvent messa...

Page 38: ...getSwipeDirection returns is equal to TouchGesture SWIPE_WEST protected boolean touchEvent TouchEvent message switch message getEvent case TouchEvent GESTURE TouchGesture gesture message getGesture sw...

Page 39: ...evice api ui Screen 2 Create a class that extends the Manager class the Screen class the Field class or one of the Field subclasses public class newButtonField extends ButtonField 3 In your implementa...

Page 40: ...d return true return false Respond to a user touching the screen lightly 1 Import the following classes net rim device api ui TouchEvent net rim device api ui TouchGesture net rim device api ui Field...

Page 41: ...t case TouchEvent MOVE return true return false Respond to a user touching the screen in two locations at the same time 1 Import the following classes net rim device api ui TouchEvent net rim device a...

Page 42: ...oard VirtualKeyboard virtKbd 3 Store an instance of a Screen class MainScreen _screen new MainScreen MainScreen VERTICAL_SCROLL 4 Invoke getVirtualKeyboard and store the return value in the VirtualKey...

Page 43: ...Visibility int usingoneofthe following constants as a parameter VirtualKeyboard SHOW or VirtualKeyboard SHOW_FORCE Hide the keyboard on a BlackBerry device with a touch screen 1 Import the following c...

Page 44: ...ent Environment version 4 3 1 Add spell check functionality 1 Import the following classes net rim blackberry api spellcheck SpellCheckEngineFactory java lang StringBuffer 2 Import the following inter...

Page 45: ...i Field 2 Import the following interfaces net rim blackberry api spellcheck SpellCheckUIListener net rim blackberry api spellcheck SpellCheckEngine 3 Create a method that returns the SpellCheckUIListe...

Page 46: ...lledWordFound SpellCheckUI ui Field field int offset int len UiApplication getUiApplication invokeLater new popUpRunner Misspelled word found return SpellCheckUIListener ACTION_OPEN_UI Development Gui...

Page 47: ...e that runs BlackBerry Device Software version 4 2 or later provides a traditional file system and support for saving content directly to the file system using JSR 75 APIs With either the BlackBerry P...

Page 48: ...e static PersistentObject and invoke PersistentStore getPersistentObject using the unique long key as a parameter static PersistentObject store static store PersistentStore getPersistentObject 0xa1a56...

Page 49: ...re getContents if currentinfo null Dialog alert _resources getString APP_ERROR else currentusernamefield setText currentinfo 0 currentpasswordfield setText currentinfo 1 Remove persistent data If you...

Page 50: ...data length Retrieve a record from a record store 1 Import the following classes javax microedition rms RecordStore java lang String 2 Invoke getRecord int byte int Pass the following parameters a rec...

Page 51: ...nization SyncCollection interface 3 To provide the BlackBerry device application with access to the newest SyncCollection data from the PersistentStore invoke the PersistentStore getPersistentObject m...

Page 52: ...entSource addCollectionListener method making sure the method adds a CollectionListener to the Vector that contains listeners In the following code sample we implement CollectionEventSource addCollect...

Page 53: ...on invoke CollectionListener elementAdded for int i 0 i _listeners size i CollectionListener cl CollectionListener _listeners elementAt i cl elementAdded this object return true 3 To notify the system...

Page 54: ...entException e Replace an object in the runtime store 1 Import the following classes net rim device api system RuntimeStore java lang String net rim device api system ControlledAccessException 2 Invok...

Page 55: ...8L catch ControlledAccessException e Retrieve an unregistered runtime object 1 Import the following classes net rim device api system RuntimeStore net rim device api system ControlledAccessException j...

Page 56: ...BlackBerry Enterprise Server is the gateway for all wireless network traffic including traffic destined for the Internet If your application connects to the Internet and you are targeting non enterpr...

Page 57: ...erageStatusListener javax microedition io StreamConnection 3 Use the CoverageInfo class and CoverageStatusListener interface of the net rim device api system package to verify that the BlackBerry devi...

Page 58: ...getBytes 0 login length false false 11 Invoke HTTPConnection setRequestProperty using the encoded login information to access the protected resource s StreamConnection Connector open http mysite com m...

Page 59: ...red HttpsConnection stream HttpsConnection Connector open https host 443 EndToE Use a socket connection Although you can implement HTTP over a socket connection you should use an HTTP connection for t...

Page 60: ...e static String URL socket local_machine_IP 4444 deviceside true apn internet com tunnelauthusername user165 tunnelauthpassword user165password StreamConnection conn null conn StreamConnection Connect...

Page 61: ...host address in dotted ASCII decimal format dest port is the destination port at the host address optional for receiving messages src port is the local source port optional apn is the network APN in...

Page 62: ...BlackBerry device applications communicate with a peripheral device that plugs into the serial or USB port 1 Import the following classes javax microedition io Connector java io DataOutputStream java...

Page 63: ...a lang String java io IOException 2 Import the javax microedition io StreamConnection interface 3 Invoke Connector open providing the serial port information that BluetoothSerialPort getSerialPortInfo...

Page 64: ...try _dout close catch IOException ioe _bluetoothConnection null _din null _dout null Wi Fi connections Wireless access families Working with the BlackBerry device transceiver involves using APIs that...

Page 65: ...cess family 1 Import the net rim device api system Radio class 2 Invoke Radio activateWAFs int WAFs The WAFs parameter is a bitmask Turn off the transceiver for a wireless access family 1 Import the n...

Page 66: ...nfo object contains a snapshot of the current wireless network WLANInfo WLANAPInfo info WLANInfo getAPInfo If the BlackBerry device is not connected to an access point the WLANInfo getAPInfo method re...

Page 67: ...terface wifi parameter applies only to TCP UDP connections To establish a Wi Fi connection and use a Wi Fi API in a BlackBerry device application the wireless service provider must support Wi Fi acces...

Page 68: ...scriptor java lang String net rim device api system 2 To retrieve information about the processes that are running invoke ApplicationManager getVisibleApplications ApplicationManager manager Applicati...

Page 69: ...T policy does not apply to BlackBerry devices that use the BlackBerry Internet Service only If the administrator or a user denies the application access to one of the protected areas the associated me...

Page 70: ...ndles for existing modules on a BlackBerry device invoke getModuleHandles int handles CodeModuleManager getModuleHandles String name CodeModuleManager getModuleName handles 0 Access control messages D...

Page 71: ...if a BlackBerry device application registers ReasonProvider A before ReasonProvider B the BlackBerry device application displays the message from ReasonProvider A followed by the message from ReasonP...

Page 72: ...The daemon module can transfer messages using a native protocol or through email messaging The daemon module starts automatically when the BlackBerry device starts A BlackBerry device user cannot star...

Page 73: ...to the ApplicationMessageFolderRegistry ApplicationMessageFolderRegistry reg ApplicationMessageFolderRegistry getInstance 6 In the main method check if the value of the args parameter indicates that...

Page 74: ...message list To be able to perform operations on custom messages the BlackBerry device application must register at least one custom folder 1 Import the following classes net rim blackberry api messa...

Page 75: ...f the BlackBerry device application The name of the root folder appears in the View Folder dialog of the Message list application when a BlackBerry device application registers more than one applicati...

Page 76: ...eate an instance of an ApplicationIcon using an EncodedImage as an argument ApplicationIcon icon new ApplicationIcon image 5 Use an icon with an application indicator ApplicationIndicator indicator re...

Page 77: ...2 To unregister an indicator invoke ApplicationIndicatorRegistry unregister reg unregister Development Guide Remove an indicator for a custom folder 75...

Page 78: ...oper Guide client server push applications Client server push applications consist of a custom client BlackBerry device application on the BlackBerry device and a server side application that pushes c...

Page 79: ...ying a reliability mode for the push submission specifying a deliver before time stamp for the push submission requesting a result notification of the push submission specifyingadeliver aftertimestamp...

Page 80: ...d in a hierarchy based on inheritance If a string is not defined in a locale a string from the next closest locale is used Files required for localization File required for localization Description Ex...

Page 81: ...root locale 3 Give the projects for each resource locale the same name as the project for the root locale followed by a double underscore __ the language code and optionally an underscore _ followed b...

Page 82: ...14 Add the resource content rrc files to the projects for the appropriate locales Development Guide Manage localization files for a suite of BlackBerry device applications 80...

Page 83: ...ckBerry Smartphone Simulator without code signatures however you must obtain code signatures from RIM before you can load the BlackBerry device applications onto BlackBerry devices If you use any of t...

Page 84: ...e key If you lose this password you must register again with RIM If this password is stolen contact RIM immediately 7 Click OK 8 Move your mouse to generate data for a new private key 9 In the Registr...

Page 85: ...the cod file exists in the same folder as the cod file The BlackBerry Integrated Development Environment compiler automatically generates the csl file 3 Double click the cod file to add it to the sig...

Page 86: ...earch In Motion BlackBerry JDE 4 6 0 bin 2 Type Java jar Dhttp proxyHost myproxy com Dhttp proxyPort 80 SignatureTool jar 3 In the File Selection window select the cod file s to sign 4 Click Open View...

Page 87: ...space window double click the key file d Select the Use as default for public classes option and Use as default for non public classes settings e Click OK f In the Workspace window right click the pro...

Page 88: ...1 Import the following classes java util Hashtable net rim device api system PersistentObject 2 Create a hash ID for the object you want to store in a persistent object long MY_DATA_ID 0x33abf322367f9...

Page 89: ...ity and performance For debugging purposes you can attach your device to the BlackBerry Integrated Development Environment and use the debugging tool to step through your application code The BlackBer...

Page 90: ...actions Task Steps Save a BlackBerry device application cod file from the BlackBerry device to your computer Issue a command using the following format javaloader save cod file For example javaloader...

Page 91: ...of cod files that a cod file requires to run Issue a command using the following format javaloader info d cod file For example javaloader exe info d MyApplication cod Retrieve information on sibling...

Page 92: ...ng the browser on their BlackBerry devices The browser prompts the users to install the application and then the application downloads over the wireless network and installs on the BlackBerry device W...

Page 93: ...COD Size parameter for each sibling file Manifest Version 1 0 MIDlet Version 1 0 0 MIDlet 1 RIM COD Module Dependencies net_rim_cldc MicroEdition Configuration CLDC 1 0 RIM COD Module Name MyApp MIDl...

Page 94: ...r example test cod and test jad 2 Use the BlackBerry Signing Authority Tool to sign the cod file 3 From a command prompt navigate to the location of the Updatejad tool 4 Type a command to correct the...

Page 95: ...videuniqueness useanIDthatincludes your company domain in reverse order For example com rim samples docs helloworld TheplatformVersionattributespecifiestheversionofthe operating system software on a B...

Page 96: ...d resolves to alx location MyCodFiles b cod files fileset directory MyCodFiles directory fileset Java 1 0 files c cod resolves to alx location MyCodFiles MyCodFiles d cod files fileset application The...

Page 97: ...RS CDMA and IDEN The radio attribute is optional The langid attribute lets you load different BlackBerry device applicationsormodulesdependingonthelanguagesupportthat BlackBerry device users add to th...

Page 98: ...he Application Loader runs in the language that the langid attribute specifies To support multiple languages specify multiple language elements To specify the name description version vendor and copyr...

Page 99: ...lication loader tool of the BlackBerry Desktop Manager selects the BlackBerry device application for installation and the BlackBerry device user cannot change this selection Add the following line req...

Page 100: ...eattributesandtheMIDlet Jar URLandMIDlet Jar Sizeattributes On BlackBerry devices download the cod files on other wireless devices download the jar files Required RIM attribute Description RIM COD Cre...

Page 101: ...ribute an application for testing The BlackBerry Java Development Environment includes a command line tool called the JavaLoader tool that is located in the BIN folder in the BlackBerry JDE folder You...

Page 102: ...description and other tags to reflect the purpose of the alx file application id Push only to 8700 description This will push the COD only to 8700s description Code sample Loading a BlackBerry device...

Page 103: ...ication_id _blackberryVersion 4 0 application Code sample Providing alternative modules for different versions of the BlackBerry Device Software application id application_id fileset _blackberryVersio...

Page 104: ...cess EDGE Enhanced Data Rates for Global Evolution EVDO Evolution Data Optimized GAN generic access network GERAN GSM EDGE Radio Access Network GPRS General Packet Radio Service GSM Global System for...

Page 105: ...otocol Triple DES Triple Data Encryption Standard UDP User Datagram Protocol UMTS Universal Mobile Telecommunications System UTRAN UMTS Terrestrial Radio Access Network WAP Wireless Application Protoc...

Page 106: ...Provide feedback 12 To provide feedback on this deliverable visit www blackberry com docsfeedback Development Guide Provide feedback 104...

Page 107: ...ion that is contained in this documentation however RIM makes no commitment to provide any such changes updates enhancements or other additions to this documentation to you in a timely manner or at al...

Page 108: ...DING AIRTIME SERVICE PROVIDERS AND THEIR RESPECTIVE DIRECTORS EMPLOYEES AND INDEPENDENT CONTRACTORS IN ADDITION TO THE LIMITATIONS AND EXCLUSIONS SET OUT ABOVE IN NO EVENT SHALL ANY DIRECTOR EMPLOYEE...

Page 109: ...TOSUPERSEDEANYEXPRESSWRITTENAGREEMENTSORWARRANTIES PROVIDED BY RIM FOR PORTIONS OF ANY RIM PRODUCT OR SERVICE OTHER THAN THIS DOCUMENTATION Research In Motion Limited 295 Phillip Street Waterloo ON N2...

Reviews: