Beginner's Guide Last update : 2014.06.03 Copyright: © 2011, 2012, 2013, 2014 A

Beginner's Guide Last update : 2014.06.03 Copyright: © 2011, 2012, 2013, 2014 Anywhere Software Edition 2.9 Table of contents 2 Basic4Android Beginner's Guide 1 Getting started.........................................................................................................................8 1.1 Trial version ....................................................................................................................9 1.2 Installing Basic4Android and Android SDK ..................................................................10 1.2.1 Install and configure Basic4Android ..........................................................................12 1.3 Installing Android Emulator...........................................................................................13 2 My first program (MyFirstProgram.b4a)...............................................................................19 3 Second program (SecondProgram.b4a).................................................................................39 4 The IDE ................................................................................................................................53 4.1 Menu and Toolbar..........................................................................................................54 4.1.1 Toolbar ......................................................................................................................54 4.1.2 File menu...................................................................................................................55 4.1.3 Edit menu ..................................................................................................................55 4.1.4 Project menu..............................................................................................................56 4.1.4.1 Add a new module .............................................................................................56 4.1.5 Tools menu ................................................................................................................56 4.1.5.1 Word wrap .........................................................................................................57 4.1.5.2 Auto Save ..........................................................................................................57 4.1.5.3 Show Tooltips During Typing ............................................................................57 4.1.5.4 Test Compile When Saving................................................................................57 4.1.5.5 Take Screenshot.................................................................................................58 4.1.5.6 Clean Files Folder (unused files) ........................................................................58 4.1.5.7 Clean Project......................................................................................................58 4.2 Code area.......................................................................................................................59 4.2.1 Code header Project Attributes / Activity Attributes...................................................59 4.2.1.1 Project Attributes ...............................................................................................59 4.2.1.2 Activity Attributes..............................................................................................59 4.2.2 Undo – Redo .................................................................................................61 4.2.3 Collapse a subroutine.................................................................................................61 4.2.4 Collapse a Region......................................................................................................62 4.2.5 Collapse the whole code.............................................................................................63 4.2.6 Commenting and uncommenting code .........................................................64 4.2.7 Bookmarks .....................................................................................64 4.2.8 Indentation ...................................................................................................65 4.2.9 Autocomplete .....................................................................................................67 4.2.10 Built in documentation...........................................................................................69 4.2.11 Jump to a subroutine ..............................................................................................70 4.2.12 Highlighting occurrences of words.........................................................................71 4.2.13 Debugging .............................................................................................................72 4.2.13.1 Debug (legacy) mode .....................................................................................72 4.2.13.2 Debug (rapid) mode........................................................................................74 4.2.13.3 Release and Release (obfuscated) modes ........................................................80 4.2.14 Breakpoints............................................................................................................81 4.2.15 Color Picker...........................................................................................................84 4.3 Tabs...............................................................................................................................85 4.3.1 Module and subroutine lists ...................................................................85 4.3.1.1 Find Sub Tool (Ctrl + E) ....................................................................................86 4.3.1.2 Find All References (F7)....................................................................................87 4.3.2 Files ...........................................................................................................88 4.3.3 Logs ..........................................................................................................89 Table of contents 3 Basic4Android Beginner's Guide 4.3.3.1 Test Compile / Warnings....................................................................................90 4.3.4 Libs ............................................................................................................97 5 Screen sizes and resolutions...................................................................................................98 5.1 Special functions like 50%x, 50dip ............................................................................ 103 5.1.1 PerXToCurrent, PerYToCurrent - 50%x .................................................................. 103 5.1.2 DipToCurrent - 50dip............................................................................................... 103 5.2 Working with different screen sizes / number of layouts .............................................. 104 5.3 Screen orientations....................................................................................................... 110 5.4 Supporting multiple screens - tips and best practices.................................................... 111 5.4.1 Advices.................................................................................................................... 111 5.4.1.1 'dip' units.......................................................................................................... 111 5.4.1.2 Use only a few layout variants.......................................................................... 111 5.4.1.3 Understand the meaning of scale (dots per inch)............................................... 111 5.4.1.4 "Normalized" variants ...................................................................................... 111 5.4.1.5 Scaling strategy................................................................................................ 112 5.4.1.6 How to change the views size and text size? AutoScale.................................. 112 6 The Emulator....................................................................................................................... 113 6.1 Launch an Emulator..................................................................................................... 113 6.2 Create a new Emulator................................................................................................. 115 6.3 Emulator problems....................................................................................................... 118 6.3.1 Process timeout........................................................................................................ 119 6.4 Exchanging files with the PC....................................................................................... 120 7 Connecting a real device USB / B4A Bridge.................................................................... 123 7.1 USB............................................................................................................................. 123 7.2 B4A Bridge ................................................................................................................. 124 7.2.1 First you need to install B4A-Bridge on your device. ............................................... 124 7.2.2 Run B4A-Bridge on your device. ............................................................................. 125 7.2.3 Connect the IDE to the device.................................................................................. 125 7.2.3.1 Wireless connections........................................................................................ 125 7.2.3.2 Bluetooth connections ...................................................................................... 126 7.2.3.3 Bluetooth tips................................................................................................... 128 8 The Designer....................................................................................................................... 129 8.1 The menu..................................................................................................................... 130 8.1.1 File menu................................................................................................................. 130 8.1.2 Edit menu ................................................................................................................ 130 8.1.3 AddView menu........................................................................................................ 131 8.1.4 The Tools menu ....................................................................................................... 132 8.2 Tools ........................................................................................................................... 133 8.2.1 Generate Members................................................................................................... 133 8.2.2 BringTo Front.......................................................................................................... 134 8.2.3 Send To Back........................................................................................................... 134 8.2.4 Duplicate Selected View.......................................................................................... 134 8.2.5 Remove Selected View ............................................................................................ 135 8.2.6 Change grid ............................................................................................................. 135 8.2.7 Connect device or emulator...................................................................................... 136 8.3 General settings ........................................................................................................... 137 8.4 Image files................................................................................................................... 139 8.5 Properties list............................................................................................................... 140 8.6 Layout variants............................................................................................................ 142 8.7 The Abstract Designer ................................................................................................. 147 8.7.1 The menu................................................................................................................. 148 8.7.2 Context menus ......................................................................................................... 149 8.7.3 Select views............................................................................................................. 150 Table of contents 4 Basic4Android Beginner's Guide 8.7.4 Example................................................................................................................... 151 8.8 Adding views by code.................................................................................................. 154 8.9 Designer Scripts........................................................................................................... 157 8.10 Anchors....................................................................................................................... 164 8.10.1 First example ....................................................................................................... 167 8.10.2 Second example ................................................................................................... 175 8.11 AutoScale .................................................................................................................... 178 8.11.1 Simple AutoScale example with only one layout variant ...................................... 179 8.11.2 Same AutoScale example with portrait and landscape layout variants................... 184 8.11.3 AutoScale more advanced examples..................................................................... 187 8.12 UI Cloud...................................................................................................................... 191 9 Process and Activity life cycle............................................................................................. 193 9.1 How do we handle it ? ................................................................................................. 194 9.2 Process global variables............................................................................................... 195 9.3 Activity variables......................................................................................................... 195 9.4 Sub Activity_Create (FirstTime As Boolean)............................................................... 195 9.5 Globals versus FirstTime ............................................................................................. 196 9.6 Sub Activity_Resume Sub Activity_Pause (UserClosed As Boolean) .......................... 196 9.7 Activity.Finish / ExitApplication ............................................................................... 197 10 Variables and objects........................................................................................................... 198 10.1 Variable Types............................................................................................................. 198 10.2 Names of variables ...................................................................................................... 200 10.3 Declaring variables ...................................................................................................... 200 10.3.1 Simple variables................................................................................................... 200 10.3.2 Array variables..................................................................................................... 201 10.3.3 Array of views (objects)....................................................................................... 203 10.3.4 Type variables...................................................................................................... 204 10.4 Casting ........................................................................................................................ 205 10.5 Scope........................................................................................................................... 206 10.5.1 Process variables.................................................................................................. 206 10.5.2 Activity variables................................................................................................. 207 10.5.3 Local variables..................................................................................................... 207 10.6 Tips ............................................................................................................................. 207 11 Modules .............................................................................................................................. 208 11.1 Activity modules.......................................................................................................... 209 11.2 Class modules.............................................................................................................. 210 11.3 Code modules.............................................................................................................. 211 11.4 Service modules........................................................................................................... 212 11.5 Shared modules ........................................................................................................... 215 12 Tools ................................................................................................................................... 216 12.1 Search function in the forum........................................................................................ 216 12.2 The B4A Documentation Wiki..................................................................................... 217 12.3 B4AHelp ..................................................................................................................... 218 12.4 Help documentation - B4A Object Browser ................................................................. 221 12.5 Usefull links ................................................................................................................ 222 12.6 Books .......................................................................................................................... 223 13 Example programs............................................................................................................... 224 13.1 User interfaces............................................................................................................. 224 13.1.1 Menu example (UserInterfaceMenu.b4a)............................................................. 225 13.1.2 TabHost example (UserInterfaceTabHost.b4a)................................................... 226 13.1.3 Button toolbox example (UserInterfaceButtonToolbox.b4a)................................ 227 13.2 Program with 3 Activities (ThreeActivityExample.b4a).............................................. 228 13.3 ScrollView examples ................................................................................................... 235 Table of contents 5 Basic4Android Beginner's Guide 13.3.1 ScrollView example program............................................................................... 236 14 Basic language .................................................................................................................... 247 14.1 Program flow............................................................................................................... 247 14.1.1 Process_Globals routine....................................................................................... 247 14.1.2 Globals routine..................................................................................................... 248 14.1.3 Activity_Create (FirstTime As Boolean) routine .................................................. 248 14.1.4 Activity_Resume routine...................................................................................... 248 14.1.5 Activity_Pause (UserClosed As Boolean) routine................................................. 248 14.2 Expressions.................................................................................................................. 251 14.2.1 Mathematical expressions .................................................................................... 251 14.2.2 Relational expressions.......................................................................................... 252 14.2.3 Boolean expressions............................................................................................. 252 14.3 Conditional statements................................................................................................. 253 14.3.1 If – Then – End If................................................................................................. 253 14.3.2 Select – Case........................................................................................................ 255 14.4 Loop structures............................................................................................................ 257 14.4.1 For – Next............................................................................................................ 257 14.4.2 For - Each ............................................................................................................ 258 14.4.3 Do - Loop ............................................................................................................ 259 14.5 Subs............................................................................................................................. 261 14.5.1 Declaring ............................................................................................................. 261 14.5.2 Calling a Sub........................................................................................................ 261 14.5.3 Calling a Sub from another module...................................................................... 261 14.5.4 Naming ................................................................................................................ 262 14.5.5 Parameters ........................................................................................................... 262 14.5.6 Returned value ..................................................................................................... 262 14.6 Events.......................................................................................................................... 263 14.7 Libraries ...................................................................................................................... 266 14.7.1 Standard libraries ................................................................................................. 266 14.7.2 Additional libraries folder .................................................................................... 266 14.7.3 Load and update a Library.................................................................................... 267 14.7.4 Error message "Are you missing a library reference?".......................................... 268 14.8 String manipulation ..................................................................................................... 269 14.9 Timers ......................................................................................................................... 270 14.10 Files......................................................................................................................... 271 14.10.1 File object ............................................................................................................ 271 14.10.2 Filenames............................................................................................................. 273 14.10.3 Subfolders............................................................................................................ 273 14.10.4 TextWriter ........................................................................................................... 274 14.10.5 TextReader........................................................................................................... 275 14.10.6 Text encoding ...................................................................................................... 276 14.11 Lists......................................................................................................................... 278 14.12 Maps........................................................................................................................ 280 15 Graphics / Drawing.............................................................................................................. 282 15.1 Overview..................................................................................................................... 282 15.2 Drawing test programs................................................................................................. 284 15.2.1 First steps............................................................................................................. 284 15.2.1.1 Start Dim and Initialisation.......................................................................... 285 15.2.1.2 Draw a line................................................................................................... 285 15.2.1.3 Draw a rectangle........................................................................................... 286 15.2.1.4 Draw a circle ................................................................................................ 287 15.2.1.5 Draw a text................................................................................................... 288 15.2.2 Drawing rotating bitmaps / RotatingNeedle.......................................................... 289 Table of contents 6 Basic4Android Beginner's Guide 15.2.3 Simple draw functions.......................................................................................... 294 16 VB6 versus B4A.................................................................................................................. 303 17 FAQ .................................................................................................................................... 308 17.1 "Please save project first" message............................................................................. 308 17.2 "Are you missing a library reference" message........................................................... 308 17.3 How loading / updating a library.................................................................................. 309 17.4 When do we need to 'Initialize' and when not............................................................. 309 17.5 Split a long line into two or more lines......................................................................... 310 17.6 Avoid closing an application / capture keycodes like Back / Menu............................... 310 17.7 Unwanted events like Click, Touch or others ............................................................... 311 17.8 Adding a Menu item .................................................................................................... 311 17.9 How do I remove a View with the Designer................................................................. 312 17.10 "Process has timeout" message............................................................................... 312 17.11 Getting a picture from the gallery............................................................................. 313 17.12 How to delete x.bal files or other files from a project ............................................. 314 17.13 Block a screen orientation........................................................................................ 315 17.14 Close second Activity .............................................................................................. 316 17.15 Taking a screenshot programaticaly ......................................................................... 316 17.16 After compiling, where are the files ......................................................................... 316 17.17 Run an application from another one........................................................................ 317 17.18 How to pass an Array to a Sub ................................................................................. 317 17.19 Getting language and country from device ............................................................... 318 17.20 Where is the apk file ................................................................................................ 318 17.21 Why is my apk filename result.apk .......................................................................... 318 17.22 Why is my apk filename xxx_DEBUG.apk.............................................................. 319 17.23 Select True / Case trick ............................................................................................ 319 17.24 Fill an array with random numbers without repetition .............................................. 319 17.25 Detect screen orientation.......................................................................................... 320 17.26 Some functions don't work in Activity_Pause........................................................... 320 17.27 Calling the internal Calculator.................................................................................. 321 17.28 Get the Alpha / Red / Green / Blue........................................................................... 322 17.29 Get device type ........................................................................................................ 322 17.30 Generate a Click event ............................................................................................. 322 17.31 "Out of memory" Error / Bitmaps............................................................................. 323 17.32 Remove the scrollbar from a ScrollView.................................................................. 323 17.33 Check if directory exists........................................................................................... 323 17.34 Set Full Screen in code............................................................................................. 323 17.35 Change EditText input modes .................................................................................. 324 17.36 Sorting a file list according to last modified time...................................................... 326 17.37 Get the dpi values of the device (dots per inch) ........................................................ 326 17.38 Finding java program lines....................................................................................... 327 18 Glossary .............................................................................................................................. 328 Main contributors : Erel Uziel (Erel) Klaus Christl (klaus) nfordbscndrd To search for a given word or sentence use the Search function in the Edit menu. All the source code and files needed (layouts, images etc) of the example projects in this guide are included in the SourceCode folder. Table of contents 7 Basic4Android Beginner's Guide Updated for Basic4Android version 3.5 . A more advanced guide uploads/S4/ beginners-guide 1 .pdf

  • 26
  • 0
  • 0
Afficher les détails des licences
Licence et utilisation
Gratuit pour un usage personnel Attribution requise
Partager
  • Détails
  • Publié le Dec 09, 2021
  • Catégorie Law / Droit
  • Langue French
  • Taille du fichier 62.6118MB