Android/JNI control example

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Android/JNI control example

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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Android/JNI control example

Mattias Gaertner
On Thu, 24 Apr 2014 15:48:15 +0300
patspiper <[hidden email]> 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.

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


Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Android/JNI control example

patspiper
On 24/04/14 15:50, Mattias Gaertner wrote:

> On Thu, 24 Apr 2014 15:48:15 +0300
> patspiper <[hidden email]> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Android/JNI control example

Felipe Monteiro de Carvalho
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.

--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Android/JNI control example

patspiper
On 25/04/14 00:12, Felipe Monteiro de Carvalho wrote:
> 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 stopped at setContentView. Since 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal