1. Android Application Development
Android app to display employee details – Group 1 Page 1
Version 2.2 (Froyo)
A Project Report
On
“Android app to display Employee details
For Android Phones”
Assigned by:
Ganesh Kumar
2. Android Application Development
Android app to display employee details – Group 1 Page 2
Self-Declaration
All the below information has been provided to the best of our knowledge as part of the
Application development for the documentation purpose only for the demonstration.
Group – 1 Detail:
Index
S.No Content Information
1 Introductionof Application
2 Dependencies /Limitations
3 Application Design
4 Application Output
5 Output file
3. Android Application Development
Android app to display employee details – Group 1 Page 3
Roles of our Team:
MEMBER: ROLE:
SAIKRISHNA TANGUTURU Project Lead
TINNALURI V N PRASANTH Dev Lead
SHENBAGAMOORTHY A Developer
PRANOB JYOTI KALITA Developer
RAYAPU MOSES Developer
ANURUPA K C Test Lead
KONDALA SUMATHI Tester
DASIKA KRISHNA Tester
ARUNJUNAISELVAM P Tester
SHEIK SANAVULLA Support
4. Android Application Development
Android app to display employee details – Group 1 Page 4
1. Introduction of Application:
This Application displays the employee details of a Particular employee. It will use the following
technique to search the details for the particular employee:-
ď‚· By matching the employee names.
ď‚· After fetching the employee from the list we can use the application to call or text
message(SMS) and Email.
This application will work on 2.2(Froyo) & higher versions.
Step 1 Basic Layout:
In this first step, we define the user interface for searching employees.
Code highlights:
EmployeeList.java: The default Activity of the application. setContentView() is used to set the layout to
main.xml.
main.xml: the layout for the default activity of the application.
5. Android Application Development
Android app to display employee details – Group 1 Page 5
Go To Index
Step: 2 Working with Lists
In this second step, we add a ListView component that will be used (in the following step) to display the
list of employees matching the search criteria. In this step, we just use an ArrayAdapter to display
sample data in the list.
Code highlights:
main.xml: The updated layout with the ListView.
EmployeeList.java: An ArrayAdapter is used to populate the ListView.
6. Android Application Development
Android app to display employee details – Group 1 Page 6
Go To Index
Step 3: Working with a SQLite Database
In this third step, we use a SQLite database to persist the employees. When the user clicks the Search
button, we query the database, and populate the list with the employees matching the search criteria.
Code highlights:
EmployeeList.java:
In onCreate(), we use the DatabaseHelper class to open the database.
In search(), we use a Cursor to query the database. We then use a SimpleCursorAdapter to bind the
ListView to the Cursor using a custom layout (employee_list_item) to display each item in the list.
DatabaseHelper.java: We extend SQLiteOpenHelper to manage the access to our database: If the
database doesn’t yet exist, we create the employee table and populate it with sample data.
employee_list_item.xml: Layout to display each item in the list.
Step 4: Using Intents and passing information between Activities
In this fourth step, we create an Activity to display the details of the employee selected in the list. We
start the EmployeeDetails activity by creating an Intent.
7. Android Application Development
Android app to display employee details – Group 1 Page 7
Go To Index
Code highlights:
EmployeeList.java: in onListItemClick, we create a new Intent for the EmployeeDetails class, add the
employee id to the intent using intent.putExtra(), and start a new Activity.
EmployeeDetails.java: The Employee details activity. We retrieve the id of the employee using
getIntent().getIntExtra(). We then use a Cursor to retrieve the employee details.
employee_details.xml: A simple layout to display the details of an employee.
Go To Index
8. Android Application Development
Android app to display employee details – Group 1 Page 8
Step 5: Calling, Emailing, and Texting an Employee
In this fifth step, we interact with some of the built-in capabilities of our phone. We use Intents to allow
the user to call, email, or text an employee. We reuse the EmployeeDetails Activity to allow the user to
display the details of the manager of the selected employee.
Code highlights:
EmployeeDetails.java:
In onCreate(), we build an array of actions (call, email, sms, view manager) available to the user
depending on the information available for the displayed employee (for example, we only create a “Call
mobile” action if the employee’s mobile phone number is available in the database).
EmployeeActionAdapter is a custom list adapter that binds each action in the actions array to the
action_list_item layout.
In onListItemClick(), we create an Intent corresponding to the action selected by the user, and start a
new activity with that intent.
action_list_item.xml: Layout for each action in the actions list.
employee_details.xml: Updated employee details layout.
9. Android Application Development
Android app to display employee details – Group 1 Page 9
Go To Index
Step 6: Navigating Up and Down the Org Chart
Code highlights:
DirectReports.java: A new Activity to display the direct reports of a specific employee.
direct_reports.xml: The layout for the DirectReports Activity.
EmployeeDetails.java: “View direct reports” is added to the list of actions. When the user selects that
action, a new Intent is created for the DirectReports Activity, and a new Activity is started using that
Intent.
DatabaseHelper.java: Instead of populating the database with hardcoded sample data, the employee
table is now created and populated from an XML file (sql.xml).
sql.xml: The xml file used to create and populate the employee table.
11. Android Application Development
Android app to display employee details – Group 1 Page 11
CODE:
Main.xml
The layout for the default activity of the application.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/searchText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/searchButton"
android:text="Search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ListView
12. Android Application Development
Android app to display employee details – Group 1 Page 12
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
EmployeeList.java:
The default Activity of the application.setContentView() is used to set the layout to main.xml.
In onCreate(), we use the DatabaseHelper class to open the database.
In search(), we use a Cursor to query the database. We then use a SimpleCursorAdapter to bind
the ListView to the Cursor using a custom layout (employee_list_item) to display each item in
the list.
packagesamples.employeedirectory;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class EmployeeList extends ListActivity {
protectedEditTextsearchText;
protectedSQLiteDatabasedb;
protected Cursor cursor;
protectedListAdapter adapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
13. Android Application Development
Android app to display employee details – Group 1 Page 13
setContentView(R.layout.main);
db = (new DatabaseHelper(this)).getWritableDatabase();
searchText = (EditText) findViewById (R.id.searchText);
}
public void search(View view) {
// || is the concatenation operation in SQLite
cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employee WHERE
firstName || ' ' || lastName LIKE ?",
new String[]{"%" + searchText.getText().toString() + "%"});
adapter = new SimpleCursorAdapter(
this,
R.layout.employee_list_item,
cursor,
new String[] {"firstName", "lastName", "title"},
newint[] {R.id.firstName, R.id.lastName, R.id.title});
setListAdapter(adapter);
}
public void onListItemClick(ListView parent, View view, int position, long id) {
Intent intent = new Intent(this, EmployeeDetails.class);
Cursor cursor = (Cursor) adapter.getItem(position);
intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
startActivity(intent);
}
}
14. Android Application Development
Android app to display employee details – Group 1 Page 14
DatabaseHelper.java
We extend SQLiteOpenHelper to manage the access to our database: If the database
doesn’t yet exist, we create the employee table and populate it with sample data.
packagesamples.employeedirectory;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "employee_directory";
publicDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabasedb) {
/*
* Create the employee table and populate it with sample data.
* In step 6, we will move these hardcoded statements to an XML document.
*/
String sql = "CREATE TABLE IF NOT EXISTS employee (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"firstName TEXT, " +
"lastName TEXT, " +
"title TEXT, " +
"officePhone TEXT, " +
"cellPhone TEXT, " +
"email TEXT, " +
"managerId INTEGER)";
db.execSQL(sql);
ContentValues values = new ContentValues();
values.put("firstName", "John");
values.put("lastName", "Smith");
17. Android Application Development
Android app to display employee details – Group 1 Page 17
EmployeeDetails.java
In onCreate(), we build an array of actions (call, email, sms, view manager) available to
the user depending on the information available for the displayed employee (for
example, we only create a “Call mobile” action if the employee’s mobile phone number
is available in the database).
EmployeeActionAdapter is a custom list adapter that binds each action in the actions
array to the action_list_item layout.
In onListItemClick(), we create an Intent corresponding to the action selected by the
user, and start a new activity with that intent.
packagesamples.employeedirectory;
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class EmployeeDetails extends ListActivity {
protectedTextViewemployeeName;
protectedTextViewemployeeTitle;
protectedTextViewofficePhone;
protectedTextViewcellPhone;
protectedTextView email;
protectedintemployeeId;
18. Android Application Development
Android app to display employee details – Group 1 Page 18
protectedintmanagerId;
protected List<EmployeeAction> actions;
protectedEmployeeActionAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.employee_details);
employeeId = getIntent().getIntExtra("EMPLOYEE_ID", 0);
SQLiteDatabasedb = (new DatabaseHelper(this)).getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT emp._id, emp.firstName, emp.lastName,
emp.title, emp.officePhone, emp.cellPhone, emp.email, emp.managerId,
mgr.firstNamemanagerFirstName, mgr.lastNamemanagerLastName FROM employee
emp LEFT OUTER JOIN employee mgr ON emp.managerId = mgr._id WHERE emp._id =
?",
new String[]{""+employeeId});
if (cursor.getCount() == 1)
{
cursor.moveToFirst();
employeeName = (TextView) findViewById(R.id.employeeName);
employeeName.setText(cursor.getString(cursor.getColumnIndex("firstName")) + " " +
cursor.getString(cursor.getColumnIndex("lastName")));
employeeTitle = (TextView) findViewById(R.id.title);
employeeTitle.setText(cursor.getString(cursor.getColumnIndex("title")));
actions = new ArrayList<EmployeeAction>();
String officePhone = cursor.getString(cursor.getColumnIndex("officePhone"));
if (officePhone != null) {
actions.add(new EmployeeAction("Call office", officePhone,
EmployeeAction.ACTION_CALL));
}
19. Android Application Development
Android app to display employee details – Group 1 Page 19
String cellPhone = cursor.getString(cursor.getColumnIndex("cellPhone"));
if (cellPhone != null) {
actions.add(new EmployeeAction("Call mobile", cellPhone,
EmployeeAction.ACTION_CALL));
actions.add(new EmployeeAction("SMS", cellPhone, EmployeeAction.ACTION_SMS));
}
String email = cursor.getString(cursor.getColumnIndex("email"));
if (email != null) {
actions.add(new EmployeeAction("Email", email, EmployeeAction.ACTION_EMAIL));
}
managerId = cursor.getInt(cursor.getColumnIndex("managerId"));
if (managerId>0) {
actions.add(new EmployeeAction("View manager",
cursor.getString(cursor.getColumnIndex("managerFirstName")) + " " +
cursor.getString(cursor.getColumnIndex("managerLastName")),
EmployeeAction.ACTION_VIEW));
}
adapter = new EmployeeActionAdapter();
setListAdapter(adapter);
}
}
public void onListItemClick(ListView parent, View view, int position, long id) {
EmployeeAction action = actions.get(position);
Intent intent;
switch (action.getType()) {
caseEmployeeAction.ACTION_CALL:
Uri callUri = Uri.parse("tel:" + action.getData());
intent = new Intent(Intent.ACTION_CALL, callUri);
startActivity(intent);
20. Android Application Development
Android app to display employee details – Group 1 Page 20
break;
caseEmployeeAction.ACTION_EMAIL:
intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{action.getData()});
startActivity(intent);
break;
caseEmployeeAction.ACTION_SMS:
Uri smsUri = Uri.parse("sms:" + action.getData());
intent = new Intent(Intent.ACTION_VIEW, smsUri);
startActivity(intent);
break;
caseEmployeeAction.ACTION_VIEW:
intent = new Intent(this, EmployeeDetails.class);
intent.putExtra("EMPLOYEE_ID", managerId);
startActivity(intent);
break;
}
}
classEmployeeActionAdapter extends ArrayAdapter<EmployeeAction> {
EmployeeActionAdapter() {
super(EmployeeDetails.this, R.layout.action_list_item, actions);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
EmployeeAction action = actions.get(position);
LayoutInflaterinflater = getLayoutInflater();
View view = inflater.inflate(R.layout.action_list_item, parent, false);
TextView label = (TextView) view.findViewById(R.id.label);
label.setText(action.getLabel());
TextView data = (TextView) view.findViewById(R.id.data);
data.setText(action.getData());
21. Android Application Development
Android app to display employee details – Group 1 Page 21
return view;
}
}
}
DirectReports.java
A new Activity to display the direct reports of a specific employee.
packagesamples.employeedirectory;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class DirectReports extends ListActivity {
protected Cursor cursor=null;
protectedListAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.direct_reports);
SQLiteDatabasedb = (new DatabaseHelper(this)).getWritableDatabase();
22. Android Application Development
Android app to display employee details – Group 1 Page 22
intemployeeId = getIntent().getIntExtra("EMPLOYEE_ID", 0);
Cursor cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM
employee WHERE _id = ?",
new String[]{""+employeeId});
if (cursor.getCount() != 1)
{
return;
}
cursor.moveToFirst();
TextViewemployeeNameText = (TextView) findViewById(R.id.employeeName);
employeeNameText.setText(cursor.getString(cursor.getColumnIndex("firstName")) + " "
+ cursor.getString(cursor.getColumnIndex("lastName")));
TextViewtitleText = (TextView) findViewById(R.id.title);
titleText.setText(cursor.getString(cursor.getColumnIndex("title")));
cursor = db.rawQuery("SELECT _id, firstName, lastName, title, officePhone, cellPhone,
email FROM employee WHERE managerId = ?",
new String[]{""+employeeId});
adapter = new SimpleCursorAdapter(
this,
R.layout.employee_list_item,
cursor,
new String[] {"firstName", "lastName", "title"},
newint[] {R.id.firstName, R.id.lastName, R.id.title});
setListAdapter(adapter);
}
public void onListItemClick(ListView parent, View view, int position, long id) {
Intent intent = new Intent(this, EmployeeDetails.class);
Cursor cursor = (Cursor) adapter.getItem(position);
intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
startActivity(intent);
}
23. Android Application Development
Android app to display employee details – Group 1 Page 23
}
2. Dependencies /Limitations:
This Application will work only on Android based Platforms such as mobile devices. It will not
work on Windows Platforms (which devices are using windows OS such as Windows Phone or
Computers).
24. Android Application Development
Android app to display employee details – Group 1 Page 24
3. Application Design
employee_list_item.xml
Layout to display each item in the list
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="8px">
<TextView
android:id="@+id/firstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/lastName"
android:layout_marginLeft="6px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/firstName"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/firstName"/>
</RelativeLayout>
25. Android Application Development
Android app to display employee details – Group 1 Page 25
action_list_item.xml
Layout for each action in the actions list.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="8px">
<!--
<ImageView
android:id="@+id/icon"
android:layout_width="22px"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
-->
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"/>
<TextView
android:id="@+id/data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16px"/>
</LinearLayout>
27. Android Application Development
Android app to display employee details – Group 1 Page 27
direct_reports.xml
The layout for the DirectReports Activity.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#505050"
android:padding="8px">
<TextView
android:id="@+id/employeeName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"/>
</LinearLayout>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
Go To Index
28. Android Application Development
Android app to display employee details – Group 1 Page 28
sql.xml
The xml file used to create and populate the employee table.
<sql>
<statement>
CREATE TABLE IF NOT EXISTS employee (
_id INTEGER PRIMARY KEY AUTOINCREMENT,
firstName VARCHAR(50),
lastName VARCHAR(50),
title VARCHAR(50),
department VARCHAR(50),
managerId INTEGER,
city VARCHAR(50),
officePhone VARCHAR(30),
cellPhone VARCHAR(30),
email VARCHAR(30),
picture VARCHAR(200))
</statement>
<statement>INSERT INTO employee VALUES(1,'Ryan','Howard','Vice President, North East',
'Management', NULL, 'Scranton','570-999-8888','570-999-
8887','ryan@dundermifflin.com','howard.jpg')</statement>
<statement>INSERT INTO employee VALUES(2,'Michael','Scott','Regional
Manager','Management',1,'Scranton','570-888-9999','570-222-
3333','michael@dundermifflin.com','scott.jpg')</statement>
<statement>INSERT INTO employee VALUES(3,'Dwight','Schrute','Assistant Regional
Manager','Management',2,'Scranton','570-444-4444','570-333-
3333','dwight@dundermifflin.com','schrute.jpg')</statement>
<statement>INSERT INTO employee VALUES(4,'Jim','Halpert','Assistant Regional
Manager','Manage',2,'Scranton','570-222-2121','570-999-
1212','jim@dundermifflin.com','halpert.jpg')</statement>
<statement>INSERT INTO employee
VALUES(5,'Pamela','Beesly','Receptionist','',2,'Scranton','570-999-5555','570-999-
7474','pam@dundermifflin.com','beesly.jpg')</statement>
<statement>INSERT INTO employee VALUES(6,'Angela','Martin','Senior
Accountant','Accounting',2,'Scranton','570-555-9696','570-999-
3232','angela@dundermifflin.com','martin.jpg')</statement>
<statement>INSERT INTO employee
VALUES(7,'Kevin','Malone','Accountant','Accounting',6,'Scranton','570-777-9696','570-111-
2525','kmalone@dundermifflin.com','malone.jpg')</statement>
29. Android Application Development
Android app to display employee details – Group 1 Page 29
<statement>INSERT INTO employee
VALUES(8,'Oscar','Martinez','Accountant','Accounting',6,'Scranton','570-321-9999','570-585-
3333','oscar@dundermifflin.com','martinez.jpg')</statement>
<statement>INSERT INTO employee VALUES(9,'Creed','Bratton','Quality
Assurance','Customer Services',2,'Scranton','570-222-6666','333-
8585','creed@dundermifflin.com','bratton.jpg')</statement>
<statement>INSERT INTO employee VALUES(10,'Andy','Bernard','Sales
Director','Sales',2,'Scranton','570-555-0000','570-546-
9999','andy@dundermifflin.com','bernard.jpg')</statement>
<statement>INSERT INTO employee VALUES(11,'Phyllis','Lapin','Sales
Representative','Sales',10,'Scranton','570-141-3333','570-888-
6666','phyllis@dundermifflin.com','lapin.jpg')</statement>
<statement>INSERT INTO employee VALUES(12,'Stanley','Hudson','Sales
Representative','Sales',10,'Scranton','570-700-6666','570-777-
6666','shudson@dundermifflin.com','hudson.jpg')</statement>
<statement>INSERT INTO employee VALUES(13,'Meredith','Palmer','Supplier
Relations','Customer Services',2,'Scranton','570-555-8888','570-777-
2222','meredith@dundermifflin.com','palmer.jpg')</statement>
<statement>INSERT INTO employee VALUES(14,'Kelly','Kapoor','Customer Service
Rep.','Customer Services',2,'Scranton','570-123-9654','570-125-
3666','kelly@dundermifflin.com','kapoor.jpg')</statement>
</sql>
Go To Index