A line drawing with two positions (x1, y1) and (x2, y2) with TLine.

A line drawing with two positions(x1, y1) and (x2, y2) with TLine.

TLine's attributes are height and width, and TLine's coordinates are x, y position at the top left, so it is not easy to draw lines by specifying (x1, y1) and (x2, y2).

I have created a method that draws two positions using TLine's Rotation Angle attribute.

The principle is to find only the line width and rotation angle value with two postion.
First, you can specify the properties of TLine as shown in the figure.
The important thing is RotationCenter.
If RotationCenter has default values ​​of 0.5 and 0.5, it rotates around the center of the line.
RotationCenter should be changed to (0,0) to rotate around the end point of the line (x1.y1).



The line width and rotation angle designation can be calculated as shown in the figure.
Red color line is a TLine.



I wrote the sample code using the above method.
The position.X values is x2>x1 when the rotation angle range is 0 ~ 180.
If the SIN value exceeds 180, the +/- value changes.
So, as in the sample code, if x1>x2 then, change two position.
The drawing order is not considered.

Even if you do not understand the principle of line drawing, you can draw a line by inputting the Thickness of two Position and line as parameters.
Of course, color change is also possible.

procedure TForm1.Draw_Line2P( x1,y1, x2,y2, thick : single );
var
  d, xtemp, ytemp, rAngle : single;
  drawLine : TLine;
begin
  if x1 > x2 then
  begin
    xtemp := x1;     ytemp := y1;
    x1 := x2;          y1 := y2;
    x2 := xtemp;     y2 := ytemp;
  end;

  d := SQRT( Power( x2-x1, 2 ) + Power( y2-y1, 2 ) );   // Uses System.Math
  rAngle := RadToDeg( ArcSin( (y2-y1)/d ));

  drawLine := TLine.Create(self);
  drawLine.Parent := self;
  drawLine.LineLocation := TLineLocation.Inner;
  drawLine.LineType := TLineType.Bottom;
  drawLine.RotationCenter.X := 0;
  drawLine.RotationCenter.Y := 0;
  drawLine.Stroke.Thickness := thick;
  drawLine.Height := 1;
  drawLine.Width  := d;
  drawLine.Position.X := x1;
  drawLine.Position.Y := y1;
  drawLine.RotationAngle := rAngle;
end;





Calling apps from the web with Android Intent


How to call the Delphi Firemonkey App from a web page via Android Intent.

At this point, the URL parameter values are sent to the App.


1. Create an html page and install it on the web. (callapp.html)
<a href="delphiapp://callType1?title=This is a Type1&data1=1111&data2=2222">call Type1</a><BR><BR>

<a href="delphiapp://callType2?title=This is a Type2&data1=3333&data2=4444&data3=5555">call Type2</a><BR><BR>

<a href="delphiapp://callType2?title=Type2 : 한글로 된 제목&data1=6666&data2=7777&data3=3번째 데이터">call Type2 한글</a><BR><BR>



2. Add the same intent-filter entry to the html page's uri entry in the AndroidManifest.template.xml file.



3. Create a Delphi Project.
procedure TForm1.FormCreate(Sender: TObject);
{$IFDEF ANDROID}
var
  intent: JIntent;
  uri: Jnet_Uri;
  uriStr: String;
  rValue : TStringList;
  i : integer;
{$ENDIF}

begin
  {$IFDEF ANDROID}
  intent := SharedActivity.getIntent;
  if intent <> nil then
  begin
    if TJIntent.JavaClass.ACTION_VIEW.equals(intent.getAction) then
    begin
      uri := intent.getData;
      uriStr := JStringToString(uri.toString);  // read uriStr

      rValue := Get_URL_String( uriStr );  // parsing value

      for i := 0 to rValue.Count-1 do
         Memo1.Lines.Add( rValue[i] );
    end;
  end;
  {$ENDIF}
end;



Demo Video