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

Beginner's Guide Last update : 2014.05.06 Copyright: © 2011, 2012, 2013, 2014 Anywhere Software Edition 2.8 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 12 Tools ................................................................................................................................... 215 12.1 Search function in the forum........................................................................................ 215 12.2 The B4A Documentation Wiki..................................................................................... 216 12.3 B4AHelp ..................................................................................................................... 217 12.4 Help documentation - B4A Object Browser ................................................................. 220 12.5 Usefull links ................................................................................................................ 221 13 Example programs............................................................................................................... 222 13.1 User interfaces............................................................................................................. 222 13.1.1 Menu example (UserInterfaceMenu.b4a)............................................................. 223 13.1.2 TabHost example (UserInterfaceTabHost.b4a)................................................... 224 13.1.3 Button toolbox example (UserInterfaceButtonToolbox.b4a)................................ 225 13.2 Program with 3 Activities (ThreeActivityExample.b4a).............................................. 226 13.3 ScrollView examples ................................................................................................... 233 13.3.1 ScrollView example program............................................................................... 234 14 Basic language .................................................................................................................... 245 Table of contents 5 Basic4Android Beginner's Guide 14.1 Program flow............................................................................................................... 245 14.1.1 Process_Globals routine....................................................................................... 245 14.1.2 Globals routine..................................................................................................... 246 14.1.3 Activity_Create (FirstTime As Boolean) routine .................................................. 246 14.1.4 Activity_Resume routine...................................................................................... 246 14.1.5 Activity_Pause (UserClosed As Boolean) routine................................................. 246 14.2 Expressions.................................................................................................................. 249 14.2.1 Mathematical expressions .................................................................................... 249 14.2.2 Relational expressions.......................................................................................... 250 14.2.3 Boolean expressions............................................................................................. 250 14.3 Conditional statements................................................................................................. 251 14.3.1 If – Then – End If................................................................................................. 251 14.3.2 Select – Case........................................................................................................ 253 14.4 Loop structures............................................................................................................ 255 14.4.1 For – Next............................................................................................................ 255 14.4.2 For - Each ............................................................................................................ 256 14.4.3 Do - Loop ............................................................................................................ 257 14.5 Subs............................................................................................................................. 259 14.5.1 Declaring ............................................................................................................. 259 14.5.2 Calling a Sub........................................................................................................ 259 14.5.3 Calling a Sub from another module...................................................................... 259 14.5.4 Naming ................................................................................................................ 260 14.5.5 Parameters ........................................................................................................... 260 14.5.6 Returned value ..................................................................................................... 260 14.6 Events.......................................................................................................................... 261 14.7 Libraries ...................................................................................................................... 264 14.7.1 Standard libraries ................................................................................................. 264 14.7.2 Additional libraries folder .................................................................................... 264 14.7.3 Load and update a Library.................................................................................... 265 14.7.4 Error message "Are you missing a library reference?".......................................... 266 14.8 String manipulation ..................................................................................................... 267 14.9 Timers ......................................................................................................................... 268 14.10 Files......................................................................................................................... 269 14.10.1 File object ............................................................................................................ 269 14.10.2 Filenames............................................................................................................. 271 14.10.3 Subfolders............................................................................................................ 271 14.10.4 TextWriter ........................................................................................................... 272 14.10.5 TextReader........................................................................................................... 273 14.10.6 Text encoding ...................................................................................................... 274 14.11 Lists......................................................................................................................... 276 14.12 Maps........................................................................................................................ 278 15 Graphics / Drawing.............................................................................................................. 280 15.1 Overview..................................................................................................................... 280 15.2 Drawing test programs................................................................................................. 282 15.2.1 First steps............................................................................................................. 282 15.2.1.1 Start Dim and Initialisation.......................................................................... 283 15.2.1.2 Draw a line................................................................................................... 283 15.2.1.3 Draw a rectangle........................................................................................... 284 15.2.1.4 Draw a circle ................................................................................................ 285 15.2.1.5 Draw a text................................................................................................... 286 15.2.2 Drawing rotating bitmaps / RotatingNeedle.......................................................... 287 15.2.3 Simple draw functions.......................................................................................... 292 16 VB6 versus B4A.................................................................................................................. 301 Table of contents 6 Basic4Android Beginner's Guide 17 FAQ .................................................................................................................................... 306 17.1 "Please save project first" message............................................................................. 306 17.2 "Are you missing a library reference" message........................................................... 306 17.3 How loading / updating a library.................................................................................. 307 17.4 When do we need to 'Initialize' and when not............................................................. 307 17.5 Split a long line into two or more lines......................................................................... 308 17.6 Avoid closing an application / capture keycodes like Back / Menu............................... 308 17.7 Unwanted events like Click, Touch or others ............................................................... 309 17.8 Adding a Menu item .................................................................................................... 309 17.9 How do I remove a View with the Designer................................................................. 310 17.10 "Process has timeout" message............................................................................... 310 17.11 Getting a picture from the gallery............................................................................. 311 17.12 How to delete x.bal files or other files from a project ............................................. 312 17.13 Block a screen orientation........................................................................................ 313 17.14 Close second Activity .............................................................................................. 314 17.15 Taking a screenshot programaticaly ......................................................................... 314 17.16 After compiling, where are the files ......................................................................... 314 17.17 Run an application from another one........................................................................ 315 17.18 How to pass an Array to a Sub ................................................................................. 315 17.19 Getting language and country from device ............................................................... 316 17.20 Where is the apk file ................................................................................................ 316 17.21 Why is my apk filename result.apk .......................................................................... 316 17.22 Why is my apk filename xxx_DEBUG.apk.............................................................. 317 17.23 Select True / Case trick ............................................................................................ 317 17.24 Fill an array with random numbers without repetition .............................................. 317 17.25 Detect screen orientation.......................................................................................... 318 17.26 Some functions don't work in Activity_Pause........................................................... 318 17.27 Calling the internal Calculator.................................................................................. 319 17.28 Get the Alpha / Red / Green / Blue........................................................................... 320 17.29 Get device type ........................................................................................................ 320 17.30 Generate a Click event ............................................................................................. 320 17.31 "Out of memory" Error / Bitmaps............................................................................. 321 17.32 Remove the scrollbar from a ScrollView.................................................................. 321 17.33 Check if directory exists........................................................................................... 321 17.34 Set Full Screen in code............................................................................................. 321 17.35 Change EditText input modes .................................................................................. 322 17.36 Sorting a file list according to last modified time...................................................... 324 17.37 Get the dpi values of the device (dots per inch) ........................................................ 324 17.38 Finding java program lines....................................................................................... 325 18 Glossary .............................................................................................................................. 326 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. Updated for Basic4Android version 3.5 . Table of contents 7 Basic4Android Beginner's Guide A more advanced guide can be downloaded User's Guide. 1 Getting started 8 uploads/S4/ beginners-guide 2 .pdf

  • 22
  • 0
  • 0
Afficher les détails des licences
Licence et utilisation
Gratuit pour un usage personnel Attribution requise
Partager
  • Détails
  • Publié le Sep 14, 2022
  • Catégorie Law / Droit
  • Langue French
  • Taille du fichier 74.4964MB