Facing Android Development

Discuss anything else that does not suite other forums.

Moderator: Rathinagiri

User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Facing Android Development

Post by Roberto Lopez »

The scenario:

I must develop (for my job) an Android client to query and update databases (dbf files, living on our LAN server) via the Internet, of course.

I've achieved similar thing with HMGWEB R.11, but I must to change my development strategy.

The reason for change, is that until now, Android clients worked on remote sites via wi-fi with fast and reliable connections.

Now, this new app requirement is for really mobile clients (working on the streets, from cars, etc). So, I'll depend on Internet provided by cellular network.

Cellular network here is a nightmare (slow, unstable and very expensive).

So, to make my app work, I must minimize the use of the network.

Harbour for Android?: No!

I've took a look at current Harbour for Android development status and the situation is the following:

Harbour 'console' applications con be done easily, the problem is that a console app is unacceptable (and maybe unusable) for an Android user.

AFAIK, the only open source development currently in progress, is qtcontribs by Pritpal, but Android tutorial is not finished and I was not able to succeed creating an application.

The process of creating Harbour+QT Android apps requires install and configure Android SDK, Android NDK, Apache Ant, Java, QT and (of course) Harbour (the process is slightly simplified by qtcontribs distro).

We must be very careful about versions of each thing installed.

If you survive installation process, you must to properly configure all the tools to make it work together and (finally) have your Harbour/QT for Android application working.

Well... as I've said... I was unable to reach that goal.

But there is another thing to consider: according reports that you can find simply googling a little, for some developers, QT for Android apps are big and slow on some devices... SURPRISE! ;).

I live in a underdeveloped country, so, I can't think on terms of 'high-end' devices. I mean that my apps likely will not be used on a Xperia Z3 or a Galaxy S5, but in a more 'modest' hardware, so, performance of the application is a big concern for me.

So, after considering it for weeks, I've decided that my client app, WILL NOT BE Harbour based.

As I've stated many times, the solution for this could be extremely simple. The only thing required, could be adding interfaces for Android Webview to Harbour, then we could use simple HTML to interface with the users. Sadly I have not enough knowledge/time to do this myself, so, I can only ask for it.

The Solution:

An 'HTML + jQuery Mobile' client that send and receive data to an Apache web server, hosting Harbour CGI apps.

The tricks here are:

- ALL user interfaces will be contained in an UNIQUE HTML file, loaded once by the entire life of the user session.

- Then: No page reloads AT ALL!.

- To retrieve information from server and get the status of database update operations I'll use AJAX. So, the data returned from the server will be displayes inside a 'div' WITHOUT PAGE RELOADS.

- The only 'problem' is that you should must have knowledge about HTML, jQuery, JavaScript, CSS and jQuery Mobile. But, we could make slight modifications to HMGWEB to 'compile' a source file with form definitions to create an unique 'multi-page' HTML file for our app.

- Without page reloads, the session handling becomes tremendously easy.

- Eventually you could use anything on the server instead of Harbour CGI (ie: PHP+MySql).

The Example:

This is plain HTML+jQuery Mobile concept. You could make it work from HMGWEB R11 setup
(In such case, you will only use Harbour and Apache from it to run this example)

This will be our index.html file (it must live in c:\hmgweb\apache\htdocs):

Code: Select all

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>

<script language="JavaScript">

$(document).ready(function() {

	$('#create').submit(function() { // catch the form's submit event
	    $.ajax({ // create an AJAX call...
        	data: $(this).serialize(), // get the form data
	        type: $(this).attr('method'), // GET or POST
        	url: $(this).attr('action'), // the file to call
	        success: function(response) { // on success..
        	    $('#created').html(response); // update the DIV
	        }
	    });
	    return false; // cancel original event to prevent form submitting
	});

});

</script> 


</head>
<body>

<div data-role="page" id="pageone">
  <div data-role="header">
    <h1>Welcome To My Homepage</h1>
  </div>

  <div data-role="main" class="ui-content">
    <p>Welcome! If you click on the link below, it will take you to Page Two.</p>
    <a href="#pagetwo">Go to Page Two</a>

	<br>

	<p>Form</p>

	<form id=create method=POST action=cgi-bin/test.cgi>
	<input type=text name=url>
	<input type="submit" value="Create" /> 

	</form>

	<p>Before div</p>

	<br><br><hr>

	<div id=created>Result</div>

	<br><br><hr>

	<p>After div</p>

	<br>


  </div>

  <div data-role="footer">
    <h1>Footer Text</h1>
  </div>
</div> 

<div data-role="page" id="pagetwo">
  <div data-role="header">
    <h1>Welcome To My Homepage</h1>
  </div>

  <div data-role="main" class="ui-content">
    <p>This is Page Two. If you click on the link below, it will take you to Page One.</p>
    <a href="#pageone">Go to Page One</a>
  </div>

  <div data-role="footer">
    <h1>Footer Text</h1>
  </div>
</div> 

</body>
</html>
And this will be our server side Harbour code to manage client requests on this demo:

You must name it 'test.prg' and its compiled version (test.cgi) will live in c:\hmgweb\apache\cgi-bin

Code: Select all


REQUEST HB_GT_CGI_DEFAULT

function Main()

outstd("Content-type: text/html" + hb_OSNewLine() + hb_OSNewLine()) 

outstd( 'Hey!!!!')

return nil	

The Bonus:

An HTML client app, will work not only in Android, but in IOS too.

In fact it will work in any device with a jQuery Mobile compatible web browser, including desktops.

The Future:

I don't know if I'll have enough time to make the appropriate changes to turn HMGWEB into a translator, able to create an html file, from a forms definition file. If not, I'll code HTML+JQM directly, but maybe someone could have it. This is the reason to expose this idea here. Most of current HMGWEB code could be reused.

Good Luck!
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Agil Abdullah
Posts: 204
Joined: Mon Aug 25, 2014 11:57 am
Location: Jakarta, Indonesia
Contact:

Re: Facing Android Development

Post by Agil Abdullah »

Roberto,

I find it Interesting to follow any progress to come.
I wish you luck.
Agil Abdullah Albatati (just call me Agil)
Programmer Never Surrender
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Facing Android Development

Post by esgici »

New horizons :!:

Many thanks maestro :)

Thanks in advance :arrow:
Viva INTERNATIONAL HMG :D
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: Facing Android Development

Post by Roberto Lopez »

I've made a 'concept' to show the ideas exposed in the previous post in action (it is called hmgweb.012.concept.7z):

http://sourceforge.net/projects/hmgweb/

This is the 'readme':

HMG/WEB Alpha 012 'CONCEPT' README

1. Unzip this package at C:\HMGWEB folder

2. Run Apache web server (C:\HMGWEB\start.server.bat)

3. Demo:

Explore:

- To explore demo, open your browser and type:

127.0.0.1:8080

There is not need to add '/index.html' to this address, since 'index.html' is the
default name and apache looks for it automatically.

Details:

- Clicking the 'Go to Page Two' you'll be taken to another page, but there will not be
a page reload nor communication with server, since the page is already preloaded
(embedded into index.html).

- Clicking the 'Server Request' button the 'test.cgi' server procedure will be invoked
and the result will be displayed between 'before div' and 'after div' labels.

Modify:

If you want to make modifications:

- The client html file (index.html) is located at c:\hmgweb\apache\httpdocs

- The server (Harbour) program (test.prg) is located at c:\hmgweb\samples\demo

- Its compiled counterpart (test.cgi) is located at: c:\hmgweb\apache\cgi-bin

- To rebuild server side demo type:

build test

4. If you want to make accessible your applications from your LAN (test):

a). you must find the private IP of the machine running the server (you can
get it with IPCONFIG command).

b). Your application will be available (LAN only) at:

<server_private_address>:8080

5. If you want to make accessible your applications from the Internet (test):

a). you must to forward the port 8080 (on you router) to the IP of the
machine running the server (you can find it with IPCONFIG command).

b). Then you must find your public IP address (you could go to
http://www.whatsmyip.org/ to get it).

c). Your application will be online at:

<your_public_address>:8080

6. If you want to make accessible your applications from the Internet (production):

You have a couple of options:

a) Using your own machine:

- Assign a static IP at your machine (that will be your PC local IP).
- Forward the port 8080 (on you router) to the IP set in the previous step.
- Get a static IP from your ISP (that will be your public IP).
- Your applications will be online at:

<your_public_address>:8080

b) Using a VPS:

A VPS (Virtual Private Server) is basically a virtual machine 'in the cloud'.
Usually you have access to it via a remote desktop and FTP accounts and it feels
and work like a physical machine. Usually, the service includes a static IP to access
it too. There is Linux and Windows VPS. Obviously, using a Windows one, is preferable
if you don't have experience/knowledge on Linux.

So, you only must to upload HMG/WEB (or just Apache) to your Windows VPS and (of course)
your applications (*.cgi).

Then, You'll have your web applications online 24x7 without to care about a physical PC
at the home or office.

In both cases (your own machine or VPS) you optionally could access your DBF files using
HMG Windows desktop clients via NETIO. It is extremely fast when you use remote procedures
to handle the data.

c) Using a standard web hosting:

In this case you must not use Harbour compiled binaries for your server-side code,
but a standard technology used by web hosting providers instead (usually PHP+MySql).
Your client code (index.html) will be the same.

Notes:

- The server side applications are simple .exe files renamed to .cgi.
That is done because security reasons, since allowing the server to run exe
files could be dangerous.

- The application generated is a standard Harbour application (excepting by the GT driver)
so, you can use any library you want with it.

- To use Linux box as a server, no source code modifications are required. You only must to
recompile your sources using Harbour for Linux and put your application binaries at
cgi-bin folder on the server. You must consider that binary compatibility between
distributions and even between different versions of the same one is not guaranteed, so
you should install harbour on the Linux server machine, and recompile your apps there to
assure that they will work.

- Index.html and related (.js and .css) files could be transfered once to the client
device and then reuse them, without need of reloading, each time that the user
access the application.

TODO:

A translator allowing us to create an HTML file from HMG style GUI definition file.
It could be easily achieved, reusing most of HMGWEB r11 code.


Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Facing Android Development

Post by Rathinagiri »

Using AJAX, it is wonderful Roberto.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
mruizcanete
Posts: 16
Joined: Sat Apr 19, 2014 10:17 am

Re: Facing Android Development

Post by mruizcanete »

These are very good news. So, Android is closer than before. HTML5 can handle its own websql in the client side, there's no need to server side, but your approach needs a server or a vps. Should it possible to run in android browser avoiding any kind of server as a stand-alone html5 app?
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: Facing Android Development

Post by Roberto Lopez »

mruizcanete wrote:These are very good news. So, Android is closer than before. HTML5 can handle its own websql in the client side, there's no need to server side, but your approach needs a server or a vps. Should it possible to run in android browser avoiding any kind of server as a stand-alone html5 app?
Yes, You could access local SQL from a HTML5 app, but the usual need is to connect with remote data.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Facing Android Development

Post by esgici »

Roberto Lopez wrote:I've made a 'concept' to show the ideas exposed in the previous post in action...
Oh yes;

Excuse me;

I'm a conservative, can't follow innovations as required :(

Best regards.
Viva INTERNATIONAL HMG :D
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: Facing Android Development

Post by Roberto Lopez »

esgici wrote: Excuse me;

I'm a conservative, can't follow innovations as required :(
Its not as difficult as it could appear.

In fact, this is the most intuitive approach to web development I've made.

One file for client side and one file for server side.

The client is HTML and the server is Harbour.

In the case that I find enough time to create the translator to 'sugarize' the client syntax, you should give it a try.

I'm sure that using your own app in a phone is an enough reward :)
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
Post Reply