Recent

Author Topic: Android Module Wizard  (Read 705606 times)

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #375 on: April 17, 2015, 02:48:48 pm »
how can i get itemindex (number of item clicked) same as function listview1.itemindex of TListview on lazarus ? :o

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #376 on: April 17, 2015, 06:42:25 pm »
@m4u_hoahoctro

Quote
....how can i get itemindex (number of item clicked)....

In event "ClickCaptionItem"  or ClickItem [jListView]:

Code: [Select]
procedure TAndroidModule1.jListView1ClickCaptionItem(Sender: TObject; Item: integer; caption: string);
begin
       case Item of
          0: ............
          1: ...........
          2: ...........
       end;
end; 

There is too IsItemChecked(index: integer) when you have a checkbox or radio button composing you item row;
Code: [Select]
  if jListView1.IsItemChecked(1) then ....
  else ......
 

Thank You.
« Last Edit: April 17, 2015, 06:46:31 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #377 on: April 18, 2015, 05:21:47 am »
thanks, and :-[
I am using Bluestacks as a virtual android device,but I don't know where virtual sd card drive is, please help :-\

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #378 on: April 18, 2015, 05:43:45 am »
@m4u_hoahoctro

Sorry... I do not know Bluestacks virtual device ....

But I can say to you: if possible use real device! 

Virtual device is the origin of many strangers problems!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Android Module Wizard
« Reply #379 on: April 18, 2015, 06:19:18 am »
thanks, and :-[
I am using Bluestacks as a virtual android device,but I don't know where virtual sd card drive is, please help :-\
I think you should ask bluestacks maintainer instead of us. Surely they know their product best.

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #380 on: April 26, 2015, 12:03:45 pm »
I used this code with Button1, but on phone using android 4.2, it auto closes
so where is error ?
Code: [Select]
procedure TAndroidModule1.jButton1Click(Sender: TObject);
var cpyok:boolean;
begin
  cpyok:=Self.CopyFile(Self.GetEnvironmentDirectoryPath(dirInternalAppStorage)+'/hello.txt',Self.GetEnvironmentDirectoryPath(dirSDCard)+'/hello.txt');
  if cpyok then showmessage('complete') else showmessage('error');
end;   

link of project:
https://app.box.com/s/z4mtl4g666atyxeqgc2306p0u8szikef

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #381 on: April 27, 2015, 11:18:34 pm »
@ m4u_hoahoctro

"dirInternalAppStorage" is the internal location where your App save files....  so, "hello.txt"  need be a file created and saved by your App... is that right?
« Last Edit: April 28, 2015, 02:14:35 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

horacio_ar

  • Newbie
  • Posts: 2
Re: Android Module Wizard
« Reply #382 on: May 02, 2015, 02:38:28 am »
jmpessoa: your work is impressive! very good job!
I tried Delphi XE8, and it works... but produce extra big application.
I tried Lazarus with customdraw, and is usefull for some things, but not native widgents. The edit control have some issues.
Then I tried AMW and got the best first impression!
Now the things I need to continue:
1) How to set the ActiveControl property to the form (the one that will have the focus on start)?
2) How to set the TabOrder?
I have 2 jEditText controls on the form and 1 jButton. Pressing NEXT on keyboard on the first control shoud activate the seccond one... For the seccond one the keyboard should say Finish (or so) and on activate this key should call the OnClic of the button. how to do this?
3) The 2nd jEditText control must accept only some characters. In this case it should allow only HEX characters (0 to 9 and A to F)... I did not found the way to do this... how can I do this?
4) I want to interact with a MS SQL Server. For this I fould jTds java library. I tried to understand how to create the components for this, but I was unable to find the approach? Any hint on this will be appreciated.
Other option should be using SqlDB, but need the .so library and I was unable to find it anyware.
Thats all for now.
Horacio

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #383 on: May 02, 2015, 04:39:00 am »
@horacio_ar

1. You can try handle the event "OnJNIPrompt" from jForm

Code: [Select]
procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);
begin
    jEditText1.SetFocus;
end;

2. You can try handle the event "OnEnter" from jEditText
[enter  --->  "enter" or "done" or "next" or "go" ...]

Code: [Select]
procedure TAndroidModule1.jEditText1Enter(Sender: TObject);
begin
     jEditText2.SetFocus;
end;

3. jEditText has the property "InputTypeEx" but very limited yet [I will try improve it!]

4. You can try "SQL Server"  via jHttpClient ... I do not know about sql client in android...

Thank you!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

rx3.fireproof

  • New Member
  • *
  • Posts: 49
Re: Android Module Wizard
« Reply #384 on: May 03, 2015, 06:02:57 pm »
Hello Jmpessoa


How to destroy the form (Androidmodule) and to free the memory. In my program are 23 forms (Androidmodule). If everything is created, the application is in memory of about 120 mb.

Now I am using a form with «actSplash».

I tried to use «self.finish». The form is destroyed, but not created again.

If it possible, show an example code.



With Respect
rx3.fireproof

ps        
I posted my app in Yandex.store :D
Thank you!
« Last Edit: May 04, 2015, 11:49:36 pm by rx3.fireproof »

greenzyzyzy

  • Full Member
  • ***
  • Posts: 249
Re: Android Module Wizard
« Reply #385 on: May 06, 2015, 09:08:16 am »
   Lazarus Android Module Wizard
                 "Form Designer and Components development model!"
      
   "A wizard to create JNI Android loadable module (.so) in Lazarus/Free Pascal using
   [datamodule like] Form Designer and Components!"

   Author: Jose Marques Pessoa : jmpessoa__hotmail_com

      https://github.com/jmpessoa/lazandroidmodulewizard

Please, to start:
   "readme.txt"
   "install_tutorial_ant_users.txt"
   "install_tutorial_eclipse_users.txt"

Acknowledgements: Eny and Phil for the Project wizard hints...
                  http://forum.lazarus.freepascal.org/index.php/topic,20763.msg120823.html#msg120823

                  Felipe for Android support....

                  TrueTom for Laz4Android Package (laz4android1.1-41139)...
                  https://skydrive.live.com/?cid=89ae6b50650182c6&id=89AE6B50650182C6%21149

                  Lazarus forum community!

version 0.1 - August 2013

[1]Warning: at the moment this code is just a *proof-of-concept*

I. INSTALL LAZARUS PACKAGE (laz4android1.1-41139)

   1. From lazarus IDE

      1.1 Package -> Open Package -> "lazandroidwizardpack.lpk"
   
      1.2 From Package Wizard
          1.2.1 Compile
          1.2.2 Use -> Install

II. USE

1. From Eclipse IDE

  1.1. File -> New -> Android Application Project

  1.2. From Package Explore -> src
   
       Right click your recent created package -> new -> class 
   
       Enter new class name... (ex. JNIHello)
   
       Edit class code for wrapper native methods (ex...)

Code: [Select]

                package org.jmpessoa.app1;
 
public class JNIHello {

   public native String getString(int flag);
   public native int getSum(int x, int y);

                   static {
try {
          System.loadLibrary("jnihello");           
} catch(UnsatisfiedLinkError ule) {
    ule.printStackTrace();
}
                   }
             } 


  1.3. warning: System.loadLibrary("...") must match class Name lower case...
       ex. JNIHello -> "jnihello"

2. From lazarus IDE (laz4android1.1-41139)

   2.1 Project -> New Project
   2.2 JNI Android Module

2.1. From JNI Android Module set Paths
   2.1.1 Path to Eclipse Workspace
       ex. C:\adt32\eclipse\workspace
           
   2.1.2 Path to Ndk Plataforms
       ex. C:\adt32\ndk7\platforms\android-8\arch-arm\usr\lib
 
   2.1.3 Path to Ndk Toolchain 
       ex. C:\adt32\ndk7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\lib\gcc\arm-linux-androideabi\4.4.3

2.2. From JNI Android Module select Java wrapper class for native methods.... (ex JNIHello)

2.3. OK! 

2.3.1 - Data Module Form Code:

Code: [Select]
{Hint: save all files to location: C:\adt32\eclipse\workspace\App1\jni }
unit unit1;
 
{$mode objfpc}{$H+}
 
interface
 
uses
  Classes, SysUtils;
 
type
  TAndroidModule1 = class(TDataModule)
    private
      {private declarations}
    public
      {public declarations}
  end;
 
var
  AndroidModule1: TAndroidModule1;

implementation
 
{$R *.lfm}
 
end.

2.3.2. Library Code:
Code: [Select]
{hint: save all files to location: C:\adt32\eclipse\workspace\App1\jni }
library jnihello;
 
{$mode delphi}
 
uses
  Classes, SysUtils, CustApp, jni, Unit1;
 
const
  curClassPathName: string='';
  curClass: JClass=nil;
  curVM: PJavaVM=nil;
  curEnv: PJNIEnv=nil;
 
type
 
  TAndroidApplication = class(TCustomApplication)
   public
     procedure CreateForm(InstanceClass: TComponentClass; out Reference);
     constructor Create(TheOwner: TComponent); override;
     destructor Destroy; override;
  end;
 
procedure TAndroidApplication.CreateForm(InstanceClass: TComponentClass; out Reference);
var
  Instance: TComponent;
begin
  Instance := TComponent(InstanceClass.NewInstance);
  TComponent(Reference):= Instance;
  Instance.Create(Self);
end;
 
constructor TAndroidApplication.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  StopOnException:=True;
end;
 
destructor TAndroidApplication.Destroy;
begin
  inherited Destroy;
end;
 
var
  Application: TAndroidApplication;
 
{ Class:     org_jmpessoa_app1_JNIHello
  Method:    getString
  Signature: (I)Ljava/lang/String; }
function getString(PEnv: PJNIEnv; this: JObject; flag: JInt): JString; cdecl;
begin
  {your code....}
  {Result:=;}
end;

{ Class:     org_jmpessoa_app1_JNIHello
  Method:    getSum
  Signature: (II)I }
function getSum(PEnv: PJNIEnv; this: JObject; x: JInt; y: JInt): JInt; cdecl;
begin
  {your code....}
  {Result:=;}
end;

const NativeMethods:array[0..1] of JNINativeMethod = (
   (name:'getString';
    signature:'(I)Ljava/lang/String;';
    fnPtr:@getString;),
   (name:'getSum';
    signature:'(II)I';
    fnPtr:@getSum;)
);

function RegisterNativeMethodsArray(PEnv: PJNIEnv; className: PChar; methods: PJNINativeMethod; countMethods:integer):integer;
begin
  Result:= JNI_FALSE;
  curClass:= (PEnv^).FindClass(PEnv, className);
  if curClass <> nil then
  begin
    if (PEnv^).RegisterNatives(PEnv, curClass, methods, countMethods) > 0 then Result:= JNI_TRUE;
  end;
end;
 
function RegisterNativeMethods(PEnv: PJNIEnv): integer;
begin
  curClassPathName:= 'org/jmpessoa/app1/JNIHello';
  Result:= RegisterNativeMethodsArray(PEnv, PChar(curClassPathName), @NativeMethods[0], Length(NativeMethods));
end;
 
function JNI_OnLoad(VM: PJavaVM; reserved: pointer): JInt; cdecl;
var
  PEnv: PPointer {PJNIEnv};
begin
  PEnv:= nil;
  Result:= JNI_VERSION_1_6;
  (VM^).GetEnv(VM, @PEnv, Result);
  if PEnv <> nil then RegisterNativeMethods(PJNIEnv(PEnv));
  curVM:= VM {PJavaVM};
  curEnv:= PJNIEnv(PEnv);
end;
 
procedure JNI_OnUnload(VM: PJavaVM; reserved: pointer); cdecl;
begin
  if curEnv <> nil then (curEnv^).UnregisterNatives(curEnv, curClass);
  curClass:= nil;
  curEnv:= nil;
  curVM:= nil;
  Application.Terminate;
  FreeAndNil(Application);
end;

exports
  JNI_OnLoad name 'JNI_OnLoad',
  JNI_OnUnload name 'JNI_OnUnload',
  getString name 'Java_org_jmpessoa_app1_JNIHello_getString',
  getSum name 'Java_org_jmpessoa_app1_JNIHello_getSum';
 
begin
  Application:= TAndroidApplication.Create(nil);
  Application.Title:= 'My Android Library';
  Application.Initialize;
  Application.CreateForm(TAndroidModule1, AndroidModule1);
end.

2.4. follow the code hint: "save all files to location....."

2.5. From Lazarus IDE (laz4android1.1-41139)
     Run -> Build

III. BUILD AND RUN ANDROID APPLICATION

     1.  From Eclipse IDE

     1.1 right click your recent created project -> Run as -> Android Application

IV.  GIT HUB

     https://github.com/jmpessoa/lazandroidmodulewizard

     To facilitate follows first code release on attachment (*.rar) and some interface pictures...

     Have Fun!



how to use Android Module Wizard  to run a command line which in /system/bin

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #386 on: May 06, 2015, 05:35:23 pm »
@ rx3.fireproof

Quote
......I posted my app in Yandex.store :D

Congratulations!!!!!

Code: [Select]
....The form is destroyed, but not created again. If it possible, show an example code.

Ok I Will try some example code!

Thank you!


@greenzyzyzy

Quote
...how to use Android Module Wizard  to run a command line which in /system/bin ?

What you need? I can try ... but I do not know if we can run it in android without "root it"!

three comments:
1. There is a more updated "readme.txt"
2. Threre are two Lamw Applications Model [GUI and NoGui]
3. You can do a simple button click "hello world" [GUI] application with Lamw?

Thank you!

« Last Edit: May 06, 2015, 06:30:06 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

greenzyzyzy

  • Full Member
  • ***
  • Posts: 249
Re: Android Module Wizard
« Reply #387 on: May 07, 2015, 04:08:12 pm »
@ rx3.fireproof

Quote
......I posted my app in Yandex.store :D

Congratulations!!!!!

Code: [Select]
....The form is destroyed, but not created again. If it possible, show an example code.

Ok I Will try some example code!

Thank you!


@greenzyzyzy

Quote
...how to use Android Module Wizard  to run a command line which in /system/bin ?

What you need? I can try ... but I do not know if we can run it in android without "root it"!

three comments:
1. There is a more updated "readme.txt"
2. Threre are two Lamw Applications Model [GUI and NoGui]
3. You can do a simple button click "hello world" [GUI] application with Lamw?

Thank you!

thank you, but i slove the problem,it is a easy way to run command with asyncprocess unit.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #388 on: May 07, 2015, 05:23:54 pm »
@greenzyzyzy

Code: [Select]
.... i slove the problem,it is a easy way to run command with asyncprocess unit.

Can you put here a simple example code.... ???

Thank you!

Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

greenzyzyzy

  • Full Member
  • ***
  • Posts: 249
Re: Android Module Wizard
« Reply #389 on: May 08, 2015, 04:47:20 am »
@greenzyzyzy

Code: [Select]
.... i slove the problem,it is a easy way to run command with asyncprocess unit.

Can you put here a simple example code.... ???

Thank you!


well ,it is easy,in laz4android code like this:

uses
.....,asyncprocess;

procedure Tform1.Button1Click(Sender: TObject);
var
  proc:asyncprocess.TAsyncProcess;
begin
proc:=asyncprocess.TAsyncProcess.Create(nil);
proc.Executable:='su';
proc.Parameters.Add('-c');
proc.Parameters.Add('chmod 777 /dev/graphics/fb0');
proc.Execute;
proc.Free;
end;

 

TinyPortal © 2005-2018