1 |
package com.grundfos.android.people;
|
2 |
|
3 |
import android.app.Activity;
|
4 |
import android.content.Intent;
|
5 |
import android.net.Uri;
|
6 |
import android.os.Bundle;
|
7 |
import android.provider.Contacts;
|
8 |
import android.provider.Contacts.People;
|
9 |
import android.util.Log;
|
10 |
import android.view.ContextMenu;
|
11 |
import android.view.MenuItem;
|
12 |
import android.view.View;
|
13 |
import android.view.ContextMenu.ContextMenuInfo;
|
14 |
import android.widget.TextView;
|
15 |
|
16 |
public class PeopleDetails extends Activity {
|
17 |
|
18 |
static final int CALL_PHONE = 1000;
|
19 |
static final int CALL_CELL = 1001;
|
20 |
static final int TEXT_CELL = 1002;
|
21 |
static final int WRITE_EMAIL = 1003;
|
22 |
static final int CONTACTS = 1004;
|
23 |
|
24 |
PeopleBean people = null;
|
25 |
|
26 |
public void onCreate(Bundle savedInstanceState) {
|
27 |
super.onCreate(savedInstanceState);
|
28 |
setContentView(R.layout.details);
|
29 |
|
30 |
long id = getIntent().getLongExtra("id", -1);
|
31 |
Log.i("PeopleDatails", "ID:"+id);
|
32 |
|
33 |
people = new PeopleDatabase(this).getPeople(id);
|
34 |
|
35 |
if (people != null)
|
36 |
{
|
37 |
View details = findViewById(R.id.detailsview);
|
38 |
registerForContextMenu(details);
|
39 |
|
40 |
TextView tv = (TextView) findViewById(R.id.details_name);
|
41 |
tv.setText(people.name);
|
42 |
|
43 |
tv = (TextView) findViewById(R.id.details_inits);
|
44 |
tv.setText(people.inits);
|
45 |
|
46 |
tv = (TextView) findViewById(R.id.details_title);
|
47 |
tv.setText(people.title);
|
48 |
|
49 |
tv = (TextView) findViewById(R.id.details_dept);
|
50 |
tv.setText(people.dept);
|
51 |
|
52 |
tv = (TextView) findViewById(R.id.details_company);
|
53 |
tv.setText(people.company);
|
54 |
|
55 |
tv = (TextView) findViewById(R.id.details_phone);
|
56 |
tv.setText(people.phone);
|
57 |
|
58 |
tv = (TextView) findViewById(R.id.details_cell);
|
59 |
tv.setText(people.cell);
|
60 |
|
61 |
tv = (TextView) findViewById(R.id.details_email);
|
62 |
tv.setText(people.email);
|
63 |
} else {
|
64 |
Log.e("PeopleDetails", "Person not found!");
|
65 |
}
|
66 |
|
67 |
}
|
68 |
|
69 |
@Override
|
70 |
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
71 |
super.onCreateContextMenu(menu, v, menuInfo);
|
72 |
|
73 |
MenuItem callPhone = menu.add(0, CALL_PHONE, 0, "Call Phone");
|
74 |
MenuItem callCell = menu.add(0, CALL_CELL, 0, "Call Cell");
|
75 |
MenuItem textCell = menu.add(0, TEXT_CELL, 0, "Text Cell");
|
76 |
MenuItem writeMail = menu.add(0, WRITE_EMAIL, 0, "Write e-mail");
|
77 |
menu.add(0, CONTACTS, 0, "Copy to contacts");
|
78 |
|
79 |
if (people.phone.length() == 0)
|
80 |
callPhone.setEnabled(false);
|
81 |
|
82 |
if (people.cell.length() == 0) {
|
83 |
callCell.setEnabled(false);
|
84 |
textCell.setEnabled(false);
|
85 |
}
|
86 |
|
87 |
if (people.email.length() == 0)
|
88 |
writeMail.setEnabled(false);
|
89 |
|
90 |
}
|
91 |
public boolean onContextItemSelected(MenuItem item) {
|
92 |
Intent intent;
|
93 |
switch(item.getItemId()) {
|
94 |
case CALL_PHONE:
|
95 |
intent = new Intent(Intent.ACTION_CALL);
|
96 |
intent.setData(Uri.parse("tel:" + people.phone));
|
97 |
startActivity(intent);
|
98 |
return true;
|
99 |
case CALL_CELL:
|
100 |
intent = new Intent(Intent.ACTION_CALL);
|
101 |
intent.setData(Uri.parse("tel:" + people.cell));
|
102 |
startActivity(intent);
|
103 |
return true;
|
104 |
case TEXT_CELL:
|
105 |
intent = new Intent(Intent.ACTION_SENDTO);
|
106 |
intent.setData(Uri.parse("sms:" + people.cell));
|
107 |
startActivity(intent);
|
108 |
return true;
|
109 |
case WRITE_EMAIL:
|
110 |
intent = new Intent(Intent.ACTION_SENDTO);
|
111 |
intent.setData(Uri.parse("mailto:" + people.email));
|
112 |
startActivity(intent);
|
113 |
return true;
|
114 |
case CONTACTS:
|
115 |
intent = new Intent(Intent.ACTION_INSERT, People.CONTENT_URI);
|
116 |
|
117 |
intent.putExtra(Contacts.Intents.Insert.NAME, people.name);
|
118 |
intent.putExtra(Contacts.Intents.Insert.PHONE, people.phone);
|
119 |
intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE, Contacts.PhonesColumns.TYPE_WORK);
|
120 |
intent.putExtra(Contacts.Intents.Insert.SECONDARY_PHONE , people.cell);
|
121 |
intent.putExtra(Contacts.Intents.Insert.SECONDARY_PHONE_TYPE, Contacts.PhonesColumns.TYPE_MOBILE);
|
122 |
intent.putExtra(Contacts.Intents.Insert.EMAIL, people.email);
|
123 |
intent.putExtra(Contacts.Intents.Insert.JOB_TITLE, people.title);
|
124 |
startActivity(intent);
|
125 |
|
126 |
return true;
|
127 |
}
|
128 |
return super.onContextItemSelected(item);
|
129 |
}
|
130 |
|
131 |
|
132 |
|
133 |
}
|