Subscribe via email

Enter your email address and get Latest Material :

Tag

%temp% Android Application to understand Activity Android Applicaton login button should remain disabled Android Program C Language GTU MCA Syllabus PPT/Notes C full ppt by keval nagaria C++ GTU MCA CPI/CGPA To Percentage Calculator Core JAVA GTU MCA Core Java Create Bootable USB flash Drive Using DISKPART utility Create USB Pen Drive Create an application that will create database with table of User credential. Create an application that will have spinner with list of animation names. On selecting animation name Create an application to call specific entered number by user in the EditText Create an application to make Insert Crimping DBMS GTU MCA Syllabus PPT/Note DISKPART DOS Command to Erase temp file DS GTU MCA Delete and retrieve operation on the database. Erase/Delete Temp file Ethernet FON GTU MCA FON Practical Solution FON Program Fundamental Of Networking GTU MCA PPT GTU Student FInd CPI/CGPA To Percentage Converter Intent Java Chapter Wise Slide Show For GTU MCA Student Sem-3 LAN Cable Online CPI/CGPA Converter/Calculator PL_SQL GTU MCA Syllabus PPT/Note RG45 Connector Read messages from the mobile and display it on the screen. SS(System Software) GTU MCA Understand Menu option. a. Create an application that will change color of the screen Understand resource folders : a. Create spinner with strings taken from resource folder b. On changing spinner value WTAD GTU MCA WTAD Practical Solution Web Technology And Application Development (WTAD) Windwos 7 USB Pen Drive application that will play a media file from the memory car application to send message between two emulators based on selected options from the menu. change image. delete temp file into C drive draw line on the screen as user drag his finger gtu mca android program 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. read file from asset folder and copy it in memory card. take picture using native application that animation should affect on the images displayed below. to pick up any image from the native application gallery and display it on the screen. update

CPI/CGPA To Percentage Converter

Formula for conversation of the equivalent of CPI/CGPA

For GTU student find CPI/CGPA equivalent to the percentage The formula is given below.

Percentage Marks = (CPI/CGPA-0.5) * 10

CPI/CGPA The class should be given by below ratio.

Below 5.5
Pass Class
5.5 & Above
Second Class
6.5 & Above
First Class
7.1 & Above
First Class With Distinction

Award Of Degree
                  For all Courses, where the duration of the course is two years, students may find them Percentage on the basis of the CPI Cumulative Performance Index). If the course Duration is three or more than three they may find the percentage on the basis Of the CGPA (Cumulative Grade Point Average).

                 All the GTU Student calculates CPI/CGPA to percentage in online using the given calculator.

Here I made one Simple CPI/CGPA To Percentage Online Converter/Calculator..

Screen Shot :

Exercise : 18
Create an application to make Insert , update , Delete and retrieve operation on the database.
Screen Shot:







XML :
main.xml :



    
    
        
    
    
    
    
    




search.xml :



    
    
    



    
    
        
    
    
    
    
    


JAVA :
EighteenActivity.java :
package kmn.Eighteen;

import java.util.Locale;
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;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class EighteenActivity extends Activity
{
    /** @author Y@@D * */
	SQLiteDatabase db;	 
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        createDB();
      //do insert
		Button btnInsert=(Button)findViewById(R.id.btnInsert );
        btnInsert.setOnClickListener(new OnClickListener() 
        {
			
			public void onClick(View arg0) 
			{
				 
				insert();
			}
		});
        Button btnClear=(Button)findViewById(R.id.btnClear );
        btnClear.setOnClickListener(new OnClickListener() 
        {			
			public void onClick(View arg0) 
			{				 
				clear();
			}
		});
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
    	super.onCreateOptionsMenu(menu);
    	CreateMenu(menu);
    	return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
    	return MenuChoice(item);
    }
    
    private void CreateMenu(Menu menu)
    {
    	MenuItem mnu1 = menu.add(0, 0, 0, "Insert");
    	{
    		mnu1.setAlphabeticShortcut('i');
    		 
    	}
    	MenuItem mnu2 = menu.add(0, 1, 1, "Search");
    	{
    		mnu2.setAlphabeticShortcut('s');
    		 
    	}
    	MenuItem mnu3 = menu.add(0, 2, 2, "Delete");
    	{
    		mnu3.setAlphabeticShortcut('d');
    		//mnu3.setIcon(R.drawable.icon);
    	}
    	MenuItem mnu4 = menu.add(0, 3, 3, "View");
    	{
    		mnu4.setAlphabeticShortcut('d');
    		//mnu3.setIcon(R.drawable.icon);
    	}
     }
    private boolean MenuChoice(MenuItem item)
    {
    	Intent intent=new Intent();
    	switch (item.getItemId()) 
    	{
    		case 0:
    			insert();
    			return true;
    		case 1:
    			 intent.setClass(EighteenActivity.this, Search.class);
				startActivity(intent);
				return true;
    		case 2:
    	//		intent.setClass(E18Activity.this, SelectRecord.class);
				startActivity(intent);		
    			return true;

    		case 3:
    			intent.setClass(EighteenActivity.this, ViewRecord.class);
    			startActivity(intent);		
    	    	return true;

    	}
    	return false;
    }
    public void createDB()
	{		 
		db=openOrCreateDatabase("Student.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
		db.setLocale(Locale.getDefault());
		db.setLockingEnabled(true);
		db.setVersion(1);
		String sql="create table if not exists Stud(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)";
		db.execSQL(sql);
	}
	public void insert()
	{		 
		 EditText txtName=(EditText)findViewById(R.id.txtName);
		 EditText txtAge=(EditText)findViewById(R.id.txtAge);
		 if(txtName.getText().toString().equals(""))
		 {
			 Toast.makeText(EighteenActivity.this, "Enter Name.", Toast.LENGTH_SHORT).show();
	     }
		 else if (txtAge.getText().toString().equals(""))
		 {
			 Toast.makeText(EighteenActivity.this, "Enter Age.", Toast.LENGTH_SHORT).show();
		 }
		 else
		 {
		
			 String sql="insert into Stud(name,age) values('"+ txtName.getText().toString() +"',"+txtAge.getText().toString()+")";
			 db.execSQL(sql);
			 clear();
			 Toast.makeText(EighteenActivity.this, "Record Successfully Inserted.", Toast.LENGTH_SHORT).show();
		 }	     
	}
	public void clear()
	{
		EditText txtName=(EditText)findViewById(R.id.txtName);
		 EditText txtAge=(EditText)findViewById(R.id.txtAge);
		txtName.setText("");
		txtAge.setText("");
	 	
		txtName.clearFocus();
		txtAge.clearFocus();
		txtName.requestFocus();
		
	
	}
	@Override
    public void onDestroy()
	{
		super.onDestroy();
		db.close();
	}
}
Search.java :
package kmn.Eighteen;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
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.RelativeLayout;
import android.widget.Toast;
/** @author Y@@D * */
public class Search extends Activity 
{
	SQLiteDatabase db;
	EditText txtSearch;
	EditText txtName;
	EditText txtAge;
	Button btnEdit;
	Button btnDelete;
	RelativeLayout rlRecord;
    RelativeLayout rlSearch;
    String recID="0";
	@Override
    public void onCreate(Bundle savedInstanceState) 
	{
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.search);
        
         db=openOrCreateDatabase("Student.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
        
          
     	txtName = (EditText)findViewById(R.id.txtName);
     	txtAge = (EditText)findViewById(R.id.txtAge);
        txtSearch = (EditText)findViewById(R.id.txtSearch);
        btnEdit=(Button)findViewById(R.id.btnEdit);
        btnDelete=(Button)findViewById(R.id.btnDelete);
        
        txtSearch.requestFocus();
        txtName.setEnabled(false);
        txtAge.setEnabled(false);
        btnEdit.setEnabled(false);
        btnDelete.setEnabled(false);
        
        Button btnSearch=(Button)findViewById(R.id.btnSearch);
        btnSearch.setOnClickListener(new OnClickListener() 
        {
			public void onClick(View arg0) {
 				if (txtSearch.getText().toString().equals(""))
				 {
					 Toast.makeText(Search.this, "Enter value.", Toast.LENGTH_SHORT).show();
				 }
				 else
				 {
					 searchRecord();
				 }
			}
		});
        //---------------Edit/update---------------------------------
        final Button btnEdit=(Button)findViewById(R.id.btnEdit);
        btnEdit.setOnClickListener(new OnClickListener() 
        {
			public void onClick(View arg0) 
			{
				 
 				if (btnEdit.getText().toString().equals("Edit"))
				 {
 					 btnEdit.setText("Update");
 					 txtName.setEnabled(true);
 			         txtAge.setEnabled(true);
 			         
 			         txtName.requestFocus();
 			        
 			        btnDelete.setEnabled(false);
 			       
				 }
				 else
				 {
					 txtName.setEnabled(false);
 			         txtAge.setEnabled(false);
 			        
 			        btnDelete.setEnabled(true);
 			       
					 btnEdit.setText("Edit");
					 String sql="update Stud set name='"+txtName.getText().toString()+"', age="+txtAge.getText().toString()+" where id="+recID;
				     db.execSQL(sql);
				     Toast.makeText(Search.this, "  Record Updated Successfully" , Toast.LENGTH_LONG).show();
				 }
			}
		});
        //------------------------Delete ---------------------------
        
        btnDelete.setOnClickListener(new OnClickListener() 
        {
			
			public void onClick(View arg0) 
			{
				// TODO Auto-generated method stub
				AlertDialog.Builder alertbox = new AlertDialog.Builder(arg0.getContext());
				alertbox.setIcon(android.R.drawable.ic_dialog_alert);
				alertbox.setTitle("Confirm");				
				alertbox.setMessage("Are You Sure? You want to delete this record");
				alertbox.setPositiveButton("Delete", new DialogInterface.OnClickListener() 
				{
				 	public void onClick(DialogInterface arg0, int arg1) 
				 	{
						// TODO Auto-generated method stub
				 		String sql="Delete from Stud where id="+recID;
					    db.execSQL(sql);
						Toast.makeText(getApplicationContext(), "Record Deleted", Toast.LENGTH_LONG).show();
						//clear old search result 
						txtSearch.setText("");
						txtName.setText("");
						txtAge.setText("");
						txtSearch.requestFocus();
				 	}
				 });
		    	alertbox.setNegativeButton("  Cancel  ", new DialogInterface.OnClickListener() 
		    	{
			 		public void onClick(DialogInterface arg0, int arg1) 
					{
						// TODO Auto-generated method stub
						 
					}
				});
		    	alertbox.show();
		    }	
		});
    }
	public void searchRecord()
	{
		try
        {
        	txtSearch = (EditText)findViewById(R.id.txtSearch);
        	txtName = (EditText)findViewById(R.id.txtName);
        	txtAge = (EditText)findViewById(R.id.txtAge);
        	Cursor c=db.rawQuery("select id,name,age from Stud where id="+ txtSearch.getText().toString(), null);
       	    if(c.getCount()>0)
            {
            	 c.moveToNext();
               	 recID= c.getString(0);
            	 txtName.setText( c.getString(1));
                 txtAge.setText(c.getString(2));
          	     btnEdit.setEnabled(true);
                 btnDelete.setEnabled(true);
            }
            else
            {
            	Toast.makeText(this, "No Record Found" , Toast.LENGTH_LONG).show();
            }
        }
        catch(Exception e)
        {
        	Toast.makeText(this, ""+e, Toast.LENGTH_LONG).show();
        }
	} 
	public void onDestroy()
	{
		super.onDestroy();
		db.close();
	}
}
ViewRecord.java :
package kmn.Eighteen;
/** @author Y@@D **/
import java.util.ArrayList;

import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Toast;
 public class ViewRecord extends ListActivity 
 {
	SQLiteDatabase db;
	@Override
    public void onCreate(Bundle savedInstanceState) 
	{
        super.onCreate(savedInstanceState);
        try
        {
        	db=openOrCreateDatabase("Student.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);        	 
        	Cursor c=db.rawQuery("select id,name,age from Stud", null);
       	    ArrayList list  = new ArrayList();
        	 
            int count=c.getCount();
                        
            if(c.getCount()>0)
            {
               	while(c.moveToNext())
            	{
            	  list.add(c.getString(0)+" , "+c.getString(1)+" , "+c.getString(2));
               	}               	
            	c.close();
            	Toast.makeText(this,"Total Records: "+count, Toast.LENGTH_LONG).show();
            	ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1, list);
            	getListView().setAdapter(adapter);
            }
            else
            {
            	Toast.makeText(this, "No Record Found" , Toast.LENGTH_LONG).show();
            }
        }
        catch(Exception e)
        {
        	Toast.makeText(this, ""+e, Toast.LENGTH_LONG).show();
        }
    }
	public void onDestroy()
	{
		super.onDestroy();
		db.close();
	}
}
 

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

Screen Shot:

XML :
main.xml :



    
    
    



JAVA :

SeventeenActivity.java :
package kmn.Seventeen;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class SeventeenActivity extends Activity
{
	/** @author Y@@D */

	MediaPlayer player=null;
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button start=(Button)findViewById(R.id.button1);
        Button stop=(Button)findViewById(R.id.button2);
        getSystemService(Context.AUDIO_SERVICE);
        start.setOnClickListener(new View.OnClickListener() {
       				
			public void onClick(View arg0) 
			{
			
				try
				{
					player=null;
					player=new MediaPlayer();				
					String audioFilePath="/sdcard/braincandy.mp3";
					player.setDataSource(audioFilePath);
					player.prepare();
					player.start();
				}
				catch(Exception e)
				{
					Toast.makeText(SeventeenActivity.this,""+e,Toast.LENGTH_LONG).show();
					
				}
			}
		});
        stop.setOnClickListener(new View.OnClickListener() 
        {
			public void onClick(View arg0) 
        	{
        		player.stop();
			}
		});
    }
}
~>step to add a mp3 file to sdcard
1)goto the ddms
2)click on push button
3)and select the given mp3 file.

Enjoy.................


Exercise : 16

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

XML :
s1.xml :





JAVA :
SixteenActivity.java :
package kmn.Sixteen;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

public class SixteenActivity extends Activity 
{
	/**  @author Y@@D */

	FileOutputStream fos ;
    
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.s1);           
     
        try 
		{
			String destPath = "/sdcard/kmn.txt";
			File f = new File(destPath);
			if (!f.exists()) 
			{
				CopyDB( getBaseContext().getAssets().open("file.txt"),new FileOutputStream(destPath));
			}
			Intent i = new Intent(SixteenActivity.this,screen1.class);
    		startActivity(i);
		}
		catch (Exception e) 
		{
			Toast.makeText(SixteenActivity.this, " "+e.toString(), Toast.LENGTH_LONG).show();
		}
	}
    public void CopyDB(InputStream inputStream,OutputStream outputStream)throws IOException 
    {
		//---copy 1K bytes at a time---
		byte[] buffer = new byte[1024];
		int length;
		while ((length = inputStream.read(buffer)) > 0) 
		{
			outputStream.write(buffer, 0, length);
		}
		inputStream.close();
		outputStream.close();
    }
}
screen1.java :

package kmn.Sixteen;

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

public class screen1 extends Activity
{
	/**  @author Y@@D */

	public void onCreate(Bundle b)
	{
		super.onCreate(b);
		setContentView(R.layout.s1);		
		try 
		{
			File fileDir = Environment.getExternalStorageDirectory();
        	File directory = new File(fileDir.getAbsolutePath());
        	File file = new File(directory , "kmn.txt");
        	FileInputStream fis = new FileInputStream(file);
			String str = null;
			StringBuffer sbuffer = new StringBuffer();
			DataInputStream dataio = new DataInputStream(fis);
			while((str = dataio.readLine()) != null)
			{
				sbuffer.append(str + "\n");
			}
			TextView txt=(TextView)findViewById(R.id.showTxt);
			txt.setText(sbuffer);
		}
		catch (Exception e) 
		{
			Toast.makeText(this, " "+e.toString(), Toast.LENGTH_LONG).show();
		}
	}
}

Exercise : 15
Create an application that will create database with table of User credential.
Screen Shot:



XML :
main.xml :




JAVA :

FifteenActivity.java :
apackage kmn.Fifteen;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class FifteenActivity extends Activity 
{
	/** @author Y@@D */
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
 
		SQLiteDatabase myDB= null;
		String TableName = "myTable";
 
		String Data="";
 
		/* Create a Database. */
		try 
		{
			myDB = this.openOrCreateDatabase("DatabaseName", MODE_PRIVATE, null);
 
			/* Create a Table in the Database. */
			myDB.execSQL("CREATE TABLE IF NOT EXISTS " + TableName + " (Field1 VARCHAR, Field2 INT(3));");
			/* Insert data to a Table*/
			myDB.execSQL("INSERT INTO " + TableName + " (Field1, Field2)" + " VALUES ('Y@@D', 22);"); 
			/*retrieve data from database */
			Cursor c = myDB.rawQuery("SELECT * FROM " + TableName , null);
 
			int Column1 = c.getColumnIndex("Field1");
			int Column2 = c.getColumnIndex("Field2");

			// Check if our result was valid.
			c.moveToFirst();
			if (c != null) 
			{
				// Loop through all Results
				do 
				{
				     String Name = c.getString(Column1);
				     int Age = c.getInt(Column2);
				     Data =Data +Name+"/"+Age+"\n";
				}while(c.moveToNext());
			}
			TextView tv = new TextView(this);
			tv.setBackgroundColor(Color.BLUE);
			tv.setTextColor(Color.WHITE);
			tv.setText(Data);
			setContentView(tv);
		}
		catch(Exception e) 
		{
			Log.e("Error", "Error", e);
		} 
		finally 
		{
			if (myDB != null)
				myDB.close();
		}
	}
}
DropTb.java :
package kmn.Fifteen;

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

public class DropTb extends Activity 
{
	
	/** @author Y@@D */
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
	
		SQLiteDatabase myDB= null;
		String TableName = "myTable";
	
		/**
		* Create a Database.
		* */
		try 
		{
			myDB = this.openOrCreateDatabase("DatabaseName", MODE_PRIVATE, null);
			myDB.execSQL("DROP TABLE IF EXISTS "+TableName+";");

		}
		catch(Exception e) 
		{
			Log.e("Error", "Error", e);
		}
		finally 
		{
			if (myDB != null)
				myDB.close();
		}
	}
}

Exercise : 14
Create an application To call specific entered number by the user in the EditText
Screen Shot:




XML :
main.xml :


    
        
            
            
        
    
    


JAVA :
FourteenActivity.java : 
package kmn.Fourteen;

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

public class FourteenActivity extends Activity 
{
    /** @author Y@@D */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button call = (Button)findViewById(R.id.btncall);
        call.setOnClickListener(new View.OnClickListener() 
        {
        	public void onClick(View v) 
        	{
        		EditText txt = (EditText)findViewById(R.id.txtnumber);
        		Uri uri=Uri.parse("tel:"+txt.getText().toString());
				Intent intent=new Intent(Intent.ACTION_CALL, uri);
				startActivity(intent);
        	}
        });
    }
}

Exercise : 13
Read messages from the mobile and display it on the screen.
Screen Shot:



XML :
main.xml :
    


JAVA :
ThirteenActivity.java :
package kmn.Thirteen;
import android.app.Activity;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

public class ThirteenActivity extends Activity 
{
 /**  @author Y@@D  */
 public void onCreate(Bundle savedInstanceState) 
 {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       TextView view = new TextView(this);
       Uri uriSMS = Uri.parse("content://sms/inbox");
       Cursor c = getContentResolver().query(uriSMS, null, null, null,null);
       String sms = "";
       while (c.moveToNext())
       {
           sms += "From :" + c.getString(2) + " : " + c.getString(11)+"\n";         
       }
       view.setText(sms);
       view.setBackgroundColor(Color.BLUE);
       view.setTextColor(Color.WHITE);
       setContentView(view);
 }
}

Exercise : 12

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


XML :
main.xml :

    


JAVA :
TwelveActivity.java
package kmn.Twelve;
import java.util.ArrayList;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class TwelveActivity extends Activity 
{
    /** @author Y@@D */
 private ArrayList list;
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        int j=0;
        Cursor c=getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null,null,null);
        list= new ArrayList();
        while(c.moveToNext())
        {
         int nameindex=c.getColumnIndex(PhoneLookup.DISPLAY_NAME);
         String name=c.getString(nameindex);
         list.add(name);
         Log.d("Contacts:",name);   
        }
        ListView l=(ListView)findViewById(R.id.listView1);
        ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_list_item_1,list);
        l.setAdapter(aa);
    }
}

Exercise : 11
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.
Screen Shot:


XML :
main.xml :

    

main1.xml :


   
  
  	
  	
  	
  	
  	
  	
  	
  

JAVA :
ElevenActivity.java :
package kmn.Eleven;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class ElevenActivity extends Activity implements OnItemClickListener
{
    /** @author Y@@D */
    ListView lv;
	@Override
    public void onCreate(Bundle savedInstanceState) 
	{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        lv=(ListView) findViewById(R.id.lv);
        lv.setClickable(true);
        lv.setOnItemClickListener(this);
    }

	public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) 
	{	
		try
		{
			Integer itn=Integer.valueOf(arg2);
			String ext=itn.toString();
			Intent i = new Intent(this,CarInfo.class);
			i.putExtra("CarPos", ext);
			startActivity(i);
		}
		catch(Exception e)
		{
			Toast.makeText(this, e.getMessage()+"    OnItemClick", Toast.LENGTH_LONG).show();
		}
	}
}
CarInfo.java :
package kmn.Eleven;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;

public class CarInfo extends Activity 
{
	/** @author Y@@D */
	TextView tv;
	private Gallery gallery;
	@Override 
	public void onCreate(Bundle savedInstanceState) 
	 {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.main1);
	       
	        tv=(TextView) findViewById(R.id.tv);
	        Intent i=this.getIntent();
	        String str =i.getStringExtra("CarPos");	        
	        gallery = (Gallery) findViewById(R.id.examplegallery);
	        gallery.setAdapter(new AddImgAdp(this,str));
	        if(str.equals("0"))
	        {
	        	tv.setText("Name:Maruti Suzuki 800"+"\n"+"Launched Date:1/3/1987"+"\n"+"Company Name:Maruti Suzuki"+"\nColors Available:\nWhite\nBlue\nRed\nLight Yellow");
	        }
	        else if(str.equals("1"))
	        {
	        	tv.setText("Name:Hyundai Accent Executive"+"\n"+"Launched Date:15/10/2010"+"\n"+"Company Name:Hyundai"+"\nColors Available:\nGray\nOcean Blue\nMidnight Black\nMaganta Blue");
	        }
	        else if(str.equals("2"))
	        {
	        	tv.setText("Name:Chevrolet Beat"+"\n"+"Launched Date:11/11/2011"+"\n"+"Company Name:Chevrolet"+"\nColors Available:\nMidnight Black\nAmazon Green\nRoyal Gold\nSport Red");
	        }
	        else
	        {	        	
	        	tv.setText("No car available");
	        }	        
	 }
}
class AddImgAdp extends BaseAdapter
{
	int GalItemBg;
	private Context cont;
	String positionLast;
	private Integer[] Imgidb = {R.drawable.b1, R.drawable.b2, R.drawable.b3, R.drawable.b4};
	private Integer[] Imgidh = {R.drawable.h1, R.drawable.h2, R.drawable.h3, R.drawable.h4};
	private Integer[] Imgidm = {R.drawable.m1, R.drawable.m2, R.drawable.m3, R.drawable.m4};

	public AddImgAdp(Context c,String pos) 
	{
	cont = c;	
	positionLast=pos;
	TypedArray typArray = c.obtainStyledAttributes(R.styleable.GalleryTheme);
	GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
	
	typArray.recycle();
	}

	public int getCount()
	{
	if(positionLast.equals("0"))
	{
		return Imgidm.length;
	}
	else if(positionLast.equals("1"))
	{
		return Imgidh.length;
	}
	else if(positionLast.equals("2"))
	{
		return Imgidb.length;
	}
	else
	{
		return Imgidm.length;
	}
	}

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

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

	public View getView(int position, View convertView, ViewGroup parent)
	{
	ImageView imgView = new ImageView(cont);
	if(positionLast.equals("0"))
	{
		imgView.setImageResource(Imgidm[position]);	
	}
	else if(positionLast.equals("1"))
	{
		imgView.setImageResource(Imgidh[position]);
	}
	else if(positionLast.equals("2"))
	{
		imgView.setImageResource(Imgidb[position]);
	}
	else
	{
		imgView.setImageResource(Imgidm[position]);
	}	
	// Fixing width & height for image to display
	imgView.setLayoutParams(new Gallery.LayoutParams(200, 200));
	imgView.setScaleType(ImageView.ScaleType.FIT_XY);
	imgView.setBackgroundResource(GalItemBg);
	return imgView;
	}
}

Exercise : 10
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.
Screen Shot:



XML :
main.xml :

    
        
        
    

~> in this problem we make “anim” folder to res.  Directory and create an xml file like following:
alpha.xml :

	

rotate.xml :

    

scale.xml :

	

spin.xml :

    

translate.xml :

	

JAVA :
TenActivity.java 
package kmn.Ten;

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 TenActivity extends Activity implements OnItemSelectedListener
{
    /** @author Y@@D */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Spinner s = (Spinner)findViewById(R.id.spinner1);
        s.setOnItemSelectedListener(this);
    }

	public void onItemSelected(AdapterView arg0, View arg1, int arg2,
			long arg3)
	{
		ImageView i = (ImageView)findViewById(R.id.imageView1);
		if(arg3==1)
		{
			Animation a = AnimationUtils.loadAnimation(this, R.anim.alpha);
			i.startAnimation(a);
		}
		if(arg3==2)
		{
			Animation a = AnimationUtils.loadAnimation(this, R.anim.rotate);
			i.startAnimation(a);
		}
		if(arg3==3)
		{
			Animation a = AnimationUtils.loadAnimation(this, R.anim.scale);
			i.startAnimation(a);
		}
		if(arg3==4)
		{
			Animation a = AnimationUtils.loadAnimation(this, R.anim.spin);
			i.startAnimation(a);
		}
		if(arg3==5)
		{
			Animation a = AnimationUtils.loadAnimation(this, R.anim.translate);
			i.startAnimation(a);
		}
	}

	public void onNothingSelected(AdapterView arg0) 
	{
	
	}
}

Exercise : 9
Create a background application that will open activity on specific time.

Screen Shot:


XML :
main.xml :

    
        
        
        
    

JAVA :
MyService.java
package kmn.Nine;

import kmn.servicedemo.R;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class MyService extends Service
{
	/** @author Y@@D */
	private static final String TAG = "MyService";
	MediaPlayer player;

	public IBinder onBind(Intent intent) 
	{
		return null;
	}
	
	public void onCreate()
	{
		Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
		Log.d(TAG, "onCreate");
		
		player = MediaPlayer.create(this, R.raw.braincandy);
		player.setLooping(false); // Set looping
	}

	public void onDestroy() 
	{
		Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
		Log.d(TAG, "onDestroy");
		player.stop();
	}
	
	public void onStart(Intent intent, int startid) 
	{
		Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
		Log.d(TAG, "onStart");
		player.start();
	}
}
Nine.java :
package kmn.Nine;

import kmn.servicedemo.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Nine extends Activity implements OnClickListener
{
    /** @author Y@@D */
    private static final String TAG = "ServicesDemo";
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button start = (Button)findViewById(R.id.button1);
        Button stop = (Button)findViewById(R.id.button2);
        start.setOnClickListener(this);
        stop.setOnClickListener(this);
    }

	public void onClick(View v)
	{
		if(v.getId()==R.id.button1)
		{
			Log.d(TAG, "onClick: starting srvice");
			startService(new Intent(this, MyService.class));
			//break;
		}
		if(v.getId()==R.id.button2)
		{
			Log.d(TAG, "onClick: stopping srvice");
			stopService(new Intent(this, MyService.class));
			//break;
		}
	}
}

Exercise : 8
Create an application that will display toast(Message) on specific interval of time.
Screen Shot:



XML :
main.xml :

    
    
        
    

JAVA : Chronometer.java :
package kmn.Chronometer;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Chronometer;
import android.widget.Chronometer.OnChronometerTickListener;
import android.widget.EditText;
import android.widget.Toast;

public class ChronometerActivity extends Activity 
{
    /** @author Y@@D */
    int i=0;
    int Duration=10;
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Chronometer chn = (Chronometer)findViewById(R.id.chronometer1);
        chn.start();
        chn.setOnChronometerTickListener(new OnChronometerTickListener() 
        {	
			public void onChronometerTick(Chronometer arg0) 
			{
				EditText txt = (EditText)findViewById(R.id.editText1);
				txt.setText("Message Will Be Display After ["+(Duration-(i+1))+"] Seconds");
				i++;
				if(i>=Duration)
				{
					Toast.makeText(ChronometerActivity.this, "Message"+(i/10), 10000).show();
					Duration+=10;
				}
			}
		});
    } 
}

Exercise : 7

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


XML :
main.xml :


    

JAVA :
SeventhActivity.java :

package kmn.Seventh;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RelativeLayout;

public class SeventhActivity extends Activity 
{
    /** @author Y@@D */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    public boolean onCreateOptionsMenu(Menu menu) 
    {
     super.onCreateOptionsMenu(menu);
     CreateMenu(menu);
     return true;
    }
    public boolean onOptionsItemSelected(MenuItem item)
    {
     return MenuChoice(item);
    }
    private void CreateMenu(Menu menu)
    {
     MenuItem mnu1 = menu.add(0, 0, 0, "Red");
     {
      mnu1.setAlphabeticShortcut('r');
      mnu1.setIcon(R.drawable.icon);
     }
     MenuItem mnu2 = menu.add(0, 1, 0, "Green");
     {
      mnu2.setAlphabeticShortcut('g');
      mnu2.setIcon(R.drawable.icon);
     }
     MenuItem mnu3 = menu.add(0, 2, 0, "White");
     {
         mnu3.setAlphabeticShortcut('w');
         mnu3.setIcon(R.drawable.icon);
        }
    }
    private boolean MenuChoice(MenuItem item)
    {
     RelativeLayout l= (RelativeLayout) findViewById(R.id.relativeLayout1);
     
     switch (item.getItemId())
     {
      case 0:
       l.setBackgroundColor(Color.RED);
       return true;
      case 1:
       l.setBackgroundColor(Color.GREEN);
       return true;
      case 2:
       l.setBackgroundColor(Color.WHITE);
       return true;
     } 
  return false;
    }
}

Exercise : 6

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


    
        
        
    


JAVA :
SixActivity.java :

package kmn.Six;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class SixActivity extends Activity implements OnItemSelectedListener 
{
    /** @author Y@@D */
	
	Integer[] imageIDs = 
	{
		R.drawable.keval1,
		R.drawable.keval2,
		R.drawable.keval3,
		R.drawable.keval4,
		R.drawable.keval5
	};
						   
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Spinner s = (Spinner)findViewById(R.id.spinner1);
        s.setOnItemSelectedListener(this);
    }
	public void onItemSelected(AdapterView arg0, View arg1, int arg2,
			long arg3) 
	{
		Toast.makeText(this, "Selected Item is = "+ arg0.getSelectedItem().toString(),	Toast.LENGTH_SHORT).show();
		ImageView i = (ImageView)findViewById(R.id.imageView1);
		i.setImageResource(imageIDs[arg2]);
	}
	public void onNothingSelected(AdapterView arg0) 
	{
		
	}
}

Exercise : 5
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.
Screen Shot:


XML :
main.xml :

    
        
        
            
        
        
    



main1.xml :


    
    


JAVA :
FifthActivity.java :

package kmn.Fifth;

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 FifthActivity extends Activity implements OnClickListener 
{
    /** @author Y@@D */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button b = (Button)findViewById(R.id.btnnext);
        b.setOnClickListener(this);
    }
    public void onClick(View v)
    {
    	Intent i = new Intent(this,S2.class);
    	EditText item = (EditText)findViewById(R.id.txtitem);
    	i.putExtra("item", item.getText().toString());
    	startActivity(i);
    }
}
s2.java :

package kmn.Fifth; import java.util.ArrayList; import android.app.ListActivity; import android.os.Bundle; import android.widget.ArrayAdapter; public class S2 extends ListActivity { /** @author Y@@D */ ArrayList arr=new ArrayList(); ArrayAdapter a; int i=0; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main1); a = new ArrayAdapter(this,android.R.layout.simple_list_item_1 ,arr); setListAdapter(a); for(i=1; i<= Integer.parseInt(getIntent().getStringExtra("item")); i++) { arr.add("Item : "+i); } //Toast.makeText(this, "Welcome", Toast.LENGTH_LONG).show(); } }

Exercise : 4
Create and Login application as above . On successful login , open browser with any URL.
Screen Shot:


XML :
main.xml :


    
        
        
            
        
        
        
        
    


JAVA :
FourthActivity.java :
package kmn.Fourth;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
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;

public class FourthActivity extends Activity implements OnClickListener,TextWatcher
{
    /** @author Y@@D */
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        EditText username = (EditText)findViewById(R.id.txtusername);
        EditText password = (EditText)findViewById(R.id.txtpassword);
        username.addTextChangedListener(this);
        password.addTextChangedListener(this);
        Button login = (Button)findViewById(R.id.btnlogin);
        login.setOnClickListener(this);
    }
    public void onClick(View v)
    {
     Intent i= new Intent("android.intent.action.VIEW");
  i.setData(Uri.parse("http://www.kevalnagaria.blogspot.com"));
  startActivity(i);
    }
    public void afterTextChanged(Editable s)
    {
     EditText e = (EditText)findViewById(R.id.txtusername);
     EditText p = (EditText)findViewById(R.id.txtpassword);
     Button b = (Button)findViewById(R.id.btnlogin);
     if(e.getText().toString().equals("keval") && p.getText().toString().equals("nagaria"))  
     {
      b.setEnabled(true);
     }
     else
     {
      b.setEnabled(false);
     }
    }
 public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
   int arg3) {
  // TODO Auto-generated method stub
  
 }
 public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
  // TODO Auto-generated method stub
  
 }
}


FON GTU MCA Syllabus PPT/Note

     ((Download))

WTAD GTU MCA Syllabus PPT/Note

     ((Download))

Related Posts Plugin for WordPress, Blogger...