Lazarus

Programming => Operating Systems => Android => Topic started by: AFFRIZA 亜風実 on June 17, 2019, 09:38:41 am

Title: LAMW OnRotate
Post by: AFFRIZA 亜風実 on June 17, 2019, 09:38:41 am
Hello, I have a problem with jEditText and jListView, when the screen is rotated, the width is the same as the previous layout width, I have used OnRotate and UpdateLayout, but it doesn't do anything.

So, if the screen started with Landscape then on the Portrait layout will become ugly, and if the screen started with Portrait then on then Landscape layout will be broken.

Any ideas?  :'(
Title: Re: LAMW OnRotate
Post by: jmpessoa on June 17, 2019, 07:33:52 pm

Can you put your ".pas" and  ".lfm"  files?  [or send me your project....]
Title: Re: LAMW OnRotate
Post by: AFFRIZA 亜風実 on June 18, 2019, 04:46:23 am

Can you put your ".pas" and  ".lfm"  files?  [or send me your project....]
Thank you for the reply  :), here the form files (.pas and .lfm).
Title: Re: LAMW OnRotate
Post by: ADiV on June 20, 2019, 09:05:49 am

Can you put your ".pas" and  ".lfm"  files?  [or send me your project....]
Thank you for the reply  :), here the form files (.pas and .lfm).

Hello, I've tried your code and the bug that I see that the "jForm" uses "ActivityMode = actEasel" when you should use "ActivityMode = actRecyclable" and thus works correctly.
Title: Re: LAMW OnRotate
Post by: AFFRIZA 亜風実 on June 20, 2019, 01:35:20 pm

Can you put your ".pas" and  ".lfm"  files?  [or send me your project....]
Thank you for the reply  :), here the form files (.pas and .lfm).

Hello, I've tried your code and the bug that I see that the "jForm" uses "ActivityMode = actEasel" when you should use "ActivityMode = actRecyclable" and thus works correctly.
It makes my app freeze at startup because I am used it as a jPanel's child, the correct option is actEasel, not the actRecycleable.
Title: Re: LAMW OnRotate
Post by: jmpessoa on June 21, 2019, 05:27:10 am
Ok. 

In the  attachments,  there is a demo project and some pictures....

note1: avoid using multiple panels ... this causes an unbelievable screen process delay....

note2: you can use "margins" properties to improve the layout....

note3: tested in Galaxy S3 [4.3]  S4 [5.0.1] and S5 [6.0.1]
Title: Re: LAMW OnRotate
Post by: AFFRIZA 亜風実 on June 21, 2019, 07:29:38 am
Ok. 

In the  attachments,  there is a demo project and some pictures....

note1: avoid using multiple panels ... this causes an unbelievable screen process delay....

note2: you can use "margins" properties to improve the layout....

note3: tested in Galaxy S3 [4.3]  S4 [5.0.1] and S5 [6.0.1]
I have a problem opening the project, should I need to update LAMW?
Title: Re: LAMW OnRotate
Post by: jmpessoa on June 21, 2019, 07:38:58 am

Yes! LAMW is always evolving!  8-)
Title: Re: LAMW OnRotate
Post by: AFFRIZA 亜風実 on June 21, 2019, 08:10:28 am
Ah, yeah, I forgot to mention that. Can you check the demo "AppCompatNavigationDrawerDemo1", I'm replicate that thing to make the form, that's why I'm using a lot of panels previously. As the previous reply, the alignment problem may only affect atEeasel jForm.

I want to send my project files, but there are many SQL things. Can I send the file via email or private message maybe?
Title: Re: LAMW OnRotate
Post by: jmpessoa on June 22, 2019, 01:41:08 am
Yes, you can use jPanel as in demo "AppCompatNavigationDrawerDemo1"....
that is  a good  technique!

But, the massive use  of jPanel is bad.... [you can see: the "actEasel" forms use only one jPanel
to encapsulates all the layout!]

A revised  "AppLayoutingDemo1" demo is here:

https://od.lk/f/Ml8xNzA2NTE2ODdf               [opendrive.com]
 
Now there is an external jPanel wrapping all the layout... so you can use it as  an "actEasel" form...

And there is, too,  some code to handling the "Landscape" and  "Portrait"  screen  state/style....

P.S About "Easel" meaning ....  8-) :D
   
                http://paintingproperly.com/best-easel-reviews/
Title: Re: LAMW OnRotate
Post by: AFFRIZA 亜風実 on June 22, 2019, 06:32:33 am
Yes, you can use jPanel as in demo "AppCompatNavigationDrawerDemo1"....
that is  a good  technique!

But, the massive use  of jPanel is bad.... [you can see: the "actEasel" forms use only one jPanel
to encapsulates all the layout!]

A revised  "AppLayoutingDemo1" demo is here:

https://od.lk/f/Ml8xNzA2NTE2ODdf               [opendrive.com]
 
Now there is an external jPanel wrapping all the layout... so you can use it as  an "actEasel" form...

And there is, too,  some code to handling the "Landscape" and  "Portrait"  screen  state/style....

P.S About "Easel" meaning ....  8-) :D
   
                http://paintingproperly.com/best-easel-reviews/
The form in that demo still doesn't work after I inserted into my project as an Easel (layout still broken), but yeah it's work as a recycler, but I can't embed it to the main form as a child of the panel. I'm not sure why.  %)

Maybe I will disable the form rotate for now.  :-X

Btw, thank you for the replies and tips! I appreciate that.  ;)
Title: Re: LAMW OnRotate
Post by: jmpessoa on June 22, 2019, 09:04:01 am

Yes. We have some issues here....

1) I Fixed the file "amw_ide_menu_items.pas"   [LAMW folder "..../ide-tools"]
[Now the "Import LAMW Stuff..."  works,  again!]

2) About " layout still broken" in  "Easel"  model.... I will try some solution...
Title: Re: LAMW OnRotate
Post by: AFFRIZA 亜風実 on June 22, 2019, 09:05:39 am

Yes. We have some issues here....

1) I Fixed the file "amw_ide_menu_items.pas"   [LAMW folder "..../ide-tools"]
[Now the "Import LAMW Stuff..."  works,  again!]

2) About " layout still broken" in  "Easel"  model.... I will try some solution...
Btw, there's some fun stuff here.

jCustomDialog works fine in easel form. It still requires a timer to update, but yeah, it's better than crowding a single form with many components, that's why I like the Easel idea. It's only broken in jPanel, even I tried with a timer it doesn't work like jCustomDialog. :)

EDIT
There's what I've experienced until now.

1) I realized in jCustomDialog I'm using 2 edits (right and left, jEdit combined with jEdit), but the left side looks a bit bigger (at least it much looks better). Then I changed the right edit to a button (jEdit combined with jButton), it starts broken as the previous case.

2) If the button or edit I set to MatchParent, it will work completely normal. Like ThreeQuarter or NineTenth, it will be broken, except for MatchParent.

3) jPanel and ListView shared similar behavior when I tested in the jCustomDialog, it's only working with MatchToParent. For jPanel it will collapse until invisible when there's no component inside the jPanel (it's like the component is forcing the layout into WrapContent), even I set the weight HalfOfParent, ThreeQuarter, or anything except MatchParent. For jListView, it same as jPanel even there's contains items, it still collapsed, until I set into MatchParent.

Sorry for my bad English, I edited it so much. :D
Title: Re: LAMW OnRotate
Post by: jmpessoa on June 23, 2019, 08:47:25 am
Quote
There's what I've experienced until now.....

Yes, we need some more code to handle HalfOfParent, ThreeQuarter.... etc...

But, but I already know!

I will notify here  after some tests....
[Now I need to sleep....  :-X ]
Title: Re: LAMW OnRotate
Post by: AFFRIZA 亜風実 on June 24, 2019, 04:51:28 am
I will notify here  after some tests....
[Now I need to sleep....  :-X ]

Thank you! I will wait for it.  ;)
Title: Re: LAMW OnRotate
Post by: jmpessoa on June 24, 2019, 05:04:55 am

Done!!!

Updated "AppCompatNavigationDrawerDemo1" !!!
[and other required files....]

Now we can handle "OnRotate"!
Title: Re: LAMW OnRotate
Post by: AFFRIZA 亜風実 on June 24, 2019, 08:59:41 am

Done!!!

Updated "AppCompatNavigationDrawerDemo1" !!!
[and other required files....]

Now we can handle "OnRotate"!
The demo works wonderfully! But, when I use the form in my project it's doesn't work. I've deleted build folder, but it still the same. May I missed something?

I've added this too:
Code: Pascal  [Select][+][-]
  1. procedure TMainControl.jsNavigationView1ClickItem(Sender: TObject;
  2.   itemId: integer; itemCaption: string);
  3. begin
  4.   case itemId of
  5.     scHome: pnMain.BringToFront();
  6.     scDataSales: DataSales.jPanel3.BringToFront();
  7.     scOrderJual: OrderJual.jPanel1.BringToFront();
  8.     scScene3: AndroidModule1.jPanel1.BringToFront();
  9.   end;
  10.   ActiveScene := ItemID;
  11.   jsDrawerLayout1.CloseDrawers();
  12. end;
  13.  
  14. procedure TMainControl.MainControlRotate(Sender: TObject; rotate: TScreenStyle);
  15. begin
  16.   case ActiveScene of
  17.     scDataSales: DataSales.DataSalesRotate(Sender, rotate);
  18.     scOrderJual: OrderJual.OrderJualRotate(Sender, rotate);
  19.     scScene3: AndroidModule1.AndroidModule1Rotate(Sender, rotate);
  20.   end;
  21. end;  
  22.  

Also, I have one more bug. The main form changed every I create a new jForm, so it requires me to edit the .LPI file manually.
Title: Re: LAMW OnRotate
Post by: jmpessoa on June 24, 2019, 07:58:31 pm
(0)
Quote
I've deleted build folder....

I did not understand...

(1)
Quote
But, when I use the form in my project it's doesn't work.

You cant copy and paste a "unit" to your project...
You need "Use/Import LAMW Stuff..." from menu "Tools" --->"[LAMW] ....."

how does it work? The [dummy] unit[form] selected
will be replaced by the the imported unit[form]!


(2) 
Quote
Also, I have one more bug. The main form changed every I create a new jForm, so it requires me to edit the .LPI file manually.

The error (1)  can cause the error (2)!!!

But, to create new form you need use "File" -->  "New..."  -->  "LAMW [GUI] Android jForm"
[the default will be "Recyclable", so change to "Easel" if you need....]
Title: Re: LAMW OnRotate
Post by: AFFRIZA 亜風実 on June 25, 2019, 04:46:42 am
(0)
Quote
I've deleted build folder....

I did not understand...
I mean the layout still is broken, but only in my project, not in the demo. I thought the Java template files generated in "build" folder that caused the problem, which contains: "generated", "intermediates", "output", etc.

So, I following all in the demo. Like I changed the API into 28.0.2, still the same.  %)
Title: Re: LAMW OnRotate
Post by: jmpessoa on June 25, 2019, 05:02:45 am
Study the demo carefully ....

Unit1.pas   [main unit.....]

note this line: AndroidModule4.jPanel1.Parent:= Self.jPanel2;

Code: Pascal  [Select][+][-]
  1.   if itemId =  104 then
  2.   begin
  3.  
  4.     //prepare scene at first launch...
  5.     //put initialize here to not "delay" the application at startup...
  6.     if AndroidModule4 = nil then
  7.     begin
  8.       gApp.CreateForm(TAndroidModule4, AndroidModule4); //property "ActiveMode = actEasel" dont "show" form
  9.       AndroidModule4.Init(gApp); //fire OnJNIPrompt ...
  10.       AndroidModule4.jPanel1.Parent:= Self.jPanel2;// <<-------- need to handle LayoutParamWidth/LayoutParamHeight "OnRotate"
  11.       AndroidModule4.jPanel1.SetViewParent(Self.jPanel2.View); //add scene 4 to Self.jPanel2
  12.     end;
  13.  
  14.     ActiveScene:= 104;
  15.     AndroidModule4.jPanel1.BringToFront();
  16.   end;
  17.  

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.AndroidModule1Rotate(Sender: TObject;
  2.   rotate: TScreenStyle);
  3. begin
  4.    ......................................
  5.    if ActiveScene = 104 then //just as a demonstration....
  6.    begin
  7.       AndroidModule4.AndroidModule4Rotate(Sender, rotate);
  8.    end;
  9.    -----------------------------------
  10. end;
  11.  

Unit4.pas   [your form]
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule4.AndroidModule4JNIPrompt(Sender: TObject);
  2. begin
  3.    if Self.GetScreenOrientationStyle =  ssLandscape then
  4.    begin
  5.      Self.jScrollView1.LayoutParamHeight:= lpTwoFifthOfParent;
  6.      Self.jListView1.LayoutParamHeight:= lpOneFifthOfParent;
  7.      Self.UpdateLayout;
  8.    end
  9. end;
  10.  
  11. procedure TAndroidModule4.AndroidModule4Rotate(Sender: TObject; rotate: TScreenStyle);
  12. begin
  13.    if rotate =  ssLandscape then
  14.    begin
  15.      Self.jScrollView1.LayoutParamHeight:= lpTwoFifthOfParent;
  16.      Self.jListView1.LayoutParamHeight:= lpOneFifthOfParent;
  17.    end
  18.    else
  19.    begin
  20.      Self.jScrollView1.LayoutParamHeight:= lpHalfOfParent;
  21.      Self.jListView1.LayoutParamHeight:= lpOneQuarterOfParent
  22.    end;
  23.    Self.UpdateLayout;
  24. end;
  25.  
  26.  
Title: Re: LAMW OnRotate
Post by: AFFRIZA 亜風実 on June 25, 2019, 06:44:37 am
TMainControl.MainControlJNIPrompt
Code: Pascal  [Select][+][-]
  1. const
  2.   scHome = 1100;
  3.   scOrderJual = 1101;
  4.   scDataSales = 1102;
  5.   scScene3 = 1199;
  6.     //...
  7.     // Don't use "show" method on actEeasel
  8.     if not Assigned(AndroidModule1) then  
  9.     begin
  10.        gApp.CreateForm(TAndroidModule1, AndroidModule1);
  11.        AndroidModule1.Init(gApp);
  12.        // This is confusing, still doesn't work
  13.        AndroidModule1.Parent := pnViewer;
  14.        // Maybe I prefered using jPanel1.ChildViewList or something to handle all child view layout automatically by parent
  15.        AndroidModule1.jPanel1.SetViewParent(pnViewer.View);
  16.     end;          
  17.  

TMainControl.jsNavigationView1ClickItem
Code: Pascal  [Select][+][-]
  1.   // like in the demonstration
  2.   case itemId of
  3.     scHome: pnMain.BringToFront();
  4.     scDataSales: DataSales.jPanel3.BringToFront();
  5.     scOrderJual: OrderJual.jPanel1.BringToFront();
  6.     scScene3: AndroidModule1.jPanel1.BringToFront();
  7.   end;
  8.   // I hope I can have jsNavigationView1.ActiveMenuItem
  9.   ActiveScene := ItemID;
  10.   jsDrawerLayout1.CloseDrawers();  
  11.  

TMainControl.MainControlRotate
Code: Pascal  [Select][+][-]
  1.   // like in the demonstration
  2.   case ActiveScene of
  3.     scDataSales: DataSales.DataSalesRotate(Sender, rotate);
  4.     scOrderJual: OrderJual.OrderJualRotate(Sender, rotate);
  5.     scScene3: AndroidModule1.AndroidModule1Rotate(Sender, rotate);
  6.   end;
  7.  

TAndroidModule1.AndroidModule1JNIPrompt
Code: Pascal  [Select][+][-]
  1.    if Self.GetScreenOrientationStyle =  ssLandscape then
  2.    begin
  3.      Self.jScrollView1.LayoutParamHeight:= lpTwoFifthOfParent;
  4.      Self.jListView1.LayoutParamHeight:= lpOneFifthOfParent;
  5.      Self.UpdateLayout;
  6.    end
  7.  

TAndroidModule1.AndroidModule1Rotate
Code: Pascal  [Select][+][-]
  1.    if rotate =  ssLandscape then
  2.    begin
  3.      Self.jScrollView1.LayoutParamHeight:= lpTwoFifthOfParent;
  4.      Self.jListView1.LayoutParamHeight:= lpOneFifthOfParent;
  5.    end
  6.    else
  7.    begin
  8.      Self.jScrollView1.LayoutParamHeight:= lpHalfOfParent;
  9.      Self.jListView1.LayoutParamHeight:= lpOneQuarterOfParent
  10.    end;
  11.    Self.UpdateLayout;
  12.    // Must be triggered here
  13.    ShowMessage('rotated');        
  14.  

Yeah, I already read that. Maybe my project is broken, corrupted or something. I'll try to create a new project from the start later.
TinyPortal © 2005-2018