QuickContactActivity.java revision 4861031d5f0ac3707fe089c1efd559260672df39
1edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/* 279525d024526e0f26b9dff40162b91f7c53f17a6yaolu 3edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Copyright (C) 2009 The Android Open Source Project 4edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 5edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Licensed under the Apache License, Version 2.0 (the "License"); 6edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * you may not use this file except in compliance with the License. 7edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * You may obtain a copy of the License at 8edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 9edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * http://www.apache.org/licenses/LICENSE-2.0 10edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 11edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Unless required by applicable law or agreed to in writing, software 12edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * distributed under the License is distributed on an "AS IS" BASIS, 13edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * See the License for the specific language governing permissions and 15edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * limitations under the License. 16edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 17edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 18edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannpackage com.android.contacts.quickcontact; 19edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 200e723d937f3fc9a0bda2602d97d9fbeda7300d51Walter Jangimport android.Manifest; 21ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulosimport android.accounts.Account; 228a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.animation.ArgbEvaluator; 23b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport android.animation.ObjectAnimator; 24edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.app.Activity; 25cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.app.LoaderManager.LoaderCallbacks; 26b9065ddb28a2040cabda251891be2062b5260217Gary Maiimport android.app.ProgressDialog; 27eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.app.SearchManager; 28752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.content.ActivityNotFoundException; 29b9065ddb28a2040cabda251891be2062b5260217Gary Maiimport android.content.BroadcastReceiver; 30edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.ContentUris; 31ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulosimport android.content.ContentValues; 326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwellimport android.content.Context; 33edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.Intent; 34b9065ddb28a2040cabda251891be2062b5260217Gary Maiimport android.content.IntentFilter; 35cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.content.Loader; 36dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulosimport android.content.pm.PackageManager; 37dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulosimport android.content.pm.ResolveInfo; 3823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulosimport android.content.res.Resources; 3931b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.Bitmap; 4095c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwellimport android.graphics.BitmapFactory; 418a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.Color; 42eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuff; 43eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuffColorFilter; 4431b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.BitmapDrawable; 458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.drawable.ColorDrawable; 4631b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.Drawable; 4758a1ac2d418c716599b06bed1fa1aad1160dbf54yaoluimport android.media.RingtoneManager; 48edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.net.Uri; 4931b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.os.AsyncTask; 50edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.os.Bundle; 518a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.os.Trace; 52eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.CalendarContract; 53edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Email; 54eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Event; 55eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.GroupMembership; 56eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Identity; 57eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Im; 58eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Nickname; 59eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Note; 60eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Organization; 61edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Phone; 62eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Relation; 63edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.SipAddress; 64edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.StructuredPostal; 65edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Website; 66752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.provider.ContactsContract.Contacts; 6760e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulosimport android.provider.ContactsContract.Data; 688bac28bebae51e53885a404cdf2dd4991000ba42Walter Jangimport android.provider.ContactsContract.DataUsageFeedback; 69ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulosimport android.provider.ContactsContract.Directory; 70eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.DisplayNameSources; 71ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulosimport android.provider.ContactsContract.Intents; 72edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.QuickContact; 73edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.RawContacts; 748e56edfe8ac14879e40825cc10a73a9e2626803dguanxiongliuimport android.support.graphics.drawable.VectorDrawableCompat; 7504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliuimport android.support.v4.app.ActivityCompat; 76b9065ddb28a2040cabda251891be2062b5260217Gary Maiimport android.support.v4.content.LocalBroadcastManager; 7731b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.support.v7.graphics.Palette; 780319222b43927d4d9ce7e2a9070f3543661b5782Tyler Gunnimport android.telecom.PhoneAccount; 790319222b43927d4d9ce7e2a9070f3543661b5782Tyler Gunnimport android.telecom.TelecomManager; 80c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwellimport android.text.BidiFormatter; 81b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wangimport android.text.Spannable; 827ce5352a70e8aaf120bf4f7bd05d595f46abb080Walter Jangimport android.text.SpannableString; 83c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwellimport android.text.TextDirectionHeuristics; 84edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.text.TextUtils; 85edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.util.Log; 862a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu; 872a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu.ContextMenuInfo; 88d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.Menu; 89d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.MenuInflater; 90eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.view.MenuItem; 91f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chenimport android.view.MotionEvent; 92edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View; 93edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View.OnClickListener; 942a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.View.OnCreateContextMenuListener; 9510d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawaimport android.view.WindowManager; 96edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.widget.Toast; 97d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.widget.Toolbar; 98edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 9972b3ab1d8a62f228a540b05f4ed6373e494c7d72Christine Chenimport com.android.contacts.ContactSaveService; 100d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.ContactsActivity; 101d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerottimport com.android.contacts.DynamicShortcuts; 1022d150da246632b1649999cfabed776133b097775Brian Attwellimport com.android.contacts.NfcHandler; 103e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.R; 104363af60ea23e5a3b945005712a16564ab69db18bGary Maiimport com.android.contacts.activities.ContactEditorActivity; 1052de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaoluimport com.android.contacts.activities.ContactSelectionActivity; 106eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.CallUtil; 1072a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.common.ClipboardUtils; 108eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.Collapser; 109eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.ContactsUtils; 110f62363701d76b1283edeb7305fc19249fc34899cWalter Jangimport com.android.contacts.common.activity.RequestDesiredPermissionsActivity; 111bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwellimport com.android.contacts.common.activity.RequestPermissionsActivity; 1124c3d3e24b0de8b4170106e312f6a4ac8139e1242Wenyi Wangimport com.android.contacts.common.compat.CompatUtils; 113c85af2872f231f48b586c30f6306083a039dd6c6Wenyi Wangimport com.android.contacts.common.compat.EventCompat; 114caf26197087343fdc18739e20e217236ff26831eWenyi Wangimport com.android.contacts.common.compat.MultiWindowCompat; 1155f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunnimport com.android.contacts.common.dialog.CallSubjectDialog; 11670e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chenimport com.android.contacts.common.interactions.TouchPointManager; 11731b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport com.android.contacts.common.lettertiles.LetterTileDrawable; 118752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder; 119752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder.OnShortcutIntentCreatedListener; 12062a2074bb3b8dc66996e9fc6a8748b999ab2b51cWalter Jangimport com.android.contacts.common.logging.Logger; 12179525d024526e0f26b9dff40162b91f7c53f17a6yaoluimport com.android.contacts.common.logging.QuickContactEvent.ActionType; 122d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerottimport com.android.contacts.common.logging.QuickContactEvent.CardType; 123d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerottimport com.android.contacts.common.logging.QuickContactEvent.ContactType; 124d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerottimport com.android.contacts.common.logging.ScreenEvent.ScreenType; 1250d5588da244d0992c3ff8f25d0875fdf95a8c644Chiao Chengimport com.android.contacts.common.model.AccountTypeManager; 126cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.Contact; 127cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.ContactLoader; 128cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.RawContact; 129428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.account.AccountType; 1308bac28bebae51e53885a404cdf2dd4991000ba42Walter Jangimport com.android.contacts.common.model.dataitem.CustomDataItem; 131cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.DataItem; 132428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.dataitem.DataKind; 133cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.EmailDataItem; 134eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.EventDataItem; 135cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.ImDataItem; 136eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NicknameDataItem; 137eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NoteDataItem; 138eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.OrganizationDataItem; 139b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.common.model.dataitem.PhoneDataItem; 140eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.RelationDataItem; 141eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.SipAddressDataItem; 142eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredNameDataItem; 143eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredPostalDataItem; 144eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.WebsiteDataItem; 145eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.util.DateUtils; 1468bac28bebae51e53885a404cdf2dd4991000ba42Walter Jangimport com.android.contacts.common.util.ImplicitIntentsUtil; 147faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwellimport com.android.contacts.common.util.MaterialColorMapUtils; 148faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwellimport com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette; 14904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliuimport com.android.contacts.common.util.PermissionsUtil; 1505f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunnimport com.android.contacts.common.util.UriUtils; 151d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwellimport com.android.contacts.common.util.ViewUtil; 152333091ae754ddfc25714c14b9b89534be24379f9Paul Soulosimport com.android.contacts.detail.ContactDisplayUtils; 153363af60ea23e5a3b945005712a16564ab69db18bGary Maiimport com.android.contacts.editor.ContactEditorFragment; 1545a7a23bdb698b8e741a425c9617c5e33e6314cddWalter Jangimport com.android.contacts.editor.EditorIntents; 15558a1ac2d418c716599b06bed1fa1aad1160dbf54yaoluimport com.android.contacts.editor.EditorUiUtils; 156899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport com.android.contacts.interactions.CalendarInteractionsLoader; 157ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulosimport com.android.contacts.interactions.CallLogInteractionsLoader; 1588a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport com.android.contacts.interactions.ContactDeletionInteraction; 159b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.ContactInteraction; 160b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.SmsInteractionsLoader; 1612de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaoluimport com.android.contacts.list.UiIntentActions; 1622d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.Entry; 1632a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryContextMenuInfo; 1642ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryTag; 165e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwellimport com.android.contacts.quickcontact.ExpandingEntryCardView.ExpandingEntryCardViewListener; 166493f8d14b1d974a2939a110ce89fa68e0c915c36Brian Attwellimport com.android.contacts.quickcontact.WebAddress.ParseException; 167e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.util.ImageViewDrawableSetter; 168eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.PhoneCapabilityTester; 169b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.util.SchedulingUtils; 170ac9596e825bf8256487d836a266862e79a24206dTingting Wangimport com.android.contacts.util.SharedPreferenceUtil; 171eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.StructuredPostalUtils; 172b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller; 173b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener; 17402eaf11669d25fd885606b3b0700358323532cddBrian Attwellimport com.android.contacts.widget.QuickContactImageView; 17556bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwellimport com.android.contactsbind.HelpUtils; 176678108ebb9926a79ad0d7ac4f11417dec1583d42Gary Mai 177e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.google.common.collect.Lists; 178e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng 1792d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport java.util.ArrayList; 180899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport java.util.Arrays; 181eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Calendar; 182b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Collections; 183b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Comparator; 184eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Date; 185edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.HashMap; 186edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.List; 187b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Map; 18812ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shraunerimport java.util.concurrent.ConcurrentHashMap; 189edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 190edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/** 191edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Mostly translucent {@link Activity} that shows QuickContact dialog. It loads 192edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * data asynchronously, and then shows a popup with details centered around 193edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * {@link Intent#getSourceBounds()}. 194edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 195b9065ddb28a2040cabda251891be2062b5260217Gary Maipublic class QuickContactActivity extends ContactsActivity { 1968a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1978a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell /** 1988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * QuickContacts immediately takes up the full screen. All possible information is shown. 1998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * This value for {@link android.provider.ContactsContract.QuickContact#EXTRA_MODE} 2008a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * should only be used by the Contacts app. 2018a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell */ 2028a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public static final int MODE_FULLY_EXPANDED = 4; 2038a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 20462a2074bb3b8dc66996e9fc6a8748b999ab2b51cWalter Jang /** Used to pass the screen where the user came before launching this Activity. */ 20562a2074bb3b8dc66996e9fc6a8748b999ab2b51cWalter Jang public static final String EXTRA_PREVIOUS_SCREEN_TYPE = "previous_screen_type"; 20679525d024526e0f26b9dff40162b91f7c53f17a6yaolu /** Used to pass the Contact card action. */ 20779525d024526e0f26b9dff40162b91f7c53f17a6yaolu public static final String EXTRA_ACTION_TYPE = "action_type"; 20879525d024526e0f26b9dff40162b91f7c53f17a6yaolu public static final String EXTRA_THIRD_PARTY_ACTION = "third_party_action"; 20979525d024526e0f26b9dff40162b91f7c53f17a6yaolu 210250fc1699c72966a5118b9afd814ca2445628ae3Gary Mai /** Used to tell the QuickContact that the previous contact was edited, so it can return an 211250fc1699c72966a5118b9afd814ca2445628ae3Gary Mai * activity result back to the original Activity that launched it. */ 212250fc1699c72966a5118b9afd814ca2445628ae3Gary Mai public static final String EXTRA_CONTACT_EDITED = "contact_edited"; 21362a2074bb3b8dc66996e9fc6a8748b999ab2b51cWalter Jang 214edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String TAG = "QuickContact"; 215edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 2169b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final String KEY_THEME_COLOR = "theme_color"; 21718906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private static final String KEY_PREVIOUS_CONTACT_ID = "previous_contact_id"; 2189b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 21958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private static final String KEY_SEND_TO_VOICE_MAIL_STATE = "sendToVoicemailState"; 22058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private static final String KEY_ARE_PHONE_OPTIONS_CHANGEABLE = "arePhoneOptionsChangable"; 22158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private static final String KEY_CUSTOM_RINGTONE = "customRingtone"; 22258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 2239b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final int ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION = 150; 2248a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private static final int REQUEST_CODE_CONTACT_EDITOR_ACTIVITY = 1; 2250b267fec5cb5b2d836057b16d0085be349be5243Brian Attwell private static final int SCRIM_COLOR = Color.argb(0xC8, 0, 0, 0); 226ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos private static final int REQUEST_CODE_CONTACT_SELECTION_ACTIVITY = 2; 227ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos private static final String MIMETYPE_SMS = "vnd.android-dir/mms-sms"; 2282de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu private static final int REQUEST_CODE_JOIN = 3; 22958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private static final int REQUEST_CODE_PICK_RINGTONE = 4; 23058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 23158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private static final int CURRENT_API_VERSION = android.os.Build.VERSION.SDK_INT; 232dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 233752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** This is the Intent action to install a shortcut in the launcher. */ 234752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private static final String ACTION_INSTALL_SHORTCUT = 235752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell "com.android.launcher.action.INSTALL_SHORTCUT"; 236edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 2372de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu public static final String ACTION_SPLIT_COMPLETED = "splitCompleted"; 2382de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 23958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Phone specific option menu items 24058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private boolean mSendToVoicemailState; 24158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private boolean mArePhoneOptionsChangable; 24258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private String mCustomRingtone; 24358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 244edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @SuppressWarnings("deprecation") 245edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String LEGACY_AUTHORITY = android.provider.Contacts.AUTHORITY; 246edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 247e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String MIMETYPE_GPLUS_PROFILE = 248e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos "vnd.android.cursor.item/vnd.googleplus.profile"; 2496a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String GPLUS_PROFILE_DATA_5_VIEW_PROFILE = "view"; 250e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String MIMETYPE_HANGOUTS = 251e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos "vnd.android.cursor.item/vnd.googleplus.profile.comm"; 2526a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String HANGOUTS_DATA_5_VIDEO = "hangout"; 2536a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String HANGOUTS_DATA_5_MESSAGE = "conversation"; 25448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos private static final String CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY = 25548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos "com.android.contacts.quickcontact.QuickContactActivity"; 256e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 25779525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Set true in {@link #onCreate} after orientation change for later use in processIntent(). 25879525d024526e0f26b9dff40162b91f7c53f17a6yaolu private boolean mIsRecreatedInstance; 259d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerott private boolean mShortcutUsageReported = false; 26079525d024526e0f26b9dff40162b91f7c53f17a6yaolu 26179525d024526e0f26b9dff40162b91f7c53f17a6yaolu private boolean mShouldLog; 26279525d024526e0f26b9dff40162b91f7c53f17a6yaolu 26379525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Used to store and log the referrer package name and the contact type. 26479525d024526e0f26b9dff40162b91f7c53f17a6yaolu private String mReferrer; 26579525d024526e0f26b9dff40162b91f7c53f17a6yaolu private int mContactType; 26679525d024526e0f26b9dff40162b91f7c53f17a6yaolu 26763176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell /** 26863176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell * The URI used to load the the Contact. Once the contact is loaded, use Contact#getLookupUri() 26963176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell * instead of referencing this URI. 27063176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell */ 271edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private Uri mLookupUri; 272edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private String[] mExcludeMimes; 2738a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mExtraMode; 27405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell private String mExtraPrioritizedMimeType; 2758a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mStatusBarColor; 2768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private boolean mHasAlreadyBeenOpened; 27797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos private boolean mOnlyOnePhoneNumber; 27897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos private boolean mOnlyOneEmail; 279b9065ddb28a2040cabda251891be2062b5260217Gary Mai private ProgressDialog mProgressDialog; 280b9065ddb28a2040cabda251891be2062b5260217Gary Mai private SaveServiceListener mListener; 281edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 28202eaf11669d25fd885606b3b0700358323532cddBrian Attwell private QuickContactImageView mPhotoView; 283eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mContactCard; 2846095369885edcca566a812b551886e29c7ff8039Brian Attwell private ExpandingEntryCardView mNoContactDetailsCard; 285b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private ExpandingEntryCardView mRecentCard; 286eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mAboutCard; 28704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu private ExpandingEntryCardView mPermissionExplanationCard; 288e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 28918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private long mPreviousContactId = 0; 29004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu // Permission explanation card. 29104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu private boolean mShouldShowPermissionExplanation = false; 29204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu private String mPermissionExplanationCardSubHeader = ""; 29304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 294b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private MultiShrinkScroller mScroller; 2956bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private AsyncTask<Void, Void, Cp2DataCardModel> mEntriesAndActionsTask; 29630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell private AsyncTask<Void, Void, Void> mRecentDataTask; 297e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 2986bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 2996bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * The last copy of Cp2DataCardModel that was passed to {@link #populateContactAndAboutCard}. 3006bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 3016bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private Cp2DataCardModel mCachedCp2DataCardModel; 302f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell /** 303f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * This scrim's opacity is controlled in two different ways. 1) Before the initial entrance 304f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * animation finishes, the opacity is animated by a value animator. This is designed to 305f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * distract the user from the length of the initial loading time. 2) After the initial 306f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * entrance animation, the opacity is directly related to scroll position. 307f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell */ 3089b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private ColorDrawable mWindowScrim; 309f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell private boolean mIsEntranceAnimationFinished; 310a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell private MaterialColorMapUtils mMaterialColorMapUtils; 3118477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell private boolean mIsExitAnimationInProgress; 3128571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell private boolean mHasComputedThemeColor; 313edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 314a42ef76251778161d27bc07db214b8c81720e476Paul Soulos /** 315a42ef76251778161d27bc07db214b8c81720e476Paul Soulos * Used to stop the ExpandingEntry cards from adjusting between an entry click and the intent 316a42ef76251778161d27bc07db214b8c81720e476Paul Soulos * being launched. 317a42ef76251778161d27bc07db214b8c81720e476Paul Soulos */ 318a42ef76251778161d27bc07db214b8c81720e476Paul Soulos private boolean mHasIntentLaunched; 319a42ef76251778161d27bc07db214b8c81720e476Paul Soulos 3206cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee private Contact mContactData; 3219815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann private ContactLoader mContactLoader; 3229b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private PorterDuffColorFilter mColorFilter; 3238e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell private int mColorFilterColor; 3249815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann 3259758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter(); 3269758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus 327edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 328cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * {@link #LEADING_MIMETYPES} is used to sort MIME-types. 329edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 330edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * <p>The MIME-types in {@link #LEADING_MIMETYPES} appear in the front of the dialog, 331edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * in the order specified here.</p> 332edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 333edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final List<String> LEADING_MIMETYPES = Lists.newArrayList( 334cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos Phone.CONTENT_ITEM_TYPE, SipAddress.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE, 335405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos StructuredPostal.CONTENT_ITEM_TYPE); 336edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 337a153dba33c2152332c5706178a367f52b0550723Paul Soulos private static final List<String> SORTED_ABOUT_CARD_MIMETYPES = Lists.newArrayList( 338a153dba33c2152332c5706178a367f52b0550723Paul Soulos Nickname.CONTENT_ITEM_TYPE, 339a153dba33c2152332c5706178a367f52b0550723Paul Soulos // Phonetic name is inserted after nickname if it is available. 340a153dba33c2152332c5706178a367f52b0550723Paul Soulos // No mimetype for phonetic name exists. 341a153dba33c2152332c5706178a367f52b0550723Paul Soulos Website.CONTENT_ITEM_TYPE, 342a153dba33c2152332c5706178a367f52b0550723Paul Soulos Organization.CONTENT_ITEM_TYPE, 343a153dba33c2152332c5706178a367f52b0550723Paul Soulos Event.CONTENT_ITEM_TYPE, 344a153dba33c2152332c5706178a367f52b0550723Paul Soulos Relation.CONTENT_ITEM_TYPE, 345a153dba33c2152332c5706178a367f52b0550723Paul Soulos Im.CONTENT_ITEM_TYPE, 346a153dba33c2152332c5706178a367f52b0550723Paul Soulos GroupMembership.CONTENT_ITEM_TYPE, 347a153dba33c2152332c5706178a367f52b0550723Paul Soulos Identity.CONTENT_ITEM_TYPE, 3481bd8826c81eff79551c79c3042aca22a1d905524yaolu CustomDataItem.MIMETYPE_CUSTOM_FIELD, 349a153dba33c2152332c5706178a367f52b0550723Paul Soulos Note.CONTENT_ITEM_TYPE); 350eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 351c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwell private static final BidiFormatter sBidiFormatter = BidiFormatter.getInstance(); 352c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwell 353b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background contact loader */ 354b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_CONTACT_ID = 0; 355b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 356b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background Sms Loader */ 357b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_SMS_ID = 1; 358b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int MAX_SMS_RETRIEVE = 3; 359ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 360ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the back Calendar Loader */ 361899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int LOADER_CALENDAR_ID = 2; 362ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final String KEY_LOADER_EXTRA_EMAILS = 363ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_EMAILS"; 364899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_PAST_CALENDAR_RETRIEVE = 3; 365899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_FUTURE_CALENDAR_RETRIEVE = 3; 366899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 36740d7a65c6e68967f3f486715b194c144d93c296fPaul Soulos 1L * 24L * 60L * 60L * 1000L /* 1 day */; 368899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 36940d7a65c6e68967f3f486715b194c144d93c296fPaul Soulos 7L * 24L * 60L * 60L * 1000L /* 7 days */; 370899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 371ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the background Call Log Loader */ 372ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int LOADER_CALL_LOG_ID = 3; 373ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int MAX_CALL_LOG_RETRIEVE = 3; 3746095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int MIN_NUM_CONTACT_ENTRIES_SHOWN = 3; 3756095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN = 3; 3766095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int CARD_ENTRY_ID_EDIT_CONTACT = -2; 37704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu private static final int CARD_ENTRY_ID_REQUEST_PERMISSION = -3; 378c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu private static final String KEY_LOADER_EXTRA_PHONES = 379c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_PHONES"; 380c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu private static final String KEY_LOADER_EXTRA_SIP_NUMBERS = 381c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_SIP_NUMBERS"; 382ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 383ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int[] mRecentLoaderIds = new int[]{ 384ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_SMS_ID, 385ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALENDAR_ID, 386ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID}; 38712ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner /** 38812ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner * ConcurrentHashMap constructor params: 4 is initial table size, 0.9f is 38912ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner * load factor before resizing, 1 means we only expect a single thread to 39012ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner * write to the map so make only a single shard 39112ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner */ 39212ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner private Map<Integer, List<ContactInteraction>> mRecentLoaderResults = 39312ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner new ConcurrentHashMap<>(4, 0.9f, 1); 394b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 395d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private static final String FRAGMENT_TAG_SELECT_ACCOUNT = "select_account_fragment"; 3966cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee 3972d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos final OnClickListener mEntryClickHandler = new OnClickListener() { 3982d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos @Override 3992d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos public void onClick(View v) { 4002ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final Object entryTagObject = v.getTag(); 4012ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos if (entryTagObject == null || !(entryTagObject instanceof EntryTag)) { 4022ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos Log.w(TAG, "EntryTag was not used correctly"); 4036095369885edcca566a812b551886e29c7ff8039Brian Attwell return; 4046095369885edcca566a812b551886e29c7ff8039Brian Attwell } 4052ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final EntryTag entryTag = (EntryTag) entryTagObject; 4062ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final Intent intent = entryTag.getIntent(); 4072ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final int dataId = entryTag.getId(); 4082ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos 4092ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos if (dataId == CARD_ENTRY_ID_EDIT_CONTACT) { 4102ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos editContact(); 4112d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos return; 4122d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 413ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 41404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu if (dataId == CARD_ENTRY_ID_REQUEST_PERMISSION) { 41504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu finish(); 41604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu RequestDesiredPermissionsActivity.startPermissionActivity( 41704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu QuickContactActivity.this); 41804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu return; 41904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu } 42004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 42119c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO // Pass the touch point through the intent for use in the InCallUI 42219c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO if (Intent.ACTION_CALL.equals(intent.getAction())) { 42319c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO if (TouchPointManager.getInstance().hasValidPoint()) { 42419c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Bundle extras = new Bundle(); 42519c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO extras.putParcelable(TouchPointManager.TOUCH_POINT, 42619c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO TouchPointManager.getInstance().getPoint()); 42719c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras); 42819c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } 42919c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } 43019c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO 43119c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 43219c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO 43319c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO mHasIntentLaunched = true; 43419c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO try { 43579525d024526e0f26b9dff40162b91f7c53f17a6yaolu final int actionType = intent.getIntExtra(EXTRA_ACTION_TYPE, 43679525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION); 43779525d024526e0f26b9dff40162b91f7c53f17a6yaolu final String thirdPartyAction = intent.getStringExtra(EXTRA_THIRD_PARTY_ACTION); 43879525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, 43979525d024526e0f26b9dff40162b91f7c53f17a6yaolu CardType.UNKNOWN_CARD, actionType, thirdPartyAction); 4408c434e5bcc92963f34200634ae5e0ccbe0e7c473Tingting Wang ImplicitIntentsUtil.startActivityInAppIfPossible(QuickContactActivity.this, intent); 44119c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } catch (SecurityException ex) { 44219c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.makeText(QuickContactActivity.this, R.string.missing_app, 44319c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.LENGTH_SHORT).show(); 44419c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Log.e(TAG, "QuickContacts does not have permission to launch " 44519c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO + intent); 44619c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } catch (ActivityNotFoundException ex) { 44719c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.makeText(QuickContactActivity.this, R.string.missing_app, 44819c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.LENGTH_SHORT).show(); 44919c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } 45019c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO 451ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Default to USAGE_TYPE_CALL. Usage is summed among all types for sorting each data id 452ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // so the exact usage type is not necessary in all cases 453ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos String usageType = DataUsageFeedback.USAGE_TYPE_CALL; 454ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 45520bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos final Uri intentUri = intent.getData(); 45620bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos if ((intentUri != null && intentUri.getScheme() != null && 4571cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner intentUri.getScheme().equals(ContactsUtils.SCHEME_SMSTO)) || 458ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos (intent.getType() != null && intent.getType().equals(MIMETYPE_SMS))) { 459ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos usageType = DataUsageFeedback.USAGE_TYPE_SHORT_TEXT; 460ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 461ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 462ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Data IDs start at 1 so anything less is invalid 463ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (dataId > 0) { 46420bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos final Uri dataUsageUri = DataUsageFeedback.FEEDBACK_URI.buildUpon() 465ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendPath(String.valueOf(dataId)) 466ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, usageType) 467ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .build(); 4689881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner try { 4699881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner final boolean successful = getContentResolver().update( 4709881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner dataUsageUri, new ContentValues(), null, null) > 0; 4719881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner if (!successful) { 4729881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner Log.w(TAG, "DataUsageFeedback increment failed"); 4739881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner } 4749881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner } catch (SecurityException ex) { 4759881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner Log.w(TAG, "DataUsageFeedback increment failed", ex); 476ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 477ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } else { 478ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Log.w(TAG, "Invalid Data ID"); 479ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 4802d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 4812d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos }; 4822d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos 483e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell final ExpandingEntryCardViewListener mExpandingEntryCardViewListener 484e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell = new ExpandingEntryCardViewListener() { 485e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell @Override 486e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell public void onCollapse(int heightDelta) { 487e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell mScroller.prepareForShrinkingScrollChild(heightDelta); 488e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell } 4890cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos 4900cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos @Override 491245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell public void onExpand() { 492245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell mScroller.setDisableTouchesForSuppressLayout(/* areTouchesDisabled = */ true); 493245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell } 494245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell 495245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell @Override 496245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell public void onExpandDone() { 497245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell mScroller.setDisableTouchesForSuppressLayout(/* areTouchesDisabled = */ false); 4980cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos } 499e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell }; 500e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell 50197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos private interface ContextMenuIds { 50297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos static final int COPY_TEXT = 0; 50397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos static final int CLEAR_DEFAULT = 1; 50497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos static final int SET_DEFAULT = 2; 50597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 50697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 5072a4207fb39330e840436215c896cde911489e111Paul Soulos private final OnCreateContextMenuListener mEntryContextMenuListener = 5082a4207fb39330e840436215c896cde911489e111Paul Soulos new OnCreateContextMenuListener() { 5092a4207fb39330e840436215c896cde911489e111Paul Soulos @Override 5102a4207fb39330e840436215c896cde911489e111Paul Soulos public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 5112a4207fb39330e840436215c896cde911489e111Paul Soulos if (menuInfo == null) { 5122a4207fb39330e840436215c896cde911489e111Paul Soulos return; 5132a4207fb39330e840436215c896cde911489e111Paul Soulos } 51497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final EntryContextMenuInfo info = (EntryContextMenuInfo) menuInfo; 5152a4207fb39330e840436215c896cde911489e111Paul Soulos menu.setHeaderTitle(info.getCopyText()); 51697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menu.add(ContextMenu.NONE, ContextMenuIds.COPY_TEXT, 51797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ContextMenu.NONE, getString(R.string.copy_text)); 51897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 51997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Don't allow setting or clearing of defaults for non-editable contacts 52097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (!isContactEditable()) { 52197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return; 52297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 52397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 52497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final String selectedMimeType = info.getMimeType(); 52597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 52697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Defaults to true will only enable the detail to be copied to the clipboard. 52797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos boolean onlyOneOfMimeType = true; 52897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 52997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Only allow primary support for Phone and Email content types 53097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (Phone.CONTENT_ITEM_TYPE.equals(selectedMimeType)) { 53197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos onlyOneOfMimeType = mOnlyOnePhoneNumber; 53297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } else if (Email.CONTENT_ITEM_TYPE.equals(selectedMimeType)) { 53397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos onlyOneOfMimeType = mOnlyOneEmail; 53497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 53597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 53697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Checking for previously set default 53797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (info.isSuperPrimary()) { 53897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menu.add(ContextMenu.NONE, ContextMenuIds.CLEAR_DEFAULT, 53997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ContextMenu.NONE, getString(R.string.clear_default)); 54097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } else if (!onlyOneOfMimeType) { 54197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menu.add(ContextMenu.NONE, ContextMenuIds.SET_DEFAULT, 54297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ContextMenu.NONE, getString(R.string.set_default)); 54397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 5442a4207fb39330e840436215c896cde911489e111Paul Soulos } 5452a4207fb39330e840436215c896cde911489e111Paul Soulos }; 5462a4207fb39330e840436215c896cde911489e111Paul Soulos 5472a4207fb39330e840436215c896cde911489e111Paul Soulos @Override 5482a4207fb39330e840436215c896cde911489e111Paul Soulos public boolean onContextItemSelected(MenuItem item) { 5492a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo menuInfo; 5502a4207fb39330e840436215c896cde911489e111Paul Soulos try { 5512a4207fb39330e840436215c896cde911489e111Paul Soulos menuInfo = (EntryContextMenuInfo) item.getMenuInfo(); 5522a4207fb39330e840436215c896cde911489e111Paul Soulos } catch (ClassCastException e) { 5532a4207fb39330e840436215c896cde911489e111Paul Soulos Log.e(TAG, "bad menuInfo", e); 5542a4207fb39330e840436215c896cde911489e111Paul Soulos return false; 5552a4207fb39330e840436215c896cde911489e111Paul Soulos } 5562a4207fb39330e840436215c896cde911489e111Paul Soulos 55797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos switch (item.getItemId()) { 55897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos case ContextMenuIds.COPY_TEXT: 55997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ClipboardUtils.copyText(this, menuInfo.getCopyLabel(), menuInfo.getCopyText(), 56097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos true); 56197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return true; 56297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos case ContextMenuIds.SET_DEFAULT: 56397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final Intent setIntent = ContactSaveService.createSetSuperPrimaryIntent(this, 56497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menuInfo.getId()); 56597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos this.startService(setIntent); 56697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return true; 56797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos case ContextMenuIds.CLEAR_DEFAULT: 56897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final Intent clearIntent = ContactSaveService.createClearPrimaryIntent(this, 56997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menuInfo.getId()); 57097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos this.startService(clearIntent); 57197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return true; 57297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos default: 57397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos throw new IllegalArgumentException("Unknown menu option " + item.getItemId()); 57497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 5752a4207fb39330e840436215c896cde911489e111Paul Soulos } 5762a4207fb39330e840436215c896cde911489e111Paul Soulos 577b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell final MultiShrinkScrollerListener mMultiShrinkScrollerListener 578b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell = new MultiShrinkScrollerListener() { 579b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 580b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onScrolledOffBottom() { 581f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell finish(); 582b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 5838a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 5848a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 5858a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onEnterFullscreen() { 5868a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 5878a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 5888a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 5898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 5908a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onExitFullscreen() { 5918a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 5928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 5938477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 5948477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 5958477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell public void onStartScrollOffBottom() { 5968477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mIsExitAnimationInProgress = true; 5978477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 5988477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 5998477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 600f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void onEntranceAnimationDone() { 601f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = true; 602f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 603f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 604f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell @Override 605f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void onTransparentViewHeightChange(float ratio) { 606f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell if (mIsEntranceAnimationFinished) { 607f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mWindowScrim.setAlpha((int) (0xFF * ratio)); 6088477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 6098477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 610b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell }; 611b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 612eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 613eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 614eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Data items are compared to the same mimetype based off of three qualities: 615eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 1. Super primary 616eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 2. Primary 617eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 3. Times used 618eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 619eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<DataItem> mWithinMimeTypeDataItemComparator = 620eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<DataItem>() { 621eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 622eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(DataItem lhs, DataItem rhs) { 623eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!lhs.getMimeType().equals(rhs.getMimeType())) { 624eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Log.wtf(TAG, "Comparing DataItems with different mimetypes lhs.getMimeType(): " + 625eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getMimeType() + " rhs.getMimeType(): " + rhs.getMimeType()); 626eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 627eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 628eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 629eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lhs.isSuperPrimary()) { 630eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 631eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (rhs.isSuperPrimary()) { 632eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 633eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lhs.isPrimary() && !rhs.isPrimary()) { 634eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 635eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (!lhs.isPrimary() && rhs.isPrimary()) { 636eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 637eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 638eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = 639eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 640eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = 641eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 642eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 643eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return rhsTimesUsed - lhsTimesUsed; 644eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 645eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 646eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 647eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 648cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos /** 649cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * Sorts among different mimetypes based off: 65005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 1. Whether one of the mimetypes is the prioritized mimetype 65105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 2. Number of times used 65205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 3. Last time used 65305287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 4. Statically defined 654cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos */ 655eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<List<DataItem>> mAmongstMimeTypeDataItemComparator = 656eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<List<DataItem>> () { 657eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 658eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(List<DataItem> lhsList, List<DataItem> rhsList) { 65905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final DataItem lhs = lhsList.get(0); 66005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final DataItem rhs = rhsList.get(0); 66105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final String lhsMimeType = lhs.getMimeType(); 66205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final String rhsMimeType = rhs.getMimeType(); 66305287bf0cea303b93802a629aa883fb6322ca342Brian Attwell 66405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 1. Whether one of the mimetypes is the prioritized mimetype 66505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (!TextUtils.isEmpty(mExtraPrioritizedMimeType) && !lhsMimeType.equals(rhsMimeType)) { 66605287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (rhsMimeType.equals(mExtraPrioritizedMimeType)) { 66705287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return 1; 66805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 66905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (lhsMimeType.equals(mExtraPrioritizedMimeType)) { 67005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return -1; 67105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 67205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 67305287bf0cea303b93802a629aa883fb6322ca342Brian Attwell 67405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 2. Number of times used 675eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 676eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 677eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int timesUsedDifference = rhsTimesUsed - lhsTimesUsed; 678eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (timesUsedDifference != 0) { 679eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return timesUsedDifference; 680eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 681eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 68205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 3. Last time used 683eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lhsLastTimeUsed = 684eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getLastTimeUsed() == null ? 0 : lhs.getLastTimeUsed(); 685eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long rhsLastTimeUsed = 686eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getLastTimeUsed() == null ? 0 : rhs.getLastTimeUsed(); 687eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lastTimeUsedDifference = rhsLastTimeUsed - lhsLastTimeUsed; 688eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lastTimeUsedDifference > 0) { 689eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 690eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lastTimeUsedDifference < 0) { 691eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 692eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 693eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 69405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 4. Resort to a statically defined mimetype order. 69505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (!lhsMimeType.equals(rhsMimeType)) { 69605287bf0cea303b93802a629aa883fb6322ca342Brian Attwell for (String mimeType : LEADING_MIMETYPES) { 69705287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (lhsMimeType.equals(mimeType)) { 69805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return -1; 69905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } else if (rhsMimeType.equals(mimeType)) { 70005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return 1; 70105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 702eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 703eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 704eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 705eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 706eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 707eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 708edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @Override 709f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen public boolean dispatchTouchEvent(MotionEvent ev) { 710f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen if (ev.getAction() == MotionEvent.ACTION_DOWN) { 711f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); 712f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen } 713f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen return super.dispatchTouchEvent(ev); 714f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen } 715f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen 716f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen @Override 7178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onCreate(Bundle savedInstanceState) { 7188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onCreate()"); 7198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onCreate(savedInstanceState); 720edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 72104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu if (RequestPermissionsActivity.startPermissionActivity(this)) { 722bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell return; 723bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell } 724bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell 7257a09c70af86b9f3bae52c102ebfb6a32b99e7409yaolu mIsRecreatedInstance = savedInstanceState != null; 7262de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu if (mIsRecreatedInstance) { 7272de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu mPreviousContactId = savedInstanceState.getLong(KEY_PREVIOUS_CONTACT_ID); 72858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 72958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Phone specific options menus 73058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mSendToVoicemailState = savedInstanceState.getBoolean(KEY_SEND_TO_VOICE_MAIL_STATE); 73158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mArePhoneOptionsChangable = 73258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu savedInstanceState.getBoolean(KEY_ARE_PHONE_OPTIONS_CHANGEABLE); 73358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mCustomRingtone = savedInstanceState.getString(KEY_CUSTOM_RINGTONE); 7342de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } 735b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog = new ProgressDialog(this); 736b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.setIndeterminate(true); 737b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.setCancelable(false); 738b9065ddb28a2040cabda251891be2062b5260217Gary Mai 739b9065ddb28a2040cabda251891be2062b5260217Gary Mai mListener = new SaveServiceListener(); 740b9065ddb28a2040cabda251891be2062b5260217Gary Mai final IntentFilter intentFilter = new IntentFilter(); 741b9065ddb28a2040cabda251891be2062b5260217Gary Mai intentFilter.addAction(ContactSaveService.BROADCAST_LINK_COMPLETE); 742b9065ddb28a2040cabda251891be2062b5260217Gary Mai intentFilter.addAction(ContactSaveService.BROADCAST_UNLINK_COMPLETE); 743b9065ddb28a2040cabda251891be2062b5260217Gary Mai LocalBroadcastManager.getInstance(this).registerReceiver(mListener, 744b9065ddb28a2040cabda251891be2062b5260217Gary Mai intentFilter); 745b9065ddb28a2040cabda251891be2062b5260217Gary Mai 746b9065ddb28a2040cabda251891be2062b5260217Gary Mai 74779525d024526e0f26b9dff40162b91f7c53f17a6yaolu mShouldLog = true; 74879525d024526e0f26b9dff40162b91f7c53f17a6yaolu 74904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu // There're 3 states for each permission: 75004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu // 1. App doesn't have permission, not asked user yet. 75104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu // 2. App doesn't have permission, user denied it previously. 75204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu // 3. App has permission. 75304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu // Permission explanation card is displayed only for case 1. 7545a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang final boolean hasTelephonyFeature = 7555a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY); 7565a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang 75704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final boolean hasCalendarPermission = PermissionsUtil.hasPermission( 7580e723d937f3fc9a0bda2602d97d9fbeda7300d51Walter Jang this, Manifest.permission.READ_CALENDAR); 7595a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang final boolean hasSMSPermission = hasTelephonyFeature 7605a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang && PermissionsUtil.hasPermission(this, Manifest.permission.READ_SMS); 76104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 76204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final boolean wasCalendarPermissionDenied = 76304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu ActivityCompat.shouldShowRequestPermissionRationale( 7640e723d937f3fc9a0bda2602d97d9fbeda7300d51Walter Jang this, Manifest.permission.READ_CALENDAR); 76504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final boolean wasSMSPermissionDenied = 7665a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang hasTelephonyFeature && ActivityCompat.shouldShowRequestPermissionRationale( 7670e723d937f3fc9a0bda2602d97d9fbeda7300d51Walter Jang this, Manifest.permission.READ_SMS); 76804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 76904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final boolean shouldDisplayCalendarMessage = 77004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu !hasCalendarPermission && !wasCalendarPermissionDenied; 7715a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang final boolean shouldDisplaySMSMessage = 7725a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang hasTelephonyFeature && !hasSMSPermission && !wasSMSPermissionDenied; 77304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mShouldShowPermissionExplanation = shouldDisplayCalendarMessage || shouldDisplaySMSMessage; 77404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 77504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu if (shouldDisplayCalendarMessage && shouldDisplaySMSMessage) { 77604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCardSubHeader = 77704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu getString(R.string.permission_explanation_subheader_calendar_and_SMS); 77804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu } else if (shouldDisplayCalendarMessage) { 77904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCardSubHeader = 78004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu getString(R.string.permission_explanation_subheader_calendar); 78104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu } else if (shouldDisplaySMSMessage) { 78204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCardSubHeader = 78304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu getString(R.string.permission_explanation_subheader_SMS); 78404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu } 78504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 7861bb6c29245bbef5b8dd1c68607acf14aec639be6Walter Jang final int previousScreenType = getIntent().getIntExtra 7871bb6c29245bbef5b8dd1c68607acf14aec639be6Walter Jang (EXTRA_PREVIOUS_SCREEN_TYPE, ScreenType.UNKNOWN); 78862a2074bb3b8dc66996e9fc6a8748b999ab2b51cWalter Jang Logger.logScreenView(this, ScreenType.QUICK_CONTACT, previousScreenType); 78962a2074bb3b8dc66996e9fc6a8748b999ab2b51cWalter Jang 79079525d024526e0f26b9dff40162b91f7c53f17a6yaolu mReferrer = getCallingPackage(); 79179525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mReferrer == null && CompatUtils.isLollipopMr1Compatible() && getReferrer() != null) { 79279525d024526e0f26b9dff40162b91f7c53f17a6yaolu mReferrer = getReferrer().getAuthority(); 79379525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 79479525d024526e0f26b9dff40162b91f7c53f17a6yaolu mContactType = ContactType.UNKNOWN_TYPE; 79579525d024526e0f26b9dff40162b91f7c53f17a6yaolu 7964c3d3e24b0de8b4170106e312f6a4ac8139e1242Wenyi Wang if (CompatUtils.isLollipopCompatible()) { 7974c3d3e24b0de8b4170106e312f6a4ac8139e1242Wenyi Wang getWindow().setStatusBarColor(Color.TRANSPARENT); 7984c3d3e24b0de8b4170106e312f6a4ac8139e1242Wenyi Wang } 7992426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann 800d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(getIntent()); 801dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 80210d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa // Show QuickContact in front of soft input 80310d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 80410d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 80510d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa 806edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann setContentView(R.layout.quickcontact_activity); 807edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 808a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell mMaterialColorMapUtils = new MaterialColorMapUtils(getResources()); 809a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell 8100cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mScroller = (MultiShrinkScroller) findViewById(R.id.multiscroller); 8110cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos 812eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard = (ExpandingEntryCardView) findViewById(R.id.communication_card); 8136095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard = (ExpandingEntryCardView) findViewById(R.id.no_contact_data_card); 814b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card); 815eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard = (ExpandingEntryCardView) findViewById(R.id.about_card); 81604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard = 81704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu (ExpandingEntryCardView) findViewById(R.id.permission_explanation_card); 818edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 81904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setOnClickListener(mEntryClickHandler); 8206095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setOnClickListener(mEntryClickHandler); 821eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setOnClickListener(mEntryClickHandler); 8222a4207fb39330e840436215c896cde911489e111Paul Soulos mContactCard.setOnCreateContextMenuListener(mEntryContextMenuListener); 823b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 824b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setOnClickListener(mEntryClickHandler); 825b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setTitle(getResources().getString(R.string.recent_card_title)); 826edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 827eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setOnClickListener(mEntryClickHandler); 8282a4207fb39330e840436215c896cde911489e111Paul Soulos mAboutCard.setOnCreateContextMenuListener(mEntryContextMenuListener); 829eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 83002eaf11669d25fd885606b3b0700358323532cddBrian Attwell mPhotoView = (QuickContactImageView) findViewById(R.id.photo); 83163176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell final View transparentView = findViewById(R.id.transparent_view); 8320d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell if (mScroller != null) { 83363176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell transparentView.setOnClickListener(new OnClickListener() { 8340d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell @Override 8350d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell public void onClick(View v) { 8360d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell mScroller.scrollOffBottom(); 8370d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 8380d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell }); 8390d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 840edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 841d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell // Allow a shadow to be shown under the toolbar. 842d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell ViewUtil.addRectangularOutlineProvider(findViewById(R.id.toolbar_parent), getResources()); 843d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell 844d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 845d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell setActionBar(toolbar); 8469b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getActionBar().setTitle(null); 8479b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // Put a TextView with a known resource id into the ActionBar. This allows us to easily 8489b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // find the correct TextView location & size later. 8499b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell toolbar.addView(getLayoutInflater().inflate(R.layout.quickcontact_title_placeholder, null)); 8506219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee 8518a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = savedInstanceState != null; 852f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = mHasAlreadyBeenOpened; 8539b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mWindowScrim = new ColorDrawable(SCRIM_COLOR); 854f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mWindowScrim.setAlpha(0); 8559b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getWindow().setBackgroundDrawable(mWindowScrim); 856edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 857caf26197087343fdc18739e20e217236ff26831eWenyi Wang mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED, 858caf26197087343fdc18739e20e217236ff26831eWenyi Wang /* maximumHeaderTextSize */ -1, 859caf26197087343fdc18739e20e217236ff26831eWenyi Wang /* shouldUpdateNameViewHeight */ true); 860ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // mScroller needs to perform asynchronous measurements after initalize(), therefore 861ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // we can't mark this as GONE. 862ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.INVISIBLE); 8638a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 8649b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell setHeaderNameText(R.string.missing_name); 8659b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 866f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ true, 867f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell new Runnable() { 868f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell @Override 869f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void run() { 870f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell if (!mHasAlreadyBeenOpened) { 871f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell // The initial scrim opacity must match the scrim opacity that would be 872f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell // achieved by scrolling to the starting position. 873f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final float alphaRatio = mExtraMode == MODE_FULLY_EXPANDED ? 874f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 1 : mScroller.getStartingTransparentHeightRatio(); 875f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final int duration = getResources().getInteger( 876f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell android.R.integer.config_shortAnimTime); 877f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final int desiredAlpha = (int) (0xFF * alphaRatio); 878f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell ObjectAnimator o = ObjectAnimator.ofInt(mWindowScrim, "alpha", 0, 879f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell desiredAlpha).setDuration(duration); 880f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 881f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell o.start(); 882f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 883f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 884f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell }); 885f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 8869b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (savedInstanceState != null) { 8879b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell final int color = savedInstanceState.getInt(KEY_THEME_COLOR, 0); 888ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 889ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell new Runnable() { 890ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell @Override 891ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell public void run() { 892ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for the pre draw before setting the initial scroll 893ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // value. Prior to pre draw all scroll values are invalid. 894ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (mHasAlreadyBeenOpened) { 895ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.VISIBLE); 896ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setScroll(mScroller.getScrollNeededToBeFullScreen()); 897ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 898ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for pre draw for setting the theme color. Setting the 899ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // header tint before the MultiShrinkScroller has been measured will 900ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // cause incorrect tinting calculations. 901ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (color != 0) { 902a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell setThemeColor(mMaterialColorMapUtils 903a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell .calculatePrimaryAndSecondaryColor(color)); 9049b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 905ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 906ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell }); 9079b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 9089b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 9098a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 9108a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 9118a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 912405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos @Override 913405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos protected void onActivityResult(int requestCode, int resultCode, Intent data) { 914d1cb9045bffc3843f5a294d41ce4608c701bccccWenyi Wang final boolean deletedOrSplit = requestCode == REQUEST_CODE_CONTACT_EDITOR_ACTIVITY && 915d1cb9045bffc3843f5a294d41ce4608c701bccccWenyi Wang (resultCode == ContactDeletionInteraction.RESULT_CODE_DELETED || 916363af60ea23e5a3b945005712a16564ab69db18bGary Mai resultCode == ContactEditorActivity.RESULT_CODE_SPLIT); 9170d76abcea3e2b5ef950870d4d5cf8685524ce23eGary Mai setResult(resultCode, data); 918d1cb9045bffc3843f5a294d41ce4608c701bccccWenyi Wang if (deletedOrSplit) { 9198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell finish(); 920ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } else if (requestCode == REQUEST_CODE_CONTACT_SELECTION_ACTIVITY && 921ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos resultCode != RESULT_CANCELED) { 922ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos processIntent(data); 9232de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } else if (requestCode == REQUEST_CODE_JOIN) { 9242de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu // Ignore failed requests 9252de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu if (resultCode != Activity.RESULT_OK) { 926f83db43ccf5250574ac521bbcc642ea3c4b8278cyaolu return; 9272de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } 9282de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu if (data != null) { 9292de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu joinAggregate(ContentUris.parseId(data.getData())); 9302de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } 93158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } else if (requestCode == REQUEST_CODE_PICK_RINGTONE && data != null) { 93258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu final Uri pickedUri = data.getParcelableExtra( 93358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu RingtoneManager.EXTRA_RINGTONE_PICKED_URI); 93458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu onRingtonePicked(pickedUri); 935b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 9368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 937dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 93858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private void onRingtonePicked(Uri pickedUri) { 93958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mCustomRingtone = EditorUiUtils.getRingtoneStringFromUri(pickedUri, CURRENT_API_VERSION); 94058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu Intent intent = ContactSaveService.createSetRingtone( 94158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu this, mLookupUri, mCustomRingtone); 94258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu this.startService(intent); 94358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } 94458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 9458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 9468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onNewIntent(Intent intent) { 9478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onNewIntent(intent); 9488a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 949f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = true; 9508571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = false; 951d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(intent); 952d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 953d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 9549b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell @Override 9559b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell public void onSaveInstanceState(Bundle savedInstanceState) { 9569b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell super.onSaveInstanceState(savedInstanceState); 9579b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mColorFilter != null) { 9588e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell savedInstanceState.putInt(KEY_THEME_COLOR, mColorFilterColor); 9599b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 96018906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang savedInstanceState.putLong(KEY_PREVIOUS_CONTACT_ID, mPreviousContactId); 96158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 96258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Phone specific options 96358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu savedInstanceState.putBoolean(KEY_SEND_TO_VOICE_MAIL_STATE, mSendToVoicemailState); 96458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu savedInstanceState.putBoolean(KEY_ARE_PHONE_OPTIONS_CHANGEABLE, mArePhoneOptionsChangable); 96558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu savedInstanceState.putString(KEY_CUSTOM_RINGTONE, mCustomRingtone); 9669b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 9679b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 968d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void processIntent(Intent intent) { 969f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos if (intent == null) { 970f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos finish(); 971f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos return; 972f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos } 9732de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu if (ACTION_SPLIT_COMPLETED.equals(intent.getAction())) { 9742de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu Toast.makeText(this, R.string.contactUnlinkedToast, Toast.LENGTH_SHORT).show(); 9752de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu finish(); 9762de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu return; 9772de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } 9782de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 979d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell Uri lookupUri = intent.getData(); 980250fc1699c72966a5118b9afd814ca2445628ae3Gary Mai if (intent.getBooleanExtra(EXTRA_CONTACT_EDITED, false)) { 981363af60ea23e5a3b945005712a16564ab69db18bGary Mai setResult(ContactEditorActivity.RESULT_CODE_EDITED); 982250fc1699c72966a5118b9afd814ca2445628ae3Gary Mai } 983d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 984d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Check to see whether it comes from the old version. 985d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) { 986d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final long rawContactId = ContentUris.parseId(lookupUri); 987d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell lookupUri = RawContacts.getContactLookupUri(getContentResolver(), 988d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); 989d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 99005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, QuickContact.MODE_LARGE); 991caf26197087343fdc18739e20e217236ff26831eWenyi Wang if (isMultiWindowOnPhone()) { 992caf26197087343fdc18739e20e217236ff26831eWenyi Wang mExtraMode = QuickContact.MODE_LARGE; 993caf26197087343fdc18739e20e217236ff26831eWenyi Wang } 994caf26197087343fdc18739e20e217236ff26831eWenyi Wang mExtraPrioritizedMimeType = 995caf26197087343fdc18739e20e217236ff26831eWenyi Wang getIntent().getStringExtra(QuickContact.EXTRA_PRIORITIZED_MIMETYPE); 996d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Uri oldLookupUri = mLookupUri; 997d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 998d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerott 999fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner if (lookupUri == null) { 1000fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner finish(); 1001fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner return; 1002fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner } 1003fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner mLookupUri = lookupUri; 1004d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES); 1005d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (oldLookupUri == null) { 100679525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Should not log if only orientation changes. 100779525d024526e0f26b9dff40162b91f7c53f17a6yaolu mShouldLog = !mIsRecreatedInstance; 1008d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactLoader = (ContactLoader) getLoaderManager().initLoader( 1009d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell LOADER_CONTACT_ID, null, mLoaderContactCallbacks); 1010d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (oldLookupUri != mLookupUri) { 101179525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Should log when reload happens, regardless of orientation change. 101279525d024526e0f26b9dff40162b91f7c53f17a6yaolu mShouldLog = true; 1013d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // After copying a directory contact, the contact URI changes. Therefore, 1014144a4d16daf88dded258063bc33810b20c57f81dWenyi Wang // we need to reload the new contact. 101559a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell destroyInteractionLoaders(); 1016144a4d16daf88dded258063bc33810b20c57f81dWenyi Wang mContactLoader = (ContactLoader) (Loader<?>) getLoaderManager().getLoader( 1017144a4d16daf88dded258063bc33810b20c57f81dWenyi Wang LOADER_CONTACT_ID); 10184861031d5f0ac3707fe089c1efd559260672df39yaolu mContactLoader.setNewLookup(mLookupUri); 101959a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell mCachedCp2DataCardModel = null; 1020d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1021144a4d16daf88dded258063bc33810b20c57f81dWenyi Wang mContactLoader.forceLoad(); 10222d150da246632b1649999cfabed776133b097775Brian Attwell 10232d150da246632b1649999cfabed776133b097775Brian Attwell NfcHandler.register(this, mLookupUri); 10242426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann } 1025edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 102659a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell private void destroyInteractionLoaders() { 102759a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell for (int interactionLoaderId : mRecentLoaderIds) { 102859a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell getLoaderManager().destroyLoader(interactionLoaderId); 102959a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell } 103059a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell } 103159a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell 1032b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private void runEntranceAnimation() { 10338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mHasAlreadyBeenOpened) { 10348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 10358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 10368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 1037caf26197087343fdc18739e20e217236ff26831eWenyi Wang mScroller.scrollUpForEntranceAnimation(/* scrollToCurrentPosition */ !isMultiWindowOnPhone() 1038caf26197087343fdc18739e20e217236ff26831eWenyi Wang && (mExtraMode != MODE_FULLY_EXPANDED)); 1039caf26197087343fdc18739e20e217236ff26831eWenyi Wang } 1040caf26197087343fdc18739e20e217236ff26831eWenyi Wang 1041caf26197087343fdc18739e20e217236ff26831eWenyi Wang private boolean isMultiWindowOnPhone() { 1042caf26197087343fdc18739e20e217236ff26831eWenyi Wang return MultiWindowCompat.isInMultiWindowMode(this) && PhoneCapabilityTester.isPhone(this); 1043b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 1044b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 104581281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 1046d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void setHeaderNameText(int resId) { 10479b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 10489f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang mScroller.setTitle(getText(resId) == null ? null : getText(resId).toString(), 10499f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang /* isPhoneNumber= */ false); 10509b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 105181281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 105281281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 105381281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 10549f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang private void setHeaderNameText(String value, boolean isPhoneNumber) { 1055d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (!TextUtils.isEmpty(value)) { 10569b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 10579f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang mScroller.setTitle(value, isPhoneNumber); 10589b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 105981281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 106081281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 106181281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 106281281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** 1063edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Check if the given MIME-type appears in the list of excluded MIME-types 1064edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * that the most-recent caller requested. 1065edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 1066edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private boolean isMimeExcluded(String mimeType) { 1067edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (mExcludeMimes == null) return false; 1068edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann for (String excludedMime : mExcludeMimes) { 1069edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (TextUtils.equals(excludedMime, mimeType)) { 1070edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return true; 1071edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1072edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1073edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return false; 1074edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1075edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1076edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 1077cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann * Handle the result from the ContactLoader 1078edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 10798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void bindContactData(final Contact data) { 10808a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("bindContactData"); 108179525d024526e0f26b9dff40162b91f7c53f17a6yaolu 108279525d024526e0f26b9dff40162b91f7c53f17a6yaolu final int actionType = mContactData == null ? ActionType.START : ActionType.UNKNOWN_ACTION; 10836cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee mContactData = data; 108479525d024526e0f26b9dff40162b91f7c53f17a6yaolu 108579525d024526e0f26b9dff40162b91f7c53f17a6yaolu final int newContactType; 108679525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (DirectoryContactUtil.isDirectoryContact(mContactData)) { 108779525d024526e0f26b9dff40162b91f7c53f17a6yaolu newContactType = ContactType.DIRECTORY; 108879525d024526e0f26b9dff40162b91f7c53f17a6yaolu } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { 108979525d024526e0f26b9dff40162b91f7c53f17a6yaolu newContactType = ContactType.INVISIBLE_AND_ADDABLE; 109079525d024526e0f26b9dff40162b91f7c53f17a6yaolu } else if (isContactEditable()) { 109179525d024526e0f26b9dff40162b91f7c53f17a6yaolu newContactType = ContactType.EDITABLE; 109279525d024526e0f26b9dff40162b91f7c53f17a6yaolu } else { 109379525d024526e0f26b9dff40162b91f7c53f17a6yaolu newContactType = ContactType.UNKNOWN_TYPE; 109479525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 109579525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mShouldLog && mContactType != newContactType) { 10967a09c70af86b9f3bae52c102ebfb6a32b99e7409yaolu Logger.logQuickContactEvent(mReferrer, newContactType, CardType.UNKNOWN_CARD, 109779525d024526e0f26b9dff40162b91f7c53f17a6yaolu actionType, /* thirdPartyAction */ null); 109879525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 109979525d024526e0f26b9dff40162b91f7c53f17a6yaolu mContactType = newContactType; 110079525d024526e0f26b9dff40162b91f7c53f17a6yaolu 110158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu setStateForPhoneMenuItems(mContactData); 1102d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell invalidateOptionsMenu(); 1103edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 11048a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 11058a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("Set display photo & name"); 1106dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 110702eaf11669d25fd885606b3b0700358323532cddBrian Attwell mPhotoView.setIsBusiness(mContactData.isDisplayNameFromOrganization()); 11086219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee mPhotoSetter.setupContactPhoto(data, mPhotoView); 110931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell extractAndApplyTintFromPhotoViewAsynchronously(); 1110df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang final String displayName = ContactDisplayUtils.getDisplayName(this, data).toString(); 11119f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang setHeaderNameText( 11129f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang displayName, mContactData.getDisplayNameSource() == DisplayNameSources.PHONE); 1113df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang final String phoneticName = ContactDisplayUtils.getPhoneticName(this, data); 1114df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang if (mScroller != null) { 1115469a70fea3ce1e24ea87df3d9e325e865d5bf07fTingting Wang // Show phonetic name only when it doesn't equal the display name. 1116469a70fea3ce1e24ea87df3d9e325e865d5bf07fTingting Wang if (!TextUtils.isEmpty(phoneticName) && !phoneticName.equals(displayName)) { 1117df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang mScroller.setPhoneticName(phoneticName); 1118df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang } else { 1119df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang mScroller.setPhoneticNameGone(); 1120df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang } 1121d5b686e73dc50d90fd44dc5c738d243a81a6cc31Tingting Wang } 1122edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 11238a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 1124dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 11256bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mEntriesAndActionsTask = new AsyncTask<Void, Void, Cp2DataCardModel>() { 11268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 11278a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 11286bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell protected Cp2DataCardModel doInBackground( 1129eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Void... params) { 1130eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return generateDataModelFromContact(data); 11318a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 11328a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 11338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 11346bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell protected void onPostExecute(Cp2DataCardModel cardDataModel) { 11356bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell super.onPostExecute(cardDataModel); 11368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Check that original AsyncTask parameters are still valid and the activity 11378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // is still running before binding to UI. A new intent could invalidate 11388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the results, for example. 11398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (data == mContactData && !isCancelled()) { 11406bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell bindDataToCards(cardDataModel); 11418a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell showActivity(); 11428a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 11438a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 11448a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }; 11458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.execute(); 11468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 11478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 11486bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void bindDataToCards(Cp2DataCardModel cp2DataCardModel) { 11496bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell startInteractionLoaders(cp2DataCardModel); 1150a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang populateContactAndAboutCard(cp2DataCardModel, /* shouldAddPhoneticName */ true); 1151eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1152eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 11536bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void startInteractionLoaders(Cp2DataCardModel cp2DataCardModel) { 11546bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final Map<String, List<DataItem>> dataItemsMap = cp2DataCardModel.dataItemsMap; 11556bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> phoneDataItems = dataItemsMap.get(Phone.CONTENT_ITEM_TYPE); 1156c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu final List<DataItem> sipCallDataItems = dataItemsMap.get(SipAddress.CONTENT_ITEM_TYPE); 115797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (phoneDataItems != null && phoneDataItems.size() == 1) { 115897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos mOnlyOnePhoneNumber = true; 115997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 1160eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] phoneNumbers = null; 1161eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (phoneDataItems != null) { 1162eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers = new String[phoneDataItems.size()]; 1163eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < phoneDataItems.size(); ++i) { 1164eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers[i] = ((PhoneDataItem) phoneDataItems.get(i)).getNumber(); 1165eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1166eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1167c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu String[] sipNumbers = null; 1168c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu if (sipCallDataItems != null) { 1169c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu sipNumbers = new String[sipCallDataItems.size()]; 1170c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu for (int i = 0; i < sipCallDataItems.size(); ++i) { 1171c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu sipNumbers[i] = ((SipAddressDataItem) sipCallDataItems.get(i)).getSipAddress(); 1172c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu } 1173c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu } 1174ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle phonesExtraBundle = new Bundle(); 1175eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_PHONES, phoneNumbers); 1176c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_SIP_NUMBERS, sipNumbers); 1177eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1178eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("start sms loader"); 11798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getLoaderManager().initLoader( 11808a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell LOADER_SMS_ID, 1181ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 1182ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos mLoaderInteractionsCallbacks); 1183ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.endSection(); 1184ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 1185ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.beginSection("start call log loader"); 1186ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos getLoaderManager().initLoader( 1187ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID, 1188ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 11898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mLoaderInteractionsCallbacks); 1190899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.endSection(); 11918a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1192eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1193899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.beginSection("start calendar loader"); 11946bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> emailDataItems = dataItemsMap.get(Email.CONTENT_ITEM_TYPE); 119597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (emailDataItems != null && emailDataItems.size() == 1) { 119697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos mOnlyOneEmail = true; 119797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 1198eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] emailAddresses = null; 1199eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (emailDataItems != null) { 1200eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses = new String[emailDataItems.size()]; 1201eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < emailDataItems.size(); ++i) { 1202eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses[i] = ((EmailDataItem) emailDataItems.get(i)).getAddress(); 1203eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1204eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1205ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle emailsExtraBundle = new Bundle(); 1206eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailsExtraBundle.putStringArray(KEY_LOADER_EXTRA_EMAILS, emailAddresses); 1207899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos getLoaderManager().initLoader( 1208899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos LOADER_CALENDAR_ID, 1209ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos emailsExtraBundle, 1210899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos mLoaderInteractionsCallbacks); 12118a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 12128a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 12148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void showActivity() { 12158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller != null) { 12168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mScroller.setVisibility(View.VISIBLE); 12178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 12188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell new Runnable() { 12198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 12208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void run() { 12218a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell runEntranceAnimation(); 12228a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12238a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }); 12248a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12258a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 12276bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private List<List<Entry>> buildAboutCardEntries(Map<String, List<DataItem>> dataItemsMap) { 1228a153dba33c2152332c5706178a367f52b0550723Paul Soulos final List<List<Entry>> aboutCardEntries = new ArrayList<>(); 1229a153dba33c2152332c5706178a367f52b0550723Paul Soulos for (String mimetype : SORTED_ABOUT_CARD_MIMETYPES) { 12306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> mimeTypeItems = dataItemsMap.get(mimetype); 1231a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (mimeTypeItems == null) { 1232a153dba33c2152332c5706178a367f52b0550723Paul Soulos continue; 1233a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 12346bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // Set aboutCardTitleOut = null, since SORTED_ABOUT_CARD_MIMETYPES doesn't contain 12356bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // the name mimetype. 12366bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<Entry> aboutEntries = dataItemsToEntries(mimeTypeItems, 12376bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /* aboutCardTitleOut = */ null); 1238a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (aboutEntries.size() > 0) { 1239a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(aboutEntries); 1240a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1241a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1242a153dba33c2152332c5706178a367f52b0550723Paul Soulos return aboutCardEntries; 1243a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1244a153dba33c2152332c5706178a367f52b0550723Paul Soulos 1245a42ef76251778161d27bc07db214b8c81720e476Paul Soulos @Override 1246a42ef76251778161d27bc07db214b8c81720e476Paul Soulos protected void onResume() { 1247a42ef76251778161d27bc07db214b8c81720e476Paul Soulos super.onResume(); 1248a42ef76251778161d27bc07db214b8c81720e476Paul Soulos // If returning from a launched activity, repopulate the contact and about card 1249a42ef76251778161d27bc07db214b8c81720e476Paul Soulos if (mHasIntentLaunched) { 1250a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = false; 1251a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang populateContactAndAboutCard(mCachedCp2DataCardModel, /* shouldAddPhoneticName */ false); 1252a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 125359a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell 125459a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell // When exiting the activity and resuming, we want to force a full reload of all the 125559a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell // interaction data in case something changed in the background. On screen rotation, 125659a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell // we don't need to do this. And, mCachedCp2DataCardModel will be null, so we won't. 125759a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell if (mCachedCp2DataCardModel != null) { 125859a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell destroyInteractionLoaders(); 125959a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell startInteractionLoaders(mCachedCp2DataCardModel); 126059a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell } 1261b9065ddb28a2040cabda251891be2062b5260217Gary Mai maybeShowProgressDialog(); 1262b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 1263b9065ddb28a2040cabda251891be2062b5260217Gary Mai 1264b9065ddb28a2040cabda251891be2062b5260217Gary Mai 1265b9065ddb28a2040cabda251891be2062b5260217Gary Mai @Override 1266b9065ddb28a2040cabda251891be2062b5260217Gary Mai protected void onPause() { 1267b9065ddb28a2040cabda251891be2062b5260217Gary Mai super.onPause(); 1268b9065ddb28a2040cabda251891be2062b5260217Gary Mai dismissProgressBar(); 1269a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 1270a42ef76251778161d27bc07db214b8c81720e476Paul Soulos 1271a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang private void populateContactAndAboutCard(Cp2DataCardModel cp2DataCardModel, 1272a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang boolean shouldAddPhoneticName) { 12736bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mCachedCp2DataCardModel = cp2DataCardModel; 12746bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (mHasIntentLaunched || cp2DataCardModel == null) { 1275a42ef76251778161d27bc07db214b8c81720e476Paul Soulos return; 1276a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 1277eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind contact card"); 1278eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 12796bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> contactCardEntries = cp2DataCardModel.contactCardEntries; 12806bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> aboutCardEntries = cp2DataCardModel.aboutCardEntries; 12816bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final String customAboutCardName = cp2DataCardModel.customAboutCardName; 1282eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1283eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (contactCardEntries.size() > 0) { 1284eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.initialize(contactCardEntries, 1285eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* numInitialVisibleEntries = */ MIN_NUM_CONTACT_ENTRIES_SHOWN, 1286c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos /* isExpanded = */ mContactCard.isExpanded(), 1287139a03bd82f45338402e747154dd7b3d61bf1747yaolu /* isAlwaysExpanded = */ true, 12880cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mExpandingEntryCardViewListener, 1289139a03bd82f45338402e747154dd7b3d61bf1747yaolu mScroller); 129079525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mContactCard.getVisibility() == View.GONE && mShouldLog) { 129179525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.CONTACT, 129279525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); 129379525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 1294eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.VISIBLE); 1295eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1296eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.GONE); 1297eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1298eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 12998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1300eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind about card"); 1301c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos // Phonetic name is not a data item, so the entry needs to be created separately 1302a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang // But if mCachedCp2DataCardModel is passed to this method (e.g. returning from editor 1303a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang // without saving any changes), then it should include phoneticName and the phoneticName 1304a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang // shouldn't be changed. If this is the case, we shouldn't add it again. b/27459294 1305c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos final String phoneticName = mContactData.getPhoneticName(); 1306a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang if (shouldAddPhoneticName && !TextUtils.isEmpty(phoneticName)) { 1307c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos Entry phoneticEntry = new Entry(/* viewId = */ -1, 1308c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* icon = */ null, 1309c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos getResources().getString(R.string.name_phonetic), 1310c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos phoneticName, 13118a3fe52802135be2402a5b216325615fb796a509Walter Jang /* subHeaderIcon = */ null, 1312c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* text = */ null, 13138a3fe52802135be2402a5b216325615fb796a509Walter Jang /* textIcon = */ null, 131423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos /* primaryContentDescription = */ null, 1315c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* intent = */ null, 1316c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateIcon = */ null, 1317c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateIntent = */ null, 1318c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateContentDescription = */ null, 1319c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* shouldApplyColor = */ false, 13202a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, 13212a4207fb39330e840436215c896cde911489e111Paul Soulos /* EntryContextMenuInfo = */ new EntryContextMenuInfo(phoneticName, 132297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos getResources().getString(R.string.name_phonetic), 132397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos /* mimeType = */ null, /* id = */ -1, /* isPrimary = */ false), 132448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, 132548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIntent = */ null, 132648290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos /* thirdContentDescription = */ null, 13275f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdAction = */ Entry.ACTION_NONE, 13285f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdExtras = */ null, 13295f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* iconResourceId = */ 0); 1330c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos List<Entry> phoneticList = new ArrayList<>(); 1331c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos phoneticList.add(phoneticEntry); 1332a153dba33c2152332c5706178a367f52b0550723Paul Soulos // Phonetic name comes after nickname. Check to see if the first entry type is nickname 1333a0fa4c18dc111ceea9ff47f35ee01fecc1003578Paul Soulos if (aboutCardEntries.size() > 0 && aboutCardEntries.get(0).get(0).getHeader().equals( 1334a153dba33c2152332c5706178a367f52b0550723Paul Soulos getResources().getString(R.string.header_nickname_entry))) { 1335a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(1, phoneticList); 1336a153dba33c2152332c5706178a367f52b0550723Paul Soulos } else { 1337a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(0, phoneticList); 1338a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1339c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos } 1340c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos 13416bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!TextUtils.isEmpty(customAboutCardName)) { 13426bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mAboutCard.setTitle(customAboutCardName); 13436bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 13446bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 13453b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox mAboutCard.initialize(aboutCardEntries, 13463b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox /* numInitialVisibleEntries = */ 1, 13473b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox /* isExpanded = */ true, 13483b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox /* isAlwaysExpanded = */ true, 13493b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox mExpandingEntryCardViewListener, 13503b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox mScroller); 13516095369885edcca566a812b551886e29c7ff8039Brian Attwell 13526095369885edcca566a812b551886e29c7ff8039Brian Attwell if (contactCardEntries.size() == 0 && aboutCardEntries.size() == 0) { 135395a134512bcdca22f3cb149967acb9dbfea309b5yaolu initializeNoContactDetailCard(cp2DataCardModel.areAllRawContactsSimAccounts); 13546095369885edcca566a812b551886e29c7ff8039Brian Attwell } else { 13556095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setVisibility(View.GONE); 13566095369885edcca566a812b551886e29c7ff8039Brian Attwell } 13576095369885edcca566a812b551886e29c7ff8039Brian Attwell 1358a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos // If the Recent card is already initialized (all recent data is loaded), show the About 1359a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos // card if it has entries. Otherwise About card visibility will be set in bindRecentData() 136079525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (aboutCardEntries.size() > 0) { 136179525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mAboutCard.getVisibility() == View.GONE && mShouldLog) { 136279525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.ABOUT, 136379525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); 136479525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 136579525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (isAllRecentDataLoaded()) { 136679525d024526e0f26b9dff40162b91f7c53f17a6yaolu mAboutCard.setVisibility(View.VISIBLE); 136779525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 1368a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos } 1369eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 1370eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1371eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1372eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 13736095369885edcca566a812b551886e29c7ff8039Brian Attwell * Create a card that shows "Add email" and "Add phone number" entries in grey. 137495a134512bcdca22f3cb149967acb9dbfea309b5yaolu * When contact is a SIM contact, only shows "Add phone number". 13756095369885edcca566a812b551886e29c7ff8039Brian Attwell */ 137695a134512bcdca22f3cb149967acb9dbfea309b5yaolu private void initializeNoContactDetailCard(boolean areAllRawContactsSimAccounts) { 13776095369885edcca566a812b551886e29c7ff8039Brian Attwell final Drawable phoneIcon = getResources().getDrawable( 13786095369885edcca566a812b551886e29c7ff8039Brian Attwell R.drawable.ic_phone_24dp).mutate(); 13796095369885edcca566a812b551886e29c7ff8039Brian Attwell final Entry phonePromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, 13806095369885edcca566a812b551886e29c7ff8039Brian Attwell phoneIcon, getString(R.string.quickcontact_add_phone_number), 13818a3fe52802135be2402a5b216325615fb796a509Walter Jang /* subHeader = */ null, /* subHeaderIcon = */ null, /* text = */ null, 13828a3fe52802135be2402a5b216325615fb796a509Walter Jang /* textIcon = */ null, /* primaryContentDescription = */ null, 138323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos getEditContactIntent(), 1384dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIcon = */ null, /* alternateIntent = */ null, 1385714455bba22b99d168a2e864dfbc74a6e30dfdb6Paul Soulos /* alternateContentDescription = */ null, /* shouldApplyColor = */ true, 138648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* isEditable = */ false, /* EntryContextMenuInfo = */ null, 138748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, /* thirdIntent = */ null, 13885f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdContentDescription = */ null, 13895f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdAction = */ Entry.ACTION_NONE, 13905f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdExtras = */ null, 13915f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn R.drawable.ic_phone_24dp); 13926095369885edcca566a812b551886e29c7ff8039Brian Attwell 13936095369885edcca566a812b551886e29c7ff8039Brian Attwell final List<List<Entry>> promptEntries = new ArrayList<>(); 13946095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.add(new ArrayList<Entry>(1)); 13956095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.get(0).add(phonePromptEntry); 139695a134512bcdca22f3cb149967acb9dbfea309b5yaolu 139795a134512bcdca22f3cb149967acb9dbfea309b5yaolu if (!areAllRawContactsSimAccounts) { 139895a134512bcdca22f3cb149967acb9dbfea309b5yaolu final Drawable emailIcon = getResources().getDrawable( 139995a134512bcdca22f3cb149967acb9dbfea309b5yaolu R.drawable.ic_email_24dp).mutate(); 140095a134512bcdca22f3cb149967acb9dbfea309b5yaolu final Entry emailPromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, 140195a134512bcdca22f3cb149967acb9dbfea309b5yaolu emailIcon, getString(R.string.quickcontact_add_email), /* subHeader = */ null, 140295a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* subHeaderIcon = */ null, 140395a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* text = */ null, /* textIcon = */ null, /* primaryContentDescription = */ null, 140495a134512bcdca22f3cb149967acb9dbfea309b5yaolu getEditContactIntent(), /* alternateIcon = */ null, 140595a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* alternateIntent = */ null, /* alternateContentDescription = */ null, 140695a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* shouldApplyColor = */ true, /* isEditable = */ false, 140795a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* EntryContextMenuInfo = */ null, /* thirdIcon = */ null, 140895a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* thirdIntent = */ null, /* thirdContentDescription = */ null, 140995a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* thirdAction = */ Entry.ACTION_NONE, /* thirdExtras = */ null, 141095a134512bcdca22f3cb149967acb9dbfea309b5yaolu R.drawable.ic_email_24dp); 141195a134512bcdca22f3cb149967acb9dbfea309b5yaolu 141295a134512bcdca22f3cb149967acb9dbfea309b5yaolu promptEntries.add(new ArrayList<Entry>(1)); 141395a134512bcdca22f3cb149967acb9dbfea309b5yaolu promptEntries.get(1).add(emailPromptEntry); 141495a134512bcdca22f3cb149967acb9dbfea309b5yaolu } 14156095369885edcca566a812b551886e29c7ff8039Brian Attwell 14166095369885edcca566a812b551886e29c7ff8039Brian Attwell final int subHeaderTextColor = getResources().getColor( 14176095369885edcca566a812b551886e29c7ff8039Brian Attwell R.color.quickcontact_entry_sub_header_text_color); 14186095369885edcca566a812b551886e29c7ff8039Brian Attwell final PorterDuffColorFilter greyColorFilter = 14196095369885edcca566a812b551886e29c7ff8039Brian Attwell new PorterDuffColorFilter(subHeaderTextColor, PorterDuff.Mode.SRC_ATOP); 1420c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos mNoContactDetailsCard.initialize(promptEntries, 2, /* isExpanded = */ true, 14210cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos /* isAlwaysExpanded = */ true, mExpandingEntryCardViewListener, mScroller); 142279525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mNoContactDetailsCard.getVisibility() == View.GONE && mShouldLog) { 142379525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.NO_CONTACT, 142479525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); 142579525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 14266095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setVisibility(View.VISIBLE); 14276095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setEntryHeaderColor(subHeaderTextColor); 14286095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setColorAndFilter(subHeaderTextColor, greyColorFilter); 14296095369885edcca566a812b551886e29c7ff8039Brian Attwell } 14306095369885edcca566a812b551886e29c7ff8039Brian Attwell 14316095369885edcca566a812b551886e29c7ff8039Brian Attwell /** 1432eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Builds the {@link DataItem}s Map out of the Contact. 1433eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param data The contact to build the data from. 1434eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return A pair containing a list of data items sorted within mimetype and sorted 1435eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * amongst mimetype. The map goes from mimetype string to the sorted list of data items within 1436eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * mimetype 1437eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 14386bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private Cp2DataCardModel generateDataModelFromContact( 1439eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Contact data) { 1440eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("Build data items map"); 1441eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1442eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Map<String, List<DataItem>> dataItemsMap = new HashMap<>(); 14438bf96e78497ea9c8c893bcb357fc1e3175fb2e9bBrian Attwell 14448a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final ResolveCache cache = ResolveCache.getInstance(this); 1445851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (RawContact rawContact : data.getRawContacts()) { 1446851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (DataItem dataItem : rawContact.getDataItems()) { 1447eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setRawContactId(rawContact.getId()); 1448eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1449851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final String mimeType = dataItem.getMimeType(); 1450eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (mimeType == null) continue; 1451eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 145247b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final AccountType accountType = rawContact.getAccountType(this); 145347b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final DataKind dataKind = AccountTypeManager.getInstance(this) 145447b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng .getKindOrFallback(accountType, mimeType); 1455eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataKind == null) continue; 1456cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1457eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setDataKind(dataKind); 1458b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1459eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean hasData = !TextUtils.isEmpty(dataItem.buildDataString(this, 1460eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataKind)); 1461899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 1462eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (isMimeExcluded(mimeType) || !hasData) continue; 1463edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1464eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos List<DataItem> dataItemListByType = dataItemsMap.get(mimeType); 1465eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItemListByType == null) { 1466eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType = new ArrayList<>(); 1467eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsMap.put(mimeType, dataItemListByType); 1468edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1469eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType.add(dataItem); 1470edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1471edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 14728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 1473edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1474eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort within mimetypes"); 147516339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos /* 147616339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos * Sorting is a multi part step. The end result is to a have a sorted list of the most 1477eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * used data items, one per mimetype. Then, within each mimetype, the list of data items 1478eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * for that type is also sorted, based off of {super primary, primary, times used} in that 1479eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * order. 148016339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos */ 1481eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<List<DataItem>> dataItemsList = new ArrayList<>(); 1482eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (List<DataItem> mimeTypeDataItems : dataItemsMap.values()) { 1483eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Remove duplicate data items 1484eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collapser.collapseList(mimeTypeDataItems, this); 1485eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort within mimetype 1486eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(mimeTypeDataItems, mWithinMimeTypeDataItemComparator); 1487eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Add to the list of data item lists 1488eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsList.add(mimeTypeDataItems); 1489edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1490eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 1491edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1492eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort amongst mimetypes"); 1493eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort amongst mimetypes to bubble up the top data items for the contact card 1494eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(dataItemsList, mAmongstMimeTypeDataItemComparator); 1495eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 149616339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos 14976bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Trace.beginSection("cp2 data items to entries"); 14986bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 14996bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> contactCardEntries = new ArrayList<>(); 15006bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> aboutCardEntries = buildAboutCardEntries(dataItemsMap); 15016bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final MutableString aboutCardName = new MutableString(); 15026bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 15036bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell for (int i = 0; i < dataItemsList.size(); ++i) { 15046bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> dataItemsByMimeType = dataItemsList.get(i); 15056bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final DataItem topDataItem = dataItemsByMimeType.get(0); 15066bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (SORTED_ABOUT_CARD_MIMETYPES.contains(topDataItem.getMimeType())) { 15076bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // About card mimetypes are built in buildAboutCardEntries, skip here 15086bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell continue; 15096bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } else { 15106bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell List<Entry> contactEntries = dataItemsToEntries(dataItemsList.get(i), 15116bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell aboutCardName); 15126bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (contactEntries.size() > 0) { 15136bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell contactCardEntries.add(contactEntries); 15146bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 15156bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 15166bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 15176bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 15186bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Trace.endSection(); 15196bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 15206bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final Cp2DataCardModel dataModel = new Cp2DataCardModel(); 15216bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.customAboutCardName = aboutCardName.value; 15226bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.aboutCardEntries = aboutCardEntries; 15236bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.contactCardEntries = contactCardEntries; 15246bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.dataItemsMap = dataItemsMap; 152595a134512bcdca22f3cb149967acb9dbfea309b5yaolu dataModel.areAllRawContactsSimAccounts = data.areAllRawContactsSimAccounts(this); 15266bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell return dataModel; 15276bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 15286bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 15296bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 15306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * Class used to hold the About card and Contact cards' data model that gets generated 15316bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * on a background thread. All data is from CP2. 15326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 15336bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static class Cp2DataCardModel { 15346bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 15356bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * A map between a mimetype string and the corresponding list of data items. The data items 15366bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * are in sorted order using mWithinMimeTypeDataItemComparator. 15376bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 15386bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public Map<String, List<DataItem>> dataItemsMap; 15396bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public List<List<Entry>> aboutCardEntries; 15406bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public List<List<Entry>> contactCardEntries; 15416bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public String customAboutCardName; 154295a134512bcdca22f3cb149967acb9dbfea309b5yaolu public boolean areAllRawContactsSimAccounts; 15436bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 15446bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 15456bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static class MutableString { 15466bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public String value; 1547eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1548edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1549eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 1550eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Converts a {@link DataItem} into an {@link ExpandingEntryCardView.Entry} for display. 1551eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * If the {@link ExpandingEntryCardView.Entry} has no visual elements, null is returned. 15526bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * 15536bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * This runs on a background thread. This is set as static to avoid accidentally adding 15546bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * additional dependencies on unsafe things (like the Activity). 15556bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * 1556eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param dataItem The {@link DataItem} to convert. 15576a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * @param secondDataItem A second {@link DataItem} to help build a full entry for some 15586a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * mimetypes 1559eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return The {@link ExpandingEntryCardView.Entry}, or null if no visual elements are present. 1560eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 15616a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static Entry dataItemToEntry(DataItem dataItem, DataItem secondDataItem, 15626bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Context context, Contact contactData, 15636bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final MutableString aboutCardName) { 1564eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable icon = null; 1565eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String header = null; 1566eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String subHeader = null; 1567eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable subHeaderIcon = null; 1568eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String text = null; 1569eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable textIcon = null; 157023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos StringBuilder primaryContentDescription = new StringBuilder(); 1571b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang Spannable phoneContentDescription = null; 15725da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang Spannable smsContentDescription = null; 1573eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Intent intent = null; 157448ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos boolean shouldApplyColor = true; 1575dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Drawable alternateIcon = null; 1576dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Intent alternateIntent = null; 157723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos StringBuilder alternateContentDescription = new StringBuilder(); 1578eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEditable = false; 15792a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo entryContextMenuInfo = null; 158048fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos Drawable thirdIcon = null; 158148fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos Intent thirdIntent = null; 15825f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn int thirdAction = Entry.ACTION_NONE; 158348fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos String thirdContentDescription = null; 15845f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn Bundle thirdExtras = null; 158548290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos int iconResourceId = 0; 1586eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 15876bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell context = context.getApplicationContext(); 158823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos final Resources res = context.getResources(); 1589eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataKind kind = dataItem.getDataKind(); 1590eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1591eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItem instanceof ImDataItem) { 1592eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final ImDataItem im = (ImDataItem) dataItem; 15936bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell intent = ContactsUtils.buildImIntent(context, im).first; 1594eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEmail = im.isCreatedFromEmail(); 15957de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos final int protocol; 15967de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos if (!im.isProtocolValid()) { 15977de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos protocol = Im.PROTOCOL_CUSTOM; 15987de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } else { 15997de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol(); 16007de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } 16017de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos if (protocol == Im.PROTOCOL_CUSTOM) { 16027de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos // If the protocol is custom, display the "IM" entry header as well to distinguish 16037de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos // this entry from other ones 160423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_im_entry); 160523e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos subHeader = Im.getProtocolLabel(res, protocol, 16067de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos im.getCustomProtocol()).toString(); 16077de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos text = im.getData(); 16087de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } else { 160923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = Im.getProtocolLabel(res, protocol, 16107de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos im.getCustomProtocol()).toString(); 16117de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos subHeader = im.getData(); 16127de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } 161397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(im.getData(), header, 161497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1615eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof OrganizationDataItem) { 1616eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final OrganizationDataItem organization = (OrganizationDataItem) dataItem; 161723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_organization_entry); 1618eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = organization.getCompany(); 161997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 162097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1621eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = organization.getTitle(); 1622eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NicknameDataItem) { 1623eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NicknameDataItem nickname = (NicknameDataItem) dataItem; 1624eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Build nickname entries 1625eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isNameRawContact = 16266bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell (contactData.getNameRawContactId() == dataItem.getRawContactId()); 1627eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1628eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean duplicatesTitle = 1629eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos isNameRawContact 16306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell && contactData.getDisplayNameSource() == DisplayNameSources.NICKNAME; 1631eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1632eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!duplicatesTitle) { 163323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_nickname_entry); 1634eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = nickname.getName(); 163597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 163697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1637eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 16381bd8826c81eff79551c79c3042aca22a1d905524yaolu } else if (dataItem instanceof CustomDataItem) { 16391bd8826c81eff79551c79c3042aca22a1d905524yaolu final CustomDataItem customDataItem = (CustomDataItem) dataItem; 16401bd8826c81eff79551c79c3042aca22a1d905524yaolu final String summary = customDataItem.getSummary(); 16411bd8826c81eff79551c79c3042aca22a1d905524yaolu header = TextUtils.isEmpty(summary) 16421bd8826c81eff79551c79c3042aca22a1d905524yaolu ? res.getString(R.string.label_custom_field) : summary; 16431bd8826c81eff79551c79c3042aca22a1d905524yaolu subHeader = customDataItem.getContent(); 16441bd8826c81eff79551c79c3042aca22a1d905524yaolu entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 16451bd8826c81eff79551c79c3042aca22a1d905524yaolu dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1646eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NoteDataItem) { 1647eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NoteDataItem note = (NoteDataItem) dataItem; 164823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_note_entry); 1649eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = note.getNote(); 165097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 165197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1652eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof WebsiteDataItem) { 1653eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final WebsiteDataItem website = (WebsiteDataItem) dataItem; 165423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_website_entry); 1655eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = website.getUrl(); 165697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 165797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1658eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos try { 16593bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell final WebAddress webAddress = new WebAddress(website.buildDataStringForDisplay 16603bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell (context, kind)); 1661eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString())); 1662eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ParseException e) { 16633bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell Log.e(TAG, "Couldn't parse website: " + website.buildDataStringForDisplay( 16643bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell context, kind)); 1665eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1666eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EventDataItem) { 1667eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EventDataItem event = (EventDataItem) dataItem; 16683bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell final String dataString = event.buildDataStringForDisplay(context, kind); 1669eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Calendar cal = DateUtils.parseDate(dataString, false); 1670eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (cal != null) { 1671eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Date nextAnniversary = 1672eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DateUtils.getNextAnnualDate(cal); 1673eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); 1674eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos builder.appendPath("time"); 1675eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos ContentUris.appendId(builder, nextAnniversary.getTime()); 1676eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW).setData(builder.build()); 1677eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 167823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_event_entry); 1679f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (event.hasKindTypeColumn(kind)) { 1680c85af2872f231f48b586c30f6306083a039dd6c6Wenyi Wang subHeader = EventCompat.getTypeLabel(res, event.getKindTypeColumn(kind), 16817de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos event.getLabel()).toString(); 1682f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 16836bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell text = DateUtils.formatDate(context, dataString); 168497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(text, header, 168597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1686eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof RelationDataItem) { 1687eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final RelationDataItem relation = (RelationDataItem) dataItem; 16883bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell final String dataString = relation.buildDataStringForDisplay(context, kind); 1689eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(dataString)) { 1690eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SEARCH); 1691eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.putExtra(SearchManager.QUERY, dataString); 1692eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.setType(Contacts.CONTENT_TYPE); 1693eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 169423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_relation_entry); 1695eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = relation.getName(); 169697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 169797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1698f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (relation.hasKindTypeColumn(kind)) { 169923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = Relation.getTypeLabel(res, 17006bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell relation.getKindTypeColumn(kind), 1701f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos relation.getLabel()).toString(); 1702f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1703eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof PhoneDataItem) { 1704eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final PhoneDataItem phone = (PhoneDataItem) dataItem; 17055f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn String phoneLabel = null; 1706eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(phone.getNumber())) { 170723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(res.getString(R.string.call_other)).append(" "); 17083bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell header = sBidiFormatter.unicodeWrap(phone.buildDataStringForDisplay(context, kind), 1709c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwell TextDirectionHeuristics.LTR); 17102a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 171197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), 171297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getId(), dataItem.isSuperPrimary()); 1713f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (phone.hasKindTypeColumn(kind)) { 171401b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang final int kindTypeColumn = phone.getKindTypeColumn(kind); 171501b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang final String label = phone.getLabel(); 17165f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phoneLabel = label; 171701b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang if (kindTypeColumn == Phone.TYPE_CUSTOM && TextUtils.isEmpty(label)) { 171801b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang text = ""; 171901b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang } else { 172001b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang text = Phone.getTypeLabel(res, kindTypeColumn, label).toString(); 17215f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phoneLabel= text; 17223df785b0ad0c0292adfc03a4f804d1b38053de63Tingting Wang primaryContentDescription.append(text).append(" "); 17233df785b0ad0c0292adfc03a4f804d1b38053de63Tingting Wang } 1724f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 172523e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(header); 1726b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang phoneContentDescription = com.android.contacts.common.util.ContactDisplayUtils 1727b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang .getTelephoneTtsSpannable(primaryContentDescription.toString(), header); 172823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_phone_24dp); 172948290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos iconResourceId = R.drawable.ic_phone_24dp; 17306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (PhoneCapabilityTester.isPhone(context)) { 1731eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(phone.getNumber()); 173279525d024526e0f26b9dff40162b91f7c53f17a6yaolu intent.putExtra(EXTRA_ACTION_TYPE, ActionType.CALL); 173316339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1734dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIntent = new Intent(Intent.ACTION_SENDTO, 17351cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phone.getNumber(), null)); 173679525d024526e0f26b9dff40162b91f7c53f17a6yaolu alternateIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.SMS); 173748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos 17383133a53839e56e297ca44e5b756db5b607599600Walter Jang alternateIcon = res.getDrawable(R.drawable.ic_message_24dp_mirrored); 173923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.append(res.getString(R.string.sms_custom, header)); 17405da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang smsContentDescription = com.android.contacts.common.util.ContactDisplayUtils 17415da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang .getTelephoneTtsSpannable(alternateContentDescription.toString(), header); 174248fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos 17430a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn int videoCapability = CallUtil.getVideoCallingAvailability(context); 17440a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn boolean isPresenceEnabled = 17450a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn (videoCapability & CallUtil.VIDEO_CALLING_PRESENCE) != 0; 17460a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn boolean isVideoEnabled = (videoCapability & CallUtil.VIDEO_CALLING_ENABLED) != 0; 17470a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn 17485f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn if (CallUtil.isCallWithSubjectSupported(context)) { 17495f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdIcon = res.getDrawable(R.drawable.ic_call_note_white_24dp); 17505f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdAction = Entry.ACTION_CALL_WITH_SUBJECT; 17515f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdContentDescription = 17525f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn res.getString(R.string.call_with_a_note); 17535f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn // Create a bundle containing the data the call subject dialog requires. 17545f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras = new Bundle(); 17555f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putLong(CallSubjectDialog.ARG_PHOTO_ID, 17565f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn contactData.getPhotoId()); 17575f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putParcelable(CallSubjectDialog.ARG_PHOTO_URI, 17585f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn UriUtils.parseUriOrNull(contactData.getPhotoUri())); 17595f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putParcelable(CallSubjectDialog.ARG_CONTACT_URI, 17605f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn contactData.getLookupUri()); 17615f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putString(CallSubjectDialog.ARG_NAME_OR_NUMBER, 17625f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn contactData.getDisplayName()); 17635f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putBoolean(CallSubjectDialog.ARG_IS_BUSINESS, false); 17645f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putString(CallSubjectDialog.ARG_NUMBER, 17655f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phone.getNumber()); 17665f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putString(CallSubjectDialog.ARG_DISPLAY_NUMBER, 17675f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phone.getFormattedPhoneNumber()); 17685f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putString(CallSubjectDialog.ARG_NUMBER_LABEL, 17695f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phoneLabel); 17700a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn } else if (isVideoEnabled) { 17710a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn // Check to ensure carrier presence indicates the number supports video calling. 17720a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn int carrierPresence = dataItem.getCarrierPresence(); 17730a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn boolean isPresent = (carrierPresence & Phone.CARRIER_PRESENCE_VT_CAPABLE) != 0; 17740a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn 17750a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn if ((isPresenceEnabled && isPresent) || !isPresenceEnabled) { 17760a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn thirdIcon = res.getDrawable(R.drawable.ic_videocam); 17770a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn thirdAction = Entry.ACTION_INTENT; 17780a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn thirdIntent = CallUtil.getVideoCallIntent(phone.getNumber(), 17790a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY); 178079525d024526e0f26b9dff40162b91f7c53f17a6yaolu thirdIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.VIDEOCALL); 17810a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn thirdContentDescription = 17820a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn res.getString(R.string.description_video_call); 17830a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn } 178448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos } 1785eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1786eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EmailDataItem) { 1787eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EmailDataItem email = (EmailDataItem) dataItem; 1788eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String address = email.getData(); 1789eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(address)) { 179023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(res.getString(R.string.email_other)).append(" "); 17911cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner final Uri mailUri = Uri.fromParts(ContactsUtils.SCHEME_MAILTO, address, null); 1792eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SENDTO, mailUri); 179379525d024526e0f26b9dff40162b91f7c53f17a6yaolu intent.putExtra(EXTRA_ACTION_TYPE, ActionType.EMAIL); 1794eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = email.getAddress(); 17952a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 179697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos res.getString(R.string.emailLabelsGroup), dataItem.getMimeType(), 179797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getId(), dataItem.isSuperPrimary()); 1798f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (email.hasKindTypeColumn(kind)) { 179923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = Email.getTypeLabel(res, email.getKindTypeColumn(kind), 1800f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos email.getLabel()).toString(); 180123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(text).append(" "); 1802f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 180323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(header); 180423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_email_24dp); 180548290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos iconResourceId = R.drawable.ic_email_24dp; 1806eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1807eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredPostalDataItem) { 1808eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos StructuredPostalDataItem postal = (StructuredPostalDataItem) dataItem; 1809eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String postalAddress = postal.getFormattedAddress(); 1810eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(postalAddress)) { 181123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(res.getString(R.string.map_other)).append(" "); 1812eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress); 18137a09c70af86b9f3bae52c102ebfb6a32b99e7409yaolu intent.putExtra(EXTRA_ACTION_TYPE, ActionType.ADDRESS); 1814eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = postal.getFormattedAddress(); 18152a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 181697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos res.getString(R.string.postalLabelsGroup), dataItem.getMimeType(), 181797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getId(), dataItem.isSuperPrimary()); 1818f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (postal.hasKindTypeColumn(kind)) { 181923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = StructuredPostal.getTypeLabel(res, 1820f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos postal.getKindTypeColumn(kind), postal.getLabel()).toString(); 182123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(text).append(" "); 1822f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 182323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(header); 18246a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos alternateIntent = 18256a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos StructuredPostalUtils.getViewPostalAddressDirectionsIntent(postalAddress); 182679525d024526e0f26b9dff40162b91f7c53f17a6yaolu alternateIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.DIRECTIONS); 182723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateIcon = res.getDrawable(R.drawable.ic_directions_24dp); 182823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.append(res.getString( 182923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos R.string.content_description_directions)).append(" ").append(header); 183023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_place_24dp); 183148290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos iconResourceId = R.drawable.ic_place_24dp; 1832eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1833eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof SipAddressDataItem) { 1834593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell final SipAddressDataItem sip = (SipAddressDataItem) dataItem; 1835593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell final String address = sip.getSipAddress(); 1836593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell if (!TextUtils.isEmpty(address)) { 1837593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell primaryContentDescription.append(res.getString(R.string.call_other)).append( 1838593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell " "); 1839593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell if (PhoneCapabilityTester.isSipPhone(context)) { 18401cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner final Uri callUri = Uri.fromParts(PhoneAccount.SCHEME_SIP, address, null); 1841eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(callUri); 184279525d024526e0f26b9dff40162b91f7c53f17a6yaolu intent.putExtra(EXTRA_ACTION_TYPE, ActionType.SIPCALL); 184316339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1844593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell header = address; 1845593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell entryContextMenuInfo = new EntryContextMenuInfo(header, 1846593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), 1847593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell dataItem.getId(), dataItem.isSuperPrimary()); 1848593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell if (sip.hasKindTypeColumn(kind)) { 1849593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell text = SipAddress.getTypeLabel(res, 1850593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell sip.getKindTypeColumn(kind), sip.getLabel()).toString(); 1851593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell primaryContentDescription.append(text).append(" "); 1852593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell } 1853593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell primaryContentDescription.append(header); 1854593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell icon = res.getDrawable(R.drawable.ic_dialer_sip_black_24dp); 1855593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell iconResourceId = R.drawable.ic_dialer_sip_black_24dp; 1856edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1857eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredNameDataItem) { 18588025f801f5153917781a9496cabdd81ae1b6deafWalter Jang // If the name is already set and this is not the super primary value then leave the 18598025f801f5153917781a9496cabdd81ae1b6deafWalter Jang // current value. This way we show the super primary value when we are able to. 18608025f801f5153917781a9496cabdd81ae1b6deafWalter Jang if (dataItem.isSuperPrimary() || aboutCardName.value == null 18618025f801f5153917781a9496cabdd81ae1b6deafWalter Jang || aboutCardName.value.isEmpty()) { 18628025f801f5153917781a9496cabdd81ae1b6deafWalter Jang final String givenName = ((StructuredNameDataItem) dataItem).getGivenName(); 18638025f801f5153917781a9496cabdd81ae1b6deafWalter Jang if (!TextUtils.isEmpty(givenName)) { 18648025f801f5153917781a9496cabdd81ae1b6deafWalter Jang aboutCardName.value = res.getString(R.string.about_card_title) + 18658025f801f5153917781a9496cabdd81ae1b6deafWalter Jang " " + givenName; 18668025f801f5153917781a9496cabdd81ae1b6deafWalter Jang } else { 18678025f801f5153917781a9496cabdd81ae1b6deafWalter Jang aboutCardName.value = res.getString(R.string.about_card_title); 18688025f801f5153917781a9496cabdd81ae1b6deafWalter Jang } 1869eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1870eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1871eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Custom DataItem 18726bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = dataItem.buildDataStringForDisplay(context, kind); 1873eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = kind.typeColumn; 1874eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW); 187560e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, dataItem.getId()); 187660e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos intent.setDataAndType(uri, dataItem.getMimeType()); 187779525d024526e0f26b9dff40162b91f7c53f17a6yaolu intent.putExtra(EXTRA_ACTION_TYPE, ActionType.THIRD_PARTY); 1878a92b2d193ddab97597334075a824a3575d71cb8ayaolu intent.putExtra(EXTRA_THIRD_PARTY_ACTION, dataItem.getMimeType()); 1879e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 1880e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (intent != null) { 1881e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos final String mimetype = intent.getType(); 1882e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 18836a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Build advanced entry for known 3p types. Otherwise default to ResolveCache icon. 18848c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu if (MIMETYPE_HANGOUTS.equals(mimetype)) { 18858c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu // If a secondDataItem is available, use it to build an entry with 18868c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu // alternate actions 18878c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu if (secondDataItem != null) { 18888c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu icon = res.getDrawable(R.drawable.ic_hangout_24dp); 18898c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu alternateIcon = res.getDrawable(R.drawable.ic_hangout_video_24dp); 18908c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu final HangoutsDataItemModel itemModel = 18918c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu new HangoutsDataItemModel(intent, alternateIntent, 18928c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu dataItem, secondDataItem, alternateContentDescription, 18938c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu header, text, context); 18948c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu 18958c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu populateHangoutsDataItemModel(itemModel); 18968c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu intent = itemModel.intent; 18978c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu alternateIntent = itemModel.alternateIntent; 18988c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu alternateContentDescription = itemModel.alternateContentDescription; 18998c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu header = itemModel.header; 19008c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu text = itemModel.text; 19018c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu } else { 19028c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu if (HANGOUTS_DATA_5_VIDEO.equals(intent.getDataString())) { 19038c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu icon = res.getDrawable(R.drawable.ic_hangout_video_24dp); 19046a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 19058c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu icon = res.getDrawable(R.drawable.ic_hangout_24dp); 1906e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 19078c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu } 19088c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu } else { 19098c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu icon = ResolveCache.getInstance(context).getIcon( 19108c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu dataItem.getMimeType(), intent); 19118c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu // Call mutate to create a new Drawable.ConstantState for color filtering 19128c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu if (icon != null) { 19138c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu icon.mutate(); 19148c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu } 19158c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu shouldApplyColor = false; 19168c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu 19178c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu if (!MIMETYPE_GPLUS_PROFILE.equals(mimetype)) { 191897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, mimetype, 191997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), 192097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.isSuperPrimary()); 19218c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu } 1922e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1923e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1924eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1925b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1926eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (intent != null) { 1927eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Do not set the intent is there are no resolves 19286bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!PhoneCapabilityTester.isIntentRegistered(context, intent)) { 1929eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = null; 1930eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1931eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1932eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1933dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (alternateIntent != null) { 1934dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Do not set the alternate intent is there are no resolves 19356bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!PhoneCapabilityTester.isIntentRegistered(context, alternateIntent)) { 1936dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIntent = null; 1937f0d04c11b649e953177e79722d05fa048e53273dJay Shrauner } else if (TextUtils.isEmpty(alternateContentDescription)) { 1938f0d04c11b649e953177e79722d05fa048e53273dJay Shrauner // Attempt to use package manager to find a suitable content description if needed 193923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.append(getIntentResolveLabel(alternateIntent, context)); 1940dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1941dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1942dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1943eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // If the Entry has no visual elements, return null 1944eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) && 1945eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeaderIcon == null && TextUtils.isEmpty(text) && textIcon == null) { 1946eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return null; 1947eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1948eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1949fa238949855fba3b28a57fad3d585b13e80362bbBrian Attwell // Ignore dataIds from the Me profile. 1950ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final int dataId = dataItem.getId() > Integer.MAX_VALUE ? 1951ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos -1 : (int) dataItem.getId(); 1952ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 195323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon, 1954b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang phoneContentDescription == null 1955b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang ? new SpannableString(primaryContentDescription.toString()) 1956b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang : phoneContentDescription, 19577ce5352a70e8aaf120bf4f7bd05d595f46abb080Walter Jang intent, alternateIcon, alternateIntent, 19585da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang smsContentDescription == null 19595da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang ? new SpannableString(alternateContentDescription.toString()) 19605da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang : smsContentDescription, 19615da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang shouldApplyColor, isEditable, 19625f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn entryContextMenuInfo, thirdIcon, thirdIntent, thirdContentDescription, thirdAction, 19635f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras, iconResourceId); 1964eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1965eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 19666bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private List<Entry> dataItemsToEntries(List<DataItem> dataItems, 19676bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell MutableString aboutCardTitleOut) { 19686a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Hangouts and G+ use two data items to create one entry. 19693904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu if (dataItems.get(0).getMimeType().equals(MIMETYPE_GPLUS_PROFILE)) { 19703904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu return gPlusDataItemsToEntries(dataItems); 19713904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } else if (dataItems.get(0).getMimeType().equals(MIMETYPE_HANGOUTS)) { 19723904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu return hangoutsDataItemsToEntries(dataItems); 19736a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 19746a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final List<Entry> entries = new ArrayList<>(); 19756a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos for (DataItem dataItem : dataItems) { 19766a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, 19776a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this, mContactData, aboutCardTitleOut); 19786a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (entry != null) { 19796a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos entries.add(entry); 19806a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 19816a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 19826a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos return entries; 19836a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 19846a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 19856a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 19866a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /** 19873904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * Put the data items into buckets based on the raw contact id 19886a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos */ 19893904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu private Map<Long, List<DataItem>> dataItemsToBucket(List<DataItem> dataItems) { 19906a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Map<Long, List<DataItem>> buckets = new HashMap<>(); 1991eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (DataItem dataItem : dataItems) { 19926a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos List<DataItem> bucket = buckets.get(dataItem.getRawContactId()); 19936a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (bucket == null) { 19946a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos bucket = new ArrayList<>(); 19956a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos buckets.put(dataItem.getRawContactId(), bucket); 19966a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 19976a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos bucket.add(dataItem); 19986a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 19993904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu return buckets; 20003904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } 20013904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu 20023904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu /** 20033904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * For G+ entries, a single ExpandingEntryCardView.Entry consists of two data items. This 20043904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * method use only the View profile to build entry. 20053904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu */ 20063904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu private List<Entry> gPlusDataItemsToEntries(List<DataItem> dataItems) { 20073904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu final List<Entry> entries = new ArrayList<>(); 20083904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu 20093904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu for (List<DataItem> bucket : dataItemsToBucket(dataItems).values()) { 20103904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu for (DataItem dataItem : bucket) { 20113904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu if (GPLUS_PROFILE_DATA_5_VIEW_PROFILE.equals( 20123904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu dataItem.getContentValues().getAsString(Data.DATA5))) { 20133904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, 20143904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu this, mContactData, /* aboutCardName = */ null); 20153904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu if (entry != null) { 20163904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu entries.add(entry); 20173904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } 20183904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } 20193904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } 20203904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } 20213904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu return entries; 20223904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } 20233904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu 20243904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu /** 20253904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * For Hangouts entries, a single ExpandingEntryCardView.Entry consists of two data items. This 20263904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * method attempts to build each entry using the two data items if they are available. If there 20273904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * are more or less than two data items, a fall back is used and each data item gets its own 20283904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * entry. 20293904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu */ 20303904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu private List<Entry> hangoutsDataItemsToEntries(List<DataItem> dataItems) { 20313904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu final List<Entry> entries = new ArrayList<>(); 20326a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 20336a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Use the buckets to build entries. If a bucket contains two data items, build the special 20346a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // entry, otherwise fall back to the normal entry. 20353904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu for (List<DataItem> bucket : dataItemsToBucket(dataItems).values()) { 20366a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (bucket.size() == 2) { 20376a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Use the pair to build an entry 20386a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Entry entry = dataItemToEntry(bucket.get(0), 20396a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /* secondDataItem = */ bucket.get(1), this, mContactData, 20406a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /* aboutCardName = */ null); 20416a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (entry != null) { 20426a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos entries.add(entry); 20436a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 20446a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 20456a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos for (DataItem dataItem : bucket) { 20466a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, 20476a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this, mContactData, /* aboutCardName = */ null); 20486a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (entry != null) { 20496a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos entries.add(entry); 20506a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 20516a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 2052eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 2053eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 2054eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return entries; 2055edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 2056edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 20576a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /** 20583904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * Used for statically passing around Hangouts data items and entry fields to 20593904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * populateHangoutsDataItemModel. 20606a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos */ 20613904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu private static final class HangoutsDataItemModel { 20626a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public Intent intent; 20636a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public Intent alternateIntent; 20646a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public DataItem dataItem; 20656a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public DataItem secondDataItem; 20666a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public StringBuilder alternateContentDescription; 20676a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public String header; 20686a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public String text; 20696a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public Context context; 20706a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 20713904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu public HangoutsDataItemModel(Intent intent, Intent alternateIntent, DataItem dataItem, 20726a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos DataItem secondDataItem, StringBuilder alternateContentDescription, String header, 20736a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos String text, Context context) { 20746a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.intent = intent; 20756a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.alternateIntent = alternateIntent; 20766a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.dataItem = dataItem; 20776a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.secondDataItem = secondDataItem; 20786a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.alternateContentDescription = alternateContentDescription; 20796a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.header = header; 20806a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.text = text; 20816a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.context = context; 20826a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 20836a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 20846a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 20853904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu private static void populateHangoutsDataItemModel( 20863904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu HangoutsDataItemModel dataModel) { 20876a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Intent secondIntent = new Intent(Intent.ACTION_VIEW); 20886a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos secondIntent.setDataAndType(ContentUris.withAppendedId(Data.CONTENT_URI, 20896a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.getId()), dataModel.secondDataItem.getMimeType()); 209079525d024526e0f26b9dff40162b91f7c53f17a6yaolu secondIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.THIRD_PARTY); 2091a92b2d193ddab97597334075a824a3575d71cb8ayaolu secondIntent.putExtra(EXTRA_THIRD_PARTY_ACTION, dataModel.secondDataItem.getMimeType()); 209279525d024526e0f26b9dff40162b91f7c53f17a6yaolu 20936a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // There is no guarantee the order the data items come in. Second 20946a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // data item does not necessarily mean it's the alternate. 20953904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu // Hangouts video should be alternate. Swap if needed 20966a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (HANGOUTS_DATA_5_VIDEO.equals( 20973904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu dataModel.dataItem.getContentValues().getAsString(Data.DATA5))) { 20986a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateIntent = dataModel.intent; 20996a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateContentDescription = new StringBuilder(dataModel.header); 21006a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 21016a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.intent = secondIntent; 2102a92b2d193ddab97597334075a824a3575d71cb8ayaolu dataModel.header = dataModel.secondDataItem.buildDataStringForDisplay( 2103a92b2d193ddab97597334075a824a3575d71cb8ayaolu dataModel.context, dataModel.secondDataItem.getDataKind()); 21046a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.text = dataModel.secondDataItem.getDataKind().typeColumn; 21056a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else if (HANGOUTS_DATA_5_MESSAGE.equals( 21063904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu dataModel.dataItem.getContentValues().getAsString(Data.DATA5))) { 21076a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateIntent = secondIntent; 21086a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateContentDescription = new StringBuilder( 21096a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.buildDataStringForDisplay(dataModel.context, 21106a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.getDataKind())); 21116a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21126a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21136a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 21146bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static String getIntentResolveLabel(Intent intent, Context context) { 21156bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, 2116dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos PackageManager.MATCH_DEFAULT_ONLY); 2117dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 2118dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Pick first match, otherwise best found 2119dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos ResolveInfo bestResolve = null; 2120dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos final int size = matches.size(); 2121dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (size == 1) { 2122dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos bestResolve = matches.get(0); 2123dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } else if (size > 1) { 21246bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell bestResolve = ResolveCache.getInstance(context).getBestResolve(intent, matches); 2125dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 2126dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 2127dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (bestResolve == null) { 2128dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos return null; 2129dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 2130dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 21316bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell return String.valueOf(bestResolve.loadLabel(context.getPackageManager())); 2132dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 2133dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 2134edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 213531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * Asynchronously extract the most vibrant color from the PhotoView. Once extracted, 213631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms 213731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * on a Nexus 5. 213831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell */ 213931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell private void extractAndApplyTintFromPhotoViewAsynchronously() { 214031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell if (mScroller == null) { 214131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell return; 214231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 214331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell final Drawable imageViewDrawable = mPhotoView.getDrawable(); 2144faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell new AsyncTask<Void, Void, MaterialPalette>() { 214531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 2146faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell protected MaterialPalette doInBackground(Void... params) { 2147faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell 2148929a62f5c1bcdc3773270f7d189d88c0464b36adJay Shrauner if (imageViewDrawable instanceof BitmapDrawable && mContactData != null 214995c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell && mContactData.getThumbnailPhotoBinaryData() != null 215095c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell && mContactData.getThumbnailPhotoBinaryData().length > 0) { 215195c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell // Perform the color analysis on the thumbnail instead of the full sized 215295c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell // image, so that our results will be as similar as possible to the Bugle 215395c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell // app. 215495c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell final Bitmap bitmap = BitmapFactory.decodeByteArray( 215595c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell mContactData.getThumbnailPhotoBinaryData(), 0, 215695c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell mContactData.getThumbnailPhotoBinaryData().length); 215795c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell try { 215895c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell final int primaryColor = colorFromBitmap(bitmap); 215995c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell if (primaryColor != 0) { 216095c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor( 216195c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell primaryColor); 216295c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell } 216395c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell } finally { 216495c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell bitmap.recycle(); 2165faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell } 21668a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 21678a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (imageViewDrawable instanceof LetterTileDrawable) { 2168faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell final int primaryColor = ((LetterTileDrawable) imageViewDrawable).getColor(); 2169a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(primaryColor); 217031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 2171a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return MaterialColorMapUtils.getDefaultPrimaryAndSecondaryColors(getResources()); 217231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 217331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 217431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 2175faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell protected void onPostExecute(MaterialPalette palette) { 2176faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell super.onPostExecute(palette); 21778571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (mHasComputedThemeColor) { 21788571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // If we had previously computed a theme color from the contact photo, 21798571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // then do not update the theme color. Changing the theme color several 21808571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // seconds after QC has started, as a result of an updated/upgraded photo, 21818571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // is a jarring experience. On the other hand, changing the theme color after 21828571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // a rotation or onNewIntent() is perfectly fine. 21838571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell return; 21848571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell } 21858571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // Check that the Photo has not changed. If it has changed, the new tint 21868571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // color needs to be extracted 21878571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (imageViewDrawable == mPhotoView.getDrawable()) { 21888571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = true; 2189faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell setThemeColor(palette); 219031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 219131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 219231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell }.execute(); 219331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 219431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 2195faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell private void setThemeColor(MaterialPalette palette) { 21969b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // If the color is invalid, use the predefined default 21978e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mColorFilterColor = palette.mPrimaryColor; 21988e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mScroller.setHeaderTintColor(mColorFilterColor); 2199faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mStatusBarColor = palette.mSecondaryColor; 22009b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell updateStatusBarColor(); 22018571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell 22029b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mColorFilter = 22038e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell new PorterDuffColorFilter(mColorFilterColor, PorterDuff.Mode.SRC_ATOP); 22048e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mContactCard.setColorAndFilter(mColorFilterColor, mColorFilter); 22058e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mRecentCard.setColorAndFilter(mColorFilterColor, mColorFilter); 22068e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mAboutCard.setColorAndFilter(mColorFilterColor, mColorFilter); 22079b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 22089b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 22098a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void updateStatusBarColor() { 22104c3d3e24b0de8b4170106e312f6a4ac8139e1242Wenyi Wang if (mScroller == null || !CompatUtils.isLollipopCompatible()) { 22118a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 22128a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 22138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int desiredStatusBarColor; 22148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Only use a custom status bar color if QuickContacts touches the top of the viewport. 22158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller.getScrollNeededToBeFullScreen() <= 0) { 22168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = mStatusBarColor; 22178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } else { 22188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = Color.TRANSPARENT; 22198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 22208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Animate to the new color. 2221847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor", 2222847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell getWindow().getStatusBarColor(), desiredStatusBarColor); 2223847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION); 2224847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.setEvaluator(new ArgbEvaluator()); 2225847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.start(); 22268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 22278a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 22288a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int colorFromBitmap(Bitmap bitmap) { 22298a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Author of Palette recommends using 24 colors when analyzing profile photos. 22308a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int NUMBER_OF_PALETTE_COLORS = 24; 22318a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final Palette palette = Palette.generate(bitmap, NUMBER_OF_PALETTE_COLORS); 2232a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell if (palette != null && palette.getVibrantSwatch() != null) { 2233a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell return palette.getVibrantSwatch().getRgb(); 22348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 22358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return 0; 22368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 22378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 2238b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) { 2239eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> entries = new ArrayList<>(); 2240b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos for (ContactInteraction interaction : interactions) { 2241ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (interaction == null) { 2242ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell continue; 2243ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2244ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos entries.add(new Entry(/* id = */ -1, 2245ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos interaction.getIcon(this), 2246b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewHeader(this), 2247b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewBody(this), 2248b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getBodyIcon(this), 2249b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewFooter(this), 2250b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getFooterIcon(this), 225123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos interaction.getContentDescription(this), 2252b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getIntent(), 2253dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIcon = */ null, 2254dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIntent = */ null, 2255dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateContentDescription = */ null, 225648ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos /* shouldApplyColor = */ true, 22572a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, 225848fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* EntryContextMenuInfo = */ null, 225948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, 226048fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIntent = */ null, 226148290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos /* thirdContentDescription = */ null, 22625f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdAction = */ Entry.ACTION_NONE, 22635f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdActionExtras = */ null, 226448290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos interaction.getIconResourceId())); 2265b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2266b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return entries; 2267b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2268b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2269eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<Contact> mLoaderContactCallbacks = 2270851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu new LoaderCallbacks<Contact>() { 2271cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 2272851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoaderReset(Loader<Contact> loader) { 2273405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos mContactData = null; 2274cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2275cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2276cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 2277851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoadFinished(Loader<Contact> loader, Contact data) { 22788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onLoadFinished()"); 2279930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell try { 22808a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 2281930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell if (isFinishing()) { 2282930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell return; 2283930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } 2284930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell if (data.isError()) { 228502ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner // This means either the contact is invalid or we had an 228602ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner // internal error such as an acore crash. 228702ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner Log.i(TAG, "Failed to load contact: " + ((ContactLoader)loader).getLookupUri()); 228802ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, 228902ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner Toast.LENGTH_LONG).show(); 229002ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner finish(); 229102ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner return; 2292930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } 2293930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell if (data.isNotFound()) { 22948a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri()); 22958a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, 22968a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.LENGTH_LONG).show(); 2297930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell finish(); 2298930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell return; 22998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 2300cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2301677ee2bd9c37f3bc4cbfd1f05b3c93f12a7299f3Marcus Hagerott if (!mIsRecreatedInstance && !mShortcutUsageReported && data != null) { 2302d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerott mShortcutUsageReported = true; 2303d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerott DynamicShortcuts.reportShortcutUsed(QuickContactActivity.this, 2304d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerott data.getLookupKey()); 2305d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerott } 2306930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell bindContactData(data); 2307cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2308930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } finally { 2309930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell Trace.endSection(); 2310930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } 2311cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2312cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2313cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 2314851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public Loader<Contact> onCreateLoader(int id, Bundle args) { 2315cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (mLookupUri == null) { 2316cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann Log.wtf(TAG, "Lookup uri wasn't initialized. Loader was started too early"); 2317cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2318d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Load all contact data. We need loadGroupMetaData=true to determine whether the 2319d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // contact is invisible. If it is, we need to display an "Add to Contacts" MenuItem. 2320b2b435a944947fbf1965c3bb7c202a97f0273259Yorke Lee return new ContactLoader(getApplicationContext(), mLookupUri, 2321d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell true /*loadGroupMetaData*/, false /*loadInvitableAccountTypes*/, 23228571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell true /*postViewNotification*/, true /*computeFormattedPhoneNumber*/); 2323cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2324cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann }; 2325b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2326b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 2327b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onBackPressed() { 2328ac9596e825bf8256487d836a266862e79a24206dTingting Wang final int previousScreenType = getIntent().getIntExtra 2329ac9596e825bf8256487d836a266862e79a24206dTingting Wang (EXTRA_PREVIOUS_SCREEN_TYPE, ScreenType.UNKNOWN); 2330ac9596e825bf8256487d836a266862e79a24206dTingting Wang if ((previousScreenType == ScreenType.ALL_CONTACTS 2331ac9596e825bf8256487d836a266862e79a24206dTingting Wang || previousScreenType == ScreenType.FAVORITES) 2332ac9596e825bf8256487d836a266862e79a24206dTingting Wang && !SharedPreferenceUtil.getHamburgerPromoTriggerActionHappenedBefore(this)) { 2333ac9596e825bf8256487d836a266862e79a24206dTingting Wang SharedPreferenceUtil.setHamburgerPromoTriggerActionHappenedBefore(this); 2334ac9596e825bf8256487d836a266862e79a24206dTingting Wang } 2335b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell if (mScroller != null) { 23368477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell if (!mIsExitAnimationInProgress) { 23378477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mScroller.scrollOffBottom(); 23388477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 2339b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } else { 2340b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell super.onBackPressed(); 2341b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 2342b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 2343b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 23448a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 23458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void finish() { 23468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.finish(); 23478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 23488a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // override transitions to skip the standard window animations 23498a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell overridePendingTransition(0, 0); 23508a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 23518a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 2352eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<List<ContactInteraction>> mLoaderInteractionsCallbacks = 2353b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos new LoaderCallbacks<List<ContactInteraction>>() { 2354b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2355b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 2356b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public Loader<List<ContactInteraction>> onCreateLoader(int id, Bundle args) { 2357b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Loader<List<ContactInteraction>> loader = null; 2358b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos switch (id) { 2359b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos case LOADER_SMS_ID: 2360b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos loader = new SmsInteractionsLoader( 2361b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos QuickContactActivity.this, 2362ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 2363b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos MAX_SMS_RETRIEVE); 2364b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos break; 2365899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos case LOADER_CALENDAR_ID: 2366ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos final String[] emailsArray = args.getStringArray(KEY_LOADER_EXTRA_EMAILS); 2367ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos List<String> emailsList = null; 2368ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos if (emailsArray != null) { 2369ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos emailsList = Arrays.asList(args.getStringArray(KEY_LOADER_EXTRA_EMAILS)); 2370ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos } 2371899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos loader = new CalendarInteractionsLoader( 2372899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos QuickContactActivity.this, 2373ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos emailsList, 2374899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_FUTURE_CALENDAR_RETRIEVE, 2375899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_PAST_CALENDAR_RETRIEVE, 2376899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR, 2377899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR); 2378899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos break; 2379ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos case LOADER_CALL_LOG_ID: 2380ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos loader = new CallLogInteractionsLoader( 2381ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.this, 2382ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 2383c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu args.getStringArray(KEY_LOADER_EXTRA_SIP_NUMBERS), 2384ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos MAX_CALL_LOG_RETRIEVE); 2385b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2386b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return loader; 2387b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2388b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2389b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 2390b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoadFinished(Loader<List<ContactInteraction>> loader, 2391b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos List<ContactInteraction> data) { 2392b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.put(loader.getId(), data); 2393b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2394b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos if (isAllRecentDataLoaded()) { 2395b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos bindRecentData(); 2396b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2397b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2398b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2399b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 2400b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoaderReset(Loader<List<ContactInteraction>> loader) { 2401b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.remove(loader.getId()); 2402b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2403b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos }; 2404b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2405b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private boolean isAllRecentDataLoaded() { 2406b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return mRecentLoaderResults.size() == mRecentLoaderIds.length; 2407b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2408b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2409b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private void bindRecentData() { 2410eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<ContactInteraction> allInteractions = new ArrayList<>(); 241130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell final List<List<Entry>> interactionsWrapper = new ArrayList<>(); 2412b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2413ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell // Serialize mRecentLoaderResults into a single list. This should be done on the main 2414ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell // thread to avoid races against mRecentLoaderResults edits. 2415ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) { 2416ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell allInteractions.addAll(loaderInteractions); 2417ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2418ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell 241930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask = new AsyncTask<Void, Void, Void>() { 2420b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 242130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell protected Void doInBackground(Void... params) { 242230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.beginSection("sort recent loader results"); 242330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 242430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // Sort the interactions by most recent 242530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Collections.sort(allInteractions, new Comparator<ContactInteraction>() { 242630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell @Override 242730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell public int compare(ContactInteraction a, ContactInteraction b) { 2428ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a == null && b == null) { 2429ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 0; 2430ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2431ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a == null) { 2432ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 1; 2433ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2434ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (b == null) { 2435ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return -1; 2436ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2437ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a.getInteractionDate() > b.getInteractionDate()) { 2438ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return -1; 2439ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2440ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a.getInteractionDate() == b.getInteractionDate()) { 2441ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 0; 2442ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2443ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 1; 244430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 244530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell }); 244630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 244730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.endSection(); 244830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.beginSection("contactInteractionsToEntries"); 244930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 245030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // Wrap each interaction in its own list so that an icon is displayed for each entry 245130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell for (Entry contactInteraction : contactInteractionsToEntries(allInteractions)) { 245230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell List<Entry> entryListWrapper = new ArrayList<>(1); 245330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell entryListWrapper.add(contactInteraction); 245430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell interactionsWrapper.add(entryListWrapper); 245530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 245630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 245730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.endSection(); 245830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell return null; 2459b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 246030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 246130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell @Override 246230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell protected void onPostExecute(Void aVoid) { 246330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell super.onPostExecute(aVoid); 246430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.beginSection("initialize recents card"); 246530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 246630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell if (allInteractions.size() > 0) { 246730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentCard.initialize(interactionsWrapper, 2468b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN, 2469c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos /* isExpanded = */ mRecentCard.isExpanded(), /* isAlwaysExpanded = */ false, 247030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mExpandingEntryCardViewListener, mScroller); 247179525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mRecentCard.getVisibility() == View.GONE && mShouldLog) { 247279525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.RECENT, 247379525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); 247479525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 247530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentCard.setVisibility(View.VISIBLE); 247638fa285d8a1f24182bc279dfcced595b4b5c4d68yaolu } else { 247738fa285d8a1f24182bc279dfcced595b4b5c4d68yaolu mRecentCard.setVisibility(View.GONE); 247830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 2479eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 248030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.endSection(); 248104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu Trace.beginSection("initialize permission explanation card"); 248204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 24838e56edfe8ac14879e40825cc10a73a9e2626803dguanxiongliu final Drawable historyIcon = VectorDrawableCompat.create( 24848e56edfe8ac14879e40825cc10a73a9e2626803dguanxiongliu getResources(), R.drawable.ic_history_24dp, null); 24858e56edfe8ac14879e40825cc10a73a9e2626803dguanxiongliu 248604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final Entry permissionExplanationEntry = new Entry(CARD_ENTRY_ID_REQUEST_PERMISSION, 248704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu historyIcon, getString(R.string.permission_explanation_header), 248804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCardSubHeader, /* subHeaderIcon = */ null, 248904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* text = */ null, /* textIcon = */ null, 249004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* primaryContentDescription = */ null, getIntent(), 249104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* alternateIcon = */ null, /* alternateIntent = */ null, 249204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* alternateContentDescription = */ null, /* shouldApplyColor = */ true, 249304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* isEditable = */ false, /* EntryContextMenuInfo = */ null, 249404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* thirdIcon = */ null, /* thirdIntent = */ null, 249504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* thirdContentDescription = */ null, /* thirdAction = */ Entry.ACTION_NONE, 249604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* thirdExtras = */ null, R.drawable.ic_history_24dp); 249704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 249804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final List<List<Entry>> permissionExplanationEntries = new ArrayList<>(); 249904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu permissionExplanationEntries.add(new ArrayList<Entry>()); 250004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu permissionExplanationEntries.get(0).add(permissionExplanationEntry); 250104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 250204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final int subHeaderTextColor = getResources().getColor(android.R.color.white); 250304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final PorterDuffColorFilter whiteColorFilter = 250404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu new PorterDuffColorFilter(subHeaderTextColor, PorterDuff.Mode.SRC_ATOP); 250504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 250604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.initialize(permissionExplanationEntries, 250704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* numInitialVisibleEntries = */ 1, 250804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* isExpanded = */ true, 250904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* isAlwaysExpanded = */ true, 251004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* listener = */ null, 251104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mScroller); 251204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 251304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setColorAndFilter(subHeaderTextColor, whiteColorFilter); 251404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setBackgroundColor(mColorFilterColor); 251504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setEntryHeaderColor(subHeaderTextColor); 251604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setEntrySubHeaderColor(subHeaderTextColor); 251704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 251804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu if (mShouldShowPermissionExplanation) { 251979525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mPermissionExplanationCard.getVisibility() == View.GONE 252079525d024526e0f26b9dff40162b91f7c53f17a6yaolu && mShouldLog) { 252179525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.PERMISSION, 252279525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); 252379525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 252404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setVisibility(View.VISIBLE); 252504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu } else { 252604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setVisibility(View.GONE); 252704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu } 252804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 252904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu Trace.endSection(); 253030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 253130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // About card is initialized along with the contact card, but since it appears after 253230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // the recent card in the UI, we hold off until making it visible until the recent 253330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // card is also ready to avoid stuttering. 253430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell if (mAboutCard.shouldShow()) { 253530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mAboutCard.setVisibility(View.VISIBLE); 253630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } else { 253730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mAboutCard.setVisibility(View.GONE); 253830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 253930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask = null; 254030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 254130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell }; 254230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask.execute(); 2543b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 25448a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 25458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 25468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onStop() { 25478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onStop(); 25488a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 25498a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mEntriesAndActionsTask != null) { 25508a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Once the activity is stopped, we will no longer want to bind mEntriesAndActionsTask's 25518a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // results on the UI thread. In some circumstances Activities are killed without 25528a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // onStop() being called. This is not a problem, because in these circumstances 25538a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the entire process will be killed. 25548a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.cancel(/* mayInterruptIfRunning = */ false); 25558a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 255630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell if (mRecentDataTask != null) { 255730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask.cancel(/* mayInterruptIfRunning = */ false); 255830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 25598a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 256023889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos 2561e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang @Override 2562e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang public void onDestroy() { 2563e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang super.onDestroy(); 2564e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 2565e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 256623889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos /** 2567d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Returns true if it is possible to edit the current contact. 2568d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 2569d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private boolean isContactEditable() { 2570d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 2571d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2572d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2573a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell /** 2574a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell * Returns true if it is possible to share the current contact. 2575a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell */ 2576a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell private boolean isContactShareable() { 2577a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 2578a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell } 2579a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 25806095369885edcca566a812b551886e29c7ff8039Brian Attwell private Intent getEditContactIntent() { 2581363af60ea23e5a3b945005712a16564ab69db18bGary Mai return EditorIntents.createEditContactIntent(QuickContactActivity.this, 25821e8801bc9bc60bdd1c95f582c460590272cfad64Walter Jang mContactData.getLookupUri(), 25831e8801bc9bc60bdd1c95f582c460590272cfad64Walter Jang mHasComputedThemeColor 25841e8801bc9bc60bdd1c95f582c460590272cfad64Walter Jang ? new MaterialPalette(mColorFilterColor, mStatusBarColor) : null, 2585c41a1e5f5f4872c3a0da5dec7671b66d9d80eb4eWenyi Wang mContactData.getPhotoId()); 25866095369885edcca566a812b551886e29c7ff8039Brian Attwell } 25876095369885edcca566a812b551886e29c7ff8039Brian Attwell 25886095369885edcca566a812b551886e29c7ff8039Brian Attwell private void editContact() { 2589a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 2590c00a0b5370f0714f6af1ea9b3e29b10f25e91af0Zheng Fu mContactLoader.cacheResult(); 25916095369885edcca566a812b551886e29c7ff8039Brian Attwell startActivityForResult(getEditContactIntent(), REQUEST_CODE_CONTACT_EDITOR_ACTIVITY); 2592d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2593d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 25945d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang private void deleteContact() { 25955d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang final Uri contactUri = mContactData.getLookupUri(); 25965d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang ContactDeletionInteraction.start(this, contactUri, /* finishActivityWhenDone =*/ true); 25975d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang } 25985d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang 259979525d024526e0f26b9dff40162b91f7c53f17a6yaolu private void toggleStar(MenuItem starredMenuItem, boolean isStarred) { 260079525d024526e0f26b9dff40162b91f7c53f17a6yaolu // To improve responsiveness, swap out the picture (and tag) in the UI already 260179525d024526e0f26b9dff40162b91f7c53f17a6yaolu ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, 260279525d024526e0f26b9dff40162b91f7c53f17a6yaolu mContactData.isDirectoryEntry(), mContactData.isUserProfile(), !isStarred); 2603d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 260479525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Now perform the real save 260579525d024526e0f26b9dff40162b91f7c53f17a6yaolu final Intent intent = ContactSaveService.createSetStarredIntent( 260679525d024526e0f26b9dff40162b91f7c53f17a6yaolu QuickContactActivity.this, mContactData.getLookupUri(), !isStarred); 260779525d024526e0f26b9dff40162b91f7c53f17a6yaolu startService(intent); 260835ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell 260979525d024526e0f26b9dff40162b91f7c53f17a6yaolu final CharSequence accessibilityText = !isStarred 261079525d024526e0f26b9dff40162b91f7c53f17a6yaolu ? getResources().getText(R.string.description_action_menu_add_star) 261179525d024526e0f26b9dff40162b91f7c53f17a6yaolu : getResources().getText(R.string.description_action_menu_remove_star); 261279525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Accessibility actions need to have an associated view. We can't access the MenuItem's 261379525d024526e0f26b9dff40162b91f7c53f17a6yaolu // underlying view, so put this accessibility action on the root view. 261479525d024526e0f26b9dff40162b91f7c53f17a6yaolu mScroller.announceForAccessibility(accessibilityText); 2615d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2616d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2617752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void shareContact() { 2618752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final String lookupKey = mContactData.getLookupKey(); 2619652936f204b15097d030e870dda5054d8115cbf3Brian Attwell final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); 2620752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent intent = new Intent(Intent.ACTION_SEND); 2621552ee569d46ae5c63207a162157171b249243e56Yorke Lee intent.setType(Contacts.CONTENT_VCARD_TYPE); 26228dcb4ed13da40fc609e6913708c3d730ba4f0574Brian Attwell intent.putExtra(Intent.EXTRA_STREAM, shareUri); 2623752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2624752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Launch chooser to share contact via 2625281689f7b6e932e15f138645dbadd19d746e2740Wenyi Wang final CharSequence chooseTitle = getResources().getQuantityString( 2626281689f7b6e932e15f138645dbadd19d746e2740Wenyi Wang R.plurals.title_share_via, /* quantity */ 1); 2627752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent chooseIntent = Intent.createChooser(intent, chooseTitle); 2628752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2629752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell try { 2630a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 2631652936f204b15097d030e870dda5054d8115cbf3Brian Attwell ImplicitIntentsUtil.startActivityOutsideApp(this, chooseIntent); 2632eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ActivityNotFoundException ex) { 2633752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show(); 2634752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2635752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2636752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2637752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** 2638752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell * Creates a launcher shortcut with the current contact. 2639752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell */ 2640752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void createLauncherShortcutWithContact() { 2641752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this, 2642752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell new OnShortcutIntentCreatedListener() { 2643752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2644752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell @Override 2645752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) { 2646752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Broadcast the shortcutIntent to the launcher to create a 2647752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // shortcut to this contact 2648752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); 2649752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell QuickContactActivity.this.sendBroadcast(shortcutIntent); 2650752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2651752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Send a toast to give feedback to the user that a shortcut to this 2652752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // contact was added to the launcher. 2653ce8fc7ba2dadfaaf855b18003fb093042d6fe41cguanxiongliu final String displayName = shortcutIntent 2654ce8fc7ba2dadfaaf855b18003fb093042d6fe41cguanxiongliu .getStringExtra(Intent.EXTRA_SHORTCUT_NAME); 2655168331d85c5be43a816eb24fd37a2ebdbe61ac53Tingting Wang final String toastMessage = TextUtils.isEmpty(displayName) 2656168331d85c5be43a816eb24fd37a2ebdbe61ac53Tingting Wang ? getString(R.string.createContactShortcutSuccessful_NoName) 2657168331d85c5be43a816eb24fd37a2ebdbe61ac53Tingting Wang : getString(R.string.createContactShortcutSuccessful, displayName); 2658168331d85c5be43a816eb24fd37a2ebdbe61ac53Tingting Wang Toast.makeText(QuickContactActivity.this, toastMessage, 2659752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.LENGTH_SHORT).show(); 2660752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2661752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2662752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell }); 266363176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell builder.createContactShortcutIntent(mContactData.getLookupUri()); 2664752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2665752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 266666965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell private boolean isShortcutCreatable() { 26671c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner if (mContactData == null || mContactData.isUserProfile() || 26681c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner mContactData.isDirectoryEntry()) { 26698d0557eb013b2808402e491271fe0f13ffcfabefBrian Attwell return false; 26708d0557eb013b2808402e491271fe0f13ffcfabefBrian Attwell } 267166965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell final Intent createShortcutIntent = new Intent(); 267266965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell createShortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); 267366965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell final List<ResolveInfo> receivers = getPackageManager() 267466965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell .queryBroadcastReceivers(createShortcutIntent, 0); 267566965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell return receivers != null && receivers.size() > 0; 267666965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell } 267766965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell 267858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private void setStateForPhoneMenuItems(Contact contact) { 267958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu if (contact != null) { 268058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mSendToVoicemailState = contact.isSendToVoicemail(); 268158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mCustomRingtone = contact.getCustomRingtone(); 268258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mArePhoneOptionsChangable = isContactEditable() 268358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu && PhoneCapabilityTester.isPhone(this); 268458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } 268558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } 268658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 2687d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 2688d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onCreateOptionsMenu(Menu menu) { 2689eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final MenuInflater inflater = getMenuInflater(); 2690d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell inflater.inflate(R.menu.quickcontact, menu); 2691d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 2692d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2693d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2694d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 2695d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onPrepareOptionsMenu(Menu menu) { 2696d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mContactData != null) { 2697d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem starredMenuItem = menu.findItem(R.id.menu_star); 2698333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, 2699d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.isDirectoryEntry(), mContactData.isUserProfile(), 2700d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.getStarred()); 2701a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 2702d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Configure edit MenuItem 2703d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem editMenuItem = menu.findItem(R.id.menu_edit); 2704d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(true); 2705d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData) || InvisibleContactUtil 2706d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell .isInvisibleAndAddable(mContactData, this)) { 270730cfd121ad8c8adb83cf417ff1d40a8ba1e3761dBrian Attwell editMenuItem.setIcon(R.drawable.ic_person_add_tinted_24dp); 27082e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell editMenuItem.setTitle(R.string.menu_add_contact); 2709d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 2710d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setIcon(R.drawable.ic_create_24dp); 27112e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell editMenuItem.setTitle(R.string.menu_editContact); 2712d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else { 2713d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(false); 2714d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2715a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 2716b9065ddb28a2040cabda251891be2062b5260217Gary Mai // The link menu item is only visible if this has a single raw contact. 27172de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu final MenuItem joinMenuItem = menu.findItem(R.id.menu_join); 27182de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu joinMenuItem.setVisible(!InvisibleContactUtil.isInvisibleAndAddable(mContactData, this) 2719b9065ddb28a2040cabda251891be2062b5260217Gary Mai && isContactEditable() && !mContactData.isUserProfile() 2720b9065ddb28a2040cabda251891be2062b5260217Gary Mai && !mContactData.isMultipleRawContacts()); 2721b9065ddb28a2040cabda251891be2062b5260217Gary Mai 2722b9065ddb28a2040cabda251891be2062b5260217Gary Mai // Viewing linked contacts can only happen if there are multiple raw contacts and 2723b9065ddb28a2040cabda251891be2062b5260217Gary Mai // the link menu isn't available. 2724b9065ddb28a2040cabda251891be2062b5260217Gary Mai final MenuItem linkedContactsMenuItem = menu.findItem(R.id.menu_linked_contacts); 2725b9065ddb28a2040cabda251891be2062b5260217Gary Mai linkedContactsMenuItem.setVisible(mContactData.isMultipleRawContacts() 2726b9065ddb28a2040cabda251891be2062b5260217Gary Mai && !joinMenuItem.isVisible()); 27272de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 27285d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang final MenuItem deleteMenuItem = menu.findItem(R.id.menu_delete); 272982ed2b5380e134705f96e7e1f1586a25f8ac403fWalter Jang deleteMenuItem.setVisible(isContactEditable() && !mContactData.isUserProfile()); 27305d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang 2731a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell final MenuItem shareMenuItem = menu.findItem(R.id.menu_share); 2732a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell shareMenuItem.setVisible(isContactShareable()); 2733a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 273466965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell final MenuItem shortcutMenuItem = menu.findItem(R.id.menu_create_contact_shortcut); 273566965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell shortcutMenuItem.setVisible(isShortcutCreatable()); 273666965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell 273758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Hide telephony-related settings (ringtone, send to voicemail) 273858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // if we don't have a telephone 273958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu final MenuItem ringToneMenuItem = menu.findItem(R.id.menu_set_ringtone); 274058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu ringToneMenuItem.setVisible(!mContactData.isUserProfile() && mArePhoneOptionsChangable); 274158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 274258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu final MenuItem sendToVoiceMailMenuItem = menu.findItem(R.id.menu_send_to_voicemail); 274358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu sendToVoiceMailMenuItem.setVisible(!mContactData.isUserProfile() 274458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu && mArePhoneOptionsChangable); 274558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu sendToVoiceMailMenuItem.setTitle(mSendToVoicemailState 274658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu ? R.string.menu_unredirect_calls_to_vm : R.string.menu_redirect_calls_to_vm); 274758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 274856bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell final MenuItem helpMenu = menu.findItem(R.id.menu_help); 274956bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell helpMenu.setVisible(HelpUtils.isHelpAndFeedbackAvailable()); 275056bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell 27518a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return true; 2752d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 27538a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return false; 2754d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2755d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2756d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 2757d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onOptionsItemSelected(MenuItem item) { 2758d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell switch (item.getItemId()) { 2759d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell case R.id.menu_star: 276079525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Make sure there is a contact 276179525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mContactData != null) { 276279525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Read the current starred value from the UI instead of using the last 276379525d024526e0f26b9dff40162b91f7c53f17a6yaolu // loaded state. This allows rapid tapping without writing the same 276479525d024526e0f26b9dff40162b91f7c53f17a6yaolu // value several times 276579525d024526e0f26b9dff40162b91f7c53f17a6yaolu final boolean isStarred = item.isChecked(); 276679525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 276779525d024526e0f26b9dff40162b91f7c53f17a6yaolu isStarred ? ActionType.UNSTAR : ActionType.STAR, 276879525d024526e0f26b9dff40162b91f7c53f17a6yaolu /* thirdPartyAction */ null); 276979525d024526e0f26b9dff40162b91f7c53f17a6yaolu toggleStar(item, isStarred); 277079525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 2771d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 2772d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell case R.id.menu_edit: 2773d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData)) { 277479525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 277579525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.ADD, /* thirdPartyAction */ null); 277679525d024526e0f26b9dff40162b91f7c53f17a6yaolu 2777ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // This action is used to launch the contact selector, with the option of 2778ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // creating a new contact. Creating a new contact is an INSERT, while selecting 2779ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // an exisiting one is an edit. The fields in the edit screen will be 2780ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // prepopulated with data. 2781ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos 2782ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); 2783ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos intent.setType(Contacts.CONTENT_ITEM_TYPE); 2784ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos 2785fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell ArrayList<ContentValues> values = mContactData.getContentValues(); 2786fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell 2787fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // Only pre-fill the name field if the provided display name is an nickname 2788fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // or better (e.g. structured name, nickname) 2789fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell if (mContactData.getDisplayNameSource() >= DisplayNameSources.NICKNAME) { 2790ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos intent.putExtra(Intents.Insert.NAME, mContactData.getDisplayName()); 2791fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell } else if (mContactData.getDisplayNameSource() 2792fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell == DisplayNameSources.ORGANIZATION) { 2793fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // This is probably an organization. Instead of copying the organization 2794fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // name into a name entry, copy it into the organization entry. This 2795fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // way we will still consider the contact an organization. 2796fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell final ContentValues organization = new ContentValues(); 2797fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell organization.put(Organization.COMPANY, mContactData.getDisplayName()); 2798fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell organization.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE); 2799fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell values.add(organization); 2800ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } 2801fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell 2802ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // Last time used and times used are aggregated values from the usage stat 2803ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // table. They need to be removed from data values so the SQL table can insert 2804ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // properly 2805ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos for (ContentValues value : values) { 2806ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos value.remove(Data.LAST_TIME_USED); 2807ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos value.remove(Data.TIMES_USED); 2808ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } 2809ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos intent.putExtra(Intents.Insert.DATA, values); 2810ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos 2811ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // If the contact can only export to the same account, add it to the intent. 2812363af60ea23e5a3b945005712a16564ab69db18bGary Mai // Otherwise the ContactEditorFragment will show a dialog for selecting 28137b0970fd1db1a97f1be915d66d07f4dc8499f96dWalter Jang // an account. 2814ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos if (mContactData.getDirectoryExportSupport() == 2815ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos Directory.EXPORT_SUPPORT_SAME_ACCOUNT_ONLY) { 28164a1c574cd62eb7ca1e0fcc3a61e5378e5e0787feBrian Attwell intent.putExtra(Intents.Insert.EXTRA_ACCOUNT, 2817ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos new Account(mContactData.getDirectoryAccountName(), 2818ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos mContactData.getDirectoryAccountType())); 28194a1c574cd62eb7ca1e0fcc3a61e5378e5e0787feBrian Attwell intent.putExtra(Intents.Insert.EXTRA_DATA_SET, 2820ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos mContactData.getRawContacts().get(0).getDataSet()); 2821ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } 2822ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos 2823f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos // Add this flag to disable the delete menu option on directory contact joins 2824f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos // with local contacts. The delete option is ambiguous when joining contacts. 28258bac28bebae51e53885a404cdf2dd4991000ba42Walter Jang intent.putExtra( 2826363af60ea23e5a3b945005712a16564ab69db18bGary Mai ContactEditorFragment.INTENT_EXTRA_DISABLE_DELETE_MENU_OPTION, 2827f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos true); 2828f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos 282941c6886cabf68370f160ccd68d173bd6a59a1a07John Shao intent.setPackage(getPackageName()); 2830ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos startActivityForResult(intent, REQUEST_CODE_CONTACT_SELECTION_ACTIVITY); 2831d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { 283279525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 283379525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.ADD, /* thirdPartyAction */ null); 2834d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell InvisibleContactUtil.addToDefaultGroup(mContactData, this); 2835d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 283679525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 283779525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.EDIT, /* thirdPartyAction */ null); 2838d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editContact(); 2839d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2840d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 28412de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu case R.id.menu_join: 28422de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu return doJoinContactAction(); 2843b9065ddb28a2040cabda251891be2062b5260217Gary Mai case R.id.menu_linked_contacts: 2844b9065ddb28a2040cabda251891be2062b5260217Gary Mai return showRawContactPickerDialog(); 28455d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang case R.id.menu_delete: 284679525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 28477a09c70af86b9f3bae52c102ebfb6a32b99e7409yaolu ActionType.REMOVE, /* thirdPartyAction */ null); 28481c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner if (isContactEditable()) { 28491c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner deleteContact(); 28501c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner } 28515d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang return true; 2852752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell case R.id.menu_share: 285379525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 285479525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.SHARE, /* thirdPartyAction */ null); 285549de62f06d24653484adebd69123eeff2850a757Jay Shrauner if (isContactShareable()) { 285649de62f06d24653484adebd69123eeff2850a757Jay Shrauner shareContact(); 285749de62f06d24653484adebd69123eeff2850a757Jay Shrauner } 2858752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return true; 2859752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell case R.id.menu_create_contact_shortcut: 286079525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 286179525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.SHORTCUT, /* thirdPartyAction */ null); 28621c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner if (isShortcutCreatable()) { 28631c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner createLauncherShortcutWithContact(); 28641c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner } 2865752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return true; 286658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu case R.id.menu_set_ringtone: 286758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu doPickRingtone(); 286858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu return true; 286958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu case R.id.menu_send_to_voicemail: 287058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Update state and save 287158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mSendToVoicemailState = !mSendToVoicemailState; 287258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu item.setTitle(mSendToVoicemailState 287358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu ? R.string.menu_unredirect_calls_to_vm 287458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu : R.string.menu_redirect_calls_to_vm); 287558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu final Intent intent = ContactSaveService.createSetSendToVoicemail( 287658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu this, mLookupUri, mSendToVoicemailState); 287758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu this.startService(intent); 287858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu return true; 287956bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell case R.id.menu_help: 288079525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 288179525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.HELP, /* thirdPartyAction */ null); 288256bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell HelpUtils.launchHelpAndFeedbackForContactScreen(this); 288356bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell return true; 2884d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell default: 288579525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 288679525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); 2887d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return super.onOptionsItemSelected(item); 2888d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 288923889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos } 28902de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 2891b9065ddb28a2040cabda251891be2062b5260217Gary Mai private boolean showRawContactPickerDialog() { 2892b9065ddb28a2040cabda251891be2062b5260217Gary Mai if (mContactData == null) return false; 2893b9065ddb28a2040cabda251891be2062b5260217Gary Mai startActivityForResult(EditorIntents.createViewLinkedContactsIntent( 2894b9065ddb28a2040cabda251891be2062b5260217Gary Mai QuickContactActivity.this, 2895b9065ddb28a2040cabda251891be2062b5260217Gary Mai mContactData.getLookupUri(), 2896b9065ddb28a2040cabda251891be2062b5260217Gary Mai mHasComputedThemeColor 2897b9065ddb28a2040cabda251891be2062b5260217Gary Mai ? new MaterialPalette(mColorFilterColor, mStatusBarColor) 2898b9065ddb28a2040cabda251891be2062b5260217Gary Mai : null), 2899b9065ddb28a2040cabda251891be2062b5260217Gary Mai REQUEST_CODE_CONTACT_EDITOR_ACTIVITY); 2900b9065ddb28a2040cabda251891be2062b5260217Gary Mai return true; 2901b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2902b9065ddb28a2040cabda251891be2062b5260217Gary Mai 29032de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu private boolean doJoinContactAction() { 29042de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu if (mContactData == null) return false; 29052de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 29062de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu mPreviousContactId = mContactData.getId(); 29072de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu final Intent intent = new Intent(this, ContactSelectionActivity.class); 29082de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu intent.setAction(UiIntentActions.PICK_JOIN_CONTACT_ACTION); 29092de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu intent.putExtra(UiIntentActions.TARGET_CONTACT_ID_EXTRA_KEY, mPreviousContactId); 29102de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu startActivityForResult(intent, REQUEST_CODE_JOIN); 29112de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu return true; 29122de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } 29132de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 29142de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu /** 29152de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu * Performs aggregation with the contact selected by the user from suggestions or A-Z list. 29162de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu */ 29172de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu private void joinAggregate(final long contactId) { 29182de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu final Intent intent = ContactSaveService.createJoinContactsIntent( 29192de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu this, mPreviousContactId, contactId, QuickContactActivity.class, 29202de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu Intent.ACTION_VIEW); 29212de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu this.startService(intent); 2922b9065ddb28a2040cabda251891be2062b5260217Gary Mai showLinkProgressBar(); 29232de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } 29242de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 292558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 292658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private void doPickRingtone() { 292758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu final Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); 292858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Allow user to pick 'Default' 292958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); 293058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Show only ringtones 293158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE); 293258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Allow the user to pick a silent ringtone 293358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); 293458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 293558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu final Uri ringtoneUri = EditorUiUtils.getRingtoneUriFromString(mCustomRingtone, 293658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu CURRENT_API_VERSION); 293758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 293858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Put checkmark next to the current ringtone for this contact 293958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtoneUri); 294058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 294158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Launch! 294258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu try { 294358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu startActivityForResult(intent, REQUEST_CODE_PICK_RINGTONE); 294458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } catch (ActivityNotFoundException ex) { 294558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu Toast.makeText(this, R.string.missing_app, Toast.LENGTH_SHORT).show(); 294658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } 294758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } 2948b9065ddb28a2040cabda251891be2062b5260217Gary Mai 2949b9065ddb28a2040cabda251891be2062b5260217Gary Mai private void dismissProgressBar() { 2950b9065ddb28a2040cabda251891be2062b5260217Gary Mai if (mProgressDialog != null && mProgressDialog.isShowing()) { 2951b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.dismiss(); 2952b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2953b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2954b9065ddb28a2040cabda251891be2062b5260217Gary Mai 2955b9065ddb28a2040cabda251891be2062b5260217Gary Mai private void showLinkProgressBar() { 2956b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.setMessage(getString(R.string.contacts_linking_progress_bar)); 2957b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.show(); 2958b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2959b9065ddb28a2040cabda251891be2062b5260217Gary Mai 2960b9065ddb28a2040cabda251891be2062b5260217Gary Mai private void showUnlinkProgressBar() { 2961b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.setMessage(getString(R.string.contacts_unlinking_progress_bar)); 2962b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.show(); 2963b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2964b9065ddb28a2040cabda251891be2062b5260217Gary Mai 2965b9065ddb28a2040cabda251891be2062b5260217Gary Mai private void maybeShowProgressDialog() { 2966b9065ddb28a2040cabda251891be2062b5260217Gary Mai if (ContactSaveService.getState().isActionPending( 2967b9065ddb28a2040cabda251891be2062b5260217Gary Mai ContactSaveService.ACTION_SPLIT_CONTACT)) { 2968b9065ddb28a2040cabda251891be2062b5260217Gary Mai showUnlinkProgressBar(); 2969b9065ddb28a2040cabda251891be2062b5260217Gary Mai } else if (ContactSaveService.getState().isActionPending( 2970b9065ddb28a2040cabda251891be2062b5260217Gary Mai ContactSaveService.ACTION_JOIN_CONTACTS)) { 2971b9065ddb28a2040cabda251891be2062b5260217Gary Mai showLinkProgressBar(); 2972b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2973b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2974b9065ddb28a2040cabda251891be2062b5260217Gary Mai 2975b9065ddb28a2040cabda251891be2062b5260217Gary Mai private class SaveServiceListener extends BroadcastReceiver { 2976b9065ddb28a2040cabda251891be2062b5260217Gary Mai @Override 2977b9065ddb28a2040cabda251891be2062b5260217Gary Mai public void onReceive(Context context, Intent intent) { 2978b9065ddb28a2040cabda251891be2062b5260217Gary Mai if (Log.isLoggable(TAG, Log.DEBUG)) { 2979b9065ddb28a2040cabda251891be2062b5260217Gary Mai Log.d(TAG, "Got broadcast from save service " + intent); 2980b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2981b9065ddb28a2040cabda251891be2062b5260217Gary Mai if (ContactSaveService.BROADCAST_LINK_COMPLETE.equals(intent.getAction()) 2982b9065ddb28a2040cabda251891be2062b5260217Gary Mai || ContactSaveService.BROADCAST_UNLINK_COMPLETE.equals(intent.getAction())) { 2983b9065ddb28a2040cabda251891be2062b5260217Gary Mai dismissProgressBar(); 2984b9065ddb28a2040cabda251891be2062b5260217Gary Mai if (ContactSaveService.BROADCAST_UNLINK_COMPLETE.equals(intent.getAction())) { 2985b9065ddb28a2040cabda251891be2062b5260217Gary Mai finish(); 2986b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2987b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2988b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2989b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2990edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann} 2991