Daniel Lehmann | fbb8763 | 2011-09-30 20:54:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 17 | package com.android.contacts.quickcontact; |
| 18 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 19 | import android.content.ContentUris; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.pm.PackageManager; |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 23 | import android.graphics.drawable.Drawable; |
| 24 | import android.net.Uri; |
Dmitri Plotnikov | 15dcf1d | 2010-12-09 17:12:54 -0800 | [diff] [blame] | 25 | import android.net.WebAddress; |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 26 | import android.provider.ContactsContract.CommonDataKinds.Im; |
Daisuke Miyakawa | f31df5d | 2011-08-02 15:37:50 -0700 | [diff] [blame] | 27 | import android.provider.ContactsContract.Data; |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 28 | import android.text.TextUtils; |
| 29 | import android.util.Log; |
| 30 | |
Chiao Cheng | 3a8df86 | 2012-09-04 16:30:17 -0700 | [diff] [blame] | 31 | import com.android.contacts.common.CallUtil; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 32 | import com.android.contacts.ContactsUtils; |
| 33 | import com.android.contacts.R; |
Chiao Cheng | d7ca03e | 2012-10-24 15:14:08 -0700 | [diff] [blame] | 34 | import com.android.contacts.common.MoreContactUtils; |
Chiao Cheng | 428f008 | 2012-11-13 18:38:56 -0800 | [diff] [blame] | 35 | import com.android.contacts.common.model.account.AccountType.EditType; |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 36 | import com.android.contacts.model.dataitem.DataItem; |
Chiao Cheng | 428f008 | 2012-11-13 18:38:56 -0800 | [diff] [blame] | 37 | import com.android.contacts.common.model.dataitem.DataKind; |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 38 | import com.android.contacts.model.dataitem.EmailDataItem; |
| 39 | import com.android.contacts.model.dataitem.ImDataItem; |
| 40 | import com.android.contacts.model.dataitem.PhoneDataItem; |
| 41 | import com.android.contacts.model.dataitem.SipAddressDataItem; |
| 42 | import com.android.contacts.model.dataitem.StructuredPostalDataItem; |
| 43 | import com.android.contacts.model.dataitem.WebsiteDataItem; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 44 | import com.android.contacts.util.PhoneCapabilityTester; |
| 45 | import com.android.contacts.util.StructuredPostalUtils; |
| 46 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 47 | /** |
| 48 | * Description of a specific {@link Data#_ID} item, with style information |
| 49 | * defined by a {@link DataKind}. |
| 50 | */ |
| 51 | public class DataAction implements Action { |
| 52 | private static final String TAG = "DataAction"; |
| 53 | |
| 54 | private final Context mContext; |
| 55 | private final DataKind mKind; |
| 56 | private final String mMimeType; |
| 57 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 58 | private CharSequence mBody; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 59 | private CharSequence mSubtitle; |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 60 | private Intent mIntent; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 61 | private Intent mAlternateIntent; |
Katherine Kuan | ee05dcd | 2011-10-05 20:18:12 -0700 | [diff] [blame] | 62 | private int mAlternateIconDescriptionRes; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 63 | private int mAlternateIconRes; |
Daniel Lehmann | 9daca14 | 2011-12-20 11:41:22 +0200 | [diff] [blame] | 64 | private int mPresence = -1; |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 65 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 66 | private Uri mDataUri; |
Daniel Lehmann | 0f78e8b | 2010-11-24 17:32:03 -0800 | [diff] [blame] | 67 | private long mDataId; |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 68 | private boolean mIsPrimary; |
| 69 | |
| 70 | /** |
| 71 | * Create an action from common {@link Data} elements. |
| 72 | */ |
Chiao Cheng | 47b6f70 | 2012-09-07 17:28:17 -0700 | [diff] [blame] | 73 | public DataAction(Context context, DataItem item, DataKind kind) { |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 74 | mContext = context; |
Chiao Cheng | 47b6f70 | 2012-09-07 17:28:17 -0700 | [diff] [blame] | 75 | mKind = kind; |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 76 | mMimeType = item.getMimeType(); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 77 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 78 | // Determine type for subtitle |
| 79 | mSubtitle = ""; |
Chiao Cheng | 47b6f70 | 2012-09-07 17:28:17 -0700 | [diff] [blame] | 80 | if (item.hasKindTypeColumn(kind)) { |
| 81 | final int typeValue = item.getKindTypeColumn(kind); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 82 | |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 83 | // get type string |
Chiao Cheng | 47b6f70 | 2012-09-07 17:28:17 -0700 | [diff] [blame] | 84 | for (EditType type : kind.typeList) { |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 85 | if (type.rawValue == typeValue) { |
| 86 | if (type.customColumn == null) { |
| 87 | // Non-custom type. Get its description from the resource |
| 88 | mSubtitle = context.getString(type.labelRes); |
| 89 | } else { |
| 90 | // Custom type. Read it from the database |
| 91 | mSubtitle = item.getContentValues().getAsString(type.customColumn); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 92 | } |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 93 | break; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 94 | } |
| 95 | } |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 98 | mIsPrimary = item.isSuperPrimary(); |
Yorke Lee | b2b435a | 2012-11-12 16:47:06 -0800 | [diff] [blame] | 99 | mBody = item.buildDataStringForDisplay(context, kind); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 100 | |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 101 | mDataId = item.getId(); |
| 102 | mDataUri = ContentUris.withAppendedId(Data.CONTENT_URI, mDataId); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 103 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 104 | final boolean hasPhone = PhoneCapabilityTester.isPhone(mContext); |
| 105 | final boolean hasSms = PhoneCapabilityTester.isSmsIntentRegistered(mContext); |
| 106 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 107 | // Handle well-known MIME-types with special care |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 108 | if (item instanceof PhoneDataItem) { |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 109 | if (PhoneCapabilityTester.isPhone(mContext)) { |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 110 | PhoneDataItem phone = (PhoneDataItem) item; |
| 111 | final String number = phone.getNumber(); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 112 | if (!TextUtils.isEmpty(number)) { |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 113 | |
Chiao Cheng | 3a8df86 | 2012-09-04 16:30:17 -0700 | [diff] [blame] | 114 | final Intent phoneIntent = hasPhone ? CallUtil.getCallIntent(number) |
Daisuke Miyakawa | fadd5e1 | 2011-12-01 17:34:18 -0800 | [diff] [blame] | 115 | : null; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 116 | final Intent smsIntent = hasSms ? new Intent(Intent.ACTION_SENDTO, |
Chiao Cheng | 3a8df86 | 2012-09-04 16:30:17 -0700 | [diff] [blame] | 117 | Uri.fromParts(CallUtil.SCHEME_SMSTO, number, null)) : null; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 118 | |
| 119 | // Configure Icons and Intents. Notice actionIcon is already set to the phone |
| 120 | if (hasPhone && hasSms) { |
| 121 | mIntent = phoneIntent; |
| 122 | mAlternateIntent = smsIntent; |
Chiao Cheng | 47b6f70 | 2012-09-07 17:28:17 -0700 | [diff] [blame] | 123 | mAlternateIconRes = kind.iconAltRes; |
| 124 | mAlternateIconDescriptionRes = kind.iconAltDescriptionRes; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 125 | } else if (hasPhone) { |
| 126 | mIntent = phoneIntent; |
| 127 | } else if (hasSms) { |
| 128 | mIntent = smsIntent; |
| 129 | } |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 130 | } |
| 131 | } |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 132 | } else if (item instanceof SipAddressDataItem) { |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 133 | if (PhoneCapabilityTester.isSipPhone(mContext)) { |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 134 | final SipAddressDataItem sip = (SipAddressDataItem) item; |
| 135 | final String address = sip.getSipAddress(); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 136 | if (!TextUtils.isEmpty(address)) { |
Chiao Cheng | 3a8df86 | 2012-09-04 16:30:17 -0700 | [diff] [blame] | 137 | final Uri callUri = Uri.fromParts(CallUtil.SCHEME_SIP, address, null); |
| 138 | mIntent = CallUtil.getCallIntent(callUri); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 139 | // Note that this item will get a SIP-specific variant |
| 140 | // of the "call phone" icon, rather than the standard |
| 141 | // app icon for the Phone app (which we show for |
| 142 | // regular phone numbers.) That's because the phone |
| 143 | // app explicitly specifies an android:icon attribute |
| 144 | // for the SIP-related intent-filters in its manifest. |
| 145 | } |
| 146 | } |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 147 | } else if (item instanceof EmailDataItem) { |
| 148 | final EmailDataItem email = (EmailDataItem) item; |
| 149 | final String address = email.getData(); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 150 | if (!TextUtils.isEmpty(address)) { |
Chiao Cheng | 3a8df86 | 2012-09-04 16:30:17 -0700 | [diff] [blame] | 151 | final Uri mailUri = Uri.fromParts(CallUtil.SCHEME_MAILTO, address, null); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 152 | mIntent = new Intent(Intent.ACTION_SENDTO, mailUri); |
| 153 | } |
| 154 | |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 155 | } else if (item instanceof WebsiteDataItem) { |
| 156 | final WebsiteDataItem website = (WebsiteDataItem) item; |
| 157 | final String url = website.getUrl(); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 158 | if (!TextUtils.isEmpty(url)) { |
Dmitri Plotnikov | 15dcf1d | 2010-12-09 17:12:54 -0800 | [diff] [blame] | 159 | WebAddress webAddress = new WebAddress(url); |
| 160 | mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString())); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 163 | } else if (item instanceof ImDataItem) { |
| 164 | ImDataItem im = (ImDataItem) item; |
| 165 | final boolean isEmail = im.isCreatedFromEmail(); |
| 166 | if (isEmail || im.isProtocolValid()) { |
| 167 | final int protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol(); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 168 | |
| 169 | if (isEmail) { |
| 170 | // Use Google Talk string when using Email, and clear data |
| 171 | // Uri so we don't try saving Email as primary. |
Daniel Lehmann | 9daca14 | 2011-12-20 11:41:22 +0200 | [diff] [blame] | 172 | mSubtitle = Im.getProtocolLabel(context.getResources(), Im.PROTOCOL_GOOGLE_TALK, |
| 173 | null); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 174 | mDataUri = null; |
| 175 | } |
| 176 | |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 177 | String host = im.getCustomProtocol(); |
| 178 | String data = im.getData(); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 179 | if (protocol != Im.PROTOCOL_CUSTOM) { |
| 180 | // Try bringing in a well-known host for specific protocols |
| 181 | host = ContactsUtils.lookupProviderNameFromId(protocol); |
| 182 | } |
| 183 | |
Daisuke Miyakawa | f31df5d | 2011-08-02 15:37:50 -0700 | [diff] [blame] | 184 | if (!TextUtils.isEmpty(host) && !TextUtils.isEmpty(data)) { |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 185 | final String authority = host.toLowerCase(); |
Chiao Cheng | 3a8df86 | 2012-09-04 16:30:17 -0700 | [diff] [blame] | 186 | final Uri imUri = new Uri.Builder().scheme(CallUtil.SCHEME_IMTO).authority( |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 187 | authority).appendPath(data).build(); |
| 188 | mIntent = new Intent(Intent.ACTION_SENDTO, imUri); |
Daisuke Miyakawa | f31df5d | 2011-08-02 15:37:50 -0700 | [diff] [blame] | 189 | |
| 190 | // If the address is also available for a video chat, we'll show the capability |
| 191 | // as a secondary action. |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 192 | final int chatCapability = im.getChatCapability(); |
Daisuke Miyakawa | f31df5d | 2011-08-02 15:37:50 -0700 | [diff] [blame] | 193 | final boolean isVideoChatCapable = |
| 194 | (chatCapability & Im.CAPABILITY_HAS_CAMERA) != 0; |
| 195 | final boolean isAudioChatCapable = |
| 196 | (chatCapability & Im.CAPABILITY_HAS_VOICE) != 0; |
| 197 | if (isVideoChatCapable || isAudioChatCapable) { |
Daisuke Miyakawa | f31df5d | 2011-08-02 15:37:50 -0700 | [diff] [blame] | 198 | mAlternateIntent = new Intent( |
| 199 | Intent.ACTION_SENDTO, Uri.parse("xmpp:" + data + "?call")); |
Katherine Kuan | ee05dcd | 2011-10-05 20:18:12 -0700 | [diff] [blame] | 200 | if (isVideoChatCapable) { |
| 201 | mAlternateIconRes = R.drawable.sym_action_videochat_holo_light; |
| 202 | mAlternateIconDescriptionRes = R.string.video_chat; |
| 203 | } else { |
| 204 | mAlternateIconRes = R.drawable.sym_action_audiochat_holo_light; |
| 205 | mAlternateIconDescriptionRes = R.string.audio_chat; |
| 206 | } |
Daisuke Miyakawa | f31df5d | 2011-08-02 15:37:50 -0700 | [diff] [blame] | 207 | } |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 208 | } |
| 209 | } |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 210 | } else if (item instanceof StructuredPostalDataItem) { |
| 211 | StructuredPostalDataItem postal = (StructuredPostalDataItem) item; |
| 212 | final String postalAddress = postal.getFormattedAddress(); |
Makoto Onuki | bfb59d8 | 2011-09-30 16:34:38 -0700 | [diff] [blame] | 213 | if (!TextUtils.isEmpty(postalAddress)) { |
| 214 | mIntent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress); |
| 215 | } |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | if (mIntent == null) { |
| 219 | // Otherwise fall back to default VIEW action |
Dmitri Plotnikov | 1b89adc | 2010-12-09 17:05:54 -0800 | [diff] [blame] | 220 | mIntent = new Intent(Intent.ACTION_VIEW); |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 221 | mIntent.setDataAndType(mDataUri, item.getMimeType()); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 222 | } |
| 223 | |
Adam Powell | 8ca93ed | 2012-04-23 13:28:28 -0700 | [diff] [blame] | 224 | mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 225 | } |
| 226 | |
Daniel Lehmann | 9daca14 | 2011-12-20 11:41:22 +0200 | [diff] [blame] | 227 | @Override |
| 228 | public int getPresence() { |
| 229 | return mPresence; |
| 230 | } |
| 231 | |
| 232 | public void setPresence(int presence) { |
| 233 | mPresence = presence; |
| 234 | } |
| 235 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 236 | @Override |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 237 | public CharSequence getSubtitle() { |
| 238 | return mSubtitle; |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 241 | @Override |
| 242 | public CharSequence getBody() { |
| 243 | return mBody; |
| 244 | } |
| 245 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 246 | @Override |
| 247 | public String getMimeType() { |
| 248 | return mMimeType; |
| 249 | } |
| 250 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 251 | @Override |
| 252 | public Uri getDataUri() { |
| 253 | return mDataUri; |
| 254 | } |
| 255 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 256 | @Override |
Daniel Lehmann | 0f78e8b | 2010-11-24 17:32:03 -0800 | [diff] [blame] | 257 | public long getDataId() { |
| 258 | return mDataId; |
| 259 | } |
| 260 | |
Daniel Lehmann | 0f78e8b | 2010-11-24 17:32:03 -0800 | [diff] [blame] | 261 | @Override |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 262 | public Boolean isPrimary() { |
| 263 | return mIsPrimary; |
| 264 | } |
| 265 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 266 | @Override |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 267 | public Drawable getAlternateIcon() { |
| 268 | if (mAlternateIconRes == 0) return null; |
| 269 | |
Makoto Onuki | 82a4f44 | 2012-05-07 17:18:33 -0700 | [diff] [blame] | 270 | final String resourcePackageName = mKind.resourcePackageName; |
| 271 | if (resourcePackageName == null) { |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 272 | return mContext.getResources().getDrawable(mAlternateIconRes); |
| 273 | } |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 274 | |
| 275 | final PackageManager pm = mContext.getPackageManager(); |
Makoto Onuki | 82a4f44 | 2012-05-07 17:18:33 -0700 | [diff] [blame] | 276 | return pm.getDrawable(resourcePackageName, mAlternateIconRes, null); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 279 | @Override |
Katherine Kuan | ee05dcd | 2011-10-05 20:18:12 -0700 | [diff] [blame] | 280 | public String getAlternateIconDescription() { |
| 281 | if (mAlternateIconDescriptionRes == 0) return null; |
| 282 | return mContext.getResources().getString(mAlternateIconDescriptionRes); |
| 283 | } |
| 284 | |
| 285 | @Override |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 286 | public Intent getIntent() { |
| 287 | return mIntent; |
| 288 | } |
| 289 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 290 | @Override |
| 291 | public Intent getAlternateIntent() { |
| 292 | return mAlternateIntent; |
| 293 | } |
| 294 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 295 | @Override |
Jay Shrauner | ad29eae | 2013-01-08 11:42:17 -0800 | [diff] [blame^] | 296 | public void collapseWith(Action other) { |
| 297 | // No-op |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 300 | @Override |
| 301 | public boolean shouldCollapseWith(Action t) { |
| 302 | if (t == null) { |
| 303 | return false; |
| 304 | } |
| 305 | if (!(t instanceof DataAction)) { |
| 306 | Log.e(TAG, "t must be DataAction"); |
| 307 | return false; |
| 308 | } |
Daniel Lehmann | 69fad28 | 2011-08-28 21:15:27 -0700 | [diff] [blame] | 309 | DataAction that = (DataAction)t; |
Chiao Cheng | d7ca03e | 2012-10-24 15:14:08 -0700 | [diff] [blame] | 310 | if (!MoreContactUtils.shouldCollapse(mMimeType, mBody, that.mMimeType, that.mBody)) { |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 311 | return false; |
| 312 | } |
Daniel Lehmann | 69fad28 | 2011-08-28 21:15:27 -0700 | [diff] [blame] | 313 | if (!TextUtils.equals(mMimeType, that.mMimeType) |
| 314 | || !ContactsUtils.areIntentActionEqual(mIntent, that.mIntent)) { |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 315 | return false; |
| 316 | } |
| 317 | return true; |
| 318 | } |
| 319 | } |