Recent

Author Topic: Android Module Wizard  (Read 743723 times)

jmpessoa

  • Hero Member
  • *****
  • Posts: 2330
Re: Android Module Wizard
« Reply #870 on: September 10, 2016, 07:02:12 am »
Hi Alfred,

I got success with the following settings:

jScrollView1:
Quote
    LayoutParamWidth = lpMatchParent
    LayoutParamHeight = lpHalfOfParent
    ScrollSize = 2000

jDrawingView1:
Quote
      PosRelativeToParent = [rpCenterInParent]
      LayoutParamWidth = lpMatchParent
      LayoutParamHeight = lpSevenEighthOfParent

Code: Pascal  [Select][+][-]
  1.   TAndroidModule1 = class(jForm)
  2.     jDrawingView1: jDrawingView;
  3.     jScrollView1: jScrollView;
  4.     procedure AndroidModule1Create(Sender: TObject);
  5.     procedure jDrawingView1Draw(Sender: TObject);
  6.     procedure jDrawingView1TouchMove(Sender: TObject; Touch: TMouch);
  7.   private
  8.     {private declarations}
  9.   public
  10.     {public declarations}
  11.     P: TPoint;
  12.   end;
  13.  
  14. var
  15.   AndroidModule1: TAndroidModule1;
  16.  
  17. implementation
  18.  
  19. {$R *.lfm}
  20.  
  21. { TAndroidModule1 }
  22.  
  23. procedure TAndroidModule1.jDrawingView1Draw(Sender: TObject);
  24. var
  25.   w1, h1: integer;
  26. begin
  27.   w1:= jDrawingView1.Width;
  28.   h1:= jDrawingView1.Height;
  29.  
  30.   //Frame
  31.   jDrawingView1.DrawLine(0,0,0,h1-1);
  32.   jDrawingView1.DrawLine(0,h1-1,w1-1,h1-1);
  33.   jDrawingView1.DrawLine(w1-1,h1-1,w1-1,0);
  34.   jDrawingView1.DrawLine(w1-1,0,0,0);
  35.  
  36.   jDrawingView1.DrawText('Drawing Test....',P.X,P.Y);
  37.   jDrawingView1.DrawText('P(x,y)=(' + IntToStr(P.X) + ',' + IntToStr(P.Y)+')',10,h1-30);
  38. end;
  39.  
  40. procedure TAndroidModule1.jDrawingView1TouchMove(Sender: TObject; Touch: TMouch);
  41. begin
  42.   P:= Point(Round(Touch.Pt.X), Round(Touch.Pt.Y));
  43.   jDrawingView1.Refresh;   //call OnDraw ....
  44. end;
  45.  
  46. procedure TAndroidModule1.AndroidModule1Create(Sender: TObject);
  47. begin
  48.   P.X:= 100;
  49.   P.Y:= 100;
  50. end;
  51.  
« Last Edit: September 10, 2016, 07:13:32 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1840
Re: Android Module Wizard
« Reply #871 on: September 10, 2016, 07:20:34 am »
Thanks.
And yes, that works ... but on my phone, the drawview does not fill the scrollview for 100%.
So, I am still investigating.

In the meantime, pleae find attached a new addition for scrollview : setFillViewport.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2330
Re: Android Module Wizard
« Reply #872 on: September 10, 2016, 07:38:42 am »

Thanks!

I will apply it!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1840
Re: Android Module Wizard
« Reply #873 on: September 10, 2016, 10:51:58 am »
Some intermediate results.

I saw in your source that you put a relative layout inside the scrollview.
I know that you have to do this to allow for more childs, while a scrollview can only handle a single child.

In my case, I have a single child (very high drawingview) that has to scroll with the scrollview.
IMHO, I think that we need a new basic scrollview without relative layout for situations where there is only a single child !

renabor

  • Jr. Member
  • **
  • Posts: 74
Re: Android Module Wizard
« Reply #874 on: September 12, 2016, 06:38:14 pm »
Hallo @jmpessoa!
With latest change i'm unable to compile due to something related with (i suppose) new Canvas.
Error message that I got is this:

Code: Java  [Select][+][-]
  1. E/art     (21788): Failed to register native method com.suevoz.borsa.Controls.pOnGLRenderer(JIII)V in /data/app/com.suevoz.borsa-2/base.apk
  2. D/AndroidRuntime(21788): Shutting down VM
  3. E/AndroidRuntime(21788): FATAL EXCEPTION: main
  4. E/AndroidRuntime(21788): Process: com.suevoz.borsa, PID: 21788
  5. E/AndroidRuntime(21788): java.lang.NoSuchMethodError: no static or non-static method "Lcom/suevoz/borsa/Controls;.pOnGLRenderer(JIII)V"
  6.  

have you any advice?

thank you!

FPC 3.2.2 | Lazarus 3.5 | Kubuntu 24.04 64bit

jmpessoa

  • Hero Member
  • *****
  • Posts: 2330
Re: Android Module Wizard
« Reply #875 on: September 12, 2016, 08:25:10 pm »
Hi Renabor,

please go to menu "Run" --> "Clean up an Build" ...

The "pOnGLRenderer"  was droped...

Now we have:

 "pOnGLRenderer1" for jCanvasES1

and

 "pOnGLRenderer2" for jCanvasES2


NOTE:  if you are using "old" "Controls.java"  then you will need upgrade
your project and then to do some "custom/hack" in the new code architecture....
« Last Edit: September 13, 2016, 12:04:35 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1840
Re: Android Module Wizard
« Reply #876 on: September 14, 2016, 08:07:37 am »
@jmpessoa
Please find attached a new version of drawingview.
This version can be dropped on a FrameLayout (i.e. scrollview) as well as on a RelativeLayout.

This drawing view itself is not that imortant however.
The included patch should be applied to all (visual) components.
It will allow all components to have a FrameLayout and RelativeLayout parent !!

Please review. I hope you will apply this patch.
It makes all components more flexible !

Edit:
And, if you like it, you can easily add a linear layout too !!
« Last Edit: September 14, 2016, 08:11:04 am by DonAlfredo »

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1840
Re: Android Module Wizard
« Reply #877 on: September 14, 2016, 12:49:05 pm »
Added LinearLayout into patch !

jmpessoa

  • Hero Member
  • *****
  • Posts: 2330
Re: Android Module Wizard
« Reply #878 on: September 14, 2016, 08:45:27 pm »


Hi Alfred!

Please, commit yours patchs!

If something stops working we will help to solve!

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

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1840
Re: Android Module Wizard
« Reply #879 on: September 15, 2016, 01:06:06 pm »
Done !
Lots of code changes ... beware of the typos ...  %)

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1840
Re: Android Module Wizard
« Reply #880 on: September 16, 2016, 12:21:14 pm »
@jmpessoa --> Feature request !

I would like to ask you for the possibility to add a canvas to ListView.
At the moment, I am doing this (on a long viewlist):

Code: Java  [Select][+][-]
  1. @Override
  2. public  void onDraw( Canvas canvas) {
  3.                 super.onDraw(canvas);
  4.                 View c = super.getChildAt(0);
  5.                 int scrollposition = -c.getTop() + super.getFirstVisiblePosition() * (c.getHeight()+super.getDividerHeight());
  6.                 Paint myPaint = new Paint();
  7.                 myPaint.setColor(Color.rgb(200, 0, 0));
  8.                 myPaint.setStrokeWidth(25);
  9.                 myPaint.setStyle(Paint.Style.STROKE);
  10.                 canvas.drawRect(100, 800 - scrollposition, 200, 900 - scrollposition, myPaint);
  11.         }
  12.  
  13. @Override
  14. protected void dispatchDraw(Canvas canvas) {
  15.                 super.dispatchDraw(canvas);
  16.                 View c = super.getChildAt(0);
  17.                 int scrollposition = -c.getTop() + super.getFirstVisiblePosition() * (c.getHeight()+super.getDividerHeight());
  18.                 Paint myPaint = new Paint();
  19.                 myPaint.setColor(Color.rgb(0, 200, 0));
  20.                 myPaint.setStrokeWidth(25);
  21.                 myPaint.setStyle(Paint.Style.STROKE);
  22.                 canvas.drawRect(100, 2000 - scrollposition, 400, 2200-scrollposition, myPaint);
  23.         }
  24.  

The former draws a square behind the ListView.
The latter draws a square before the ListView.
Both move along with scrolling, due to the scrollposition.

I would like to do this in an OnDraw and an OnDispatch of the listview (drawing on the attached Canvas).
These two will also have to transport the scroll-position !
Is this possible ?

Thanks.

renabor

  • Jr. Member
  • **
  • Posts: 74
Re: Android Module Wizard
« Reply #881 on: September 17, 2016, 11:55:21 am »
Hi all,

I have uploaded a brand new version of new_howto_install_by_renabor to github.

Please notice that the old new_how_to_install_by_renabor has been converted in several scripts!

Now all you have to do is run first script, "1-master-script.sh", that will call other scripts in the right sequence.

At the end you will have:

1) /etc/fpc.cfg moved to /etc/fpc.cfg.bak and substituted by a symlink
2) ndk, sdk and lamw code placed in a new directory $HOME/Android
3) fpc and lazarus code placed in a new directory $HOME/bin/freepascal
4) a lot of scripts in $HOME/bin/freepascal

and a running compiled full suite of freepascal and lazarus ready to crosscompile to android!

Version of software downloaded:

ndk            android-ndk-r11c-linux-x86_64
sdk            android-sdk_r24.4.1-linux
fpc (fixes)         3.0.1
lazarus          1.7

enjoy!

N.B. There is a bug in lamwdesigner.pas that make compiling problematic.
please change line 58 as
Code: [Select]
//    procedure OnDesignerModified(Sender: TObject{$If lcl_fullversion>1060004}; {%H-}PropName: ShortString{$ENDIF});
procedure OnDesignerModified(Sender: TObject);
and line 1009
Code: [Select]
//procedure TAndroidWidgetMediator.OnDesignerModified(Sender: TObject{$If lcl_fullversion>1060004}; {%H-}PropName: ShortString{$ENDIF});
procedure TAndroidWidgetMediator.OnDesignerModified(Sender: TObject);
« Last Edit: September 17, 2016, 06:39:41 pm by renabor »
FPC 3.2.2 | Lazarus 3.5 | Kubuntu 24.04 64bit

jmpessoa

  • Hero Member
  • *****
  • Posts: 2330
Re: Android Module Wizard
« Reply #882 on: September 19, 2016, 01:44:18 am »
Hi Alfred,

Something like that [??]:

added to "jListView.java"

Code: Java  [Select][+][-]
  1.         @Override
  2.         protected void dispatchDraw(Canvas canvas) {
  3.  
  4.             View c = super.getChildAt(0);
  5.         int scrollposition = -c.getTop() + super.getFirstVisiblePosition() * (c.getHeight()+super.getDividerHeight());                 
  6.                
  7.             //DO YOUR DRAWING ON UNDER THIS VIEWS CHILDREN
  8.                 controls.pOnBeforedispatchDraw(canvas, scrollposition);  //handle by pascal side
  9.                
  10.             super.dispatchDraw(canvas);
  11.            
  12.             //DO YOUR DRAWING ON TOP OF THIS VIEWS CHILDREN
  13.             controls.pOnAfterdispatchDraw(canvas,scrollposition);        //handle by pascal side    
  14.         }
  15.  

So in pascal [event] side we could use the param "canvas" to set "jCanvas"  and then draw some stuff... Something like that?

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jListView1BeforeDispatchDraw(Obj: TObject;
  2.   canvas: JObject; scrollposition: integer);
  3. begin
  4.   jCanvas1.SetCanvas(canvas);
  5.   jCanvas1.drawRect(100, 100, 400, 400);  // Yes!  \o/ \o/ \o/ \o/
  6. end;
  7.  

NOTE: I Got  scrollposition = 0 [always] ....

ref.
http://stackoverflow.com/questions/9655435/custom-listview-drawing
http://stackoverflow.com/questions/16342945/ondraw-bug-on-listview
« Last Edit: September 19, 2016, 03:57:05 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1840
Re: Android Module Wizard
« Reply #883 on: September 19, 2016, 06:47:57 am »
Yes, this would be perfect ! Thanks !!
If you have implemented this, I will investigate/debug the scrollposition problem.

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #884 on: September 20, 2016, 02:42:49 am »
Hi jmpessoa
I am using below components:
java 8 update 101 64 bits
java sdk 8 update 101 32 bits
newest version of lamw
ndk r10e
ant 1.9.7

But when i chose Project > New project and create new one, This alert always appear and i dont know how to fix it
Quote
Error: Access violation
http://imgur.com/a/dMA0D

please help. thanks much  :) :)

And in dialog creating new project I see 2 options are armv7 + soft armv7 +Fv3
So which one I should choose , and what are differences ?

Thanks  :) :)

 

TinyPortal © 2005-2018