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