User's Guide Last update: 2016.02.28 Copyright: © 2012, 2013, 2014, 2015, 2016

User's Guide Last update: 2016.02.28 Copyright: © 2012, 2013, 2014, 2015, 2016 Anywhere Software Edition 1.7 Table of contents 2 B4A User's Guide 1 General information.................................................................................................................5 2 Conditional compilation ..........................................................................................................6 2.1 Build configurations ........................................................................................................6 2.1.1 Built-in symbols...........................................................................................................6 2.2 Code Exclusion................................................................................................................7 2.2.1 Example from the forum..............................................................................................7 2.3 Unsupported structure....................................................................................................10 3 Starter Service .......................................................................................................................11 4 Libraries................................................................................................................................13 4.1 IME Input Methods Editor...........................................................................................13 4.1.1 Handling the screen size changed event......................................................................15 4.1.2 Showing and hiding the keyboard ..............................................................................16 4.1.3 Handle the action button ............................................................................................16 4.1.4 Custom filters ............................................................................................................17 4.2 #AdditionalJar attribute..................................................................................................18 5 SQLite Database....................................................................................................................22 5.1 SQLite Database basics..................................................................................................23 5.1.1 Database initialisation SQL1.Initialize ....................................................................23 5.1.2 Table creation CREATE TABLE............................................................................23 5.1.3 INTEGER PRIMARY KEY rowID...........................................................................24 5.1.4 Adding data INSERT INTO....................................................................................25 5.1.5 Updating data UPDATE..........................................................................................25 5.1.6 Reading data SELECT............................................................................................25 5.1.7 Filtering WHERE...................................................................................................27 5.1.8 Sorting ORDER BY...............................................................................................28 5.1.9 Date / Time functions.................................................................................................29 5.1.10 Other functions ......................................................................................................30 5.1.11 Get Table information PRAGMA..........................................................................31 5.1.12 Deleting data DELETE FROM............................................................................32 5.1.13 Rename a table ALTER TABLE Name ADD COLUMN.....................................32 5.1.14 Add a column ALTER TABLE Name ADD COLUMN.......................................32 5.1.14.1 Update the database after having added a column...........................................32 5.1.15 Delete a table DROP TABLE.............................................................................32 5.1.16 Insert an image.......................................................................................................33 5.1.17 Read an image........................................................................................................33 5.1.18 ExecQuery vs ExecQuery2 / ExecNonQuery vs ExecNonQuery2.........................34 5.1.19 Insert many rows SQL.BeginTransaction / SQL.EndTransaction...........................35 5.1.20 Asynchronus queries..............................................................................................36 5.1.21 Batch inserts AddNonQueryToBatch / ExecNonQueryBatch.................................36 5.2 Multiple tables...............................................................................................................37 5.3 Transaction speed ..........................................................................................................38 5.4 First steps ......................................................................................................................39 5.5 SQLite Viewer...............................................................................................................41 5.6 SQLite Database first simple example program SQLiteLight1 ......................................42 5.7 SQLite Database second simple example program SQLiteLight2..................................48 5.8 SQLite Database third simple example program SQLiteLight3 ....................................54 5.9 SQLite Database forth example program SQLiteLight4 ................................................55 5.10 SQLite Database fifth example program ........................................................................57 5.10.1 Editing ...................................................................................................................59 5.10.2 Filtering .................................................................................................................60 5.10.3 Code ......................................................................................................................61 5.10.3.1 Starter Service................................................................................................62 Table of contents 3 B4A User's Guide 5.10.3.2 Main Activity.................................................................................................62 5.10.3.3 Edit activity....................................................................................................64 5.10.3.4 Filter Activity.................................................................................................65 6 DBUtils.................................................................................................................................66 6.1 DBUtils functions..........................................................................................................67 6.2 Examples.......................................................................................................................69 6.2.1 Example program Main module................................................................................69 6.2.2 Show the table in a WebView ....................................................................................71 6.2.3 Show FirstName and LastName in a ListView ...........................................................75 6.2.4 Display database in Spinners......................................................................................77 6.2.5 Edit database..............................................................................................................79 7 GPS.......................................................................................................................................87 7.1 GPS Library...................................................................................................................87 7.1.1 GPS Object................................................................................................................87 7.1.2 GPS Satellite..............................................................................................................88 7.1.3 GPS Location.............................................................................................................88 7.1.4 NMEA data sentences................................................................................................89 7.2 GPS Program.................................................................................................................90 7.2.1 General explanations..................................................................................................93 7.2.2 Setup..........................................................................................................................94 7.2.3 GPS display ...............................................................................................................96 7.2.4 Satellites ....................................................................................................................97 7.2.5 Map display ...............................................................................................................98 7.2.6 GPS path.................................................................................................................. 100 7.2.7 Save GPS path file / KML file.................................................................................. 103 7.3 GPS Program Code...................................................................................................... 104 7.3.1 Initialization of the GPS........................................................................................... 105 7.3.2 Button with tooltip................................................................................................... 106 7.3.3 Button with tooltip and additional buttons................................................................ 109 7.3.4 GPS Calculate distance scales.................................................................................. 112 7.3.5 Drawing GPS position ............................................................................................. 113 8 Widgets, home screen widgets............................................................................................. 116 8.1 Widgets Part I............................................................................................................. 116 8.2 Widgets Part II............................................................................................................ 119 9 okHttpUtils2........................................................................................................................ 122 9.1 okHttpUtils2 Objects .................................................................................................. 122 9.2 HttpUtils2 Functions................................................................................................... 122 9.3 okHttpUtils Example1 ................................................................................................ 125 9.4 HttpUtils Example2 .................................................................................................... 126 9.5 The Flickr Viewer example.......................................................................................... 127 10 Network / AsyncStreams ..................................................................................................... 128 11 Advanced drawings ............................................................................................................. 132 11.1 View Drawables .......................................................................................................... 132 11.1.1 ColorDrawable..................................................................................................... 132 11.1.2 GradientDrawable................................................................................................ 133 11.1.3 BitmapDrawable .................................................................................................. 134 11.1.4 StateListDrawable................................................................................................ 135 11.1.5 NinePatchDrawable ............................................................................................. 138 11.2 Layers with Panels / ImageViews / Images .................................................................. 140 11.2.1 Source code.......................................................................................................... 141 11.3 Diagrams / Charts........................................................................................................ 145 11.3.1 Diagrams / Graph example program................................................................... 145 11.3.2 Second Graph program......................................................................................... 154 Table of contents 4 B4A User's Guide 11.3.3 Charts Framework................................................................................................ 155 11.3.3.1 Pie Chart ...................................................................................................... 156 11.3.3.2 Bar Chart...................................................................................................... 159 11.3.3.3 Stacked Bar Chart......................................................................................... 162 11.3.3.4 Lines Chart................................................................................................... 164 11.4 Antialiasing filter......................................................................................................... 169 12 Class modules...................................................................................................................... 170 12.1 Getting started ............................................................................................................. 170 12.1.1 Adding a class module ......................................................................................... 171 12.1.2 Polymorphism...................................................................................................... 172 12.1.3 Self reference....................................................................................................... 173 12.1.4 Activity object...................................................................................................... 174 12.2 Standard class structure................................................................................................ 175 12.3 Classes from the forum................................................................................................ 177 12.4 Custom views .............................................................................................................. 178 12.4.1 Custom view class structure................................................................................. 178 12.4.1.1 Event declaration.......................................................................................... 178 12.4.1.2 Designer properties declarations................................................................... 179 12.4.1.3 Global variable declarations ......................................................................... 179 12.4.1.4 Initialization routine ..................................................................................... 179 12.4.1.5 Designer support routine............................................................................... 180 12.4.1.6 Routine to get the base Panel........................................................................ 180 12.4.2 Adding a custom view by code............................................................................. 181 12.4.3 Add properties...................................................................................................... 182 12.4.4 Custom view in the Designer................................................................................ 183 12.5 First example LimitBar ............................................................................................... 186 12.6 Compile a class into a Library...................................................................................... 192 12.6.1 Example with the LimitBar class example............................................................ 194 12.6.2 Using the library in a program.............................................................................. 196 12.7 Second example Wheel selection ................................................................................ 197 12.7.1 Simple example.................................................................................................... 197 12.7.2 Show the selected entry centred in the middle window......................................... 201 12.7.3 Return the selected value...................................................................................... 203 12.7.4 Color properties ................................................................................................... 205 12.7.5 A more advanced example ................................................................................... 209 Main contributors : Klaus Christl (klaus) Erel Uziel (Erel). 1 General information 5 B4A User's Guide 1 General information This guide is dedicated for more advanced users and treats more specific topics. It covers Basic4Android version 5.80. All the source code and files needed (layouts, images etc) of the example projects in this guide are included in the SourceCode folder. Beginners should first read the Beginner's Guide. 2 Conditional Compilation 6 B4A User's Guide 2 Conditional compilation In computer programming, conditional compilation is compilation implementing methods which allow the compiler to produce differences in the executable produced controlled by parameters that are provided during compilation. 2.1 Build configurations The build configurations dialog is available in the IDE menu under Project -> Build Configurations (Ctrl + B). This dialog allows you to edit or add new configurations and to choose the current active configuration. A build configuration is made of a package name and a set of conditional symbols. The package name replaces the previously global package field. This means that you can produce APKs with different package names from the same project. Note that multiple configurations can share the same package name. The conditional symbols define the active compiler symbols. This allows you to exclude parts of the code based on the chosen build configuration. You can set multiple symbols separated with commas. 2.1.1 Built-in symbols There are several built-in symbols:  For B4A: B4A, DEBUG and RELEASE. Either DEBUG or RELEASE will be active based on the deployment mode.  For B4J: B4J, DEBUG, RELEASE, UI or NON_UI (based on the app type) 2 Conditional Compilation 7 B4A User's Guide 2.2 Code Exclusion With the conditional compilation feature you can exclude any code you like from the code editor, manifest editor and designer script (any text can be excluded, including complete subs and attributes). Excluded code will not be parsed and will be effectively removed before it reaches the compiler. The code exclusion syntax: Each build configuration holds a set of symbols. Multiple configurations can share all or some of the symbols. This makes it possible to include or exclude code in several different configurations. There is no support for #Else (it is related to the code editor lexer implementation). You can however achieve the same result by adding the same symbol to all other build configurations. 2.2.1 Example from the forum The example code is in the ConditionalCompiling project in the SourceCode folder. Let’s create three configurations:  FREE  PAID  AMAZON In the IDE menu click on Project / Build Configuration. Fill the in the fields. Click on to confirm. 2 Conditional Compilation 8 B4A User's Guide Select Project / Build Configuration again you’ll see this. In the drop down list Default is replaced by FREE. Click on to create a new configuration. Fill in the new values. Click on to create the third configuration. Replace PAID by AMAZON and click to finish. 2 Conditional Compilation 9 B4A User's Guide Enter the code below: We see that the code after IF AMAZON is colored because the last selected configuration is AMAZON. Sub Globals #If FREE Dim sRelease As String = "(Free)" Dim sDist As String = "" #End If #If PAID Dim sRelease As String = "(Paid)" Dim sDist As String = "" #End If #If AMAZON Dim sRelease As String = "(Free)" Dim sDist As String = "Amazon" #End If End Sub Now select PAID in the BuildConfigurations window: We see now the three configurations in the list. Sub Globals #If FREE Dim sRelease As String = "(Free)" Dim sDist As String = "" #End If #If PAID Dim sRelease As String = "(Paid)" Dim sDist As String = "" #End If #If AMAZON Dim sRelease As String = "(Free)" Dim sDist As String = "Amazon" #End If End Sub Note that now the code after IF PAID is colored showing that this code will be executed and the other code will not be executed. If you have a code like this, where the code for FREE and AMAZON is the same: #If FREE #ApplicationLabel: Yahtzee! (Free) #VersionCode: 119 #VersionName: 11.9 #End If #If AMAZON #ApplicationLabel: Yahtzee! (Free) #VersionCode: 119 #VersionName: 11.9 #End If #If PAID #ApplicationLabel: Yahtzee! (Paid) #VersionCode: 89 #VersionName: 8.9 #End If 2 Conditional Compilation 10 B4A User's Guide You could add a new configuration FreeOrAmazon like this: In Conditional Symbols we need to add also FREE and AMAZON to allow alse these configurations. In this case we need to add the FreeOrAmazon configuration to both FREE and AMAZON configurations. And replace the code by: #If FreeOrAmazon #ApplicationLabel: Yahtzee! (Free) #VersionCode: 119 uploads/S4/ b4-auser-guide.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 Sep 16, 2022
  • Catégorie Law / Droit
  • Langue French
  • Taille du fichier 5.0372MB