QuickContactActivity.java revision f9d5c0e24d1b11527475227549f9530127e9dc07
1edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/* 2edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Copyright (C) 2009 The Android Open Source Project 3edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 4edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Licensed under the Apache License, Version 2.0 (the "License"); 5edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * you may not use this file except in compliance with the License. 6edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * You may obtain a copy of the License at 7edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 8edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * http://www.apache.org/licenses/LICENSE-2.0 9edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 10edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Unless required by applicable law or agreed to in writing, software 11edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * distributed under the License is distributed on an "AS IS" BASIS, 12edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * See the License for the specific language governing permissions and 14edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * limitations under the License. 15edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 16edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 17edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannpackage com.android.contacts.quickcontact; 18edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 198477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwellimport android.animation.Animator; 208477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwellimport android.animation.Animator.AnimatorListener; 218477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwellimport android.animation.AnimatorListenerAdapter; 228a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.animation.ArgbEvaluator; 23b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport android.animation.ObjectAnimator; 24edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.app.Activity; 25d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.app.Fragment; 26cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.app.LoaderManager.LoaderCallbacks; 27eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.app.SearchManager; 28752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.content.ActivityNotFoundException; 29eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.content.ComponentName; 30edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.ContentUris; 31ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulosimport android.content.ContentValues; 32edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.Intent; 33cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.content.Loader; 3431b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.Bitmap; 358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.Color; 36eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuff; 37eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuffColorFilter; 3831b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.BitmapDrawable; 398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.drawable.ColorDrawable; 4031b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.Drawable; 41eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.net.ParseException; 42edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.net.Uri; 43eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.net.WebAddress; 4431b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.os.AsyncTask; 45edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.os.Bundle; 468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.os.Trace; 47eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.CalendarContract; 48752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.provider.ContactsContract; 49edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Email; 50eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Event; 51eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.GroupMembership; 52eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Identity; 53eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Im; 54eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Nickname; 55eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Note; 56eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Organization; 57edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Phone; 58eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Relation; 59edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.SipAddress; 60edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.StructuredPostal; 61edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Website; 62752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.provider.ContactsContract.Contacts; 63eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.DisplayNameSources; 64ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulosimport android.provider.ContactsContract.DataUsageFeedback; 65edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.QuickContact; 66edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.RawContacts; 6731b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.support.v7.graphics.Palette; 68edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.text.TextUtils; 69edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.util.Log; 70eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.util.Pair; 71d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.Menu; 72d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.MenuInflater; 73eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.view.MenuItem; 74edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View; 75edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View.OnClickListener; 7610d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawaimport android.view.WindowManager; 77edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.widget.ImageView; 78edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.widget.Toast; 79d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.widget.Toolbar; 80edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 8172b3ab1d8a62f228a540b05f4ed6373e494c7d72Christine Chenimport com.android.contacts.ContactSaveService; 82d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.ContactsActivity; 83e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.R; 84eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.CallUtil; 85eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.Collapser; 86eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.ContactsUtils; 87d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.common.editor.SelectAccountDialogFragment; 8831b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport com.android.contacts.common.lettertiles.LetterTileDrawable; 89752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder; 90752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder.OnShortcutIntentCreatedListener; 910d5588da244d0992c3ff8f25d0875fdf95a8c644Chiao Chengimport com.android.contacts.common.model.AccountTypeManager; 92cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.Contact; 93cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.ContactLoader; 94cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.RawContact; 95428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.account.AccountType; 96d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.common.model.account.AccountWithDataSet; 97cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.DataItem; 98428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.dataitem.DataKind; 99cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.EmailDataItem; 100eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.EventDataItem; 101cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.ImDataItem; 102eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NicknameDataItem; 103eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NoteDataItem; 104eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.OrganizationDataItem; 105b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.common.model.dataitem.PhoneDataItem; 106eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.RelationDataItem; 107eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.SipAddressDataItem; 108eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredNameDataItem; 109eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredPostalDataItem; 110eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.WebsiteDataItem; 111eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.util.DateUtils; 112d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.detail.ContactDetailDisplayUtils; 113899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport com.android.contacts.interactions.CalendarInteractionsLoader; 114ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulosimport com.android.contacts.interactions.CallLogInteractionsLoader; 1158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport com.android.contacts.interactions.ContactDeletionInteraction; 116b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.ContactInteraction; 117b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.SmsInteractionsLoader; 1182d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.Entry; 119e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwellimport com.android.contacts.quickcontact.ExpandingEntryCardView.ExpandingEntryCardViewListener; 120e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.util.ImageViewDrawableSetter; 121eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.PhoneCapabilityTester; 122b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.util.SchedulingUtils; 123eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.StructuredPostalUtils; 124b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller; 125b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener; 126eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.google.common.annotations.VisibleForTesting; 127e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.google.common.base.Preconditions; 128e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.google.common.collect.Lists; 129e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng 1302d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport java.util.ArrayList; 131899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport java.util.Arrays; 132eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Calendar; 133b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Collections; 134b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Comparator; 135eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Date; 136edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.HashMap; 137edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.HashSet; 138edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.List; 139b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Map; 140edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.Set; 141edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 142edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/** 143edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Mostly translucent {@link Activity} that shows QuickContact dialog. It loads 144edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * data asynchronously, and then shows a popup with details centered around 145edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * {@link Intent#getSourceBounds()}. 146edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 147d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellpublic class QuickContactActivity extends ContactsActivity { 1488a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1498a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell /** 1508a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * QuickContacts immediately takes up the full screen. All possible information is shown. 1518a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * This value for {@link android.provider.ContactsContract.QuickContact#EXTRA_MODE} 1528a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * should only be used by the Contacts app. 1538a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell */ 1548a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public static final int MODE_FULLY_EXPANDED = 4; 1558a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 156edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String TAG = "QuickContact"; 157edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1589b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final String KEY_THEME_COLOR = "theme_color"; 1599b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 1609b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final int ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION = 150; 1618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private static final int REQUEST_CODE_CONTACT_EDITOR_ACTIVITY = 1; 1628a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private static final float SYSTEM_BAR_BRIGHTNESS_FACTOR = 0.7f; 1639b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final int SCRIM_COLOR = Color.argb(0xB2, 0, 0, 0); 164ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos private static final String SCHEME_SMSTO = "smsto"; 165ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos private static final String MIMETYPE_SMS = "vnd.android-dir/mms-sms"; 166dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 167752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** This is the Intent action to install a shortcut in the launcher. */ 168752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private static final String ACTION_INSTALL_SHORTCUT = 169752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell "com.android.launcher.action.INSTALL_SHORTCUT"; 170edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 171edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @SuppressWarnings("deprecation") 172edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String LEGACY_AUTHORITY = android.provider.Contacts.AUTHORITY; 173edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 174edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private Uri mLookupUri; 175edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private String[] mExcludeMimes; 1768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mExtraMode; 1778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mStatusBarColor; 1788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private boolean mHasAlreadyBeenOpened; 179edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1806219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee private ImageView mPhotoView; 1810d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell private View mTransparentView; 182eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mContactCard; 183b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private ExpandingEntryCardView mRecentCard; 184eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mAboutCard; 185eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 186eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * This list contains all the {@link DataItem}s. Each nested list contains all data items of a 187eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * specific mimetype in sorted order, using mWithinMimeTypeDataItemComparator. The mimetype 188eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * lists are sorted using mAmongstMimeTypeDataItemComparator. 189eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 190eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private List<List<DataItem>> mDataItemsList; 191eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 192eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * A map between a mimetype string and the corresponding list of data items. The data items 193eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * are in sorted order using mWithinMimeTypeDataItemComparator. 194eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 195eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private Map<String, List<DataItem>> mDataItemsMap; 196b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private MultiShrinkScroller mScroller; 197d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private SelectAccountDialogFragmentListener mSelectAccountFragmentListener; 198eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private AsyncTask<Void, Void, Pair<List<List<DataItem>>, Map<String, List<DataItem>>>> 199eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mEntriesAndActionsTask; 2009b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private ColorDrawable mWindowScrim; 2018477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell private boolean mIsWaitingForOtherPieceOfExitAnimation; 2028477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell private boolean mIsExitAnimationInProgress; 2038571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell private boolean mHasComputedThemeColor; 204eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ComponentName mSmsComponent; 205edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 206eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private static final int MIN_NUM_CONTACT_ENTRIES_SHOWN = 3; 207b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN = 3; 208b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2096cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee private Contact mContactData; 2109815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann private ContactLoader mContactLoader; 2119b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private PorterDuffColorFilter mColorFilter; 2129815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann 2139758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter(); 2149758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus 215edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 216edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * {@link #LEADING_MIMETYPES} and {@link #TRAILING_MIMETYPES} are used to sort MIME-types. 217edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 218edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * <p>The MIME-types in {@link #LEADING_MIMETYPES} appear in the front of the dialog, 219edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * in the order specified here.</p> 220edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 221edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * <p>The ones in {@link #TRAILING_MIMETYPES} appear in the end of the dialog, in the order 222edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * specified here.</p> 223edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 224edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * <p>The rest go between them, in the order in the array.</p> 225edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 226edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final List<String> LEADING_MIMETYPES = Lists.newArrayList( 227edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann Phone.CONTENT_ITEM_TYPE, SipAddress.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE); 228edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 229edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** See {@link #LEADING_MIMETYPES}. */ 230edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final List<String> TRAILING_MIMETYPES = Lists.newArrayList( 231edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann StructuredPostal.CONTENT_ITEM_TYPE, Website.CONTENT_ITEM_TYPE); 232edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 233eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private static final List<String> ABOUT_CARD_MIMETYPES = Lists.newArrayList( 234eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Event.CONTENT_ITEM_TYPE, GroupMembership.CONTENT_ITEM_TYPE, Identity.CONTENT_ITEM_TYPE, 235eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Im.CONTENT_ITEM_TYPE, Nickname.CONTENT_ITEM_TYPE, Note.CONTENT_ITEM_TYPE, 236eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Organization.CONTENT_ITEM_TYPE, Relation.CONTENT_ITEM_TYPE, Website.CONTENT_ITEM_TYPE); 237eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 238b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background contact loader */ 239b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_CONTACT_ID = 0; 240b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 241ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final String KEY_LOADER_EXTRA_PHONES = 242ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_PHONES"; 243ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 244b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background Sms Loader */ 245b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_SMS_ID = 1; 246b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int MAX_SMS_RETRIEVE = 3; 247ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 248ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the back Calendar Loader */ 249899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int LOADER_CALENDAR_ID = 2; 250ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final String KEY_LOADER_EXTRA_EMAILS = 251ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_EMAILS"; 252899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_PAST_CALENDAR_RETRIEVE = 3; 253899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_FUTURE_CALENDAR_RETRIEVE = 3; 254899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 255899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 180L * 24L * 60L * 60L * 1000L /* 180 days */; 256899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 257899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 36L * 60L * 60L * 1000L /* 36 hours */; 258899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 259ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the background Call Log Loader */ 260ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int LOADER_CALL_LOG_ID = 3; 261ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int MAX_CALL_LOG_RETRIEVE = 3; 262ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 263ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 264ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int[] mRecentLoaderIds = new int[]{ 265ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_SMS_ID, 266ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALENDAR_ID, 267ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID}; 268b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private Map<Integer, List<ContactInteraction>> mRecentLoaderResults; 269b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 270d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private static final String FRAGMENT_TAG_SELECT_ACCOUNT = "select_account_fragment"; 2716cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee 2722d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos final OnClickListener mEntryClickHandler = new OnClickListener() { 2732d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos @Override 2742d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos public void onClick(View v) { 275ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Data Id is stored as the entry view id 276ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final int dataId = v.getId(); 277ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Object intentObject = v.getTag(); 278ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (intentObject == null || !(intentObject instanceof Intent)) { 279ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Log.w(TAG, "Intent tag was not used correctly"); 2802d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos return; 2812d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 282ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final Intent intent = (Intent) intentObject; 283ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 284ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Default to USAGE_TYPE_CALL. Usage is summed among all types for sorting each data id 285ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // so the exact usage type is not necessary in all cases 286ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos String usageType = DataUsageFeedback.USAGE_TYPE_CALL; 287ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 288ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (intent.getData().getScheme().equals(SCHEME_SMSTO) || 289ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos (intent.getType() != null && intent.getType().equals(MIMETYPE_SMS))) { 290ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos usageType = DataUsageFeedback.USAGE_TYPE_SHORT_TEXT; 291ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 292ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 293ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Data IDs start at 1 so anything less is invalid 294ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (dataId > 0) { 295ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final Uri uri = DataUsageFeedback.FEEDBACK_URI.buildUpon() 296ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendPath(String.valueOf(dataId)) 297ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, usageType) 298ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .build(); 299ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final boolean successful = getContentResolver().update( 300ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos uri, new ContentValues(), null, null) > 0; 301ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (!successful) { 302ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Log.w(TAG, "DataUsageFeedback increment failed"); 303ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 304ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } else { 305ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Log.w(TAG, "Invalid Data ID"); 306ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 307ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 308ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos startActivity(intent); 3092d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 3102d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos }; 3112d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos 312e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell final ExpandingEntryCardViewListener mExpandingEntryCardViewListener 313e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell = new ExpandingEntryCardViewListener() { 314e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell @Override 315e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell public void onCollapse(int heightDelta) { 316e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell mScroller.prepareForShrinkingScrollChild(heightDelta); 317e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell } 318e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell }; 319e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell 320d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell /** 321d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Headless fragment used to handle account selection callbacks invoked from 322d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * {@link DirectoryContactUtil}. 323d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 324d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public static class SelectAccountDialogFragmentListener extends Fragment 325d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell implements SelectAccountDialogFragment.Listener { 326d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 327d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private QuickContactActivity mQuickContactActivity; 328d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 329d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public SelectAccountDialogFragmentListener() {} 330d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 331d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 332d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void onAccountChosen(AccountWithDataSet account, Bundle extraArgs) { 333d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell DirectoryContactUtil.createCopy(mQuickContactActivity.mContactData.getContentValues(), 334d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell account, mQuickContactActivity); 335d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 336d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 337d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 338d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void onAccountSelectorCancelled() {} 339d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 340d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell /** 341d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Set the parent activity. Since rotation can cause this fragment to be used across 342d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * more than one activity instance, we need to explicitly set this value instead 343d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * of making this class non-static. 344d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 345d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void setQuickContactActivity(QuickContactActivity quickContactActivity) { 346d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mQuickContactActivity = quickContactActivity; 347d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 348d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 349d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 350b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell final MultiShrinkScrollerListener mMultiShrinkScrollerListener 351b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell = new MultiShrinkScrollerListener() { 352b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 353b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onScrolledOffBottom() { 3548477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell if (!mIsWaitingForOtherPieceOfExitAnimation) { 3558477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell finish(); 3568477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell return; 3578477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 3588477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mIsWaitingForOtherPieceOfExitAnimation = false; 359b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 3608a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 3618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 3628a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onEnterFullscreen() { 3638a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 3648a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 3658a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 3668a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 3678a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onExitFullscreen() { 3688a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 3698a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 3708477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 3718477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 3728477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell public void onStartScrollOffBottom() { 3738477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell // Remove the window shim now that we are starting an Activity exit animation. 3748477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell final int duration = getResources().getInteger(android.R.integer.config_shortAnimTime); 3759b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell final ObjectAnimator animator = ObjectAnimator.ofInt(mWindowScrim, "alpha", 0xFF, 0); 3768477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell animator.addListener(mExitWindowShimAnimationListener); 3778477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell animator.setDuration(duration).start(); 3788477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mIsWaitingForOtherPieceOfExitAnimation = true; 3798477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mIsExitAnimationInProgress = true; 3808477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 3818477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell }; 3828477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 3838477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell final AnimatorListener mExitWindowShimAnimationListener = new AnimatorListenerAdapter() { 3848477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 3858477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell public void onAnimationEnd(Animator animation) { 3868477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell if (!mIsWaitingForOtherPieceOfExitAnimation) { 3878477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell finish(); 3888477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell return; 3898477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 3908477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mIsWaitingForOtherPieceOfExitAnimation = false; 3918477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 392b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell }; 393b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 394eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 395eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 396eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Data items are compared to the same mimetype based off of three qualities: 397eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 1. Super primary 398eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 2. Primary 399eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 3. Times used 400eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 401eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<DataItem> mWithinMimeTypeDataItemComparator = 402eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<DataItem>() { 403eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 404eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(DataItem lhs, DataItem rhs) { 405eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!lhs.getMimeType().equals(rhs.getMimeType())) { 406eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Log.wtf(TAG, "Comparing DataItems with different mimetypes lhs.getMimeType(): " + 407eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getMimeType() + " rhs.getMimeType(): " + rhs.getMimeType()); 408eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 409eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 410eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 411eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lhs.isSuperPrimary()) { 412eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 413eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (rhs.isSuperPrimary()) { 414eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 415eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lhs.isPrimary() && !rhs.isPrimary()) { 416eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 417eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (!lhs.isPrimary() && rhs.isPrimary()) { 418eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 419eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 420eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = 421eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 422eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = 423eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 424eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 425eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return rhsTimesUsed - lhsTimesUsed; 426eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 427eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 428eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 429eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 430eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<List<DataItem>> mAmongstMimeTypeDataItemComparator = 431eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<List<DataItem>> () { 432eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 433eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(List<DataItem> lhsList, List<DataItem> rhsList) { 434eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataItem lhs = lhsList.get(0); 435eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataItem rhs = rhsList.get(0); 436eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 437eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 438eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int timesUsedDifference = rhsTimesUsed - lhsTimesUsed; 439eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (timesUsedDifference != 0) { 440eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return timesUsedDifference; 441eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 442eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 443eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lhsLastTimeUsed = 444eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getLastTimeUsed() == null ? 0 : lhs.getLastTimeUsed(); 445eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long rhsLastTimeUsed = 446eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getLastTimeUsed() == null ? 0 : rhs.getLastTimeUsed(); 447eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lastTimeUsedDifference = rhsLastTimeUsed - lhsLastTimeUsed; 448eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lastTimeUsedDifference > 0) { 449eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 450eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lastTimeUsedDifference < 0) { 451eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 452eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 453eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 454eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Times used and last time used are the same. Resort to statically defined. 455eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String lhsMimeType = lhs.getMimeType(); 456eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String rhsMimeType = rhs.getMimeType(); 457eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (String mimeType : LEADING_MIMETYPES) { 458eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lhsMimeType.equals(mimeType)) { 459eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 460eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (rhsMimeType.equals(mimeType)) { 461eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 462eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 463eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 464eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Trailing types come last, so flip the returns 465eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (String mimeType : TRAILING_MIMETYPES) { 466eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lhsMimeType.equals(mimeType)) { 467eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 468eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (rhsMimeType.equals(mimeType)) { 469eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 470eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 471eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 472eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 473eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 474eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 475eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 476edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @Override 4778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onCreate(Bundle savedInstanceState) { 4788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onCreate()"); 4798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onCreate(savedInstanceState); 480edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 4818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getWindow().setStatusBarColor(Color.TRANSPARENT); 4828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Since we can't disable Window animations from the Launcher, we can minimize the 4838a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // silliness of the animation by setting the navigation bar transparent. 4848a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getWindow().setNavigationBarColor(Color.TRANSPARENT); 4852426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann 486d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(getIntent()); 487dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 48810d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa // Show QuickContact in front of soft input 48910d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 49010d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 49110d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa 492edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann setContentView(R.layout.quickcontact_activity); 493edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 494eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mSmsComponent = PhoneCapabilityTester.getSmsComponent(this); 495eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 496eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard = (ExpandingEntryCardView) findViewById(R.id.communication_card); 497b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card); 498eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard = (ExpandingEntryCardView) findViewById(R.id.about_card); 499b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell mScroller = (MultiShrinkScroller) findViewById(R.id.multiscroller); 500edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 501eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setOnClickListener(mEntryClickHandler); 502eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setTitle(getResources().getString(R.string.communication_card_title)); 503eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setExpandButtonText( 50423889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos getResources().getString(R.string.expanding_entry_card_view_see_all)); 505b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 506b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setOnClickListener(mEntryClickHandler); 507b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setTitle(getResources().getString(R.string.recent_card_title)); 508edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 509eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setOnClickListener(mEntryClickHandler); 510eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 511d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mPhotoView = (ImageView) findViewById(R.id.photo); 5120d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell mTransparentView = findViewById(R.id.transparent_view); 5130d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell if (mScroller != null) { 5140d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell mTransparentView.setOnClickListener(new OnClickListener() { 5150d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell @Override 5160d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell public void onClick(View v) { 5170d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell mScroller.scrollOffBottom(); 5180d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 5190d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell }); 5200d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 521edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 522d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 523d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell setActionBar(toolbar); 5249b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getActionBar().setTitle(null); 5259b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // Put a TextView with a known resource id into the ActionBar. This allows us to easily 5269b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // find the correct TextView location & size later. 5279b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell toolbar.addView(getLayoutInflater().inflate(R.layout.quickcontact_title_placeholder, null)); 5286219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee 5298a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = savedInstanceState != null; 5308a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 5319b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mWindowScrim = new ColorDrawable(SCRIM_COLOR); 5329b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getWindow().setBackgroundDrawable(mWindowScrim); 5338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (!mHasAlreadyBeenOpened) { 5348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int duration = getResources().getInteger(android.R.integer.config_shortAnimTime); 5359b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell ObjectAnimator.ofInt(mWindowScrim, "alpha", 0, 0xFF).setDuration(duration).start(); 5368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 537edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 538c33ae17c9816b770041ee1f9ccde10e7c7eee491Brian Attwell mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED); 539ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // mScroller needs to perform asynchronous measurements after initalize(), therefore 540ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // we can't mark this as GONE. 541ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.INVISIBLE); 5428a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 5439b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell setHeaderNameText(R.string.missing_name); 5449b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 545d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener= (SelectAccountDialogFragmentListener) getFragmentManager() 546d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell .findFragmentByTag(FRAGMENT_TAG_SELECT_ACCOUNT); 547d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mSelectAccountFragmentListener == null) { 548d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener = new SelectAccountDialogFragmentListener(); 549d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell getFragmentManager().beginTransaction().add(0, mSelectAccountFragmentListener, 550d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell FRAGMENT_TAG_SELECT_ACCOUNT).commit(); 551d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener.setRetainInstance(true); 552d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 553d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener.setQuickContactActivity(this); 55423889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos 5559b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (savedInstanceState != null) { 5569b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell final int color = savedInstanceState.getInt(KEY_THEME_COLOR, 0); 557ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 558ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell new Runnable() { 559ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell @Override 560ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell public void run() { 561ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for the pre draw before setting the initial scroll 562ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // value. Prior to pre draw all scroll values are invalid. 563ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (mHasAlreadyBeenOpened) { 564ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.VISIBLE); 565ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setScroll(mScroller.getScrollNeededToBeFullScreen()); 566ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 567ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for pre draw for setting the theme color. Setting the 568ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // header tint before the MultiShrinkScroller has been measured will 569ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // cause incorrect tinting calculations. 570ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (color != 0) { 5719b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell setThemeColor(color); 5729b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 573ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 574ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell }); 5759b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 5769b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 5778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 5788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 5798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 5808a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onActivityResult(int requestCode, int resultCode, 5818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Intent data) { 5828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (requestCode == REQUEST_CODE_CONTACT_EDITOR_ACTIVITY && 5838a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell resultCode == ContactDeletionInteraction.RESULT_CODE_DELETED) { 5848a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // The contact that we were showing has been deleted. 5858a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell finish(); 586b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 5878a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 588dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 5898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 5908a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onNewIntent(Intent intent) { 5918a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onNewIntent(intent); 5928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 5938571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = false; 594d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(intent); 595d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 596d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 5979b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell @Override 5989b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell public void onSaveInstanceState(Bundle savedInstanceState) { 5999b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell super.onSaveInstanceState(savedInstanceState); 6009b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mColorFilter != null) { 6019b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell savedInstanceState.putInt(KEY_THEME_COLOR, mColorFilter.getColor()); 6029b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 6039b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 6049b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 605d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void processIntent(Intent intent) { 606d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell Uri lookupUri = intent.getData(); 607d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 608d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Check to see whether it comes from the old version. 609d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) { 610d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final long rawContactId = ContentUris.parseId(lookupUri); 611d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell lookupUri = RawContacts.getContactLookupUri(getContentResolver(), 612d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); 613d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 614d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, 615d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell QuickContact.MODE_LARGE); 616d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Uri oldLookupUri = mLookupUri; 617d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 618d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mLookupUri = Preconditions.checkNotNull(lookupUri, "missing lookupUri"); 619d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES); 620d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (oldLookupUri == null) { 621d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactLoader = (ContactLoader) getLoaderManager().initLoader( 622d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell LOADER_CONTACT_ID, null, mLoaderContactCallbacks); 623d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (oldLookupUri != mLookupUri) { 624d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // After copying a directory contact, the contact URI changes. Therefore, 625d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // we need to restart the loader and reload the new contact. 626d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactLoader = (ContactLoader) getLoaderManager().restartLoader( 627d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell LOADER_CONTACT_ID, null, mLoaderContactCallbacks); 628899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos for (int interactionLoaderId : mRecentLoaderIds) { 629899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos getLoaderManager().destroyLoader(interactionLoaderId); 630899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos } 631d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 6322426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann } 633edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 634b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private void runEntranceAnimation() { 6358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mHasAlreadyBeenOpened) { 6368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 6378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 6388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 639c33ae17c9816b770041ee1f9ccde10e7c7eee491Brian Attwell mScroller.scrollUpForEntranceAnimation(mExtraMode != MODE_FULLY_EXPANDED); 640b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 641b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 64281281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 643d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void setHeaderNameText(int resId) { 6449b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 645f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell mScroller.setTitle(getText(resId) == null ? null : getText(resId).toString()); 6469b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 64781281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 64881281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 64981281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 650f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell private void setHeaderNameText(String value) { 651d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (!TextUtils.isEmpty(value)) { 6529b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 653f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell mScroller.setTitle(value); 6549b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 65581281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 65681281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 65781281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 65881281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** 659edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Check if the given MIME-type appears in the list of excluded MIME-types 660edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * that the most-recent caller requested. 661edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 662edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private boolean isMimeExcluded(String mimeType) { 663edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (mExcludeMimes == null) return false; 664edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann for (String excludedMime : mExcludeMimes) { 665edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (TextUtils.equals(excludedMime, mimeType)) { 666edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return true; 667edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 668edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 669edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return false; 670edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 671edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 672edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 673cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann * Handle the result from the ContactLoader 674edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 6758a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void bindContactData(final Contact data) { 6768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("bindContactData"); 6776cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee mContactData = data; 678d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell invalidateOptionsMenu(); 679edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 6808a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 6818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("Set display photo & name"); 682dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 6836219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee mPhotoSetter.setupContactPhoto(data, mPhotoView); 68431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell extractAndApplyTintFromPhotoViewAsynchronously(); 6854936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell analyzeWhitenessOfPhotoAsynchronously(); 686d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell setHeaderNameText(data.getDisplayName()); 687edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 6888a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 689dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 690eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mEntriesAndActionsTask = new AsyncTask<Void, Void, 691eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Pair<List<List<DataItem>>, Map<String, List<DataItem>>>>() { 6928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 6938a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 694eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos protected Pair<List<List<DataItem>>, Map<String, List<DataItem>>> doInBackground( 695eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Void... params) { 696eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return generateDataModelFromContact(data); 6978a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 6988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 6998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 700eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos protected void onPostExecute(Pair<List<List<DataItem>>, 701eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Map<String, List<DataItem>>> dataItemsPair) { 702eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos super.onPostExecute(dataItemsPair); 703eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mDataItemsList = dataItemsPair.first; 704eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mDataItemsMap = dataItemsPair.second; 7058a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Check that original AsyncTask parameters are still valid and the activity 7068a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // is still running before binding to UI. A new intent could invalidate 7078a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the results, for example. 7088a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (data == mContactData && !isCancelled()) { 709eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos bindDataToCards(); 7108a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell showActivity(); 7118a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 7128a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 7138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }; 7148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.execute(); 7158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 7168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 717eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private void bindDataToCards() { 718eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos startInteractionLoaders(); 719eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos populateContactAndAboutCard(); 720eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 721eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 722eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private void startInteractionLoaders() { 723eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<DataItem> phoneDataItems = mDataItemsMap.get(Phone.CONTENT_ITEM_TYPE); 724eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] phoneNumbers = null; 725eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (phoneDataItems != null) { 726eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers = new String[phoneDataItems.size()]; 727eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < phoneDataItems.size(); ++i) { 728eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers[i] = ((PhoneDataItem) phoneDataItems.get(i)).getNumber(); 729eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 730eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 731ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle phonesExtraBundle = new Bundle(); 732eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_PHONES, phoneNumbers); 733eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 734eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("start sms loader"); 7358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getLoaderManager().initLoader( 7368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell LOADER_SMS_ID, 737ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 738ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos mLoaderInteractionsCallbacks); 739ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.endSection(); 740ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 741ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.beginSection("start call log loader"); 742ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos getLoaderManager().initLoader( 743ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID, 744ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 7458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mLoaderInteractionsCallbacks); 746899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.endSection(); 7478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 748eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 749899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.beginSection("start calendar loader"); 750eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<DataItem> emailDataItems = mDataItemsMap.get(Email.CONTENT_ITEM_TYPE); 751eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] emailAddresses = null; 752eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (emailDataItems != null) { 753eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses = new String[emailDataItems.size()]; 754eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < emailDataItems.size(); ++i) { 755eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses[i] = ((EmailDataItem) emailDataItems.get(i)).getAddress(); 756eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 757eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 758ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle emailsExtraBundle = new Bundle(); 759eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailsExtraBundle.putStringArray(KEY_LOADER_EXTRA_EMAILS, emailAddresses); 760899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos getLoaderManager().initLoader( 761899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos LOADER_CALENDAR_ID, 762ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos emailsExtraBundle, 763899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos mLoaderInteractionsCallbacks); 7648a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 7658a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 7668a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 7678a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void showActivity() { 7688a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller != null) { 7698a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mScroller.setVisibility(View.VISIBLE); 7708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 7718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell new Runnable() { 7728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 7738a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void run() { 7748a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell runEntranceAnimation(); 7758a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 7768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }); 7778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 7788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 7798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 780eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private void populateContactAndAboutCard() { 781eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind contact card"); 782eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 783eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> contactCardEntries = new ArrayList<>(); 784eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> aboutCardEntries = new ArrayList<>(); 785eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 786eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos int topContactIndex = 0; 787eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < mDataItemsList.size(); ++i) { 788eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<DataItem> dataItemsByMimeType = mDataItemsList.get(i); 789eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final DataItem topDataItem = dataItemsByMimeType.get(0); 790eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (ABOUT_CARD_MIMETYPES.contains(topDataItem.getMimeType())) { 791eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos aboutCardEntries.addAll(dataItemsToEntries(mDataItemsList.get(i))); 792eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 793eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Add most used to the top of the contact card 794eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Entry topEntry = dataItemToEntry(topDataItem); 795eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (topEntry != null) { 796eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos contactCardEntries.add(topContactIndex++, dataItemToEntry(topDataItem)); 797eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 798eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // TODO merge SMS into secondary action 799eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (topDataItem instanceof PhoneDataItem) { 800eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final PhoneDataItem phone = (PhoneDataItem) topDataItem; 801eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Intent smsIntent = null; 802eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (mSmsComponent != null) { 803eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos smsIntent = new Intent(Intent.ACTION_SENDTO, 804eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Uri.fromParts(CallUtil.SCHEME_SMSTO, phone.getNumber(), null)); 805eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos smsIntent.setComponent(mSmsComponent); 806eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 807ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final int dataId = phone.getId() > Integer.MAX_VALUE ? 808ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos -1 : (int) phone.getId(); 809eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos contactCardEntries.add(topContactIndex++, 810ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos new Entry(dataId, 811eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos getResources().getDrawable(R.drawable.ic_message_24dp), 812eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos getResources().getString(R.string.send_message), 813eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* subHeader = */ null, 814eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* text = */ phone.buildDataString( 815eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos this, topDataItem.getDataKind()), 816eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos smsIntent, 817eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* isEditable = */ false)); 818eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 819eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Add the rest of the entries to the bottom of the card 820eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItemsByMimeType.size() > 1) { 821eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos contactCardEntries.addAll(dataItemsToEntries( 822eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsByMimeType.subList(1, dataItemsByMimeType.size()))); 823eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 824eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 825eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 826eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 827eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (contactCardEntries.size() > 0) { 828eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.initialize(contactCardEntries, 829eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* numInitialVisibleEntries = */ MIN_NUM_CONTACT_ENTRIES_SHOWN, 830eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* isExpanded = */ false, 831eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mExpandingEntryCardViewListener); 832eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.VISIBLE); 833eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 834eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.GONE); 835eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 836eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 8378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 838eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind about card"); 839eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.initialize(aboutCardEntries, 840eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* numInitialVisibleEntries = */ 1, 841eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* isExpanded = */ true, 842eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mExpandingEntryCardViewListener); 843eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 844eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 845eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 846eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 847eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Builds the {@link DataItem}s Map out of the Contact. 848eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param data The contact to build the data from. 849eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return A pair containing a list of data items sorted within mimetype and sorted 850eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * amongst mimetype. The map goes from mimetype string to the sorted list of data items within 851eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * mimetype 852eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 853eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private Pair<List<List<DataItem>>, Map<String, List<DataItem>>> generateDataModelFromContact( 854eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Contact data) { 855eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("Build data items map"); 856eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 857eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Map<String, List<DataItem>> dataItemsMap = new HashMap<>(); 8588bf96e78497ea9c8c893bcb357fc1e3175fb2e9bBrian Attwell 8598a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final ResolveCache cache = ResolveCache.getInstance(this); 860851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (RawContact rawContact : data.getRawContacts()) { 861851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (DataItem dataItem : rawContact.getDataItems()) { 862eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setRawContactId(rawContact.getId()); 863eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 864851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final String mimeType = dataItem.getMimeType(); 865eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (mimeType == null) continue; 866eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 86747b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final AccountType accountType = rawContact.getAccountType(this); 86847b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final DataKind dataKind = AccountTypeManager.getInstance(this) 86947b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng .getKindOrFallback(accountType, mimeType); 870eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataKind == null) continue; 871cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 872eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setDataKind(dataKind); 873b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 874eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean hasData = !TextUtils.isEmpty(dataItem.buildDataString(this, 875eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataKind)); 876899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 877eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (isMimeExcluded(mimeType) || !hasData) continue; 878edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 879eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos List<DataItem> dataItemListByType = dataItemsMap.get(mimeType); 880eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItemListByType == null) { 881eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType = new ArrayList<>(); 882eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsMap.put(mimeType, dataItemListByType); 883edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 884eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType.add(dataItem); 885edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 886edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 8878a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 888edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 889eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort within mimetypes"); 89016339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos /* 89116339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos * Sorting is a multi part step. The end result is to a have a sorted list of the most 892eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * used data items, one per mimetype. Then, within each mimetype, the list of data items 893eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * for that type is also sorted, based off of {super primary, primary, times used} in that 894eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * order. 89516339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos */ 896eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<List<DataItem>> dataItemsList = new ArrayList<>(); 897eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (List<DataItem> mimeTypeDataItems : dataItemsMap.values()) { 898eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Remove duplicate data items 899eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collapser.collapseList(mimeTypeDataItems, this); 900eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort within mimetype 901eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(mimeTypeDataItems, mWithinMimeTypeDataItemComparator); 902eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Add to the list of data item lists 903eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsList.add(mimeTypeDataItems); 904edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 905eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 906edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 907eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort amongst mimetypes"); 908eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort amongst mimetypes to bubble up the top data items for the contact card 909eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(dataItemsList, mAmongstMimeTypeDataItemComparator); 910eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 91116339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos 912eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return new Pair<>(dataItemsList, dataItemsMap); 913eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 914edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 915eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 916eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Converts a {@link DataItem} into an {@link ExpandingEntryCardView.Entry} for display. 917eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * If the {@link ExpandingEntryCardView.Entry} has no visual elements, null is returned. 918eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param dataItem The {@link DataItem} to convert. 919eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return The {@link ExpandingEntryCardView.Entry}, or null if no visual elements are present. 920eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 921eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private Entry dataItemToEntry(DataItem dataItem) { 922eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable icon = null; 923eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String header = null; 924eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String subHeader = null; 925eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable subHeaderIcon = null; 926eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String text = null; 927eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable textIcon = null; 928eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Intent intent = null; 929eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEditable = false; 930eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 931eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataKind kind = dataItem.getDataKind(); 932eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 933eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItem instanceof ImDataItem) { 934eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final ImDataItem im = (ImDataItem) dataItem; 935eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = ContactsUtils.buildImIntent(this, im).first; 936eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_im_entry); 937eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEmail = im.isCreatedFromEmail(); 938eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol(); 939eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = Im.getProtocolLabel(getResources(), protocol, 940eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos im.getCustomProtocol()).toString(); 941eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof OrganizationDataItem) { 942eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final OrganizationDataItem organization = (OrganizationDataItem) dataItem; 943eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_organization_entry); 944eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = organization.getCompany(); 945eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = organization.getTitle(); 946eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NicknameDataItem) { 947eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NicknameDataItem nickname = (NicknameDataItem) dataItem; 948eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Build nickname entries 949eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isNameRawContact = 950eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos (mContactData.getNameRawContactId() == dataItem.getRawContactId()); 951eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 952eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean duplicatesTitle = 953eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos isNameRawContact 954eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos && mContactData.getDisplayNameSource() == DisplayNameSources.NICKNAME; 955eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 956eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!duplicatesTitle) { 957eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_nickname_entry); 958eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = nickname.getName(); 959eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 960eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NoteDataItem) { 961eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NoteDataItem note = (NoteDataItem) dataItem; 962eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_note_entry); 963eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = note.getNote(); 964eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof WebsiteDataItem) { 965eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final WebsiteDataItem website = (WebsiteDataItem) dataItem; 966eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_website_entry); 967eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = website.getUrl(); 968eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos try { 969eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final WebAddress webAddress = new WebAddress(website.buildDataString(this, kind)); 970eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString())); 971eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ParseException e) { 972eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Log.e(TAG, "Couldn't parse website: " + website.buildDataString(this, kind)); 973eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 974eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EventDataItem) { 975eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EventDataItem event = (EventDataItem) dataItem; 976eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String dataString = event.buildDataString(this, kind); 977eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Calendar cal = DateUtils.parseDate(dataString, false); 978eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (cal != null) { 979eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Date nextAnniversary = 980eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DateUtils.getNextAnnualDate(cal); 981eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); 982eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos builder.appendPath("time"); 983eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos ContentUris.appendId(builder, nextAnniversary.getTime()); 984eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW).setData(builder.build()); 985eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 986eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_event_entry); 987f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (event.hasKindTypeColumn(kind)) { 988f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos subHeader = getResources().getString(Event.getTypeResource( 989f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos event.getKindTypeColumn(kind))); 990f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 991eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = DateUtils.formatDate(this, dataString); 992eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof RelationDataItem) { 993eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final RelationDataItem relation = (RelationDataItem) dataItem; 994eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String dataString = relation.buildDataString(this, kind); 995eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(dataString)) { 996eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SEARCH); 997eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.putExtra(SearchManager.QUERY, dataString); 998eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.setType(Contacts.CONTENT_TYPE); 999eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1000eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_relation_entry); 1001eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = relation.getName(); 1002f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (relation.hasKindTypeColumn(kind)) { 1003f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos text = Relation.getTypeLabel(getResources(), relation.getKindTypeColumn(kind), 1004f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos relation.getLabel()).toString(); 1005f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1006eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof PhoneDataItem) { 1007eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final PhoneDataItem phone = (PhoneDataItem) dataItem; 1008eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(phone.getNumber())) { 1009eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = phone.buildDataString(this, kind); 1010f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (phone.hasKindTypeColumn(kind)) { 1011f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos text = Phone.getTypeLabel(getResources(), phone.getKindTypeColumn(kind), 1012f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos phone.getLabel()).toString(); 1013f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1014eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos icon = getResources().getDrawable(R.drawable.ic_phone_24dp); 1015eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (PhoneCapabilityTester.isPhone(this)) { 1016eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(phone.getNumber()); 101716339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1018eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1019eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EmailDataItem) { 1020eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EmailDataItem email = (EmailDataItem) dataItem; 1021eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String address = email.getData(); 1022eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(address)) { 1023eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri mailUri = Uri.fromParts(CallUtil.SCHEME_MAILTO, address, null); 1024eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SENDTO, mailUri); 1025eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = email.getAddress(); 1026f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (email.hasKindTypeColumn(kind)) { 1027f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos text = Email.getTypeLabel(getResources(), email.getKindTypeColumn(kind), 1028f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos email.getLabel()).toString(); 1029f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1030eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos icon = getResources().getDrawable(R.drawable.ic_email_24dp); 1031eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1032eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredPostalDataItem) { 1033eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos StructuredPostalDataItem postal = (StructuredPostalDataItem) dataItem; 1034eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String postalAddress = postal.getFormattedAddress(); 1035eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(postalAddress)) { 1036eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress); 1037eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = postal.getFormattedAddress(); 1038f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (postal.hasKindTypeColumn(kind)) { 1039f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos text = StructuredPostal.getTypeLabel(getResources(), 1040f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos postal.getKindTypeColumn(kind), postal.getLabel()).toString(); 1041f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1042eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos icon = getResources().getDrawable(R.drawable.ic_place_24dp); 1043eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1044eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof SipAddressDataItem) { 1045eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (PhoneCapabilityTester.isSipPhone(this)) { 1046eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final SipAddressDataItem sip = (SipAddressDataItem) dataItem; 1047eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String address = sip.getSipAddress(); 1048eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(address)) { 1049eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri callUri = Uri.fromParts(CallUtil.SCHEME_SIP, address, null); 1050eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(callUri); 1051eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Note that this item will get a SIP-specific variant 1052eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // of the "call phone" icon, rather than the standard 1053eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // app icon for the Phone app (which we show for 1054eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // regular phone numbers.) That's because the phone 1055eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // app explicitly specifies an android:icon attribute 1056eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // for the SIP-related intent-filters in its manifest. 1057eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1058eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos icon = ResolveCache.getInstance(this).getIcon(sip.getMimeType(), intent); 1059eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Call mutate to create a new Drawable.ConstantState for color filtering 1060eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (icon != null) { 1061eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos icon.mutate(); 106216339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1063edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1064eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredNameDataItem) { 1065eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String givenName = ((StructuredNameDataItem) dataItem).getGivenName(); 1066eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(givenName)) { 1067eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setTitle(getResources().getString(R.string.about_card_title) + 1068eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos " " + givenName); 1069eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1070eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setTitle(getResources().getString(R.string.about_card_title)); 1071eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1072eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1073eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Custom DataItem 1074eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = dataItem.buildDataStringForDisplay(this, kind); 1075eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = kind.typeColumn; 1076eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW); 1077eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.setDataAndType(Uri.parse(dataItem.buildDataString(this, kind)), 1078eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.getMimeType()); 1079eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos icon = ResolveCache.getInstance(this).getIcon(dataItem.getMimeType(), intent); 1080eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1081b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1082eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (intent != null) { 1083eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Do not set the intent is there are no resolves 1084eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!PhoneCapabilityTester.isIntentRegistered(this, intent)) { 1085eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = null; 1086eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1087eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1088eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1089eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // If the Entry has no visual elements, return null 1090eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) && 1091eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeaderIcon == null && TextUtils.isEmpty(text) && textIcon == null) { 1092eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return null; 1093eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1094eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1095ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final int dataId = dataItem.getId() > Integer.MAX_VALUE ? 1096ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos -1 : (int) dataItem.getId(); 1097ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 1098ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon, 1099eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent, isEditable); 1100eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1101eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1102eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private List<Entry> dataItemsToEntries(List<DataItem> dataItems) { 1103eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> entries = new ArrayList<>(); 1104eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (DataItem dataItem : dataItems) { 1105eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Entry entry = dataItemToEntry(dataItem); 1106eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (entry != null) { 1107eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos entries.add(entry); 1108eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1109eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1110eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return entries; 1111edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1112edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1113edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 111431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * Asynchronously extract the most vibrant color from the PhotoView. Once extracted, 111531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms 111631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * on a Nexus 5. 111731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell */ 111831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell private void extractAndApplyTintFromPhotoViewAsynchronously() { 111931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell if (mScroller == null) { 112031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell return; 112131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 112231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell final Drawable imageViewDrawable = mPhotoView.getDrawable(); 112331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell new AsyncTask<Void, Void, Integer>() { 112431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 112531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell protected Integer doInBackground(Void... params) { 112631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell if (imageViewDrawable instanceof BitmapDrawable) { 11278a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final Bitmap bitmap = ((BitmapDrawable) imageViewDrawable).getBitmap(); 11288a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return colorFromBitmap(bitmap); 11298a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 11308a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (imageViewDrawable instanceof LetterTileDrawable) { 11319b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell return ((LetterTileDrawable) imageViewDrawable).getColor(); 113231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 11338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return 0; 113431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 113531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 113631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 113731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell protected void onPostExecute(Integer color) { 113831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell super.onPostExecute(color); 11398571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (mHasComputedThemeColor) { 11408571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // If we had previously computed a theme color from the contact photo, 11418571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // then do not update the theme color. Changing the theme color several 11428571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // seconds after QC has started, as a result of an updated/upgraded photo, 11438571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // is a jarring experience. On the other hand, changing the theme color after 11448571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // a rotation or onNewIntent() is perfectly fine. 11458571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell return; 11468571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell } 11478571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // Check that the Photo has not changed. If it has changed, the new tint 11488571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // color needs to be extracted 11498571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (imageViewDrawable == mPhotoView.getDrawable()) { 11508571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = true; 11519b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell setThemeColor(color); 115231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 115331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 115431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell }.execute(); 115531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 115631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 11574936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell /** 11584936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell * Examine how many white pixels are in the bitmap in order to determine whether or not 11594936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell * we need gradient overlays on top of the image. 11604936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell */ 11614936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell private void analyzeWhitenessOfPhotoAsynchronously() { 11624936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell final Drawable imageViewDrawable = mPhotoView.getDrawable(); 11634936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell new AsyncTask<Void, Void, Boolean>() { 11644936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell @Override 11654936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell protected Boolean doInBackground(Void... params) { 11664936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell if (imageViewDrawable instanceof BitmapDrawable) { 11674936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell final Bitmap bitmap = ((BitmapDrawable) imageViewDrawable).getBitmap(); 11684936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell return WhitenessUtils.isBitmapWhiteAtTopOrBottom(bitmap); 11694936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell } 11704936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell return !(imageViewDrawable instanceof LetterTileDrawable); 11714936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell } 11724936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell 11734936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell @Override 11744936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell protected void onPostExecute(Boolean isWhite) { 11754936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell super.onPostExecute(isWhite); 11764936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell mScroller.setUseGradient(isWhite); 11774936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell } 11784936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell }.execute(); 11794936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell } 11804936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell 11819b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private void setThemeColor(int color) { 11829b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // If the color is invalid, use the predefined default 11839b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (color == 0) { 11849b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell color = getResources().getColor(R.color.actionbar_background_color); 11859b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 11869b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mScroller.setHeaderTintColor(color); 11879b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 11889b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // Create a darker version of the actionbar color. HSV is device dependent 11899b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // and not perceptually-linear. Therefore, we can't say mStatusBarColor is 11909b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // 70% as bright as the action bar color. We can only say: it is a bit darker. 11919b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell final float hsvComponents[] = new float[3]; 11929b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell Color.colorToHSV(color, hsvComponents); 11939b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell hsvComponents[2] *= SYSTEM_BAR_BRIGHTNESS_FACTOR; 11949b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mStatusBarColor = Color.HSVToColor(hsvComponents); 11959b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell updateStatusBarColor(); 11968571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell 11979b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mColorFilter = 11989b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP); 1199eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setColorAndFilter(color, mColorFilter); 12009b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mRecentCard.setColorAndFilter(color, mColorFilter); 1201eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setColorAndFilter(color, mColorFilter); 12029b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 12039b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 12048a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void updateStatusBarColor() { 12058a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller == null) { 12068a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 12078a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12088a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int desiredStatusBarColor; 12098a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Only use a custom status bar color if QuickContacts touches the top of the viewport. 12108a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller.getScrollNeededToBeFullScreen() <= 0) { 12118a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = mStatusBarColor; 12128a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } else { 12138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = Color.TRANSPARENT; 12148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Animate to the new color. 12168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (desiredStatusBarColor != getWindow().getStatusBarColor()) { 12178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor", 12188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getWindow().getStatusBarColor(), desiredStatusBarColor); 12198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION); 12208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell animation.setEvaluator(new ArgbEvaluator()); 12218a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell animation.start(); 12228a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12238a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12248a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 12258a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int colorFromBitmap(Bitmap bitmap) { 12268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Author of Palette recommends using 24 colors when analyzing profile photos. 12278a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int NUMBER_OF_PALETTE_COLORS = 24; 12288a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final Palette palette = Palette.generate(bitmap, NUMBER_OF_PALETTE_COLORS); 1229a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell if (palette != null && palette.getVibrantSwatch() != null) { 1230a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell return palette.getVibrantSwatch().getRgb(); 12318a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12328a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return 0; 12338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1235b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) { 1236eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> entries = new ArrayList<>(); 1237b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos for (ContactInteraction interaction : interactions) { 1238ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos entries.add(new Entry(/* id = */ -1, 1239ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos interaction.getIcon(this), 1240b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewHeader(this), 1241b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewBody(this), 1242b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getBodyIcon(this), 1243b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewFooter(this), 1244b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getFooterIcon(this), 1245b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getIntent(), 1246b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /* isEditable = */ false)); 1247b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1248b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return entries; 1249b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1250b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1251eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<Contact> mLoaderContactCallbacks = 1252851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu new LoaderCallbacks<Contact>() { 1253cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 1254851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoaderReset(Loader<Contact> loader) { 1255cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1256cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1257cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 1258851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoadFinished(Loader<Contact> loader, Contact data) { 12598a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onLoadFinished()"); 12608a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1261cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (isFinishing()) { 1262cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann return; 1263cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1264cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (data.isError()) { 1265cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann // This shouldn't ever happen, so throw an exception. The {@link ContactLoader} 1266cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann // should log the actual exception. 1267cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann throw new IllegalStateException("Failed to load contact", data.getException()); 1268cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1269cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (data.isNotFound()) { 12708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mHasAlreadyBeenOpened) { 12718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell finish(); 12728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } else { 12738a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri()); 12748a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, 12758a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.LENGTH_LONG).show(); 12768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 1277cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann return; 1278cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1279cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1280b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos bindContactData(data); 1281cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 12828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 1283cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1284cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1285cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 1286851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public Loader<Contact> onCreateLoader(int id, Bundle args) { 1287cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (mLookupUri == null) { 1288cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann Log.wtf(TAG, "Lookup uri wasn't initialized. Loader was started too early"); 1289cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1290d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Load all contact data. We need loadGroupMetaData=true to determine whether the 1291d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // contact is invisible. If it is, we need to display an "Add to Contacts" MenuItem. 1292b2b435a944947fbf1965c3bb7c202a97f0273259Yorke Lee return new ContactLoader(getApplicationContext(), mLookupUri, 1293d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell true /*loadGroupMetaData*/, false /*loadInvitableAccountTypes*/, 12948571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell true /*postViewNotification*/, true /*computeFormattedPhoneNumber*/); 1295cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1296cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann }; 1297b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1298b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 1299b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onBackPressed() { 1300b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell if (mScroller != null) { 13018477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell if (!mIsExitAnimationInProgress) { 13028477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mScroller.scrollOffBottom(); 13038477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 1304b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } else { 1305b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell super.onBackPressed(); 1306b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 1307b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 1308b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 13098a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 13108a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void finish() { 13118a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.finish(); 13128a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 13138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // override transitions to skip the standard window animations 13148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell overridePendingTransition(0, 0); 13158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 13168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1317eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<List<ContactInteraction>> mLoaderInteractionsCallbacks = 1318b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos new LoaderCallbacks<List<ContactInteraction>>() { 1319b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1320b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 1321b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public Loader<List<ContactInteraction>> onCreateLoader(int id, Bundle args) { 1322b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Log.v(TAG, "onCreateLoader"); 1323b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Loader<List<ContactInteraction>> loader = null; 1324b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos switch (id) { 1325b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos case LOADER_SMS_ID: 1326b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Log.v(TAG, "LOADER_SMS_ID"); 1327b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos loader = new SmsInteractionsLoader( 1328b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos QuickContactActivity.this, 1329ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 1330b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos MAX_SMS_RETRIEVE); 1331b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos break; 1332899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos case LOADER_CALENDAR_ID: 1333899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Log.v(TAG, "LOADER_CALENDAR_ID"); 1334899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos loader = new CalendarInteractionsLoader( 1335899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos QuickContactActivity.this, 1336ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Arrays.asList(args.getStringArray(KEY_LOADER_EXTRA_EMAILS)), 1337899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_FUTURE_CALENDAR_RETRIEVE, 1338899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_PAST_CALENDAR_RETRIEVE, 1339899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR, 1340899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR); 1341899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos break; 1342ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos case LOADER_CALL_LOG_ID: 1343ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Log.v(TAG, "LOADER_CALL_LOG_ID"); 1344ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos loader = new CallLogInteractionsLoader( 1345ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.this, 1346ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 1347ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos MAX_CALL_LOG_RETRIEVE); 1348b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1349b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return loader; 1350b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1351b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1352b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 1353b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoadFinished(Loader<List<ContactInteraction>> loader, 1354b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos List<ContactInteraction> data) { 1355b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos if (mRecentLoaderResults == null) { 1356b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults = new HashMap<Integer, List<ContactInteraction>>(); 1357b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1358899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Log.v(TAG, "onLoadFinished ~ loader.getId() " + loader.getId() + " data.size() " + 1359899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos data.size()); 1360b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.put(loader.getId(), data); 1361b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1362b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos if (isAllRecentDataLoaded()) { 1363b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos bindRecentData(); 1364b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1365b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1366b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1367b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 1368b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoaderReset(Loader<List<ContactInteraction>> loader) { 1369b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.remove(loader.getId()); 1370b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1371b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1372b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos }; 1373b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1374b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private boolean isAllRecentDataLoaded() { 1375b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return mRecentLoaderResults.size() == mRecentLoaderIds.length; 1376b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1377b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1378b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private void bindRecentData() { 1379eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<ContactInteraction> allInteractions = new ArrayList<>(); 1380b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) { 1381b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos allInteractions.addAll(loaderInteractions); 1382b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1383b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1384b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos // Sort the interactions by most recent 1385b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Collections.sort(allInteractions, new Comparator<ContactInteraction>() { 1386b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 1387b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public int compare(ContactInteraction a, ContactInteraction b) { 1388b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return a.getInteractionDate() >= b.getInteractionDate() ? -1 : 1; 1389b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1390b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos }); 1391b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1392b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos if (allInteractions.size() > 0) { 1393b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.initialize(contactInteractionsToEntries(allInteractions), 1394b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN, 1395e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell /* isExpanded = */ false, mExpandingEntryCardViewListener); 1396b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setVisibility(View.VISIBLE); 1397b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1398eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1399eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // About card is initialized along with the contact card, but since it appears after 1400eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // the recent card in the UI, we hold off until making it visible until the recent card 1401eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // is also ready to avoid stuttering. 1402eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (mAboutCard.shouldShow()) { 1403eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setVisibility(View.VISIBLE); 1404eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1405eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setVisibility(View.GONE); 1406eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1407b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 14088a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 14098a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 14108a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onStop() { 14118a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onStop(); 14128a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 14138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mEntriesAndActionsTask != null) { 14148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Once the activity is stopped, we will no longer want to bind mEntriesAndActionsTask's 14158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // results on the UI thread. In some circumstances Activities are killed without 14168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // onStop() being called. This is not a problem, because in these circumstances 14178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the entire process will be killed. 14188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.cancel(/* mayInterruptIfRunning = */ false); 14198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 14208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 142123889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos 142223889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos /** 1423d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Returns true if it is possible to edit the current contact. 1424d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 1425d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private boolean isContactEditable() { 1426d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 1427d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1428d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1429d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void editContact() { 1430d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Intent intent = new Intent(Intent.ACTION_EDIT, mLookupUri); 1431d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactLoader.cacheResult(); 1432d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 1433d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell startActivityForResult(intent, REQUEST_CODE_CONTACT_EDITOR_ACTIVITY); 1434d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1435d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1436d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void toggleStar(MenuItem starredMenuItem) { 1437d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Make sure there is a contact 1438d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mLookupUri != null) { 1439d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Read the current starred value from the UI instead of using the last 1440d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // loaded state. This allows rapid tapping without writing the same 1441d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // value several times 1442d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final boolean isStarred = starredMenuItem.isChecked(); 1443d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1444d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // To improve responsiveness, swap out the picture (and tag) in the UI already 1445d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell ContactDetailDisplayUtils.configureStarredMenuItem(starredMenuItem, 1446d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.isDirectoryEntry(), mContactData.isUserProfile(), 1447d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell !isStarred); 1448d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1449d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Now perform the real save 1450eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Intent intent = ContactSaveService.createSetStarredIntent( 1451d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell QuickContactActivity.this, mLookupUri, !isStarred); 1452d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell startService(intent); 1453d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1454d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1455d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1456752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** 1457752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell * Calls into the contacts provider to get a pre-authorized version of the given URI. 1458752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell */ 1459752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private Uri getPreAuthorizedUri(Uri uri) { 1460752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Bundle uriBundle = new Bundle(); 1461752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell uriBundle.putParcelable(ContactsContract.Authorization.KEY_URI_TO_AUTHORIZE, uri); 1462752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Bundle authResponse = getContentResolver().call( 1463752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell ContactsContract.AUTHORITY_URI, 1464752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell ContactsContract.Authorization.AUTHORIZATION_METHOD, 1465752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell null, 1466752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell uriBundle); 1467752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell if (authResponse != null) { 1468752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return (Uri) authResponse.getParcelable( 1469752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell ContactsContract.Authorization.KEY_AUTHORIZED_URI); 1470752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } else { 1471752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return uri; 1472752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1473752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1474752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void shareContact() { 1475752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final String lookupKey = mContactData.getLookupKey(); 1476752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); 1477752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell if (mContactData.isUserProfile()) { 1478752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // User is sharing the profile. We don't want to force the receiver to have 1479752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // the highly-privileged READ_PROFILE permission, so we need to request a 1480752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // pre-authorized URI from the provider. 1481752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell shareUri = getPreAuthorizedUri(shareUri); 1482752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1483752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1484752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent intent = new Intent(Intent.ACTION_SEND); 1485752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell intent.setType(Contacts.CONTENT_VCARD_TYPE); 1486752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell intent.putExtra(Intent.EXTRA_STREAM, shareUri); 1487752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1488752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Launch chooser to share contact via 1489752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final CharSequence chooseTitle = getText(R.string.share_via); 1490752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent chooseIntent = Intent.createChooser(intent, chooseTitle); 1491752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1492752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell try { 1493752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell this.startActivity(chooseIntent); 1494eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ActivityNotFoundException ex) { 1495752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show(); 1496752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1497752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1498752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1499752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** 1500752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell * Creates a launcher shortcut with the current contact. 1501752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell */ 1502752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void createLauncherShortcutWithContact() { 1503752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this, 1504752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell new OnShortcutIntentCreatedListener() { 1505752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1506752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell @Override 1507752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) { 1508752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Broadcast the shortcutIntent to the launcher to create a 1509752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // shortcut to this contact 1510752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); 1511752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell QuickContactActivity.this.sendBroadcast(shortcutIntent); 1512752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1513752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Send a toast to give feedback to the user that a shortcut to this 1514752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // contact was added to the launcher. 1515752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.makeText(QuickContactActivity.this, 1516752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell R.string.createContactShortcutSuccessful, 1517752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.LENGTH_SHORT).show(); 1518752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1519752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1520752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell }); 1521752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell builder.createContactShortcutIntent(mLookupUri); 1522752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1523752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1524d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 1525d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onCreateOptionsMenu(Menu menu) { 1526eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final MenuInflater inflater = getMenuInflater(); 1527d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell inflater.inflate(R.menu.quickcontact, menu); 1528d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 1529d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1530d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1531d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 1532d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onPrepareOptionsMenu(Menu menu) { 1533d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mContactData != null) { 1534d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem starredMenuItem = menu.findItem(R.id.menu_star); 1535d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell ContactDetailDisplayUtils.configureStarredMenuItem(starredMenuItem, 1536d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.isDirectoryEntry(), mContactData.isUserProfile(), 1537d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.getStarred()); 1538d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Configure edit MenuItem 1539d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem editMenuItem = menu.findItem(R.id.menu_edit); 1540d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(true); 1541d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData) || InvisibleContactUtil 1542d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell .isInvisibleAndAddable(mContactData, this)) { 154330cfd121ad8c8adb83cf417ff1d40a8ba1e3761dBrian Attwell editMenuItem.setIcon(R.drawable.ic_person_add_tinted_24dp); 1544d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 1545d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setIcon(R.drawable.ic_create_24dp); 1546d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else { 1547d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(false); 1548d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 15498a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return true; 1550d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 15518a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return false; 1552d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1553d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1554d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 1555d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onOptionsItemSelected(MenuItem item) { 1556d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell switch (item.getItemId()) { 1557d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell case R.id.menu_star: 1558d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell toggleStar(item); 1559d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 1560d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell case R.id.menu_edit: 1561d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData)) { 1562d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell DirectoryContactUtil.addToMyContacts(mContactData, this, getFragmentManager(), 1563d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener); 1564d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { 1565d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell InvisibleContactUtil.addToDefaultGroup(mContactData, this); 1566d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 1567d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editContact(); 1568d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1569d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 1570752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell case R.id.menu_share: 1571752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell shareContact(); 1572752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return true; 1573752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell case R.id.menu_create_contact_shortcut: 1574752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell createLauncherShortcutWithContact(); 1575752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return true; 1576d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell default: 1577d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return super.onOptionsItemSelected(item); 1578d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 157923889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos } 1580edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann} 1581