Wednesday, March 23, 2011

Mobile WebApps in Android with HTML5

Mobile WebApps in Android with HTML DOWNLOAD SOURCE CODE
 Now you can develop Mobile WebApps in android using HTML5







screen shot.


Source Code
goto assets folder->create one file->file.html.

<!DOCTYPE html>
<html>
<head  >
<body style="background-color:#000000;">
<div id="logo"><a href="http://iamvijayakumar.blogspot.com/">
<marquee behavior="alternate" style="color:#ffffff">iamvijayakumar.blogspot.com</marquee>
</a></div>
</body>
</head>
</html>



Activity code

public class WebviewActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        WebView webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebChromeClient(new WebChromeClient());
        webView.loadUrl("file:///android_asset/webview/home.html");
    }
}

Tuesday, March 22, 2011

Android Tips

Android Tips

what is the folder structure of android?
1. src - It contain the java code
2. Resource - It contain the all resource with different floder
drawable - Icon
raw - Sounds
menu - Menu
values - Project Properties
layout - User interface Screens
3. gen - It contains the R.java file. You could not edit R.java manually. This have been generated automatically by understanding resource files etc.
4. AndroidManifest -It contains the Project properties
5. Android lib.


 what are the api available in the Android?
Activity Manager,

WindowManager, 
Location Manager,
View System, 
Notification Manager,
Telephonic Manager, 
Package Manager,
Resource Manager,

Webview in Android

Webview in Android

DOWNLOAD SOURCE CODE


Webview is primarily used for loading a html content  in our application.

Let us discuss this in several parts. In this first part let load a normal web page to application using webview.

loadUrl is  the prime method to load a particular webpage to webview.

Hence make use of the snippet to load a page.


screen shot 


sourcecode


WebviewActivity.class

package com.webview;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebviewActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        WebView webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://iamvijayakumar.blogspot.com/");

        webView.setWebViewClient(new HelloWebViewClient());

    }
}





But the above method loads the browser instead of opening the webpage inside the application.
To overcome this difficulty we should use the method shouldOverrideUrlLoading() along with webview and url string.
Now the application opens the web page inside the application itself.

 HelloWebViewClient.class

package com.webview;

import android.webkit.WebView;
import android.webkit.WebViewClient;

public class HelloWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

}






main.xml 
 


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:gravity="center" android:padding="10px">
    <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="iamvijayakumar.blogspot.com  " android:textStyle="bold" android:textSize="20sp" android:textColor="#fff"></TextView>
   
    <WebView android:id="@+id/webview" android:layout_width="fill_parent"
        android:layout_height="fill_parent" />


</LinearLayout>

Friday, March 18, 2011

Android Some Tips

Android some Tips

Views and ViewGroups

An Activity contains Views and ViewGroups. A View is a widget that has an appearance on screen. Examples of widgets are buttons, labels, text boxes, etc. A View derives from the base class android.view.View.
One or more Views can be grouped together into a ViewGroup. A ViewGroup (which is by itself is a special type of View) provides the layout in which you can order the appearance and sequence of views. Examples of Viewgroups are LinearLayout, FrameLayout, etc. A ViewGroup derives from the base class android.view.ViewGroup.
Android supports the following ViewGroups:

  • LinearLayout
  • AbsoluteLayout
  • TableLayout
  • RelativeLayout
  • FrameLayout
  • ScrollView


Android Sliding Drawer

Android Sliding Drawer

DOWNLOAD SOURCE CODE

There are two main important component
  1. Sliding Handler - This is the one contains handler button that is always visible in the application.
  2. Sliding Container - The object container that animate slide up/down to show the objects.

i added android sliding drawer code with screen shot also... please find and check it.

it is use full for creating short cut menu like that only.

screen shot


main.xml


<?xml version="1.0" encoding="utf-8"?>


<LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:gravity="bottom" >
   
   
    <LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent" android:layout_height="50dip"
    android:orientation="vertical" android:gravity="bottom" android:background="@drawable/vijayakumar">
   
    <TextView
        android:layout_height="wrap_content"
        android:textColor="#FFFFFF"
        android:textStyle="bold"
        android:paddingLeft="5dip"
        android:textSize="17dip"
        android:layout_width="wrap_content"
        android:text="iamvijayakumar.blogspot.com" />
   
   
    </LinearLayout>
    <SlidingDrawer android:layout_width="wrap_content" android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton" android:content="@+id/contentLayout" android:padding="10dip" android:layout_height="250dip">
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/slideHandleButton" android:background="@drawable/closearrow"></Button>
        <LinearLayout android:layout_width="wrap_content" android:id="@+id/contentLayout" android:orientation="vertical" android:gravity="center|top" android:padding="10dip" android:background="#C0C0C0" android:layout_height="wrap_content">
           
           
        <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Page1"></Button>
<Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Page2"></Button>
<Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Page3"></Button>
</LinearLayout>
    </SlidingDrawer>
</LinearLayout>




Wednesday, March 16, 2011

Android WebService With AsyncTask,Saxparser,HttpClient in Custom ListView

Android WebService With AsyncTask,Saxparser,HttpClient in Custom ListView

DOWNLOAD SOURCE CODE
 


android webservice with AsyncTask,saxparser and httpclient.with listview


we are going to how to access xml file with saxparser using web service.


This is XML format getting all the data. thriught given URL
<maintag>
<item>
<name>AndroidPeople</name>
<website category="android">www.androidpeople.com</website>
</item>
<item>
<name>iPhoneAppDeveloper</name>
<website category="iPhone">www.iphone-app-developer.com</website>
</item>
</maintag>


http://str10.aceonetest.com/myxml.xml
  in this url only example XML file is there. i am accessing this url only for parsing.




ItemStructure.java

public class ItemStructure {
    private String name;
    private String website;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getWebsite() {
        return website;
    }
    public void setWebsite(String website) {
        this.website = website;
    }
     
}



XMLhandler.java


import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;

public class XMLhandler extends DefaultHandler {
    //private ChannelList channelList = new ChannelList();
     private StringBuilder builder;
     private List<ItemStructure> channelList;
      private ItemStructure chList;
    //  private RoomRate currentMessage=new RoomRate();
       
    @Override
    public void characters(char[] ch, int start, int length)
        throws SAXException {
        // TODO Auto-generated method stub
        super.characters(ch, start, length);
        builder.append(ch, start, length);
    }
    @Override
    public void endElement(String uri, String localName, String name)
            throws SAXException {
          // TODO Auto-generated method stub
            super.endElement(uri, localName, name);
            if (chList != null){
           
            if (localName.equalsIgnoreCase("name"))
            {
            chList.setName(builder.toString());
            Log.i("111CITYYYYYYY", "++++++++"+chList.getName());
            }
           
            else if (localName.equalsIgnoreCase("website")){
                chList.setWebsite(builder.toString());
               
            }
            else if (localName.equalsIgnoreCase("item")){
                channelList.add(chList);
            }   
            builder.setLength(0);   
           
            }       
    }
    @Override
    public void startDocument() throws SAXException {
        // TODO Auto-generated method stub
        super.startDocument();
        channelList = new ArrayList<ItemStructure>();
         builder = new StringBuilder();

    }
    @Override
    public void startElement(String uri, String localName, String name,
            Attributes attributes) throws SAXException {
        // TODO Auto-generated method stub
        super.startElement(uri, localName, name, attributes);
         if (localName.equalsIgnoreCase("item")){
                this.chList = new ItemStructure();
                builder.setLength(0);
            }
    }
    public List<ItemStructure> getChannelList() {
        return channelList;
    }
    public void setChannelList(List<ItemStructure> channelList) {
        this.channelList = channelList;
    }
   
}

XMLparsing.java


import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;



public class XMLparsing {
    private InputStream xmlInputStream;

   
   
    public XMLparsing(InputStream xmlInputStream){
          this.xmlInputStream = xmlInputStream;
        }
   
   
   
     public List<ItemStructure> xmlParse() throws IOException
        {
            SAXParserFactory factory = SAXParserFactory.newInstance();
            List<ItemStructure> channellist=null;
        try {     
            SAXParser parser = factory.newSAXParser();
            XMLhandler handler = new XMLhandler();        
            parser.parse(this.getInputStream(),handler);
            return handler.getChannelList();       
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return channellist; 
    }
   
    private InputStream getInputStream() {
        // TODO Auto-generated method stub
        return xmlInputStream;
    }
}






URLHelper.java

public class URLHelper {
    /** Called when the activity is first created. */
   
   
    @SuppressWarnings("unchecked")
    public static ArrayList<ItemStructure> executeRequest( ) throws ClientProtocolException, IOException
{
          
       
        //AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
        HttpClient client = new DefaultHttpClient();

        String response= "";           
    ArrayList<ItemStructure> resarrHotelList= null;
    ArrayList <NameValuePair> params = new ArrayList<NameValuePair>();
    String url1 = "http://www.androidpeople.com/wp-content/uploads/2010/06/example.xml";                             
              HttpGet getUrl = new HttpGet(url1);
              HttpResponse httpResponse = client.execute(getUrl);             
          HttpEntity entity = httpResponse.getEntity();             
        if (entity != null) {                     
             InputStream instream = entity.getContent();                 
             XMLparsing fdParser = new XMLparsing(instream);
             resarrHotelList = (ArrayList<ItemStructure>) fdParser.xmlParse(); 
             instream.close();
         }
                                 
    if(resarrHotelList!=null)
     Log.i("INFOOOO++++", "LIST"+resarrHotelList.size());
    //client.close();
    return resarrHotelList;
 

}


ListAdapter.java

public class ListAdapter extends ArrayAdapter<ItemStructure> {
    //mapData is an hashmap of hotelId vs arraylist,
    private ArrayList<ItemStructure> reservationdata;
    private Context ctx;
    public ListAdapter(Context context, int textViewResourceId,
            ArrayList<ItemStructure> reservationdata) {
        super(context, textViewResourceId, reservationdata);
        this.reservationdata = reservationdata;
        this.ctx = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) ctx
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.main, null);
            //v = vi.inflate(R.layout.bookingdetails, null);
        }
        final ItemStructure o = reservationdata.get(position);
        if (o != null) {
            TextView studentName = (TextView) v.findViewById(R.id.TextView01);
            TextView conNo = (TextView) v.findViewById(R.id.TextView02);
           
            studentName.setText(o.getName());
            conNo.setText(o.getWebsite());
            //fatherName.setText(o.getFatherName());
                       
        Log.i("INFOOOOOOO", "DISPLAY NAME"+o.getName());
           
           
        }
        return v;
    }   
}

MainActivity.java

public class MainActivity extends Activity {
    private Object TestAsyncTask;
    private ListAdapter htlAdapt = null;
    private ListView htlListView = null;
    private String name;
   
    private ItemStructure reservationdata=new ItemStructure();
    static ArrayList<ItemStructure> Content = new ArrayList<ItemStructure>();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.main); 
        setContentView(R.layout.listview);
    //    TextView hotelname=(TextView)findViewById(R.id.slist);
        htlListView = (ListView) findViewById(R.id.ListView01);
        htlAdapt = new ListAdapter(this, R.layout.main,
                Content);       
        htlListView.setAdapter(htlAdapt);       
       
        getURL("http://www.androidpeople.com/wp-content/uploads/2010/06/example.xml");
    }
    public void getURL(String url) {
        TestAsyncTask test = new TestAsyncTask();
       
        test.setContext(this);
   
              test.execute(url);
    }
    class TestAsyncTask extends
            AsyncTask<String, Void, ArrayList<ItemStructure>>{
       
        //  private String Content; 

        ArrayList<ItemStructure> Contents = null;
        private String Error = null;
        private ProgressDialog Dialog;
        private Context ctx;
                public void setContext(Context ctx) {
            this.ctx = ctx;
        }

        protected void onPreExecute() {
            Dialog = new ProgressDialog(ctx);
            Dialog.setMessage("Loading Data...");
 
            Dialog.show();
        }

        protected ArrayList<ItemStructure> doInBackground(String... urls) {

            try {
               
                Log.i("INFOOOOOO", "++++++++1");
                Contents = URLHelper.executeRequest();
               
               
               
                Log.i("INFOOOOOO", "++++++++"+Contents.size());
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            return Contents;
        }

        protected void onPostExecute(ArrayList<ItemStructure> content) {
            Dialog.dismiss();

            if (Error != null) {
                Toast.makeText(ctx, "Pls Try Again  " + Error,
                        Toast.LENGTH_LONG).show();
            }
            else {
                updateView(content);
               
               
            }
        }
    }
    private void updateView(ArrayList<ItemStructure> content) {

        this.Content.clear();

        this.Content.addAll(content);

        this.htlAdapt.notifyDataSetChanged();
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

   
}



Tuesday, March 15, 2011

Difference Between Android 2.1 vs 2.2

Difference Between Android 2.1 vs 2.2

1. Android 2.2 has more speed and performance optimizations
2. Android 2.2 has USB tethering and Wi-Fi hotspot functionality not found in 2.1
3. Android 2.2 allows for app installation to the memory card while 2.1 does not
4. Android 2.2 adds Flash 10.1 support absent in 2.1
5. Android 2.2 has a lot of modified and added APIs
6. Android 2.2 improves support for Microsoft Exchange over 2.1





Friday, March 11, 2011

Android SMS Send and Receive.

Android SMS Send And Receive Application.

DOWNLOAD SOURCE CODE 



you can check this sms send receive local emulator.

just create two emulator .

where you give  phone no that place you have pass that receiving emulator no:5556

ex:
first emulator no:5554(sms sent)

second emulator no:5556(receive sms) .

source code
serbt.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                EditText no=(EditText)findViewById(R.id.no);
                EditText name=(EditText)findViewById(R.id.name);
                EditText author=(EditText)findViewById(R.id.author);
                EditText version=(EditText)findViewById(R.id.version);
                data.insertData(no.getText().toString(), name.getText().toString(), author.getText().toString(), version.getText().toString());
               
                String phoneNo = "5556";
                String message = "Books Succesfully  Details Added!!!!"+","+no.getText().toString()+","+name.getText().toString()+","+author.getText().toString()+","+version.getText().toString();                
                if (phoneNo.length()>0 && message.length()>0)               
                    sendSMS(phoneNo, message);               
                else
                    Toast.makeText(getBaseContext(),
                        "Please enter both phone number and message.",
                        Toast.LENGTH_SHORT).show();              
                Intent in=new Intent(AddBooksActivity.this,AddBooksActivity.class);
                in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(in);
                // ArrayList<String> getData = data.getAllData();                          
            }
          });
       
        Screen Shot First Emulator:5554

             

Second Emulator 5556



               





Source Code:
for receving purpose

@Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
         //---get the SMS message passed in---
        Bundle bundle = intent.getExtras();       
        SmsMessage[] msgs = null;
        String str = "";           
        if (bundle != null)
        {
            //---retrieve the SMS message received---
            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsMessage[pdus.length];           
            for (int i=0; i<msgs.length; i++){
                msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);               
                str += "SMS from " + msgs[i].getOriginatingAddress();                    
                str += " :";
                str += msgs[i].getMessageBody().toString();
                str += "\n";       
            }
            //---display the new SMS message---
            Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
        }                        
    }





Check out this may be help you

Related Posts Plugin for WordPress, Blogger...