Recent

Author Topic: Lazarus Android graphics  (Read 3190 times)

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Lazarus Android graphics
« Reply #15 on: April 29, 2021, 04:54:09 pm »
This demo demos\GUI\AppDrawingInBitmapAndDensity has:
Code: Pascal  [Select][+][-]
  1. library controls;  //[by LAMW: Lazarus Android Module Wizard: 9/26/2019 17:20:36]
  2.  
  3. {$mode delphi}
  4.  
  5. uses
  6. ...
  7.  
  8. begin
  9.   gApp:= jApp.Create(nil);
  10.   gApp.Title:= 'LAMW JNI Android Bridges Library';
  11.   gjAppName:= 'org.lamw.appdrawinginbitmap';
  12.   gjClassName:= 'org/lamw/appdrawinginbitmap/Controls';
  13.   gApp.AppName:=gjAppName;
  14.   gApp.ClassName:=gjClassName;
  15.   gApp.Initialize;
  16.   gApp.CreateForm(TAndroidModule1, AndroidModule1);
  17. end.

So gApp is similar to Application.

The demo itself is bothering me because I see three canvases being used, but I don't see where they get created. Anyway I noticed these two lines:
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. ...
  3.    //show on screen
  4.    ivLow.SetImage(canvasLow.GetBitmap());

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Lazarus Android graphics
« Reply #16 on: April 29, 2021, 05:56:57 pm »

About jCanvas component :

jCanvas can take a "real" java canvas from other component:
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule2.jButton1BeforeDispatchDraw(Sender: TObject; canvas: JObject; tag: integer);
  2. begin
  3.    jCanvas1. SetCanvas(canvas);
  4.    //now you can draw:
  5.    //jCanvas1.DrawCircle(30, 30, 15);
  6.    //etc...
  7. end;  
  8.  


You can get the real java canvas object, too:

function GetJInstance(): jObject;  //return the "real" java Canvas....

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

Tomi

  • Full Member
  • ***
  • Posts: 102
Re: Lazarus Android graphics
« Reply #17 on: May 01, 2021, 11:28:58 am »
You can get the real java canvas object, too:

function GetJInstance(): jObject;  //return the "real" java Canvas....
It sounds good. Can you explain me using of this? For example: maincanvas:=GetJInstance(); or how?
And:
why can't I resize a button? The app in the emulator always shows the same size button, however I resized it:
Code: Pascal  [Select][+][-]
  1. btn2:=jButton.create(Elion);
  2.      btn2.parent:=Elion;
  3.      btn2.init(gApp);
  4.      btn2.text:='A new button';
  5.      btn2.left:=Elion.left+200; //The button position is always at 0,0
  6.      btn2.top:=Elion.top+200;
  7.      btn2.width:=50; //The button will larger than this value
  8.      btn2.height:=50;
  9.      btn2.enabled:=true;
« Last Edit: May 01, 2021, 11:33:52 am by Tomi »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Lazarus Android graphics
« Reply #18 on: May 01, 2021, 04:18:19 pm »

On android this code don't work!

Code: Pascal  [Select][+][-]
  1.      btn2.left:=Elion.left+200; //The button position is always at 0,0
  2.      btn2.top:=Elion.top+200;
  3.      btn2.width:=50; //The button will larger than this value
  4.      btn2.height:=50;
  5.  

From here:
https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/LAMW_Getting_Started.txt

Quote
[FAQ 2]: [Thanks to Ahmad Bohloolbandi (a.k.a. @developing) ]

#Question: How do we can design a layout that shown same in real device?

[Answer]: You should use the component properties:

      "Anchor",
      "PosRelativeToParent",
      "PosRelativeToAnchor",
      "LayoutParamHeight",
      "LayoutParamWhidth"
         
Example:

1-Put a "jTextView" component on your AndroidModule form:

   Set "PosRelativeToParent"
      "rpCenterHorizontal" [True]
      "rpTop" [True]

2-Put a "jButton" component on AndroidModule form:

   Set "Anchor" to "jTextView" (Because you should set position relative with "jTextView")
   set "PosRelativeToAnchor"
      "raBelow" [True]

3-Put a "jEditText" component on form:

   Set "Anchor" to "jButton".
   Set "PosRelativeToAnchor"
      "raBelow" [True]

NOTE: Anchor setting is most important section of this design,
   because your component position depends on this property.
   And for change width and/or height of each components you should
   change/configure "LayoutParamWhidth" and/or "LayoutParamHeight".



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

 

TinyPortal © 2005-2018