/[projects]/android/People/src/com/grundfos/android/people/PeopleDetails.java
ViewVC logotype

Contents of /android/People/src/com/grundfos/android/people/PeopleDetails.java

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20