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