Recent

Author Topic: Android Module Wizard  (Read 522959 times)

Dio Affriza

  • Jr. Member
  • **
  • Posts: 77
Re: Android Module Wizard
« Reply #1170 on: August 24, 2019, 08:10:05 am »

Quote
I think there's something is wrong....

Yes!  your jPanel.java  is outdated!!!!!

I just found the LAMW.ini in the Lazarus config folder. That's why it trying to copying my old LAMW.
I think that "flag:=false" in TLamwGlobalSettings.ReloadIni is okay to removed, since I have multiple LAMW.
« Last Edit: August 24, 2019, 08:32:14 am by Dio Affriza »

jmpessoa

  • Hero Member
  • *****
  • Posts: 1468
Re: Android Module Wizard
« Reply #1171 on: August 24, 2019, 08:14:31 am »

It's part of our programming adventure.... let's move on!

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

Dio Affriza

  • Jr. Member
  • **
  • Posts: 77
Re: Android Module Wizard
« Reply #1172 on: September 02, 2019, 10:30:59 am »
Hello, Marquez. Can you inspect on unit LamwDesigner on line 1812?

So, I have 2 forms, the first is actSplash (with name ControlSplash), and the second is actMain (with name ControlMain).
If I modified properties in actMain, it forcing an update on ProjectStartModule into ControlMain. So, it makes me to always modify the LPI file.

I have an idea here. How about make actSplash is prioritized than actMain. Like this:

Code: Pascal  [Select]
  1.     if (Instance = AndroidForm)
  2.     and (AndroidForm.ActivityMode in [actMain, actSplash])
  3.     and FProjFile.IsPartOfProject then
  4.     begin
  5.       if AndroidForm.ActivityMode = actSplash then
  6.         LamwSmartDesigner.UpdateProjectStartModule(AndroidForm.Name)
  7.       else
  8.         LamwSmartDesigner.UpdateProjectStartModule(AndroidForm.Name);
  9.     end;          
  10.  

Thank you.  :D

kordal

  • New member
  • *
  • Posts: 7
Re: Android Module Wizard
« Reply #1173 on: September 28, 2019, 01:54:59 am »
Hi everyone) Android Module Wizard is a good job. Although I do not like Pascal, it is probably a better Android app development tool than Delphi. The most important feature is the size of the application, with the same code it can vary 25 times. It is very important. Thank you very much!

So. I added some functionality to the jBitmap, jCanvas, and jDrawingView component classes. Now in order:
1. jBitmap. Added function:
Code: Pascal  [Select]
  1. LoadFromBuffer (buffer: pointer; size: integer);
2. jCanvas and jDrawingView. Added overloaded functions:
Code: Pascal  [Select]
  1. procedure DrawBitmap(bitMap: jObject; srcLeft, srcTop, srcRight, srcBottom, dstLeft, dstTop, dstRight, dstBottom: Integer);
  2. procedure DrawFrame(bitMap: jObject; srcX, srcY, srcW, srcH, X, Y, W, H: Integer; rotateDegree: Single=0);
  3. procedure DrawFrame(bitMap: jObject; X, Y, Index, Size: Integer; scaleFactor: Single=1; rotateDegree: Single=0);

I attach the modified files, as well as a new demo using them. In addition, two utilities are included:
1. bin2pas - a packer of binary files in * .pas
2. JC Sign - a program for convenient viewing of signatures of * .class java files.

lamw_modif.7z

Have fun :)

jmpessoa

  • Hero Member
  • *****
  • Posts: 1468
Re: Android Module Wizard
« Reply #1174 on: September 28, 2019, 11:54:58 pm »

@kordal:
Quote
I added some functionality to the jBitmap, jCanvas, and jDrawingView component classes....

Commited!!

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

kordal

  • New member
  • *
  • Posts: 7
Re: Android Module Wizard
« Reply #1175 on: October 04, 2019, 06:17:36 pm »
1. Added a new type in the AndroidWidget unit:
Code: Pascal  [Select]
  1. type
  2. // ...
  3.   PColor = ^TColor;
  4.   TColor = -$7FFFFFFF-1..$7FFFFFFF;

2. I modified and fixed some functions in the jDrawingView component. So:
  • New overloaded and some function:
jDrawingView.pas
Code: Pascal  [Select]
  1. interface
  2.  
  3. jDrawingView = class(jVisualControl)
  4. public
  5. // ...
  6.   procedure SetPaintColor( _color: TColor); overload;
  7.   procedure DrawRoundRect(Left, Top, Right, Bottom, radiusX, radiusY: Single);
  8. // ..
  9. end;
  10.  
  11. procedure jDrawingView_DrawRoundRect(env: PJNIEnv; _jdrawingview: JObject; _left, _top, _right, _bottom, _rx, _ry: Single);
  12.  
  13. implementation
  14.  
  15. procedure jDrawingView.SetPaintColor(_color: TColor);
  16. begin
  17.   if FInitialized then
  18.      jDrawingView_SetPaintColor(FjEnv, FjObject, _color);
  19. end;
  20.  
  21. procedure jDrawingView.DrawRoundRect(Left, Top, Right, Bottom, radiusX, radiusY: Single);
  22. begin
  23.   if FInitialized then
  24.      jDrawingView_DrawRoundRect(FjEnv, FjObject, Left, Top, Right, Bottom, radiusX, radiusY);
  25. end;
  26.  
  27. // ...
  28. procedure jDrawingView_DrawRoundRect(env: PJNIEnv; _jdrawingview: JObject; _left, _top, _right, _bottom, _rx, _ry: Single);
  29. var
  30.   jParams: array[0..5] of jValue;
  31.   jMethod: jMethodID = nil;
  32.   jCls   : jClass = nil;
  33. begin
  34.   jParams[0].f:= _left;
  35.   jParams[1].f:= _top;
  36.   jParams[2].f:= _right;
  37.   jParams[3].f:= _bottom;
  38.   jParams[4].f:= _rx;
  39.   jParams[5].f:= _ry;
  40.   jCls:= env^.GetObjectClass(env, _jdrawingview);
  41.   jMethod:= env^.GetMethodID(env, jCls, 'DrawRoundRect', '(FFFFFF)V');
  42.   env^.CallVoidMethodA(env, _jdrawingview, jMethod, @jParams);
  43.   env^.DeleteLocalRef(env, jCls);
  44. end;    
  45.  
jDrawingView.java
Code: Java  [Select]
  1. public void DrawRoundRect(float _left, float _top, float _right, float _bottom, float _rx, float _ry) {
  2.         mCanvas.drawRoundRect(_left, _top, _right, _bottom, _rx, _ry, mDrawPaint);
  3. }
  • There was a problem while displaying Cyrillic in DrawText functions. The program failed with an error. Please modify functions ..DrawText :)
Code: Pascal  [Select]
  1. // example
  2. procedure jDrawingView_DrawText(env: PJNIEnv; _jdrawingview: JObject; _text: string; _x: single; _y: single);
  3. var
  4.   jParams: array[0..2] of jValue;
  5.   jMethod: jMethodID=nil;
  6.   jCls: jClass=nil;
  7. begin
  8.   // ...
  9.   // example calls
  10.   //    ...DrawText('String', 10, 10); its ok
  11.   //    ...DrawText('Строка', 10, 10); filed !
  12.  
  13.   // modified line:
  14.   // jParams[0].l:= env^.NewStringUTF(env, PChar(_text));  // bug!!!
  15.   jParams[0].l:= env^.NewString(env, PjChar(UTF8Decode(_text)), Length(_text)); // fix !!
  16.   jParams[1].f:= _x;
  17.   jParams[2].f:= _y;
  18.   // ...
  19.   env^.DeleteLocalRef(env, jCls);
  20. end;
  21.  
    « Last Edit: October 04, 2019, 06:25:35 pm by kordal »

    jmpessoa

    • Hero Member
    • *****
    • Posts: 1468
    Re: Android Module Wizard
    « Reply #1176 on: October 04, 2019, 10:46:50 pm »

    Quote
    There was a problem while displaying Cyrillic in DrawText functions......

    Code: Pascal  [Select]
    1.  // jParams[0].l:= env^.NewStringUTF(env, PChar(_text));  // bug!!!
    2.  jParams[0].l:= env^.NewString(env, PjChar(UTF8Decode(_text)), Length(_text)); // fix !!
    3.  

    So this could be happening all over LAMW?



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

    kordal

    • New member
    • *
    • Posts: 7
    Re: Android Module Wizard
    « Reply #1177 on: October 04, 2019, 11:33:50 pm »
    In theory. It is necessary to check while I noticed an error only in the jDrawingView module in DrawText functions. It is likely that all those modules that use the same approach for text output will fail.

    Just in case, version FPC 3.2.0, Lazarus 2.0.2, Aarch64 chipset, jdk1.8.0_221, SDK 29, APK Builder - Ant. All tests were conducted on a real Android devices.

    upd.
    Code: Pascal  [Select]
    1. jParams [0] .l: = env ^ .NewStringUTF (env, PChar (_text));
    After several rebuilding of the project and LAMW, it worked. Need more tests. The problem arose precisely with the Cyrillic text.
    « Last Edit: October 05, 2019, 04:55:54 am by kordal »

    jmpessoa

    • Hero Member
    • *****
    • Posts: 1468
    Re: Android Module Wizard
    « Reply #1178 on: October 05, 2019, 04:23:23 am »

    Suggestions/improvements commiteds!!!

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

    kordal

    • New member
    • *
    • Posts: 7
    Re: Android Module Wizard
    « Reply #1179 on: October 08, 2019, 02:10:06 am »
    1. I converted the drawing functions to the Float version, because everywhere they use Float coordinates instead of Integer. Therefore, it will be more correct.
    DrawingView.pas
    Code: Pascal  [Select]
    1.  // ...
    2. public  
    3.   procedure DrawBitmap(bitMap: jObject; srcLeft, srcTop, srcRight, srcBottom: Integer; dstLeft, dstTop, dstRight, dstBottom: Single); overload;
    4.   procedure DrawFrame(bitMap: jObject; srcX, srcY, srcW, srcH: Integer; X, Y, W, H: Single; rotateDegree: Single=0); overload; // by Kordal
    5.   procedure DrawFrame(bitMap: jObject; X, Y: Single; Index, Size: Integer; scaleFactor: Single=1; rotateDegree: Single=0); overload;
    6. end;
    7. //...
    8.   procedure jDrawingView_DrawBitmap(env: PJNIEnv; _jdrawingview: JObject; _bitmap: jObject; _sl, _st, _sr, _sb: Integer; _dl, _dt, _dr, _db: Single); overload;
    9.   procedure jDrawingView_DrawFrame(env: PJNIEnv; _jdrawingview: JObject; _bitmap: jObject; _srcX, _srcY, _srcW, _srcH: Integer; _X, _Y, _Wh, _Ht, _rotateDegree: Single); overload;
    10.   procedure jDrawingView_DrawFrame(env: PJNIEnv; _jdrawingview: JObject; _bitmap: jObject; _X, _Y: Single; _Index, _Size: Integer; _scaleFactor, _rotateDegree: Single); overload;
    11.  
    12. implementation
    13.  
    14. procedure jDrawingView.DrawBitmap(bitMap: jObject; srcLeft, srcTop, srcRight, srcBottom: Integer; dstLeft, dstTop, dstRight, dstBottom: Single);
    15. begin
    16.   if FInitialized then
    17.     jDrawingView_DrawBitmap(FjEnv, FjObject, bitMap, srcLeft, srcTop, srcRight, srcBottom, dstLeft, dstTop, dstRight, dstBottom);
    18. end;
    19.  
    20. procedure jDrawingView.DrawFrame(bitMap: jObject; srcX, srcY, srcW, srcH: Integer; X, Y, W, H, rotateDegree: Single);
    21. begin
    22.   if FInitialized then
    23.     jDrawingView_DrawFrame(FjEnv, FjObject, bitMap, srcX, srcY, srcW, srcH, X, Y, W, H, rotateDegree);
    24. end;
    25.  
    26. procedure jDrawingView.DrawFrame(bitMap: jObject; X, Y: Single; Index, Size: Integer; scaleFactor: Single; rotateDegree: Single);
    27. begin
    28.   if FInitialized then
    29.     jDrawingView_DrawFrame(FjEnv, FjObject, bitMap, X, Y, Index, Size, scaleFactor, rotateDegree);
    30. end;
    31.  
    32. procedure jDrawingView_DrawBitmap(env: PJNIEnv; _jdrawingview: JObject; _bitmap: jObject; _sl, _st, _sr, _sb: Integer; _dl, _dt, _dr, _db: Single);
    33. var
    34.   jParams: array [0..8] of jValue;
    35.   jMethod: jMethodID=nil;
    36.   jCls   : jClass=nil;
    37. begin
    38.   jParams[0].l := _bitmap;
    39.   jParams[1].i := _sl;
    40.   jParams[2].i := _st;
    41.   jParams[3].i := _sr;
    42.   jParams[4].i := _sb;
    43.   jParams[5].f := _dl;
    44.   jParams[6].f := _dt;
    45.   jParams[7].f := _dr;
    46.   jParams[8].f := _db;
    47.   jCls:= env^.GetObjectClass(env, _jdrawingview);
    48.   jMethod:= env^.GetMethodID(env, jCls, 'DrawBitmap', '(Landroid/graphics/Bitmap;IIIIFFFF)V');
    49.   env^.CallVoidMethodA(env, _jdrawingview, jMethod, @jParams);
    50.   env^.DeleteLocalRef(env,  jCls);
    51. end;        
    52.  
    53. procedure jDrawingView_DrawFrame(env: PJNIEnv; _jdrawingview: JObject; _bitmap: jObject; _srcX, _srcY, _srcW, _srcH: Integer; _X, _Y, _Wh, _Ht, _rotateDegree: Single);
    54. var
    55.   jParams: array [0..9] of jValue;
    56.   jMethod: jMethodID = nil;
    57.   jCls   : jClass = nil;
    58. begin
    59.   jParams[0].l := _bitmap;
    60.   jParams[1].i := _srcX;
    61.   jParams[2].i := _srcY;
    62.   jParams[3].i := _srcW;
    63.   jParams[4].i := _srcH;
    64.   jParams[5].f := _X;
    65.   jParams[6].f := _Y;
    66.   jParams[7].f := _Wh;
    67.   jParams[8].f := _Ht;
    68.   jParams[9].f := _rotateDegree;
    69.   jCls := env^.GetObjectClass(env, _jdrawingview);
    70.   jMethod := env^.GetMethodID(env, jCls, 'DrawFrame', '(Landroid/graphics/Bitmap;IIIIFFFFF)V');
    71.   env^.CallVoidMethodA(env, _jdrawingview, jMethod, @jParams);
    72.   env^.DeleteLocalRef(env, jCls);
    73. end;
    74.  
    75. procedure jDrawingView_DrawFrame(env: PJNIEnv; _jdrawingview: JObject; _bitmap: jObject; _X, _Y: Single; _Index, _Size: Integer; _scaleFactor, _rotateDegree: Single);
    76. var
    77.   jParams: array [0..6] of jValue;
    78.   jMethod: jMethodID = nil;
    79.   jCls   : jClass = nil;
    80. begin
    81.   jParams[0].l := _bitmap;
    82.   jParams[1].f := _X;
    83.   jParams[2].f := _Y;
    84.   jParams[3].i := _Index;
    85.   jParams[4].i := _Size;
    86.   jParams[5].f := _scaleFactor;
    87.   jParams[6].f := _rotateDegree;
    88.   jCls := env^.GetObjectClass(env, _jdrawingview);
    89.   jMethod := env^.GetMethodID(env, jCls, 'DrawFrame', '(Landroid/graphics/Bitmap;FFIIFF)V');
    90.   env^.CallVoidMethodA(env, _jdrawingview, jMethod, @jParams);
    91.   env^.DeleteLocalRef(env, jCls);
    92. end;                                    
    93.  

    jDrawingView.java
    Code: Java  [Select]
    1. // by Kordal
    2.         public void DrawBitmap(Bitmap _bitMap, int _srcLeft, int _srcTop, int _srcRight, int _srcBottom, float _dstLeft, float _dstTop, float _dstRight, float _dstBottom) {
    3.                 Rect srcRect = new Rect(_srcLeft, _srcTop, _srcRight, _srcBottom);
    4.         RectF dstRect = new RectF(_dstLeft, _dstTop, _dstRight, _dstBottom);
    5.                
    6.                 mCanvas.drawBitmap(_bitMap, srcRect, dstRect, mDrawPaint);
    7.         }
    8.        
    9.         public void DrawFrame(Bitmap _bitMap, int _srcX, int _srcY, int _srcW, int _srcH, float _X, float _Y, float _Wh, float _Ht, float _rotateDegree) {
    10.                 Rect srcRect = new Rect(_srcX, _srcY, _srcX + _srcW, _srcY + _srcH);
    11.         RectF dstRect = new RectF(_X, _Y, _X + _Wh, _Y + _Ht);
    12.                
    13.                 if (_rotateDegree != 0) {
    14.                         mCanvas.save();
    15.                         mCanvas.rotate(_rotateDegree, _X + _Wh / 2, _Y + _Ht / 2);
    16.                         mCanvas.drawBitmap(_bitMap, srcRect, dstRect, mDrawPaint);
    17.                         mCanvas.restore();
    18.                 } else {
    19.                         mCanvas.drawBitmap(_bitMap, srcRect, dstRect, mDrawPaint);
    20.                 }
    21.         }
    22.        
    23.         public void DrawFrame(Bitmap _bitMap, float _X, float _Y, int _Index, int _Size, float _scaleFactor, float _rotateDegree) {
    24.                 float sf = _Size * _scaleFactor;
    25.                 DrawFrame(_bitMap, _Index % (_bitMap.getWidth() / _Size) * _Size, _Index / (_bitMap.getWidth() / _Size) * _Size, _Size, _Size, _X, _Y, sf, sf, _rotateDegree);
    26.         }      
    27.  

    2. Functions added:
    DrawingView.pas
    Code: Pascal  [Select]
    1. // ...
    2. public
    3.   procedure DrawGrid(Left, Top, Width, Height: Single; cellsX, cellsY: Integer);  
    4.   procedure ClipRect(Left, Top, Right, Bottom: Single);  
    5.   function GetDensity(): Single;
    6.  
    7. published
    8.   property Density: Single read GetDensity;
    9. // ...
    10. end;
    11.  
    12. procedure jDrawingView_DrawGrid(env: PJNIEnv; _jdrawingview: JObject; _left, _top, _width, _height: Single; _cellsX, _cellsY: Integer);
    13. procedure jDrawingView_ClipRect(env: PJNIEnv; _jdrawingview: JObject; Left, Top, Right, Bottom: Single);
    14. function  jDrawingView_GetDensity(env: PJNIEnv; _jdrawingview: JObject): Single;
    15.  
    16. implementation
    17.  
    18. function jDrawingView.GetDensity(): Single;
    19. begin
    20.   Result := 1;
    21.   if not FInitialized then Exit;
    22.   Result := jDrawingView_GetDensity(FjEnv, FjObject);
    23. end;
    24.  
    25. procedure jDrawingView.ClipRect(Left, Top, Right, Bottom: Single);
    26. begin
    27.   if FInitialized then
    28.     jDrawingView_ClipRect(FjEnv, FjObject, Left, Top, Right, Bottom);
    29. end;  
    30.  
    31. procedure jDrawingView.DrawGrid(Left, Top, Width, Height: Single; cellsX, cellsY: Integer);
    32. begin
    33.   if FInitialized then
    34.     jDrawingView_DrawGrid(FjEnv, FjObject, Left, Top, Width, Height, cellsX, cellsY);
    35. end;  
    36.  
    37. procedure jDrawingView_DrawGrid(env: PJNIEnv; _jdrawingview: JObject; _left, _top, _width, _height: Single; _cellsX, _cellsY: Integer);
    38. var
    39.   jParams: array[0..5] of jValue;
    40.   jMethod: jMethodID = nil;
    41.   jCls   : jClass = nil;
    42. begin
    43.   jParams[0].f:= _left;
    44.   jParams[1].f:= _top;
    45.   jParams[2].f:= _width;
    46.   jParams[3].f:= _height;
    47.   jParams[4].i:= _cellsX;
    48.   jParams[5].i:= _cellsY;
    49.   jCls:= env^.GetObjectClass(env, _jdrawingview);
    50.   jMethod:= env^.GetMethodID(env, jCls, 'DrawGrid', '(FFFFII)V');
    51.   env^.CallVoidMethodA(env, _jdrawingview, jMethod, @jParams);
    52.   env^.DeleteLocalRef(env, jCls);
    53. end;      
    54.  
    55. function jDrawingView_GetDensity(env: PJNIEnv; _jdrawingview: JObject): Single;
    56. var
    57.   jMethod: jMethodID=nil;
    58.   jCls: jClass=nil;
    59. begin
    60.   jCls:= env^.GetObjectClass(env, _jdrawingview);
    61.   jMethod:= env^.GetMethodID(env, jCls, 'GetDensity', '()F');
    62.   Result:= env^.CallFloatMethod(env, _jdrawingview, jMethod);
    63.   env^.DeleteLocalRef(env, jCls);
    64. end;
    65.  
    66. procedure jDrawingView_ClipRect(env: PJNIEnv; _jdrawingview: JObject; Left, Top, Right, Bottom: Single);
    67. var
    68.   jParams: array[0..3] of jValue;
    69.   jMethod: jMethodID = nil;
    70.   jCls   : jClass = nil;
    71. begin
    72.   jParams[0].f:= Left;
    73.   jParams[0].f:= Top;
    74.   jParams[0].f:= Right;
    75.   jParams[0].f:= Bottom;
    76.   jCls:= env^.GetObjectClass(env, _jdrawingview);
    77.   jMethod:= env^.GetMethodID(env, jCls, 'ClipRect', '(FFFF)V');
    78.   env^.CallVoidMethodA(env, _jdrawingview, jMethod, @jParams);
    79.   env^.DeleteLocalRef(env, jCls);
    80. end;          
    81.  

    jDrawingView.java
    Code: Java  [Select]
    1. public float GetDensity() {
    2.                 return controls.activity.getResources().getDisplayMetrics().density;
    3.         }      
    4.  
    5. public void ClipRect(float _left, float _top, float _right, float _bottom) {
    6.         mCanvas.clipRect(_left, _top, _right, _bottom);
    7.     }
    8.  
    9. public void DrawGrid(float _left, float _top, float _width, float _height, int _cellsX, int _cellsY) {
    10.                 float cw = _width / _cellsX;
    11.                 float ch = _height / _cellsY;
    12.                 for (int i = 0; i < _cellsX + 1; i++) {
    13.                         mCanvas.drawLine(_left + i * cw, _top, _left + i * cw, _top + _height, mDrawPaint); // draw Y lines
    14.                 }
    15.                 for (int i = 0; i < _cellsY + 1; i++) {
    16.                         mCanvas.drawLine(_left, _top + i * ch, _left + _width, _top + i * ch, mDrawPaint); // draw X lines
    17.                 }
    18.         }      
    19.  

    3. Some modifications and the final version of the text output. The string is passed as an array of bytes, and on the java side we can do any conversion. (as I noticed, Delphi does not use NewStringUTF function either). Interesting article: https://juejin.im/post/5a96a79e6fb9a0635865ace3  :)
    jDrawingView.java
    Code: Java  [Select]
    1. import java.nio.charset.Charset;
    2. //...
    3. public class jDrawingView extends View /*dummy*/ {
    4.   //...
    5.   private final Charset UTF8_CHARSET = Charset.forName("UTF-8");
    6.   // ...
    7.  
    8.   // in drawing functions where the rotation, translation or scale matrix is ​​not used, the following function calls are not needed:
    9.   // mCanvas.save () ;
    10.   // mCanvas.restore ();
    11.   // example:
    12.   public void DrawBitmap(Bitmap _bitmap, int _width, int _height) {
    13.         Bitmap bmp = GetResizedBitmap(_bitmap, _width, _height);
    14.         Rect rect = new Rect(0, 0, _width, _height);
    15.         // mCanvas.save(); // not needed!
    16.         mCanvas.drawBitmap(bmp, null, rect, mDrawPaint);
    17.         // mCanvas.restore(); // not needed!
    18.     }
    19.        
    20.     public void DrawBitmap(Bitmap _bitmap, float _x, float _y, float _angleDegree) {
    21.         int x = (int) _x;
    22.         int y = (int) _y;
    23.         Bitmap bmp = GetResizedBitmap(_bitmap, _bitmap.getWidth(), _bitmap.getHeight());
    24.         mCanvas.save(); // needed, uses rotate matrix
    25.         mCanvas.rotate(_angleDegree, x + _bitmap.getWidth() / 2, y + _bitmap.getHeight() / 2);
    26.         mCanvas.drawBitmap(bmp, x, y, null);
    27.         mCanvas.restore();
    28.     }
    29.  
    30.    // new
    31.    private String decodeUTF8(byte[] bytes) {
    32.    return new String(bytes, UTF8_CHARSET);
    33.    //return new String(bytes);
    34.   }
    35.  
    36.   public void DrawText(byte[] _text, float _x, float _y) {
    37.                 mCanvas.drawText(decodeUTF8(_text), _x, _y, mTextPaint);
    38.     }
    39.  

    DrawingView.pas
    Code: Pascal  [Select]
    1. procedure jDrawingView_DrawText(env: PJNIEnv; _jdrawingview: JObject; _text: string; _x: single; _y: single);
    2. var
    3.   jParams: array[0..2] of jValue;
    4.   jMethod: jMethodID=nil;
    5.   jCls: jClass=nil;
    6.   byteArray: jByteArray;
    7.   //AStr: AnsiString;
    8. begin
    9.   //jParams[0].l:= env^.NewStringUTF(env, PChar(_Text)); //  works well with ASCII, but with other encodings, sometimes it works with errors, the application crashes
    10.   //jParams[0].l:= env^.NewString{UTF}(env, PJChar(UTF8Decode(_Text)), Length(_text)); // sometimes the tail appears as unnecessary text characters
    11.   byteArray:= env^.NewByteArray(env, Length(_text));  // allocate
    12.   env^.SetByteArrayRegion(env, byteArray, 0, Length(_text), PJByte(_text));
    13.   jParams[0].l := byteArray;
    14.   jParams[1].f:= _x;
    15.   jParams[2].f:= _y;
    16.   jCls:= env^.GetObjectClass(env, _jdrawingview);
    17.   jMethod:= env^.GetMethodID(env, jCls, 'DrawText', '([BFF)V' {'(Ljava/lang/String;FF)V'});
    18.   env^.CallVoidMethodA(env, _jdrawingview, jMethod, @jParams);
    19.   env^.DeleteLocalRef(env, jParams[0].l);
    20.   env^.DeleteLocalRef(env, jCls);
    21. end;  
    22.  
    « Last Edit: October 09, 2019, 03:41:31 am by kordal »

    jmpessoa

    • Hero Member
    • *****
    • Posts: 1468
    Re: Android Module Wizard
    « Reply #1180 on: October 13, 2019, 01:41:59 am »

    @kordal

    Suggestions/improvements commiteds!!!

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

    kordal

    • New member
    • *
    • Posts: 7
    Re: Android Module Wizard
    « Reply #1181 on: October 24, 2019, 12:40:07 am »
    I updated jDrawingView and added methods for working with shaders: BitmapShader, LinearGradient, RadialGradient, SweepGradient. I'll post the source code a bit later.

    upd. Redid everything and put it out in a separate component JPaintShader that works with JCanvas, JDrawingView

    Example:
    « Last Edit: November 02, 2019, 02:23:07 am by kordal »

    jmpessoa

    • Hero Member
    • *****
    • Posts: 1468
    Re: Android Module Wizard
    « Reply #1182 on: October 24, 2019, 04:03:40 am »

    Great!

    Quote
    I'll post the source code a bit later.

    If possible, please, post the complete ".pas"  and ".java" units as attachments.

    Thank you!


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

    Segator

    • Jr. Member
    • **
    • Posts: 53
    Re: Android Module Wizard
    « Reply #1183 on: November 06, 2019, 03:32:21 pm »
    Hi all, its posible to convert or get the real file path from a content uri like content://... to /strorage/sdcard...

    kordal

    • New member
    • *
    • Posts: 7
    Re: Android Module Wizard
    « Reply #1184 on: November 08, 2019, 01:44:53 am »
    @Segator, hi) Maybe ?
    Code: Pascal  [Select]
    1. Self.GetInternalAppStoragePath(): String // get application path
    2. Self.GetEnvironmentDirectoryPath(dirDCIM): String // ex. get DCIM directory, return: /storage/emulated/0/DCIM
    3. (* TEnvDirectory = (dirDownloads,
    4.                     dirDCIM,
    5.                     dirMusic,
    6.                     dirPictures,
    7.                     dirNotifications,
    8.                     dirMovies,
    9.                     dirPodcasts,
    10.                     dirRingtones,
    11.                     dirSdCard,  // <------------------------------- sdcard
    12.                     dirInternalAppStorage,
    13.                     dirDatabase,
    14.                     dirSharedPrefs,
    15.                     dirCache); *)  

    @jmpessoa, I finally finished working on a new component - JPaintShader, which works in tandem with JCanvas or JDrawingView. As promised, here are the sources and some new demos. I hope I haven’t forgotten anything  :)
    « Last Edit: November 08, 2019, 06:03:43 am by kordal »