Beginner's Guide Copyright: © 2011, 2012, 2013, 2014, 2015, 2016 Anywhere Softw
Beginner's Guide Copyright: © 2011, 2012, 2013, 2014, 2015, 2016 Anywhere Software Edition 3.3 Last update : 2016.10.26 Table of contents 2 B4A Beginner's Guide 1 Getting started .............................................................................................................................. 9 1.1 Trial version ....................................................................................................................... 10 1.2 Installing B4A and Android SDK ...................................................................................... 11 1.2.1 Install and configure B4A .............................................................................................. 13 1.3 Installing B4A Bridge ........................................................................................................ 14 2 My first program (MyFirstProgram.b4a) .................................................................................. 15 3 Second program (SecondProgram.b4a) .................................................................................... 40 4 The IDE ...................................................................................................................................... 54 4.1 Menu and Toolbar .............................................................................................................. 55 4.1.1 Toolbar ........................................................................................................................... 55 4.1.2 File menu ........................................................................................................................ 56 4.1.3 Edit menu ....................................................................................................................... 56 4.1.4 Project menu................................................................................................................... 57 4.1.4.1 Add a new module ................................................................................................. 57 4.1.5 Tools menu ..................................................................................................................... 57 4.1.5.1 IDE Options ........................................................................................................... 58 4.1.5.1.1 Themes ............................................................................................................. 58 4.1.5.1.2 Font Picker ....................................................................................................... 59 4.1.5.1.2.1 Word wrap ................................................................................................. 59 4.1.5.1.2.2 Configure Process Timeout ....................................................................... 59 4.1.5.1.2.3 Disable Implicit Auto Completion ............................................................ 59 4.1.5.2 Take Screenshot ..................................................................................................... 60 4.1.5.3 Create Video........................................................................................................... 61 4.1.5.4 Clean Files Folder (unused files) ........................................................................... 62 4.1.5.5 Clean Project .......................................................................................................... 62 4.2 Code area ............................................................................................................................ 63 4.2.1 Split the code area .......................................................................................................... 63 4.2.2 Code header Project Attributes / Activity Attributes ..................................................... 64 4.2.2.1 Project Attributes ................................................................................................... 64 4.2.2.2 Activity Attributes .................................................................................................. 64 4.2.3 Undo – Redo ...................................................................................................... 66 4.2.4 Collapse a subroutine ..................................................................................................... 66 4.2.5 Collapse a Region .......................................................................................................... 67 4.2.6 Collapse the entire code ................................................................................................. 68 4.2.7 Copy a selected bloc of text ........................................................................................... 69 4.2.8 Find / Replace ................................................................................................................ 70 4.2.9 Commenting and uncommenting code ............................................................. 71 4.2.10 Bookmarks ........................................................................................................... 72 4.2.11 Indentation ..................................................................................................... 73 4.2.12 Documentation tool tips while hovering over code elements .................................... 75 4.2.13 Auto Completion ........................................................................................................ 76 4.2.14 Built in documentation ............................................................................................... 80 4.2.14.1 Copy code examples .......................................................................................... 81 4.2.15 Jump to a subroutine .................................................................................................. 82 4.2.16 Highlighting occurrences of words ............................................................................ 83 4.2.17 Compiler mode ........................................................................................................... 83 4.2.17.1 Release and Release (obfuscated) modes ........................................................... 84 4.2.18 Breakpoints ................................................................................................................ 85 4.2.19 Color Picker ............................................................................................................... 87 4.2.20 Colors in the left side ................................................................................................. 88 4.2.21 URLs in comments and strings are ctrl-clickable ...................................................... 89 4.3 Tabs .................................................................................................................................... 90 Table of contents 3 B4A Beginner's Guide 4.3.1 Floating Tab windows .................................................................................................... 91 4.3.2 Float ........................................................................................................................ 92 4.3.3 Auto Hide ................................................................................................................ 95 4.3.4 Close ............................................................................................................................... 97 4.3.5 Modules and subroutine lists ...................................................................... 98 4.3.5.1 Find Sub / Module (Ctrl + E) ................................................................................. 99 4.3.6 Files Manager .................................................................................... 100 4.3.7 Logs ............................................................................................................... 102 4.3.7.1 Compile Warnings ............................................................................................... 103 4.3.7.1.1 Ignoring warnings ........................................................................................... 104 4.3.7.1.2 List of warnings .............................................................................................. 105 4.3.8 Libraries Manager ........................................................................ 111 4.3.9 Quick Search ...................................................................................... 112 4.3.10 Find All References (F7) .................................................. 114 4.4 Navigation in the IDE ...................................................................................................... 115 4.4.1 Alt + Left / Alt + Right Move backwards and forwards ............................................ 115 4.4.2 Alt + N Navigation stack menu .................................................................................. 115 4.4.3 Split the screen ............................................................................................................. 115 4.4.4 Multiple windows ........................................................................................................ 116 4.4.5 Ctrl + E Search for sub or module .............................................................................. 116 4.4.6 Ctrl + Click on any sub or variable .............................................................................. 116 4.4.7 F7 - Find all references ................................................................................................ 116 4.4.8 Ctrl + F Quick Search ................................................................................................. 116 5 Screen sizes and resolutions ..................................................................................................... 117 5.1 Special functions like 50%x, 50dip ................................................................................ 122 5.1.1 PerXToCurrent, PerYToCurrent - 50%x ..................................................................... 122 5.1.2 DipToCurrent - 50dip ................................................................................................... 122 5.1.3 LayoutValues.ApproximateScreenSize ....................................................................... 123 5.1.4 ActivitySize in the DesignerScripts ............................................................................. 123 5.2 Working with different screen sizes / number of layouts ................................................ 124 5.3 Screen orientations ........................................................................................................... 131 5.4 Supporting multiple screens - tips and best practices ...................................................... 132 5.4.1 Advices ......................................................................................................................... 132 5.4.1.1 'dip' units .............................................................................................................. 132 5.4.1.2 Use only a few layout variants ............................................................................. 132 5.4.1.3 Understand the meaning of scale (dots per inch) ................................................. 132 5.4.1.4 "Normalized" variants .......................................................................................... 132 5.4.1.5 Scaling strategy .................................................................................................... 133 5.4.1.6 How to change the views size and text size? AutoScale .................................... 133 6 Connecting a real device .......................................................................................................... 134 6.1 Connecting via B4A Bridge ............................................................................................. 134 6.1.1 Getting started with B4A-Bridge ................................................................................. 134 6.1.2 Run B4A-Bridge on your device.................................................................................. 135 6.1.3 Wireless connections .................................................................................................... 136 6.1.4 Bluetooth connections .................................................................................................. 138 6.1.4.1 Bluetooth tips ....................................................................................................... 139 6.2 Connecting via USB ......................................................................................................... 140 7 Emulators ................................................................................................................................. 141 7.1 Genymotion Emulator ...................................................................................................... 141 7.2 Android Emulator............................................................................................................. 142 7.2.1 Create a new Emulator ................................................................................................. 142 Table of contents 4 B4A Beginner's Guide 7.2.2 Launch an Android Emulator ....................................................................................... 145 7.2.3 Android Emulator problems ......................................................................................... 148 7.2.4 Process timeout ............................................................................................................ 149 7.2.5 Exchanging files with the PC ....................................................................................... 150 8 The Visual Designer ................................................................................................................. 153 8.1 The menu .......................................................................................................................... 154 8.1.1 File menu ...................................................................................................................... 154 8.1.2 AddView menu ............................................................................................................ 155 8.1.3 WYSIWYG Designer menu ......................................................................................... 155 8.1.4 The Tools menu............................................................................................................ 156 8.1.5 Windows menu ............................................................................................................ 156 8.2 Visual Designer Windows ............................................................................................... 157 8.2.1 Views windows Views Tree / Files / Variants ........................................................ 157 8.2.1.1 Views Tree window ............................................................................................. 157 8.2.1.2 Files Windows ...................................................................................................... 157 8.2.1.3 Variants window .................................................................................................. 158 8.2.2 Properties window ........................................................................................................ 159 8.2.3 Script (General) / (Variant) windows ........................................................................... 159 8.2.4 Abstract Designer window ........................................................................................... 160 8.3 Floating windows ............................................................................................................. 161 8.3.1 Float ............................................................................................................................. 161 8.3.2 Dock ............................................................................................................................. 162 8.3.3 Dock as Document ....................................................................................................... 162 8.3.4 Auto Hide ..................................................................................................................... 163 8.3.5 Maximize...................................................................................................................... 164 8.3.6 New Horizontal / Vertical Tab Group .......................................................................... 165 8.4 Tools ................................................................................................................................. 166 8.4.1 Generate Members ....................................................................................................... 166 8.4.2 Connect device or emulator ......................................................................................... 167 8.4.3 Change grid .................................................................................................................. 168 8.5 Image files ........................................................................................................................ 169 8.6 Properties list .................................................................................................................... 170 8.6.1 Main properties ............................................................................................................ 171 8.6.2 Common properties ...................................................................................................... 172 8.6.3 Activity properties ........................................................................................................ 173 8.6.4 Color properties ............................................................................................................ 174 8.7 Layout variants ................................................................................................................. 176 8.8 The Abstract Designer...................................................................................................... 180 8.8.1 Selection of a screen size ............................................................................................. 181 8.8.2 Zoom ............................................................................................................................ 181 8.8.3 Context menus .............................................................................................................. 182 8.8.3.1 Add View ............................................................................................................. 183 8.8.3.2 Cut ........................................................................................................................ 184 8.8.3.3 Copy ..................................................................................................................... 184 8.8.3.4 Paste ..................................................................................................................... 184 8.8.3.5 Duplicate .............................................................................................................. 184 8.8.3.6 Undo / Redo ......................................................................................................... 184 8.8.3.7 Horizontal Anchor ................................................................................................ 184 8.8.3.8 Vertical Anchor .................................................................................................... 185 8.8.3.9 Bring To Front ..................................................................................................... 185 8.8.3.10 Send To Back ................................................................................................... 185 8.8.3.11 Generate ........................................................................................................... 186 8.8.4 Select views .................................................................................................................. 187 Table of contents 5 B4A Beginner's Guide 8.8.5 Example........................................................................................................................ 189 8.9 Adding views by code ...................................................................................................... 191 8.10 Designer Scripts ............................................................................................................... 194 8.10.1 The menu .................................................................................................................. 196 8.10.2 Supported Properties ................................................................................................ 200 8.10.3 Supported Methods .................................................................................................. 200 8.10.4 Supported Keywords ................................................................................................ 200 8.10.5 Autocomplete ........................................................................................................... 201 8.10.6 Notes and tips ........................................................................................................... 201 8.11 Anchors ............................................................................................................................ 202 8.11.1 Horizontal Anchor .................................................................................................... 202 8.11.2 Vertical Anchor ........................................................................................................ 203 8.11.3 First example ............................................................................................................ 205 8.11.4 Second example ....................................................................................................... 213 8.12 AutoScale ......................................................................................................................... 216 8.12.1 Simple AutoScale example with only one layout variant ........................................ 217 8.12.2 Same AutoScale example with portrait and landscape layout variants .................... 222 8.12.3 AutoScale more advanced examples ........................................................................ 225 8.13 UI Cloud ........................................................................................................................... 230 9 Process and Activity life cycle ................................................................................................. 232 9.1 Program Start ................................................................................................................... 233 9.2 Process global variables ................................................................................................... 234 9.3 Activity variables ............................................................................................................. 234 9.4 Starter service ................................................................................................................... 235 9.5 Program flow .................................................................................................................... 236 9.6 Globals versus FirstTime ................................................................................................. 237 9.7 Sub Activity_Create (FirstTime As Boolean) .................................................................. 237 9.8 Variable declaration summary ......................................................................................... 238 9.9 Sub Activity_Resume Sub Activity_Pause (UserClosed As Boolean) ............................ 239 9.10 Activity.Finish / ExitApplication ................................................................................... 240 10 Variables and objects ............................................................................................................... 241 10.1 Variable Types ................................................................................................................. 241 10.2 Names of variables ........................................................................................................... 243 10.3 Declaring variables........................................................................................................... 243 10.3.1 Simple variables ....................................................................................................... 243 10.3.2 Array variables ......................................................................................................... 244 10.3.3 Array of views (objects) ........................................................................................... 246 10.3.4 Type variables .......................................................................................................... 247 10.4 Casting ............................................................................................................................. 248 10.5 Scope ................................................................................................................................ 249 10.5.1 Process variables ...................................................................................................... 249 10.5.2 Activity variables ..................................................................................................... 250 10.5.3 Local variables ......................................................................................................... 250 10.6 Tips ................................................................................................................................... 250 11 Modules .................................................................................................................................... 251 11.1 Activity modules .............................................................................................................. 252 11.2 Class modules .................................................................................................................. 253 11.3 Code modules ................................................................................................................... 254 11.4 Service modules ............................................................................................................... 255 11.5 Shared modules ................................................................................................................ 258 12 Help tools ................................................................................................................................. 259 12.1 Search function in the forum ............................................................................................ 259 12.2 B4x Help Viewer.............................................................................................................. 261 Table of contents 6 B4A Beginner's Guide 12.3 Help documentation - B4A Object Browser .................................................................... 266 12.4 Useful links ...................................................................................................................... 267 12.5 Books ............................................................................................................................... 268 13 Debugging ................................................................................................................................ 269 13.1 Debug mode ..................................................................................................................... 270 13.1.1 Debugger advantages ............................................................................................... 270 13.1.2 Debugger Limitations............................................................................................... 271 13.1.3 Debug Toolbar ......................................................................................................... 272 13.1.3.1 Run F5 ...................................................................................................... 272 13.1.3.2 Step In F8 ................................................................................................. 273 13.1.3.3 Step Over F9 ............................................................................................ 274 13.1.3.4 Step Out F10 ............................................................................................ 274 13.1.3.5 Stop ........................................................................................................... 275 13.1.3.6 Restart F11 ............................................................................................... 275 13.1.4 Small debug example ............................................................................................... 276 13.1.5 Watch Expressions feature ....................................................................................... 279 13.2 Debug (legacy) mode ....................................................................................................... 280 14 Example programs ................................................................................................................... 281 14.1 User interfaces .................................................................................................................. 281 14.1.1 Menu example (UserInterfaceMenu.b4a) ............................................................... 283 14.1.2 TabHost example (UserInterfaceTabHost.b4a) ..................................................... 284 14.1.3 Button toolbox example (UserInterfaceButtonToolbox.b4a) ................................. 285 14.2 Program with 3 Activities (ThreeActivityExample.b4a) ................................................ 286 14.3 ScrollView examples ....................................................................................................... 293 14.3.1 ScrollView example program .................................................................................. 294 15 Basic language ......................................................................................................................... 305 15.1 Expressions ...................................................................................................................... 306 15.1.1 Mathematical expressions ........................................................................................ 306 15.1.2 Relational expressions .............................................................................................. 307 15.1.3 Boolean expressions ................................................................................................. 307 15.2 Conditional statements ..................................................................................................... 308 15.2.1 If – Then – End If ..................................................................................................... 308 15.2.2 Select – Case ............................................................................................................ 310 15.3 Loop structures ................................................................................................................. 312 15.3.1 For – Next ................................................................................................................ 312 15.3.2 For - Each ................................................................................................................. 313 15.3.3 Do - Loop ................................................................................................................. 314 15.4 Subs uploads/S4/ b4abeginners-guide.pdf
Documents similaires










-
34
-
0
-
0
Licence et utilisation
Gratuit pour un usage personnel Attribution requise- Détails
- Publié le Aoû 08, 2021
- Catégorie Law / Droit
- Langue French
- Taille du fichier 13.2745MB