Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
| 17 | package com.android.contacts.quickcontact; |
| 18 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 19 | import android.animation.ArgbEvaluator; |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 20 | import android.animation.ObjectAnimator; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 21 | import android.app.Activity; |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 22 | import android.app.LoaderManager.LoaderCallbacks; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 23 | import android.content.ContentUris; |
| 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 26 | import android.content.Loader; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 28 | import android.graphics.Bitmap; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 29 | import android.graphics.Color; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 30 | import android.graphics.drawable.BitmapDrawable; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 31 | import android.graphics.drawable.ColorDrawable; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 32 | import android.graphics.drawable.Drawable; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 33 | import android.net.Uri; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 34 | import android.os.AsyncTask; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 35 | import android.os.Bundle; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 36 | import android.os.Trace; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 37 | import android.provider.ContactsContract.CommonDataKinds.Email; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 38 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 39 | import android.provider.ContactsContract.CommonDataKinds.SipAddress; |
| 40 | import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; |
| 41 | import android.provider.ContactsContract.CommonDataKinds.Website; |
| 42 | import android.provider.ContactsContract.Contacts; |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 43 | import android.provider.ContactsContract.DisplayNameSources; |
| 44 | import android.provider.ContactsContract.Intents.Insert; |
| 45 | import android.provider.ContactsContract.Directory; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 46 | import android.provider.ContactsContract.QuickContact; |
| 47 | import android.provider.ContactsContract.RawContacts; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 48 | import android.support.v7.graphics.Palette; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 49 | import android.text.TextUtils; |
| 50 | import android.util.Log; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 51 | import android.view.View; |
| 52 | import android.view.View.OnClickListener; |
Daisuke Miyakawa | 10d7df7 | 2011-07-29 16:11:05 -0700 | [diff] [blame] | 53 | import android.view.WindowManager; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 54 | import android.widget.ImageView; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 55 | import android.widget.TextView; |
| 56 | import android.widget.Toast; |
| 57 | |
Christine Chen | 72b3ab1 | 2013-08-13 23:22:34 +0200 | [diff] [blame] | 58 | import com.android.contacts.ContactSaveService; |
Chiao Cheng | d7ca03e | 2012-10-24 15:14:08 -0700 | [diff] [blame] | 59 | import com.android.contacts.common.Collapser; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 60 | import com.android.contacts.R; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 61 | import com.android.contacts.common.lettertiles.LetterTileDrawable; |
Chiao Cheng | 0d5588d | 2012-11-26 15:34:14 -0800 | [diff] [blame] | 62 | import com.android.contacts.common.model.AccountTypeManager; |
Yorke Lee | cd321f6 | 2013-10-28 15:20:15 -0700 | [diff] [blame] | 63 | import com.android.contacts.common.model.Contact; |
| 64 | import com.android.contacts.common.model.ContactLoader; |
| 65 | import com.android.contacts.common.model.RawContact; |
Chiao Cheng | 428f008 | 2012-11-13 18:38:56 -0800 | [diff] [blame] | 66 | import com.android.contacts.common.model.account.AccountType; |
Yorke Lee | cd321f6 | 2013-10-28 15:20:15 -0700 | [diff] [blame] | 67 | import com.android.contacts.common.model.dataitem.DataItem; |
Chiao Cheng | 428f008 | 2012-11-13 18:38:56 -0800 | [diff] [blame] | 68 | import com.android.contacts.common.model.dataitem.DataKind; |
Yorke Lee | cd321f6 | 2013-10-28 15:20:15 -0700 | [diff] [blame] | 69 | import com.android.contacts.common.model.dataitem.EmailDataItem; |
| 70 | import com.android.contacts.common.model.dataitem.ImDataItem; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 71 | import com.android.contacts.common.model.dataitem.PhoneDataItem; |
Yorke Lee | cd321f6 | 2013-10-28 15:20:15 -0700 | [diff] [blame] | 72 | import com.android.contacts.common.util.DataStatus; |
Yorke Lee | 2e38583 | 2013-09-09 14:42:01 -0700 | [diff] [blame] | 73 | import com.android.contacts.common.util.UriUtils; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 74 | import com.android.contacts.interactions.ContactDeletionInteraction; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 75 | import com.android.contacts.interactions.ContactInteraction; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 76 | import com.android.contacts.interactions.SmsInteractionsLoader; |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 77 | import com.android.contacts.quickcontact.ExpandingEntryCardView.Entry; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 78 | import com.android.contacts.util.ImageViewDrawableSetter; |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 79 | import com.android.contacts.util.SchedulingUtils; |
| 80 | import com.android.contacts.widget.MultiShrinkScroller; |
| 81 | import com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener; |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 82 | |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 83 | import com.google.common.base.Preconditions; |
| 84 | import com.google.common.collect.Lists; |
| 85 | |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 86 | import java.util.ArrayList; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 87 | import java.util.Collections; |
| 88 | import java.util.Comparator; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 89 | import java.util.HashMap; |
| 90 | import java.util.HashSet; |
| 91 | import java.util.List; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 92 | import java.util.Map; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 93 | import java.util.Set; |
| 94 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 95 | /** |
| 96 | * Mostly translucent {@link Activity} that shows QuickContact dialog. It loads |
| 97 | * data asynchronously, and then shows a popup with details centered around |
| 98 | * {@link Intent#getSourceBounds()}. |
| 99 | */ |
| 100 | public class QuickContactActivity extends Activity { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 101 | |
| 102 | /** |
| 103 | * QuickContacts immediately takes up the full screen. All possible information is shown. |
| 104 | * This value for {@link android.provider.ContactsContract.QuickContact#EXTRA_MODE} |
| 105 | * should only be used by the Contacts app. |
| 106 | */ |
| 107 | public static final int MODE_FULLY_EXPANDED = 4; |
| 108 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 109 | private static final String TAG = "QuickContact"; |
| 110 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 111 | private static final int ANIMATION_SLIDE_OPEN_DURATION = 250; |
| 112 | private static final int ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION = 75; |
| 113 | private static final int REQUEST_CODE_CONTACT_EDITOR_ACTIVITY = 1; |
| 114 | private static final float SYSTEM_BAR_BRIGHTNESS_FACTOR = 0.7f; |
| 115 | private static final int SHIM_COLOR = Color.argb(0x7F, 0, 0, 0); |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 116 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 117 | |
| 118 | @SuppressWarnings("deprecation") |
| 119 | private static final String LEGACY_AUTHORITY = android.provider.Contacts.AUTHORITY; |
| 120 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 121 | private Uri mLookupUri; |
| 122 | private String[] mExcludeMimes; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 123 | private int mExtraMode; |
| 124 | private int mStatusBarColor; |
| 125 | private boolean mHasAlreadyBeenOpened; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 126 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 127 | private View mPhotoContainer; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 128 | |
Yorke Lee | 6219668 | 2013-09-06 18:34:17 -0700 | [diff] [blame] | 129 | private ImageView mPhotoView; |
Paul Soulos | 5ec23fd | 2014-05-29 18:19:38 -0700 | [diff] [blame] | 130 | private ImageView mEditOrAddContactImage; |
Christine Chen | 72b3ab1 | 2013-08-13 23:22:34 +0200 | [diff] [blame] | 131 | private ImageView mStarImage; |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 132 | private ExpandingEntryCardView mCommunicationCard; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 133 | private ExpandingEntryCardView mRecentCard; |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 134 | private MultiShrinkScroller mScroller; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 135 | private AsyncTask<Void, Void, Void> mEntriesAndActionsTask; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 136 | |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 137 | private static final int MIN_NUM_COMMUNICATION_ENTRIES_SHOWN = 3; |
| 138 | private static final int MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN = 3; |
| 139 | |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 140 | private Contact mContactData; |
Daniel Lehmann | 9815d7f | 2012-04-16 18:28:03 -0700 | [diff] [blame] | 141 | private ContactLoader mContactLoader; |
| 142 | |
Josh Gargus | 9758a92 | 2012-03-08 17:12:42 -0800 | [diff] [blame] | 143 | private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter(); |
| 144 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 145 | /** |
| 146 | * Keeps the default action per mimetype. Empty if no default actions are set |
| 147 | */ |
| 148 | private HashMap<String, Action> mDefaultsMap = new HashMap<String, Action>(); |
| 149 | |
| 150 | /** |
| 151 | * Set of {@link Action} that are associated with the aggregate currently |
| 152 | * displayed by this dialog, represented as a map from {@link String} |
| 153 | * MIME-type to a list of {@link Action}. |
| 154 | */ |
| 155 | private ActionMultiMap mActions = new ActionMultiMap(); |
| 156 | |
| 157 | /** |
| 158 | * {@link #LEADING_MIMETYPES} and {@link #TRAILING_MIMETYPES} are used to sort MIME-types. |
| 159 | * |
| 160 | * <p>The MIME-types in {@link #LEADING_MIMETYPES} appear in the front of the dialog, |
| 161 | * in the order specified here.</p> |
| 162 | * |
| 163 | * <p>The ones in {@link #TRAILING_MIMETYPES} appear in the end of the dialog, in the order |
| 164 | * specified here.</p> |
| 165 | * |
| 166 | * <p>The rest go between them, in the order in the array.</p> |
| 167 | */ |
| 168 | private static final List<String> LEADING_MIMETYPES = Lists.newArrayList( |
| 169 | Phone.CONTENT_ITEM_TYPE, SipAddress.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE); |
| 170 | |
| 171 | /** See {@link #LEADING_MIMETYPES}. */ |
| 172 | private static final List<String> TRAILING_MIMETYPES = Lists.newArrayList( |
| 173 | StructuredPostal.CONTENT_ITEM_TYPE, Website.CONTENT_ITEM_TYPE); |
| 174 | |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 175 | /** Id for the background contact loader */ |
| 176 | private static final int LOADER_CONTACT_ID = 0; |
| 177 | |
| 178 | /** Id for the background Sms Loader */ |
| 179 | private static final int LOADER_SMS_ID = 1; |
| 180 | private static final String KEY_LOADER_EXTRA_SMS_PHONES = |
| 181 | QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_SMS_PHONES"; |
| 182 | private static final int MAX_SMS_RETRIEVE = 3; |
| 183 | |
| 184 | private static final int[] mRecentLoaderIds = new int[LOADER_SMS_ID]; |
| 185 | private Map<Integer, List<ContactInteraction>> mRecentLoaderResults; |
| 186 | |
Paul Soulos | 5ec23fd | 2014-05-29 18:19:38 -0700 | [diff] [blame] | 187 | final OnClickListener mEditContactClickHandler = new OnClickListener() { |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 188 | @Override |
| 189 | public void onClick(View v) { |
Paul Soulos | 5ec23fd | 2014-05-29 18:19:38 -0700 | [diff] [blame] | 190 | final Intent intent = new Intent(Intent.ACTION_EDIT, mLookupUri); |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 191 | mContactLoader.cacheResult(); |
| 192 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 193 | startActivityForResult(intent, REQUEST_CODE_CONTACT_EDITOR_ACTIVITY); |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 194 | } |
| 195 | }; |
| 196 | |
| 197 | final OnClickListener mAddToContactsClickHandler = new OnClickListener() { |
| 198 | @Override |
| 199 | public void onClick(View v) { |
| 200 | if (mContactData == null) { |
| 201 | Log.e(TAG, "Empty contact data when trying to add to contact"); |
| 202 | return; |
| 203 | } |
| 204 | final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 205 | intent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 206 | |
| 207 | // Only pre-fill the name field if the provided display name is an organization |
| 208 | // name or better (e.g. structured name, nickname) |
| 209 | if (mContactData.getDisplayNameSource() >= DisplayNameSources.ORGANIZATION) { |
| 210 | intent.putExtra(Insert.NAME, mContactData.getDisplayName()); |
| 211 | } |
| 212 | intent.putExtra(Insert.DATA, mContactData.getContentValues()); |
| 213 | startActivity(intent); |
| 214 | } |
| 215 | }; |
| 216 | |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 217 | final OnClickListener mEntryClickHandler = new OnClickListener() { |
| 218 | @Override |
| 219 | public void onClick(View v) { |
| 220 | Log.i(TAG, "mEntryClickHandler onClick"); |
| 221 | Object intent = v.getTag(); |
| 222 | if (intent == null || !(intent instanceof Intent)) { |
| 223 | return; |
| 224 | } |
| 225 | startActivity((Intent) intent); |
| 226 | } |
| 227 | }; |
| 228 | |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 229 | final MultiShrinkScrollerListener mMultiShrinkScrollerListener |
| 230 | = new MultiShrinkScrollerListener() { |
| 231 | @Override |
| 232 | public void onScrolledOffBottom() { |
| 233 | onBackPressed(); |
| 234 | } |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 235 | |
| 236 | @Override |
| 237 | public void onEnterFullscreen() { |
| 238 | updateStatusBarColor(); |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public void onExitFullscreen() { |
| 243 | updateStatusBarColor(); |
| 244 | } |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 245 | }; |
| 246 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 247 | @Override |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 248 | protected void onCreate(Bundle savedInstanceState) { |
| 249 | Trace.beginSection("onCreate()"); |
| 250 | super.onCreate(savedInstanceState); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 251 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 252 | getWindow().setStatusBarColor(Color.TRANSPARENT); |
| 253 | // Since we can't disable Window animations from the Launcher, we can minimize the |
| 254 | // silliness of the animation by setting the navigation bar transparent. |
| 255 | getWindow().setNavigationBarColor(Color.TRANSPARENT); |
Daniel Lehmann | 2426cb0 | 2012-05-10 18:41:21 -0700 | [diff] [blame] | 256 | |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 257 | // Parse intent |
| 258 | final Intent intent = getIntent(); |
| 259 | |
| 260 | Uri lookupUri = intent.getData(); |
| 261 | |
| 262 | // Check to see whether it comes from the old version. |
| 263 | if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) { |
| 264 | final long rawContactId = ContentUris.parseId(lookupUri); |
| 265 | lookupUri = RawContacts.getContactLookupUri(getContentResolver(), |
| 266 | ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); |
| 267 | } |
| 268 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 269 | mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, |
| 270 | QuickContact.MODE_LARGE); |
| 271 | |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 272 | mLookupUri = Preconditions.checkNotNull(lookupUri, "missing lookupUri"); |
| 273 | |
| 274 | mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES); |
| 275 | |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 276 | mContactLoader = (ContactLoader) getLoaderManager().initLoader( |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 277 | LOADER_CONTACT_ID, null, mLoaderContactCallbacks); |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 278 | |
Daisuke Miyakawa | 10d7df7 | 2011-07-29 16:11:05 -0700 | [diff] [blame] | 279 | // Show QuickContact in front of soft input |
| 280 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
| 281 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
| 282 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 283 | setContentView(R.layout.quickcontact_activity); |
| 284 | |
Paul Soulos | 5ec23fd | 2014-05-29 18:19:38 -0700 | [diff] [blame] | 285 | mEditOrAddContactImage = (ImageView) findViewById(R.id.contact_edit_image); |
Christine Chen | 72b3ab1 | 2013-08-13 23:22:34 +0200 | [diff] [blame] | 286 | mStarImage = (ImageView) findViewById(R.id.quickcontact_star_button); |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 287 | mCommunicationCard = (ExpandingEntryCardView) findViewById(R.id.communication_card); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 288 | mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card); |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 289 | mScroller = (MultiShrinkScroller) findViewById(R.id.multiscroller); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 290 | |
Paul Soulos | 5ec23fd | 2014-05-29 18:19:38 -0700 | [diff] [blame] | 291 | mEditOrAddContactImage.setOnClickListener(mEditContactClickHandler); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 292 | |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 293 | mCommunicationCard.setOnClickListener(mEntryClickHandler); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 294 | mCommunicationCard.setTitle(getResources().getString(R.string.communication_card_title)); |
| 295 | |
| 296 | mRecentCard.setOnClickListener(mEntryClickHandler); |
| 297 | mRecentCard.setTitle(getResources().getString(R.string.recent_card_title)); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 298 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 299 | // find and prepare correct header view |
| 300 | mPhotoContainer = findViewById(R.id.photo_container); |
Yorke Lee | 6219668 | 2013-09-06 18:34:17 -0700 | [diff] [blame] | 301 | |
Katherine Kuan | 81281ee | 2011-07-28 16:20:59 -0700 | [diff] [blame] | 302 | setHeaderNameText(R.id.name, R.string.missing_name); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 303 | |
Yorke Lee | 6219668 | 2013-09-06 18:34:17 -0700 | [diff] [blame] | 304 | mPhotoView = (ImageView) mPhotoContainer.findViewById(R.id.photo); |
Paul Soulos | 5ec23fd | 2014-05-29 18:19:38 -0700 | [diff] [blame] | 305 | mPhotoView.setOnClickListener(mEditContactClickHandler); |
Yorke Lee | 6219668 | 2013-09-06 18:34:17 -0700 | [diff] [blame] | 306 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 307 | mHasAlreadyBeenOpened = savedInstanceState != null; |
Daniel Lehmann | 2426cb0 | 2012-05-10 18:41:21 -0700 | [diff] [blame] | 308 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 309 | final ColorDrawable windowShim = new ColorDrawable(SHIM_COLOR); |
| 310 | getWindow().setBackgroundDrawable(windowShim); |
| 311 | if (!mHasAlreadyBeenOpened) { |
| 312 | final int duration = getResources().getInteger(android.R.integer.config_shortAnimTime); |
| 313 | ObjectAnimator.ofInt(windowShim, "alpha", 0, 0xFF).setDuration(duration).start(); |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 314 | } |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 315 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 316 | if (mScroller != null) { |
| 317 | mScroller.initialize(mMultiShrinkScrollerListener); |
| 318 | if (mHasAlreadyBeenOpened) { |
| 319 | mScroller.setVisibility(View.VISIBLE); |
| 320 | mScroller.setScroll(mScroller.getScrollNeededToBeFullScreen()); |
| 321 | } else { |
| 322 | mScroller.setVisibility(View.GONE); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | Trace.endSection(); |
| 327 | } |
| 328 | |
| 329 | protected void onActivityResult(int requestCode, int resultCode, |
| 330 | Intent data) { |
| 331 | if (requestCode == REQUEST_CODE_CONTACT_EDITOR_ACTIVITY && |
| 332 | resultCode == ContactDeletionInteraction.RESULT_CODE_DELETED) { |
| 333 | // The contact that we were showing has been deleted. |
| 334 | finish(); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | @Override |
| 339 | protected void onNewIntent(Intent intent) { |
| 340 | super.onNewIntent(intent); |
| 341 | mHasAlreadyBeenOpened = true; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 344 | private void runEntranceAnimation() { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 345 | if (mHasAlreadyBeenOpened) { |
| 346 | return; |
| 347 | } |
| 348 | mHasAlreadyBeenOpened = true; |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 349 | final int bottomScroll = mScroller.getScrollUntilOffBottom() - 1; |
| 350 | final ObjectAnimator scrollAnimation |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 351 | = ObjectAnimator.ofInt(mScroller, "scroll", -bottomScroll, |
| 352 | mExtraMode != MODE_FULLY_EXPANDED ? 0 : mScroller.getScrollNeededToBeFullScreen()); |
| 353 | scrollAnimation.setDuration(ANIMATION_SLIDE_OPEN_DURATION); |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 354 | scrollAnimation.start(); |
| 355 | } |
| 356 | |
Katherine Kuan | 81281ee | 2011-07-28 16:20:59 -0700 | [diff] [blame] | 357 | /** Assign this string to the view if it is not empty. */ |
| 358 | private void setHeaderNameText(int id, int resId) { |
| 359 | setHeaderNameText(id, getText(resId)); |
| 360 | } |
| 361 | |
| 362 | /** Assign this string to the view if it is not empty. */ |
| 363 | private void setHeaderNameText(int id, CharSequence value) { |
| 364 | final View view = mPhotoContainer.findViewById(id); |
| 365 | if (view instanceof TextView) { |
| 366 | if (!TextUtils.isEmpty(value)) { |
| 367 | ((TextView)view).setText(value); |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | /** |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 373 | * Check if the given MIME-type appears in the list of excluded MIME-types |
| 374 | * that the most-recent caller requested. |
| 375 | */ |
| 376 | private boolean isMimeExcluded(String mimeType) { |
| 377 | if (mExcludeMimes == null) return false; |
| 378 | for (String excludedMime : mExcludeMimes) { |
| 379 | if (TextUtils.equals(excludedMime, mimeType)) { |
| 380 | return true; |
| 381 | } |
| 382 | } |
| 383 | return false; |
| 384 | } |
| 385 | |
| 386 | /** |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 387 | * Handle the result from the ContactLoader |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 388 | */ |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 389 | private void bindContactData(final Contact data) { |
| 390 | Trace.beginSection("bindContactData"); |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 391 | mContactData = data; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 392 | final Context context = this; |
| 393 | |
Paul Soulos | 5ec23fd | 2014-05-29 18:19:38 -0700 | [diff] [blame] | 394 | mEditOrAddContactImage.setVisibility(isMimeExcluded(Contacts.CONTENT_ITEM_TYPE) ? |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 395 | View.GONE : View.VISIBLE); |
Christine Chen | 72b3ab1 | 2013-08-13 23:22:34 +0200 | [diff] [blame] | 396 | final boolean isStarred = data.getStarred(); |
| 397 | if (isStarred) { |
| 398 | mStarImage.setImageResource(R.drawable.ic_favorite_on_lt); |
Ben Gilad | 69f67d0 | 2013-10-04 15:39:40 -0700 | [diff] [blame] | 399 | mStarImage.setContentDescription( |
| 400 | getResources().getString(R.string.menu_removeStar)); |
Christine Chen | 72b3ab1 | 2013-08-13 23:22:34 +0200 | [diff] [blame] | 401 | } else { |
| 402 | mStarImage.setImageResource(R.drawable.ic_favorite_off_lt); |
Ben Gilad | 69f67d0 | 2013-10-04 15:39:40 -0700 | [diff] [blame] | 403 | mStarImage.setContentDescription( |
| 404 | getResources().getString(R.string.menu_addStar)); |
Christine Chen | 72b3ab1 | 2013-08-13 23:22:34 +0200 | [diff] [blame] | 405 | } |
| 406 | final Uri lookupUri = data.getLookupUri(); |
Christine Chen | 72b3ab1 | 2013-08-13 23:22:34 +0200 | [diff] [blame] | 407 | |
Yorke Lee | 2e38583 | 2013-09-09 14:42:01 -0700 | [diff] [blame] | 408 | // If this is a json encoded URI, there is no local contact to star |
| 409 | if (UriUtils.isEncodedContactUri(lookupUri)) { |
| 410 | mStarImage.setVisibility(View.GONE); |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 411 | |
| 412 | // If directory export support is not allowed, then don't allow the user to add |
| 413 | // to contacts |
| 414 | if (mContactData.getDirectoryExportSupport() == Directory.EXPORT_SUPPORT_NONE) { |
Yorke Lee | 88df712 | 2013-09-29 15:00:18 -0700 | [diff] [blame] | 415 | configureHeaderClickActions(false); |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 416 | } else { |
Yorke Lee | 88df712 | 2013-09-29 15:00:18 -0700 | [diff] [blame] | 417 | configureHeaderClickActions(true); |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 418 | } |
Yorke Lee | 2e38583 | 2013-09-09 14:42:01 -0700 | [diff] [blame] | 419 | } else { |
Yorke Lee | 88df712 | 2013-09-29 15:00:18 -0700 | [diff] [blame] | 420 | configureHeaderClickActions(false); |
Yorke Lee | 2e38583 | 2013-09-09 14:42:01 -0700 | [diff] [blame] | 421 | mStarImage.setVisibility(View.VISIBLE); |
| 422 | mStarImage.setOnClickListener(new OnClickListener() { |
| 423 | @Override |
| 424 | public void onClick(View view) { |
| 425 | // Toggle "starred" state |
| 426 | // Make sure there is a contact |
| 427 | if (lookupUri != null) { |
| 428 | // Changes the state of the image already before sending updates to the |
| 429 | // database |
| 430 | if (isStarred) { |
| 431 | mStarImage.setImageResource(R.drawable.ic_favorite_off_lt); |
| 432 | } else { |
| 433 | mStarImage.setImageResource(R.drawable.ic_favorite_on_lt); |
| 434 | } |
| 435 | |
| 436 | // Now perform the real save |
| 437 | final Intent intent = ContactSaveService.createSetStarredIntent(context, |
| 438 | lookupUri, !isStarred); |
| 439 | context.startService(intent); |
| 440 | } |
Christine Chen | 72b3ab1 | 2013-08-13 23:22:34 +0200 | [diff] [blame] | 441 | } |
Yorke Lee | 2e38583 | 2013-09-09 14:42:01 -0700 | [diff] [blame] | 442 | }); |
| 443 | } |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 444 | |
| 445 | mDefaultsMap.clear(); |
| 446 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 447 | Trace.endSection(); |
| 448 | Trace.beginSection("Set display photo & name"); |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 449 | |
Yorke Lee | 6219668 | 2013-09-06 18:34:17 -0700 | [diff] [blame] | 450 | mPhotoSetter.setupContactPhoto(data, mPhotoView); |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 451 | extractAndApplyTintFromPhotoViewAsynchronously(); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 452 | setHeaderNameText(R.id.name, data.getDisplayName()); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 453 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 454 | Trace.endSection(); |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 455 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 456 | final List<String> sortedActionMimeTypes = Lists.newArrayList(); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 457 | // Maintain a list of phone numbers to pass into SmsInteractionsLoader |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 458 | final List<String> phoneNumbers = Lists.newArrayList(); |
| 459 | // List of Entry that makes up the ExpandingEntryCardView |
| 460 | final List<Entry> entries = Lists.newArrayList(); |
| 461 | |
| 462 | mEntriesAndActionsTask = new AsyncTask<Void, Void, Void>() { |
| 463 | @Override |
| 464 | protected Void doInBackground(Void... params) { |
| 465 | computeEntriesAndActions(data, phoneNumbers, sortedActionMimeTypes, entries); |
| 466 | return null; |
| 467 | } |
| 468 | |
| 469 | @Override |
| 470 | protected void onPostExecute(Void aVoid) { |
| 471 | super.onPostExecute(aVoid); |
| 472 | // Check that original AsyncTask parameters are still valid and the activity |
| 473 | // is still running before binding to UI. A new intent could invalidate |
| 474 | // the results, for example. |
| 475 | if (data == mContactData && !isCancelled()) { |
| 476 | bindEntriesAndActions(entries, phoneNumbers, sortedActionMimeTypes); |
| 477 | showActivity(); |
| 478 | } |
| 479 | } |
| 480 | }; |
| 481 | mEntriesAndActionsTask.execute(); |
| 482 | } |
| 483 | |
| 484 | private void bindEntriesAndActions(List<Entry> entries, |
| 485 | List<String> phoneNumbers, |
| 486 | List<String> sortedActionMimeTypes) { |
| 487 | Trace.beginSection("start sms loader"); |
| 488 | |
| 489 | Bundle smsExtraBundle = new Bundle(); |
| 490 | smsExtraBundle.putStringArray(KEY_LOADER_EXTRA_SMS_PHONES, |
| 491 | phoneNumbers.toArray(new String[phoneNumbers.size()])); |
| 492 | getLoaderManager().initLoader( |
| 493 | LOADER_SMS_ID, |
| 494 | smsExtraBundle, |
| 495 | mLoaderInteractionsCallbacks); |
| 496 | |
| 497 | Trace.endSection(); |
| 498 | Trace.beginSection("bind communicate card"); |
| 499 | |
| 500 | if (entries.size() > 0) { |
| 501 | mCommunicationCard.initialize(entries, |
| 502 | /* numInitialVisibleEntries = */ MIN_NUM_COMMUNICATION_ENTRIES_SHOWN, |
| 503 | /* isExpanded = */ false, |
| 504 | /* themeColor = */ 0); |
| 505 | } |
| 506 | |
| 507 | final boolean hasData = !sortedActionMimeTypes.isEmpty(); |
| 508 | mCommunicationCard.setVisibility(hasData ? View.VISIBLE: View.GONE); |
| 509 | |
| 510 | Trace.endSection(); |
| 511 | } |
| 512 | |
| 513 | private void showActivity() { |
| 514 | if (mScroller != null) { |
| 515 | mScroller.setVisibility(View.VISIBLE); |
| 516 | SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, |
| 517 | new Runnable() { |
| 518 | @Override |
| 519 | public void run() { |
| 520 | runEntranceAnimation(); |
| 521 | } |
| 522 | }); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | private void computeEntriesAndActions(Contact data, List<String> phoneNumbers, |
| 527 | List<String> sortedActionMimeTypes, List<Entry> entries) { |
| 528 | Trace.beginSection("inflate entries and actions"); |
| 529 | |
| 530 | final ResolveCache cache = ResolveCache.getInstance(this); |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 531 | for (RawContact rawContact : data.getRawContacts()) { |
| 532 | for (DataItem dataItem : rawContact.getDataItems()) { |
| 533 | final String mimeType = dataItem.getMimeType(); |
Chiao Cheng | 47b6f70 | 2012-09-07 17:28:17 -0700 | [diff] [blame] | 534 | final AccountType accountType = rawContact.getAccountType(this); |
| 535 | final DataKind dataKind = AccountTypeManager.getInstance(this) |
| 536 | .getKindOrFallback(accountType, mimeType); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 537 | |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 538 | if (dataItem instanceof PhoneDataItem) { |
| 539 | phoneNumbers.add(((PhoneDataItem) dataItem).getNormalizedNumber()); |
| 540 | } |
| 541 | |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 542 | // Skip this data item if MIME-type excluded |
| 543 | if (isMimeExcluded(mimeType)) continue; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 544 | |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 545 | final long dataId = dataItem.getId(); |
| 546 | final boolean isPrimary = dataItem.isPrimary(); |
| 547 | final boolean isSuperPrimary = dataItem.isSuperPrimary(); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 548 | |
Chiao Cheng | 47b6f70 | 2012-09-07 17:28:17 -0700 | [diff] [blame] | 549 | if (dataKind != null) { |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 550 | // Build an action for this data entry, find a mapping to a UI |
| 551 | // element, build its summary from the cursor, and collect it |
| 552 | // along with all others of this MIME-type. |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 553 | final Action action = new DataAction(getApplicationContext(), |
| 554 | dataItem, dataKind); |
Maurice Chu | 8a0dd0f | 2012-04-12 16:16:32 -0700 | [diff] [blame] | 555 | final boolean wasAdded = considerAdd(action, cache, isSuperPrimary); |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 556 | if (wasAdded) { |
| 557 | // Remember the default |
| 558 | if (isSuperPrimary || (isPrimary && (mDefaultsMap.get(mimeType) == null))) { |
| 559 | mDefaultsMap.put(mimeType, action); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 560 | } |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 561 | } |
| 562 | } |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 563 | |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 564 | // Handle Email rows with presence data as Im entry |
Daniel Lehmann | 9daca14 | 2011-12-20 11:41:22 +0200 | [diff] [blame] | 565 | final DataStatus status = data.getStatuses().get(dataId); |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 566 | if (status != null && dataItem instanceof EmailDataItem) { |
| 567 | final EmailDataItem email = (EmailDataItem) dataItem; |
| 568 | final ImDataItem im = ImDataItem.createFromEmail(email); |
Chiao Cheng | 47b6f70 | 2012-09-07 17:28:17 -0700 | [diff] [blame] | 569 | if (dataKind != null) { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 570 | final DataAction action = new DataAction(getApplicationContext(), |
| 571 | im, dataKind); |
Daniel Lehmann | 9daca14 | 2011-12-20 11:41:22 +0200 | [diff] [blame] | 572 | action.setPresence(status.getPresence()); |
Maurice Chu | 8a0dd0f | 2012-04-12 16:16:32 -0700 | [diff] [blame] | 573 | considerAdd(action, cache, isSuperPrimary); |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 574 | } |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 579 | Trace.endSection(); |
| 580 | Trace.beginSection("collapsing action list"); |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 581 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 582 | // Collapse Action Lists (remove e.g. duplicate e-mail addresses from different sources) |
| 583 | for (List<Action> actionChildren : mActions.values()) { |
| 584 | Collapser.collapseList(actionChildren); |
| 585 | } |
| 586 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 587 | Trace.endSection(); |
| 588 | Trace.beginSection("sort mimetypes"); |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 589 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 590 | // All the mime-types to add. |
| 591 | final Set<String> containedTypes = new HashSet<String>(mActions.keySet()); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 592 | // First, add LEADING_MIMETYPES, which are most common. |
| 593 | for (String mimeType : LEADING_MIMETYPES) { |
| 594 | if (containedTypes.contains(mimeType)) { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 595 | sortedActionMimeTypes.add(mimeType); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 596 | containedTypes.remove(mimeType); |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 597 | entries.addAll(actionsToEntries(mActions.get(mimeType))); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | |
| 601 | // Add all the remaining ones that are not TRAILING |
| 602 | for (String mimeType : containedTypes.toArray(new String[containedTypes.size()])) { |
| 603 | if (!TRAILING_MIMETYPES.contains(mimeType)) { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 604 | sortedActionMimeTypes.add(mimeType); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 605 | containedTypes.remove(mimeType); |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 606 | entries.addAll(actionsToEntries(mActions.get(mimeType))); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | |
| 610 | // Then, add TRAILING_MIMETYPES, which are least common. |
| 611 | for (String mimeType : TRAILING_MIMETYPES) { |
| 612 | if (containedTypes.contains(mimeType)) { |
| 613 | containedTypes.remove(mimeType); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 614 | sortedActionMimeTypes.add(mimeType); |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 615 | entries.addAll(actionsToEntries(mActions.get(mimeType))); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 618 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 619 | Trace.endSection(); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | /** |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 623 | * Asynchronously extract the most vibrant color from the PhotoView. Once extracted, |
| 624 | * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms |
| 625 | * on a Nexus 5. |
| 626 | */ |
| 627 | private void extractAndApplyTintFromPhotoViewAsynchronously() { |
| 628 | if (mScroller == null) { |
| 629 | return; |
| 630 | } |
| 631 | final Drawable imageViewDrawable = mPhotoView.getDrawable(); |
| 632 | new AsyncTask<Void, Void, Integer>() { |
| 633 | @Override |
| 634 | protected Integer doInBackground(Void... params) { |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 635 | if (imageViewDrawable instanceof BitmapDrawable) { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 636 | final Bitmap bitmap = ((BitmapDrawable) imageViewDrawable).getBitmap(); |
| 637 | return colorFromBitmap(bitmap); |
| 638 | } |
| 639 | if (imageViewDrawable instanceof LetterTileDrawable) { |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 640 | // LetterTileDrawable doesn't normally draw unless it is visible. Therefore, |
| 641 | // we need to directly ask it for its color via getColor(). We could directly |
| 642 | // return this color. However, in the future Palette#generate() may incorporate |
| 643 | // saturation boosting. So I want to use Palette#generate() for the sake of |
| 644 | // consistency. |
| 645 | final LetterTileDrawable tileDrawable = (LetterTileDrawable) imageViewDrawable; |
| 646 | final int PALETTE_BITMAP_SIZE = 1; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 647 | final Bitmap bitmap = Bitmap.createBitmap(PALETTE_BITMAP_SIZE, |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 648 | PALETTE_BITMAP_SIZE, Bitmap.Config.ARGB_8888); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 649 | // If Palette can not extract a primary color, our UX person says we are better |
| 650 | // off using the LetterTileDrawable's non vibrant color than falling back |
| 651 | // to the app's default color. |
| 652 | final int color = colorFromBitmap(bitmap); |
| 653 | if (color == 0) { |
| 654 | return tileDrawable.getColor(); |
| 655 | } else { |
| 656 | return color; |
| 657 | } |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 658 | } |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 659 | return 0; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | @Override |
| 663 | protected void onPostExecute(Integer color) { |
| 664 | super.onPostExecute(color); |
| 665 | if (color != 0 && imageViewDrawable == mPhotoView.getDrawable()) { |
| 666 | // TODO: animate from the previous tint. |
| 667 | mScroller.setHeaderTintColor(color); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 668 | |
| 669 | // Create a darker version of the actionbar color. HSV is device dependent |
| 670 | // and not perceptually-linear. Therefore, we can't say mStatusBarColor is |
| 671 | // 70% as bright as the action bar color. We can only say: it is a bit darker. |
| 672 | final float hsvComponents[] = new float[3]; |
| 673 | Color.colorToHSV(color, hsvComponents); |
| 674 | hsvComponents[2] *= SYSTEM_BAR_BRIGHTNESS_FACTOR; |
| 675 | mStatusBarColor = Color.HSVToColor(hsvComponents); |
| 676 | |
| 677 | updateStatusBarColor(); |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | }.execute(); |
| 681 | } |
| 682 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 683 | private void updateStatusBarColor() { |
| 684 | if (mScroller == null) { |
| 685 | return; |
| 686 | } |
| 687 | final int desiredStatusBarColor; |
| 688 | // Only use a custom status bar color if QuickContacts touches the top of the viewport. |
| 689 | if (mScroller.getScrollNeededToBeFullScreen() <= 0) { |
| 690 | desiredStatusBarColor = mStatusBarColor; |
| 691 | } else { |
| 692 | desiredStatusBarColor = Color.TRANSPARENT; |
| 693 | } |
| 694 | // Animate to the new color. |
| 695 | if (desiredStatusBarColor != getWindow().getStatusBarColor()) { |
| 696 | final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor", |
| 697 | getWindow().getStatusBarColor(), desiredStatusBarColor); |
| 698 | animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION); |
| 699 | animation.setEvaluator(new ArgbEvaluator()); |
| 700 | animation.start(); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | private int colorFromBitmap(Bitmap bitmap) { |
| 705 | // Author of Palette recommends using 24 colors when analyzing profile photos. |
| 706 | final int NUMBER_OF_PALETTE_COLORS = 24; |
| 707 | final Palette palette = Palette.generate(bitmap, NUMBER_OF_PALETTE_COLORS); |
| 708 | if (palette != null && palette.getVibrantColor() != null) { |
| 709 | return palette.getVibrantColor().getRgb(); |
| 710 | } |
| 711 | return 0; |
| 712 | } |
| 713 | |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 714 | /** |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 715 | * Consider adding the given {@link Action}, which will only happen if |
| 716 | * {@link PackageManager} finds an application to handle |
| 717 | * {@link Action#getIntent()}. |
Maurice Chu | 8a0dd0f | 2012-04-12 16:16:32 -0700 | [diff] [blame] | 718 | * @param action the action to handle |
| 719 | * @param resolveCache cache of applications that can handle actions |
| 720 | * @param front indicates whether to add the action to the front of the list |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 721 | * @return true if action has been added |
| 722 | */ |
Maurice Chu | 8a0dd0f | 2012-04-12 16:16:32 -0700 | [diff] [blame] | 723 | private boolean considerAdd(Action action, ResolveCache resolveCache, boolean front) { |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 724 | if (resolveCache.hasResolve(action)) { |
Maurice Chu | 8a0dd0f | 2012-04-12 16:16:32 -0700 | [diff] [blame] | 725 | mActions.put(action.getMimeType(), action, front); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 726 | return true; |
| 727 | } |
| 728 | return false; |
| 729 | } |
| 730 | |
| 731 | /** |
Yorke Lee | 88df712 | 2013-09-29 15:00:18 -0700 | [diff] [blame] | 732 | * Bind the correct image resource and click handlers to the header views |
| 733 | * |
| 734 | * @param canAdd Whether or not the user can directly add information in this quick contact |
| 735 | * to their local contacts |
| 736 | */ |
| 737 | private void configureHeaderClickActions(boolean canAdd) { |
| 738 | if (canAdd) { |
Paul Soulos | b8eb33c | 2014-05-30 15:32:48 -0700 | [diff] [blame] | 739 | mEditOrAddContactImage.setImageResource(R.drawable.ic_person_add_24dp); |
Paul Soulos | 5ec23fd | 2014-05-29 18:19:38 -0700 | [diff] [blame] | 740 | mEditOrAddContactImage.setOnClickListener(mAddToContactsClickHandler); |
Yorke Lee | 88df712 | 2013-09-29 15:00:18 -0700 | [diff] [blame] | 741 | mPhotoView.setOnClickListener(mAddToContactsClickHandler); |
| 742 | } else { |
Paul Soulos | b8eb33c | 2014-05-30 15:32:48 -0700 | [diff] [blame] | 743 | mEditOrAddContactImage.setImageResource(R.drawable.ic_create_24dp); |
Paul Soulos | 5ec23fd | 2014-05-29 18:19:38 -0700 | [diff] [blame] | 744 | mEditOrAddContactImage.setOnClickListener(mEditContactClickHandler); |
| 745 | mPhotoView.setOnClickListener(mEditContactClickHandler); |
Yorke Lee | 88df712 | 2013-09-29 15:00:18 -0700 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | |
| 749 | /** |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 750 | * Converts a list of Action into a list of Entry |
| 751 | * @param actions The list of Action to convert |
| 752 | * @return The converted list of Entry |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 753 | */ |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 754 | private List<Entry> actionsToEntries(List<Action> actions) { |
| 755 | List<Entry> entries = new ArrayList<>(); |
| 756 | for (Action action : actions) { |
| 757 | entries.add(new Entry(ResolveCache.getInstance(this).getIcon(action), |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 758 | action.getMimeType(), |
| 759 | action.getSubtitle() == null ? null : action.getSubtitle().toString(), |
| 760 | action.getBody() == null ? null : action.getBody().toString(), |
| 761 | action.getIntent(), /* isEditable= */ false)); |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 762 | } |
| 763 | return entries; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 766 | private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) { |
| 767 | List<Entry> entries = new ArrayList<>(); |
| 768 | for (ContactInteraction interaction : interactions) { |
| 769 | entries.add(new Entry(interaction.getIcon(this), |
| 770 | interaction.getViewHeader(this), |
| 771 | interaction.getViewBody(this), |
| 772 | interaction.getBodyIcon(this), |
| 773 | interaction.getViewFooter(this), |
| 774 | interaction.getFooterIcon(this), |
| 775 | interaction.getIntent(), |
| 776 | /* isEditable = */ false)); |
| 777 | } |
| 778 | return entries; |
| 779 | } |
| 780 | |
| 781 | private LoaderCallbacks<Contact> mLoaderContactCallbacks = |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 782 | new LoaderCallbacks<Contact>() { |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 783 | @Override |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 784 | public void onLoaderReset(Loader<Contact> loader) { |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | @Override |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 788 | public void onLoadFinished(Loader<Contact> loader, Contact data) { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 789 | Trace.beginSection("onLoadFinished()"); |
| 790 | |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 791 | if (isFinishing()) { |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 792 | return; |
| 793 | } |
| 794 | if (data.isError()) { |
| 795 | // This shouldn't ever happen, so throw an exception. The {@link ContactLoader} |
| 796 | // should log the actual exception. |
| 797 | throw new IllegalStateException("Failed to load contact", data.getException()); |
| 798 | } |
| 799 | if (data.isNotFound()) { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 800 | if (mHasAlreadyBeenOpened) { |
| 801 | finish(); |
| 802 | } else { |
| 803 | Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri()); |
| 804 | Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, |
| 805 | Toast.LENGTH_LONG).show(); |
| 806 | } |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 807 | return; |
| 808 | } |
| 809 | |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 810 | bindContactData(data); |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 811 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 812 | Trace.endSection(); |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | @Override |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 816 | public Loader<Contact> onCreateLoader(int id, Bundle args) { |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 817 | if (mLookupUri == null) { |
| 818 | Log.wtf(TAG, "Lookup uri wasn't initialized. Loader was started too early"); |
| 819 | } |
Yorke Lee | b2b435a | 2012-11-12 16:47:06 -0800 | [diff] [blame] | 820 | return new ContactLoader(getApplicationContext(), mLookupUri, |
Paul Sliwowski | 45f23d4 | 2013-08-27 15:29:40 -0700 | [diff] [blame] | 821 | false /*loadGroupMetaData*/, false /*loadInvitableAccountTypes*/, |
| 822 | false /*postViewNotification*/, true /*computeFormattedPhoneNumber*/); |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 823 | } |
| 824 | }; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 825 | |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 826 | @Override |
| 827 | public void onBackPressed() { |
| 828 | if (mScroller != null) { |
| 829 | // TODO: implement exit animation if the scroller isn't already off the screen |
| 830 | finish(); |
| 831 | } else { |
| 832 | super.onBackPressed(); |
| 833 | } |
| 834 | } |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 835 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 836 | @Override |
| 837 | public void finish() { |
| 838 | super.finish(); |
| 839 | |
| 840 | // override transitions to skip the standard window animations |
| 841 | overridePendingTransition(0, 0); |
| 842 | } |
| 843 | |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 844 | private LoaderCallbacks<List<ContactInteraction>> mLoaderInteractionsCallbacks = |
| 845 | new LoaderCallbacks<List<ContactInteraction>>() { |
| 846 | |
| 847 | @Override |
| 848 | public Loader<List<ContactInteraction>> onCreateLoader(int id, Bundle args) { |
| 849 | Log.v(TAG, "onCreateLoader"); |
| 850 | Loader<List<ContactInteraction>> loader = null; |
| 851 | switch (id) { |
| 852 | case LOADER_SMS_ID: |
| 853 | Log.v(TAG, "LOADER_SMS_ID"); |
| 854 | loader = new SmsInteractionsLoader( |
| 855 | QuickContactActivity.this, |
| 856 | args.getStringArray(KEY_LOADER_EXTRA_SMS_PHONES), |
| 857 | MAX_SMS_RETRIEVE); |
| 858 | break; |
| 859 | } |
| 860 | return loader; |
| 861 | } |
| 862 | |
| 863 | @Override |
| 864 | public void onLoadFinished(Loader<List<ContactInteraction>> loader, |
| 865 | List<ContactInteraction> data) { |
| 866 | if (mRecentLoaderResults == null) { |
| 867 | mRecentLoaderResults = new HashMap<Integer, List<ContactInteraction>>(); |
| 868 | } |
| 869 | mRecentLoaderResults.put(loader.getId(), data); |
| 870 | |
| 871 | if (isAllRecentDataLoaded()) { |
| 872 | bindRecentData(); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | @Override |
| 877 | public void onLoaderReset(Loader<List<ContactInteraction>> loader) { |
| 878 | mRecentLoaderResults.remove(loader.getId()); |
| 879 | } |
| 880 | |
| 881 | }; |
| 882 | |
| 883 | private boolean isAllRecentDataLoaded() { |
| 884 | return mRecentLoaderResults.size() == mRecentLoaderIds.length; |
| 885 | } |
| 886 | |
| 887 | private void bindRecentData() { |
| 888 | List<ContactInteraction> allInteractions = new ArrayList<>(); |
| 889 | for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) { |
| 890 | allInteractions.addAll(loaderInteractions); |
| 891 | } |
| 892 | |
| 893 | // Sort the interactions by most recent |
| 894 | Collections.sort(allInteractions, new Comparator<ContactInteraction>() { |
| 895 | @Override |
| 896 | public int compare(ContactInteraction a, ContactInteraction b) { |
| 897 | return a.getInteractionDate() >= b.getInteractionDate() ? -1 : 1; |
| 898 | } |
| 899 | }); |
| 900 | |
| 901 | if (allInteractions.size() > 0) { |
| 902 | mRecentCard.initialize(contactInteractionsToEntries(allInteractions), |
| 903 | /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN, |
| 904 | /* isExpanded = */ false, |
| 905 | /* themeColor = */ 0); |
| 906 | mRecentCard.setVisibility(View.VISIBLE); |
| 907 | } |
| 908 | } |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame^] | 909 | |
| 910 | @Override |
| 911 | protected void onStop() { |
| 912 | super.onStop(); |
| 913 | |
| 914 | if (mEntriesAndActionsTask != null) { |
| 915 | // Once the activity is stopped, we will no longer want to bind mEntriesAndActionsTask's |
| 916 | // results on the UI thread. In some circumstances Activities are killed without |
| 917 | // onStop() being called. This is not a problem, because in these circumstances |
| 918 | // the entire process will be killed. |
| 919 | mEntriesAndActionsTask.cancel(/* mayInterruptIfRunning = */ false); |
| 920 | } |
| 921 | } |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 922 | } |