1fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann/* 2fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * Copyright (C) 2010 The Android Open Source Project 3fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * 4fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * Licensed under the Apache License, Version 2.0 (the "License"); 5fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * you may not use this file except in compliance with the License. 6fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * You may obtain a copy of the License at 7fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * 8fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * http://www.apache.org/licenses/LICENSE-2.0 9fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * 10fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * Unless required by applicable law or agreed to in writing, software 11fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * distributed under the License is distributed on an "AS IS" BASIS, 12fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * See the License for the specific language governing permissions and 14fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann * limitations under the License. 15fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann */ 16fbb876392608a36ec1d23704f29d8b46d5d23991Daniel Lehmann 17af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannpackage com.android.contacts.quickcontact; 18af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 1976de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braunimport android.content.ComponentName; 20af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannimport android.content.ContentUris; 21af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannimport android.content.Context; 22af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannimport android.content.Intent; 23af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannimport android.content.pm.PackageManager; 24af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannimport android.graphics.drawable.Drawable; 25af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannimport android.net.Uri; 26af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Im; 27f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawaimport android.provider.ContactsContract.Data; 280319222b43927d4d9ce7e2a9070f3543661b5782Tyler Gunnimport android.telecom.PhoneAccount; 29af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannimport android.text.TextUtils; 30af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannimport android.util.Log; 31af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 3216339336653fa028a2e02e1eee92851fe5084d1cPaul Soulosimport com.android.contacts.R; 333a8df86541c91ac5023bc46efae4ed23502512faChiao Chengimport com.android.contacts.common.CallUtil; 34cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.ContactsUtils; 35d7ca03e23948c3b2d5f97ec5598d8b50e3fc0b25Chiao Chengimport com.android.contacts.common.MoreContactUtils; 36428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.account.AccountType.EditType; 37cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.DataItem; 38428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.dataitem.DataKind; 39cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.EmailDataItem; 40cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.ImDataItem; 41cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.PhoneDataItem; 42cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.SipAddressDataItem; 43cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.StructuredPostalDataItem; 44cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.WebsiteDataItem; 45493f8d14b1d974a2939a110ce89fa68e0c915c36Brian Attwellimport com.android.contacts.quickcontact.WebAddress.ParseException; 46e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.util.PhoneCapabilityTester; 47e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.util.StructuredPostalUtils; 48e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng 49af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann/** 50af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * Description of a specific {@link Data#_ID} item, with style information 51af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * defined by a {@link DataKind}. 52af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann */ 53af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannpublic class DataAction implements Action { 54af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann private static final String TAG = "DataAction"; 55af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 56af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann private final Context mContext; 57af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann private final DataKind mKind; 58af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann private final String mMimeType; 5916339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos private final Integer mTimesUsed; 6016339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos private final Long mLastTimeUsed; 61af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 62af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann private CharSequence mBody; 63edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private CharSequence mSubtitle; 64af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann private Intent mIntent; 65edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private Intent mAlternateIntent; 66ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan private int mAlternateIconDescriptionRes; 67edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private int mAlternateIconRes; 689daca14706f3699c9e9d46dfb522132fc566e57eDaniel Lehmann private int mPresence = -1; 69af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 70af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann private Uri mDataUri; 710f78e8b198c56963d6d6044839bb0679f4afd075Daniel Lehmann private long mDataId; 72af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann private boolean mIsPrimary; 7316339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos private boolean mIsSuperPrimary; 74af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 75af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann /** 76af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * Create an action from common {@link Data} elements. 77af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann */ 7847b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng public DataAction(Context context, DataItem item, DataKind kind) { 79af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann mContext = context; 8047b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng mKind = kind; 81851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu mMimeType = item.getMimeType(); 8216339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos mTimesUsed = item.getTimesUsed(); 8316339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos mLastTimeUsed = item.getLastTimeUsed(); 84af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 85edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann // Determine type for subtitle 86edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann mSubtitle = ""; 8747b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng if (item.hasKindTypeColumn(kind)) { 8847b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final int typeValue = item.getKindTypeColumn(kind); 89851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu 90851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu // get type string 9147b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng for (EditType type : kind.typeList) { 92851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu if (type.rawValue == typeValue) { 93851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu if (type.customColumn == null) { 94851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu // Non-custom type. Get its description from the resource 95851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu mSubtitle = context.getString(type.labelRes); 96851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu } else { 97851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu // Custom type. Read it from the database 98851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu mSubtitle = item.getContentValues().getAsString(type.customColumn); 99edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 100851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu break; 101edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 102edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 103af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 104af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 10516339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos mIsPrimary = item.isPrimary(); 10616339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos mIsSuperPrimary = item.isSuperPrimary(); 107b2b435a944947fbf1965c3bb7c202a97f0273259Yorke Lee mBody = item.buildDataStringForDisplay(context, kind); 108af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 109851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu mDataId = item.getId(); 110851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu mDataUri = ContentUris.withAppendedId(Data.CONTENT_URI, mDataId); 111af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 112edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann final boolean hasPhone = PhoneCapabilityTester.isPhone(mContext); 11376de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun final ComponentName smsComponent = PhoneCapabilityTester.getSmsComponent(mContext); 11476de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun final boolean hasSms = (smsComponent != null); 115edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 116af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann // Handle well-known MIME-types with special care 117851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu if (item instanceof PhoneDataItem) { 118af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann if (PhoneCapabilityTester.isPhone(mContext)) { 119851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu PhoneDataItem phone = (PhoneDataItem) item; 120851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final String number = phone.getNumber(); 121af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann if (!TextUtils.isEmpty(number)) { 122edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1233a8df86541c91ac5023bc46efae4ed23502512faChiao Cheng final Intent phoneIntent = hasPhone ? CallUtil.getCallIntent(number) 124fadd5e1f1845b8d98e247bbd30535928dc5e0f81Daisuke Miyakawa : null; 12576de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun Intent smsIntent = null; 12676de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun if (hasSms) { 12776de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun smsIntent = new Intent(Intent.ACTION_SENDTO, 1281cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner Uri.fromParts(ContactsUtils.SCHEME_SMSTO, number, null)); 12976de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun smsIntent.setComponent(smsComponent); 13076de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun } 131edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 132edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann // Configure Icons and Intents. Notice actionIcon is already set to the phone 133edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (hasPhone && hasSms) { 134edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann mIntent = phoneIntent; 135edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann mAlternateIntent = smsIntent; 13647b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng mAlternateIconRes = kind.iconAltRes; 13747b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng mAlternateIconDescriptionRes = kind.iconAltDescriptionRes; 138edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } else if (hasPhone) { 139edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann mIntent = phoneIntent; 140edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } else if (hasSms) { 141edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann mIntent = smsIntent; 142edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 143af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 144af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 145851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu } else if (item instanceof SipAddressDataItem) { 146af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann if (PhoneCapabilityTester.isSipPhone(mContext)) { 147851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final SipAddressDataItem sip = (SipAddressDataItem) item; 148851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final String address = sip.getSipAddress(); 149af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann if (!TextUtils.isEmpty(address)) { 1501cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner final Uri callUri = Uri.fromParts(PhoneAccount.SCHEME_SIP, address, null); 1513a8df86541c91ac5023bc46efae4ed23502512faChiao Cheng mIntent = CallUtil.getCallIntent(callUri); 152af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann // Note that this item will get a SIP-specific variant 153af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann // of the "call phone" icon, rather than the standard 154af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann // app icon for the Phone app (which we show for 155af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann // regular phone numbers.) That's because the phone 156af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann // app explicitly specifies an android:icon attribute 157af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann // for the SIP-related intent-filters in its manifest. 158af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 159af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 160851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu } else if (item instanceof EmailDataItem) { 161851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final EmailDataItem email = (EmailDataItem) item; 162851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final String address = email.getData(); 163af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann if (!TextUtils.isEmpty(address)) { 1641cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner final Uri mailUri = Uri.fromParts(ContactsUtils.SCHEME_MAILTO, address, null); 165af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann mIntent = new Intent(Intent.ACTION_SENDTO, mailUri); 166af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 167af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 168851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu } else if (item instanceof WebsiteDataItem) { 169851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final WebsiteDataItem website = (WebsiteDataItem) item; 170851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final String url = website.getUrl(); 171af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann if (!TextUtils.isEmpty(url)) { 172493f8d14b1d974a2939a110ce89fa68e0c915c36Brian Attwell try { 173493f8d14b1d974a2939a110ce89fa68e0c915c36Brian Attwell final WebAddress webAddress = new WebAddress(url); 174493f8d14b1d974a2939a110ce89fa68e0c915c36Brian Attwell mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString())); 175493f8d14b1d974a2939a110ce89fa68e0c915c36Brian Attwell } catch (ParseException e) { 176493f8d14b1d974a2939a110ce89fa68e0c915c36Brian Attwell mIntent = null; 177493f8d14b1d974a2939a110ce89fa68e0c915c36Brian Attwell } 178af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 179af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 180851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu } else if (item instanceof ImDataItem) { 181851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu ImDataItem im = (ImDataItem) item; 182851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final boolean isEmail = im.isCreatedFromEmail(); 183851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu if (isEmail || im.isProtocolValid()) { 184851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final int protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol(); 185af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 186af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann if (isEmail) { 187af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann // Use Google Talk string when using Email, and clear data 188af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann // Uri so we don't try saving Email as primary. 1899daca14706f3699c9e9d46dfb522132fc566e57eDaniel Lehmann mSubtitle = Im.getProtocolLabel(context.getResources(), Im.PROTOCOL_GOOGLE_TALK, 1909daca14706f3699c9e9d46dfb522132fc566e57eDaniel Lehmann null); 191af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann mDataUri = null; 192af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 193af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 194851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu String host = im.getCustomProtocol(); 195851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu String data = im.getData(); 196af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann if (protocol != Im.PROTOCOL_CUSTOM) { 197af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann // Try bringing in a well-known host for specific protocols 198af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann host = ContactsUtils.lookupProviderNameFromId(protocol); 199af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 200af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 201f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawa if (!TextUtils.isEmpty(host) && !TextUtils.isEmpty(data)) { 202af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann final String authority = host.toLowerCase(); 2031cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner final Uri imUri = new Uri.Builder().scheme(ContactsUtils.SCHEME_IMTO).authority( 204af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann authority).appendPath(data).build(); 205af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann mIntent = new Intent(Intent.ACTION_SENDTO, imUri); 206f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawa 207f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawa // If the address is also available for a video chat, we'll show the capability 208f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawa // as a secondary action. 209851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final int chatCapability = im.getChatCapability(); 210f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawa final boolean isVideoChatCapable = 211f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawa (chatCapability & Im.CAPABILITY_HAS_CAMERA) != 0; 212f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawa final boolean isAudioChatCapable = 213f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawa (chatCapability & Im.CAPABILITY_HAS_VOICE) != 0; 214f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawa if (isVideoChatCapable || isAudioChatCapable) { 215f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawa mAlternateIntent = new Intent( 216f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawa Intent.ACTION_SENDTO, Uri.parse("xmpp:" + data + "?call")); 217ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan if (isVideoChatCapable) { 218ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan mAlternateIconRes = R.drawable.sym_action_videochat_holo_light; 219ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan mAlternateIconDescriptionRes = R.string.video_chat; 220ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan } else { 221ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan mAlternateIconRes = R.drawable.sym_action_audiochat_holo_light; 222ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan mAlternateIconDescriptionRes = R.string.audio_chat; 223ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan } 224f31df5d850fd0c10d9da4cd356f944c962fb44bbDaisuke Miyakawa } 225af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 226af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 227851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu } else if (item instanceof StructuredPostalDataItem) { 228851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu StructuredPostalDataItem postal = (StructuredPostalDataItem) item; 229851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final String postalAddress = postal.getFormattedAddress(); 230bfb59d8edce8c5604915a6e2ec288ad0becc7c7dMakoto Onuki if (!TextUtils.isEmpty(postalAddress)) { 231bfb59d8edce8c5604915a6e2ec288ad0becc7c7dMakoto Onuki mIntent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress); 232bfb59d8edce8c5604915a6e2ec288ad0becc7c7dMakoto Onuki } 233af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 234af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 235af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann if (mIntent == null) { 236af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann // Otherwise fall back to default VIEW action 2371b89adcfc9a2dab203789d489f6ab66ba782800cDmitri Plotnikov mIntent = new Intent(Intent.ACTION_VIEW); 238851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu mIntent.setDataAndType(mDataUri, item.getMimeType()); 239af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 240af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 2418ca93ed0938e00ee94b03e6d609895593cfdbdbdAdam Powell mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 242af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 243af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 2449daca14706f3699c9e9d46dfb522132fc566e57eDaniel Lehmann @Override 2459daca14706f3699c9e9d46dfb522132fc566e57eDaniel Lehmann public int getPresence() { 2469daca14706f3699c9e9d46dfb522132fc566e57eDaniel Lehmann return mPresence; 2479daca14706f3699c9e9d46dfb522132fc566e57eDaniel Lehmann } 2489daca14706f3699c9e9d46dfb522132fc566e57eDaniel Lehmann 2499daca14706f3699c9e9d46dfb522132fc566e57eDaniel Lehmann public void setPresence(int presence) { 2509daca14706f3699c9e9d46dfb522132fc566e57eDaniel Lehmann mPresence = presence; 2519daca14706f3699c9e9d46dfb522132fc566e57eDaniel Lehmann } 2529daca14706f3699c9e9d46dfb522132fc566e57eDaniel Lehmann 253af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann @Override 254edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann public CharSequence getSubtitle() { 255edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return mSubtitle; 256af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 257af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 258af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann @Override 259af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann public CharSequence getBody() { 260af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann return mBody; 261af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 262af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 263af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann @Override 264af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann public String getMimeType() { 265af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann return mMimeType; 266af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 267af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 268af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann @Override 269af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann public Uri getDataUri() { 270af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann return mDataUri; 271af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 272af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 273af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann @Override 2740f78e8b198c56963d6d6044839bb0679f4afd075Daniel Lehmann public long getDataId() { 2750f78e8b198c56963d6d6044839bb0679f4afd075Daniel Lehmann return mDataId; 2760f78e8b198c56963d6d6044839bb0679f4afd075Daniel Lehmann } 2770f78e8b198c56963d6d6044839bb0679f4afd075Daniel Lehmann 2780f78e8b198c56963d6d6044839bb0679f4afd075Daniel Lehmann @Override 27916339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos public boolean isPrimary() { 280af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann return mIsPrimary; 281af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 282af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 283af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann @Override 28416339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos public boolean isSuperPrimary() { 28516339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos return mIsSuperPrimary; 28616339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 28716339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos 28816339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos @Override 289edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann public Drawable getAlternateIcon() { 290edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (mAlternateIconRes == 0) return null; 291edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 29282a4f4408b74e193b43a12dc8e16c946a93bae4aMakoto Onuki final String resourcePackageName = mKind.resourcePackageName; 29382a4f4408b74e193b43a12dc8e16c946a93bae4aMakoto Onuki if (resourcePackageName == null) { 294edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return mContext.getResources().getDrawable(mAlternateIconRes); 295edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 296af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 297af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann final PackageManager pm = mContext.getPackageManager(); 29882a4f4408b74e193b43a12dc8e16c946a93bae4aMakoto Onuki return pm.getDrawable(resourcePackageName, mAlternateIconRes, null); 299af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 300af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 301af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann @Override 302ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan public String getAlternateIconDescription() { 303ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan if (mAlternateIconDescriptionRes == 0) return null; 304ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan return mContext.getResources().getString(mAlternateIconDescriptionRes); 305ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan } 306ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan 307ee05dcdd4b066ad909322c10919fb1812214673bKatherine Kuan @Override 308af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann public Intent getIntent() { 309af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann return mIntent; 310af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 311af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 312edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @Override 313edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann public Intent getAlternateIntent() { 314edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return mAlternateIntent; 315edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 316edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 317af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann @Override 318ad29eae127034dbfd4aaf781a09ff08984b72b08Jay Shrauner public void collapseWith(Action other) { 319ad29eae127034dbfd4aaf781a09ff08984b72b08Jay Shrauner // No-op 320af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 321af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 322af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann @Override 3230646ee3eb604800e381575035665258629b1ab47Paul Soulos public boolean shouldCollapseWith(Action t, Context context) { 324af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann if (t == null) { 325af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann return false; 326af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 327af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann if (!(t instanceof DataAction)) { 328af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann Log.e(TAG, "t must be DataAction"); 329af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann return false; 330af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 33169fad288d10ea261c12787e5a0e280cf938a7784Daniel Lehmann DataAction that = (DataAction)t; 332d7ca03e23948c3b2d5f97ec5598d8b50e3fc0b25Chiao Cheng if (!MoreContactUtils.shouldCollapse(mMimeType, mBody, that.mMimeType, that.mBody)) { 333af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann return false; 334af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 33569fad288d10ea261c12787e5a0e280cf938a7784Daniel Lehmann if (!TextUtils.equals(mMimeType, that.mMimeType) 33669fad288d10ea261c12787e5a0e280cf938a7784Daniel Lehmann || !ContactsUtils.areIntentActionEqual(mIntent, that.mIntent)) { 337af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann return false; 338af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 339af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann return true; 340af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 34116339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos 34216339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos @Override 34316339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos public Integer getTimesUsed() { 34416339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos return mTimesUsed; 34516339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 34616339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos 34716339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos @Override 34816339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos public Long getLastTimeUsed() { 34916339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos return mLastTimeUsed; 35016339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 351af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann} 352