Recent

Author Topic: Android Module Wizard  (Read 705473 times)

renabor

  • Jr. Member
  • **
  • Posts: 73
Re: Android Module Wizard
« Reply #555 on: July 18, 2015, 04:32:11 pm »
Hello @jmpessoa!

Here the solution (finally!) to my problem with click lost on jListView with custom adapter. Problem was related to code that accessed to alist even if was empty in onItemClickListener and the basic hack is to call controls.pOnClickCaptionItem(PasObj, lastSelectedItem, "") with a empty Caption (last parameter) and check with isEmpty if alist is or not empty.

Code: [Select]
/////////////////
Controls.java
////////////////
onItemClickListener = new OnItemClickListener() {@Override
public void onItemClick(AdapterView <? > parent, View v, int position, long id) {
lastSelectedItem = (int) position;
if (!isEmpty(alist)) { // this test is necessary !
if (highLightSelectedItem) {
if (lastSelectedItem > -1) {
DoHighlight(lastSelectedItem, textColor);
}
DoHighlight((int) id, highLightColor);
}
if (alist.get((int) id).widget == 2 /*radio*/ ) { //fix 16-febr-2015
for (int i = 0; i < alist.size(); i++) {
alist.get(i).checked = false;
}
alist.get((int) id).checked = true;
aadapter.notifyDataSetChanged();
}
controls.pOnClickCaptionItem(PasObj, (int) id, alist.get((int) id).label);
} else {
controls.pOnClickCaptionItem(PasObj, lastSelectedItem, ""); // avoid passing possibly undefined Caption
}
}
};

this.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {@Override
public boolean onItemLongClick(AdapterView <? > parent, View view, int position, long id) {
if (!isEmpty(alist)) {
selectedItemCaption = alist.get((int) id).label;
controls.pOnListViewLongClickCaptionItem(PasObj, (int) id, alist.get((int) id).label);
return false;
}
lastSelectedItem = (int) id;
return false;
}
});

}
public static boolean isEmpty(ArrayList coll) {
return (coll == null || coll.isEmpty());
}

p.s. I think that method jFree must set setOnItemLongClickListener(null) too

New method jHttpClient.DeleteStateful

The method implements the DELETE with 2 parameter: Url and Value.
Useful for REST server that will receive a call like this, made with DELETE method:

http://Url/Value

Code: [Select]
/////////////////
Laz_And_Controls
////////////////
function DeleteStateful(_url: string; _value:string): string;

function jHttpClient.DeleteStateful(_url, _value:string): string;
begin
  //in designing component state: result value here...
  if FInitialized then
   Result:= jHttpClient_DeleteStateful(FjEnv, FjObject, _url, _value);
end;   

/////////////////
And_jni_bridge
////////////////
function jHttpClient_DeleteStateful(env: PJNIEnv; _jhttpclient: JObject; _url, _value: string): string;

function jHttpClient_DeleteStateful(env: PJNIEnv; _jhttpclient: JObject; _url, _value: string): string;
var
  jStr: JString;
  jBoo: JBoolean;
  jParams: array[0..1] of jValue;
  jMethod: jMethodID=nil;
  jCls: jClass=nil;
begin
  jParams[0].l:= env^.NewStringUTF(env, PChar(_url));
  jParams[1].l:= env^.NewStringUTF(env, PChar(_value));
  jCls:= env^.GetObjectClass(env, _jhttpclient);
  jMethod:= env^.GetMethodID(env, jCls, 'DeleteStateful', '(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;');
  jStr:= env^.CallObjectMethodA(env, _jhttpclient, jMethod, @jParams);
  case jStr = nil of
     True : Result:= '';
     False: begin
              jBoo:= JNI_False;
              Result:= string( env^.GetStringUTFChars(env, jStr, @jBoo));
            end;
  end;
  env^.DeleteLocalRef(env,jParams[0].l);
  env^.DeleteLocalRef(env,jParams[1].l);
  env^.DeleteLocalRef(env, jCls);
end;

/////////////////
Controls.java
////////////////

import org.apache.http.client.methods.HttpDelete;

    public String DeleteStateful(String _url, String _value) throws Exception {

    int statusCode = 0;
    String strResult = "";

    HttpParams httpParams = new BasicHttpParams();
    int connection_Timeout = 5000;
    HttpConnectionParams.setConnectionTimeout(httpParams, connection_Timeout);
    HttpConnectionParams.setSoTimeout(httpParams, connection_Timeout);

    HttpDelete httpDelete = new HttpDelete(_url + "/" + _value);

    if (mAuthenticationMode != 0) {
    String _credentials = mUSERNAME + ":" + mPASSWORD;
    String _base64EncodedCredentials = Base64.encodeToString(_credentials.getBytes(), Base64.NO_WRAP);
    httpDelete.addHeader("Authorization", "Basic " + _base64EncodedCredentials);
    }

    HttpResponse response = client2.execute(httpDelete, localContext);
    HttpEntity entity = response.getEntity();

    StatusLine statusLine = response.getStatusLine();
    statusCode = statusLine.getStatusCode();

    if (statusCode == 200) { //OK       
    entity = response.getEntity();
    if (entity != null) {
    strResult = EntityUtils.toString(entity);
    }
    }
    return strResult;
    }

Thank you!
« Last Edit: July 18, 2015, 06:01:24 pm by renabor »
FPC 3.2.2 | Lazarus 2.2.3 | Kubuntu 22.04 64bit

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #556 on: July 18, 2015, 10:00:38 pm »

@ renabor

I will make these patches!

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

liuzg2

  • Newbie
  • Posts: 5
Re: Android Module Wizard
« Reply #557 on: July 24, 2015, 04:20:24 pm »
how to call  a webservice

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #558 on: July 25, 2015, 11:11:56 am »
how to call  a webservice

Can explain more ? What exactly do you want ? load a website ?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Android Module Wizard
« Reply #559 on: July 25, 2015, 08:27:12 pm »
I just tried the NoGUI and it seems broken. There are at least 3 scenarios, all after filling the initial dialog:
  • Nothing happened (folder structure created except jni), could happen for the first time use where JNIAndroidProject.ini already exists
  • Second dialog appears, right click on App.java and get simonsayz templates then click OK -> List index out of bound (-1)
  • Delete JNIAndroidProject.ini first, in the second dialog, don't directly click OK but double click Controls.java first and see the Pascal interface, only after that click OK -> Could not change directory to "path to project/obj/controls" Directory not exists
Could you test?

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #560 on: July 25, 2015, 08:47:20 pm »

@ Leledumbo,

Ok, I will test and fix NoGUI.

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

renabor

  • Jr. Member
  • **
  • Posts: 73
Re: Android Module Wizard
« Reply #561 on: July 27, 2015, 07:45:30 am »
Hello @jmpessoa!

I'm trying to use jImageBtn in order to replace normal buttons but can't find the right road.
Which is correct method to load an image as background resource  in jImageBtn?
The sample jImageBtn in AppMenuDemo won't work.
My intent is to replace all buttons with jImageBtn loaded with images taken from Android icons pack in material style (rounded).

Same trouble changing backgroundcolor of a Form or Panel. Changin color from palette work, but it where very nice changing backgroundcolor loading directly the color resource into color settings, using name, not numeric representation.

It is possible to change font for entire App?

A minor typo in jPanel. Having an object inside it (i.e. jEditText), his property MarginBottom is not read and has no effect.

Have you plan to add the Navigation Drawer and Floating Action Button?

Thank you!

FPC 3.2.2 | Lazarus 2.2.3 | Kubuntu 22.04 64bit

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #562 on: July 27, 2015, 11:47:04 am »
Hello @jmpessoa!

I'm trying to use jImageBtn in order to replace normal buttons but can't find the right road.
Which is correct method to load an image as background resource  in jImageBtn?
The sample jImageBtn in AppMenuDemo won't work.
My intent is to replace all buttons with jImageBtn loaded with images taken from Android icons pack in material style (rounded).


Same trouble changing backgroundcolor of a Form or Panel. Changin color from palette work, but it where very nice changing backgroundcolor loading directly the color resource into color settings, using name, not numeric representation.

It is possible to change font for entire App?

A minor typo in jPanel. Having an object inside it (i.e. jEditText), his property MarginBottom is not read and has no effect.

Have you plan to add the Navigation Drawer and Floating Action Button?

Thank you!

may be using bitmap for imagebutton  :)

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #563 on: July 29, 2015, 01:32:47 pm »
Hello All!

There is an updated Lamw/Lazarus Android Module Wizard revision!

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

Version 0.6 - rev. 35 - 28 July 2015 -

   IMPROVEMENT/FIXED!   

          jBluetoothClientSocket component <<--- @Euller and @osvaldotcf request!
               jBluetoothServerSocket component <<--- @Euller and @osvaldotcf request!             
               

   NEW Demos!
 
                AppBluetoothServerSocketDemo1 <---> AppBluetoothClientSocketDemo1 //<<--- No header

                AppBluetoothServerSocketDemo2 <---> AppBluetoothClientSocketDemo2 //<<--- header support

         Technical Notes [header support]:
            .Set property "DataHeaderReceiveEnable = True" for both [client/server]
            .Internal Format [yes, you can use without knowing this information!]:
               first two bytes: size of "header"
               following four bytes: size of "content"
               following bytes "dataHeader"
               following bytes "dataContent"
                  

   FIXED!  Target x86 [AndroidWizard_intf.pas]//<---- thanks to Takeda Matsuki.


   HINT 1: Old Projects: Please, upgrade your project 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"!
         [After any form/component/property  changed and saved.... Problem solved!]

Thanks to All!
« Last Edit: July 29, 2015, 01:42:02 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: Android Module Wizard
« Reply #564 on: July 30, 2015, 04:12:39 am »
@jmpessoa

if load music or video from internet, they will be downloaded and saved to cache memory first, then played, we must wait some minutes if them have large size (>some megabytes)
So I want to ask do we can load and play at the same time ?  :)

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Android Module Wizard
« Reply #565 on: August 01, 2015, 07:23:09 pm »
@jmpessoa

As promissed:
The Wiki-Page:
http://wiki.freepascal.org/Talk:Android_tutorial
Maybe a LAMW-Wiki-Page could also help.
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

renabor

  • Jr. Member
  • **
  • Posts: 73
Re: Android Module Wizard
« Reply #566 on: August 02, 2015, 12:07:16 pm »
@jmpessoa

With last revision, under Linux, it is still impossible to create a new Application.
Selecting JNI Android Module [Lamw GUI] from New menu the error message is:
"Unable to create file build-debug.bat"



FPC 3.2.2 | Lazarus 2.2.3 | Kubuntu 22.04 64bit

liuzg2

  • Newbie
  • Posts: 5
Re: Android Module Wizard
« Reply #567 on: August 03, 2015, 05:31:09 am »
how to call  a webservice

Can explain more ? What exactly do you want ? load a website ?

ps: a  webservice server address   http://localhost:9001/Service/logon?wsdl
  then  client call    logon(name,password)

renabor

  • Jr. Member
  • **
  • Posts: 73
Re: Android Module Wizard
« Reply #568 on: August 03, 2015, 06:15:49 am »
Hello liuzg2

Quote
ps: a  webservice server address   http://localhost:9001/Service/logon?wsdl
  then  client call    logon(name,password)

With jHttClient you have a full suite of opportunities:

Set authentication:

Code: [Select]
  jHttpClient1.SetAuthenticationHost('',-1);
  jHttpClient1.AuthenticationMode:=autBasic;   
  jHttpClient1.SetAuthenticationUser('username', 'password');

make a post:

Code: [Select]
  jHttpClient1.AddNameValueData('name','value');
  jHttpClient1.AddNameValueData('anothername','anothervalue');
  jHttpClient1.PostStateful('http://yourhost');   

using Get:

Code: [Select]
  string := jHttpClient1.Get('http://yourhost/getservice');

Call Delete method:

Code: [Select]
  jHttpClient1.DeleteStateful('http://yourhost','whattodelete');

See example in demos/Eclipse/AppHttpClientDemo1 too.

Best regards,
FPC 3.2.2 | Lazarus 2.2.3 | Kubuntu 22.04 64bit

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android Module Wizard
« Reply #569 on: August 03, 2015, 07:27:05 am »

Hello People!

within a few hours I will make an update to github, trying to solve some instability of lamw wizard
and jImageBtn ... [yes, the wizard lamw will become more smart!]

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

 

TinyPortal © 2005-2018