Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Friday 26 October 2012

Create an application to open any URL inside the application and clicking on any link from that URl should not open Native browser but that URL should open the same screen.

Note:Give "INTERNET" permission in android Manifest file.
WebViewActivity.java
package ps.webview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class WebviewActivity extends Activity implements OnClickListener 
{
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */

//CREATE WEBVIEW OBJECT
 WebView web;
 TextView edurl;
 Button btgo;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        // INTIALIZE WEBVIEW OBJECT
        // GIVE PERMISSION INTERNET IN ANDROIDMAINFEST FILE
        
        web=(WebView) findViewById(R.id.webView1);
        edurl=(TextView) findViewById(R.id.editTexturl);
        btgo=(Button) findViewById(R.id.buttongo);
        
        btgo.setOnClickListener(this);
    }
 @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  if(edurl.getText().toString().equals(""))
  {
   Toast.makeText(this, "Pls Enter URL...", 1).show();
  }
  else 
  {
   String stringurl=edurl.getText().toString();
   
   if(!stringurl.startsWith("http://") &&  !stringurl.startsWith("https://") )
    stringurl="http://"+stringurl;
   
   //ENABELING JAVA SCRIPT ON WEBVIEW
   web.getSettings().setJavaScriptEnabled(true);
   
   //LOAD URL ON WEBVIEW
   web.loadUrl(stringurl);

   //SETTING WEBVIEW CLIENT TO OPEN IN SAME SCREEN NOT ON NATIVE BROWSER
   web.setWebViewClient(new WebViewClient());
  }
 }
}

Friday 19 October 2012

Simple Database Operation Example In Android

QUESTION
 Develop an android application for student marks sheet
   a. create student database on SDcard
   b. create table
    i.  student { sno, name, dob }
    ii. marks { sno, s1, s2, s3 }
   c. action to be performed
    i.   Add record
    check for duplication
    ii.  View record
    sno, name, total, per, grade
    iii. Search record
    search by no and name
    iv.  Delete record
 
   With Proper Validation

DatabaseActivity.java
package ps.database;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class DatabaseActivity extends Activity implements OnItemClickListener, TextWatcher {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 ListView lv;
 SQLiteDatabase db;
 TextView edsearchbyno;
 
  String names[];
 TextView edsearchbyname;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        db=openOrCreateDatabase("/sdcard/database", SQLiteDatabase.CREATE_IF_NECESSARY, null);
        db.execSQL("create table if not exists student(sno text, name text, dob text)");
        db.execSQL("create table if not exists marks(sno text, s1 text, s2 text, s3 text)");
        lv=(ListView) findViewById(R.id.listView1);
        
        Cursor cur=db.rawQuery("select * from student", null);
names=new String[cur.getCount()];
for(int i=0;i<cur.getCount();i++)
{
 cur.moveToNext();
 names[i]=cur.getstring(0)+". "+cur.getString(1);
}
ArrayAdapter<"String">arr=new ArrayAdapter<string>(this, android.R.layout.simple_list_item_1,names);
lv.setAdapter(arr);
lv.setOnItemClickListener(this);
        
        //===============================
        
        edsearchbyname=(TextView) findViewById(R.id.editTextsearchname);
        
        edsearchbyname.addTextChangedListener(this);
        
        //===============================
    }
 @Override
 public void onItemClick(AdapterView arg0, View arg1, int pos, long arg3) {
  // TODO Auto-generated method stub
  Intent myintent =new Intent(this,view.class);
  myintent.putExtra("pos", names[pos].substring(0, names[pos].indexOf('.'))+"");
  Toast.makeText(this,names[pos].substring(0, names[pos].indexOf('.'))+" ",1).show();
  startActivity(myintent);
 }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // TODO Auto-generated method stub
  super.onCreateOptionsMenu(menu);
  menu.add(0,0,0,"INSERT");
  menu.add(0,1,1,"REFERESH");
  return true;
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // TODO Auto-generated method stub
  super.onOptionsItemSelected(item);
  if(item.getItemId()==0)
  {
   
   startActivity(new Intent(this,insert.class));
  }
  else if(item.getItemId()==1)
  {
   
   startActivity(new Intent(this,DatabaseActivity.class));
  }
  return true;
 }
 //======================searching===========================
 @Override
 public void afterTextChanged(Editable arg0) {
  // TODO Auto-generated method stub
  Cursor cur=db.rawQuery("select * from student where name like '%"+edsearchbyname.getText().toString()+"%'", null);
  if(cur.getCount()>0)
  {
   names=new String[cur.getCount()];
names=new String[cur.getCount()];
for(int i=0;i<cur.getCount();i++)
{
 cur.moveToNext();
 names[i]=cur.getstring(0)+". "+cur.getString(1);
}
ArrayAdapter<"String">arr=new ArrayAdapter<string>(this, android.R.layout.simple_list_item_1,names);
lv.setAdapter(arr);
lv.setOnItemClickListener(this);
   lv.setAdapter(arr);
  }
 }
 @Override
 public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
   int arg3) {
  // TODO Auto-generated method stub
  
 }
 @Override
 public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
  // TODO Auto-generated method stub
  
 }
}

view.java
package ps.database;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class view extends Activity implements OnClickListener
{
 EditText edno,edname,edtotal,edper,edgrade;
 Button btdelete;
 SQLiteDatabase db;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.view);
  
  db=openOrCreateDatabase("/sdcard/database", SQLiteDatabase.CREATE_IF_NECESSARY, null);
  edno=(EditText) findViewById(R.id.editTextviewnumber);
  edname=(EditText) findViewById(R.id.editTextviewname);
  edtotal=(EditText) findViewById(R.id.editTexttotal);
  edper=(EditText) findViewById(R.id.editTextper);
  edgrade=(EditText) findViewById(R.id.editTextgrade);
  
  btdelete=(Button) findViewById(R.id.buttondelete);
 
  String pos=getIntent().getStringExtra("pos");
  
  Cursor cur=db.rawQuery("select * from student where sno='"+pos+"'", null);
  
  cur.moveToNext();
  
  edno.setText(cur.getString(0));
  edname.setText(cur.getString(1));
  cur.close();
  
  cur=db.rawQuery("select * from marks where sno='"+edno.getText().toString()+"'", null);
  cur.moveToNext();
  int total=Integer.parseInt(cur.getString(1)+"") +Integer.parseInt(cur.getString(2)+"") +Integer.parseInt(cur.getString(3)+"");
  edtotal.setText(total+"");
  int per=total/3;
  edper.setText(total/3+"");
  if(per>65)
   edgrade.setText("A");
  else if(per<=65)
   edgrade.setText("B");

  edno.setEnabled(false);
  edname.setEnabled(false);
  edtotal.setEnabled(false);
  edper.setEnabled(false);
  edgrade.setEnabled(false);
  
  
  btdelete.setOnClickListener(this);
 }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if(btdelete.getId()==v.getId())
  {
   try
   {
   db.execSQL("delete from student where sno='"+edno.getText().toString()+"'");
   db.execSQL("delete from marks where sno='"+edno.getText().toString()+"'");
   Toast.makeText(this, "Delete Success",1).show();
   }
   catch(Exception e)
   {
    Toast.makeText(this, e.toString(), 1).show();
   }
  }
 }
}
insert.java
package ps.database;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class insert extends Activity implements OnClickListener 
{
 EditText edsno,edname,eddob,eds1,eds2,eds3;
 Button btsave,btclear;
 SQLiteDatabase db;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.insert);
  
  db=openOrCreateDatabase("/sdcard/database", SQLiteDatabase.CREATE_IF_NECESSARY, null);
  edsno=(EditText) findViewById(R.id.editTextinsertnumber);
  edname=(EditText) findViewById(R.id.editTextinsertname);
  eddob=(EditText) findViewById(R.id.editTextinsertdob);
  eds1=(EditText) findViewById(R.id.editTextinserts1);
  eds2=(EditText) findViewById(R.id.editTextinserts2);
  eds3=(EditText) findViewById(R.id.editTextinserts3);
  btsave=(Button) findViewById(R.id.buttoninsertsave);
  btclear=(Button) findViewById(R.id.buttoninsertclear);
  
  btsave.setOnClickListener(this);
  btclear.setOnClickListener(this);

 }

 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if(btsave.getId()==v.getId())
  {
   Cursor cur=db.rawQuery("select * from student where sno='"+edsno.getText().toString()+"'", null);
   
   if(cur.getCount()>0)
   {
    Toast.makeText(this, "aleready exists..",1).show(); 
   }
   else 
   {
    if(edsno.getText().toString().equals("") || edname.getText().toString().equals("") || eddob.getText().toString().equals("") ||eds1.getText().toString().equals("")  || eds2.getText().toString().equals("") ||eds3.getText().toString().equals("") )
    {
     Toast.makeText(this, "Pls Enter All the fields", 1).show(); 
    }
    else 
    {
     db.execSQL("insert into student values('"+edsno.getText().toString()+"','"+edname.getText().toString()+"','"+eddob.getText().toString()+"')");
     db.execSQL("insert into marks values('"+edsno.getText().toString()+"','"+eds1.getText().toString()+"','"+eds2.getText().toString()+"','"+eds3.getText().toString()+"')");
    }

    Toast.makeText(this,"Insert success...", 1).show();
   }
  }
  else if(btclear.getId()==v.getId())
  {
   edsno.setText("");
   edname.setText("");
   eddob.setText("");
   eds1.setText("");
   eds2.setText("");
   eds3.setText("");
  }
 }
}

Thursday 18 October 2012

Create an application to pick up any image from the native application gallery and display it on the screen.

Pro23Activity.java
Note :  Drop Images on Sdcard then go to menus open "Dev-Tools" -> "Media Scanner"
package ps.pro23;

import android.app.Activity;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore.Images.Media;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class Pro23Activity extends Activity implements OnClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 
 ImageView img;
 Button btnext, btprevious;
 Cursor cur;
 int total,current;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        img=(ImageView) findViewById(R.id.imageView1);
        btnext=(Button) findViewById(R.id.buttonnext);
        btprevious=(Button) findViewById(R.id.buttonprevious);
        btprevious.setEnabled(false);
        
        btnext.setOnClickListener(this);
        btprevious.setOnClickListener(this);

//Note Media Class is inside MediaStore.Images for images [see 8th line]
        
        //Uri umedia=Uri.parse(Media.EXTERNAL_CONTENT_URI);
        Uri umedia=Uri.parse("content://media/external/images/media");
        
        cur=managedQuery(umedia, null, null,null,null);
        total=cur.getCount();
        
        current=1;
        cur.moveToNext();
        img.setImageBitmap(BitmapFactory.decodeFile(cur.getString(1)));       
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if(v.getId()==btnext.getId())
  {
   current++;
   cur.moveToNext();
   img.setImageBitmap(BitmapFactory.decodeFile(cur.getString(1)));
   if(current==total)
   {
    btnext.setEnabled(false);
   }
   btprevious.setEnabled(true);
  }
  else if(v.getId()==btprevious.getId())
  {
   current--;
   cur.moveToPrevious();
   img.setImageBitmap(BitmapFactory.decodeFile(cur.getString(1)));
   if(current==1)
   {
    btprevious.setEnabled(false);
   }
   btnext.setEnabled(true);
  }
 }
}

Create an application to take picture using native application.

Pro22Activity.java
Note: Give permission in manifest file as "android.permission.CAMERA"
package ps.pro22;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class Pro22Activity extends Activity implements OnClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 
 ImageView img;
 Button btcapture;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        img=(ImageView) findViewById(R.id.imageView1);
        btcapture=(Button) findViewById(R.id.buttoncapture);
        
        btcapture.setOnClickListener(this);
    }
    @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  Intent myintent=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  startActivityForResult(myintent, 0);
 }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     // TODO Auto-generated method stub
     super.onActivityResult(requestCode, resultCode, data);
     Bitmap myimage=(Bitmap) data.getExtras().get("data");
     img.setImageBitmap(myimage);
    }
}

Create an application to send message between two emulators.

Pro21Activity.java
package ps.pro21;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Pro21Activity extends Activity implements OnClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 EditText ednumber, edmsg;
 Button btsend;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ednumber=(EditText) findViewById(R.id.editTextnumber);
        edmsg=(EditText) findViewById(R.id.EditTextmsg);
        btsend=(Button) findViewById(R.id.buttonsend);
        
        btsend.setOnClickListener(this);
    }
    private void sendsms(String num,String msg)
    {
     SmsManager sms=SmsManager.getDefault();
     sms.sendTextMessage(num, null, msg, null, null);
    }
 @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  sendsms(ednumber.getText().toString(),edmsg.getText().toString());;
 }
}

Create an application to draw line on the screen as user drag his finger.

Pro20Activity.java
package ps.pro20;

import android.app.Activity;
import android.os.Bundle;
public class Pro20Activity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new ScreenActivity(this));
    }
}
ScreenActivity.java
package ps.pro20;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.MotionEvent;
import android.view.View;
public class ScreenActivity extends View 
{
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 Paint paintBrush=new Paint(Paint.ANTI_ALIAS_FLAG);
 Path path=new Path();
 
 public ScreenActivity(Context context) {
  super(context);  
  paintBrush.setColor(Color.RED);
  paintBrush.setStrokeWidth(5);
  paintBrush.setStyle(Paint.Style.STROKE);
 }
 @Override
 protected void onDraw(Canvas canvas) {
  // TODO Auto-generated method stub
 super.onDraw(canvas);
  canvas.drawPath(path, paintBrush);
 }
 @Override
 public boolean onTouchEvent(MotionEvent event) {
  // TODO Auto-generated method stub
  super.onTouchEvent(event);
  
  //------getting position-------
  
  float x=event.getX();
  float y=event.getY();
  
  switch(event.getAction())
  {
   case MotionEvent.ACTION_DOWN:
    path.moveTo(x, y);
    return true;
    
   case MotionEvent.ACTION_MOVE:
    path.lineTo(x, y);
    break;
  }
  invalidate();
  return true; 
 }
}

Create an application to read file from the sdcard and display that file content to the screen.

Pro19Activity.java
package ps.pro19;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class Pro19Activity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 TextView tvcontent;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
        tvcontent=(TextView) findViewById(R.id.textView2);
        
        try
        {
         File myFile=new File("/sdcard/hello.txt");
         InputStream in=null;
         in=new FileInputStream(myFile);
         
         String msg="";
         while(in.available()>0)
         {
          msg=msg+(char)in.read();
         }
         in.close();
         tvcontent.setText(msg);

        }
        catch(Exception e)
        {
         Toast.makeText(this, e.toString(),Toast.LENGTH_LONG).show();
        }
    }
}

Create an application to make Insert , update , Delete and retrieve operation on the database.

DataBaseActivity.java
package vc.dataBase;

import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class DataBaseActivity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 SQLiteDatabase db;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       // db.openDatabase("Data1",SQLiteDatabase.CREATE_IF_NECESSARY,null);
        db=openOrCreateDatabase("Data1",SQLiteDatabase.CREATE_IF_NECESSARY,null);
        db.execSQL("create table if not exists student(id integer primary key, name text not null,age integer not null,phone text not null)");
    }
    public boolean onCreateOptionsMenu(Menu menu)
    {
     
     super.onCreateOptionsMenu(menu);
     //When You are put icon in Menu then create the Menu item object
     
     menu.add(0,0,0,"Insert");
     menu.add(0,1,0,"Update");
     menu.add(0,2,0,"Delete");
     menu.add(0,3,0,"View");
  return true;
     
    }
    public boolean onOptionsItemSelected(MenuItem item)
    {
     super.onOptionsItemSelected(item);
     Intent myIntent=new Intent(this,InsertActivity.class);
  myIntent.putExtra("label",item.getItemId());
     if(item.getItemId()==0)
     {
   this.startActivity(myIntent);
     }
     else if(item.getItemId()==1)
     {
      this.startActivity(myIntent);
     }
     else if(item.getItemId()==2)
     {
      this.startActivity(myIntent);
     }
     else if(item.getItemId()==3)
     {
      this.startActivity(myIntent);
     }
     
  return true;
     
    }
}
InsertActivity.java
package vc.dataBase;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class InsertActivity extends Activity implements OnClickListener, TextWatcher, OnItemClickListener {
    /** Called when the activity is first created. */
 //Control Declaration
 EditText txtname,txtage,txtphone;
 Button btnSubmit,btnClear;
 TextView lblname,lblage,lblphone,lblmsg;
 ListView list;
 
 //Variable Declaration
 boolean duplicate=true;
 int flag,len=0,count=0;
 String record[];
 String sname;
 
 //DataBase Object Declaration
 SQLiteDatabase db;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.insert);
        db=openOrCreateDatabase("Data",SQLiteDatabase.CREATE_IF_NECESSARY,null);
        
        txtname=(EditText) findViewById(R.id.txtname);
        txtage=(EditText) findViewById(R.id.txtage);
        txtphone=(EditText) findViewById(R.id.txtphone);
        
        lblname=(TextView) findViewById(R.id.lblname);
        lblage=(TextView) findViewById(R.id.lblage);
        lblphone=(TextView) findViewById(R.id.lblphone);
        lblmsg=(TextView) findViewById(R.id.lblmsg);
        list=(ListView) findViewById(R.id.list);
        list.setOnItemClickListener(this);
        
        btnSubmit=(Button) findViewById(R.id.btnSumit);
        btnClear=(Button) findViewById(R.id.btnClear);
        
        Intent intent=getIntent();
  flag=intent.getIntExtra("label", 0);
  
     btnSubmit.setOnClickListener(this);
     btnClear.setOnClickListener(this);
     txtname.requestFocus();
     list.setVisibility(-1);
     lblmsg.setVisibility(-1);
  
     if(flag==1)
  {
   invisible();
   txtname.addTextChangedListener(this);
   btnSubmit.setText("Edit");
   btnClear.setText("Cancel");
   list.setVisibility(0);
  }
  else if(flag==2)
  {
   invisible();
   txtname.addTextChangedListener(this);
   btnSubmit.setText("Delete");
   btnClear.setText("Cancel");
   list.setVisibility(0);
  }
  else if(flag==3)
  {
   View_Records();
  }
     }
    //Method Declaration
    public void invisible()
 {
     lblage.setVisibility(-1);
  lblphone.setVisibility(-1);
  txtage.setVisibility(-1);
  txtphone.setVisibility(-1);
  btnSubmit.setVisibility(-1);
  btnClear.setVisibility(-1);
 }
    public void visible()
    {
     lblage.setVisibility(0);
  lblphone.setVisibility(0);
  txtage.setVisibility(0);
  txtphone.setVisibility(0);
  btnSubmit.setVisibility(0);
  btnClear.setVisibility(0);
 }
    public void DisEnable()
    {
     txtname.setEnabled(false);
     txtage.setEnabled(false);
     txtphone.setEnabled(false);
    }
    public void Enable()
    {
     txtname.setEnabled(true);
     txtage.setEnabled(true);
     txtphone.setEnabled(true);
    }
    public void clear()
 {
  txtname.setText("");
  txtage.setText("");
  txtphone.setText("");
  txtname.requestFocus();
 }
    public void View_Records()
    {
     list.setVisibility(0);
     lblmsg.setVisibility(0);
     invisible();
     txtname.setVisibility(-1);
     lblname.setVisibility(-1);
     
     int i=0;
     Cursor cur=db.rawQuery("select *from Student",null);
     len=cur.getCount();
     record=new String[len];
     if(len>0)
  {
   while(cur.moveToNext())
   {
    record[i]=cur.getString(0)+"  |  "+cur.getString(1)+"  |  "+cur.getString(3);
    i++;
   }
  }
     
     ArrayAdapter<String> arr=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,record);
     list.setAdapter(arr);
    }
    //Control Method
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  Button action=(Button) v;
  duplicate=true;
  if(action.getText().toString().equals("Submit")) //Record Insert
  {   
   if((txtname.getText().toString().equals(""))&&(txtage.getText().toString().equals(""))&&(txtphone.getText().toString().equals("")))
   {
    Toast.makeText(this,"Record is Already Empty",Toast.LENGTH_SHORT).show();
   }
   else if((txtname.getText().toString().equals("")))
   {
    Toast.makeText(this,"Please Enter Name",Toast.LENGTH_SHORT).show();
   }
   else if((txtage.getText().toString().equals("")))
   {
    Toast.makeText(this,"Please Enter Age",Toast.LENGTH_SHORT).show();
   }
   else if((txtphone.getText().toString().equals("")))
   {
    Toast.makeText(this,"Please Enter Phone Number",Toast.LENGTH_SHORT).show();
   }
   else //Duplicate Record
   {
    String name=txtname.getText().toString();
    String phone=txtphone.getText().toString();
    Cursor c;
    if((c=db.rawQuery("select *from Student where name='"+name+"'", null))!=null)
    {
     if(c.getCount()>0)
     {
      duplicate=false;
      Toast.makeText(this,"Name Already Exist ",Toast.LENGTH_SHORT).show();
     }
    }
    if((c=db.rawQuery("select *from Student where phone='"+phone+"'", null))!=null)
    {
     if(c.getCount()>0)
     {
      duplicate=false;
      Toast.makeText(this,"Number Already Exist ",Toast.LENGTH_SHORT).show();
     }
    }
    if(duplicate==true)
    {
     int age=Integer.parseInt(txtage.getText().toString());
     db.execSQL("insert into Student(name,age,phone)values('"+name+"',"+age+",'"+phone+"')");
     clear();
     Toast.makeText(this,"Record Add SuccessFully",Toast.LENGTH_SHORT).show();
    }
    
   }
  }
  else if(action.getText().toString().equals("Clear")) //Clear Field
  {
   if(!((txtname.getText().toString().equals(""))&&(txtage.getText().toString().equals(""))&&(txtphone.getText().toString().equals(""))))
   {
    clear();
   }
   else
   {
    Toast.makeText(this,"Record is Already Empty",Toast.LENGTH_SHORT).show();
   }
  }
  else if(action.getText().toString().equals("Edit")) //Edit Record
  {
   Enable();
   btnSubmit.setText("Save");
  }
  else if(action.getText().toString().equals("Save")) //After Edit Record or Check Duplicate Record 
  {
   String name=txtname.getText().toString();
   String phone=txtphone.getText().toString();
   Cursor c;
   if((c=db.rawQuery("select *from Student where name='"+name+"'and phone='"+phone+"'", null))!=null)
   {
    if(c.getCount()>0)
    {
     duplicate=false;
     Toast.makeText(this,"Duplicate Name Not Allow ",Toast.LENGTH_SHORT).show();
    }
   }
   else if((c=db.rawQuery("select *from Student where phone='"+phone+"'and name!='"+name+"'", null))!=null)
   {
    if(c.getCount()>0)
    {
     duplicate=false;
     Toast.makeText(this,"Duplicate Number Not Allow ",Toast.LENGTH_SHORT).show();
    }
   }
   if(duplicate==true)
   {
    int age=Integer.parseInt(txtage.getText().toString());
    db.execSQL("update Student set name='"+name+"',age="+age+",phone='"+phone+"' where name='"+sname+"';");
    Toast.makeText(this,"Record Update Successfully",Toast.LENGTH_SHORT).show();
    btnSubmit.setText("Submit");
    this.startActivity(new Intent(this,DataBaseActivity.class));
   }
  }
  else if(action.getText().toString().equals("Cancel")) //Cancel Record and Move First Screen
  {
   this.startActivity(new Intent(this,DataBaseActivity.class));
  }
  else if(action.getText().toString().equals("Delete")) //Delete Particular Record
  {
   String name=txtname.getText().toString();
   db.execSQL("delete from Student where name='"+name+"';");
   Toast.makeText(this,"Delete Record Successfully",Toast.LENGTH_SHORT).show();
   this.startActivity(new Intent(this,DataBaseActivity.class));
  }
 }
 //Edit Text Method
 @Override
 public void afterTextChanged(Editable arg0) { //Filtering the Record
  // TODO Auto-generated method stub
  String name=txtname.getText().toString();
  Cursor cur=db.rawQuery("select *from Student where name LIKE '"+name+"%'", null);
  len=cur.getCount();
  if(txtname.getText().toString().equals(""))
  {
   Toast.makeText(this,"Enter Name"+count,Toast.LENGTH_SHORT).show();
   list.setAdapter(null);
   for(int i=0; i<count; i++)
    record[i]="";
  }
  else if(len>0)
  {
   if(txtname.getText().toString().equals(""))
   {
    list.setAdapter(null);
    for(int i=0; i<count; i++)
     record[i]="";
   }
   else if(len>0)
   {
    record=new String[len];
    cur.moveToNext();
    count=len;
    for(int i=0; i<len; i++)
    {
     record[i]=cur.getString(1);
     cur.moveToNext();
    }
   }
   ArrayAdapter<String> arr =new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,record);
   list.setAdapter(arr);
 }
 else
 {
  Toast.makeText(this,"Record Not Found",Toast.LENGTH_SHORT).show();
 }
 }
 @Override
 public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
   int arg3) {
  // TODO Auto-generated method stub
 }
 @Override
 public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
  // TODO Auto-generated method stub
 }
 @Override
 public void onItemClick(AdapterView<?> p, View v, int pos, long s) {
  // TODO Auto-generated method stub
  list.setVisibility(-1);
  visible();
  sname=record[pos];
  Cursor c=db.rawQuery("select *from Student",null);
  int len1=c.getCount();
  if(len1>0)
  {
   while(c.moveToNext())
   {
    if(sname.equals(c.getString(1)))
    {
     txtname.setText(c.getString(1));
     txtage.setText(c.getInt(2)+"");
     txtphone.setText(c.getString(3));
     break;
    }
    DisEnable();
    list.setVisibility(-1);
   }
  }
 }
}

Create an application that will play a media file from the memory card.

PRO17Activity.java
Note :  Drop Audios on Sdcard then go to menus open "Dev-Tools" -> "Media Scanner"
package vc.PRO17;

import android.app.Activity;
import android.database.Cursor;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.provider.MediaStore.Audio.Media;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class PRO17Activity extends Activity implements OnClickListener, OnItemClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 Button btnpre,btnstart,btnnext;
 String song[];
 MediaPlayer player;
 ListView lv;
 boolean flag=false;
 static int j=0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        btnpre=(Button) findViewById(R.id.btnpre);
        btnstart=(Button) findViewById(R.id.btnstart);
        btnnext=(Button) findViewById(R.id.btnnext);
        lv=(ListView) findViewById(R.id.list);
        
        btnpre.setOnClickListener(this);
        btnstart.setOnClickListener(this);
        btnnext.setOnClickListener(this);
        lv.setOnItemClickListener(this);
        btnpre.setTextColor(Color.GREEN);
        btnstart.setTextColor(Color.GREEN);
        btnnext.setTextColor(Color.GREEN);
        try
        {
         Cursor cur=managedQuery(Media.EXTERNAL_CONTENT_URI, null, null, null, null);
         song=new String[cur.getCount()];
         int i=0;
         while(cur.moveToNext())
         {
          song[i]=cur.getString(1).substring(12);
          i++;
         }
         ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_list_item_1,song);
         lv.setAdapter(aa);
        }
        catch(Exception e)
        {
         Toast.makeText(this,e.toString(),1).show();
        }
    }
    public void song_play()
    {
     try
     {
      if(flag==true)
       player.stop();
      player=new MediaPlayer();
   player.setDataSource("/sdcard/"+song[j]);
      player.prepare();
   player.start();
   flag=true;
  }
     catch(Exception e)
  {
   Toast.makeText(this,"Play"+j, 1).show();
  }
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  Button action =(Button) v;
  if(v.getId()==btnpre.getId())
  {
   if(j>0)
   {
    j--;
    song_play();
   }
   else
   {
    song_play();
   }
   
  }
  else if(action.getText().toString().equals("|>"))
  {
   song_play();
   btnstart.setBackgroundResource(R.drawable.pause);
   btnstart.setText("||");
  }
  else if(action.getText().toString().equals("||"))
  {
   player.stop();
   btnstart.setBackgroundResource(R.drawable.play);
   btnstart.setText("|>");
  }
  else if(v.getId()==btnnext.getId())
  {
   if(song.length-1>j)
   {
    j++;
    song_play();
   }
   else
   {
    song_play();
   }
  }
 }
 @Override
 public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
  // TODO Auto-generated method stub
  j=arg2;
  song_play();
  btnstart.setText("||");
  btnstart.setBackgroundResource(R.drawable.pause);
 }
}

Create an application to read file from asset folder and copy it in memory card.

Pro16Activity.java
package ps.pro16;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class Pro16Activity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 TextView tvmsgfromasset,tvmsgfromsdcard;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        try 
        {
         tvmsgfromasset=(TextView) findViewById(R.id.textView2);
            tvmsgfromsdcard=(TextView) findViewById(R.id.textView4);
            
   //--------reading from asset folder-----------
         
         InputStream is1=null;     
   is1=getResources().getAssets().open("hello.txt");
   
   if(is1!=null)
   {

    Toast.makeText(this, "File Exists", Toast.LENGTH_LONG).show();
    
    String myMsg1="";
    while(is1.available()>0)
    {
     myMsg1=myMsg1+(char)is1.read();
    }
    is1.close();
    
    tvmsgfromasset.setText(myMsg1);
    
   //--------writing to sdcard-----------
    
    byte b[]=myMsg1.getBytes();
    File myFile = new File("/sdcard/hello.txt");
    OutputStream os=new FileOutputStream(myFile);
    os.write(b);
    os.close();
    Toast.makeText(this, "write Success.", Toast.LENGTH_LONG).show();
    
   //--------read file from sdcard--------
    
    InputStream is2=null;
    is2=new FileInputStream(myFile);
    String myMsg2="";
    while(is2.available()>0)
    {
     myMsg2=myMsg2+(char)is2.read();
    }
    is2.close();
    tvmsgfromsdcard.setText(myMsg2+"");
   }
  } 
        catch (IOException e) 
        {
   Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
  }
    }
}

Create an application that will create database with table of User credential.

PRO15Activity.java
package vc.PRO15;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class PRO15Activity extends Activity implements OnItemClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 SQLiteDatabase db;
 ListView lv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        db=openOrCreateDatabase("database1",SQLiteDatabase.CREATE_IF_NECESSARY, null);
  db.execSQL("create table if not exists stud(id integer primary key AUTOINCREMENT,name text,age integer)");
  lv =(ListView) findViewById(R.id.list);
  lv.setOnItemClickListener(this);
  Cursor cur=db.query("stud",null, null, null, null, null, null);
  
  if(cur.getCount()>0)
  {
   String name[]=new String[cur.getCount()];
   int i=0;
   while(cur.moveToNext())
   {
    name[i++]=cur.getString(1);
   }
   ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_list_item_1,name);
   lv.setAdapter(aa);
  }
  else
  {
         Toast.makeText(this,"DataBase is Empty...", 1000).show();
  }
    }
 @Override
 public void onItemClick(AdapterView p, View v, int pos, long c) {
  // TODO Auto-generated method stub
  Intent myintent=new Intent(this,update.class);
  TextView iname=(TextView) v;
  myintent.putExtra("label",iname.getText().toString() );
  startActivity(myintent);
 }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // TODO Auto-generated method stub
  super.onCreateOptionsMenu(menu);
  menu.add(0,5,0,"Insert");
  menu.add(0,1,0,"Update");
  menu.add(0,2,0,"Delete");
  return true;
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // TODO Auto-generated method stub
   super.onOptionsItemSelected(item);
   if(item.getItemId()==5)
   {
    Intent myintent=new Intent(this,update.class);
    myintent.putExtra("flag",item.getItemId());
    startActivity(myintent);
   } 
   else if(item.getItemId()==1)
   {
    Intent myintent=new Intent(this,update.class);
    myintent.putExtra("flag",item.getItemId());
    startActivity(myintent);
   }
   else  if(item.getItemId()==2)
   {
    Intent myintent=new Intent(this,update.class);
    myintent.putExtra("flag",item.getItemId());
    startActivity(myintent);
   }
   return true;
 }
}
insert.java
package vc.PRO15;

import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

public class insert extends Activity  {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 SQLiteDatabase db;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        db=openOrCreateDatabase("database1",SQLiteDatabase.CREATE_IF_NECESSARY, null);
  db.execSQL("create table if not exists stud(id integer primary key,name text,age integer)");
    }
}
update.java
package vc.PRO15;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class update extends Activity implements OnClickListener, TextWatcher, OnItemClickListener  {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 SQLiteDatabase db;
 EditText txtname,txtage,txtid;
 Button btnedit,btncancel;
 TextView lblage;
 ListView lv;
 String name[];
 int flag=-1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.update);
        db=openOrCreateDatabase("database1",SQLiteDatabase.CREATE_IF_NECESSARY, null);
  db.execSQL("create table if not exists stud(id integer primary key AUTOINCREMENT,name text,age integer)");
  
  lblage=(TextView) findViewById(R.id.textView2);
  txtname=(EditText) findViewById(R.id.txtname);
  txtage=(EditText) findViewById(R.id.txtage);
  txtid=(EditText) findViewById(R.id.txtid);
  btnedit=(Button) findViewById(R.id.btnedit);
  btncancel=(Button) findViewById(R.id.btncancel);
  
  lv=(ListView) findViewById(R.id.list);
  lv.setVisibility(-1);
  txtid.setVisibility(-1);
  Intent myintent=getIntent();
  flag=myintent.getIntExtra("flag", 0);
  if(flag==0)
  {
   try
   {
    String label=myintent.getStringExtra("label");
    Cursor cur=db.query("stud",null,"name=?",new String []{label},null, null,null);
    cur.moveToFirst();
    Toast.makeText(this,cur.getString(0)+"", 1).show();
    txtid.setText(cur.getString(0)+"");
    txtname.setText(cur.getString(1));
    txtage.setText(cur.getString(2));
    btnedit.setText("Update");
    txtage.setEnabled(true);
   }
   catch(Exception e)
   {
    Toast.makeText(this,e.toString(), 1).show();
   }
  }
  else if(flag==1)
  {
   txtname.addTextChangedListener(this);
   lv.setVisibility(0);
   invisible();
   txtage.setEnabled(false);
  }
  else if(flag==2)
  {
   txtname.addTextChangedListener(this);
   lv.setVisibility(0);
   invisible();
   btnedit.setText("Delete");
  }
  else if(flag==5)
  {
   btnedit.setText("Save");
  }
  btnedit.setOnClickListener(this);
  btncancel.setOnClickListener(this);
  lv.setOnItemClickListener(this);
    }
    public void invisible()
    {
     lblage.setVisibility(-1);
     txtage.setVisibility(-1);
     btncancel.setVisibility(-1);
     btnedit.setVisibility(-1);
    }
    public void visible()
    {
     lblage.setVisibility(0);
     txtage.setVisibility(0);
     btncancel.setVisibility(0);
     btnedit.setVisibility(0);
    }
    public void clear()
    {
     txtid.setText("");
     txtname.setText("");
     txtage.setText("");
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  Button action=(Button) v;
  if(action.getText().toString().equals("Edit"))
  {
   txtage.setEnabled(true);
   btnedit.setText("Update");
  }
  else if(action.getText().toString().equals("Update"))
  {
   ContentValues value=new ContentValues();
   value.put("name", txtname.getText().toString());
   value.put("age",txtage.getText().toString());
   db.update("stud",value, "id=?", new String[]{txtid.getText().toString()});
   btnedit.setText("Edit");
   Toast.makeText(this,"Update Successfully",1000).show();
   startActivity(new Intent(this,PRO15Activity.class));
  }
  else if(action.getText().toString().equals("Delete"))
  {
   db.delete("stud", "id=?",new String[]{txtid.getText().toString()});
   Toast.makeText(this, "Record Deleted...", Toast.LENGTH_LONG).show();
   startActivity(new Intent(this,PRO15Activity.class));
  }
  else if(action.getText().toString().equals("Save"))
  {
   if(txtname.getText().toString().equals(""))
   {
    Toast.makeText(this,"Please Enter Name ...", 1).show();
   }
   else if(txtage.getText().toString().equals(""))
   {
    Toast.makeText(this,"Please Enter Age ...", 1).show();
   }
   else
   {
    try
    {
     Cursor cur=db.query("stud", null, "name=?",new String[]{txtname.getText().toString()},null, null,null);
     if(cur.getCount()>0)
     {
      Toast.makeText(this,"Name Allready Exists ...",1).show();
     }
     else
     {
       ContentValues values=new ContentValues();
       values.put("name", txtname.getText().toString());
       values.put("age",txtage.getText().toString());
       db.insert("stud",null, values);
       Toast.makeText(this,"Record Saved...", 1).show();
     }
    }
    catch(Exception e)
    {
     Toast.makeText(this,e.toString(), 1).show();
    }
   }
  }
  else if(v.getId()==btncancel.getId())
  {
   startActivity(new Intent(this,PRO15Activity.class));
  }
 }
 public void enabled()
 {
  txtage.setEnabled(true);
 }
 public void disabled()
 {
  txtage.setEnabled(false);
 }
 @Override
 public void afterTextChanged(Editable arg0) {
  // TODO Auto-generated method stub
  Cursor cur=db.rawQuery("select *from stud where name like '"+txtname.getText().toString()+"%'",null);
  int len=cur.getCount();
  try
  {
   if(txtname.getText().toString().equals(""))
   {
    lv.setAdapter(null);
    name[0]="";
   }
   else if(len>0)
   {
    if(txtname.getText().toString().equals(""))
    {
     lv.setAdapter(null);
     for(int i=0; i<len; i++)
      name[i]="";
    }
    else if(len>0)
    {
     name=new String[len];
     cur.moveToNext();
     for(int i=0; i<len; i++)
     {
      name[i]=cur.getString(1);
      cur.moveToNext();
     }
    }
    ArrayAdapter<String> aa=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,name);
    lv.setAdapter(aa);
   }
   else
   {
    Toast.makeText(this,"Recoerd Not Found...", 1000).show();
   }
  }
  catch(Exception e)
  {
   Toast.makeText(this,e.toString(),1000).show();
  }
 }
 @Override
 public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
   int arg3) {
  // TODO Auto-generated method stub
 }
 @Override
 public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
  // TODO Auto-generated method stub
 }
 @Override
 public void onItemClick(AdapterView<?> p, View v, int pos, long c) {
  // TODO Auto-generated method stub
  TextView iname=(TextView) v;
  String sname=iname.getText().toString();
  
  Cursor cur=db.rawQuery("select *from stud",null);
  if(cur.getCount()>0)
  {
   while(cur.moveToNext())
   {
    if(sname.equals(cur.getString(1)))
    {
     txtid.setText(cur.getInt(0)+"");
     txtname.setText(cur.getString(1));
     txtage.setText(cur.getString(2));
     break;
    }
   }
   visible();
   lv.setVisibility(-1);
  }
 }
}

Create an application to call specific entered number by user in the EditText

Pro14Activity.java
package ps.pro14;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Pro14Activity extends Activity implements OnClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 EditText num;
 Button dial;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        num=(EditText) findViewById(R.id.editTextnum);
        dial=(Button) findViewById(R.id.buttondial);
        
        dial.setOnClickListener(this);
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if(v.getId()==dial.getId())
  {
   Intent myintent=new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+num.getText()));
   startActivity(myintent);
  }
 }
}

Read messages from the mobile and display it on the screen.

Pro13Activity.java
package ps.pro13;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

public class Pro13Activity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 TextView txtmsg;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        txtmsg=(TextView) findViewById(R.id.TextViewmsgs);
        
        Uri u=Uri.parse("content://sms/inbox");
        Cursor cur=managedQuery(u, null, null, null, null);
        
        String msg="";
        while(cur.moveToNext())
        {
         msg+=cur.getString(2)+":\n\t"+cur.getString(11)+"\n\n";
        }
        txtmsg.setText(msg);
       
    }
}

Understanding content providers and permissions:
a. Read phonebook contacts using content providers and display in list.

Pro12Activity.java
Note:Give "READ_CONTACTS" permission in android Manifest file.
package ps.pro12;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Pro12Activity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 ListView mylist;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mylist=(ListView) findViewById(R.id.listView1);
        
        //Uri u=Uri.parse("content://contacts/people");
        Uri u=Phones.CONTENT_URI;
        Cursor cur=managedQuery(u, null,null,null,null);
        
        String names[]=new String[cur.getCount()];
        
        int i=0;
        while(cur.moveToNext())
        {
         names[i++]=cur.getString(15)+"ntttt"+cur.getString(7);
        }
        
        ArrayAdapter<String> aa=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,names);
        mylist.setAdapter(aa);
    }
}

Understanding of UI :
a. Create an UI such that , one screen have list of all the types of cars.
b. On selecting of any car name, next screen should show Car details like : name , launched date , company name, images(using gallery) if available, show different colors in which it is available.

Pro11Activity.java
package ps.pro11;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class Pro11Activity extends Activity implements OnItemClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 ListView lv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        lv=(ListView) findViewById(R.id.listView1);
        lv.setOnItemClickListener(this);
    }
 @Override
 public void onItemClick(AdapterView arg0, View arg1, int pos, long arg3) {
  // TODO Auto-generated method stub
  Toast.makeText(this, pos + " click", Toast.LENGTH_SHORT).show();
  
  Intent myintent=new Intent(this,Details.class);
  myintent.putExtra("id", pos);
  startActivity(myintent);
 }
}
ImageAdapter.java
package ps.pro11;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 Context c;
 int id;
 
 Integer listmarutisuzuki[]={R.drawable.marutisuzuki1,R.drawable.marutisuzuki2,R.drawable.marutisuzuki3};
 Integer listalto[]={R.drawable.alto1,R.drawable.alto2,R.drawable.alto3};
 Integer listhundai[]={R.drawable.hundai1,R.drawable.hundai2,R.drawable.hundai3};
 Integer listoodi[]={R.drawable.oodi1,R.drawable.oodi2,R.drawable.oodi3};
 
 public ImageAdapter(Context c,int id)
 {
  this.c=c;
  this.id=id;
  Log.d("master", id+"clicked");
 }
 @Override
 public int getCount() {
  // TODO Auto-generated method stub
  
  if(id==0)
  {
   return listmarutisuzuki.length; 
  }
  if(id==1)
  {
   return listalto.length;
  }
  if(id==2)
  {
   return listhundai.length;
  }
  if(id==3)
  {
   return listoodi.length;
  }
  return listmarutisuzuki.length;
 }

 @Override
 public Object getItem(int arg0) {
  // TODO Auto-generated method stub
  return arg0;
 }

 @Override
 public long getItemId(int arg0) {
  // TODO Auto-generated method stub
  return arg0;
 }

 @Override
 public View getView(int arg0, View arg1, ViewGroup arg2) {
  // TODO Auto-generated method stub
  ImageView img=new ImageView(c);
  
  if(id==0)
  {
   img.setImageResource(listmarutisuzuki[arg0]);
   
  }
  if(id==1)
  {
   img.setImageResource(listalto[arg0]);
  }
  if(id==2)
  {
   img.setImageResource(listhundai[arg0]);
  }
  if(id==3)
  {
   img.setImageResource(listoodi[arg0]);
     
  }
  img.setScaleType(ImageView.ScaleType.FIT_XY);
  img.setLayoutParams(new Gallery.LayoutParams(120, 200));
  return img;
 }
}
Details.java
package ps.pro11;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Gallery;
import android.widget.TextView;
import android.widget.Toast;

public class Details extends Activity implements OnItemClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 TextView tvname,tvdate,tvcompanyname;
 Gallery gv;
 ImageAdapter obj;
 int id=0;
 
 Integer listmarutisuzuki[]={R.drawable.marutisuzuki1,R.drawable.marutisuzuki2,R.drawable.marutisuzuki3};
 Integer listalto[]={R.drawable.alto1,R.drawable.alto2,R.drawable.alto3};
 Integer listhundai[]={R.drawable.hundai1,R.drawable.hundai2,R.drawable.hundai3};
 Integer listoodi[]={R.drawable.oodi1,R.drawable.oodi2,R.drawable.oodi3};
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.details);
 
  tvname=(TextView) findViewById(R.id.textViewname);
  tvdate=(TextView) findViewById(R.id.textViewdate);
  tvcompanyname=(TextView) findViewById(R.id.textViewcompanyname);
  
  gv=(Gallery) findViewById(R.id.gallery1);
  
  Intent myintent=getIntent();
  id=myintent.getIntExtra("id", 0);
  
  if(id==0)
  {
   tvname.setText("maruti suzuki");
   tvdate.setText("1-12-1987");
   tvcompanyname.setText("Maruti");
  }
  if(id==1)
  {
   Toast.makeText(this, id+" clicked", Toast.LENGTH_SHORT).show();
   tvname.setText("maruti alto");
   tvdate.setText("2-01-1988");
   tvcompanyname.setText("Maruti");
  }
  if(id==2)
  {
   tvname.setText("hundai i10");
   tvdate.setText("2-12-1987");
   tvcompanyname.setText("Hundai");
  }
  if(id==3)
  {
   tvname.setText("oodi");
   tvdate.setText("1-10-1993");
   tvcompanyname.setText("Oodi");
  }

  obj=new ImageAdapter(this,id);
  gv.setAdapter(obj);
  gv.setOnItemClickListener(this);
 }
 @Override
 public void onItemClick(AdapterView arg0, View arg1, int pos, long arg3) 
 {
  // TODO Auto-generated method stub
  Intent myintent2=new Intent(this,enlarge.class);
  if(id==0)
   myintent2.putExtra("id", listmarutisuzuki[pos]);
  else if(id==1)
   myintent2.putExtra("id", listalto[pos]);
  else if(id==2)
   myintent2.putExtra("id", listhundai[pos]);
  else if(id==3)
   myintent2.putExtra("id", listoodi[pos]);
  
   
  //myintent2.putExtra("id", arg0.getId());
  startActivity(myintent2);
  //Toast.makeText(this," selected", Toast.LENGTH_SHORT).show();
 }
}
enlarge.java
package ps.pro11;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;

public class enlarge extends Activity 
{
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 ImageView imgview;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.enlarge);
  
  Intent myintent2=getIntent();
  int id=myintent2.getIntExtra("id", 0);
  imgview=(ImageView) findViewById(R.id.imageView1);
  imgview.setImageResource(id);
 }
}

Create an application that will have spinner with list of animation names. On selecting animation name , that animation should affect on the images displayed below.

Pro10Activity.java
package ps.pro10;

import android.app.Activity; 
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ImageView;
import android.widget.Spinner;

public class Pro10Activity extends Activity implements OnItemSelectedListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 Spinner spin;
 ImageView imgmaster;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        spin=(Spinner) findViewById(R.id.spinnereffect);
        imgmaster=(ImageView) findViewById(R.id.imageViewmaster);
        
        spin.setOnItemSelectedListener(this); 
    }

 @Override
 public void onItemSelected(AdapterView arg0, View arg1, int arg2,
   long arg3) {
  // TODO Auto-generated method stub
  Animation anim=AnimationUtils.loadAnimation(this, R.anim.alpha);
  if(spin.getSelectedItem().equals("alpha"))
   anim=AnimationUtils.loadAnimation(this, R.anim.alpha);
  else if(spin.getSelectedItem().equals("Rotate"))
   anim=AnimationUtils.loadAnimation(this, R.anim.rotate);
  else if(spin.getSelectedItem().equals("Scale"))
   anim=AnimationUtils.loadAnimation(this, R.anim.scale);
  else if(spin.getSelectedItem().equals("Translate"))
   anim=AnimationUtils.loadAnimation(this, R.anim.translate);
  
  imgmaster.startAnimation(anim);
 }

 @Override
 public void onNothingSelected(AdapterView arg0) {
  // TODO Auto-generated method stub
  
 }
}

Create an application that will display toast(Message) on specific interval of time.

Pro8Activity.java
package ps.pro8;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.Chronometer.OnChronometerTickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Pro8Activity extends Activity implements OnClickListener, OnChronometerTickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 EditText editsec;
 Button btclick;
 TextView msg;
 Chronometer timer;
 int sec=0,delay=0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        editsec=(EditText) findViewById(R.id.editTextsec);
        btclick=(Button) findViewById(R.id.buttonclick);
        msg=(TextView) findViewById(R.id.textViewmsg);
        timer=(Chronometer) findViewById(R.id.chronometer1);
        
        timer.setVisibility(-1);
        
        btclick.setOnClickListener(this);
        timer.setOnChronometerTickListener(this);
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if(v.getId()==btclick.getId())
  {
   delay=Integer.parseInt(editsec.getText().toString());
   sec=0;
   timer.start();
  }
 }
 @Override
 public void onChronometerTick(Chronometer arg0) {
  // TODO Auto-generated method stub
  
  msg.setText("Text Next Message is [ 0"+ (delay-sec) +" ] sec delay");
  sec++;
  if(sec==delay)
  {
   sec=0;
   Toast.makeText(this, "Heres The Message...", Toast.LENGTH_SHORT).show();
  }
 }
}

Understand Menu option.
a. Create an application that will change color of the screen, based on selected options from the menu.

Pro7Activity.java
package ps.pro7;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AbsoluteLayout;

@SuppressWarnings("deprecation")
public class Pro7Activity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 
 AbsoluteLayout al;
    
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        al=(AbsoluteLayout) findViewById(R.id.alayout);
        al.setOnCreateContextMenuListener(this);
    }
 public void createMenu(Menu menu)
 {
  
  MenuItem m1=menu.add(0,0,0,"RED");
  m1.setAlphabeticShortcut('r');
  m1.setIcon(R.drawable.icon);
  
  MenuItem m2=menu.add(0,1,1,"GREEN");
  m2.setAlphabeticShortcut('g');
  m1.setIcon(R.drawable.icon);
  
  MenuItem m3=menu.add(0,2,2,"BLUE");
  m3.setAlphabeticShortcut('b');
  m1.setIcon(R.drawable.icon);
     
 }
 public void listenMenu(MenuItem item)
 {
  int id=item.getItemId();
     switch(id)
     {
     case 0:
      al.setBackgroundColor(Color.RED);
      break;
     case 1:
      al.setBackgroundColor(Color.GREEN);
      break;
     case 2:
      al.setBackgroundColor(Color.BLUE);
      break;
     }
 }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
     // TODO Auto-generated method stub
     super.onCreateOptionsMenu(menu);
     createMenu(menu);
     return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
     // TODO Auto-generated method stub
     super.onOptionsItemSelected(item);
     listenMenu(item);
     return true;
    }
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
      ContextMenuInfo menuInfo) {
     // TODO Auto-generated method stub
     super.onCreateContextMenu(menu, v, menuInfo);
     createMenu(menu);
    }
    @Override
    public boolean onContextItemSelected(MenuItem item) {
     // TODO Auto-generated method stub
     super.onContextItemSelected(item);
     listenMenu(item);
     return true;
    }
}

Understand resource folders :
a. Create spinner with strings taken from resource folder(res >> value folder).
b. On changing spinner value, change image.

Pro6Activity.java
package ps.pro6;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ImageView;
import android.widget.Spinner;

public class Pro6Activity extends Activity implements OnItemSelectedListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 Spinner spin;
 ImageView img;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        spin=(Spinner) findViewById(R.id.spinnernames);
        img=(ImageView) findViewById(R.id.imageView1);

        spin.setOnItemSelectedListener(this);
    }

 @Override
 public void onItemSelected(AdapterView arg0, View arg1, int arg2,
   long arg3) {
  // TODO Auto-generated method stub
  String name=spin.getSelectedItem().toString();
  if(name.equals("AMI"))
   img.setImageResource(R.drawable.ami);
  else if(name.equals("MEHUL"))
   img.setImageResource(R.drawable.mehul);
  else if(name.equals("PANKAJ"))
   img.setImageResource(R.drawable.pankaj);
  else if(name.equals("JIGNESH"))
   img.setImageResource(R.drawable.jignesh);
  else if(name.equals("VIJAY"))
   img.setImageResource(R.drawable.vijay);
  else if(name.equals("SATISH"))   
   img.setImageResource(R.drawable.satish);

 }
 @Override
 public void onNothingSelected(AdapterView arg0) {
  // TODO Auto-generated method stub
  
 }
}

Create an application that will pass some number to the next screen , and on the next screen that number of items should be display in the list.

Pro5Activity
package ps.pro5;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Pro5Activity extends Activity implements OnClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 EditText editnum;
 Button btshow;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        editnum=(EditText) findViewById(R.id.editTextNumber);
        btshow=(Button) findViewById(R.id.buttonshow);
        
        btshow.setOnClickListener(this);
    
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if(v.getId()==btshow.getId())
  {
   Intent myintent=new Intent(this,listActivity.class);
   myintent.putExtra("num", Integer.parseInt(editnum.getText().toString()));
   this.startActivity(myintent);
  }
 }
}
listActivity.java
package ps.pro5;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class listActivity extends Activity implements  OnItemClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 ListView lv;
 String items[];
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listlayout);
        
        lv=(ListView) findViewById(R.id.listViewItems);
        int num=getIntent().getIntExtra("num", 0);
        items=new String[num];
        for(int i=0;i<num;i++)
        {
         items[i]="item "+(i+1);
        }
        ArrayAdapter<String> arr=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,items);
        lv.setAdapter(arr);
       
        lv.setOnItemClickListener(this);
    }
 @Override
 public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
  // TODO Auto-generated method stub
  Toast.makeText(this,items[pos] + " selected", Toast.LENGTH_SHORT).show();
 }
}

Create and Login application as above . On successful login , open browser with any URL.

Pro4Activity.java
package ps.pro4;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Pro4Activity extends Activity implements OnClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 Button btlogin,btclear;
 EditText editemail,editpass;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        editemail=(EditText) findViewById(R.id.editemail);
        editpass=(EditText) findViewById(R.id.editpass);
        btlogin=(Button) findViewById(R.id.btlogin);
        btclear=(Button) findViewById(R.id.btclear);
        btlogin.setOnClickListener(this);
        btclear.setOnClickListener(this);
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  Button action=(Button) v;
  if(action.getId()==btlogin.getId())
  {
   String email=editemail.getText().toString();
   String pass=editpass.getText().toString();
   
   if(email.equals("pankaj@gmail.com") && pass.equals("pankaj"))
   {
    Intent myintent=new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.gmail.com"));
    this.startActivity(myintent);
   }
   else
   {
    Toast.makeText(this,"Sorry", Toast.LENGTH_SHORT).show();
   }
   
  }
  else if(action.getId()==btclear.getId())
  {
   if(!editemail.getText().toString().equals("") ||  !editpass.getText().toString().equals(""))
   {
    editemail.setText("");
    editpass.setText("");
   }
   else
   {
    Toast.makeText(this,"Already Cleared...", Toast.LENGTH_SHORT).show();
   }
  }
 }
}

Create login application where you will have to validate EmailID(UserName). Till the username and password is not validated , login button should remain disabled.

PRO3Activity.java
package vc.pro3;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class PRO3Activity extends Activity implements OnClickListener, TextWatcher {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 Button btnLogin,btnCancel;
 EditText txtuname,txtpass;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        btnLogin=(Button) findViewById(R.id.btnLogin);
        btnCancel=(Button) findViewById(R.id.btnCancel);
        txtuname=(EditText) findViewById(R.id.txtuname);
        txtpass=(EditText)findViewById(R.id.txtpass);
        
        btnLogin.setOnClickListener(this);
        btnCancel.setOnClickListener(this);
        btnLogin.setEnabled(false);
        txtuname.addTextChangedListener(this);
        txtpass.addTextChangedListener(this);
    }
    
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if(v.getId()==btnLogin.getId())
  {
   if(txtuname.getText().toString().equals(""))
   {
    Toast.makeText(this,"Please Enter Use Name", Toast.LENGTH_SHORT).show();
   }
   else if(txtpass.getText().toString().equals(""))
   {
    Toast.makeText(this,"Please Enter Pass", Toast.LENGTH_SHORT).show();
   }
   else 
   {
     Toast.makeText(this,"Login Success Fully", Toast.LENGTH_SHORT).show();
   }
   
  }
  else if(v.getId() == btnCancel.getId())
  {
   if(txtuname.getText().toString().equals("") && txtpass.getText().toString().equals(""))
   {
    Toast.makeText(this,"Text is Already Empty...",Toast.LENGTH_SHORT).show();
   }
   else
   {
    
    txtuname.setText("");
    txtpass.setText("");
   }
  }
 }
 @Override
 public void afterTextChanged(Editable v) {
  // TODO Auto-generated method stub
  int firstat_rat,lastat_rat,first_dot,last_dot;
  boolean flag_email=true,flag_pass=true,flag=false;
  String email,pass;
   email=txtuname.getText().toString();
   pass=txtpass.getText().toString();
       
  firstat_rat=email.indexOf("@");
  lastat_rat=email.lastIndexOf("@");
  first_dot=email.indexOf(".");
  last_dot=email.lastIndexOf(".");
     
  if(firstat_rat<=0)
  {
   flag_email=false;
  }
  else if(firstat_rat!=lastat_rat )
  {
   flag_email=false;
  }
  else if(lastat_rat==email.length()-1)
  {
   flag_email=false;
  }
  else if(first_dot<= 0)
  {
   flag_email=false;
  }
  else if('.'==email.charAt(lastat_rat-1) ||'.'==email.charAt(lastat_rat+1))
  {
   flag_email=false;
  }
  else if(last_dot==email.length()-1)
  {
   flag_email=false;
  }
  else if(last_dot<lastat_rat)
  {
   flag_email=false;
  }
  else if(first_dot!=last_dot)
  {
   for(int i=first_dot; i<=last_dot; i++)
   {
    if(email.charAt(i)=='.')
    {
     if(flag==true)
     {
      flag_email=false;
      break;
     }
     else
      flag=true;
    }
    else
    {
     flag=false;
    }
   }
  }
  else
  {
   flag_email=true;
  }
  
  if(pass.equals(""))
  {
   flag_pass=false;
  }
  else
  {
   flag_pass=true;
  }
  if(flag_email==true && flag_pass==true )
    btnLogin.setEnabled(true);
  else 
   btnLogin.setEnabled(false);
 }

 @Override
 public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
   int arg3) {
  // TODO Auto-generated method stub
  
 }

 @Override
 public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
  // TODO Auto-generated method stub
  
 }
}

To understand Activity, Intent a. Create sample application with login module.(Check username and password) b. On successful login, go to next screen. And on failing login, alert user using Toast. c. Also pass username to next screen.

Pro2Activity.java
package ps.pro2;

import android.app.Activity;
import android.content.Intent;
import android.view.*;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Pro2Activity extends Activity implements View.OnClickListener 
{
   /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 Button btlogin,btclear;
 EditText editusername,editpassword;
 TextView textmsg;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        editusername=(EditText)findViewById(R.id.username);
        editpassword=(EditText)findViewById(R.id.password);
        btlogin=(Button) findViewById(R.id.btlogin);
        btclear=(Button) findViewById(R.id.btclear);
       
        btlogin.setOnClickListener(this);
        btclear.setOnClickListener(this);
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  Button action=(Button) v;
  String name,pass;
  boolean flagusername=false;
  boolean flagpassword=false;
  name=editusername.getText().toString();
  pass=editpassword.getText().toString();
  if(name.equals(""))
  {
   flagusername=true;
  }
  if(pass.equals(""))
  {
   flagpassword=true;
  }
  if(btlogin.getId()==action.getId())
  {
   if(flagusername==false && flagpassword==false)
   {
    if(pass.equals(name+"@123"))
    {
     Toast.makeText(this,"Login success...", Toast.LENGTH_SHORT).show();
     Intent myintent=new Intent(this,home.class);
     myintent.putExtra("name", name);
     this.startActivity(myintent);
    }
    else
     Toast.makeText(this,"Login faild...", Toast.LENGTH_SHORT).show();
   }
   else
   {
    if(flagusername==true)
     Toast.makeText(this,"Pls Enter Username...", Toast.LENGTH_SHORT).show();
    else if(flagpassword==true)
     Toast.makeText(this,"Pls Enter Password...", Toast.LENGTH_SHORT).show();
   }
  }
  else if(btclear.getId()==action.getId())
  {
   if(flagusername==false || flagpassword==false)
   {
    editusername.setText("");
    editpassword.setText("");
    Toast.makeText(this,"Field Cleared...", Toast.LENGTH_SHORT).show();
   }
   else
   {
    Toast.makeText(this,"Already Cleared...", Toast.LENGTH_SHORT).show();
   }
  }
 }
}
home.java
package ps.pro2;

import android.app.Activity;
import android.content.Intent;
//import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class home extends Activity implements OnClickListener {
   /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 TextView textmsg;
 Button btback;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        
        
        textmsg=(TextView) findViewById(R.id.textmsg);
        btback=(Button) findViewById(R.id.btback);
        
        btback.setOnClickListener(this);
       
        Intent myintent=getIntent(); 
        textmsg.setText("welcome "+ myintent.getStringExtra("name"));
    }
 @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  Intent i=new Intent(this,Pro2Activity.class);
  this.startActivity(i);
 }
}

Create “Hello World” application. That will display “Hello World” in the middle of the screen in the red color with white background.

Pro1Activity.java
package ps.pro1;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class Pro1Activity extends Activity {
   /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 RelativeLayout rl;
 TextView tvmsg;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        rl=(RelativeLayout) findViewById(R.id.rl);
        tvmsg = (TextView) findViewById(R.id.textView1);
        
        rl.setBackgroundColor(Color.WHITE);
        tvmsg.setTextColor(Color.RED);
    }
}

Saturday 6 October 2012

Unix Simple Commands Tutorial

1. DATE COMMAND
   -----------------------------------
date +%<option> date "+%m %y"
m month numeric (output 08)
h momth Character (output Aug)
d The day of the month (output 1 to 31 date)
D The date in the formate(mm/dd/yy)  (output month\day\year)
T The Time in the format hh:mm:yy (output 18:25:37)
y The last two digits of the year
H Hours
M Minute
S Second
Y full year (output 2011)

2. LIST COMMAND
    ---------------------------------
ls -<option>
a All filenames including those beginning with a dot
d Only filenames beginning with a dot.
i Inode number unic identity
l Long listing in ASCII collating sequance
L First text file after folder ascending order
r Sort filename in reverse order(ASCII collating sequence by default)
s Total size of file with file name
t Filenames sorted by last modification time
u Filenames sorted by last accrss time
e Owner read write pamutable
x Multicolumnar output
F Marks executable with  *,directories with / and symbolic links with @
lt Sorts listing by last modification time
lu Sorts by ASCII collating sequence but listing shows last access time
lut As above but sorted by last access time
others
etc Filenames in/etc
-d /etc Only /etc
-ld /etc Listing of /etc
-ls lRa Recursive listing  of all filename in file system

3. WHO COMMAND
        ----------------------------------
who current users name
whoami current pc
who -<option>
H heading
u idle time of pc


4. CAL COMMAND //CALENDER
        ---------------------------------
cal <option>
cal current month calender
cal current month calender
cal 2010 specific year cal.
cal 08-2011 specific month

5. PS COMMAND //VIEWING PROCESSES
        ------------------------------
ps display the process owner
Note := you can use - or not both are same output.
ps -<option>
l Long listing showing memory-related information
u username
u urs Processes of user usr only
a how many users online or Processes of all usera excluding processes not associated with terminal
f Full listing showing the PPID of each process
e or A  All processes including user and system processes
aux Display filename and folder
t Processes running on terminal term(say/dev/console) or term or filename

6. WC COMMAND //WORD COUNT
          -------------------------------
wc Counting Lines, Words and Characters
wc -<option>
l Number of Lines
w Number of words
c Number of characters
l < filename
ls | wc -l folder and file count


7. CAT COMMAND
        ---------------------------------
cat > filename (creat file name)
cat filename (open file)
cat -v Displaying nonprinting Character
cat -n Number of line

8.      UNAME COMMAND
              ----------------------------------------
uname   or unemw -s Display the name of the operating System
uname -r Disply the virson operating system
uname -n The first word of the domain name
a Display all details and You can use the -an,-as and -ar

9.      PWD(present working directory)COMMAND
             -----------
pwd Displys the absolute pathname

10.     MKDIR COMMAND //MAKING DIRECTORIES
               --------------------------------------
mkdir Create New Directory in Specific Drive
mkdir veer data data1 this command will create individual directory
mkdir   veer veer/data veer/data1 this command generate tree as below
      veer
        /\
      /    \
    /        \
 Data      Data1

11.     RMDIR COMMAND //REMOVING DIRECTORIES
                ---------------------------------------
rmdir <file name> Removing file
rmdir veer veer/data veer/data1   Actually this command Remove Child Directories but Parent directory remain as it's
rmdir veer/data  veer/data veer   This command Remove parent and child directory

12.     CD COMMAND //CHANGE DIRECTORIES 
              ------------------------------
cd Display the main directories // home/owner
cd . this represents the current directory
cd .. this represents the parent directory or move one level up
cd ./filename Add the child directories
cd ../.. Move two level up

13.     CP COMMAND //COPY
              ----------- -------------------
cp <Firstfilename Secondfilename> the first is copied to the second
cp -i <Firstfilename Secondfilename> //INTERACTIVE COPY
cp -R <Firstfilename Secondfilename> //RECURVELY TO COPY OR COPY DIRECTORIES STRUCTURES
//overwrite yes / no
14.      RM COMMAND //REMOVE FILE
                -------------------------------
rm * Remove all Files
rm -<option>
i Interactive Deletion //user for confirmtion before each file
r or R Recursive Deletion
r * Behaves partially like rmdir
f Forcfully Remove files
rf * Delete everything in the current directory

15.     MV COMMAND // MOVE FILE
               -------------------------------
mv command have two points
1. It renames file or directory
2. It moves a group of file to file to different directory

mv <files move> to <file> //MOVE
mv <old filename> <new filename> //RENAME

16.    DIFF COMMAND // CONVERTING ONE FILE TO OTHER
         ------------------------------------
diff <first filename> <second filename>

17.    CHMOD COMMAND //CHANGING FILE PERMISSIONS
           -----------------------------------
ls -l <filename> Display permission
chmod <option> <filename>
l file need to be change
u user
o Other
a All(ugo)
+-- Assigns premission
--- Removes permission
=-- Assigns absoulute permission
666 Read and Write permission
r Read permission
w write permission
x Execute permission
644 To assign all pemission tothe owner  read and write permission
To the group  and omly executepermission to other use this
000 All permission are remove
777 Granted all permission
R Recursively
-R 755 Works on hidden files
_R a+x Leaves out hidden files

18.    GREP COMMAND //SEARCHING FOR A PATTERM
              ----------------------------------
grep <argument> <filename> [<second filename>]
grep -<pattern> <filename> .* All line display
grep -<option>
i Ignores case for matching
v Doesn't display line matching expression
n Display line number along with lines
c Display count of numbers of occurrences
l Display list of filenames only
e exp Specifies expression with this option Can use multiple times Also use for
matching expression beginning with a hyphen
x Matches pattern with entire line
f Takes patterns from file one per line it need to second filename
E Treats pattern as an extended regular expression (ERE)
F Matches multiple fixed string

19.    Different Command
              ----------------------------------

grep "[small letter and Capital letter] " <filename>
eg. grep "v[iI]j[aA]y" list
*
eg. grep "v[iI]j*[aA]y" list
grep "^v" list Display Starting character v
grep "^[^a]" list Anywhere "a" than this record should display
grep "a...$" Specifices position "a" this record  should display
ls -l | grep "^d" Shows only directories
grep -E '(vi|a)jay' list
output
vijay
ajay // sanjay can't be display

grep -E '(jamnagar|rajkot)' list

20.    SED COMMAND // STREAM EDITOR
         --------------------
sed '3q' list First three Record display here q = Quit
sed -n '1,2p' list First two line display here p= print
sed -n '$p' list Display last line
sed -n '3,$p' list Don't print lines 3 to end
sed -n '/jamnagar/p' list Display specific place or /jamnagar/,/rajkot/

21.     DELETE USING SED COMMAND
              -------------------------------------------------------------
sed '/jamnagar/d' list
sed 'v/|/:/' list1

22.     HEAD COMMAND 
               ----------------------------------
head -n 3 list First three line display
head -n 5 list | tee list1 list file is empty

23.     TAIL COMMAND
                --------------------------------
tail -n 3 list Last three line display
tail +5 list First four line skeep
tail -c -512 list Copies last 512 bytes from list
tail -c +512 list Copies everything afterskipping 511 byte

24.     CUT COMMAND
          ---------------------
cut -<option>
c <specific character no.> To extract Cut the specific columns
eg. cut -c 2-3 list
d
f
using cut command then copy another file
cut -d \| -f 2.3 slist | tree list1

25.      PASTE COMMAND
                 -----------------------------------
paste <oldfilename> <newfilename>
paste -d "|" <old filenae> <new filename>
paste -s -d "||\n" list
output
vijay |jay |pankaj
jignesh |rahul |amit as it's

26.      SORT COMMAND
                ----------------------------------
sort -<option>
tchar Uses delimiter char to identify fields
k n Sort on nth field
k m,n Start sort on "m"th field and ends sort on "n"th field
k m.n Start sort on "n"th  column of "m"th fiels
u Removes repeated line
n Sorts numerically
r Reverses sort order
f Folder lowercase to equivalent uppercase (case insensitive sort)
m list Merges sorted files in list
c Checks if file is sorted
o flname    Places output in file flname

27.     FIND COMMAND
               --------------------------------
find -name  "*.txt" -print All files extension
find -name '[A-Z]' -print Single quates  will also do
cd; find . -type d -print 2>/dev/null shows the . also Display hidden directories also
find -mtime  -2 -print Display list of file and folder

find -<operation>
find . ! -name "*.txt" -print Select all text file
-inum n Having inode number n
-type x If of type x,x can be f(ordinary file).d (directory) or l(symbolic link)
-type f if an ordinary file
-perm nnn If octal permission match nnn completely
-link n If having n link
-user usname If owned by usname
-group gname If owned by group gname
-size +x[c] If size greater than  blocks (characters if c is also specified)
-mtime -x If modified  in less than x days
-newer flnmae If modified after  flnmae
-mmin -x If modified in less than x minutes (Linux only)
-atime +x If accessed in more than x days
-aminv+x If accessed in more than x minutes (Linux only)
-name flnmae Flname
-iname flname As above but match is case-insensitive(Linux only)
-follow After following a symbolic link
-prune But don't desend directory if matched
-mount But don't look in other file system


28.   PASSWD COMMAND
            --------------- ------------------------
passwd password changing