📜 ⬆️ ⬇️

Basic4Android. We write native applications for Android on basic

I do not know why about this product of engineering thought have not yet been told on Habré. Maybe because it was written in Israel, and maybe because the very idea that Basic can be written under Android is a blasphemy.
In general, the fact remains: writing on Basic for Android is now possible and will help you with this product under the predictable name “Basic4Android”.
Who is interested in reading about the possibilities of the product on the official website ? I propose to look at this beast in battle and make out a small example that will show the process of developing a simple gallery.
The first thing that pleased me when meeting b4a is that he has his own small and smart editor.



Nothing supernatural. Only the most familiar and necessary: ​​a code editor and a visual form editor.
A little later, I discovered and appreciated the ability to draw forms right inside the regular Android emulator or virtual machine.
Now let's go to the example. With the help of b4a, we will create a simple image viewer that searches for all the pictures in the sdcard / Images folder and displays them as a scrolling gallery.
To do this, in the visual editor add the item "HorizontalScrollView".
')


We expose him such initial settings:



Then, stretch this element across the width of the window. To do this, go to the tab "Designer scripts" and enter the following code:

HorizontalScrollView1.Width = 100%x 


After that, the designer can be closed. Before closing, you will be prompted to save the layer. Save:



Then go to the code editor and in the global modules we define the objects to which we refer:
 Sub Process_Globals 'These global variables will be declared once when the application starts. 'These variables can be accessed from all modules. Dim imagesFolder As String : imagesFolder = File.DirRootExternal & "/Images" Dim Bitmaps As List End Sub Sub Globals 'These global variables will be redeclared each time the activity is created. 'These variables can only be accessed from this module. Dim HorizontalScrollView1 As HorizontalScrollView End Sub 

And this is the listing of the main part of the program with comments:
 Sub Activity_Create(FirstTime As Boolean) If FirstTime Then ' Activity    ProgressDialogShow(" ") '  - Bitmaps.Initialize '        Dim files As List '          If File.Exists(imagesFolder, "") = False Then '     ToastMessageShow("  : " & CRLF & imagesFolder, True) Return '    End If files = File.ListFiles(imagesFolder) '        Dim f As String For i = 0 To files.Size - 1 DoEvents '    ' i- .     .jpg      f = files.Get(i) If f.ToLowerCase.EndsWith(".jpg") Then '      '         '      50  Dim b As Bitmap b.InitializeSample(imagesFolder,f,350dip,350dip) Bitmaps.Add(b) If Bitmaps.Size > 50 Then Exit End If Next '       ToastMessageShow(" " & Bitmaps.Size & " ", True) ProgressDialogHide '  End If Activity.LoadLayout("main") '   Activity   '    HorizontalScrollView1     HorizontalScrollView1.Panel.Width = 350dip* files.Size ' ImageView        '    For i = 0 To Bitmaps.Size -1 Dim iv As ImageView : iv.Initialize("") Dim bd As BitmapDrawable bd.Initialize(Bitmaps.Get(i)) iv.Background = bd HorizontalScrollView1.Panel.AddView(iv, 5dip + i * 350dip, 5dip, 340dip, 340dip) Next End Sub 


We start Debug
We respond to requests for the name of the package and the name of the program:





As a result, we get a gallery with a smooth scrolling.



It only remains to add that the product is paid. Today, the cost of a subscription is from $ 34 to $ 299. Personally, I purchased a two-year subscription, because The product is developing well now and I don’t see any reason to take it with a subscription for 2 months. By the way, if anyone wants to buy - write in a personal, I have a few coupons with a 50% discount.

Source: https://habr.com/ru/post/142758/


All Articles