BEGINNING BLACKBERRY 7 DEVELOPMENT - DANTE SARIGUMBA

 
CONTINUE READING
Beginning BlackBerry 7
       Development

Robert Kao

Dante     Sarigumba
With   Anthony Rizk and Kevin Michaluk

                                         Apress*
Contents

Contents at         a   Glance                                            iv
About the Authors                                                          x

About the Technical Reviewer                                              xi

Acknowledgments                                                           xii

 Chapter 1: Setting the Stage                                              1
  What This Book Is                                                         1
  What You Need to Know Before You Can     Begin                            2

  Setting Up Your Development Environment                                   2

     Installing the Development Environment                                 3

     Getting Code Signing Keys                                              8

  What's Different About Developing for BlackBerry                         11

     Limited CPU and Memory                                                11

     Java As the Native API                                                11

     Limited Screen Real Estate                                            12

     User   Input                                                          12

             Different Devices                                             12
     Many
  What's in This Book                                                      12

     Chapter 2                                                             12

     Chapter 3                                                             13

               4                                                           13
     Chapter
               5                                                           13
     Chapter
                                                                           13
     Chapter 6
                                                                           13
     Chapter   7
                                                                           13
     Chapter 8
                                                                           13
     Chapter 9
                                                                           14
     Chapter 10
                                                                           14
  Summary
                                                                          15
  Chapter 2: Hello World
                                                                           15
  Creating an   Application with the BlackBerry JDE Plug-In for Eclipse
                                                                           16
     Creating   the Project
                                                                           18
     Creating   the Application Classes
                                                                           22
     Basic   GUI Fields Explained

                                                                                V
i   CONTENTS

                   Running the Simulator                                                    22

                   Building with Different JDE Versions                                     28

                   Packaging and Signing Your Application                                   29

                   Debugging on a Device                                                    30

                Polishing the Application                                                   31

                   Setting the Title in      the BlackBerry Application       Descriptor    31

                   Creating an Icon                                                         32

                Seeing It All in Action                                                     33

                Summary                                                                     33

                Chapter 3: What Makes                        a    BlackBerry Application?   35
                Javadocs                                                                    35

                The   BlackBerry Application      Life Cycle                                37

                   Starting the Application                                                 37

                   Creating the Application                                                 37

                   Invoking the Event Thread                                                38

                   Processing Events                                                        38

                   Exiting the Application                                                  38

                Threading and the Event Thread                                              38

                   Knowing When Your Application                 Is on the Event Thread     39

                   Updating      the Ul from Other Threads                                  39

                Running Background Applications                                             42

                   Detecting Backgrounding          or   Foregrounding                      42

                   Sending     Your   Application   to the  Background                      43

                Understanding the Types of Projects                                         44

                   Libraries                                                                44

                   Creating      an Alternate   Entry   Point                               46

                   MIDP and MIDIet       Projects                                           48

                Summary                                                                     48

                Chapter        4: User Interface                  Basics                    49
                The Ul Fun Application                                                      49

                The Components of a BlackBerry            Ul                                50

                   Creating the Application                                                 51
                   Adding the Logo Image                                                    52

                   Adding a Few More Fields                                                 55

                Handling User Interaction                                                   59

                      Handling   Ul Events                                                  59

                      Handling   the Clear Button                                           60

                      Handling the Login Button                                             62

                Creating Menus                                                              64

                   Understanding Menu Items                                                 64
                   Implementing the Login         and    Clear Menu Items                   65

                Displaying Images                                                           69

                Summary                                                                     73

               I Chapter 5:         Beyond        the Basics of User Interfaces             75
                Enhancing the Ul Fun Application                                            75

                Working with Fonts                                                          77

                Drawing to the Screen Using the Graphics Context                            79

Vl
ii CONTENTS

  Using    the Paint Method                                     79

  Understanding         How the BlackBerry Screen Is Drawn      80

Creating Custom Fields                                          82

  Adding     a Custom Label Field                               82

  Creating       a Custom Button      Field                     90

  A Review of Custom Fields                                     97

Creating Custom Managers                                        97

  Creating       a   Manager                                    100
                                                                107
   Tidying Up the Login Success Screen
                                                                109
Creating a Custom Screen
   Delegate Managers                                            110

  Implementing          the Screen's    Sublayout     Method    110
                                                                112
  Adding a Few Fields
   Painting the Background                                      113

Adding    the Final Touches                                     114

  Adding     a   Header     Background                          114

             Minor Tweaks                                       116
  Making
Working with Touch Screen Models                                117

Creating   Basic Animation                                      119

   Setting   the Vertical Offset                                119

   Animating the Layout                                         120

Summary                                                         122

Chapter          6:   Storing and Searching Data               123
Storing   Data on the       BlackBerry                          123

Choices for Persistence                                         124

   RMS                                                          124

   Persistent Store                                             124

   Runtime Store                                                124

   JSR 75 FileConnection                                        125

   SQLite                                                       125

BlackBerry Persistent Store                                     125

   Persistent Store Keys                                        126

   Persistent Objects                                           126

   What Can You Persist?                                        127

   The Persistable       Application                            128

   More Advanced Persistence                                    132

   Clearing      Persistent Data from a Device                  135

The FileConnection API                                          136

   Basic Application Framework                                  136

   Opening       a File Connection                              138

             the                 Contents                       139
   Listing           Directory
                 Pictures                                       141
   Viewing
   The Image Display Screen                                     141

   Loading Images from            the File   System             142
                                                                142
   Getting Images into the          Simulator
                                                                144
   Scaling the Image
Writing to the File System                                      145

                      Menu Item                                 146
   A   Dynamic
                                                                         vii
5CONTENTS

                  The File Name Screen                                                                               147

                   Copying the File                                                                                  148

                Using SQLite                                                                                         150

                   Creating   a Database and a Table                                                                 150

                   Inserting Records                                                                                 151

                   Querying Tables                                                                                   151

                   SQLite Sample Application                                                                         151

                Integrating Your App with Unified          Search                                                    157

                Summary                                                                                              167

                Chapter       7: Hello Out There!               Making      a   Network-Enabled Application          169
                Different Ways to Connect                                                                            169

                   BES/MDS                                                                                            170
                   Direct TCP/IP                                                                                     171
                   BIS                                                                                               172
                   Wi-Fi                                                                                              172

                   WAP 2.0                                                                                            172
                   WAP 1.0                                                                                           173

                   Short-Range Communication                                                                         173
                   Recommendation                                                                                     173
                Service Book                                                                                          174

                The MIDP Connection         Framework                                                                 175
                   Connector                                                                                          175
                   Connections                                                                                        175
                   HTTP Basics                                                                                        176
                   The Test Web Application                                                                           177
                The Networking Application                                                                            177

                   Some Controls                                                                                      178

                   Making an HTTP Connection                                                                          179
                   The HttpRequestDispatcher Class                                                                    179

                   Testing It                                                                                         182

                   Two-Way Interaction: Sending            Data via HTTP POST                                         187
                Connection Method: Using Direct TCP/IP Instead of BES/MDS                                             192

                   Making     a   Connection Using WAP 2.0                                                            192

                   Making     a Connection     Using BIS                                                              193

                   Making     a Wi-Fi    Connection                                                                   194

                Determining       Network   Availability                                                              194

                   Using Coveragelnfo                                                                                 194

                   Using WLANInfo                                                                                     195

                   Putting   It All   Together                                                                        195
                TCP Socket Connections                                                                                196

                Summary                                                                                               198
            '
                Chapter 8: Where Am I? Using Location-Based Services                                                 201
                GPS Support       on   BlackBerry   Devices                                                           201

                Getting Location Information                                                                          202

                Getting Location Information Using          JSR 179   APIs and the BlackBerry Extensions to JSR179    202

                   GPS Modes                                                                                          203

                   Specifying a        GPS Mode Using JSR 179                                                         204

Vlli
CONTENTS

     Specifying a GPS Mode Using          the   BlackBerry Extensions   to JSR 179    205
 The Location  Application                                                            207

     Getting Periodic Location Updates Using LocationListener                         211

 Using Geocoding      and Reverse       Geocoding                                     214

    Geocoding: Getting Coordinates from            an   Address                       215

 Using BlackBerry Maps                                                                216

     The Invoke API                                                                   216

     Launching     the Default   BlackBerry Maps        View                          217
     Location Documents                                                               218

     Displaying    a Custom   Map View                                                220

     MapField: Embedding BlackBerry Maps                in Your Ul                    221

 Summary                                                                             223

 Chapter 9: Getting Your App Out There: Packaging and Publishing                     225
 Setting Application Properties                                                       226

 Over-the-Air Installation                                                            226

     Sibling   COD Files                                                             227
     The JAD File                                                                     228
     Content Types (MIME Types)                                                       228

     Uploading    Your   Application                                                  229

     Downloading the Application                                                      229

  Desktop Installation                                                                230

     The ALX File                                                                     230

  BlackBerry   App World                                                              232

     Getting an App World      Account                                                233

     Distributing Your Application on App World                                       234

     Implementing     License    Keys                                                 235

     Pricing                                                                          236
     The Submission Process                                                           236

     App World API                                                                    240

     In-App    Purchase                                                               241
  Other Application Stores                                                            244
     MobiHand                                                                         244

     Other Sites                                                                      247

  Summary                                                                             247

 Chapter        10: Next       Steps                                                 249
  Keeping Current                                                                     249

     Forums                                                                           250

     BlackBerry Conferences                                                           250

     OpenGL on the BlackBerry                                                         250

     Newsletters, Blogs, and Other Resources                                          250

     Farewell                                                                         251

Index                                                                                253

                                                                                                  ix
You can also read