Merge commit 'bfecfce120917d099e3e5806b334a53e9bbc3846' * commit 'bfecfce120917d099e3e5806b334a53e9bbc3846': Switch Email to new FastTrack API.
This commit is contained in:
commit
c0c8b24789
@ -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;
|
||||||
|
|
||||||
// Pass along full E-mail string for possible create dialog
|
// First perform lookup query to find existing contact
|
||||||
contactIntent.putExtra(ContactsContract.Intents.EXTRA_CREATE_DESCRIPTION,
|
final ContentResolver resolver = getContentResolver();
|
||||||
senderEmail.toString());
|
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);
|
||||||
|
|
||||||
// Only provide personal name hint if we have one
|
if (lookupUri != null) {
|
||||||
String senderPersonal = senderEmail.getPersonal();
|
// Found matching contact, trigger FastTrack
|
||||||
if (senderPersonal != null) {
|
FastTrack.showFastTrack(this, mSenderPresenceView, lookupUri, FastTrack.MODE_MEDIUM,
|
||||||
contactIntent.putExtra(ContactsContract.Intents.Insert.NAME, senderPersonal);
|
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);
|
||||||
|
|
||||||
contactIntent.putExtra(ContactsContract.Intents.EXTRA_TARGET_RECT,
|
// Pass along full E-mail string for possible create dialog
|
||||||
getAbsoluteRect(mSenderPresenceView));
|
intent.putExtra(ContactsContract.Intents.EXTRA_CREATE_DESCRIPTION,
|
||||||
startActivity(contactIntent);
|
senderEmail.toString());
|
||||||
|
|
||||||
|
// Only provide personal name hint if we have one
|
||||||
|
final String senderPersonal = senderEmail.getPersonal();
|
||||||
|
if (!TextUtils.isEmpty(senderPersonal)) {
|
||||||
|
intent.putExtra(ContactsContract.Intents.Insert.NAME, senderPersonal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user