Loading src/com/android/contacts/detail/ContactDetailFragment.java +16 −25 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.contacts.detail; import android.app.Activity; import android.app.Fragment; import android.app.SearchManager; import android.content.ComponentName; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; Loading Loading @@ -168,21 +169,6 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen new AddToMyContactsQuickFix() }; /** * Device capability: Set during buildEntries and used in the long-press context menu */ private boolean mHasPhone; /** * Device capability: Set during buildEntries and used in the long-press context menu */ private boolean mHasSms; /** * Device capability: Set during buildEntries and used in the long-press context menu */ private boolean mHasSip; /** * The view shown if the detail list is empty. * We set this to the list view when first bind the adapter, so that it won't be shown while Loading Loading @@ -533,9 +519,10 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen * Build up the entries to display on the screen. */ private final void buildEntries() { mHasPhone = PhoneCapabilityTester.isPhone(mContext); mHasSms = PhoneCapabilityTester.isSmsIntentRegistered(mContext); mHasSip = PhoneCapabilityTester.isSipPhone(mContext); final boolean hasPhone = PhoneCapabilityTester.isPhone(mContext); final ComponentName smsComponent = PhoneCapabilityTester.getSmsComponent(getContext()); final boolean hasSms = (smsComponent != null); final boolean hasSip = PhoneCapabilityTester.isSipPhone(mContext); // Clear out the old entries mAllEntries.clear(); Loading Loading @@ -583,21 +570,25 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen PhoneDataItem phone = (PhoneDataItem) dataItem; // Build phone entries entry.data = phone.getFormattedPhoneNumber(); final Intent phoneIntent = mHasPhone ? final Intent phoneIntent = hasPhone ? CallUtil.getCallIntent(entry.data) : null; final Intent smsIntent = mHasSms ? new Intent(Intent.ACTION_SENDTO, Uri.fromParts(CallUtil.SCHEME_SMSTO, entry.data, null)) : null; Intent smsIntent = null; if (hasSms) { smsIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(CallUtil.SCHEME_SMSTO, entry.data, null)); smsIntent.setComponent(smsComponent); } // Configure Icons and Intents. if (mHasPhone && mHasSms) { if (hasPhone && hasSms) { entry.intent = phoneIntent; entry.secondaryIntent = smsIntent; entry.secondaryActionIcon = kind.iconAltRes; entry.secondaryActionDescription = ContactDisplayUtils.getSmsLabelResourceId(entry.type); } else if (mHasPhone) { } else if (hasPhone) { entry.intent = phoneIntent; } else if (mHasSms) { } else if (hasSms) { entry.intent = smsIntent; } else { entry.intent = null; Loading Loading @@ -694,7 +685,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen } else if (dataItem instanceof SipAddressDataItem && hasData) { // Build SipAddress entries entry.uri = null; if (mHasSip) { if (hasSip) { entry.intent = CallUtil.getCallIntent( Uri.fromParts(CallUtil.SCHEME_SIP, entry.data, null)); } else { Loading src/com/android/contacts/quickcontact/DataAction.java +9 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.contacts.quickcontact; import android.content.ComponentName; import android.content.ContentUris; import android.content.Context; import android.content.Intent; Loading Loading @@ -102,7 +103,8 @@ public class DataAction implements Action { mDataUri = ContentUris.withAppendedId(Data.CONTENT_URI, mDataId); final boolean hasPhone = PhoneCapabilityTester.isPhone(mContext); final boolean hasSms = PhoneCapabilityTester.isSmsIntentRegistered(mContext); final ComponentName smsComponent = PhoneCapabilityTester.getSmsComponent(mContext); final boolean hasSms = (smsComponent != null); // Handle well-known MIME-types with special care if (item instanceof PhoneDataItem) { Loading @@ -113,8 +115,12 @@ public class DataAction implements Action { final Intent phoneIntent = hasPhone ? CallUtil.getCallIntent(number) : null; final Intent smsIntent = hasSms ? new Intent(Intent.ACTION_SENDTO, Uri.fromParts(CallUtil.SCHEME_SMSTO, number, null)) : null; Intent smsIntent = null; if (hasSms) { smsIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(CallUtil.SCHEME_SMSTO, number, null)); smsIntent.setComponent(smsComponent); } // Configure Icons and Intents. Notice actionIcon is already set to the phone if (hasPhone && hasSms) { Loading src/com/android/contacts/util/PhoneCapabilityTester.java +17 −6 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.contacts.util; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; Loading @@ -23,6 +24,7 @@ import android.content.pm.ResolveInfo; import android.net.Uri; import android.net.sip.SipManager; import android.provider.MediaStore; import android.provider.Telephony; import android.telephony.TelephonyManager; import com.android.contacts.common.CallUtil; Loading Loading @@ -75,13 +77,22 @@ public final class PhoneCapabilityTester { } /** * Returns true if the device has an SMS application installed. * Returns the component name to use for sending to sms or null. */ public static boolean isSmsIntentRegistered(Context context) { // Don't cache the result as the user might install third party apps to send SMS public static ComponentName getSmsComponent(Context context) { String smsPackage = Telephony.Sms.getDefaultSmsPackage(context); if (smsPackage != null) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(CallUtil.SCHEME_SMSTO, "", null)); return isIntentRegistered(context, intent); final List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent, 0); for (ResolveInfo resolveInfo : resolveInfos) { if (smsPackage.equals(resolveInfo.activityInfo.packageName)) { return new ComponentName(smsPackage, resolveInfo.activityInfo.name); } } } return null; } /** Loading Loading
src/com/android/contacts/detail/ContactDetailFragment.java +16 −25 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.contacts.detail; import android.app.Activity; import android.app.Fragment; import android.app.SearchManager; import android.content.ComponentName; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; Loading Loading @@ -168,21 +169,6 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen new AddToMyContactsQuickFix() }; /** * Device capability: Set during buildEntries and used in the long-press context menu */ private boolean mHasPhone; /** * Device capability: Set during buildEntries and used in the long-press context menu */ private boolean mHasSms; /** * Device capability: Set during buildEntries and used in the long-press context menu */ private boolean mHasSip; /** * The view shown if the detail list is empty. * We set this to the list view when first bind the adapter, so that it won't be shown while Loading Loading @@ -533,9 +519,10 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen * Build up the entries to display on the screen. */ private final void buildEntries() { mHasPhone = PhoneCapabilityTester.isPhone(mContext); mHasSms = PhoneCapabilityTester.isSmsIntentRegistered(mContext); mHasSip = PhoneCapabilityTester.isSipPhone(mContext); final boolean hasPhone = PhoneCapabilityTester.isPhone(mContext); final ComponentName smsComponent = PhoneCapabilityTester.getSmsComponent(getContext()); final boolean hasSms = (smsComponent != null); final boolean hasSip = PhoneCapabilityTester.isSipPhone(mContext); // Clear out the old entries mAllEntries.clear(); Loading Loading @@ -583,21 +570,25 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen PhoneDataItem phone = (PhoneDataItem) dataItem; // Build phone entries entry.data = phone.getFormattedPhoneNumber(); final Intent phoneIntent = mHasPhone ? final Intent phoneIntent = hasPhone ? CallUtil.getCallIntent(entry.data) : null; final Intent smsIntent = mHasSms ? new Intent(Intent.ACTION_SENDTO, Uri.fromParts(CallUtil.SCHEME_SMSTO, entry.data, null)) : null; Intent smsIntent = null; if (hasSms) { smsIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(CallUtil.SCHEME_SMSTO, entry.data, null)); smsIntent.setComponent(smsComponent); } // Configure Icons and Intents. if (mHasPhone && mHasSms) { if (hasPhone && hasSms) { entry.intent = phoneIntent; entry.secondaryIntent = smsIntent; entry.secondaryActionIcon = kind.iconAltRes; entry.secondaryActionDescription = ContactDisplayUtils.getSmsLabelResourceId(entry.type); } else if (mHasPhone) { } else if (hasPhone) { entry.intent = phoneIntent; } else if (mHasSms) { } else if (hasSms) { entry.intent = smsIntent; } else { entry.intent = null; Loading Loading @@ -694,7 +685,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen } else if (dataItem instanceof SipAddressDataItem && hasData) { // Build SipAddress entries entry.uri = null; if (mHasSip) { if (hasSip) { entry.intent = CallUtil.getCallIntent( Uri.fromParts(CallUtil.SCHEME_SIP, entry.data, null)); } else { Loading
src/com/android/contacts/quickcontact/DataAction.java +9 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.contacts.quickcontact; import android.content.ComponentName; import android.content.ContentUris; import android.content.Context; import android.content.Intent; Loading Loading @@ -102,7 +103,8 @@ public class DataAction implements Action { mDataUri = ContentUris.withAppendedId(Data.CONTENT_URI, mDataId); final boolean hasPhone = PhoneCapabilityTester.isPhone(mContext); final boolean hasSms = PhoneCapabilityTester.isSmsIntentRegistered(mContext); final ComponentName smsComponent = PhoneCapabilityTester.getSmsComponent(mContext); final boolean hasSms = (smsComponent != null); // Handle well-known MIME-types with special care if (item instanceof PhoneDataItem) { Loading @@ -113,8 +115,12 @@ public class DataAction implements Action { final Intent phoneIntent = hasPhone ? CallUtil.getCallIntent(number) : null; final Intent smsIntent = hasSms ? new Intent(Intent.ACTION_SENDTO, Uri.fromParts(CallUtil.SCHEME_SMSTO, number, null)) : null; Intent smsIntent = null; if (hasSms) { smsIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(CallUtil.SCHEME_SMSTO, number, null)); smsIntent.setComponent(smsComponent); } // Configure Icons and Intents. Notice actionIcon is already set to the phone if (hasPhone && hasSms) { Loading
src/com/android/contacts/util/PhoneCapabilityTester.java +17 −6 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.contacts.util; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; Loading @@ -23,6 +24,7 @@ import android.content.pm.ResolveInfo; import android.net.Uri; import android.net.sip.SipManager; import android.provider.MediaStore; import android.provider.Telephony; import android.telephony.TelephonyManager; import com.android.contacts.common.CallUtil; Loading Loading @@ -75,13 +77,22 @@ public final class PhoneCapabilityTester { } /** * Returns true if the device has an SMS application installed. * Returns the component name to use for sending to sms or null. */ public static boolean isSmsIntentRegistered(Context context) { // Don't cache the result as the user might install third party apps to send SMS public static ComponentName getSmsComponent(Context context) { String smsPackage = Telephony.Sms.getDefaultSmsPackage(context); if (smsPackage != null) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(CallUtil.SCHEME_SMSTO, "", null)); return isIntentRegistered(context, intent); final List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent, 0); for (ResolveInfo resolveInfo : resolveInfos) { if (smsPackage.equals(resolveInfo.activityInfo.packageName)) { return new ComponentName(smsPackage, resolveInfo.activityInfo.name); } } } return null; } /** Loading