Thursday, December 27, 2012

Android and me : Button Action

  • use the Button onClick attr to declare the name of the action method
  • open the Activity that displays the layout with the Button
  • add a method with a name matching onClick attr value
  • make sure the method takes in a single View as a parameter
in /res/layout
 <Button
        android:text="@string/love_button_text"
        android:id="@+id/Button01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onLoveButtonClicked"
         />
in java
public void onLoveButtonClicked(View view){
      //action
    }

Android and me : Layout

Installation List

1- Get ADT Bundle . refer to this "http://developer.android.com/sdk/installing/bundle.html"

Project Contents
  • screen layouts and resources (defined in XML)
  • app behaviour (defined in java source code)
  • binary assets included in the project
  • configuration file (XML)
Layout in /res/layouts
Values in /res/values




Sunday, December 16, 2012

mysql : command

1 - copy database to new database

 create database <new_database>
mysqldump -u<user> -p<password> <current_database> | mysql -<user> -p<password> <new_database>;
2 - show table status
SHOW TABLE STATUS from <database>

Wednesday, December 12, 2012

axis2 1.6.2 client behind proxy

import
import org.apache.axis2.client.Options;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties; 
   
Call the server webservice

<StubClass> stub = new <StubClass>();
Options options = stub._getServiceClient().getOptions();
HttpTransportProperties.ProxyProperties pp = new HttpTransportProperties.ProxyProperties();
pp.setProxyName(<proxy_host>);
pp.setProxyPort(<proxy_port>);
pp.setPassWord(<proxy_password>);
pp.setUserName(<proxy_username>);
options.setProperty(HTTPConstants.PROXY, pp);

Sunday, December 9, 2012

Httpclient : name value pair


Jar
httpclient-4.2.4.jar
httpcore-4.2.2.jar
httpmime-4.2.2.jar

Import package


import org.apache.http.Consts;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;



Send request to server

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(<url>);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair(<field>, <value>);
httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
HttpResponse response = httpclient.execute(httpost);

Request from proxy and need username and password

           httpclient.getCredentialsProvider().setCredentials(
                   new AuthScope("<proxy_host>", <proxy_port>),
                    new UsernamePasswordCredentials("<proxy_user>", "<proxy_password>"));
           HttpHost proxy = new HttpHost("("<proxy_host>", <proxy_port>);
           httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);


Response
Server response as below :
 <fieldName>=<value>&<fieldName>=<value>
Get response
Map<String, String> responseParams = parseResponse(response);
responseParams.get(<fieldName>") 

 
private static Map<String, String> parseResponse(HttpResponse response) throws IOException {
        Map<String, String> map = new HashMap<String, String>();
        String responseStr = getResponseContent(response);
        List<NameValuePair> responseParams = new ArrayList<NameValuePair>();
        URLEncodedUtils.parse(responseParams, new Scanner(responseStr), "UTF-8");
        for (NameValuePair nvp : responseParams) {
            map.put(nvp.getName(), nvp.getValue());
        }
        return map;
    }

    private static String getResponseContent(HttpResponse response) throws IOException {
        String result = "";
        InputStream is = response.getEntity().getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = null;
        while ((line = br.readLine()) != null) {
            result += line;
        }
        return result;
    }