SlideShare a Scribd company logo
1 of 20
EmployeeList.java
package samples.employeedirectory;
import android.app.Activity;
import android.os.Bundle;
public class EmployeeList extends Activity {
/** Called when theactivity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
main.xml r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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>
main.xml r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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"
19
20
21
22
23
24
25
26
27
28
29
30
31
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
EmployeeList.java r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package samples.employeedirectory;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
public class EmployeeList extends Activity {
protected String[] employees = {"ChristopheCoenraets", "John Smith"};
/** Called when theactivity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, employees);
ListView employeeList = (ListView) findViewById(R.id.list);
employeeList.setAdapter(adapter);
}
}
EmployeeList.java r14
1
2
3
4
5
6
7
8
9
10
11
12
13
package samples.employeedirectory;
import android.app.Activity;
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 Activity {
protected EditText searchText;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
protected SQLiteDatabase db;
protected Cursor cursor;
protected ListAdapter adapter;
protected ListView employeeList;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
db = (new DatabaseHelper(this)).getWritableDatabase();
searchText = (EditText) findViewById (R.id.searchText);
employeeList = (ListView) findViewById (R.id.list);
}
public void search(View view) {
// || is theconcatenation operation in SQLite
cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employeeWHERE firstName || ' '
|| lastName LIKE ?",
new String[]{"%" + searchText.getText().toString() + "%"});
adapter = new SimpleCursorAdapter(
this,
R.layout.employee_list_item,
cursor,
new String[] {"firstName", "lastName", "title"},
new int[] {R.id.firstName, R.id.lastName, R.id.title});
employeeList.setAdapter(adapter);
}
}
DatabaseHelper.java r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package samples.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 staticfinal String DATABASE_NAME = "employee_directory";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
/*
* Create the employee table and populateit with sample data.
* In step 6, we will move thesehardcoded statements to an XMLdocument.
*/
String sql = "CREATE TABLEIF NOT EXISTS employee (" +
"_id INTEGER PRIMARYKEY AUTOINCREMENT, " +
"firstName TEXT, " +
"lastName TEXT, " +
"title TEXT, " +
"officePhone TEXT, " +
"cellPhone TEXT, " +
"email TEXT, " +
"managerId INTEGER)";
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
db.execSQL(sql);
ContentValues values = new ContentValues();
values.put("firstName", "John");
values.put("lastName", "Smith");
values.put("title", "CEO");
values.put("officePhone", "617-219-2001");
values.put("cellPhone", "617-456-7890");
values.put("email", "jsmith@email.com");
db.insert("employee", "lastName", values);
values.put("firstName", "Robert");
values.put("lastName", "Jackson");
values.put("title", "VP Engineering");
values.put("officePhone", "617-219-3333");
values.put("cellPhone", "781-444-2222");
values.put("email", "rjackson@email.com");
values.put("managerId", "1");
db.insert("employee", "lastName", values);
values.put("firstName", "Marie");
values.put("lastName", "Potter");
values.put("title", "VP Sales");
values.put("officePhone", "617-219-2002");
values.put("cellPhone", "987-654-3210");
values.put("email", "mpotter@email.com");
values.put("managerId", "1");
db.insert("employee", "lastName", values);
values.put("firstName", "Lisa");
values.put("lastName", "Jordan");
values.put("title", "VP Marketing");
values.put("officePhone", "617-219-2003");
values.put("cellPhone", "987-654-7777");
values.put("email", "ljordan@email.com");
values.put("managerId", "2");
db.insert("employee", "lastName", values);
values.put("firstName", "Christophe");
values.put("lastName", "Coenraets");
values.put("title", "Evangelist");
values.put("officePhone", "617-219-0000");
values.put("cellPhone", "617-666-7777");
values.put("email", "ccoenrae@adobe.com");
values.put("managerId", "2");
db.insert("employee", "lastName", values);
values.put("firstName", "Paula");
values.put("lastName", "Brown");
values.put("title", "Director Engineering");
values.put("officePhone", "617-612-0987");
values.put("cellPhone", "617-123-9876");
values.put("email", "pbrown@email.com");
values.put("managerId", "2");
db.insert("employee", "lastName", values);
values.put("firstName", "Mark");
values.put("lastName", "Taylor");
values.put("title", "Lead Architect");
values.put("officePhone", "617-444-1122");
values.put("cellPhone", "617-555-3344");
values.put("email", "mtaylor@email.com");
values.put("managerId", "2");
db.insert("employee", "lastName", values);
}
@Override
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLEIF EXISTS employees");
onCreate(db);
}
}
Hide details
Change log
r8 by ccoenraets on Sep 8, 2010 Diff
[No log message]
Go
to: ...yeedirectory/DatabaseHelper.java
Project members, sign in to write a code review
Older revisions
All revisions of this file
File info
Size: 3469 bytes, 105 lines
View raw file
File properties
svn:mime-type
text/plain
Terms - Privacy - Project Hosting Help
employee_list_item.xml r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns: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"
16
17
18
19
20
21
22
23
24
25
26
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>
EmployeeList.java r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package samples.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 {
protected EditText searchText;
protected SQLiteDatabase db;
protected Cursor cursor;
protected ListAdapter adapter;
/** Called when theactivity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
db = (new DatabaseHelper(this)).getWritableDatabase();
searchText = (EditText) findViewById (R.id.searchText);
}
public void search(View view) {
// || is theconcatenation operation in SQLite
cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employeeWHERE firstName || ' '
|| lastName LIKE ?",
new String[]{"%" + searchText.getText().toString() + "%"});
adapter = new SimpleCursorAdapter(
this,
R.layout.employee_list_item,
cursor,
new String[] {"firstName", "lastName", "title"},
new int[] {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);
}
49
50
}
Hide details
Change log
r10 by ccoenraets on Sep 8, 2010 Diff
[No log message]
Go
to:
...loyeedirectory/EmployeeList.java
Project members, sign in to write a code review
Older revisions
All revisions of this file
File info
Size: 1739 bytes, 50 lines
View raw file
File properties
svn:mime-type
text/plain
Terms - Privacy - Project Hosting Help
EmployeeDetails.java r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package samples.employeedirectory;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TextView;
public class EmployeeDetails extends Activity {
protected TextView employeeName;
protected TextView employeeTitle;
protected TextView officePhone;
protected TextView cellPhone;
protected TextView email;
protected int employeeId;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.employee_details);
employeeId = getIntent().getIntExtra("EMPLOYEE_ID", 0);
SQLiteDatabase db = (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.firstName managerFirstName, mgr.lastName managerLastName
FROM employeeemp 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")) + " " +
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
cursor.getString(cursor.getColumnIndex("lastName")));
employeeTitle= (TextView) findViewById(R.id.title);
employeeTitle.setText(cursor.getString(cursor.getColumnIndex("title")));
officePhone = (TextView) findViewById(R.id.officePhone);
officePhone.setText(cursor.getString(cursor.getColumnIndex("officePhone")));
cellPhone = (TextView) findViewById(R.id.cellPhone);
cellPhone.setText(cursor.getString(cursor.getColumnIndex("cellPhone")));
email = (TextView) findViewById(R.id.email);
email.setText(cursor.getString(cursor.getColumnIndex("email")));
}
}
}
Hide details
Change log
r10 by ccoenraets on Sep 8, 2010 Diff
[No log message]
Go
to: ...eedirectory/EmployeeDetails.java
Project members, sign in to write a code review
Older revisions
All revisions of this file
File info
Size: 2005 bytes, 51 lines
View raw file
File properties
svn:mime-type
text/plain
employee_details.xml r14
1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/employeeName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/title"
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/officePhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/cellPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Hide details
Change log
r10 by ccoenraets on Sep 8, 2010 Diff
[No log message]
Go
to: .../res/layout/employee_details.xml
Project members, sign in to write a code review
Older revisions
All revisions of this file
File info
Size: 898 bytes, 28 lines
View raw file
File properties
svn:mime-type
text/plain
EmployeeDetails.java r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package samples.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;
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
public class EmployeeDetails extends ListActivity {
protected TextView employeeName;
protected TextView employeeTitle;
protected TextView officePhone;
protected TextView cellPhone;
protected TextView email;
protected int employeeId;
protected int managerId;
protected List<EmployeeAction> actions;
protected EmployeeActionAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.employee_details);
employeeId = getIntent().getIntExtra("EMPLOYEE_ID", 0);
SQLiteDatabase db = (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.firstName managerFirstName, mgr.lastName managerLastName
FROM employeeemp 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));
}
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);
}
}
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
public void onListItemClick(ListView parent, View view, int position, long id) {
EmployeeAction action = actions.get(position);
Intent intent;
switch (action.getType()) {
case EmployeeAction.ACTION_CALL:
Uri callUri = Uri.parse("tel:" + action.getData());
intent = new Intent(Intent.ACTION_CALL, callUri);
startActivity(intent);
break;
case EmployeeAction.ACTION_EMAIL:
intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{action.getData()});
startActivity(intent);
break;
case EmployeeAction.ACTION_SMS:
Uri smsUri = Uri.parse("sms:" + action.getData());
intent = new Intent(Intent.ACTION_VIEW, smsUri);
startActivity(intent);
break;
case EmployeeAction.ACTION_VIEW:
intent = new Intent(this, EmployeeDetails.class);
intent.putExtra("EMPLOYEE_ID", managerId);
startActivity(intent);
break;
}
}
class EmployeeActionAdapter 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);
LayoutInflater inflater = 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());
return view;
}
}
}
Hide details
Change log
r12 by ccoenraets on Sep 8, 2010 Diff
[No log message]
G
o
to: ...eedirectory/EmployeeDetails.java
Project members, sign in to write a code review
Older revisions
All revisions of this file
File info
Size: 5082 bytes, 136 lines
View raw file
File properties
svn:mime-type
text/plain
action_list_item.xml r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android: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>
/ employee_details.xml r14
1
2
3
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/employeeName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
DirectReports.java r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package samples.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;
protected ListAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.direct_reports);
SQLiteDatabase db = (new DatabaseHelper(this)).getWritableDatabase();
int employeeId = getIntent().getIntExtra("EMPLOYEE_ID", 0);
Cursor cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employeeWHERE _id = ?",
new String[]{""+employeeId});
if (cursor.getCount() != 1)
{
return;
}
cursor.moveToFirst();
TextView employeeNameText = (TextView) findViewById(R.id.employeeName);
employeeNameText.setText(cursor.getString(cursor.getColumnIndex("firstName")) + " " +
cursor.getString(cursor.getColumnIndex("lastName")));
TextView titleText = (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,
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
new String[] {"firstName", "lastName", "title"},
new int[] {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);
}
}
Hide details
Change log
r14 by ccoenraets on Sep 8, 2010 Diff
[No log message]
G
o
to
:
...oyeedirectory/DirectReports.java
Project members, sign in to write a code review
Older revisions
All revisions of this file
File info
Size: 2164 bytes, 63 lines
View raw file
File properties
svn:mime-type
text/plain
Terms - Privacy - Project Hosting Help
direct_reports.xml r14
1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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>
EmployeeDetails.java r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package samples.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 {
protected TextView employeeNameText;
protected TextView titleText;
protected List<EmployeeAction> actions;
protected EmployeeActionAdapter adapter;
protected int employeeId;
protected int managerId;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.employee_details);
employeeId = getIntent().getIntExtra("EMPLOYEE_ID", 0);
SQLiteDatabase db = (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.firstName managerFirstName, mgr.lastName managerLastName
FROM employeeemp LEFT OUTER JOIN employee mgr ON emp.managerId = mgr._id WHERE emp._id = ?",
new String[]{""+employeeId});
if (cursor.getCount() == 1)
{
cursor.moveToFirst();
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
employeeNameText = (TextView) findViewById(R.id.employeeName);
employeeNameText.setText(cursor.getString(cursor.getColumnIndex("firstName")) + " " +
cursor.getString(cursor.getColumnIndex("lastName")));
titleText = (TextView) findViewById(R.id.title);
titleText.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));
}
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));
}
cursor = db.rawQuery("SELECT count(*) FROM employeeWHERE managerId = ?",
new String[]{""+employeeId});
cursor.moveToFirst();
int count = cursor.getInt(0);
if (count>0) {
actions.add(new EmployeeAction("View direct reports", "(" + count + ")",
EmployeeAction.ACTION_REPORTS));
}
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()) {
case EmployeeAction.ACTION_CALL:
Uri callUri = Uri.parse("tel:" + action.getData());
intent = new Intent(Intent.ACTION_CALL, callUri);
startActivity(intent);
break;
case EmployeeAction.ACTION_EMAIL:
intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{action.getData()});
startActivity(intent);
break;
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
case EmployeeAction.ACTION_SMS:
Uri smsUri = Uri.parse("sms:" + action.getData());
intent = new Intent(Intent.ACTION_VIEW, smsUri);
startActivity(intent);
break;
case EmployeeAction.ACTION_REPORTS:
intent = new Intent(this, DirectReports.class);
intent.putExtra("EMPLOYEE_ID", employeeId);
startActivity(intent);
break;
case EmployeeAction.ACTION_VIEW:
intent = new Intent(this, EmployeeDetails.class);
intent.putExtra("EMPLOYEE_ID", managerId);
startActivity(intent);
break;
}
}
class EmployeeActionAdapter 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);
LayoutInflater inflater = 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());
return view;
}
}
}
Hide details
Change log
r14 by ccoenraets on Sep 8, 2010 Diff
[No log message]
G
o
to
:
...eedirectory/EmployeeDetails.java
Project members, sign in to write a code review
Older revisions
All revisions of this file
File info
Size: 5534 bytes, 145 lines
View raw file
File properties
svn:mime-type
text/plain
Terms - Privacy - Project Hosting Help
DatabaseHelper.java r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package samples.employeedirectory;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;
public class DatabaseHelper extends SQLiteOpenHelper {
public staticfinal String DATABASE_NAME = "employee_directory2";
protected Context context;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
this.context = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
String s;
try {
Toast.makeText(context, "1", 2000).show();
InputStreamin = context.getResources().openRawResource(R.raw.sql);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in, null);
NodeList statements = doc.getElementsByTagName("statement");
for (int i=0; i<statements.getLength(); i++) {
s = statements.item(i).getChildNodes().item(0).getNodeValue();
db.execSQL(s);
}
} catch (Throwable t) {
Toast.makeText(context, t.toString(), 50000).show();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLEIF EXISTS employees");
onCreate(db);
}
}
45
46
47
48
49
50
Hide details
Change log
r14 by ccoenraets on Sep 8, 2010 Diff
[No log message]
G
o
to
:
...yeedirectory/DatabaseHelper.java
Project members, sign in to write a code review
Older revisions
All revisions of this file
File info
Size: 1467 bytes, 50 lines
View raw file
File properties
svn:mime-type
text/plain
Terms - Privacy - Project Hosting Help
sql.xml r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<sql>
<statement>
CREATE TABLEIF NOT EXISTS employee (
_id INTEGER PRIMARYKEY 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),
pictureVARCHAR(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 employeeVALUES(2,'Michael','Scott','Regional
Manager','Management',1,'Scranton','570-888-9999','570-222-
3333','michael@dundermifflin.com','scott.jpg')</statement>
<statement>INSERT INTO employeeVALUES(3,'Dwight','Schrute','Assistant Regional
Manager','Management',2,'Scranton','570-444-4444','570-333-
3333','dwight@dundermifflin.com','schrute.jpg')</statement>
<statement>INSERT INTO employeeVALUES(4,'Jim','Halpert','Assistant Regional
25
26
27
28
29
30
Manager','Manage',2,'Scranton','570-222-2121','570-999-1212','jim@dundermifflin.com','halpert.jpg')</statement>
<statement>INSERT INTO employeeVALUES(5,'Pamela','Beesly','Receptionist','',2,'Scranton','570-999-
5555','570-999-7474','pam@dundermifflin.com','beesly.jpg')</statement>
<statement>INSERT INTO employeeVALUES(6,'Angela','Martin','Senior
Accountant','Accounting',2,'Scranton','570-555-9696','570-999-
3232','angela@dundermifflin.com','martin.jpg')</statement>
<statement>INSERT INTO employeeVALUES(7,'Kevin','Malone','Accountant','Accounting',6,'Scranton','570-777-
9696','570-111-2525','kmalone@dundermifflin.com','malone.jpg')</statement>
<statement>INSERT INTO employeeVALUES(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 employeeVALUES(10,'Andy','Bernard','Sales Director','Sales',2,'Scranton','570-555-
0000','570-546-9999','andy@dundermifflin.com','bernard.jpg')</statement>
<statement>INSERT INTO employeeVALUES(11,'Phyllis','Lapin','Sales Representative','Sales',10,'Scranton','570-
141-3333','570-888-6666','phyllis@dundermifflin.com','lapin.jpg')</statement>
<statement>INSERT INTO employeeVALUES(12,'Stanley','Hudson','Sales
Representative','Sales',10,'Scranton','570-700-6666','570-777-
6666','shudson@dundermifflin.com','hudson.jpg')</statement>
<statement>INSERT INTO employeeVALUES(13,'Meredith','Palmer','Supplier Relations','Customer
Services',2,'Scranton','570-555-8888','570-777-2222','meredith@dundermifflin.com','palmer.jpg')</statement>
<statement>INSERT INTO employeeVALUES(14,'Kelly','Kapoor','Customer Service Rep.','Customer
Services',2,'Scranton','570-123-9654','570-125-3666','kelly@dundermifflin.com','kapoor.jpg')</statement>
</sql>

More Related Content

What's hot

2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...PHP Conference Argentina
 
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)Agile Lietuva
 
My Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API'sMy Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API'sRoel Hartman
 
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
Praktik Pengembangan Konten E-Learning HTML5 SederhanaPraktik Pengembangan Konten E-Learning HTML5 Sederhana
Praktik Pengembangan Konten E-Learning HTML5 SederhanaMuhammad Yusuf
 
The Ring programming language version 1.9 book - Part 36 of 210
The Ring programming language version 1.9 book - Part 36 of 210The Ring programming language version 1.9 book - Part 36 of 210
The Ring programming language version 1.9 book - Part 36 of 210Mahmoud Samir Fayed
 
Tweaking the interactive grid
Tweaking the interactive gridTweaking the interactive grid
Tweaking the interactive gridRoel Hartman
 
The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210Mahmoud Samir Fayed
 
Google Play Services Rock
Google Play Services RockGoogle Play Services Rock
Google Play Services RockPeter Friese
 
Angular.js Primer in Aalto University
Angular.js Primer in Aalto UniversityAngular.js Primer in Aalto University
Angular.js Primer in Aalto UniversitySC5.io
 

What's hot (14)

2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
 
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
 
My Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API'sMy Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API's
 
Android For All The Things
Android For All The ThingsAndroid For All The Things
Android For All The Things
 
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
Praktik Pengembangan Konten E-Learning HTML5 SederhanaPraktik Pengembangan Konten E-Learning HTML5 Sederhana
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
 
Nativescript angular
Nativescript angularNativescript angular
Nativescript angular
 
The Ring programming language version 1.9 book - Part 36 of 210
The Ring programming language version 1.9 book - Part 36 of 210The Ring programming language version 1.9 book - Part 36 of 210
The Ring programming language version 1.9 book - Part 36 of 210
 
#ajn3.lt.marblejenka
#ajn3.lt.marblejenka#ajn3.lt.marblejenka
#ajn3.lt.marblejenka
 
Tweaking the interactive grid
Tweaking the interactive gridTweaking the interactive grid
Tweaking the interactive grid
 
The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210
 
Baitap tkw
Baitap tkwBaitap tkw
Baitap tkw
 
Google Play Services Rock
Google Play Services RockGoogle Play Services Rock
Google Play Services Rock
 
Angular mix chrisnoring
Angular mix chrisnoringAngular mix chrisnoring
Angular mix chrisnoring
 
Angular.js Primer in Aalto University
Angular.js Primer in Aalto UniversityAngular.js Primer in Aalto University
Angular.js Primer in Aalto University
 

Viewers also liked (13)

Cdn
CdnCdn
Cdn
 
Create link button in radgrid dynamically without item template tags in aspx ...
Create link button in radgrid dynamically without item template tags in aspx ...Create link button in radgrid dynamically without item template tags in aspx ...
Create link button in radgrid dynamically without item template tags in aspx ...
 
Radgrid
RadgridRadgrid
Radgrid
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
sample tutorial
 sample tutorial  sample tutorial
sample tutorial
 
00016335
0001633500016335
00016335
 
Schemas and soap_prt
Schemas and soap_prtSchemas and soap_prt
Schemas and soap_prt
 
Jaxrs 1.0-final-spec
Jaxrs 1.0-final-specJaxrs 1.0-final-spec
Jaxrs 1.0-final-spec
 
Walkthrough asp.net
Walkthrough asp.netWalkthrough asp.net
Walkthrough asp.net
 
Cdn tutorial adcom
Cdn tutorial adcomCdn tutorial adcom
Cdn tutorial adcom
 
Tutorial 1
Tutorial 1Tutorial 1
Tutorial 1
 
Dynamically define rad grid using code behind in c# grid - ui for asp
Dynamically define rad grid using code behind in c#   grid - ui for aspDynamically define rad grid using code behind in c#   grid - ui for asp
Dynamically define rad grid using code behind in c# grid - ui for asp
 
Sq lite manager
Sq lite managerSq lite manager
Sq lite manager
 

Similar to Android examples

CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensionserwanl
 
20110525[Taipei GTUG] titanium mobile簡介
20110525[Taipei GTUG] titanium mobile簡介20110525[Taipei GTUG] titanium mobile簡介
20110525[Taipei GTUG] titanium mobile簡介Justin Lee
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web developmentJohannes Brodwall
 
Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersSaeid Zebardast
 
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseHeiko Behrens
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)Oswald Campesato
 
A mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutesA mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutesJames Pearce
 
SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!Sébastien Levert
 
Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Mario Jorge Pereira
 
Windows 8 Training Fundamental - 1
Windows 8 Training Fundamental - 1Windows 8 Training Fundamental - 1
Windows 8 Training Fundamental - 1Kevin Octavian
 
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j queryTraining in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j queryprav068
 

Similar to Android examples (20)

CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
 
greenDAO
greenDAOgreenDAO
greenDAO
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 
20110525[Taipei GTUG] titanium mobile簡介
20110525[Taipei GTUG] titanium mobile簡介20110525[Taipei GTUG] titanium mobile簡介
20110525[Taipei GTUG] titanium mobile簡介
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web development
 
Mobile Web 5.0
Mobile Web 5.0Mobile Web 5.0
Mobile Web 5.0
 
mobl
moblmobl
mobl
 
Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginners
 
Java and xml
Java and xmlJava and xml
Java and xml
 
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
 
Tutorial basicapp
Tutorial basicappTutorial basicapp
Tutorial basicapp
 
A mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutesA mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutes
 
SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!
 
Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
 
Windows 8 Training Fundamental - 1
Windows 8 Training Fundamental - 1Windows 8 Training Fundamental - 1
Windows 8 Training Fundamental - 1
 
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j queryTraining in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
 

Recently uploaded

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 

Recently uploaded (20)

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 

Android examples

  • 1. EmployeeList.java package samples.employeedirectory; import android.app.Activity; import android.os.Bundle; public class EmployeeList extends Activity { /** Called when theactivity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } main.xml r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <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> main.xml r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <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"
  • 2. 19 20 21 22 23 24 25 26 27 28 29 30 31 android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </LinearLayout> EmployeeList.java r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 package samples.employeedirectory; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.ListView; public class EmployeeList extends Activity { protected String[] employees = {"ChristopheCoenraets", "John Smith"}; /** Called when theactivity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, employees); ListView employeeList = (ListView) findViewById(R.id.list); employeeList.setAdapter(adapter); } } EmployeeList.java r14 1 2 3 4 5 6 7 8 9 10 11 12 13 package samples.employeedirectory; import android.app.Activity; 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 Activity { protected EditText searchText;
  • 3. 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 protected SQLiteDatabase db; protected Cursor cursor; protected ListAdapter adapter; protected ListView employeeList; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); db = (new DatabaseHelper(this)).getWritableDatabase(); searchText = (EditText) findViewById (R.id.searchText); employeeList = (ListView) findViewById (R.id.list); } public void search(View view) { // || is theconcatenation operation in SQLite cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employeeWHERE firstName || ' ' || lastName LIKE ?", new String[]{"%" + searchText.getText().toString() + "%"}); adapter = new SimpleCursorAdapter( this, R.layout.employee_list_item, cursor, new String[] {"firstName", "lastName", "title"}, new int[] {R.id.firstName, R.id.lastName, R.id.title}); employeeList.setAdapter(adapter); } } DatabaseHelper.java r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 package samples.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 staticfinal String DATABASE_NAME = "employee_directory"; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, 1); } @Override public void onCreate(SQLiteDatabase db) { /* * Create the employee table and populateit with sample data. * In step 6, we will move thesehardcoded statements to an XMLdocument. */ String sql = "CREATE TABLEIF NOT EXISTS employee (" + "_id INTEGER PRIMARYKEY AUTOINCREMENT, " + "firstName TEXT, " + "lastName TEXT, " + "title TEXT, " + "officePhone TEXT, " + "cellPhone TEXT, " + "email TEXT, " + "managerId INTEGER)";
  • 4. 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 db.execSQL(sql); ContentValues values = new ContentValues(); values.put("firstName", "John"); values.put("lastName", "Smith"); values.put("title", "CEO"); values.put("officePhone", "617-219-2001"); values.put("cellPhone", "617-456-7890"); values.put("email", "jsmith@email.com"); db.insert("employee", "lastName", values); values.put("firstName", "Robert"); values.put("lastName", "Jackson"); values.put("title", "VP Engineering"); values.put("officePhone", "617-219-3333"); values.put("cellPhone", "781-444-2222"); values.put("email", "rjackson@email.com"); values.put("managerId", "1"); db.insert("employee", "lastName", values); values.put("firstName", "Marie"); values.put("lastName", "Potter"); values.put("title", "VP Sales"); values.put("officePhone", "617-219-2002"); values.put("cellPhone", "987-654-3210"); values.put("email", "mpotter@email.com"); values.put("managerId", "1"); db.insert("employee", "lastName", values); values.put("firstName", "Lisa"); values.put("lastName", "Jordan"); values.put("title", "VP Marketing"); values.put("officePhone", "617-219-2003"); values.put("cellPhone", "987-654-7777"); values.put("email", "ljordan@email.com"); values.put("managerId", "2"); db.insert("employee", "lastName", values); values.put("firstName", "Christophe"); values.put("lastName", "Coenraets"); values.put("title", "Evangelist"); values.put("officePhone", "617-219-0000"); values.put("cellPhone", "617-666-7777"); values.put("email", "ccoenrae@adobe.com"); values.put("managerId", "2"); db.insert("employee", "lastName", values); values.put("firstName", "Paula"); values.put("lastName", "Brown"); values.put("title", "Director Engineering"); values.put("officePhone", "617-612-0987"); values.put("cellPhone", "617-123-9876"); values.put("email", "pbrown@email.com"); values.put("managerId", "2"); db.insert("employee", "lastName", values); values.put("firstName", "Mark"); values.put("lastName", "Taylor"); values.put("title", "Lead Architect"); values.put("officePhone", "617-444-1122"); values.put("cellPhone", "617-555-3344"); values.put("email", "mtaylor@email.com"); values.put("managerId", "2"); db.insert("employee", "lastName", values); } @Override
  • 5. 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLEIF EXISTS employees"); onCreate(db); } } Hide details Change log r8 by ccoenraets on Sep 8, 2010 Diff [No log message] Go to: ...yeedirectory/DatabaseHelper.java Project members, sign in to write a code review Older revisions All revisions of this file File info Size: 3469 bytes, 105 lines View raw file File properties svn:mime-type text/plain Terms - Privacy - Project Hosting Help employee_list_item.xml r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns: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"
  • 6. 16 17 18 19 20 21 22 23 24 25 26 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> EmployeeList.java r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 package samples.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 { protected EditText searchText; protected SQLiteDatabase db; protected Cursor cursor; protected ListAdapter adapter; /** Called when theactivity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); db = (new DatabaseHelper(this)).getWritableDatabase(); searchText = (EditText) findViewById (R.id.searchText); } public void search(View view) { // || is theconcatenation operation in SQLite cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employeeWHERE firstName || ' ' || lastName LIKE ?", new String[]{"%" + searchText.getText().toString() + "%"}); adapter = new SimpleCursorAdapter( this, R.layout.employee_list_item, cursor, new String[] {"firstName", "lastName", "title"}, new int[] {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); }
  • 7. 49 50 } Hide details Change log r10 by ccoenraets on Sep 8, 2010 Diff [No log message] Go to: ...loyeedirectory/EmployeeList.java Project members, sign in to write a code review Older revisions All revisions of this file File info Size: 1739 bytes, 50 lines View raw file File properties svn:mime-type text/plain Terms - Privacy - Project Hosting Help EmployeeDetails.java r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 package samples.employeedirectory; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.widget.TextView; public class EmployeeDetails extends Activity { protected TextView employeeName; protected TextView employeeTitle; protected TextView officePhone; protected TextView cellPhone; protected TextView email; protected int employeeId; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.employee_details); employeeId = getIntent().getIntExtra("EMPLOYEE_ID", 0); SQLiteDatabase db = (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.firstName managerFirstName, mgr.lastName managerLastName FROM employeeemp 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")) + " " +
  • 8. 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 cursor.getString(cursor.getColumnIndex("lastName"))); employeeTitle= (TextView) findViewById(R.id.title); employeeTitle.setText(cursor.getString(cursor.getColumnIndex("title"))); officePhone = (TextView) findViewById(R.id.officePhone); officePhone.setText(cursor.getString(cursor.getColumnIndex("officePhone"))); cellPhone = (TextView) findViewById(R.id.cellPhone); cellPhone.setText(cursor.getString(cursor.getColumnIndex("cellPhone"))); email = (TextView) findViewById(R.id.email); email.setText(cursor.getString(cursor.getColumnIndex("email"))); } } } Hide details Change log r10 by ccoenraets on Sep 8, 2010 Diff [No log message] Go to: ...eedirectory/EmployeeDetails.java Project members, sign in to write a code review Older revisions All revisions of this file File info Size: 2005 bytes, 51 lines View raw file File properties svn:mime-type text/plain employee_details.xml r14 1 2 3 4 5 6 7 8 9 10 11 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/employeeName" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/title"
  • 9. 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/officePhone" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/cellPhone" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/email" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> Hide details Change log r10 by ccoenraets on Sep 8, 2010 Diff [No log message] Go to: .../res/layout/employee_details.xml Project members, sign in to write a code review Older revisions All revisions of this file File info Size: 898 bytes, 28 lines View raw file File properties svn:mime-type text/plain EmployeeDetails.java r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 package samples.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;
  • 10. 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 public class EmployeeDetails extends ListActivity { protected TextView employeeName; protected TextView employeeTitle; protected TextView officePhone; protected TextView cellPhone; protected TextView email; protected int employeeId; protected int managerId; protected List<EmployeeAction> actions; protected EmployeeActionAdapter adapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.employee_details); employeeId = getIntent().getIntExtra("EMPLOYEE_ID", 0); SQLiteDatabase db = (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.firstName managerFirstName, mgr.lastName managerLastName FROM employeeemp 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)); } 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); } }
  • 11. 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 public void onListItemClick(ListView parent, View view, int position, long id) { EmployeeAction action = actions.get(position); Intent intent; switch (action.getType()) { case EmployeeAction.ACTION_CALL: Uri callUri = Uri.parse("tel:" + action.getData()); intent = new Intent(Intent.ACTION_CALL, callUri); startActivity(intent); break; case EmployeeAction.ACTION_EMAIL: intent = new Intent(Intent.ACTION_SEND); intent.setType("plain/text"); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{action.getData()}); startActivity(intent); break; case EmployeeAction.ACTION_SMS: Uri smsUri = Uri.parse("sms:" + action.getData()); intent = new Intent(Intent.ACTION_VIEW, smsUri); startActivity(intent); break; case EmployeeAction.ACTION_VIEW: intent = new Intent(this, EmployeeDetails.class); intent.putExtra("EMPLOYEE_ID", managerId); startActivity(intent); break; } } class EmployeeActionAdapter 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); LayoutInflater inflater = 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()); return view; } } }
  • 12. Hide details Change log r12 by ccoenraets on Sep 8, 2010 Diff [No log message] G o to: ...eedirectory/EmployeeDetails.java Project members, sign in to write a code review Older revisions All revisions of this file File info Size: 5082 bytes, 136 lines View raw file File properties svn:mime-type text/plain action_list_item.xml r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android: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> / employee_details.xml r14 1 2 3 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
  • 13. 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/employeeName" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </LinearLayout> DirectReports.java r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 package samples.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; protected ListAdapter adapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.direct_reports); SQLiteDatabase db = (new DatabaseHelper(this)).getWritableDatabase(); int employeeId = getIntent().getIntExtra("EMPLOYEE_ID", 0); Cursor cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employeeWHERE _id = ?", new String[]{""+employeeId}); if (cursor.getCount() != 1) { return; } cursor.moveToFirst(); TextView employeeNameText = (TextView) findViewById(R.id.employeeName); employeeNameText.setText(cursor.getString(cursor.getColumnIndex("firstName")) + " " + cursor.getString(cursor.getColumnIndex("lastName"))); TextView titleText = (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,
  • 14. 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 new String[] {"firstName", "lastName", "title"}, new int[] {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); } } Hide details Change log r14 by ccoenraets on Sep 8, 2010 Diff [No log message] G o to : ...oyeedirectory/DirectReports.java Project members, sign in to write a code review Older revisions All revisions of this file File info Size: 2164 bytes, 63 lines View raw file File properties svn:mime-type text/plain Terms - Privacy - Project Hosting Help direct_reports.xml r14 1 2 3 4 5 6 7 8 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent"
  • 15. 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 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> EmployeeDetails.java r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 package samples.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 { protected TextView employeeNameText; protected TextView titleText; protected List<EmployeeAction> actions; protected EmployeeActionAdapter adapter; protected int employeeId; protected int managerId; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.employee_details); employeeId = getIntent().getIntExtra("EMPLOYEE_ID", 0); SQLiteDatabase db = (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.firstName managerFirstName, mgr.lastName managerLastName FROM employeeemp LEFT OUTER JOIN employee mgr ON emp.managerId = mgr._id WHERE emp._id = ?", new String[]{""+employeeId}); if (cursor.getCount() == 1) { cursor.moveToFirst();
  • 16. 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 employeeNameText = (TextView) findViewById(R.id.employeeName); employeeNameText.setText(cursor.getString(cursor.getColumnIndex("firstName")) + " " + cursor.getString(cursor.getColumnIndex("lastName"))); titleText = (TextView) findViewById(R.id.title); titleText.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)); } 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)); } cursor = db.rawQuery("SELECT count(*) FROM employeeWHERE managerId = ?", new String[]{""+employeeId}); cursor.moveToFirst(); int count = cursor.getInt(0); if (count>0) { actions.add(new EmployeeAction("View direct reports", "(" + count + ")", EmployeeAction.ACTION_REPORTS)); } 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()) { case EmployeeAction.ACTION_CALL: Uri callUri = Uri.parse("tel:" + action.getData()); intent = new Intent(Intent.ACTION_CALL, callUri); startActivity(intent); break; case EmployeeAction.ACTION_EMAIL: intent = new Intent(Intent.ACTION_SEND); intent.setType("plain/text"); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{action.getData()}); startActivity(intent); break;
  • 17. 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 case EmployeeAction.ACTION_SMS: Uri smsUri = Uri.parse("sms:" + action.getData()); intent = new Intent(Intent.ACTION_VIEW, smsUri); startActivity(intent); break; case EmployeeAction.ACTION_REPORTS: intent = new Intent(this, DirectReports.class); intent.putExtra("EMPLOYEE_ID", employeeId); startActivity(intent); break; case EmployeeAction.ACTION_VIEW: intent = new Intent(this, EmployeeDetails.class); intent.putExtra("EMPLOYEE_ID", managerId); startActivity(intent); break; } } class EmployeeActionAdapter 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); LayoutInflater inflater = 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()); return view; } } } Hide details Change log r14 by ccoenraets on Sep 8, 2010 Diff [No log message] G o to : ...eedirectory/EmployeeDetails.java Project members, sign in to write a code review
  • 18. Older revisions All revisions of this file File info Size: 5534 bytes, 145 lines View raw file File properties svn:mime-type text/plain Terms - Privacy - Project Hosting Help DatabaseHelper.java r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 package samples.employeedirectory; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.widget.Toast; public class DatabaseHelper extends SQLiteOpenHelper { public staticfinal String DATABASE_NAME = "employee_directory2"; protected Context context; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, 1); this.context = context; } @Override public void onCreate(SQLiteDatabase db) { String s; try { Toast.makeText(context, "1", 2000).show(); InputStreamin = context.getResources().openRawResource(R.raw.sql); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(in, null); NodeList statements = doc.getElementsByTagName("statement"); for (int i=0; i<statements.getLength(); i++) { s = statements.item(i).getChildNodes().item(0).getNodeValue(); db.execSQL(s); } } catch (Throwable t) { Toast.makeText(context, t.toString(), 50000).show(); } } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLEIF EXISTS employees"); onCreate(db); } }
  • 19. 45 46 47 48 49 50 Hide details Change log r14 by ccoenraets on Sep 8, 2010 Diff [No log message] G o to : ...yeedirectory/DatabaseHelper.java Project members, sign in to write a code review Older revisions All revisions of this file File info Size: 1467 bytes, 50 lines View raw file File properties svn:mime-type text/plain Terms - Privacy - Project Hosting Help sql.xml r14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 <sql> <statement> CREATE TABLEIF NOT EXISTS employee ( _id INTEGER PRIMARYKEY 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), pictureVARCHAR(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 employeeVALUES(2,'Michael','Scott','Regional Manager','Management',1,'Scranton','570-888-9999','570-222- 3333','michael@dundermifflin.com','scott.jpg')</statement> <statement>INSERT INTO employeeVALUES(3,'Dwight','Schrute','Assistant Regional Manager','Management',2,'Scranton','570-444-4444','570-333- 3333','dwight@dundermifflin.com','schrute.jpg')</statement> <statement>INSERT INTO employeeVALUES(4,'Jim','Halpert','Assistant Regional
  • 20. 25 26 27 28 29 30 Manager','Manage',2,'Scranton','570-222-2121','570-999-1212','jim@dundermifflin.com','halpert.jpg')</statement> <statement>INSERT INTO employeeVALUES(5,'Pamela','Beesly','Receptionist','',2,'Scranton','570-999- 5555','570-999-7474','pam@dundermifflin.com','beesly.jpg')</statement> <statement>INSERT INTO employeeVALUES(6,'Angela','Martin','Senior Accountant','Accounting',2,'Scranton','570-555-9696','570-999- 3232','angela@dundermifflin.com','martin.jpg')</statement> <statement>INSERT INTO employeeVALUES(7,'Kevin','Malone','Accountant','Accounting',6,'Scranton','570-777- 9696','570-111-2525','kmalone@dundermifflin.com','malone.jpg')</statement> <statement>INSERT INTO employeeVALUES(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 employeeVALUES(10,'Andy','Bernard','Sales Director','Sales',2,'Scranton','570-555- 0000','570-546-9999','andy@dundermifflin.com','bernard.jpg')</statement> <statement>INSERT INTO employeeVALUES(11,'Phyllis','Lapin','Sales Representative','Sales',10,'Scranton','570- 141-3333','570-888-6666','phyllis@dundermifflin.com','lapin.jpg')</statement> <statement>INSERT INTO employeeVALUES(12,'Stanley','Hudson','Sales Representative','Sales',10,'Scranton','570-700-6666','570-777- 6666','shudson@dundermifflin.com','hudson.jpg')</statement> <statement>INSERT INTO employeeVALUES(13,'Meredith','Palmer','Supplier Relations','Customer Services',2,'Scranton','570-555-8888','570-777-2222','meredith@dundermifflin.com','palmer.jpg')</statement> <statement>INSERT INTO employeeVALUES(14,'Kelly','Kapoor','Customer Service Rep.','Customer Services',2,'Scranton','570-123-9654','570-125-3666','kelly@dundermifflin.com','kapoor.jpg')</statement> </sql>