Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 1 | /* |
Daniel Lehmann | ef3f8f0 | 2010-07-26 18:55:25 -0700 | [diff] [blame] | 2 | * Copyright (C) 2010 The Android Open Source Project |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 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 | |
Dmitri Plotnikov | 18ffaa2 | 2010-12-03 14:28:00 -0800 | [diff] [blame] | 17 | package com.android.contacts; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 18 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 19 | import com.android.contacts.util.DataStatus; |
| 20 | |
| 21 | import android.content.ContentResolver; |
| 22 | import android.content.ContentUris; |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 23 | import android.content.ContentValues; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.content.Entity; |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 26 | import android.content.Entity.NamedContentValues; |
Jeff Hamilton | 3c46291 | 2010-05-15 02:20:01 -0500 | [diff] [blame] | 27 | import android.content.Loader; |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManager; |
| 29 | import android.content.pm.PackageManager.NameNotFoundException; |
| 30 | import android.content.res.Resources; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 31 | import android.database.Cursor; |
| 32 | import android.net.Uri; |
| 33 | import android.os.AsyncTask; |
Daniel Lehmann | 1316b13 | 2010-04-13 15:08:53 -0700 | [diff] [blame] | 34 | import android.provider.ContactsContract; |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 35 | import android.provider.ContactsContract.CommonDataKinds.GroupMembership; |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 36 | import android.provider.ContactsContract.CommonDataKinds.Photo; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 37 | import android.provider.ContactsContract.Contacts; |
| 38 | import android.provider.ContactsContract.Data; |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 39 | import android.provider.ContactsContract.Directory; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 40 | import android.provider.ContactsContract.DisplayNameSources; |
Dmitri Plotnikov | 2deaee1 | 2010-09-15 15:42:08 -0700 | [diff] [blame] | 41 | import android.provider.ContactsContract.Groups; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 42 | import android.provider.ContactsContract.RawContacts; |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 43 | import android.text.TextUtils; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 44 | import android.util.Log; |
| 45 | |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 46 | import java.io.ByteArrayOutputStream; |
| 47 | import java.io.IOException; |
| 48 | import java.io.InputStream; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 49 | import java.util.ArrayList; |
| 50 | import java.util.HashMap; |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 51 | import java.util.List; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Loads a single Contact and all it constituent RawContacts. |
| 55 | */ |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 56 | public class ContactLoader extends Loader<ContactLoader.Result> { |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 57 | private static final String TAG = "ContactLoader"; |
| 58 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 59 | private Uri mLookupUri; |
Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 60 | private boolean mLoadGroupMetaData; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 61 | private Result mContact; |
| 62 | private ForceLoadContentObserver mObserver; |
| 63 | private boolean mDestroyed; |
| 64 | |
Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 65 | |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 66 | public interface Listener { |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 67 | public void onContactLoaded(Result contact); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * The result of a load operation. Contains all data necessary to display the contact. |
| 72 | */ |
| 73 | public static final class Result { |
| 74 | /** |
| 75 | * Singleton instance that represents "No Contact Found" |
| 76 | */ |
| 77 | public static final Result NOT_FOUND = new Result(); |
| 78 | |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 79 | /** |
| 80 | * Singleton instance that represents an error, e.g. because of an invalid Uri |
| 81 | * TODO: We should come up with something nicer here. Maybe use an Either type so |
| 82 | * that we can capture the Exception? |
| 83 | */ |
| 84 | public static final Result ERROR = new Result(); |
| 85 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 86 | private final Uri mLookupUri; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 87 | private final Uri mUri; |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 88 | private final long mDirectoryId; |
| 89 | private final String mLookupKey; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 90 | private final long mId; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 91 | private final long mNameRawContactId; |
| 92 | private final int mDisplayNameSource; |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 93 | private final long mPhotoId; |
Dmitri Plotnikov | f9eb73f | 2010-10-21 11:48:56 -0700 | [diff] [blame] | 94 | private final String mPhotoUri; |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 95 | private final String mDisplayName; |
| 96 | private final String mPhoneticName; |
| 97 | private final boolean mStarred; |
| 98 | private final Integer mPresence; |
| 99 | private final ArrayList<Entity> mEntities; |
| 100 | private final HashMap<Long, DataStatus> mStatuses; |
| 101 | private final String mStatus; |
| 102 | private final Long mStatusTimestamp; |
| 103 | private final Integer mStatusLabel; |
| 104 | private final String mStatusResPackage; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 105 | |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 106 | private String mDirectoryDisplayName; |
| 107 | private String mDirectoryType; |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 108 | private String mDirectoryAccountType; |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 109 | private String mDirectoryAccountName; |
| 110 | private int mDirectoryExportSupport; |
| 111 | |
Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 112 | private ArrayList<GroupMetaData> mGroups; |
Dmitri Plotnikov | 2deaee1 | 2010-09-15 15:42:08 -0700 | [diff] [blame] | 113 | |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 114 | private boolean mLoadingPhoto; |
| 115 | private byte[] mPhotoBinaryData; |
| 116 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 117 | /** |
| 118 | * Constructor for case "no contact found". This must only be used for the |
| 119 | * final {@link Result#NOT_FOUND} singleton |
| 120 | */ |
| 121 | private Result() { |
| 122 | mLookupUri = null; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 123 | mUri = null; |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 124 | mDirectoryId = -1; |
| 125 | mLookupKey = null; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 126 | mId = -1; |
| 127 | mEntities = null; |
| 128 | mStatuses = null; |
| 129 | mNameRawContactId = -1; |
| 130 | mDisplayNameSource = DisplayNameSources.UNDEFINED; |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 131 | mPhotoId = -1; |
Dmitri Plotnikov | f9eb73f | 2010-10-21 11:48:56 -0700 | [diff] [blame] | 132 | mPhotoUri = null; |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 133 | mDisplayName = null; |
| 134 | mPhoneticName = null; |
| 135 | mStarred = false; |
| 136 | mPresence = null; |
| 137 | mStatus = null; |
| 138 | mStatusTimestamp = null; |
| 139 | mStatusLabel = null; |
| 140 | mStatusResPackage = null; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Constructor to call when contact was found |
| 145 | */ |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 146 | private Result(Uri uri, Uri lookupUri, long directoryId, String lookupKey, long id, |
Dmitri Plotnikov | f9eb73f | 2010-10-21 11:48:56 -0700 | [diff] [blame] | 147 | long nameRawContactId, int displayNameSource, long photoId, String photoUri, |
| 148 | String displayName, String phoneticName, boolean starred, Integer presence, |
| 149 | String status, Long statusTimestamp, Integer statusLabel, String statusResPackage) { |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 150 | mLookupUri = lookupUri; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 151 | mUri = uri; |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 152 | mDirectoryId = directoryId; |
| 153 | mLookupKey = lookupKey; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 154 | mId = id; |
| 155 | mEntities = new ArrayList<Entity>(); |
| 156 | mStatuses = new HashMap<Long, DataStatus>(); |
| 157 | mNameRawContactId = nameRawContactId; |
| 158 | mDisplayNameSource = displayNameSource; |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 159 | mPhotoId = photoId; |
Dmitri Plotnikov | f9eb73f | 2010-10-21 11:48:56 -0700 | [diff] [blame] | 160 | mPhotoUri = photoUri; |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 161 | mDisplayName = displayName; |
| 162 | mPhoneticName = phoneticName; |
| 163 | mStarred = starred; |
| 164 | mPresence = presence; |
| 165 | mStatus = status; |
| 166 | mStatusTimestamp = statusTimestamp; |
| 167 | mStatusLabel = statusLabel; |
| 168 | mStatusResPackage = statusResPackage; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Dmitri Plotnikov | 7cee774 | 2011-01-13 17:11:06 -0800 | [diff] [blame] | 171 | private Result(Result from) { |
| 172 | mLookupUri = from.mLookupUri; |
| 173 | mUri = from.mUri; |
| 174 | mDirectoryId = from.mDirectoryId; |
| 175 | mLookupKey = from.mLookupKey; |
| 176 | mId = from.mId; |
| 177 | mNameRawContactId = from.mNameRawContactId; |
| 178 | mDisplayNameSource = from.mDisplayNameSource; |
| 179 | mPhotoId = from.mPhotoId; |
| 180 | mPhotoUri = from.mPhotoUri; |
| 181 | mDisplayName = from.mDisplayName; |
| 182 | mPhoneticName = from.mPhoneticName; |
| 183 | mStarred = from.mStarred; |
| 184 | mPresence = from.mPresence; |
| 185 | mEntities = from.mEntities; |
| 186 | mStatuses = from.mStatuses; |
| 187 | mStatus = from.mStatus; |
| 188 | mStatusTimestamp = from.mStatusTimestamp; |
| 189 | mStatusLabel = from.mStatusLabel; |
| 190 | mStatusResPackage = from.mStatusResPackage; |
| 191 | |
| 192 | mDirectoryDisplayName = from.mDirectoryDisplayName; |
| 193 | mDirectoryType = from.mDirectoryType; |
| 194 | mDirectoryAccountType = from.mDirectoryAccountType; |
| 195 | mDirectoryAccountName = from.mDirectoryAccountName; |
| 196 | mDirectoryExportSupport = from.mDirectoryExportSupport; |
| 197 | |
| 198 | mGroups = from.mGroups; |
| 199 | |
| 200 | mLoadingPhoto = from.mLoadingPhoto; |
| 201 | mPhotoBinaryData = from.mPhotoBinaryData; |
| 202 | } |
| 203 | |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 204 | /** |
| 205 | * @param exportSupport See {@link Directory#EXPORT_SUPPORT}. |
| 206 | */ |
Daniel Lehmann | 1ad4d1b | 2010-10-18 19:20:41 -0700 | [diff] [blame] | 207 | private void setDirectoryMetaData(String displayName, String directoryType, |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 208 | String accountType, String accountName, int exportSupport) { |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 209 | mDirectoryDisplayName = displayName; |
| 210 | mDirectoryType = directoryType; |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 211 | mDirectoryAccountType = accountType; |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 212 | mDirectoryAccountName = accountName; |
| 213 | mDirectoryExportSupport = exportSupport; |
| 214 | } |
| 215 | |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 216 | private void setLoadingPhoto(boolean flag) { |
| 217 | mLoadingPhoto = flag; |
| 218 | } |
| 219 | |
| 220 | private void setPhotoBinaryData(byte[] photoBinaryData) { |
| 221 | mPhotoBinaryData = photoBinaryData; |
| 222 | } |
| 223 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 224 | public Uri getLookupUri() { |
| 225 | return mLookupUri; |
| 226 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 227 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 228 | public String getLookupKey() { |
| 229 | return mLookupKey; |
| 230 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 231 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 232 | public Uri getUri() { |
| 233 | return mUri; |
| 234 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 235 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 236 | public long getId() { |
| 237 | return mId; |
| 238 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 239 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 240 | public long getNameRawContactId() { |
| 241 | return mNameRawContactId; |
| 242 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 243 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 244 | public int getDisplayNameSource() { |
| 245 | return mDisplayNameSource; |
| 246 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 247 | |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 248 | public long getPhotoId() { |
| 249 | return mPhotoId; |
| 250 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 251 | |
Dmitri Plotnikov | f9eb73f | 2010-10-21 11:48:56 -0700 | [diff] [blame] | 252 | public String getPhotoUri() { |
| 253 | return mPhotoUri; |
| 254 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 255 | |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 256 | public String getDisplayName() { |
| 257 | return mDisplayName; |
| 258 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 259 | |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 260 | public String getPhoneticName() { |
| 261 | return mPhoneticName; |
| 262 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 263 | |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 264 | public boolean getStarred() { |
| 265 | return mStarred; |
| 266 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 267 | |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 268 | public Integer getPresence() { |
| 269 | return mPresence; |
| 270 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 271 | |
Daniel Lehmann | 2d4f759 | 2010-10-12 23:31:31 -0700 | [diff] [blame] | 272 | public String getSocialSnippet() { |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 273 | return mStatus; |
| 274 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 275 | |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 276 | public Long getStatusTimestamp() { |
| 277 | return mStatusTimestamp; |
| 278 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 279 | |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 280 | public Integer getStatusLabel() { |
| 281 | return mStatusLabel; |
| 282 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 283 | |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 284 | public String getStatusResPackage() { |
| 285 | return mStatusResPackage; |
| 286 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 287 | |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 288 | public ArrayList<Entity> getEntities() { |
| 289 | return mEntities; |
| 290 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 291 | |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 292 | public HashMap<Long, DataStatus> getStatuses() { |
| 293 | return mStatuses; |
| 294 | } |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 295 | |
| 296 | public long getDirectoryId() { |
| 297 | return mDirectoryId; |
| 298 | } |
| 299 | |
| 300 | public boolean isDirectoryEntry() { |
Dmitri Plotnikov | 5f72c1f | 2010-09-01 21:21:04 -0700 | [diff] [blame] | 301 | return mDirectoryId != -1 && mDirectoryId != Directory.DEFAULT |
| 302 | && mDirectoryId != Directory.LOCAL_INVISIBLE; |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | public int getDirectoryExportSupport() { |
| 306 | return mDirectoryExportSupport; |
| 307 | } |
| 308 | |
| 309 | public String getDirectoryDisplayName() { |
| 310 | return mDirectoryDisplayName; |
| 311 | } |
| 312 | |
| 313 | public String getDirectoryType() { |
| 314 | return mDirectoryType; |
| 315 | } |
| 316 | |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 317 | public String getDirectoryAccountType() { |
| 318 | return mDirectoryAccountType; |
| 319 | } |
| 320 | |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 321 | public String getDirectoryAccountName() { |
| 322 | return mDirectoryAccountName; |
| 323 | } |
| 324 | |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 325 | public boolean isLoadingPhoto() { |
| 326 | return mLoadingPhoto; |
| 327 | } |
| 328 | |
| 329 | public byte[] getPhotoBinaryData() { |
| 330 | return mPhotoBinaryData; |
| 331 | } |
| 332 | |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 333 | public ArrayList<ContentValues> getContentValues() { |
| 334 | if (mEntities.size() != 1) { |
| 335 | throw new IllegalStateException( |
| 336 | "Cannot extract content values from an aggregated contact"); |
| 337 | } |
| 338 | |
| 339 | Entity entity = mEntities.get(0); |
| 340 | ArrayList<ContentValues> result = new ArrayList<ContentValues>(); |
| 341 | ArrayList<NamedContentValues> subValues = entity.getSubValues(); |
| 342 | if (subValues != null) { |
| 343 | int size = subValues.size(); |
| 344 | for (int i = 0; i < size; i++) { |
| 345 | NamedContentValues pair = subValues.get(i); |
| 346 | if (Data.CONTENT_URI.equals(pair.uri)) { |
| 347 | result.add(pair.values); |
| 348 | } |
| 349 | } |
| 350 | } |
Dmitri Plotnikov | 40ec3a8 | 2010-11-10 11:25:33 -0800 | [diff] [blame] | 351 | |
| 352 | // If the photo was loaded using the URI, create an entry for the photo |
| 353 | // binary data. |
| 354 | if (mPhotoId == 0 && mPhotoBinaryData != null) { |
| 355 | ContentValues photo = new ContentValues(); |
| 356 | photo.put(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE); |
| 357 | photo.put(Photo.PHOTO, mPhotoBinaryData); |
| 358 | result.add(photo); |
| 359 | } |
| 360 | |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 361 | return result; |
| 362 | } |
Dmitri Plotnikov | 2deaee1 | 2010-09-15 15:42:08 -0700 | [diff] [blame] | 363 | |
Daniel Lehmann | 1ad4d1b | 2010-10-18 19:20:41 -0700 | [diff] [blame] | 364 | private void addGroupMetaData(GroupMetaData group) { |
Dmitri Plotnikov | 2deaee1 | 2010-09-15 15:42:08 -0700 | [diff] [blame] | 365 | if (mGroups == null) { |
Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 366 | mGroups = new ArrayList<GroupMetaData>(); |
Dmitri Plotnikov | 2deaee1 | 2010-09-15 15:42:08 -0700 | [diff] [blame] | 367 | } |
| 368 | mGroups.add(group); |
| 369 | } |
| 370 | |
Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 371 | public List<GroupMetaData> getGroupMetaData() { |
Dmitri Plotnikov | 2deaee1 | 2010-09-15 15:42:08 -0700 | [diff] [blame] | 372 | return mGroups; |
| 373 | } |
| 374 | } |
| 375 | |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 376 | private static class ContactQuery { |
| 377 | // Projection used for the query that loads all data for the entire contact. |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 378 | final static String[] COLUMNS = new String[] { |
| 379 | Contacts.NAME_RAW_CONTACT_ID, |
| 380 | Contacts.DISPLAY_NAME_SOURCE, |
| 381 | Contacts.LOOKUP_KEY, |
| 382 | Contacts.DISPLAY_NAME, |
| 383 | Contacts.PHONETIC_NAME, |
| 384 | Contacts.PHOTO_ID, |
| 385 | Contacts.STARRED, |
| 386 | Contacts.CONTACT_PRESENCE, |
| 387 | Contacts.CONTACT_STATUS, |
| 388 | Contacts.CONTACT_STATUS_TIMESTAMP, |
| 389 | Contacts.CONTACT_STATUS_RES_PACKAGE, |
| 390 | Contacts.CONTACT_STATUS_LABEL, |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 391 | Contacts.Entity.CONTACT_ID, |
| 392 | Contacts.Entity.RAW_CONTACT_ID, |
| 393 | |
| 394 | RawContacts.ACCOUNT_NAME, |
| 395 | RawContacts.ACCOUNT_TYPE, |
| 396 | RawContacts.DIRTY, |
| 397 | RawContacts.VERSION, |
| 398 | RawContacts.SOURCE_ID, |
| 399 | RawContacts.SYNC1, |
| 400 | RawContacts.SYNC2, |
| 401 | RawContacts.SYNC3, |
| 402 | RawContacts.SYNC4, |
| 403 | RawContacts.DELETED, |
| 404 | RawContacts.IS_RESTRICTED, |
| 405 | RawContacts.NAME_VERIFIED, |
| 406 | |
| 407 | Contacts.Entity.DATA_ID, |
| 408 | Data.DATA1, |
| 409 | Data.DATA2, |
| 410 | Data.DATA3, |
| 411 | Data.DATA4, |
| 412 | Data.DATA5, |
| 413 | Data.DATA6, |
| 414 | Data.DATA7, |
| 415 | Data.DATA8, |
| 416 | Data.DATA9, |
| 417 | Data.DATA10, |
| 418 | Data.DATA11, |
| 419 | Data.DATA12, |
| 420 | Data.DATA13, |
| 421 | Data.DATA14, |
| 422 | Data.DATA15, |
| 423 | Data.SYNC1, |
| 424 | Data.SYNC2, |
| 425 | Data.SYNC3, |
| 426 | Data.SYNC4, |
| 427 | Data.DATA_VERSION, |
| 428 | Data.IS_PRIMARY, |
| 429 | Data.IS_SUPER_PRIMARY, |
| 430 | Data.MIMETYPE, |
| 431 | Data.RES_PACKAGE, |
| 432 | |
| 433 | GroupMembership.GROUP_SOURCE_ID, |
| 434 | |
| 435 | Data.PRESENCE, |
Daniel Lehmann | 8fd7bb6 | 2010-08-13 20:50:31 -0700 | [diff] [blame] | 436 | Data.CHAT_CAPABILITY, |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 437 | Data.STATUS, |
| 438 | Data.STATUS_RES_PACKAGE, |
| 439 | Data.STATUS_ICON, |
| 440 | Data.STATUS_LABEL, |
Dmitri Plotnikov | f9eb73f | 2010-10-21 11:48:56 -0700 | [diff] [blame] | 441 | Data.STATUS_TIMESTAMP, |
| 442 | |
| 443 | Contacts.PHOTO_URI, |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 444 | }; |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 445 | |
| 446 | public final static int NAME_RAW_CONTACT_ID = 0; |
| 447 | public final static int DISPLAY_NAME_SOURCE = 1; |
| 448 | public final static int LOOKUP_KEY = 2; |
| 449 | public final static int DISPLAY_NAME = 3; |
| 450 | public final static int PHONETIC_NAME = 4; |
| 451 | public final static int PHOTO_ID = 5; |
| 452 | public final static int STARRED = 6; |
| 453 | public final static int CONTACT_PRESENCE = 7; |
| 454 | public final static int CONTACT_STATUS = 8; |
| 455 | public final static int CONTACT_STATUS_TIMESTAMP = 9; |
| 456 | public final static int CONTACT_STATUS_RES_PACKAGE = 10; |
| 457 | public final static int CONTACT_STATUS_LABEL = 11; |
| 458 | public final static int CONTACT_ID = 12; |
| 459 | public final static int RAW_CONTACT_ID = 13; |
| 460 | |
| 461 | public final static int ACCOUNT_NAME = 14; |
| 462 | public final static int ACCOUNT_TYPE = 15; |
| 463 | public final static int DIRTY = 16; |
| 464 | public final static int VERSION = 17; |
| 465 | public final static int SOURCE_ID = 18; |
| 466 | public final static int SYNC1 = 19; |
| 467 | public final static int SYNC2 = 20; |
| 468 | public final static int SYNC3 = 21; |
| 469 | public final static int SYNC4 = 22; |
| 470 | public final static int DELETED = 23; |
| 471 | public final static int IS_RESTRICTED = 24; |
| 472 | public final static int NAME_VERIFIED = 25; |
| 473 | |
| 474 | public final static int DATA_ID = 26; |
| 475 | public final static int DATA1 = 27; |
| 476 | public final static int DATA2 = 28; |
| 477 | public final static int DATA3 = 29; |
| 478 | public final static int DATA4 = 30; |
| 479 | public final static int DATA5 = 31; |
| 480 | public final static int DATA6 = 32; |
| 481 | public final static int DATA7 = 33; |
| 482 | public final static int DATA8 = 34; |
| 483 | public final static int DATA9 = 35; |
| 484 | public final static int DATA10 = 36; |
| 485 | public final static int DATA11 = 37; |
| 486 | public final static int DATA12 = 38; |
| 487 | public final static int DATA13 = 39; |
| 488 | public final static int DATA14 = 40; |
| 489 | public final static int DATA15 = 41; |
| 490 | public final static int DATA_SYNC1 = 42; |
| 491 | public final static int DATA_SYNC2 = 43; |
| 492 | public final static int DATA_SYNC3 = 44; |
| 493 | public final static int DATA_SYNC4 = 45; |
| 494 | public final static int DATA_VERSION = 46; |
| 495 | public final static int IS_PRIMARY = 47; |
| 496 | public final static int IS_SUPERPRIMARY = 48; |
| 497 | public final static int MIMETYPE = 49; |
| 498 | public final static int RES_PACKAGE = 50; |
| 499 | |
| 500 | public final static int GROUP_SOURCE_ID = 51; |
| 501 | |
| 502 | public final static int PRESENCE = 52; |
Daniel Lehmann | 8fd7bb6 | 2010-08-13 20:50:31 -0700 | [diff] [blame] | 503 | public final static int CHAT_CAPABILITY = 53; |
| 504 | public final static int STATUS = 54; |
Dmitri Plotnikov | f9eb73f | 2010-10-21 11:48:56 -0700 | [diff] [blame] | 505 | public final static int STATUS_RES_PACKAGE = 55; |
| 506 | public final static int STATUS_ICON = 56; |
| 507 | public final static int STATUS_LABEL = 57; |
| 508 | public final static int STATUS_TIMESTAMP = 58; |
| 509 | |
| 510 | public final static int PHOTO_URI = 59; |
Daniel Lehmann | d3e0cdb | 2010-04-19 13:45:53 -0700 | [diff] [blame] | 511 | } |
Daniel Lehmann | 1316b13 | 2010-04-13 15:08:53 -0700 | [diff] [blame] | 512 | |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 513 | private static class DirectoryQuery { |
| 514 | // Projection used for the query that loads all data for the entire contact. |
| 515 | final static String[] COLUMNS = new String[] { |
| 516 | Directory.DISPLAY_NAME, |
| 517 | Directory.PACKAGE_NAME, |
| 518 | Directory.TYPE_RESOURCE_ID, |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 519 | Directory.ACCOUNT_TYPE, |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 520 | Directory.ACCOUNT_NAME, |
| 521 | Directory.EXPORT_SUPPORT, |
| 522 | }; |
| 523 | |
| 524 | public final static int DISPLAY_NAME = 0; |
| 525 | public final static int PACKAGE_NAME = 1; |
| 526 | public final static int TYPE_RESOURCE_ID = 2; |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 527 | public final static int ACCOUNT_TYPE = 3; |
| 528 | public final static int ACCOUNT_NAME = 4; |
| 529 | public final static int EXPORT_SUPPORT = 5; |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Dmitri Plotnikov | 2deaee1 | 2010-09-15 15:42:08 -0700 | [diff] [blame] | 532 | private static class GroupQuery { |
| 533 | final static String[] COLUMNS = new String[] { |
| 534 | Groups.ACCOUNT_NAME, |
| 535 | Groups.ACCOUNT_TYPE, |
| 536 | Groups._ID, |
| 537 | Groups.TITLE, |
| 538 | Groups.AUTO_ADD, |
| 539 | Groups.FAVORITES, |
| 540 | }; |
| 541 | |
| 542 | public final static int ACCOUNT_NAME = 0; |
| 543 | public final static int ACCOUNT_TYPE = 1; |
| 544 | public final static int ID = 2; |
| 545 | public final static int TITLE = 3; |
| 546 | public final static int AUTO_ADD = 4; |
| 547 | public final static int FAVORITES = 5; |
| 548 | } |
| 549 | |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 550 | private final class LoadContactTask extends AsyncTask<Void, Void, Result> { |
Daniel Lehmann | 1316b13 | 2010-04-13 15:08:53 -0700 | [diff] [blame] | 551 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 552 | @Override |
| 553 | protected Result doInBackground(Void... args) { |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 554 | try { |
| 555 | final ContentResolver resolver = getContext().getContentResolver(); |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 556 | final Uri uriCurrentFormat = ensureIsContactUri(resolver, mLookupUri); |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 557 | Result result = loadContactEntity(resolver, uriCurrentFormat); |
Dmitri Plotnikov | 217245c | 2010-09-18 13:04:50 -0700 | [diff] [blame] | 558 | if (result != Result.NOT_FOUND) { |
| 559 | if (result.isDirectoryEntry()) { |
| 560 | loadDirectoryMetaData(result); |
| 561 | } else if (mLoadGroupMetaData) { |
| 562 | loadGroupMetaData(result); |
| 563 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 564 | loadPhotoBinaryData(result); |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 565 | } |
| 566 | return result; |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 567 | } catch (Exception e) { |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 568 | Log.e(TAG, "Error loading the contact: " + mLookupUri, e); |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 569 | return Result.ERROR; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 570 | } |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /** |
Daniel Lehmann | 1316b13 | 2010-04-13 15:08:53 -0700 | [diff] [blame] | 574 | * Transforms the given Uri and returns a Lookup-Uri that represents the contact. |
| 575 | * For legacy contacts, a raw-contact lookup is performed. |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 576 | * @param resolver |
Daniel Lehmann | 1316b13 | 2010-04-13 15:08:53 -0700 | [diff] [blame] | 577 | */ |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 578 | private Uri ensureIsContactUri(final ContentResolver resolver, final Uri uri) { |
Daniel Lehmann | 1316b13 | 2010-04-13 15:08:53 -0700 | [diff] [blame] | 579 | if (uri == null) throw new IllegalArgumentException("uri must not be null"); |
| 580 | |
| 581 | final String authority = uri.getAuthority(); |
| 582 | |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 583 | // Current Style Uri? |
Daniel Lehmann | 1316b13 | 2010-04-13 15:08:53 -0700 | [diff] [blame] | 584 | if (ContactsContract.AUTHORITY.equals(authority)) { |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 585 | final String type = resolver.getType(uri); |
| 586 | // Contact-Uri? Good, return it |
| 587 | if (Contacts.CONTENT_ITEM_TYPE.equals(type)) { |
| 588 | return uri; |
| 589 | } |
| 590 | |
| 591 | // RawContact-Uri? Transform it to ContactUri |
| 592 | if (RawContacts.CONTENT_ITEM_TYPE.equals(type)) { |
| 593 | final long rawContactId = ContentUris.parseId(uri); |
| 594 | return RawContacts.getContactLookupUri(getContext().getContentResolver(), |
| 595 | ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); |
| 596 | } |
| 597 | |
| 598 | // Anything else? We don't know what this is |
| 599 | throw new IllegalArgumentException("uri format is unknown"); |
Daniel Lehmann | 1316b13 | 2010-04-13 15:08:53 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | // Legacy Style? Convert to RawContact |
| 603 | final String OBSOLETE_AUTHORITY = "contacts"; |
| 604 | if (OBSOLETE_AUTHORITY.equals(authority)) { |
| 605 | // Legacy Format. Convert to RawContact-Uri and then lookup the contact |
| 606 | final long rawContactId = ContentUris.parseId(uri); |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 607 | return RawContacts.getContactLookupUri(resolver, |
Daniel Lehmann | 1316b13 | 2010-04-13 15:08:53 -0700 | [diff] [blame] | 608 | ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); |
| 609 | } |
| 610 | |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 611 | throw new IllegalArgumentException("uri authority is unknown"); |
Daniel Lehmann | 1316b13 | 2010-04-13 15:08:53 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 614 | private Result loadContactEntity(ContentResolver resolver, Uri contactUri) { |
| 615 | Uri entityUri = Uri.withAppendedPath(contactUri, Contacts.Entity.CONTENT_DIRECTORY); |
| 616 | Cursor cursor = resolver.query(entityUri, ContactQuery.COLUMNS, null, null, |
| 617 | Contacts.Entity.RAW_CONTACT_ID); |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 618 | if (cursor == null) { |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 619 | Log.e(TAG, "No cursor returned in loadContactEntity"); |
| 620 | return Result.NOT_FOUND; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 621 | } |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 622 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 623 | try { |
| 624 | if (!cursor.moveToFirst()) { |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 625 | cursor.close(); |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 626 | return Result.NOT_FOUND; |
| 627 | } |
| 628 | |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 629 | long currentRawContactId = -1; |
| 630 | Entity entity = null; |
| 631 | Result result = loadContactHeaderData(cursor, contactUri); |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 632 | ArrayList<Entity> entities = result.getEntities(); |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 633 | HashMap<Long, DataStatus> statuses = result.getStatuses(); |
| 634 | for (; !cursor.isAfterLast(); cursor.moveToNext()) { |
| 635 | long rawContactId = cursor.getLong(ContactQuery.RAW_CONTACT_ID); |
| 636 | if (rawContactId != currentRawContactId) { |
| 637 | currentRawContactId = rawContactId; |
| 638 | entity = new android.content.Entity(loadRawContact(cursor)); |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 639 | entities.add(entity); |
| 640 | } |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 641 | if (!cursor.isNull(ContactQuery.DATA_ID)) { |
| 642 | ContentValues data = loadData(cursor); |
| 643 | entity.addSubValue(ContactsContract.Data.CONTENT_URI, data); |
| 644 | |
| 645 | if (!cursor.isNull(ContactQuery.PRESENCE) |
| 646 | || !cursor.isNull(ContactQuery.STATUS)) { |
| 647 | final DataStatus status = new DataStatus(cursor); |
| 648 | final long dataId = cursor.getLong(ContactQuery.DATA_ID); |
| 649 | statuses.put(dataId, status); |
| 650 | } |
| 651 | } |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 652 | } |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 653 | |
| 654 | return result; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 655 | } finally { |
| 656 | cursor.close(); |
| 657 | } |
| 658 | } |
| 659 | |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 660 | /** |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 661 | * Looks for the photo data item in entities. If found, creates a new Bitmap instance. If |
| 662 | * not found, returns null |
| 663 | */ |
| 664 | private void loadPhotoBinaryData(Result contactData) { |
| 665 | final long photoId = contactData.getPhotoId(); |
| 666 | if (photoId <= 0) { |
| 667 | // No photo ID |
| 668 | return; |
| 669 | } |
| 670 | |
| 671 | for (Entity entity : contactData.getEntities()) { |
| 672 | for (NamedContentValues subValue : entity.getSubValues()) { |
| 673 | final ContentValues entryValues = subValue.values; |
| 674 | final long dataId = entryValues.getAsLong(Data._ID); |
| 675 | if (dataId == photoId) { |
| 676 | final String mimeType = entryValues.getAsString(Data.MIMETYPE); |
| 677 | // Correct Data Id but incorrect MimeType? Don't load |
| 678 | if (!Photo.CONTENT_ITEM_TYPE.equals(mimeType)) { |
| 679 | return; |
| 680 | } |
| 681 | contactData.setPhotoBinaryData(entryValues.getAsByteArray(Photo.PHOTO)); |
| 682 | break; |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | /** |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 689 | * Extracts Contact level columns from the cursor. |
| 690 | */ |
| 691 | private Result loadContactHeaderData(final Cursor cursor, Uri contactUri) { |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 692 | final String directoryParameter = |
| 693 | contactUri.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY); |
| 694 | final long directoryId = directoryParameter == null |
| 695 | ? Directory.DEFAULT |
| 696 | : Long.parseLong(directoryParameter); |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 697 | final long contactId = cursor.getLong(ContactQuery.CONTACT_ID); |
| 698 | final String lookupKey = cursor.getString(ContactQuery.LOOKUP_KEY); |
| 699 | final long nameRawContactId = cursor.getLong(ContactQuery.NAME_RAW_CONTACT_ID); |
| 700 | final int displayNameSource = cursor.getInt(ContactQuery.DISPLAY_NAME_SOURCE); |
| 701 | final String displayName = cursor.getString(ContactQuery.DISPLAY_NAME); |
| 702 | final String phoneticName = cursor.getString(ContactQuery.PHONETIC_NAME); |
| 703 | final long photoId = cursor.getLong(ContactQuery.PHOTO_ID); |
Dmitri Plotnikov | f9eb73f | 2010-10-21 11:48:56 -0700 | [diff] [blame] | 704 | final String photoUri = cursor.getString(ContactQuery.PHOTO_URI); |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 705 | final boolean starred = cursor.getInt(ContactQuery.STARRED) != 0; |
| 706 | final Integer presence = cursor.isNull(ContactQuery.CONTACT_PRESENCE) |
| 707 | ? null |
| 708 | : cursor.getInt(ContactQuery.CONTACT_PRESENCE); |
| 709 | final String status = cursor.getString(ContactQuery.CONTACT_STATUS); |
| 710 | final Long statusTimestamp = cursor.isNull(ContactQuery.CONTACT_STATUS_TIMESTAMP) |
| 711 | ? null |
| 712 | : cursor.getLong(ContactQuery.CONTACT_STATUS_TIMESTAMP); |
| 713 | final Integer statusLabel = cursor.isNull(ContactQuery.CONTACT_STATUS_LABEL) |
| 714 | ? null |
| 715 | : cursor.getInt(ContactQuery.CONTACT_STATUS_LABEL); |
| 716 | final String statusResPackage = cursor.getString( |
| 717 | ContactQuery.CONTACT_STATUS_RES_PACKAGE); |
| 718 | |
Dmitri Plotnikov | 1536ea1 | 2010-10-29 11:51:05 -0700 | [diff] [blame] | 719 | Uri lookupUri; |
| 720 | if (directoryId == Directory.DEFAULT || directoryId == Directory.LOCAL_INVISIBLE) { |
| 721 | lookupUri = ContentUris.withAppendedId( |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 722 | Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey), contactId); |
Dmitri Plotnikov | 1536ea1 | 2010-10-29 11:51:05 -0700 | [diff] [blame] | 723 | } else { |
| 724 | lookupUri = contactUri; |
| 725 | } |
| 726 | |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 727 | return new Result(contactUri, lookupUri, directoryId, lookupKey, contactId, |
Dmitri Plotnikov | f9eb73f | 2010-10-21 11:48:56 -0700 | [diff] [blame] | 728 | nameRawContactId, displayNameSource, photoId, photoUri, displayName, |
| 729 | phoneticName, starred, presence, status, statusTimestamp, statusLabel, |
| 730 | statusResPackage); |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | /** |
| 734 | * Extracts RawContact level columns from the cursor. |
| 735 | */ |
| 736 | private ContentValues loadRawContact(Cursor cursor) { |
| 737 | ContentValues cv = new ContentValues(); |
| 738 | |
| 739 | cv.put(RawContacts._ID, cursor.getLong(ContactQuery.RAW_CONTACT_ID)); |
| 740 | |
| 741 | cursorColumnToContentValues(cursor, cv, ContactQuery.ACCOUNT_NAME); |
| 742 | cursorColumnToContentValues(cursor, cv, ContactQuery.ACCOUNT_TYPE); |
| 743 | cursorColumnToContentValues(cursor, cv, ContactQuery.DIRTY); |
| 744 | cursorColumnToContentValues(cursor, cv, ContactQuery.VERSION); |
| 745 | cursorColumnToContentValues(cursor, cv, ContactQuery.SOURCE_ID); |
| 746 | cursorColumnToContentValues(cursor, cv, ContactQuery.SYNC1); |
| 747 | cursorColumnToContentValues(cursor, cv, ContactQuery.SYNC2); |
| 748 | cursorColumnToContentValues(cursor, cv, ContactQuery.SYNC3); |
| 749 | cursorColumnToContentValues(cursor, cv, ContactQuery.SYNC4); |
| 750 | cursorColumnToContentValues(cursor, cv, ContactQuery.DELETED); |
| 751 | cursorColumnToContentValues(cursor, cv, ContactQuery.CONTACT_ID); |
| 752 | cursorColumnToContentValues(cursor, cv, ContactQuery.STARRED); |
| 753 | cursorColumnToContentValues(cursor, cv, ContactQuery.IS_RESTRICTED); |
| 754 | cursorColumnToContentValues(cursor, cv, ContactQuery.NAME_VERIFIED); |
| 755 | |
| 756 | return cv; |
| 757 | } |
| 758 | |
| 759 | /** |
| 760 | * Extracts Data level columns from the cursor. |
| 761 | */ |
| 762 | private ContentValues loadData(Cursor cursor) { |
| 763 | ContentValues cv = new ContentValues(); |
| 764 | |
| 765 | cv.put(Data._ID, cursor.getLong(ContactQuery.DATA_ID)); |
| 766 | |
| 767 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA1); |
| 768 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA2); |
| 769 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA3); |
| 770 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA4); |
| 771 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA5); |
| 772 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA6); |
| 773 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA7); |
| 774 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA8); |
| 775 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA9); |
| 776 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA10); |
| 777 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA11); |
| 778 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA12); |
| 779 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA13); |
| 780 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA14); |
| 781 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA15); |
| 782 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA_SYNC1); |
| 783 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA_SYNC2); |
| 784 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA_SYNC3); |
| 785 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA_SYNC4); |
| 786 | cursorColumnToContentValues(cursor, cv, ContactQuery.DATA_VERSION); |
| 787 | cursorColumnToContentValues(cursor, cv, ContactQuery.IS_PRIMARY); |
| 788 | cursorColumnToContentValues(cursor, cv, ContactQuery.IS_SUPERPRIMARY); |
| 789 | cursorColumnToContentValues(cursor, cv, ContactQuery.MIMETYPE); |
| 790 | cursorColumnToContentValues(cursor, cv, ContactQuery.RES_PACKAGE); |
| 791 | cursorColumnToContentValues(cursor, cv, ContactQuery.GROUP_SOURCE_ID); |
Daniel Lehmann | 8fd7bb6 | 2010-08-13 20:50:31 -0700 | [diff] [blame] | 792 | cursorColumnToContentValues(cursor, cv, ContactQuery.CHAT_CAPABILITY); |
Dmitri Plotnikov | 4d44424 | 2010-07-30 11:39:39 -0700 | [diff] [blame] | 793 | |
| 794 | return cv; |
| 795 | } |
| 796 | |
| 797 | private void cursorColumnToContentValues( |
| 798 | Cursor cursor, ContentValues values, int index) { |
| 799 | switch (cursor.getType(index)) { |
| 800 | case Cursor.FIELD_TYPE_NULL: |
| 801 | // don't put anything in the content values |
| 802 | break; |
| 803 | case Cursor.FIELD_TYPE_INTEGER: |
| 804 | values.put(ContactQuery.COLUMNS[index], cursor.getLong(index)); |
| 805 | break; |
| 806 | case Cursor.FIELD_TYPE_STRING: |
| 807 | values.put(ContactQuery.COLUMNS[index], cursor.getString(index)); |
| 808 | break; |
| 809 | case Cursor.FIELD_TYPE_BLOB: |
| 810 | values.put(ContactQuery.COLUMNS[index], cursor.getBlob(index)); |
| 811 | break; |
| 812 | default: |
| 813 | throw new IllegalStateException("Invalid or unhandled data type"); |
| 814 | } |
| 815 | } |
| 816 | |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 817 | private void loadDirectoryMetaData(Result result) { |
| 818 | long directoryId = result.getDirectoryId(); |
| 819 | |
| 820 | Cursor cursor = getContext().getContentResolver().query( |
| 821 | ContentUris.withAppendedId(Directory.CONTENT_URI, directoryId), |
| 822 | DirectoryQuery.COLUMNS, null, null, null); |
| 823 | if (cursor == null) { |
| 824 | return; |
| 825 | } |
| 826 | try { |
| 827 | if (cursor.moveToFirst()) { |
| 828 | final String displayName = cursor.getString(DirectoryQuery.DISPLAY_NAME); |
| 829 | final String packageName = cursor.getString(DirectoryQuery.PACKAGE_NAME); |
| 830 | final int typeResourceId = cursor.getInt(DirectoryQuery.TYPE_RESOURCE_ID); |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 831 | final String accountType = cursor.getString(DirectoryQuery.ACCOUNT_TYPE); |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 832 | final String accountName = cursor.getString(DirectoryQuery.ACCOUNT_NAME); |
| 833 | final int exportSupport = cursor.getInt(DirectoryQuery.EXPORT_SUPPORT); |
| 834 | String directoryType = null; |
| 835 | if (!TextUtils.isEmpty(packageName)) { |
| 836 | PackageManager pm = getContext().getPackageManager(); |
| 837 | try { |
| 838 | Resources resources = pm.getResourcesForApplication(packageName); |
| 839 | directoryType = resources.getString(typeResourceId); |
| 840 | } catch (NameNotFoundException e) { |
| 841 | Log.w(TAG, "Contact directory resource not found: " |
| 842 | + packageName + "." + typeResourceId); |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | result.setDirectoryMetaData( |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 847 | displayName, directoryType, accountType, accountName, exportSupport); |
Dmitri Plotnikov | 02cd491 | 2010-09-01 20:42:17 -0700 | [diff] [blame] | 848 | } |
| 849 | } finally { |
| 850 | cursor.close(); |
| 851 | } |
| 852 | } |
| 853 | |
Dmitri Plotnikov | 2deaee1 | 2010-09-15 15:42:08 -0700 | [diff] [blame] | 854 | /** |
| 855 | * Loads groups meta-data for all groups associated with all constituent raw contacts' |
| 856 | * accounts. |
| 857 | */ |
| 858 | private void loadGroupMetaData(Result result) { |
| 859 | StringBuilder selection = new StringBuilder(); |
| 860 | ArrayList<String> selectionArgs = new ArrayList<String>(); |
| 861 | for (Entity entity : result.mEntities) { |
| 862 | ContentValues values = entity.getEntityValues(); |
| 863 | String accountName = values.getAsString(RawContacts.ACCOUNT_NAME); |
| 864 | String accountType = values.getAsString(RawContacts.ACCOUNT_TYPE); |
| 865 | if (accountName != null && accountType != null) { |
| 866 | if (selection.length() != 0) { |
| 867 | selection.append(" OR "); |
| 868 | } |
| 869 | selection.append( |
| 870 | "(" + Groups.ACCOUNT_NAME + "=? AND " + Groups.ACCOUNT_TYPE + "=?)"); |
| 871 | selectionArgs.add(accountName); |
| 872 | selectionArgs.add(accountType); |
| 873 | } |
| 874 | } |
| 875 | Cursor cursor = getContext().getContentResolver().query(Groups.CONTENT_URI, |
| 876 | GroupQuery.COLUMNS, selection.toString(), selectionArgs.toArray(new String[0]), |
| 877 | null); |
| 878 | try { |
| 879 | while (cursor.moveToNext()) { |
| 880 | final String accountName = cursor.getString(GroupQuery.ACCOUNT_NAME); |
| 881 | final String accountType = cursor.getString(GroupQuery.ACCOUNT_TYPE); |
| 882 | final long groupId = cursor.getLong(GroupQuery.ID); |
| 883 | final String title = cursor.getString(GroupQuery.TITLE); |
| 884 | final boolean defaultGroup = cursor.isNull(GroupQuery.AUTO_ADD) |
| 885 | ? false |
| 886 | : cursor.getInt(GroupQuery.AUTO_ADD) != 0; |
| 887 | final boolean favorites = cursor.isNull(GroupQuery.FAVORITES) |
| 888 | ? false |
| 889 | : cursor.getInt(GroupQuery.FAVORITES) != 0; |
| 890 | |
Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 891 | result.addGroupMetaData(new GroupMetaData( |
Dmitri Plotnikov | 2deaee1 | 2010-09-15 15:42:08 -0700 | [diff] [blame] | 892 | accountName, accountType, groupId, title, defaultGroup, favorites)); |
| 893 | } |
| 894 | } finally { |
| 895 | cursor.close(); |
| 896 | } |
| 897 | } |
| 898 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 899 | @Override |
| 900 | protected void onPostExecute(Result result) { |
Dmitri Plotnikov | c3f2a52 | 2010-11-17 18:36:17 -0800 | [diff] [blame] | 901 | unregisterObserver(); |
| 902 | |
Daniel Lehmann | 1316b13 | 2010-04-13 15:08:53 -0700 | [diff] [blame] | 903 | // The creator isn't interested in any further updates |
Dmitri Plotnikov | c3f2a52 | 2010-11-17 18:36:17 -0800 | [diff] [blame] | 904 | if (mDestroyed || result == null) { |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 905 | return; |
| 906 | } |
| 907 | |
| 908 | mContact = result; |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 909 | |
Dmitri Plotnikov | c3f2a52 | 2010-11-17 18:36:17 -0800 | [diff] [blame] | 910 | if (result != Result.ERROR && result != Result.NOT_FOUND) { |
| 911 | mLookupUri = result.getLookupUri(); |
| 912 | |
| 913 | if (!result.isDirectoryEntry()) { |
| 914 | Log.i(TAG, "Registering content observer for " + mLookupUri); |
| 915 | if (mObserver == null) { |
| 916 | mObserver = new ForceLoadContentObserver(); |
| 917 | } |
| 918 | getContext().getContentResolver().registerContentObserver( |
| 919 | mLookupUri, true, mObserver); |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 920 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 921 | |
| 922 | if (mContact.getPhotoBinaryData() == null && mContact.getPhotoUri() != null) { |
| 923 | mContact.setLoadingPhoto(true); |
| 924 | new AsyncPhotoLoader().execute(mContact.getPhotoUri()); |
| 925 | } |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 926 | } |
Dmitri Plotnikov | c3f2a52 | 2010-11-17 18:36:17 -0800 | [diff] [blame] | 927 | |
| 928 | deliverResult(mContact); |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 932 | private class AsyncPhotoLoader extends AsyncTask<String, Void, byte[]> { |
| 933 | |
| 934 | private static final int BUFFER_SIZE = 1024*16; |
| 935 | |
| 936 | @Override |
| 937 | protected byte[] doInBackground(String... params) { |
| 938 | Uri uri = Uri.parse(params[0]); |
| 939 | byte[] data = null; |
| 940 | try { |
| 941 | InputStream is = getContext().getContentResolver().openInputStream(uri); |
| 942 | if (is != null) { |
| 943 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 944 | try { |
| 945 | byte[] mBuffer = new byte[BUFFER_SIZE]; |
| 946 | |
| 947 | int size; |
| 948 | while ((size = is.read(mBuffer)) != -1) { |
| 949 | baos.write(mBuffer, 0, size); |
| 950 | } |
| 951 | data = baos.toByteArray(); |
| 952 | } finally { |
| 953 | is.close(); |
| 954 | } |
| 955 | } else { |
| 956 | Log.v(TAG, "Cannot load photo " + uri); |
| 957 | } |
| 958 | } catch (IOException e) { |
| 959 | Log.e(TAG, "Cannot load photo " + uri, e); |
| 960 | } |
| 961 | |
| 962 | return data; |
| 963 | } |
| 964 | |
| 965 | @Override |
| 966 | protected void onPostExecute(byte[] data) { |
Dmitri Plotnikov | c3f2a52 | 2010-11-17 18:36:17 -0800 | [diff] [blame] | 967 | if (mContact != null) { |
Dmitri Plotnikov | 7cee774 | 2011-01-13 17:11:06 -0800 | [diff] [blame] | 968 | mContact = new Result(mContact); |
Dmitri Plotnikov | c3f2a52 | 2010-11-17 18:36:17 -0800 | [diff] [blame] | 969 | mContact.setPhotoBinaryData(data); |
| 970 | mContact.setLoadingPhoto(false); |
| 971 | deliverResult(mContact); |
| 972 | } |
Dmitri Plotnikov | 7f4f8d1 | 2010-11-10 10:22:19 -0800 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
Daniel Lehmann | 3a12077 | 2010-06-21 16:21:35 -0700 | [diff] [blame] | 976 | private void unregisterObserver() { |
| 977 | if (mObserver != null) { |
| 978 | getContext().getContentResolver().unregisterContentObserver(mObserver); |
| 979 | mObserver = null; |
| 980 | } |
| 981 | } |
| 982 | |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 983 | public ContactLoader(Context context, Uri lookupUri) { |
Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 984 | this(context, lookupUri, false); |
| 985 | } |
| 986 | |
| 987 | public ContactLoader(Context context, Uri lookupUri, boolean loadGroupMetaData) { |
Daniel Lehmann | 74a2dc5 | 2010-04-15 16:52:33 -0700 | [diff] [blame] | 988 | super(context); |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 989 | mLookupUri = lookupUri; |
Dmitri Plotnikov | e843f91 | 2010-09-16 15:21:48 -0700 | [diff] [blame] | 990 | mLoadGroupMetaData = loadGroupMetaData; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Dmitri Plotnikov | 5a30d9a | 2010-11-23 14:59:50 -0800 | [diff] [blame] | 993 | public Uri getLookupUri() { |
| 994 | return mLookupUri; |
| 995 | } |
| 996 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 997 | @Override |
Dianne Hackborn | c04fc27 | 2010-12-20 23:13:10 -0800 | [diff] [blame] | 998 | protected void onStartLoading() { |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 999 | if (mContact != null) { |
Daniel Lehmann | cbcc449 | 2010-04-12 18:03:54 -0700 | [diff] [blame] | 1000 | deliverResult(mContact); |
Dmitri Plotnikov | 97e90c6 | 2011-01-03 11:58:13 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | if (takeContentChanged() || mContact == null) { |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 1004 | forceLoad(); |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | @Override |
Dianne Hackborn | c04fc27 | 2010-12-20 23:13:10 -0800 | [diff] [blame] | 1009 | protected void onForceLoad() { |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 1010 | final LoadContactTask task = new LoadContactTask(); |
Daniel Lehmann | 74a2dc5 | 2010-04-15 16:52:33 -0700 | [diff] [blame] | 1011 | task.execute((Void[])null); |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | @Override |
Dianne Hackborn | c04fc27 | 2010-12-20 23:13:10 -0800 | [diff] [blame] | 1015 | protected void onReset() { |
Dianne Hackborn | 4ef95cc | 2010-12-16 00:44:33 -0800 | [diff] [blame] | 1016 | unregisterObserver(); |
| 1017 | mContact = null; |
| 1018 | mDestroyed = true; |
| 1019 | } |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 1020 | } |