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; |
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; |
Tyler Gunn | 0319222 | 2014-09-10 15:20:09 -0700 | [diff] [blame] | 28 | import android.telecom.PhoneAccount; |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 29 | import android.text.TextUtils; |
| 30 | import android.util.Log; |
| 31 | |
Paul Soulos | 1633933 | 2014-06-24 13:59:56 -0700 | [diff] [blame] | 32 | import com.android.contacts.R; |
Chiao Cheng | 3a8df86 | 2012-09-04 16:30:17 -0700 | [diff] [blame] | 33 | import com.android.contacts.common.CallUtil; |
Yorke Lee | cd321f6 | 2013-10-28 15:20:15 -0700 | [diff] [blame] | 34 | import com.android.contacts.common.ContactsUtils; |
Chiao Cheng | d7ca03e | 2012-10-24 15:14:08 -0700 | [diff] [blame] | 35 | import com.android.contacts.common.MoreContactUtils; |
Chiao Cheng | 428f008 | 2012-11-13 18:38:56 -0800 | [diff] [blame] | 36 | import com.android.contacts.common.model.account.AccountType.EditType; |
Yorke Lee | cd321f6 | 2013-10-28 15:20:15 -0700 | [diff] [blame] | 37 | import com.android.contacts.common.model.dataitem.DataItem; |
Chiao Cheng | 428f008 | 2012-11-13 18:38:56 -0800 | [diff] [blame] | 38 | import com.android.contacts.common.model.dataitem.DataKind; |
Yorke Lee | cd321f6 | 2013-10-28 15:20:15 -0700 | [diff] [blame] | 39 | import com.android.contacts.common.model.dataitem.EmailDataItem; |
| 40 | import com.android.contacts.common.model.dataitem.ImDataItem; |
| 41 | import com.android.contacts.common.model.dataitem.PhoneDataItem; |
| 42 | import com.android.contacts.common.model.dataitem.SipAddressDataItem; |
| 43 | import com.android.contacts.common.model.dataitem.StructuredPostalDataItem; |
| 44 | import com.android.contacts.common.model.dataitem.WebsiteDataItem; |
Brian Attwell | 493f8d1 | 2014-12-18 12:42:03 -0800 | [diff] [blame] | 45 | import com.android.contacts.quickcontact.WebAddress.ParseException; |
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)) { |
Brian Attwell | 493f8d1 | 2014-12-18 12:42:03 -0800 | [diff] [blame] | 172 | try { |
| 173 | final WebAddress webAddress = new WebAddress(url); |
| 174 | mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString())); |
| 175 | } catch (ParseException e) { |
| 176 | mIntent = null; |
| 177 | } |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 180 | } else if (item instanceof ImDataItem) { |
| 181 | ImDataItem im = (ImDataItem) item; |
| 182 | final boolean isEmail = im.isCreatedFromEmail(); |
| 183 | if (isEmail || im.isProtocolValid()) { |
| 184 | final int protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol(); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 185 | |
| 186 | if (isEmail) { |
| 187 | // Use Google Talk string when using Email, and clear data |
| 188 | // Uri so we don't try saving Email as primary. |
Daniel Lehmann | 9daca14 | 2011-12-20 11:41:22 +0200 | [diff] [blame] | 189 | mSubtitle = Im.getProtocolLabel(context.getResources(), Im.PROTOCOL_GOOGLE_TALK, |
| 190 | null); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 191 | mDataUri = null; |
| 192 | } |
| 193 | |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 194 | String host = im.getCustomProtocol(); |
| 195 | String data = im.getData(); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 196 | if (protocol != Im.PROTOCOL_CUSTOM) { |
| 197 | // Try bringing in a well-known host for specific protocols |
| 198 | host = ContactsUtils.lookupProviderNameFromId(protocol); |
| 199 | } |
| 200 | |
Daisuke Miyakawa | f31df5d | 2011-08-02 15:37:50 -0700 | [diff] [blame] | 201 | if (!TextUtils.isEmpty(host) && !TextUtils.isEmpty(data)) { |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 202 | final String authority = host.toLowerCase(); |
Jay Shrauner | 1cd88e3 | 2014-09-05 15:37:55 -0700 | [diff] [blame] | 203 | final Uri imUri = new Uri.Builder().scheme(ContactsUtils.SCHEME_IMTO).authority( |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 204 | authority).appendPath(data).build(); |
| 205 | mIntent = new Intent(Intent.ACTION_SENDTO, imUri); |
Daisuke Miyakawa | f31df5d | 2011-08-02 15:37:50 -0700 | [diff] [blame] | 206 | |
| 207 | // If the address is also available for a video chat, we'll show the capability |
| 208 | // as a secondary action. |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 209 | final int chatCapability = im.getChatCapability(); |
Daisuke Miyakawa | f31df5d | 2011-08-02 15:37:50 -0700 | [diff] [blame] | 210 | final boolean isVideoChatCapable = |
| 211 | (chatCapability & Im.CAPABILITY_HAS_CAMERA) != 0; |
| 212 | final boolean isAudioChatCapable = |
| 213 | (chatCapability & Im.CAPABILITY_HAS_VOICE) != 0; |
| 214 | if (isVideoChatCapable || isAudioChatCapable) { |
Daisuke Miyakawa | f31df5d | 2011-08-02 15:37:50 -0700 | [diff] [blame] | 215 | mAlternateIntent = new Intent( |
| 216 | Intent.ACTION_SENDTO, Uri.parse("xmpp:" + data + "?call")); |
Katherine Kuan | ee05dcd | 2011-10-05 20:18:12 -0700 | [diff] [blame] | 217 | if (isVideoChatCapable) { |
| 218 | mAlternateIconRes = R.drawable.sym_action_videochat_holo_light; |
| 219 | mAlternateIconDescriptionRes = R.string.video_chat; |
| 220 | } else { |
| 221 | mAlternateIconRes = R.drawable.sym_action_audiochat_holo_light; |
| 222 | mAlternateIconDescriptionRes = R.string.audio_chat; |
| 223 | } |
Daisuke Miyakawa | f31df5d | 2011-08-02 15:37:50 -0700 | [diff] [blame] | 224 | } |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 225 | } |
| 226 | } |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 227 | } else if (item instanceof StructuredPostalDataItem) { |
| 228 | StructuredPostalDataItem postal = (StructuredPostalDataItem) item; |
| 229 | final String postalAddress = postal.getFormattedAddress(); |
Makoto Onuki | bfb59d8 | 2011-09-30 16:34:38 -0700 | [diff] [blame] | 230 | if (!TextUtils.isEmpty(postalAddress)) { |
| 231 | mIntent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress); |
| 232 | } |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | if (mIntent == null) { |
| 236 | // Otherwise fall back to default VIEW action |
Dmitri Plotnikov | 1b89adc | 2010-12-09 17:05:54 -0800 | [diff] [blame] | 237 | mIntent = new Intent(Intent.ACTION_VIEW); |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 238 | mIntent.setDataAndType(mDataUri, item.getMimeType()); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Adam Powell | 8ca93ed | 2012-04-23 13:28:28 -0700 | [diff] [blame] | 241 | mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Daniel Lehmann | 9daca14 | 2011-12-20 11:41:22 +0200 | [diff] [blame] | 244 | @Override |
| 245 | public int getPresence() { |
| 246 | return mPresence; |
| 247 | } |
| 248 | |
| 249 | public void setPresence(int presence) { |
| 250 | mPresence = presence; |
| 251 | } |
| 252 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 253 | @Override |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 254 | public CharSequence getSubtitle() { |
| 255 | return mSubtitle; |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 258 | @Override |
| 259 | public CharSequence getBody() { |
| 260 | return mBody; |
| 261 | } |
| 262 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 263 | @Override |
| 264 | public String getMimeType() { |
| 265 | return mMimeType; |
| 266 | } |
| 267 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 268 | @Override |
| 269 | public Uri getDataUri() { |
| 270 | return mDataUri; |
| 271 | } |
| 272 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 273 | @Override |
Daniel Lehmann | 0f78e8b | 2010-11-24 17:32:03 -0800 | [diff] [blame] | 274 | public long getDataId() { |
| 275 | return mDataId; |
| 276 | } |
| 277 | |
Daniel Lehmann | 0f78e8b | 2010-11-24 17:32:03 -0800 | [diff] [blame] | 278 | @Override |
Paul Soulos | 1633933 | 2014-06-24 13:59:56 -0700 | [diff] [blame] | 279 | public boolean isPrimary() { |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 280 | return mIsPrimary; |
| 281 | } |
| 282 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 283 | @Override |
Paul Soulos | 1633933 | 2014-06-24 13:59:56 -0700 | [diff] [blame] | 284 | public boolean isSuperPrimary() { |
| 285 | return mIsSuperPrimary; |
| 286 | } |
| 287 | |
| 288 | @Override |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 289 | public Drawable getAlternateIcon() { |
| 290 | if (mAlternateIconRes == 0) return null; |
| 291 | |
Makoto Onuki | 82a4f44 | 2012-05-07 17:18:33 -0700 | [diff] [blame] | 292 | final String resourcePackageName = mKind.resourcePackageName; |
| 293 | if (resourcePackageName == null) { |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 294 | return mContext.getResources().getDrawable(mAlternateIconRes); |
| 295 | } |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 296 | |
| 297 | final PackageManager pm = mContext.getPackageManager(); |
Makoto Onuki | 82a4f44 | 2012-05-07 17:18:33 -0700 | [diff] [blame] | 298 | return pm.getDrawable(resourcePackageName, mAlternateIconRes, null); |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 301 | @Override |
Katherine Kuan | ee05dcd | 2011-10-05 20:18:12 -0700 | [diff] [blame] | 302 | public String getAlternateIconDescription() { |
| 303 | if (mAlternateIconDescriptionRes == 0) return null; |
| 304 | return mContext.getResources().getString(mAlternateIconDescriptionRes); |
| 305 | } |
| 306 | |
| 307 | @Override |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 308 | public Intent getIntent() { |
| 309 | return mIntent; |
| 310 | } |
| 311 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 312 | @Override |
| 313 | public Intent getAlternateIntent() { |
| 314 | return mAlternateIntent; |
| 315 | } |
| 316 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 317 | @Override |
Jay Shrauner | ad29eae | 2013-01-08 11:42:17 -0800 | [diff] [blame] | 318 | public void collapseWith(Action other) { |
| 319 | // No-op |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 322 | @Override |
Paul Soulos | 0646ee3 | 2014-06-26 16:40:28 -0700 | [diff] [blame] | 323 | public boolean shouldCollapseWith(Action t, Context context) { |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 324 | if (t == null) { |
| 325 | return false; |
| 326 | } |
| 327 | if (!(t instanceof DataAction)) { |
| 328 | Log.e(TAG, "t must be DataAction"); |
| 329 | return false; |
| 330 | } |
Daniel Lehmann | 69fad28 | 2011-08-28 21:15:27 -0700 | [diff] [blame] | 331 | DataAction that = (DataAction)t; |
Chiao Cheng | d7ca03e | 2012-10-24 15:14:08 -0700 | [diff] [blame] | 332 | if (!MoreContactUtils.shouldCollapse(mMimeType, mBody, that.mMimeType, that.mBody)) { |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 333 | return false; |
| 334 | } |
Daniel Lehmann | 69fad28 | 2011-08-28 21:15:27 -0700 | [diff] [blame] | 335 | if (!TextUtils.equals(mMimeType, that.mMimeType) |
| 336 | || !ContactsUtils.areIntentActionEqual(mIntent, that.mIntent)) { |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 337 | return false; |
| 338 | } |
| 339 | return true; |
| 340 | } |
Paul Soulos | 1633933 | 2014-06-24 13:59:56 -0700 | [diff] [blame] | 341 | |
| 342 | @Override |
| 343 | public Integer getTimesUsed() { |
| 344 | return mTimesUsed; |
| 345 | } |
| 346 | |
| 347 | @Override |
| 348 | public Long getLastTimeUsed() { |
| 349 | return mLastTimeUsed; |
| 350 | } |
Daniel Lehmann | af8e386 | 2010-11-19 15:38:44 -0800 | [diff] [blame] | 351 | } |