Sign in Join

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

Mailing lists / fpc-pascal / 2014-04

Android/JNI control example

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

patspiper

Hi,

With the successful preliminary implementation of java events calling pascal code, my next step is to try to integrate android's visual controls. Can anyone give a very basic example using pascal/JNI only (even pseudo code) on how to create and display an android control from scratch? In other words, what are the steps needed?

To make an analogy, creating a Lazarus button requires these basic steps to make a button visible:
- Create the button object (TButton.Create)
- Set its owner (button.Owner := form)
- Set its parent (button.Parent := form)

Stephano

Reply by email

Mattias Gaertner
to patspiper
Show quoted text 12 lines
Hi, With the successful preliminary implementation of java events calling pascal code, my next step is to try to integrate android's visual controls. Can anyone give a very basic example using pascal/JNI only (even pseudo code) on how to create and display an android control from scratch? In other words, what are the steps needed? To make an analogy, creating a Lazarus button requires these basic steps to make a button visible: - Create the button object (TButton.Create) - Set its owner (button.Owner := form)

The Owner is only needed for streaming.

- Set its parent (button.Parent := form)

Mattias

Reply by email

patspiper
to Mattias Gaertner
Mattias Gaertner wrote 16 lines
On Thu, 24 Apr 2014 15:48:15 +0300 patspiper wrote: > Hi, > > With the successful preliminary implementation of java events calling > pascal code, my next step is to try to integrate android's visual > controls. Can anyone give a very basic example using pascal/JNI only > (even pseudo code) on how to create and display an android control from > scratch? In other words, what are the steps needed? > > To make an analogy, creating a Lazarus button requires these basic steps > to make a button visible: > - Create the button object (TButton.Create) > - Set its owner (button.Owner := form) The Owner is only needed for streaming.

The thought never occurred to me as setting the owner is as almost like breathing. You just don't think about it :)

Stephano

Reply by email

patspiper
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 7 lines
There is a JNI example app here: http://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/bindings/android-ndk/examples/jnitest/ It doesn't create a button, instead it creates a TextView, and it doesn't create it in Pascal, but in Java. Anyway, it is a starting point to do whatever you want, including creating buttons in Pascal.

Thanks.

I had already progressed but I am using
LazAndroidModuleWizard to kickstart, it seems I can't use that method, especially that the code that creates the button is called from the main data module. I am trying to find how to "inject" the button into the datamodule.

If the concept works, then the workflow of creating an android app with Lazarus would be:

- Use a project wizard to setup the project. It will place a fixed java snippet in the src project folder and set up manifest files and ancillary files.

- Run a tool which reads android "headers" and produces a pascal unit(s) according to certain rules.

- Code in pascal :)

The tool will produce for each java class a corresponding pascal class. For example, the pascal android media player class will be analogous to the java one, but acts as a gateway to the actual java class. It uses normal pascal events instead of listeners.

example code for the media player:
   gMediaPlayer := TJMediaPlayer.Create;
   ....
   gMediaPlayer.SetOnCompletionListener(DataModuleOnCompletion);
   gMediaPlayer.SetOnPreparedListener(DataModuleOnPrepared);
gMediaPlayer.SetDataSource('http://www.soundjay.com/button/button-1.mp3');
   gMediaPlayer.Prepare;
   gMediaPlayer.Start;
   ...
   gMediaPlayer.Free;

DataModuleOnCompletion and DataModuleOnPrepared are normal pascal methods (TNotifyEvent in this case).

Stephano

Reply by email