LAMW Bug: UpdateLayout After Rotate lazarus / 43-Android ---------------------------------------------------------------------- Handoko · 2019-02-12 18:31 When learning how to use jView, I found something not working correctly. I could be wrong but I believe it is a bug. How to reproduce the bug? 1. Run the code below (you can download and use the apk on the next post) 2. Press the button several times, to switch between different layout parameters 3. A small rectangle and triangle will be moving inside the jView1 4. The big green rectangle represents the border of jView1 5. Rotate your mobile phone 6. Bug: If the jView1.LayoutParam = lpMatchParent and the phone orientation is Landscape then the value of jView1.Width and jView1.Height are incorrect (swapped). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {Hint: save all files to location: /home/handoko/Desktop/JCanvasPolygon/LamwGUIProject1/jni }unit unit1; {$mode delphi} interface uses  Classes, SysUtils, AndroidWidget, Laz_And_Controls;  type   TPolygon = array of TPoint;   { TAndroidModule1 }   TAndroidModule1 = class(jForm)    jButton1: jButton;    jCanvas1: jCanvas;    jTextView1: jTextView;    jTimer1: jTimer;    jView1: jView;    procedure AndroidModule1Destroy(Sender: TObject);    procedure AndroidModule1JNIPrompt(Sender: TObject);    procedure AndroidModule1Rotate(Sender: TObject; rotate: TScreenStyle);    procedure jButton1Click(Sender: TObject);    procedure jTimer1Timer(Sender: TObject);    procedure jView1Draw(Sender: TObject);  private    FBorderS: Integer;    FSquareX: Integer;    FSquareY: Integer;    FSquareS: Integer;    FSquareVeloX: Integer;    FSquareVeloY: Integer;    FTriangleX: Integer;    FTriangleY: Integer;    FTriangleVeloX: Integer;    FTriangleVeloY: Integer;    procedure DrawPoly(BorderColor: TARGBColorBridge; BorderWidth: Integer;      Points: TPolygon);    procedure ShowInfo;  end; var  AndroidModule1: TAndroidModule1; implementation {$R *.lfm} { TAndroidModule1 } procedure TAndroidModule1.jView1Draw(Sender: TObject);var  Polygon: TPolygon;begin   // Draw Border  Polygon := TPolygon.Create(    Point(0, 0),    Point(jView1.Width, 0),    Point(jView1.Width, jView1.Height),    Point(0, jView1.Height));  DrawPoly(colbrGreen, FBorderS, Polygon);   // Draw Square  Polygon := TPolygon.Create(    Point(FSquareX-FSquareS, FSquareY-FSquareS),    Point(FSquareX+FSquareS, FSquareY-FSquareS),    Point(FSquareX+FSquareS, FSquareY+FSquareS),    Point(FSquareX- FSquareS, FSquareY+FSquareS));  DrawPoly(colbrCyan, 3, Polygon);   // Draw Triangle  Polygon := TPolygon.Create(    Point(FTriangleX,     FTriangleY-80),    Point(FTriangleX+100, FTriangleY+80),    Point(FTriangleX-100, FTriangleY+80));  DrawPoly(colbrRed, 3, Polygon); end; procedure TAndroidModule1.jButton1Click(Sender: TObject);const  Layout: Integer = 0;begin  Inc(Layout);  if Layout > 3 then Layout := 1;  case Layout of    1: begin      jView1.LayoutParamHeight := lpMatchParent;      jView1.LayoutParamWidth  := lpMatchParent;      jButton1.Text          := 'lpMatchParent';    end;    2: begin      jView1.LayoutParamHeight := lpFourFifthOfParent;      jView1.LayoutParamWidth  := lpFourFifthOfParent;      jButton1.Text          := 'lpFourFifthOfParent';    end;    3: begin      jView1.LayoutParamHeight := lp99PercentOfParent;      jView1.LayoutParamWidth  := lp99PercentOfParent;      jButton1.Text          := 'lp99PercentOfParent';    end;  end;  jView1.UpdateLayout;  ShowInfo;end; procedure TAndroidModule1.jTimer1Timer(Sender: TObject);begin   // Animate Border  Inc(FBorderS);  if FBorderS > 50 then FBorderS := 1;   // Animate Square  Inc(FSquareS);  if FSquareS > 200 then            FSquareS := 50;  if FSquareX <= 0  then            FSquareVeloX := abs(FSquareVeloX);  if FSquareX >= jView1.Width then  FSquareVeloX := -(abs(FSquareVeloX));  if FSquareY <= 0  then          FSquareVeloY := abs(FSquareVeloY);  if FSquareY >= jView1.Height then FSquareVeloY := -(abs(FSquareVeloY));  Inc(FSquareX, FSquareVeloX);  Inc(FSquareY, FSquareVeloY);   // Animate Triangle  if FTriangleX <= 0  then            FTriangleVeloX := Random(8)  +1;  if FTriangleX >= jView1.Width  then FTriangleVeloX := -Random(8) -1;  if FTriangleY <= 0  then            FTriangleVeloY := Random(8)  +1;  if FTriangleY >= jView1.Height then FTriangleVeloY := -Random(8) -1;  Inc(FTriangleX, FTriangleVeloX);  Inc(FTriangleY, FTriangleVeloY);   jView1.Refresh; end; procedure TAndroidModule1.AndroidModule1Destroy(Sender: TObject);begin  jTimer1.Enabled := False;end; procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);begin   // Initial Border  FBorderS := 1;   // Initialize Square  FSquareX     := (jView1.Width div 2) -100;  FSquareY     := jView1.Height div 2;  FSquareS     := 50;  FSquareVeloX := Random(8) +1;  FSquareVeloY := Random(8) +1;   // Initialize Triangle  FTriangleX     := (jView1.Width div 2) +100;  FTriangleY     := jView1.Height div 2;  FTriangleVeloX := Random(8) +1;  FTriangleVeloY := Random(8) +1;   jTimer1.Enabled := True;  ShowInfo; end; procedure TAndroidModule1.AndroidModule1Rotate(Sender: TObject;  rotate: TScreenStyle);begin  jView1.UpdateLayout;end; procedure TAndroidModule1.DrawPoly(BorderColor: TARGBColorBridge;  BorderWidth: Integer; Points: TPolygon);var  i: Integer;begin  jView1.Canvas.PaintColor       := BorderColor;  jView1.Canvas.PaintStrokeWidth := BorderWidth;  for i := Low(Points) to High(Points)-1 do    jCanvas1.drawLine(Points[i].x, Points[i].y, Points[i+1].x, Points[i+1].y);  i := High(Points);  jView1.Canvas.drawLine(Points[i].X, Points[i].Y, Points[0].X, Points[0].Y);end; procedure TAndroidModule1.ShowInfo;begin  jTextView1.Text := jView1.Width.ToString + ' x ' + jView1.Height.ToString;end; end. ---------------------------------------------------------------------- Handoko · 2019-02-12 18:34 Below is the apk file. Note: Tested on Redmi 4X Android 7.1.2 LAMW 0.7 Lazarus 1.8.4. I first notice this issue because the moving objects move to the outside the visible screen area. To make it clearly, I have added the green border. So you can ignore the moving objects. ---------------------------------------------------------------------- loaded · 2019-02-12 18:59 Handoko, I don't think it's a bug. There's something we don't know. I found the solution in the following way. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {Hint: save all files to location: C:\Users\loaded\Desktop\silan\AppLAMWProject2\jni }unit unit1; {$mode delphi} interface uses  Classes, SysUtils, AndroidWidget, Laz_And_Controls;  type   { TAndroidModule1 }   TAndroidModule1 = class(jForm)    jCanvas1: jCanvas;    jView1: jView;    procedure AndroidModule1Rotate(Sender: TObject; rotate: TScreenStyle);    procedure jView1Draw(Sender: TObject);   private    {private declarations}  public    {public declarations}  end; var  AndroidModule1: TAndroidModule1;  J_Rotate:Boolean=false;implementation  {$R *.lfm}   { TAndroidModule1 }procedure TAndroidModule1.jView1Draw(Sender: TObject);begin  if J_Rotate then  begin  showmessage(inttostr(jView1.Width)+'x'+inttostr(jView1.Height));  J_Rotate:=false;  end;end;   procedure TAndroidModule1.AndroidModule1Rotate(Sender: TObject;  rotate: TScreenStyle);begin  Self.UpdateLayout;  J_Rotate:=true;  jView1.Refresh;end; end.