Saturday, April 30, 2011

Splash Screen In Android ....

.XML File

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/splashbackground"
  android:layout_gravity="center"
  android:gravity="center"
  android:orientation="vertical">
 
  <ImageView
  android:src="@drawable/logo"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
     android:id="@+id/logo"/>
    
     <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/shipbell"
     style="@style/textview"
android:layout_marginTop="8dip"
     />
</LinearLayout>


.JAVA File


package com.bell.shipclock;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;

public class SplashScreen extends Activity {
    protected boolean _active = true;
    protected int _splashTime = 5000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.splashscreen);
       
        Thread splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) {
                        sleep(100);
                        if(_active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    Intent intent =new Intent(SplashScreen.this, Home.class);
                    startActivity(intent);
                    stop();
                }
            }
        };
        splashTread.start();
       
       

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            _active = false;
        }
        return true;
    }
   
   

}

Splash Screen In Android ....

.XML File

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/splashbackground"
  android:layout_gravity="center"
  android:gravity="center"
  android:orientation="vertical">
 
  <ImageView
  android:src="@drawable/logo"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
     android:id="@+id/logo"/>
    
     <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/shipbell"
     style="@style/textview"
android:layout_marginTop="8dip"
     />
</LinearLayout>


.JAVA File


package com.bell.shipclock;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;

public class SplashScreen extends Activity {
    protected boolean _active = true;
    protected int _splashTime = 5000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.splashscreen);
       
        Thread splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) {
                        sleep(100);
                        if(_active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    Intent intent =new Intent(SplashScreen.this, Home.class);
                    startActivity(intent);
                    stop();
                }
            }
        };
        splashTread.start();
       
       

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            _active = false;
        }
        return true;
    }
   
   

}

Friday, April 29, 2011

spannable in android

.Java File

TextView forgot = (TextView) findViewById(R.id.text1);
        SpannableString content = new SpannableString("Forgot Password");
        content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
        forgot.setText(content);
        forgot.setTextColor(Color.BLACK);

Android New Device (HoneyComb)


New User Features

New UI designed from the ground up for tablets

Android 3.0 is a new version of the Android platform that is specifically optimized for devices with larger screen sizes, particularly tablets. It introduces a brand new, truly virtual and “holographic” UI design, as well as an elegant, content-focused interaction model.
Android 3.0 builds on the things people love most about Android — refined multitasking, rich notifications, Home screen customization, widgets, and more — and transforms them with a vibrant, 3D experience and deeper interactivity, making them familiar but even better than before.
The new UI brings fresh paradigms for interaction, navigation, and customization and makes them available to all applications — even those built for earlier versions of the platform. Applications written for Android 3.0 are able to use an extended set of UI objects, powerful graphics, and media capabilities to engage users in new ways.





System Bar, for global status and notifications
Across the system and in all applications, users have quick access to notifications, system status, and soft navigation buttons in a System Bar, available at the bottom of the screen. The System Bar is always present and is a key touchpoint for users, but in a new "lights out mode" can also be dimmed for full-screen viewing, such as for videos.
Action Bar, for application control
In every application, users have access to contextual options, navigation, widgets, or other types of content in an Action Bar, displayed at the top of the screen. The Action Bar is always present when an application is in use, although its content, theme, and other properties are managed by the application rather than the system. The Action Bar is another key touchpoint for users, especially with action items and an overflow dropdown menu, which users frequently access in a similar manner in most applications.


Customizable Home screens
Five customizable Home screens give users instant access to all parts of the system from any context. Each screen offers a large grid that maintains spatial arrangement in all orientations. Users can select and manipulate Home screen widgets, app shortcuts, and wallpapers using a dedicated visual layout mode. Visual cues and drop shadows improve visibility when adjusting the layout of shortcuts and widgets. Each Home screen also offers a familiar launcher for access to all installed applications, as well as a Search box for universal search of apps, contacts, media files, web content, and more.




The Android 3.0 platform includes an updated set of standard applications that are designed for use on larger screen devices. The sections below highlight some of the new features.
Browser The browser includes new features that let users navigate and organize more efficiently. Multiple tabs replace browser windows and a new “incognito” mode allows anonymous browsing. Bookmarks and history are presented and managed in a single unified view. Users can now choose to automatically sign into Google sites on the browser with a supplied account and sync bookmarks with Google Chrome. New multitouch support is now available to JavaScript and plugins. Users can enjoy a better browsing experience at non-mobile sites through an improved zoom and viewport model, overflow scrolling, support for fixed positioning, and more.
Camera and Gallery
The Camera application has been redesigned to take advantage of a larger screen for quick access to exposure, focus, flash, zoom, front-facing camera, and more. To let users capture scenes in new ways, it adds built-in support for time-lapse video recording. The Gallery application lets users view albums and other collections in full-screen mode, with easy access to thumbnails for other photos in the collection.
Contacts
The Contacts app uses a new two-pane UI and Fast Scroll to let users easily organize and locate contacts. The application offers improved formatting of international phone numbers as user types, based on home country and an international number parsing library. Contact information is presented in a card-like UI, making it easier for users to read and edit contacts.
Email
The Email application uses a new two-pane UI to make viewing and organizing messages more efficient. The app lets users select one or more messages, then select an action from the Action Bar, such as moving them to a folder. Users can sync attachments for later viewing and keep track of email using a home screen Widget.


Wednesday, April 20, 2011

Auto change backgroundcolor by Seek bar in Android




main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/myScreen"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<SeekBar
android:id="@+id/mySeekingBar_R"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:max="255"
    android:progress="0"/>
<SeekBar
android:id="@+id/mySeekingBar_G"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:max="255"
    android:progress="0"/>
<SeekBar
android:id="@+id/mySeekingBar_B"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:max="255"
    android:progress="0"/>
</LinearLayout>
 
SeekColorActivity.java 
 package com.exercise.seekcolor;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.SeekBar;

public class SeekColorActivity extends Activity {

private int seekR, seekG, seekB;
SeekBar redSeekBar, greenSeekBar, blueSeekBar;
LinearLayout mScreen;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mScreen = (LinearLayout) findViewById(R.id.myScreen);
    redSeekBar = (SeekBar) findViewById(R.id.mySeekingBar_R);
    greenSeekBar = (SeekBar) findViewById(R.id.mySeekingBar_G);
    blueSeekBar = (SeekBar) findViewById(R.id.mySeekingBar_B);
    updateBackground();

    redSeekBar.setOnSeekBarChangeListener(seekBarChangeListener);
    greenSeekBar.setOnSeekBarChangeListener(seekBarChangeListener);
    blueSeekBar.setOnSeekBarChangeListener(seekBarChangeListener);

}

private SeekBar.OnSeekBarChangeListener seekBarChangeListener
= new SeekBar.OnSeekBarChangeListener()
{

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
  boolean fromUser) {
// TODO Auto-generated method stub
 updateBackground();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
};

private void updateBackground()
{
 seekR = redSeekBar.getProgress();
 seekG = greenSeekBar.getProgress();
 seekB = blueSeekBar.getProgress();
 mScreen.setBackgroundColor(
  0xff000000
  + seekR * 0x10000
  + seekG * 0x100
  + seekB
  );
}
} 

Gridview Example in Android

.java File



package com.stress;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class Mood extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mood);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v,
                    int position, long id) {
                Toast.makeText(Mood.this, "" + position, Toast.LENGTH_SHORT)
                        .show();

            }
        });
    }

    public class ImageAdapter extends BaseAdapter {
        private Context mContext;

        public ImageAdapter(Context c) {
            mContext = c;
        }

        public int getCount() {
            return mThumbIds.length;
        }

        public Object getItem(int position) {
            return null;
        }

        public long getItemId(int position) {
            return 0;
        }

        // create a new ImageView for each item referenced by the Adapter
        public View getView(int position, View convertView, ViewGroup parent) {
            View grid;

            if (convertView == null) { // if it's not recycled, initialize some
                // attributes
                grid = new View(mContext);
                LayoutInflater inflater = getLayoutInflater();
                grid = inflater.inflate(R.layout.moodcus, parent, false);

            } else {
                grid = (View) convertView;

            }
            ImageView imageView = (ImageView) grid.findViewById(R.id.imgview);
            TextView textView = (TextView) grid.findViewById(R.id.txtview);
            imageView.setImageResource(mThumbIds[position]);
            textView.setText(mMoodnames[position]);
            return grid;
        }

        // references to our images
        private Integer[] mThumbIds = { R.drawable.angry_text,
                R.drawable.bored, R.drawable.calm, R.drawable.confident,
                R.drawable.confused, R.drawable.cool, R.drawable.dipressed,
                R.drawable.elated, R.drawable.embrassed, R.drawable.evil,
                R.drawable.flirt, R.drawable.forgetfull, R.drawable.frusted,
                R.drawable.happy, R.drawable.hungry, R.drawable.impatient,
                R.drawable.inlove, R.drawable.insecure, R.drawable.irrited,
                R.drawable.jealous, R.drawable.lonely, R.drawable.nervous,
                R.drawable.pure, R.drawable.sad, R.drawable.satisfied,
                R.drawable.scared, R.drawable.shy, R.drawable.sick,
                R.drawable.stressed, R.drawable.tired };

        private String[] mMoodnames = { "Angry", "Bored", "Calm", "Confident",
                "Confused", "Cool", "Dipressed", "Elated", "Embrassed", "Evil",
                "Flirt", "Forgetfull", "Frusted", "Happy", "Hungry",
                "Impatient", "Inlove", "Insecure", "Irrited", "Jealous",
                "Lonely", "Nervous", "Pure", "Sad", "Satisfied", "Scared",
                "Shy", "Sick", "Stressed", "Tired" };
    }

}


mood.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="@drawable/background">
    <RelativeLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/grid">
        <GridView android:id="@+id/gridview" android:layout_width="fill_parent"
            android:scrollbars="none" android:layout_height="wrap_content"
            android:columnWidth="90dp" android:numColumns="4" android:fadingEdge="none"
            android:verticalSpacing="10dp" android:horizontalSpacing="10dp"
            android:stretchMode="columnWidth" android:gravity="center"
            android:layout_above="@+id/doneLay" android:layout_marginBottom="100dip" />
    </RelativeLayout>
    <RelativeLayout android:layout_width="fill_parent"
        android:id="@+id/doneLay" android:layout_below="@+id/grid"
        android:layout_centerHorizontal="true" android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button android:layout_width="wrap_content" android:id="@+id/done"
            android:layout_weight="1" android:layout_marginTop="10dip"
            android:layout_centerHorizontal="true" android:layout_marginBottom="55dip"
            android:layout_marginLeft="15dip" android:background="@drawable/done"
            android:layout_height="wrap_content" android:text="@string/done"></Button>
    </RelativeLayout>

</RelativeLayout>



moodcus.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    <ImageView android:id="@+id/imgview" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_gravity="center" />
    <TextView android:id="@+id/txtview" android:layout_width="wrap_content"
        android:textColor="#6687B2" android:layout_height="wrap_content"
        android:layout_gravity="center" />
</LinearLayout>

How to us Tab Group Activity In Android

main.xml

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

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="#F4F4F4">

    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:gravity="center">

        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" android:layout_height="wrap_content" />

        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent" android:layout_height="fill_parent"
            android:gravity="bottom|center_horizontal"></TabWidget>

    </LinearLayout>
</TabHost>

TabGrouActivity.java

package com.statepermit;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Window;

/**
 * The purpose of this Activity is to manage the activities in a tab.
 * Note: Child Activities can handle Key Presses before they are seen here.
 * @author Eric Harlow
 */
public class TabGroupActivity extends ActivityGroup {

    private ArrayList<String> mIdList;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);      
        if (mIdList == null) mIdList = new ArrayList<String>();
    }
 
    /**
     * This is called when a child activity of this one calls its finish method.
     * This implementation calls {@link LocalActivityManager#destroyActivity} on the child activity
     * and starts the previous activity.
     * If the last child activity just called finish(),this activity (the parent),
     * calls finish to finish the entire group.
     */
  @Override
  public void finishFromChild(Activity child) {
      LocalActivityManager manager = getLocalActivityManager();
      int index = mIdList.size()-1;
     
      if (index < 1) {
          finish();
          return;
      }
         
      manager.destroyActivity(mIdList.get(index), true);
      mIdList.remove(index); index--;
      String lastId = mIdList.get(index);
      Intent lastIntent = manager.getActivity(lastId).getIntent();
      Window newWindow = manager.startActivity(lastId, lastIntent);
      setContentView(newWindow.getDecorView());
  }
 
  /**
   * Starts an Activity as a child Activity to this.
   * @param Id Unique identifier of the activity to be started.
   * @param intent The Intent describing the activity to be started.
   * @throws android.content.ActivityNotFoundException.
   */
  public void startChildActivity(String Id, Intent intent) {    
      Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
      if (window != null) {
          mIdList.add(Id);
          Log.v("log_tag", "startchildactivity: " + mIdList.size() + ":" + Id);
          setContentView(window.getDecorView());
      }   
  }
 
  /**
   * The primary purpose is to prevent systems before android.os.Build.VERSION_CODES.ECLAIR
   * from calling their default KeyEvent.KEYCODE_BACK during onKeyDown.
   */
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      Log.v("log_tag", "  this function involve when press-down " );
      if (keyCode == KeyEvent.KEYCODE_BACK) {
          //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
          onBackPressed();
          return true;
      }
      return super.onKeyDown(keyCode, event);
  }

  /**
   * Overrides the default implementation for KeyEvent.KEYCODE_BACK
   * so that all systems call onBackPressed().
   */
  @Override
  public boolean onKeyUp(int keyCode, KeyEvent event) {
     
      Log.v("log_tag", "  this function involve when press-up ");
      if (keyCode == KeyEvent.KEYCODE_BACK) {
          onBackPressed();
          return true;
      }
      return super.onKeyUp(keyCode, event);
  }
 
  /**
   * If a Child Activity handles KeyEvent.KEYCODE_BACK.
   * Simply override and add this method.
   */
  @Override
  public void  onBackPressed() {
      Log.v("log_tag", "this function involve when press back");
      int length = mIdList.size();
      Log.v("log_tag", "length: " + length);
      if (length >= 1) {
          Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
          Log.v("log_tag", "the child view :"+current);
          this.finishFromChild(current);
      }
 
  }
}


StatePermitApplication.java

package com.statepermit;

import android.app.Application;

public class StatePermitApplication extends Application {

    private static String from = "state";

    public static String getFrom() {
        return from;
    }

    public static void setFrom(String fromPage) {
        from = fromPage;
    }
}




statepermit.java

package com.statepermit;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;
import android.widget.TextView;

public class statepermit extends TabActivity
{
    TabHost mTabHost;
    TabWidget mTabWidget;

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

        Resources res = getResources();
        mTabHost = getTabHost();
        TabHost.TabSpec spec;
        mTabWidget = mTabHost.getTabWidget();
        Intent intent;

        intent = new Intent().setClass(this, Home.class);
        spec = mTabHost.newTabSpec(getString(R.string.state))
                .setIndicator("Home", res.getDrawable(R.drawable.home))
                .setContent(intent);
        mTabHost.addTab(spec);

        intent = new Intent().setClass(this, Search.class);
        spec = mTabHost.newTabSpec("Search")
                .setIndicator("Search", res.getDrawable(R.drawable.search))
                .setContent(intent);
        mTabHost.addTab(spec);

        intent = new Intent().setClass(this, Back.class);
        spec = mTabHost.newTabSpec("Back")
                .setIndicator("Back", res.getDrawable(R.drawable.back))
                .setContent(intent);
        mTabHost.addTab(spec);

        for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++)
        {
            mTabHost.getTabWidget().getChildAt(i)
                    .setBackgroundColor(Color.parseColor("#CCCCCC"));
            TextView tv = (TextView) mTabWidget.getChildAt(i).findViewById(
                    android.R.id.title);
            tv.setTextColor(Color.BLACK);
        }

        mTabHost.getTabWidget().getChildAt(0)
                .setBackgroundColor(Color.parseColor("#FFFFFF"));

        mTabHost.setCurrentTab(0);
       
        mTabHost.setOnTabChangedListener(new OnTabChangeListener()
        {
            @Override
            public void onTabChanged(String tabId)
            {
                int tab = mTabHost.getCurrentTab();
                if (tab == 0)
                {
                    mTabHost.getTabWidget().getChildAt(1)
                            .setBackgroundColor(Color.parseColor("#CCCCCC"));
                    mTabHost.getTabWidget().getChildAt(2)
                            .setBackgroundColor(Color.parseColor("#CCCCCC"));
                }
                else if (tab == 1)
                {
                    mTabHost.getTabWidget().getChildAt(0)
                            .setBackgroundColor(Color.parseColor("#CCCCCC"));
                    mTabHost.getTabWidget().getChildAt(2)
                            .setBackgroundColor(Color.parseColor("#CCCCCC"));
                }
                else
                {
                    mTabHost.getTabWidget().getChildAt(0)
                            .setBackgroundColor(Color.parseColor("#CCCCCC"));
                    mTabHost.getTabWidget().getChildAt(1)
                            .setBackgroundColor(Color.parseColor("#CCCCCC"));
                }

                mTabHost.getTabWidget().getChildAt(tab)
                        .setBackgroundColor(Color.WHITE);
            }
        });
    }
}



Login.java


package com.statepermit;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Login extends TabGroupActivity {

    protected static final String TAG = Login.class.getName();
    private static final String LOG = "log_tag";
    public static XMLParser xmlParser;
    public static User myUser;
    private EditText urname;
    private EditText urpass;
    private String username;
    private String password;
    public String myError;
    private Dialog dialog;
    int l = 0;
    protected ProgressDialog mProgressDialog;

    private Handler myHandler = new Handler() {
        public void handleMessage(Message msg) {
            Log.v(LOG, "Message Received");
            if (msg.what == 0) {
                Log.v("log_tag", "Print Error Message");
                errorMessage();
            }
        }
    };

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        Log.v("log_tag", "from where" + StatePermitApplication.getFrom());

        TextView forgot = (TextView) findViewById(R.id.text1);
        SpannableString content = new SpannableString("Forgot Password");
        content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
        forgot.setText(content);
        forgot.setTextColor(Color.BLACK);

        forgot.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent intent = new Intent(Login.this, Forgotpassword.class);
                StatePermitApplication.setFrom("state_login");
                startChildActivity("forgot", intent);

            }
        });

        StatePermitApplication.setFrom("state");
        Button login = (Button) findViewById(R.id.button1);

        urname = (EditText) findViewById(R.id.edit1);
        urpass = (EditText) findViewById(R.id.edit2);
       
        login.setOnClickListener(new OnClickListener() {
    @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                username = urname.getText().toString().trim();
                password = urpass.getText().toString().trim();

                if (username.equals("") && password.equals("")) {
                    Log.v("log_tag", "data is blank");
                    insertdata();
                } else {

                    if (checkInternetConnection()) {
                       
                        //Login.this.showDialog(1);
                        mProgressDialog=ProgressDialog.show(getParent(), "Please Wait", "Login In Process", true);

                        new LoadUserData()
                                .execute(
                                        "http://www.retailpermits.com/WebServices/iPhone/WS_iPhone.asmx/ValidateUser?strUserName="
                                                + username
                                                + "&strPassword="
                                                + password, username, password);
                        StateApplicationClass.setLoginname(username);
                        StateApplicationClass.setPassword(password);
                       
                        Log.v("log_tag",
                                "Full Path :"
                                        + "http://www.retailpermits.com/WebServices/iPhone/WS_iPhone.asmx/ValidateUser?strUserName="
                                        + username + "&strPassword=" + password);
                    } else {
                        // showInternetErrorDialog();
                        internetError();
                        Log.e(TAG, "Internet Error: ");
                    }
                }
            }

        });
    }

    private class LoadUserData extends AsyncTask<String, Integer, Integer> {
        protected Integer doInBackground(String... paths) {
            String url;
            int type;
            try {
                url = paths[0];
                Log.v("log_tag", "URL: " + url);
                xmlParser = new XMLParser("ValidateUser");
                xmlParser.parseUser(url);

                if (xmlParser.getUserId() < 0) {
                    myError = "Could not complete the login. Try again later.";
                    type = 0;
                    Log.v("log_tag", "Error: " + myError);
                } else {
                    type = 1;
                    Log.v("log_tag", "XMLPARSER: " + xmlParser.getUserId());
                }
                return type;
            } catch (Exception e) {
                Log.v("log_tag", "Exception: " + e.toString());
            }
            return 0;
        }

        protected void onPostExecute(Integer result) {
            //dialog.dismiss();
            mProgressDialog.dismiss();
            if (result == 1) {
                Log.v("log_tag", "Succesfully Login");
                Intent intent = new Intent(Login.this, Info.class);
                StatePermitApplication.setFrom("state_login");
                startChildActivity("state_info", intent);
                // startActivity(intent);
                l = xmlParser.getUserId();
            } else if (result == 0) {
                // errorMessage();
                // showErrorMessage(myError);
                Log.v("log_tag", "the wrong password");
                Message msg = new Message();
                msg.what = 0;
                myHandler.sendMessage(msg);
                Log.v("log_tag", "Message Sent");
            }
        }
    }

    private boolean checkInternetConnection() {

        ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        // ARE WE CONNECTED TO THE NET
        if (conMgr.getActiveNetworkInfo() != null
                && conMgr.getActiveNetworkInfo().isAvailable()
                && conMgr.getActiveNetworkInfo().isConnected()) {

            return true;

        } else {
            Log.v(TAG, "Internet Connection Not Present");
            return false;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.DONUT
                && keyCode == KeyEvent.KEYCODE_BACK
                && event.getRepeatCount() == 0) {
            onBackPressed();
        }

        return super.onKeyDown(keyCode, event);
    }

    public void onBackPressed() {
        Log.v("log_tag", "On home Back");
        Intent intent = new Intent(Login.this, statepermit.class);
        StatePermitApplication.setFrom("state");
        startActivity(intent);
        finish();
        return;
    }

    private void internetError() {

        AlertDialog.Builder alt_bld = new AlertDialog.Builder(getParent());
        alt_bld.setMessage(R.string.con_error_text)
                .setCancelable(false)
                .setPositiveButton(R.string.ok,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // Action for 'Yes' Button

                            }
                        })
                .setNegativeButton(R.string.cancel,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // Action for 'NO' Button
                                dialog.cancel();
                            }
                        });
        AlertDialog alert = alt_bld.create();
        // Title for AlertDialog
        alert.setTitle(R.string.connection_error);
        // Icon for AlertDialog
        // alert.setIcon(R.drawable.icon);
        alert.show();

    }

    private void errorMessage() {
        AlertDialog.Builder alt_bld = new AlertDialog.Builder(getParent());
        alt_bld.setMessage(R.string.error_message)
                .setCancelable(false)
                .setPositiveButton(R.string.ok,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // Action for 'Yes' Button
                            }
                        });
        AlertDialog alert = alt_bld.create();
        // Title for AlertDialog
        alert.setTitle(R.string.error);
        alert.show();

    }
    private void insertdata() {

        AlertDialog.Builder alt_bld = new AlertDialog.Builder(getParent());
        alt_bld.setMessage(R.string.insertdata)
                .setCancelable(false)
                .setPositiveButton(R.string.ok,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // Action for 'Yes' Button
                            }
                        });
        AlertDialog alert = alt_bld.create();
        // Title for AlertDialog
        alert.setTitle(R.string.error);
        alert.show();
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        if (id == 1) {
            if (dialog == null) {
                dialog = new Dialog(getParent());
                dialog.setTitle(R.string.please_wait);

            }
            return dialog;
        }
        return super.onCreateDialog(id);
    }

}

Tuesday, April 19, 2011

AMAZON Product

 

Monday, April 18, 2011

XMl Parsing With SAX Parser


example.xml

[sourcecode language="xml"]
<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>
[/sourcecode]

 XMLParsingExample.java
 

package com.androidpeople.xml.parsing;
import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
public class XMLParsingExample extends Activity {
/** Create Object For SiteList Class */
SitesList sitesList = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** Create a new layout to display the view */
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(1);
/** Create a new textview array to display the results */
TextView name[];
TextView website[];
TextView category[];
try {
/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Send URL to parse XML Tags */
URL sourceUrl = new URL(
"http://www.androidpeople.com/wp-content/uploads/2010/06/example.xml");
/** Create handler to handle XML Tags ( extends DefaultHandler ) */
MyXMLHandler myXMLHandler = new MyXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
/** Get result from MyXMLHandler SitlesList Object */
sitesList = MyXMLHandler.sitesList;
/** Assign textview array lenght by arraylist size */
name = new TextView[sitesList.getName().size()];
website = new TextView[sitesList.getName().size()];
category = new TextView[sitesList.getName().size()];
/** Set the result text in textview and add it to layout */
for (int i = 0; i < sitesList.getName().size(); i++) {
name[i] = new TextView(this);
name[i].setText("Name = "+sitesList.getName().get(i));
website[i] = new TextView(this);
website[i].setText("Website = "+sitesList.getWebsite().get(i));
category[i] = new TextView(this);
category[i].setText("Website Category = "+sitesList.getCategory().get(i));
layout.addView(name[i]);
layout.addView(website[i]);
layout.addView(category[i]);
}
/** Set the layout view to display */
setContentView(layout);
}
}
[/sourcecode]

MyXMLHandler.java


package com.androidpeople.xml.parsing;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class MyXMLHandler extends DefaultHandler {
Boolean currentElement = false;
String currentValue = null;
public static SitesList sitesList = null;
public static SitesList getSitesList() {
return sitesList;
}
public static void setSitesList(SitesList sitesList) {
MyXMLHandler.sitesList = sitesList;
}
/** Called when tag starts ( ex:- <name>AndroidPeople</name>
* -- <name> )*/
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
currentElement = true;
if (localName.equals("maintag"))
{
/** Start */
sitesList = new SitesList();
} else if (localName.equals("website")) {
/** Get attribute value */
String attr = attributes.getValue("category");
sitesList.setCategory(attr);
}
}
/** Called when tag closing ( ex:- <name>AndroidPeople</name>
* -- </name> )*/
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
currentElement = false;
/** set value */
if (localName.equalsIgnoreCase("name"))
sitesList.setName(currentValue);
else if (localName.equalsIgnoreCase("website"))
sitesList.setWebsite(currentValue);
}
/** Called to get tag characters ( ex:- <name>AndroidPeople</name>
* -- to get AndroidPeople Character ) */
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
if (currentElement) {
currentValue = new String(ch, start, length);
currentElement = false;
}
}
}
[/sourcecode]

SitesList.java


package com.androidpeople.xml.parsing;
import java.util.ArrayList;
/** Contains getter and setter method for varialbles */
public class SitesList {
/** Variables */
private ArrayList<String> name = new ArrayList<String>();
private ArrayList<String> website = new ArrayList<String>();
private ArrayList<String> category = new ArrayList<String>();
/** In Setter method default it will return arraylist
* change that to add */
public ArrayList<String> getName() {
return name;
}
public void setName(String name) {
this.name.add(name);
}
public ArrayList<String> getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website.add(website);
}
public ArrayList<String> getCategory() {
return category;
}
public void setCategory(String category) {
this.category.add(category);
}
}
[/sourcecode] 

Android Screen Orientation

Change /your Acreen Orientation to your Code in  Androidmanifest.xml,
if you want partrait and Landscape then select both

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.statepermit" android:versionCode="1" android:versionName="1.0">
    <application android:icon="@drawable/stateheader" android:label="@string/app_name">
        <activity android:name=".statepermit" android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
       
    </application>
    <uses-sdk android:minSdkVersion="7" />

</manifest>

Sunday, April 17, 2011

how to change Image In Android

Put this code in ur Program 
 
 .XML file
<Button android:id="@+id/btnLogin" android:text="Login"
        android:background="@drawable/my_button" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:textColor="#FFFFFF"
        android:layout_marginTop="20dip"
        />

/drawable/button_login.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/loginblue" />
    <item android:drawable="@drawable/login_bt" />
    <item android:state_focused="true" android:drawable="@drawable/loginblue" />
</selector>

Android NotePad Tutorial

Notepad Tutorial

This tutorial on writing a notepad application gives you a "hands-on" introduction to the Android framework and the tools you use to build applications on it. Starting from a preconfigured project file, it guides you through the process of developing a simple notepad application and provides concrete examples of how to set up the project, develop the application logic and user interface, and then compile and run the application.
The tutorial presents the application development as a set of exercises (see below), each consisting of several steps. You should follow the steps in each exercise to gradually build and refine your application. The exercises explain each step in detail and provide all the sample code you need to complete the application.
When you are finished with the tutorial, you will have created a functioning Android application and will have learned many of the most important concepts in Android development. If you want to add more complex features to your application, you can examine the code in an alternative implementation of a Note Pad application, in the Sample Code section.

Who Should Use this Tutorial

This tutorial is designed for experienced developers, especially those with knowledge of the Java programming language. If you haven't written Java applications before, you can still use the tutorial, but you might need to work at a slower pace.
Also note that this tutorial uses the Eclipse development environment, with the Android plugin installed. If you are not using Eclipse, you can follow the exercises and build the application, but you will need to determine how to accomplish the Eclipse-specific steps in your environment.

Preparing for the Exercises

The tutorial assumes that you have some familiarity with basic Android application concepts and terminology. If you are not, you should read Application Fundamentals before continuing.
This tutorial also builds on the introductory information provided in the Hello World tutorial, which explains how to set up your Eclipse environment for building Android applications. We recommend you complete the Hello World tutorial before starting this one.
To prepare for this lesson:
  1. Download the project exercises archive (.zip).
  2. Unpack the archive file to a suitable location on your machine.
  3. Open the NotepadCodeLab folder.
Inside the NotepadCodeLab folder, you should see six project files: Notepadv1, Notepadv2, Notepadv3, Notepadv1Solution, Notepadv2Solution and Notepadv3Solution. The Notepadv# projects are the starting points for each of the exercises, while the Notepadv#Solution projects are the exercise solutions. If you are having trouble with a particular exercise, you can compare your current work against the exercise solution.

Exercises

The table below lists the tutorial exercises and describes the development areas that each covers. Each exercise assumes that you have completed any previous exercises.
Exercise 1 Start here. Construct a simple notes list that lets the user add new notes but not edit them. Demonstrates the basics of ListActivity and creating and handling menu options. Uses a SQLite database to store the notes.
Exercise 2 Add a second Activity to the application. Demonstrates constructing a new Activity, adding it to the Android manifest, passing data between the activities, and using more advanced screen layout. Also shows how to invoke another Activity to return a result, using startActivityForResult().
Exercise 3 Add handling of life-cycle events to the application, to let it maintain application state across the life cycle.
Extra Credit Demonstrates how to use the Eclipse debugger and how you can use it to view life-cycle events as they are generated. This section is optional but highly recommended.

Other Resources and Further Learning

  • For a lighter but broader introduction to concepts not covered in the tutorial, take a look at Common Android Tasks.
  • The Android SDK includes a variety of fully functioning sample applications that make excellent opportunities for further learning. You can find the sample applications in the samples/ directory of your downloaded SDK, or browser them here, in the Sample Code section.
  • This tutorial draws from the full Notepad application included in the samples/ directory of the SDK, though it does not match it exactly. When you are done with the tutorial, it is highly recommended that you take a closer look at this version of the Notepad application, as it demonstrates a variety of interesting additions for your application, such as:
    • Setting up a custom striped list for the list of notes.
    • Creating a custom text edit view that overrides the draw() method to make it look like a lined notepad.
    • Implementing a full ContentProvider for notes.
    • Reverting and discarding edits instead of just automatically saving them.

Android Layout

Hello, Views

This is a collection of "Hello World"-style tutorials designed to get you started quickly with common Android layouts and widgets.
A certain amount of knowledge is assumed for these tutorials. Before you start, you should have completed the Hello, World tutorial—it will teach you several things about basic Android development. More specifically, you should know:
  • How to create an Android project and run it
  • The basic structure of an Android project (resource files, layout files, etc.)
  • The basic components of an Activity
Note: In order to make these tutorials as simple as possible, some code may not conform to best practices for coding Android applications. In particular, hard-coded strings are used in places, when the better practice is to reference strings from a res/values/strings.xml resource file.
Tip: After you have pasted sample code into an Eclipse project, press Ctrl (or Cmd) + Shift + O to import the required packages.

Layouts


Widgets & Other Views

There are plenty more layouts and widgets available. See the View class for more on View layouts, and the widget package for more useful widgets. And for more raw code samples, visit the Api Demos.

How to Installing SDK and start Eclipse

Installing the SDK

This page describes how to install the Android SDK and set up your development environment for the first time.
If you encounter any problems during installation, see the Troubleshooting section at the bottom of this page.

Updating?

If you already have an Android SDK, use the Android SDK and AVD Manager tool to install updated tools and new Android platforms into your existing environment. For information about how to do that, see Adding SDK Components

Step 1. Preparing Your Development Computer

Before getting started with the Android SDK, take a moment to confirm that your development computer meets the System Requirements. In particular, you might need to install the JDK, if you don't have it already.
If you will be developing in Eclipse with the Android Development Tools (ADT) Plugin—the recommended path if you are new to Android—make sure that you have a suitable version of Eclipse installed on your computer as described in the System Requirements document. If you need to install Eclipse, you can download it from this location:
The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.

Step 2. Downloading the SDK Starter Package

The SDK starter package is not a full development environment—it includes only the core SDK Tools, which you can use to download the rest of the SDK components (such as the latest Android platform).
If you haven't already, get the latest version of the SDK starter package from the SDK download page.
If you downloaded a .zip or .tgz package (instead of the SDK installer), unpack it to a safe location on your machine. By default, the SDK files are unpacked into a directory named android-sdk-<machine-platform>.
If you downloaded the Windows installer (.exe file), run it now and it will check whether the proper Java SE Development Kit (JDK) is installed (installing it, if necessary), then install the SDK Tools into a default location (which you can modify).
Make a note of the name and location of the SDK directory on your system—you will need to refer to the SDK directory later, when setting up the ADT plugin and when using the SDK tools from command line.

Step 3. Installing the ADT Plugin for Eclipse

Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT), that is designed to give you a powerful, integrated environment in which to build Android applications. It extends the capabilites of Eclipse to let you quickly set up new Android projects, create an application UI, debug your applications using the Android SDK tools, and even export signed (or unsigned) APKs in order to distribute your application. In general, developing in Eclipse with ADT is a highly recommended approach and is the fastest way to get started with Android.
If you'd like to use ADT for developing Android applications, install it now. Read Installing the ADT Plugin for step-by-step installation instructions, then return here to continue the last step in setting up your Android SDK.
If you prefer to work in a different IDE, you do not need to install Eclipse or ADT, instead, you can directly use the SDK tools to build and debug your application. The Overview section of the developer guide outlines the major steps that you need to complete when developing in Eclipse or other IDEs.

Step 4. Adding Platforms and Other Components

The last step in setting up your SDK is using the Android SDK and AVD Manager (a tool included in the SDK starter package) to download essential SDK components into your development environment.
The SDK uses a modular structure that separates the major parts of the SDK—Android platform versions, add-ons, tools, samples, and documentation—into a set of separately installable components. The SDK starter package, which you've already downloaded, includes only a single component: the latest version of the SDK Tools. To develop an Android application, you also need to download at least one Android platform and the SDK Platform-tools (tools that the latest platform depend upon). However, downloading additional components is highly recommended.
If you used the Windows installer, when you complete the installation wizard, it will launch the Android SDK and AVD Manager with a default set of platforms and other components selected for you to install. Simply click Install to accept the recommended set of components and install them. You can then skip to Step 5, but we recommend you first read the section about the Available Components to better understand the components available from the Android SDK and AVD Manager.
You can launch the Android SDK and AVD Manager in one of the following ways:
  • From within Eclipse, select Window > Android SDK and AVD Manager.
  • On Windows, double-click the SDK Manager.exe file at the root of the Android SDK directory.
  • On Mac or Linux, open a terminal and navigate to the tools/ directory in the Android SDK, then execute:
    android
To download components, use the graphical UI of the Android SDK and AVD Manager, shown in Figure 1, to browse the SDK repository and select new or updated components. The Android SDK and AVD Manager will install the selected components in your SDK environment. For information about which components you should download, see the following section about Recommended Components.
Figure 1. The Android SDK and AVD Manager's Available Packages panel, which shows the SDK components that are available for you to download into your environment.

Available Components

By default, there are two repositories of components for your SDK: Android Repository and Third party Add-ons.
The Android Repository offers these types of components:
  • SDK Tools (pre-installed in the Android SDK starter package) — Contains tools for debugging and testing your application and other utility tools. You can access these in the <sdk>/tools/ directory of your SDK and read more about them in the Tools section of the developer guide.
  • SDK Platform-tools — Contains tools that are required to develop and debug your application, but which are developed alongside the Android platform in order to support the latest features. These tools are typically updated only when a new platform becomes available. You can access these in the <sdk>/platform-tools/ directory. Read more about them in the Tools section of the developer guide.
  • Android platforms — An SDK platform is available for every production Android platform deployable to Android-powered devices. Each platform component includes a fully compliant Android library and system image, sample code, emulator skins, and any version specific tools. For detailed information about each platform, see the overview documents available under the section "Downloadable SDK Components," at left.
  • USB Driver for Windows (Windows only) — Contains driver files that you can install on your Windows computer, so that you can run and debug your applications on an actual device. You do not need the USB driver unless you plan to debug your application on an actual Android-powered device. If you develop on Mac OS X or Linux, you do not need a special driver to debug your application on an Android-powered device. (See Developing on a Device for more information about developing on a real device.)
  • Samples — Contains the sample code and apps available for each Android development platform. If you are just getting started with Android development, make sure to download the samples to your SDK.
  • Documentation — Contains a local copy of the latest multiversion documentation for the Android framework API.
The Third party Add-ons provide components that allow you to create a development environment using a specific Android external library (such as the Google Maps library) or a customized (but fully compliant) Android system image. You can add additional Add-on repositories, by clicking Add Add-on Site.

Recommended Components

The SDK repository contains a range of components that you can download. Use the table below to determine which components you need, based on whether you want to set up a basic, recommended, or full development environment:
Environment SDK Component Comments
Basic SDK Tools If you've just installed the SDK starter package, then you already have the latest version of this component. The SDK Tools component is required to develop an Android application. Make sure you keep this up to date.
SDK Platform-tools This includes more tools that are required for application development. These tools are platform-dependent and typically update only when a new SDK platform is made available, in order to support new features in the platform. These tools are always backward compatible with older platforms, but you must be sure that you have the latest version of these tools when you install a new SDK platform.
SDK platform You need to download at least one platform into your environment, so that you will be able to compile your application and set up an Android Virtual Device (AVD) to run it on (in the emulator). To start with, just download the latest version of the platform. Later, if you plan to publish your application, you will want to download other platforms as well, so that you can test your application on the full range of Android platform versions that your application supports.
+
Recommended
(plus Basic)
Documentation The Documentation component is useful because it lets you work offline and also look up API reference information from inside Eclipse.
Samples The Samples components give you source code that you can use to learn about Android, load as a project and run, or reuse in your own app. Note that multiple samples components are available — one for each Android platform version. When you are choosing a samples component to download, select the one whose API Level matches the API Level of the Android platform that you plan to use.
Usb Driver The Usb Driver component is needed only if you are developing on Windows and have an Android-powered device on which you want to install your application for debugging and testing. For Mac OS X and Linux platforms, no special driver is needed.
+
Full
(plus Recommended)
Google APIs The Google APIs add-on gives your application access to the Maps external library, which makes it easy to display and manipulate Maps data in your application.
Additional SDK Platforms If you plan to publish your application, you will want to download additional platforms corresponding to the Android platform versions on which you want the application to run. The recommended approach is to compile your application against the lowest version you want to support, but test it against higher versions that you intend the application to run on. You can test your applications on different platforms by running in an Android Virtual Device (AVD) on the Android emulator.
Once you've installed at least the basic configuration of SDK components, you're ready to start developing Android apps. The next section describes the contents of the Android SDK to familiarize you with the components you've just installed.
For more information about using the Android SDK and AVD Manager, see the Adding SDK Components document.

Step 5. Exploring the SDK (Optional)

Once you've installed the SDK and downloaded the platforms, documentation, and add-ons that you need, we suggest that you open the SDK directory and take a look at what's inside.
The table below describes the full SDK directory contents, with components installed.
NameDescription
add-ons/ Contains add-ons to the Android SDK development environment, which let you develop against external libraries that are available on some devices.
docs/ A full set of documentation in HTML format, including the Developer's Guide, API Reference, and other information. To read the documentation, load the file offline.html in a web browser.
platform-tools/ Contains development tools that may be updated with each platform release (from the Android SDK Platform-tools component). Tools in here include adb, dexdump, and others others that you don't typically use directly. These tools are separate from the generic development tools in the tools/ directory, because these tools may be updated in order to support new features in the latest Android platform, whereas the other tools have no dependencies on the platform version.
platforms/ Contains a set of Android platform versions that you can develop applications against, each in a separate directory.

<platform>/ Platform version directory, for example "android-1.6". All platform version directories contain a similar set of files and subdirectory structure.
 
data/ Storage area for default fonts and resource definitions.


images/ Storage area for default disk images, including the Android system image, the default userdata image, the default ramdisk image, and more. The images are used in emulator sessions.


skins/ A set of emulator skins available for the platform version. Each skin is designed for a specific screen resolution.


templates/ Storage area for file templates used by the SDK development tools.


tools/ This directory is used only by SDK Tools r7 and below for development tools that are specific to this platform version—it's not used by SDK Tools r8 and above.


android.jar The Android library used when compiling applications against this platform version.
samples/ Sample code and apps that are specific to platform version.
tools/ Contains the set of development and profiling tools that are platform-independent, such as the emulator, the AVD and SDK Manager, ddms, hierarchyviewer and more. The tools in this directory may be updated at any time (from the Android SDK Tools component), independent of platform releases, whereas the tools in platform-tools/ may be updated based on the latest platform release.
SDK Readme.txt A file that explains how to perform the initial setup of your SDK, including how to launch the Android SDK and AVD Manager tool on all platforms
SDK Manager.exe Windows SDK only. A shortcut that launches the Android SDK and AVD Manager tool, which you use to add components to your SDK.
Optionally, you might want to add the location of the SDK's tools/ and platform-tools to your PATH environment variable, to provide easy access to the tools.
How to update your PATH
Adding both tools/ and platform-tools/ to your PATH lets you run command line tools without needing to supply the full path to the tool directories. Depending on your operating system, you can include these directories in your PATH in the following way:
  • On Windows, right-click on My Computer, and select Properties. Under the Advanced tab, hit the Environment Variables button, and in the dialog that comes up, double-click on Path (under System Variables). Add the full path to the tools/ and platform-tools/ directories to the path.
  • On Linux, edit your ~/.bash_profile or ~/.bashrc file. Look for a line that sets the PATH environment variable and add the full path to the tools/ and platform-tools directories to it. If you don't see a line setting the path, you can add one:
    export PATH=${PATH}:<sdk>/tools:<sdk>/platform-tools
  • On a Mac OS X, look in your home directory for .bash_profile and proceed as for Linux. You can create the .bash_profile if you don't already have one.

Next Steps

Once you have completed installation, you are ready to begin developing applications. Here are a few ways you can get started:
Set up the Hello World application
  • If you have just installed the SDK for the first time, go to the Hello World tutorial. The tutorial takes you step-by-step through the process of setting up your first Android project, including setting up an Android Virtual Device (AVD) on which to run the application.
Following the Hello World tutorial is an essential first step in getting started with Android development.
Learn about Android
  • Take a look at the Dev Guide and the types of information it provides
  • Read an introduction to Android as a platform in What is Android?
  • Learn about the Android framework and how applications run on it in Application Fundamentals
  • Take a look at the Android framework API specification in the Reference tab
Explore the development tools
Follow the Notepad tutorial
  • The Notepad Tutorial shows you how to build a full Android application and provides helpful commentary on the Android system and API. The Notepad tutorial helps you bring together the important design and architectural concepts in a moderately complex application.
Following the Notepad tutorial is an excellent second step in getting started with Android development.
Explore some code
  • The Android SDK includes sample code and applications for each platform version. You can browse the samples in the Resources tab or download them into your SDK using the Android SDK and AVD Manager. Once you've downloaded the samples, you'll find them in <sdk>/samples/<platform>/.
Visit the Android developer groups
  • Take a look at the Community pages to see a list of Android developers groups. In particular, you might want to look at the Android Developers group to get a sense for what the Android developer community is like.

Troubleshooting

Ubuntu Linux Notes

  • If you need help installing and configuring Java on your development machine, you might find these resources helpful:
  • Here are the steps to install Java and Eclipse, prior to installing the Android SDK and ADT Plugin.
    1. If you are running a 64-bit distribution on your development machine, you need to install the ia32-libs package using apt-get::
      apt-get install ia32-libs
    2. Next, install Java:
      apt-get install sun-java6-jdk
    3. The Ubuntu package manager does not currently offer an Eclipse 3.3 version for download, so we recommend that you download Eclipse from eclipse.org (http://www.eclipse.org/ downloads/). A Java or RCP version of Eclipse is recommended.
    4. Follow the steps given in previous sections to install the SDK and the ADT plugin.

Other Linux Notes

  • If JDK is already installed on your development computer, please take a moment to make sure that it meets the version requirements listed in the System Requirements. In particular, note that some Linux distributions may include JDK 1.4 or Gnu Compiler for Java, both of which are not supported for Android development.