Recent

Author Topic: Android Module Wizard  (Read 704806 times)

Martin Lowry

  • New Member
  • *
  • Posts: 17
Potential Flaw in Android Module Wizard
« Reply #1005 on: January 31, 2018, 01:08:30 pm »
Hi All,

I've been using LAMW now for nearly a month and am very impressed with it. It's obviously taken a huge amount of work to get it to where it is now. Congratulations and thanks.

However I do have a problem  (isn't there always one  :)). I'm writing a database App using jSQLDataaccess and jSQLCursor with jGridview to display my data. Unfortunately there isn't a jDBGridView (I know it would be a big task but much appreciated) so I'm stringing these together on the native code side like so:

for R := 0 to sqlCursor.RowCount-1 do
begin
  for C := 0 to sqlCursor.ColCount-1 do
    Gridview.Cells(C, R) := sqlCursor.GetValueAsString(c);
  sqlCursor.MoveToNext;
end;

and here come the issue, I can't display all my records in the Gridview without running out of local reference space in the JNI.  I trace this to the JNI function 'jSqliteCursor_GetValueAsString' in 'And_jni_Bridge.pas' which uses GetStringUTFChars to obtain the field value. It returns to my function without ever calling ReleaseStringUTFChars so the references accumulate in the JNI and eventually cause the App to crash. The JNI spec recommends always to call ReleaseStringUTFChars, irrespective of the value of the isCopy parameter to GetStringUTFChars so that its local reference stack can be cleaned by the GC process.  I've tried several solutions to make a copy of the string value and then call ReleaseStringUTFChars but they all fail with the same error.  Does anybody have a solution?

This mechanism is used in several places in LAMW so could potentially cause problems in other situations too.

Your responses awaited with eagerness :)

Cheers

2-2-18  Edited out the silly mistake :) The problem remains.
« Last Edit: February 02, 2018, 12:07:25 pm by MrtnLowr »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: Android Module Wizard
« Reply #1006 on: February 02, 2018, 12:41:27 am »
What about:

Code: Pascal  [Select][+][-]
  1. for R := 0 to sqlCursor.RowCount -1  do   // <<-----try change here
  2. begin
  3.     for C := 0 to sqlCursor.ColCount - 1 do   // <<-----try change here
  4.     begin
  5.     .....
  6.     end;
  7. end
  8.  
« Last Edit: February 02, 2018, 12:44:22 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Martin Lowry

  • New Member
  • *
  • Posts: 17
Re: Android Module Wizard
« Reply #1007 on: February 02, 2018, 12:06:13 pm »
Hi jmpessoa,

Whoops, that was a silly mistake in my pseudo-code (now edited). What you wrote was what I was actually doing in the App, so the problem remains.

Cheers

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: Android Module Wizard
« Reply #1008 on: February 02, 2018, 04:07:55 pm »

Ok. Write here you rowCount and colCount ....
[maybe a gridview capacity ???]
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Martin Lowry

  • New Member
  • *
  • Posts: 17
Re: Android Module Wizard
« Reply #1009 on: February 02, 2018, 05:32:24 pm »
Hi jmpessoa,

Quite a small table really for a DB,  120 rows by 18 columns, all fields as strings.  Would that be too big for a gridview?

What really got me posting was the logcat output: see attached.

Cheers



Horas

  • Newbie
  • Posts: 1
Re: Android Module Wizard
« Reply #1010 on: March 10, 2018, 10:29:10 am »
Dear jmpessoa,
  I'm using LAMW for quit some time now, and I would like to thank you and please improve it more and keep it upto datey.
I would like to upload an image file to my http server using httpclient post, Can you help me.
jHttpClient looks like doesn't support file upload, please can you provide me with an example code to upload file or image from the android mobile to http server
Many thanks,
Horas

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: Android Module Wizard
« Reply #1011 on: March 11, 2018, 03:18:36 am »
Hello, Horas!

I will try improve jHttpClient!

Thank you!

PS.

As a side note: you can try pure fpc stuff...
put this units [from: "\lazarus\fpc\3.1.1\source\packages\fcl-web\src\base"]
fphttpclient.pp
httpdefs.pp
httpprotocol.pp

 in your project  "....\jni"  folder:

The "GET" sample is here:

Code: Pascal  [Select][+][-]
  1. unit unit1;
  2.  
  3. {$mode delphi}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, AndroidWidget, Laz_And_Controls, fphttpclient, httpdefs,
  9.   httpprotocol;
  10.  
  11. type
  12.  
  13.   { TAndroidModule1 }
  14.  
  15.   TAndroidModule1 = class(jForm)
  16.     jButton1: jButton;
  17.     procedure jButton1Click(Sender: TObject);
  18.   private
  19.     {private declarations}
  20.   public
  21.     {public declarations}
  22.   end;
  23.  
  24. var
  25.   AndroidModule1: TAndroidModule1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31.  
  32. { TAndroidModule1 }
  33.  
  34. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  35. var
  36.   resp: string;
  37. begin
  38.      With TFPHTTPClient.Create(Nil) do
  39.       try
  40.          resp:= Get('http://....');
  41.       finally
  42.         Free;
  43.       end;
  44.       ShowMessage(resp);
  45. end;
  46.  
« Last Edit: March 11, 2018, 04:52:02 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Martin Lowry

  • New Member
  • *
  • Posts: 17
LAMW: onNewIntent
« Reply #1012 on: March 23, 2018, 04:43:24 pm »
Hi,

I was hoping to use Activity.onNewIntent to communicate new data to a single_instance task but see that the event is not surfaced in jForm even though all the necessary code is present in App.java, Controls.java and AndroidWidget.pas.  Will it work if I just un-comment the appropriate lines?

Cheers

Sergei

  • New member
  • *
  • Posts: 8
Re: Android Module Wizard
« Reply #1013 on: March 24, 2018, 02:52:03 pm »
Hello,

writing for the first time here, so thanks a lot for the LAMW tools, the Lazarus + LAMW approach to Android development seems rocket-fast compared to the alternatives. Also I like the LAMW widget model, it seems to me more straightforward than the LCL applied to mobile devices.

I need your LAMW experts' help though. As I tried creation of the wrappers around an Android widget, I used the Smart LAMW Designer tool (my config is Laz4android 1.8/ FPC 3.0.4 on Windows 10 x64, Android platform 19, Android SDK from tools_r25.2.5-windows):
  • Tools > [Lamw] Android Module Wizard > New jComponent Create
  • for my tests I pasted the code of \lazandroidmodulewizard\java\lamwdesigner\jToggleButton.java in the Java tab
  • right-clicked > Write  [Draft] Pascal jVisualControl Interface
  • after a couple of warnings, I got some code in the Pascal tab
   
My question is about these fragments in the generated Pascal code:
Code: Pascal  [Select][+][-]
  1. unit lass;
  2. class = class(jVisualControl)
  3. constructor class.Create(AOwner: TComponent);
  4. procedure class_SetBackgroundDrawable(env: PJNIEnv; _class: JObject; _imageIdentifier: string);
   
Is that possible to somehow configure the tool to generate something like this instead:
Code: Pascal  [Select][+][-]
  1. unit togglebutton;
  2. jToggleButton = class(jVisualControl)
  3. constructor jToggleButton.Create(AOwner: TComponent);
  4. procedure jToggleButton_SetBackgroundDrawable(env: PJNIEnv; _class: JObject; _imageIdentifier: string);
   
I understand, that jToggleButton is already there, but I saw the same behavior for any Java class name.

Thank you for your help,
Sergei

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: Android Module Wizard
« Reply #1014 on: March 24, 2018, 05:05:07 pm »
Hi, Sergei!

Quote
class = class(jVisualControl)

Here we got a bug!!!

Please change "public class jToggleButton"  to  "class jToggleButton" before
right-clicked > Write  [Draft] Pascal jVisualControl Interface...
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Sergei

  • New member
  • *
  • Posts: 8
Re: Android Module Wizard
« Reply #1015 on: March 24, 2018, 05:48:57 pm »
Thank you so much, the workaround works here!

Sergei

  • New member
  • *
  • Posts: 8
Re: Android Module Wizard
« Reply #1016 on: March 26, 2018, 12:18:37 pm »
Hi Jose, experts,

is that possible to create a LAMW wrapper for a 3-rd party widget, indirectly subclassing Android SDK widgets?

I am trying to connect the MaskEditText widget (https://github.com/santalu/mask-edittext). The widget is inheriting from android.support.v7.widget.AppCompatEditText and sits in its com.santalu.maskedittext package. I tried to create a directory structure for that package in several places of the source tree, but to no avail. Most likely modifications to the Gradle build are necessary too.

Also, if a widget had dependencies to jars/Gradle artifacts in outside repos, how can I configure tfpandroidbridge_pack.lpk or my project?

Any pointers are highly appreciated.
Sergei

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: Android Module Wizard
« Reply #1017 on: March 27, 2018, 01:24:35 am »
Hi Sergei!

Incoming "LAMW 0.8"  will support  "google support libraries" (AppCompat,  design, Cardview,  ReciclerView, etc..) and Gradle build system ...

A preview is here:     https://od.lk/f/Ml8xNTU4Mjc1NDVf     [updated!!!]

It would be interesting someone could do some testing before a major update of the git repository ....

   NEW! "AppCompat" material theme support!
   NEW! "Android Bridges Support" component palete to support "AppCompat" material theme!
      NEW! jsDrawerLayout component
      NEW! jsNavigationView component
      NEW! jsCoordinatorLayout component
      NEW! jsAppBarLayout component
      NEW! jsCollapsingToolbarLayout component
      NEW! jsToolbar component
      NEW! jsTabLayout component
      NEW! jsNestedScrollView component
      NEW! jsRecyclerView component
      NEW! jsViewPager component
      NEW! jsCardView component
      NEW! jsFloatingButton component
      NEW! jsBottomNavigationView component
      NEW! jsTextInput component

   NEW! demo AppCompatFloatingButtonDemo1
   NEW! demo AppCompatViewPagerDemo1
   NEW! demo AppCompatNavigationDrawerDemo1
   NEW! demo AppCompatCollapsingToolbarDemo1
   NEW! demo AppCompatTabLayoutDemo1
   NEW! demo AppCompatTabLayoutDemo2

   NEW! jDBListView component by Martin Lowry [Thanks!]
   NEW! demo AppDBGridViewDemo1  by Martin Lowry [Thanks!]

       Edited: demos preview:  https://od.lk/f/Ml8xNTU3ODQyMDlf
   REQUIREMENTS:

      [LAMW 0.8] "AppCompat" [material] theme need:
      1. Java JDK 1.8
      2. Gradle 4.1
      3. Android SDK "plataforms" 25 + "build-tools" 25.0.3 [or]
      3. Android SDK "plataforms" 26 + "build-tools" 26.0.3 [or]
      3. Android SDK "plataforms" 27 + "build-tools" 27.0.3
      4. Android SDK/Extra  "Support Repository"
      5. Android SDK/Extra  "Support Library"


Thanks!
« Last Edit: April 01, 2018, 03:35:41 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Sergei

  • New member
  • *
  • Posts: 8
Re: Android Module Wizard
« Reply #1018 on: March 28, 2018, 04:18:30 pm »
Many thanks for sharing the 0.8 preview, seems like a huge amount of work has been done.

Installation went smoothly, but I was not able to use the packages as my android-26 config was not recognized in the new project form.

I would love to try tackling the code, can you give me some light on how to debug the 3 *.lpk packages in the most efficient way? What strategy are you using? Is there any integration test somewhere to initialize and run the forms?

« Last Edit: March 28, 2018, 04:22:09 pm by Sergei »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: Android Module Wizard
« Reply #1019 on: March 28, 2018, 11:15:09 pm »
Quote
but I was not able to use the packages as my android-26 config was not recognized in the new project form.

You can look in "...sdk\build-tools" if you lost the "26.x.x"  folder...

You can try  "uformworkspace.pas"  code [LAMW folder "android_wizard"] ... look for
method "GetMaxSdkPlatform" in line:

Code: Pascal  [Select][+][-]
  1. if HasBuildTools(intAux, outBuildTool) then  Result:= intAux;
  2.  

Edited:

LAMW 0.8 preview:  https://od.lk/f/Ml8xNTU4Mjc1NDVf [updated!!!]

demos preview:  https://od.lk/f/Ml8xNTU3ODQyMDlf

« Last Edit: April 01, 2018, 03:35:13 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018