Programming for Android
HDroidGUI 0.4 build 6
HDroidGUI on Github
hdDemo 1.1 apk
HdDemo on Github
hdCalcul 1.5 apk
HdCalcul on Github
HdDbf on Github
It's a framework for Android, a tool designed to write in Harbour applications for Android based devices - just as HwGUI allows you to write in Harbour GUI applications for Windows and Linux. I even thought about it first, as about HwGUI for Android, but along the way decided that it is better to refuse from thoughts to provide compatibility on prg level with applications on other operating systems - too specific is and the Android platform, and it interface, and the nature of the devices that use Android. Take the size of mobile devices, which is unlikely to significantly change as technological advances - just add a normal keyboard, or double the size of the screen - and the device will simply cease to be mobile. Now, imagine how any familiar desktop application with a bunch of widgets will look at this device ... It is clear that the interface of the application will have to be rewritten to suit the standards of mobile devices. And if so, why should we care about full compatibility with GUI libraries for Windows and Linux ? Application code that uses HDroidGUI, in the part which is responsible for the interface will be different from the code of HwGUI applications, although I try to use the most similar syntax.
What to begin with ?
The tools that you need to download and install before you can start using HDroidGUI are listed in the "Android" section.
Download HDroidGUI here or from the repository on Github, unpack and see what is inside it.
And inside we see the following:
The structure of HDroidGUI distribution:
First, edit the
setenv.bat ( or
setenv.sh if you have Linux ),
setting needed paths there and run
buildall.bat ( or
buildall.sh ) -
HDriudGUI must be compiled otherwise will be issued to report problems.
I would like to draw your attention to the dynamic library
which is included in the distribution.
I put almost all Harbour modules there, except those that are responsible for console input/output and
few codepages, plus Letodb RDD. Scripts to build the libraries are in
repository on Github, you
may want to include something else and rebuild
may need it also, if you want to use the latest version of the Harbour.
after compilation you should see the following files:
- lib/armeabi/libh4droid.so, lib/armeabi/libharbour.so - dynamic libraries of the "native" part of the framework.
- lib/libh4droida.a - static library of the "native" part of the framework.
- libs/su/harbour/hDroidGUI/* - compiled Java classes.
Now we are ready to create our first application for Android in Harbour.
For this we need to create a new directory with the project, where is all that is necessary for
building of apk - and
AndroidManifest.xml, and Java-sources, and
command scripts to build, and makefiles to build dynamic libraries that will be included with
package - yes, Java and Android are not so simple, as simple is the Harbour application.
But, fortunately:) we have a special tool, part of the HDroidGUI -
already mentioning here
utils/newproject.prg; you need to compile it
using the Harbour or even just to run it with necessary parameters using the hbrun.
Create your project for Android:
newproject [hrb] [-path=PATHtoHDROIDGUI] [-pass=cPassword] cFullPackageName
Let's start parsing parameters from the end:
- cFullPackageName is the full name of our application.
- It is accepted in Java systems to put classes into packages to provide uniqueness of their names.
A package is a container that is used for insulation of class names,
in order to avoid possible conflicts with other classes with the same names. The names of the packages
to ensure uniqueness, it is customary to assign in accordance with the names of your domains
( domains of your website ), and they are indicated in reverse order. So, if your site is
www.zzz.org and the application is called MyApp, then the full name of the package is recommended
to be the org.zzz.MyApp. In this case the Java - sources should be placed in the directory
src/org/zzz/MyApp/. It is therefore important to specify the full name of the application. If there will not be at least one dot,
newprojectwill refuse to create the project.
- -pass=cPassword is the password for the apk signature.
- Each apk must be signed, therefore it is necessary to specify
a password to sign -
newprojectwill include it in the command script, which he will create. If you do not specify the password in the command line,
newprojectwill ask you to enter it at start.
- [-path=PATHtoHDROIDGUI] is the full path to HDroidGUI.
- To compile your application and create an apk HDroidGUI is needed,
therefore, it is necessary to specify the
newproject, where it is to include it in the generated command script (
setenv.sh). If you do not specify it in the command line,
newprojectwill ask you to enter it at start.
- [hrb] - the type of project.
- HDroidGUI allows you to create a project of two types:
- prg file is compiled into hrb.
- prg-files are compiled in the usual way - in object files are built to a binary.
In the first case, the compiled hrb is copied to the directory
asset/of the apk package, and at the start of the program is copied from
asset/in the application home directory of your Android device and runs exactly as it is done in h4aFirstApp - my first attempt to create a Harbour application for Android. I do not see special advantages of this type of project, except that it is faster and easier going and possibly it can be convenient for small applications. To set this type of project, specify
-hrbin the command line.
The second option is the default option. Your entire Harbour code is built in a binary module - dynamic library
libh4droid.so, which is included in apk. If you, like me, like to use hrbfiles, you can do it in this case, too, - no one is stopping you from creating hrb during program execution, or download precast from your web store.
So, by running
newproject org.zzz.MyApp and specifying while execution
the path to HDroidGUI and password to sign the package, we will get the directory MyApp
with this content:
- build.bat (build.sh) is the command script to compile and build the package.
- clear.bat (clear.sh) is the command script to remove the compilation results.
- run.bat run.sh) is the command script to run the ready application on the emulator.
- setenv.bat (setenv.sh) is a command script that sets environment variables for compile and build.
- AndroidManifest.xml file with information about the project, required to build the package.
- jni/Android.mk, jni/Application.mk - make files to build dynamic libraries from our prg code and HDroidGUI static library.
- src/main.prg - the template for the main source file of your project.
- src/org/zzz/MyApp/* - Java-sources of your project.
- res/ is the default directory for the resources in Android.
- bin/ is the directory where the ready apk will be placed after building.
- lib/, libs/, obj/ - directories, where object files and libraries will be placed while compiling.
Now you can start writing the program. The main source file can have any name,
not necessarily the
main.prg but if you change it, don't forget to edit
build.bat(build.sh) - the same thing if you add new files
in your project.
Still need to learn the commands and classes HDroidGUI. While the description is not ready, watch the text of example HdCalcul and prg - sources of HDroidGUI.
(not be shown publicly)