Recent

Author Topic: Android Module Wizard  (Read 705547 times)

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #465 on: June 04, 2015, 10:19:24 am »
@m4u_hoahoctro

QUESTION 1

Quote
about error:
....Identifier not found "Java_Event_pOnAsyncEvent"

solution: you need upgrade you project  code  templates .... [need by new revision]

Lazarus IDE --> menu Tools --> [Lamw] Android Module Wizard --> Upgrade code Templates [*.lpr, *.java]


thanks much  :)

in demos about internet and socket, it seems not to say about how to get content of a website ( then save to tstringlist ), just about web browser and get url of site, so
how to do that ?  :D

renabor

  • Jr. Member
  • **
  • Posts: 73
Re: Android Module Wizard
« Reply #466 on: June 04, 2015, 03:34:39 pm »
Hello jmpessoa,
I've resolved my problem creating a new project and copying all unit files to the new location.
Have you in plan to implement https and/or OAuth protocol?

thank you very much for your patience and your great job!
FPC 3.2.2 | Lazarus 2.2.3 | Kubuntu 22.04 64bit

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #467 on: June 04, 2015, 05:25:33 pm »
@m4u_hoahoctro

Quote
..... how to get content of a website ( then save to tstringlist )....

Code: [Select]
procedure TAndroidModule1.jHttpClient1ContentResult(Sender: TObject; content: string);
var
   myList: TStringList;
begin
  myList:= TStringList.Create;
  myList.Text:= content;
  myList.SaveToFile(self.GetEnvironmentDirectoryPath(dirDownloads), 'mycontent.txt');
  myList.Free;
end;

Quote
  ....jmediaplayer can't open film file ?

Ok,  I'm improving it!


 @renabor

Quote
... Have you in plan to implement https and/or OAuth protocol?

I will search and try some implementation...


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

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #468 on: June 05, 2015, 11:40:09 am »
thanks much jmpessoa   :)

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #469 on: June 06, 2015, 03:46:43 pm »
Today I tested bluetooth app again, I used your code in BluetoothAppDemos

Quote
var jimage:jobject;
   copyOk:boolean;
begin
  jimage:= jImageFileManager1.LoadFromAssets('picture.jpg');

   //save to internal app storage...
  jImageFileManager1.SaveToFile(jimage, 'picture.jpg');

  //copy from internal storage  to /downloads [public directory!]
  copyOk:= Self.CopyFile(Self.GetEnvironmentDirectoryPath(dirInternalAppStorage)+'/picture.jpg',
                        Self.GetEnvironmentDirectoryPath(dirDownloads)+'/picture.jpg');

   //_mimetype [lowercase!]:  "image/jpeg" or "text/plain" or "image/*" or "*/*" etc...
   if copyOk then
      jBluetooth1.SendFile(Self.GetEnvironmentDirectoryPath(dirDownloads),'picture.jpg', 'image/*');
end;                             

After press button, my app closes and show notification: The application process org.laz.gin2 has stopped unexpectedly. Please try again

I am thinking about lamw no longer supports bluetooth connection on andr 2.3  although If i use jsharefile, it still can work  :o

euller

  • New Member
  • *
  • Posts: 16
Re: Android Module Wizard
« Reply #470 on: June 06, 2015, 04:13:59 pm »
Today I tested bluetooth app again, I used your code in BluetoothAppDemos

Quote
var jimage:jobject;
   copyOk:boolean;
begin
  jimage:= jImageFileManager1.LoadFromAssets('picture.jpg');

   //save to internal app storage...
  jImageFileManager1.SaveToFile(jimage, 'picture.jpg');

  //copy from internal storage  to /downloads [public directory!]
  copyOk:= Self.CopyFile(Self.GetEnvironmentDirectoryPath(dirInternalAppStorage)+'/picture.jpg',
                        Self.GetEnvironmentDirectoryPath(dirDownloads)+'/picture.jpg');

   //_mimetype [lowercase!]:  "image/jpeg" or "text/plain" or "image/*" or "*/*" etc...
   if copyOk then
      jBluetooth1.SendFile(Self.GetEnvironmentDirectoryPath(dirDownloads),'picture.jpg', 'image/*');
end;                             

After press button, my app closes and show notification: The application process org.laz.gin2 has stopped unexpectedly. Please try again

I am thinking about lamw no longer supports bluetooth connection on andr 2.3  although If i use jsharefile, it still can work  :o


@m4u_hoahoctro: the bluetooth components are partially functional, if you see this https://github.com/jmpessoa/lazandroidmodulewizard/issues/19, you will know what I'm talking about. Right now, I'm experimenting with the components, to see if I can implement these functionalities, but I'm not making promises that they will work, or be reliable, I can only promise that I will try to make it happens.

P.S.: I tried using on the APIs 15, 16, 17, 19 and 22, and I didn't see what you've described.
The best way to find a if a tool is faulty; is to use it in a stupid way for stupid purposes

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #471 on: June 07, 2015, 01:49:02 am »
Today I tested bluetooth app again, I used your code in BluetoothAppDemos

Quote
var jimage:jobject;
   copyOk:boolean;
begin
  jimage:= jImageFileManager1.LoadFromAssets('picture.jpg');

   //save to internal app storage...
  jImageFileManager1.SaveToFile(jimage, 'picture.jpg');

  //copy from internal storage  to /downloads [public directory!]
  copyOk:= Self.CopyFile(Self.GetEnvironmentDirectoryPath(dirInternalAppStorage)+'/picture.jpg',
                        Self.GetEnvironmentDirectoryPath(dirDownloads)+'/picture.jpg');

   //_mimetype [lowercase!]:  "image/jpeg" or "text/plain" or "image/*" or "*/*" etc...
   if copyOk then
      jBluetooth1.SendFile(Self.GetEnvironmentDirectoryPath(dirDownloads),'picture.jpg', 'image/*');
end;                             

After press button, my app closes and show notification: The application process org.laz.gin2 has stopped unexpectedly. Please try again

I am thinking about lamw no longer supports bluetooth connection on andr 2.3  although If i use jsharefile, it still can work  :o


@m4u_hoahoctro: the bluetooth components are partially functional, if you see this https://github.com/jmpessoa/lazandroidmodulewizard/issues/19, you will know what I'm talking about. Right now, I'm experimenting with the components, to see if I can implement these functionalities, but I'm not making promises that they will work, or be reliable, I can only promise that I will try to make it happens.

P.S.: I tried using on the APIs 15, 16, 17, 19 and 22, and I didn't see what you've described.

may be it doesn't support android 2.3, thanks for your answer  :)

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #472 on: June 07, 2015, 04:46:31 pm »
@jmpessoa

I created a browser from your demo (Demo1-Webcontrol ), and when I press button to navigate google.com ( or another link), webpage not available ( I tested on virtual and real device, but result same as )

compiler also show error: not defind 'self.updatelayout', commands about self.* still work if I don't use jwebview

this is project:

https://app.box.com/s/a171qc4clw47guulhbrhrbc4n0ijk95v

So what did I miss ?  :o

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #473 on: June 10, 2015, 07:35:08 am »
Hi All!

There is a new Lamw/Lazarus Android Module Wizard revision !!

ref.    https://github.com/jmpessoa/lazandroidmodulewizard

Version 0.6 - rev. 29 - 08 June 2015 -

   NEW!

               jSurfaceView component

   IMPROVEDMENTS!   

      jMediaPlayer component:         
         New! Added support to video play! // <<- @m4u_hoahoctro's request

   NEW! 

      Demo AppMediaPlayerDemo1 [Eclipse Compatible Project]          
      Demo AppSurfaceViewDemo1 [Eclipse Compatible Project]

   UPDATED: All Demos was "upgrade"!         

   HINT 1: Old Projects: upgrade your projects code templates !
      Lazarus IDE --> menu Tools --> [Lamw] Android Module Wizard --> Upgrade code Templates [*.lpr, *.java]

   HINT 2:   When prompt "Read error" [Unknown Property] just choice "Continue Loading"!

Thanks to All!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #474 on: June 10, 2015, 04:17:08 pm »
@jmpessoa, I haven't had any knowledges about web programming yet, so although I tried to read your examples to write an web application, but it seems not be easy  %)

if you have free time, would you mind helping me write an web application that can read text data on a website ( example: read this text and save to string from my site here: http://cartoonforyou.forumvi.com/h1-page)

I also have some problems with jwebview as I replied above

thanks much  :)

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #475 on: June 10, 2015, 05:46:55 pm »
Hi All!

There is a new Lamw/Lazarus Android Module Wizard revision !!

ref.    https://github.com/jmpessoa/lazandroidmodulewizard

Version 0.6 - rev. 29 - 08 June 2015 -

   NEW!

               jSurfaceView component

   IMPROVEDMENTS!   

      jMediaPlayer component:         
         New! Added support to video play! // <<- @m4u_hoahoctro's request

   NEW! 

      Demo AppMediaPlayerDemo1 [Eclipse Compatible Project]          
      Demo AppSurfaceViewDemo1 [Eclipse Compatible Project]

   UPDATED: All Demos was "upgrade"!         

   HINT 1: Old Projects: upgrade your projects code templates !
      Lazarus IDE --> menu Tools --> [Lamw] Android Module Wizard --> Upgrade code Templates [*.lpr, *.java]

   HINT 2:   When prompt "Read error" [Unknown Property] just choice "Continue Loading"!

Thanks to All!

I updated my project, but seems to have an error with jmediaplayer, can't play mp3 or mp4 files as before, I must reuse old version of lamw  :(
« Last Edit: June 12, 2015, 07:46:23 am by m4u_hoahoctro »

euller

  • New Member
  • *
  • Posts: 16
Re: Android Module Wizard
« Reply #476 on: June 11, 2015, 03:05:50 pm »
@m4u_hoahoctro: the bluetooth components are partially functional, if you see this https://github.com/jmpessoa/lazandroidmodulewizard/issues/19, you will know what I'm talking about. Right now, I'm experimenting with the components, to see if I can implement these functionalities, but I'm not making promises that they will work, or be reliable, I can only promise that I will try to make it happens.

P.S.: I tried using on the APIs 15, 16, 17, 19 and 22, and I didn't see what you've described.

Well, I tried to do by myself, and failed miserably. I don't know the why, I used code that worked on other application and nothing. Every time I tested the new component with the modified functionalities, the application didn't even start properly. For now, I'm gonna put this on pause, but I will return to it briefly.
The best way to find a if a tool is faulty; is to use it in a stupid way for stupid purposes

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #477 on: June 12, 2015, 12:07:17 am »
@euller

Quote
... For now, I'm gonna put this on pause

Ok, I also had to do this to avoid delaying the project ...  but I will return in the weekend ...let's see what I can do

@ m4u_hoahoctro

Ok I will do a new demo....
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #478 on: June 12, 2015, 06:56:21 am »
@ m4u_hoahoctro

here is a simple HttpClient and WebView demo ....

https://jmpessoa.opendrive.com/files?Ml85MDM4MzUyNV9lS2ZMTw

or you can create a new project and replace yours  "unit1.pas" and "unit1.lfm" by these:

unit1.pas [demo code ]
Code: [Select]

unit unit1;
 
{$mode delphi}
 
interface
 
uses
  Classes, SysUtils, And_jni, And_jni_Bridge, Laz_And_Controls,
    Laz_And_Controls_Events, AndroidWidget, textfilemanager;
 
type

  { TAndroidModule1 }

  TAndroidModule1 = class(jForm)
      jButton1: jButton;
      jEditText1: jEditText;
      jEditText2: jEditText;
      jHttpClient1: jHttpClient;
      jTextFileManager1: jTextFileManager;
      jTextView1: jTextView;
      jTextView2: jTextView;
      jWebView1: jWebView;
      procedure AndroidModule1JNIPrompt(Sender: TObject);
      procedure AndroidModule1Rotate(Sender: TObject; rotate: integer;
        var rstRotate: integer);
      procedure jButton1Click(Sender: TObject);
      procedure jHttpClient1CodeResult(Sender: TObject; code: integer);
      procedure jHttpClient1ContentResult(Sender: TObject; content: string);

    private
      {private declarations}
    public
      {public declarations}
  end;
 
var
  AndroidModule1: TAndroidModule1;

implementation
 
{$R *.lfm}

{ TAndroidModule1 }

procedure TAndroidModule1.jButton1Click(Sender: TObject);
begin
  jEditText2.Clear;
  jHttpClient1.Get(jEditText1.Text);    //get content  ... http://cartoonforyou.forumvi.com/h1-page
  jWebView1.Navigate('http://www.freepascal.org');  // view web page  ... or: http://cartoonforyou.forumvi.com/h1-page
end;

procedure TAndroidModule1.jHttpClient1CodeResult(Sender: TObject; code: integer);
begin
   ShowMessage(IntToStr(code));
end;

procedure TAndroidModule1.jHttpClient1ContentResult(Sender: TObject; content: string);
var
  list: TStringList;
  txtContent: String;
  ok: boolean;
begin

  jEditText2.AppendLn(content);

  //save to device folder Download...   you can try others folders
  list:= TStringList.Create;
  list.Text:= content;
  list.SaveToFile(Self.GetEnvironmentDirectoryPath(dirDownloads)+'/mycontent.txt');
  list.Free;

   //test  [is it there ?]
   txtContent:=  jTextFileManager1.LoadFromFile( Self.GetEnvironmentDirectoryPath(dirDownloads), 'mycontent.txt');
   ShowMessage(txtContent);   //yes, it is !!!!

  //others test ....
  {ok:= Self.CopyFile(Self.GetEnvironmentDirectoryPath(dirDownloads) + '/mycontent.txt',
                      Self.GetEnvironmentDirectoryPath(dirSdCard) + '/mycontent.txt');

   if ok then ShowMessage('copied !!') else  ShowMessage('copy  fail!')
  }

end;

procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);
begin
  jEditText2.Clear;
  jEditText1.SetFocus;

  if  not Self.IsWifiEnabled() then Self.SetWifiEnabled(True);

  //Test
  {if Self.IsSdCardMounted then ShowMessage('Yes, SdCard is Mounted!!!')
   else ShowMessage('Warning, SdCard is NOT Mounted!');
  }
end;

procedure TAndroidModule1.AndroidModule1Rotate(Sender: TObject;
  rotate: integer; var rstRotate: integer);
begin
   Self.UpdateLayout;
end;

end.



unit1.lfm  [demo code]
Code: [Select]
object AndroidModule1: TAndroidModule1
  Left = 339
  Top = 80
  Width = 300
  Height = 600
  MarginLeft = 0
  MarginTop = 0
  MarginRight = 0
  MarginBottom = 0
  Text = 'AndroidModule1'
  ActivityMode = actMain
  BackgroundColor = colbrDefault
  OnRotate = AndroidModule1Rotate
  OnJNIPrompt = AndroidModule1JNIPrompt
  object jTextView1: jTextView
    Left = 46
    Top = 5
    Width = 208
    Height = 20
    MarginLeft = 5
    MarginTop = 5
    MarginRight = 5
    MarginBottom = 5
    Visible = True
    PosRelativeToAnchor = []
    PosRelativeToParent = [rpTop, rpCenterHorizontal]
    LayoutParamWidth = lpWrapContent
    LayoutParamHeight = lpWrapContent
    Text = 'App HttpClient and WebView Demo'
    Alignment = taLeft
    Enabled = True
    BackgroundColor = colbrDefault
    FontColor = colbrDefault
    FontSize = 0
    TextTypeFace = tfNormal
    Id = 1806969
  end
  object jEditText1: jEditText
    Left = 5
    Top = 70
    Width = 290
    Height = 39
    MarginLeft = 5
    MarginTop = 10
    MarginRight = 5
    MarginBottom = 10
    Visible = True
    Anchor = jTextView2
    PosRelativeToAnchor = [raBelow]
    PosRelativeToParent = []
    LayoutParamWidth = lpMatchParent
    LayoutParamHeight = lpWrapContent
    Text = 'http://cartoonforyou.forumvi.com/h1-page'
    Alignment = taLeft
    InputTypeEx = itxText
    MaxTextLength = 300
    BackgroundColor = colbrDefault
    FontColor = colbrDefault
    FontSize = 0
    HintTextColor = colbrSilver
    ScrollBarStyle = scrNone
    MaxLines = 1
    HorScrollBar = True
    VerScrollBar = False
    WrappingLine = False
    Editable = True
    Id = 5407544
  end
  object jTextView2: jTextView
    Left = 5
    Top = 35
    Width = 20
    Height = 20
    MarginLeft = 5
    MarginTop = 5
    MarginRight = 5
    MarginBottom = 5
    Visible = True
    Anchor = jTextView1
    PosRelativeToAnchor = [raBelow]
    PosRelativeToParent = []
    LayoutParamWidth = lpWrapContent
    LayoutParamHeight = lpWrapContent
    Text = 'Url:'
    Alignment = taLeft
    Enabled = True
    BackgroundColor = colbrDefault
    FontColor = colbrDefault
    FontSize = 0
    TextTypeFace = tfNormal
    Id = 313328
  end
  object jEditText2: jEditText
    Left = 5
    Top = 177
    Width = 290
    Height = 106
    MarginLeft = 5
    MarginTop = 10
    MarginRight = 5
    MarginBottom = 10
    Visible = True
    Anchor = jButton1
    PosRelativeToAnchor = [raBelow]
    PosRelativeToParent = []
    LayoutParamWidth = lpMatchParent
    LayoutParamHeight = lpOneFifthOfParent
    Text = 'jEditText2'
    Alignment = taLeft
    InputTypeEx = itxMultiLine
    MaxTextLength = 2000
    BackgroundColor = colbrPeachPuff
    FontColor = colbrDefault
    FontSize = 0
    HintTextColor = colbrSilver
    ScrollBarStyle = scrNone
    MaxLines = 20
    HorScrollBar = True
    VerScrollBar = True
    WrappingLine = False
    Editable = True
    Id = 3379671
  end
  object jButton1: jButton
    Left = 2
    Top = 123
    Width = 296
    Height = 40
    MarginLeft = 2
    MarginTop = 4
    MarginRight = 2
    MarginBottom = 4
    Visible = True
    Anchor = jEditText1
    PosRelativeToAnchor = [raBelow]
    PosRelativeToParent = []
    LayoutParamWidth = lpMatchParent
    LayoutParamHeight = lpWrapContent
    Text = 'Get Url Content'
    BackgroundColor = colbrDefault
    FontColor = colbrDefault
    FontSize = 0
    OnClick = jButton1Click
    Id = 2166001
  end
  object jWebView1: jWebView
    Left = 8
    Top = 296
    Width = 280
    Height = 280
    Visible = True
    Anchor = jEditText2
    PosRelativeToAnchor = [raBelow]
    PosRelativeToParent = []
    LayoutParamWidth = lpMatchParent
    LayoutParamHeight = lpHalfOfParent
    JavaScript = True
    BackgroundColor = colbrDefault
    ZoomControl = False
    Id = 0
  end
  object jHttpClient1: jHttpClient
    IndexUrl = -1
    AuthenticationMode = autNone
    OnContentResult = jHttpClient1ContentResult
    OnCodeResult = jHttpClient1CodeResult
    left = 128
    top = 208
  end
  object jTextFileManager1: jTextFileManager
    left = 224
    top = 208
  end
end
« Last Edit: June 12, 2015, 07:04:48 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

renabor

  • Jr. Member
  • **
  • Posts: 73
Re: Android Module Wizard
« Reply #479 on: June 12, 2015, 08:36:54 am »
Hi @jmpessoa,

I have a problem with the Id of the objects.
Any new object inserted in a form get an Id of 0, with the conseguence that you can imagine. Is it possible to automate the generation of a unique Id for the newly created object?
I use Lazarus Ide under linux.

Which is the correct way to work with jHttpClient authentication, I have tried this code but without positiv results:

      jHttpClient1.SetAuthenticationHost('http://192.168.1.16',80);
      jHttpClient1.SetAuthenticationUser('username', 'password');
      jHttpClient1.AuthenticationMode:=autBasic;
      jHttpClient1.Get('http://192.168.1.16');

and so, what is wrong?
Can you extend the jHttpClient Class implementing the UPDATE and DELETE methods?

Another question about menu.
I have many Forms in my app and I need different menu in each form, how can I achieve this result?
I use intensely jSqlLite and jHttpClient in any form of my app but I'm unable to share the first instance so I recreate it in every new form. Is there a way to improve it?
Can you suggest me a method to access Contacts for reading and writing them?

thank you very much!

« Last Edit: June 12, 2015, 10:54:10 am by renabor »
FPC 3.2.2 | Lazarus 2.2.3 | Kubuntu 22.04 64bit

 

TinyPortal © 2005-2018