Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-02

Android Target GUI

25 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff

Hi,

I'd like to know, how GUI building for Android is handled using Lazarus.

I have pretty much no idea of the Android SDK or things, but I understand that this target involves compiling the code to Java byte code. The details are not what I need at the moment, only a broad overview how things work together and what role Lazarus plays in the GUI part.

How is the GUI specified, is it drawn like building a form or is it made by drawing on a canvas in code?

Or does Lazarus/fpc only generate the event handlers an making a GUI is a seperate task for a HTML designer or the like?

TIA,
Marc

Marc Santhoff

Reply by email

Felipe Monteiro de Carvalho
to Marc Santhoff
Marc Santhoff wrote
I have pretty much no idea of the Android SDK or things, but I understand that this target involves compiling the code to Java byte code.

Android can run native code too, it runs Linux shared objects. Lazarus for Android compiles the project as a Linux shared object which is exactly what many large and successful Android applications do and it does not use the FPC compiler support for Java. I doubt that the Java backend would ever support building all the necessary libraries which the LCL uses or the LCL itself, for example due to the lack of pointers. Also if that was the case then no 3rd party libraries would work at all, like LNet. Basically I doubt that there can be any significant sharing of code here. Also when I started the Java backend didn't exist.

How is the GUI specified, is it drawn like building a form or is it made by drawing on a canvas in code?

Android applications are full screen apps which respond to events, for example paint or touch or key event. We redirect all events to LCL-CustomDrawn common handlers for any platform and it does it's job. In the paint event we draw every single pixel in Pascal code in our TLazCanvas surface and send a finished bitmap to Android.

Or does Lazarus/fpc only generate the event handlers an making a GUI is a seperate task for a HTML designer or the like?

HTML!? No, there is no HTML involved.

Felipe Monteiro de Carvalho

Reply by email

Unknown author
to Marc Santhoff: I'd like to know, how GUI building for Android is handled using Lazarus. I have pretty…
Marc Santhoff wrote 9 lines
Hi, I'd like to know, how GUI building for Android is handled using Lazarus. I have pretty much no idea of the Android SDK or things, but I understand that this target involves compiling the code to Java byte code. The details are not what I need at the moment, only a broad overview how things work together and what role Lazarus plays in the GUI part.

There are 2 approaches:

1. Do as Felipe does. He has described how it works.

2. Use the JVM backend. In that case, you make direct use of the Java classes and the android API. Your app willl look and behave like any other Android app. (I am not sure what Felipe's approach results in)

In the second case, Lazarus offers no help except that it's an excellent Pascal editor/compiler. But the GUI designing part of Lazarus is then not used. You must create the XML files manually.

How is the GUI specified, is it drawn like building a form or is it made by drawing on a canvas in code?

Android uses XML files to specify the layout. This is the recommended way by Google. You can build the GUI in code as well, but then you're pretty much in uncharted territory.

Or does Lazarus/fpc only generate the event handlers an making a GUI is a seperate task for a HTML designer or the like?

The android API does not know event handlers as Object Pascal does. It has some form of callback objects, which are pretty much the same thing, yet they work slightly different.

Basically, your class must expose a certain interface, and then it can be assigned as the 'event handling object' to the GUI control.

It's probably easier to see it work in code than explain in words :-)

I just wrote an app in this way. It has about 160 lines of code (including declaration) for a 2-form program that talks to a database to show some stuff on screen.

Michael.

Reply by email

Sven Barth
to Felipe Monteiro de Carvalho: Android can run native code too, it runs Linux shared objects. Lazarus for Android…
Felipe Monteiro de Carvalho wrote 15 lines
On Fri, Feb 17, 2012 at 5:59 AM, Marc Santhoff wrote: > I have pretty much no idea of the Android SDK or things, but I > understand that this target involves compiling the code to Java byte > code. Android can run native code too, it runs Linux shared objects. Lazarus for Android compiles the project as a Linux shared object which is exactly what many large and successful Android applications do and it does not use the FPC compiler support for Java. I doubt that the Java backend would ever support building all the necessary libraries which the LCL uses or the LCL itself, for example due to the lack of pointers. Also if that was the case then no 3rd party libraries would work at all, like LNet. Basically I doubt that there can be any significant sharing of code here. Also when I started the Java backend didn't exist.

Though this doesn't invalidate most of your other reasons, but the JVM port DOES support pointers (more or less). See here: http://wiki.freepascal.org/FPC_JVM/Language#Partially_supported_language_features

Regards,
Sven

Reply by email

Felipe Monteiro de Carvalho
to Unknown author: There are 2 approaches: 1. Do as Felipe does. He has described how it works. 2. Use the…
Android uses XML files to specify the layout. This is the recommended way by Google. You can build the GUI in code as well, but then you're pretty much in uncharted territory.

It is pretty trivial to build the UI without XML. I never used the XML part while programming for Android. For example (in pseudo-code):

procedure TMyActivity.OnCreate;
var
  layout: TAbsoluteLayout;
  params: TAbsoluteLayout_LayoutParams;
  tv: TTextView;
  et: TTextView;
  btn: TButton;
  ClickCount: Integer = 0;
begin
  // Prepares the UI of the program
  layout := TAbsoluteLayout.Create;
  tv := TTextView.Create;
  tv.setText('The first Pascal Android application =)');
  params := TAbsoluteLayout_LayoutParams.Create(320, 300, 0, 120);
  layout.addView(tv, params);
  params.Free;
  et := TEditText.Create;
  et.setText('edit me please');
  params := TAbsoluteLayout_LayoutParams.Create(320, 50, 0, 0);
  layout.addView(et, params);
  params.Free;
  btn := TButton.Create;
  btn.setText('Go!');
  btn.setOnClickListener(@buttonClickCallback);
  params := TAbsoluteLayout_LayoutParams.Create(320, 50, 0, 60);
  layout.addView(btn, params);
  params.Free;
  Activity.setContentView(layout);
end;
Felipe Monteiro de Carvalho

Reply by email

Sven Barth
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 42 lines
On Fri, Feb 17, 2012 at 9:11 AM, wrote: > Android uses XML files to specify the layout. This is the recommended way by > Google. You can build the GUI in code as well, but then you're pretty much > in uncharted territory. It is pretty trivial to build the UI without XML. I never used the XML part while programming for Android. For example (in pseudo-code): procedure TMyActivity.OnCreate; var layout: TAbsoluteLayout; params: TAbsoluteLayout_LayoutParams; tv: TTextView; et: TTextView; btn: TButton; ClickCount: Integer = 0; begin // Prepares the UI of the program layout := TAbsoluteLayout.Create; tv := TTextView.Create; tv.setText('The first Pascal Android application =)'); params := TAbsoluteLayout_LayoutParams.Create(320, 300, 0, 120); layout.addView(tv, params); params.Free; et := TEditText.Create; et.setText('edit me please'); params := TAbsoluteLayout_LayoutParams.Create(320, 50, 0, 0); layout.addView(et, params); params.Free; btn := TButton.Create; btn.setText('Go!'); btn.setOnClickListener(@buttonClickCallback); params := TAbsoluteLayout_LayoutParams.Create(320, 50, 0, 60); layout.addView(btn, params); params.Free; Activity.setContentView(layout); end;

This part is rather easy, but it gets more interesting when using menus or the views for items in list views.

Also the XML layouts allows for a more clean seperation of layout and code ;)

Regards,
Sven

Reply by email

Unknown author
to Sven Barth
Sven Barth wrote 9 lines
Am 17.02.2012 10:23, schrieb Felipe Monteiro de Carvalho: > On Fri, Feb 17, 2012 at 9:11 AM, wrote: >> Android uses XML files to specify the layout. This is the recommended way >> by >> Google. You can build the GUI in code as well, but then you're pretty much >> in uncharted territory. > > It is pretty trivial to build the UI without XML. I never used the XML > part while programming for Android. For example (in pseudo-code):

I know it is trivial (did it myself), but I just meant to say it is not the 'recommended way', hence you're in 'uncharted territory' =-)

Michael.

Reply by email

Michael Van Canneyt
to Michael Schnell: I suppose the Android SDK by Google provides a GUI designer that can be used here ...…
Michael Schnell wrote 6 lines
On 02/17/2012 09:11 AM, wrote: > Android uses XML files to specify the layout. This is the recommended way > by > Google. I suppose the Android SDK by Google provides a GUI designer that can be used here ...

Not really. You should use Eclipse is about the only recommendation (like that's going to happen). There is an DroidDraw open source program which can produce the necessary XML files.

Michael.

Reply by email

Sven Barth
to Michael Van Canneyt
Michael Van Canneyt wrote 15 lines
On Fri, 17 Feb 2012, Michael Schnell wrote: > On 02/17/2012 09:11 AM, wrote: >> Android uses XML files to specify the layout. This is the recommended >> way by >> Google. > I suppose the Android SDK by Google provides a GUI designer that can > be used here ... Not really. You should use Eclipse is about the only recommendation (like that's going to happen). There is an DroidDraw open source program which can produce the necessary XML files.

Maybe it's time to implement some non-LCL designer for that? :D

Regards,
Sven

Reply by email

Graeme Geldenhuys
to Michael Schnell: Which is desirable for appropriately schooled programmers but very uncommon in the…
Michael Schnell wrote 8 lines
On 02/17/2012 10:27 AM, Sven Barth wrote: > > > Also the XML layouts allows for a more clean seperation of layout and code > ;) > Which is desirable for appropriately schooled programmers but very uncommon in the "RAD-infected" Lazarus and Delphi community ;-) .

Actually, Delphi and Lazarus also use external files for the UI. But instead of XML, they are some pascal object files (*.lfm & *.dfm).

Now if you were talking about fpGUI's UI Designer, then yes, there the UI code is generated as source code. But, I still have clear separation between UI and business code/objects. The form unit is what I consider the UI, so the UI Designer is welcome to write code inside that. My business objects, eg TLearner, TSchool etc are in separate units, learner.pas and school.pas, respectively. The business objects know nothing about the UI. ;-)

Regards, ? - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

Reply by email

Graeme Geldenhuys
to Sven Barth: Maybe it's time to implement some non-LCL designer for that? :D Sven
Sven Barth <pascaldragon at ... wrote
Maybe it's time to implement some non-LCL designer for that? :D

That is probably a smart idea. The Lazarus LCL Form Designer can already save to XML too, it just can't read XML (as far as I know).

Regards, ? - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

Reply by email

Sven Barth
to Graeme Geldenhuys: Actually, Delphi and Lazarus also use external files for the UI. But instead of XML, they…
Graeme Geldenhuys wrote 13 lines
On 17 February 2012 12:05, Michael Schnell wrote: > On 02/17/2012 10:27 AM, Sven Barth wrote: >> >> >> Also the XML layouts allows for a more clean seperation of layout and code >> ;) >> > Which is desirable for appropriately schooled programmers but very uncommon > in the "RAD-infected" Lazarus and Delphi community ;-) . Actually, Delphi and Lazarus also use external files for the UI. But instead of XML, they are some pascal object files (*.lfm& *.dfm).

The difference between Delphi/Lazarus and Android is that in the former there still exists a GUI class (descendant of TForm, TFrame, etc.) containing all available controls that needs to be instantiated. In case of Android you simply pass the ID of the layout to the containing "control" (the activity or e.g. the listview) and it instantiates all controls itself.

Regards,
Sven

Reply by email

Reimar Grabowski
to Michael Van Canneyt: Not really. You should use Eclipse is about the only recommendation (like that's going to…
Show quoted text 8 lines
On Fri, 17 Feb 2012, Michael Schnell wrote: > I suppose the Android SDK by Google provides a GUI designer that can be used > here ... Not really. You should use Eclipse is about the only recommendation (like that's going to happen).

There is a GUI designer integrated in the Eclipse plugin (and IMHO quite a good one with preview functions for different phone or tablet resolutions and other goodies). Developing with Eclipse for Android is a pleasant experience with all the tools you need very well integrated into the IDE. Pascal development on the other hand is a little bit more cumbersome and not so pleasant at all, because of no integration to speak of. It is not really difficult in any way but the Java + Eclipse way makes for a lot smoother experience. But I am one of those strange guys that always liked Eclipse and I don't really understand that Eclipse bashing.

R.

Reply by email

Marc Santhoff
to Felipe Monteiro de Carvalho: It is pretty trivial to build the UI without XML. I never used the XML part while…

Am Freitag, den 17.02.2012, 10:23 +0100 schrieb Felipe Monteiro de Carvalho:

Show quoted text 21 lines
On Fri, Feb 17, 2012 at 9:11 AM, wrote: > Android uses XML files to specify the layout. This is the recommended way by > Google. You can build the GUI in code as well, but then you're pretty much > in uncharted territory. It is pretty trivial to build the UI without XML. I never used the XML part while programming for Android. For example (in pseudo-code): procedure TMyActivity.OnCreate; var layout: TAbsoluteLayout; params: TAbsoluteLayout_LayoutParams; tv: TTextView; et: TTextView; btn: TButton; ClickCount: Integer = 0; begin // Prepares the UI of the program layout := TAbsoluteLayout.Create; tv := TTextView.Create;

[...]

Show quoted text 11 lines
params.Free; btn := TButton.Create; btn.setText('Go!'); btn.setOnClickListener(@buttonClickCallback); params := TAbsoluteLayout_LayoutParams.Create(320, 50, 0, 60); layout.addView(btn, params); params.Free; Activity.setContentView(layout); end;

Very similar to what Java IDEs generate for form building code. ;)

Beautiful, very easy to handle and reagularly looking code. Besides having to self draw any component that's nice. But by code reuse the drawing issue will be solved very soon once started, I assume.

Thank you!
Marc

Marc Santhoff

Reply by email

Marc Santhoff
to Unknown author: There are 2 approaches: 1. Do as Felipe does. He has described how it works. 2. Use the…

Am Freitag, den 17.02.2012, 09:11 +0100 schrieb
:

Show quoted text 24 lines
On Fri, 17 Feb 2012, Marc Santhoff wrote: > Hi, > > I'd like to know, how GUI building for Android is handled using Lazarus. > > I have pretty much no idea of the Android SDK or things, but I > understand that this target involves compiling the code to Java byte > code. The details are not what I need at the moment, only a broad > overview how things work together and what role Lazarus plays in the GUI > part. There are 2 approaches: 1. Do as Felipe does. He has described how it works. 2. Use the JVM backend. In that case, you make direct use of the Java classes and the android API. Your app willl look and behave like any other Android app. (I am not sure what Felipe's approach results in) In the second case, Lazarus offers no help except that it's an excellent Pascal editor/compiler. But the GUI designing part of Lazarus is then not used. You must create the XML files manually.

I see, my next stop will be the Android SDK for understanding this XML type for describing the viasual part.

Show quoted text 7 lines
> > How is the GUI specified, is it drawn like building a form or is it made > by drawing on a canvas in code? Android uses XML files to specify the layout. This is the recommended way by Google. You can build the GUI in code as well, but then you're pretty much in uncharted territory.

OK, good to know.

Show quoted text 10 lines
> > Or does Lazarus/fpc only generate the event handlers an making a GUI is > a seperate task for a HTML designer or the like? The android API does not know event handlers as Object Pascal does. It has some form of callback objects, which are pretty much the same thing, yet they work slightly different. Basically, your class must expose a certain interface, and then it can be assigned as the 'event handling object' to the GUI control.

Reminds me of GTK. Semms to be no big deal ...

Show quoted text 5 lines
It's probably easier to see it work in code than explain in words :-) I just wrote an app in this way. It has about 160 lines of code (including declaration) for a 2-form program that talks to a database to show some stuff on screen.

Wetting my appetite here, is that program already in some repo or publicly visible? ;)
Or what magazine or book do I need to buy?

Currently I'm only sorting out the masses of information, there are some tutorials in magazines already, but since the goal is to understand how to write android apps fpc will be most welcome.

Thanks a lot!
Marc

Marc Santhoff

Reply by email

Sven Barth
to Marc Santhoff
Marc Santhoff wrote 9 lines
> It's probably easier to see it work in code than explain in words :-) > > I just wrote an app in this way. It has about 160 lines of code (including > declaration) for a 2-form program that talks to a database to show some > stuff on screen. Wetting my appetite here, is that program already in some repo or publicly visible? ;) Or what magazine or book do I need to buy?

Look for the XFree. The current issue has Felipe's native method as an article and maybe the next(?) one will have Michael's article.

The issue before that contained an article about the JVM port of FPC (without Android). I don't have the last issue though only the current one, so I can't comment on that article. :(

Regards,
Sven

Reply by email

Sven Barth
to Sven Barth
Sven Barth wrote 18 lines
On 26.02.2012 14:34, Marc Santhoff wrote: >> It's probably easier to see it work in code than explain in words :-) >> >> I just wrote an app in this way. It has about 160 lines of code >> (including >> declaration) for a 2-form program that talks to a database to show some >> stuff on screen. > > Wetting my appetite here, is that program already in some repo or > publicly visible? ;) > Or what magazine or book do I need to buy? Look for the XFree. The current issue has Felipe's native method as an article and maybe the next(?) one will have Michael's article. The issue before that contained an article about the JVM port of FPC (without Android). I don't have the last issue though only the current one, so I can't comment on that article. :(

Small correction: freeX not XFree ;)

Regards,
Sven

Reply by email

Felipe Monteiro de Carvalho
to Sven Barth: Look for the XFree. The current issue has Felipe's native method as an article and maybe…
Sven Barth wrote 7 lines
On 26.02.2012 14:34, Marc Santhoff wrote: > Wetting my appetite here, is that program already in some repo or > publicly visible? ;) > Or what magazine or book do I need to buy? Look for the XFree. The current issue has Felipe's native method as an article and maybe the next(?) one will have Michael's article.

To complement:

Here is the website of the FreeX magazine: http://www.cul.de/freex.html

Felipe Monteiro de Carvalho

Reply by email

Sven Barth
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 7 lines
On Mon, Feb 27, 2012 at 10:01 AM, Felipe Monteiro de Carvalho wrote: > Here is the website of the FreeX magazine: http://www.cul.de/freex.html Aha, noting that FreeX is in german. If you can't read german you can buy the Blaise Pascal Magazine:

Did you note Marc's E-Mail address? "@web.de" So it's very likely that he is a German speaker which is why I didn't say anything about freeX being German.

Show quoted text 5 lines
http://www.blaisepascal.eu/ Issue #20 has an article about Android Programming using the LCL.

I recommend reading BlaisePascal nevertheless as well ;)

Regards,
Sven

Reply by email

Marc Santhoff
to Sven Barth
Sven Barth wrote 6 lines
Am 27.02.2012 10:03, schrieb Felipe Monteiro de Carvalho: > On Mon, Feb 27, 2012 at 10:01 AM, Felipe Monteiro de Carvalho > wrote: >> Here is the website of the FreeX magazine: http://www.cul.de/freex.html > > Aha, noting that FreeX is in german.

Interesting, many thanks. I didn't even know these magazine exists ...

Show quoted text 5 lines
> If you can't read german you can buy the Blaise Pascal Magazine: Did you note Marc's E-Mail address? "@web.de" So it's very likely that he is a German speaker which is why I didn't say anything about freeX being German.

Genau.

Show quoted text 7 lines
> > http://www.blaisepascal.eu/ > > Issue #20 has an article about Android Programming using the LCL. > I recommend reading BlaisePascal nevertheless as well ;)

Nice, any source of information promoting object pascal is very welcome. I knew this one, but lost track of it.

Thanks to you all,
Marc

Marc Santhoff

Reply by email