am bfecfce1: am 68b620cc: Switch Email to new FastTrack API.

Merge commit 'bfecfce120917d099e3e5806b334a53e9bbc3846'

* commit 'bfecfce120917d099e3e5806b334a53e9bbc3846':
  Switch Email to new FastTrack API.
This commit is contained in:
Jeff Sharkey 2009-09-18 00:19:10 -07:00 committed by Android Git Automerger
commit c0c8b24789

View File

@ -36,6 +36,7 @@ import org.apache.commons.io.IOUtils;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.ContentObserver; import android.database.ContentObserver;
@ -53,7 +54,9 @@ import android.os.Environment;
import android.os.Handler; import android.os.Handler;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds; import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.FastTrack;
import android.provider.ContactsContract.Presence; import android.provider.ContactsContract.Presence;
import android.text.TextUtils;
import android.text.util.Regex; import android.text.util.Regex;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -445,37 +448,45 @@ public class MessageView extends Activity implements OnClickListener {
} }
} }
private Rect getAbsoluteRect(View view) { /**
int[] location = new int[2]; * Handle clicks on sender, which shows {@link FastTrack} or prompts to add
view.getLocationOnScreen(location); * the sender as a contact.
int x = location[0]; */
int y = location[1];
return new Rect(x, y, x + view.getWidth(), y + view.getHeight());
}
private void onClickSender() { private void onClickSender() {
if (mMessage != null) { // Bail early if message or sender not present
Address senderEmail = Address.unpackFirst(mMessage.mFrom); if (mMessage == null) return;
if (senderEmail != null) {
Uri contactUri = Uri.fromParts("mailto", senderEmail.getAddress(), null);
Intent contactIntent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT); final Address senderEmail = Address.unpackFirst(mMessage.mFrom);
contactIntent.setData(contactUri); if (senderEmail == null) return;
// First perform lookup query to find existing contact
final ContentResolver resolver = getContentResolver();
final String address = senderEmail.getAddress();
final Uri dataUri = Uri.withAppendedPath(CommonDataKinds.Email.CONTENT_FILTER_URI,
Uri.encode(address));
final Uri lookupUri = ContactsContract.Data.getContactLookupUri(resolver, dataUri);
if (lookupUri != null) {
// Found matching contact, trigger FastTrack
FastTrack.showFastTrack(this, mSenderPresenceView, lookupUri, FastTrack.MODE_MEDIUM,
null);
} else {
// No matching contact, ask user to create one
final Uri mailUri = Uri.fromParts("mailto", address, null);
final Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT,
mailUri);
// Pass along full E-mail string for possible create dialog // Pass along full E-mail string for possible create dialog
contactIntent.putExtra(ContactsContract.Intents.EXTRA_CREATE_DESCRIPTION, intent.putExtra(ContactsContract.Intents.EXTRA_CREATE_DESCRIPTION,
senderEmail.toString()); senderEmail.toString());
// Only provide personal name hint if we have one // Only provide personal name hint if we have one
String senderPersonal = senderEmail.getPersonal(); final String senderPersonal = senderEmail.getPersonal();
if (senderPersonal != null) { if (!TextUtils.isEmpty(senderPersonal)) {
contactIntent.putExtra(ContactsContract.Intents.Insert.NAME, senderPersonal); intent.putExtra(ContactsContract.Intents.Insert.NAME, senderPersonal);
} }
contactIntent.putExtra(ContactsContract.Intents.EXTRA_TARGET_RECT, startActivity(intent);
getAbsoluteRect(mSenderPresenceView));
startActivity(contactIntent);
}
} }
} }