Recent

Author Topic: Android Module Wizard  (Read 527298 times)

Segator

  • Jr. Member
  • **
  • Posts: 53
Re: Android Module Wizard
« Reply #1185 on: November 08, 2019, 04:54:37 pm »
@kordal, hi thats is good for fixed path but i am talking about convert a content uri from a intent activity like when you open an imagen file with your app the system send a uri string like content://media/external/images/media/112 but this content have a real file path like /storage/sdcard/Pictures/imagen.jpg so i want to convert it content uri to the real path

Segator

  • Jr. Member
  • **
  • Posts: 53
Re: Android Module Wizard
« Reply #1186 on: November 08, 2019, 05:06:10 pm »
I found this but is a java code  %) :
Code: Java  [Select]
  1. public class getRealPathUtil {
  2.  
  3.         @ @TargetApi(Build.VERSION_CODES.KITKAT)
  4.         public static String getRealPathFromURI_API19(Context context, Uri uri){
  5.                 String filePath = "";
  6.                 String wholeID = DocumentsContract.getDocumentId(uri);
  7.              String id = wholeID.split(":")[1];
  8.  
  9.              String[] column = { MediaStore.Images.Media.DATA };    
  10.  
  11.              // where id is equal to            
  12.              String sel = MediaStore.Images.Media._ID + "=?";
  13.  
  14.              Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
  15.                                        column, sel, new String[]{ id }, null);
  16.              int columnIndex = cursor.getColumnIndex(column[0]);
  17.              if (cursor.moveToFirst()) {
  18.                  filePath = cursor.getString(columnIndex);
  19.              }
  20.              cursor.close();
  21.              return filePath;
  22.         }
  23.        
  24.        
  25.         public static String getRealPathFromURI(Context context, Uri contentUri) {
  26.                   Cursor cursor = null;
  27.         try {
  28.             String[] proj = { MediaStore.Images.Media.DATA };
  29.             cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
  30.             cursor.moveToFirst();
  31.            int column_index = cursor.getColumnIndex(proj[0]);
  32.             String path = cursor.getString(column_index);
  33.             return path;
  34.         } finally {
  35.             if (cursor != null) {
  36.                 cursor.close();
  37.             }
  38.         }
  39.                   return result;  
  40.         }
  41.        
  42. }
  43.  
can be implemented in LAMW?

jmpessoa

  • Hero Member
  • *****
  • Posts: 1479
Re: Android Module Wizard
« Reply #1187 on: November 08, 2019, 08:02:04 pm »
Quote
can be implemented in LAMW?

Yes!  i will implement them as jForm methods...

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

kordal

  • New Member
  • *
  • Posts: 17
Re: Android Module Wizard
« Reply #1188 on: November 11, 2019, 01:09:18 am »
@jmpessoa, Have you looked at the source ? And then the post remained unanswered, suddenly did not notice the link)
« Last Edit: November 11, 2019, 01:11:16 am by kordal »

jmpessoa

  • Hero Member
  • *****
  • Posts: 1479
Re: Android Module Wizard
« Reply #1189 on: November 11, 2019, 03:07:13 am »

Hi, kordal!

Yes!

Great work!

I will commit your code!  [as soon as possible!]

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

jmpessoa

  • Hero Member
  • *****
  • Posts: 1479
Re: Android Module Wizard
« Reply #1190 on: November 11, 2019, 05:41:18 am »
@Segator
Quote
I found this but is a java code

Done!

implement as jForm methods...

Code: Pascal  [Select]
  1. var
  2.   Uri: jObjectRef;
  3. begin
  4.      ....................
  5.  
  6.      ShowMessage(Self.GetRealPathFromURI(Uri));
  7.  
  8.      ............................................
  9. end;
  10.  
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Segator

  • Jr. Member
  • **
  • Posts: 53
Re: Android Module Wizard
« Reply #1191 on: November 11, 2019, 03:20:09 pm »
@Segator
Quote
I found this but is a java code

Done!

implement as jForm methods...

Code: Pascal  [Select]
  1. var
  2.   Uri: jObjectRef;
  3. begin
  4.      ....................
  5.  
  6.      ShowMessage(Self.GetRealPathFromURI(Uri));
  7.  
  8.      ............................................
  9. end;
  10.  

Thats is great!, very thank to you.

kordal

  • New Member
  • *
  • Posts: 17
Re: Android Module Wizard
« Reply #1192 on: November 11, 2019, 11:01:07 pm »
Hi, jmpessoa! It`s ok, thanks. I modified my example and adding new (SetRotate) overload method.

jmpessoa

  • Hero Member
  • *****
  • Posts: 1479
Re: Android Module Wizard
« Reply #1193 on: November 12, 2019, 01:53:37 am »

Quote
I modified my example ....

In time!

Commited!

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

kordal

  • New Member
  • *
  • Posts: 17
Re: Android Module Wizard
« Reply #1194 on: November 12, 2019, 09:02:18 pm »
Very well! good news, thank you :)

kordal

  • New Member
  • *
  • Posts: 17
Re: Android Module Wizard
« Reply #1195 on: November 21, 2019, 05:25:52 am »
Hi jmpessoa! After updating LAMW, a bug got out of the repository. In previous versions of this was not observed. I venture to suggest that the name of the original file is taken from the component class name, which is written in Pascal, and not just copied from LAMW. What for? Java source file names are case sensitive.

jmpessoa

  • Hero Member
  • *****
  • Posts: 1479
Re: Android Module Wizard
« Reply #1196 on: November 21, 2019, 07:39:26 am »

Quote
I venture to suggest that the name of the original file is taken from the component class name, which is written in Pascal,....

Terrible! I have no idea where this can happen ...   %)
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

jmpessoa

  • Hero Member
  • *****
  • Posts: 1479
Re: Android Module Wizard
« Reply #1197 on: November 21, 2019, 11:44:47 pm »

Fixed  ["a short term solution"]

("smartdesigner.pas"   line 1606....)

add suppport to 'J' [upcase] in componet  class name...as in "JPaintShader"
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

kordal

  • New Member
  • *
  • Posts: 17
Re: Android Module Wizard
« Reply #1198 on: November 22, 2019, 02:37:36 am »
Thanks for the help. We will find out where this mysterious mistake came from.

kordal

  • New Member
  • *
  • Posts: 17
Re: Android Module Wizard
« Reply #1199 on: November 22, 2019, 07:27:55 am »
Your method did not work. I found a more elegant solution that does not limit the case of writing components. Original JAVA files remain with their names and are not renamed based on the component name.

So, the problem was this:
SmartDesigner.pas
Code: Pascal  [Select]
  1. // ... line 1863
  2. if FileExists(LamwGlobalSettings.PathToJavaTemplates + jclassname + '.java') then
  3.    begin
  4.      list.LoadFromFile(LamwGlobalSettings.PathToJavaTemplates + jclassname + '.java');
  5.      list.Strings[0]:= 'package ' + FPackageName + ';';
  6.      list.SaveToFile(FPathToJavaSource + jclassname + '.java'); // In my case jclassname = JPaintShader, the original jPaintShader.java file. Crash!
  7.                                                                                           // Since FileExists is not case sensitive, the code worked.
  8. // ...
  9.  

What i suggest:
Code: Pascal  [Select]
  1. // returns the original file name from the JAVA template directory
  2. // ex: JClasSs = class(JControl) -> jClass.java
  3. function TLamwSmartDesigner.IsCorrectFileName(const Path, FileName: String): String;
  4. var
  5.   SR: TSearchRec;  
  6. begin
  7.   Result := FileName;
  8.   if FindFirst(Path + FileName, faAnyFile, SR) = 0 then
  9.     Result := SR.Name;
  10.   FindClose(SR);
  11. end;      
  12.  
  13. // ...
  14. if FileExists(LamwGlobalSettings.PathToJavaTemplates + jclassname + '.java') then
  15.    begin
  16.      list.LoadFromFile(LamwGlobalSettings.PathToJavaTemplates + jclassname + '.java');
  17.      list.Strings[0]:= 'package ' + FPackageName + ';';
  18.      list.SaveToFile(FPathToJavaSource + IsCorrectFileName(LamwGlobalSettings.PathToJavaTemplates, jclassname + '.java'));
  19.      // classes can now be written case-insensitively :)
  20. // ...
  21.  

The classes can now be written case-insensitively, file names are taken from the JAVA template directory. On Linux, this should also work because TSearchRec is cross-platform, but I have not tested it.
« Last Edit: November 22, 2019, 07:47:54 am by kordal »