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; 3891520d763209fa61de58fa54ba4864ed87a2df6fGary Maiimport android.content.pm.ShortcutManager; 3923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulosimport android.content.res.Resources; 4031b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.Bitmap; 4195c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwellimport android.graphics.BitmapFactory; 428a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.Color; 43eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuff; 44eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuffColorFilter; 4531b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.BitmapDrawable; 468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.drawable.ColorDrawable; 4731b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.Drawable; 4858a1ac2d418c716599b06bed1fa1aad1160dbf54yaoluimport android.media.RingtoneManager; 49edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.net.Uri; 5031b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.os.AsyncTask; 51edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.os.Bundle; 528a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.os.Trace; 53eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.CalendarContract; 54edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Email; 55eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Event; 56eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.GroupMembership; 57eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Identity; 58eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Im; 59eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Nickname; 60eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Note; 61eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Organization; 62edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Phone; 63eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Relation; 64edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.SipAddress; 65edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.StructuredPostal; 66edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Website; 67752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.provider.ContactsContract.Contacts; 6860e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulosimport android.provider.ContactsContract.Data; 698bac28bebae51e53885a404cdf2dd4991000ba42Walter Jangimport android.provider.ContactsContract.DataUsageFeedback; 70ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulosimport android.provider.ContactsContract.Directory; 71eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.DisplayNameSources; 72ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulosimport android.provider.ContactsContract.Intents; 73edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.QuickContact; 74edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.RawContacts; 7504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliuimport android.support.v4.app.ActivityCompat; 76b9065ddb28a2040cabda251891be2062b5260217Gary Maiimport android.support.v4.content.LocalBroadcastManager; 773cbc7482cf5eb745f9ac0b51420a295f51aa46b3Marcus Hagerottimport android.support.v4.content.res.ResourcesCompat; 7891520d763209fa61de58fa54ba4864ed87a2df6fGary Maiimport android.support.v4.os.BuildCompat; 7931b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.support.v7.graphics.Palette; 800319222b43927d4d9ce7e2a9070f3543661b5782Tyler Gunnimport android.telecom.PhoneAccount; 810319222b43927d4d9ce7e2a9070f3543661b5782Tyler Gunnimport android.telecom.TelecomManager; 82c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwellimport android.text.BidiFormatter; 83b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wangimport android.text.Spannable; 847ce5352a70e8aaf120bf4f7bd05d595f46abb080Walter Jangimport android.text.SpannableString; 85c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwellimport android.text.TextDirectionHeuristics; 86edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.text.TextUtils; 87edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.util.Log; 882a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu; 892a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu.ContextMenuInfo; 90d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.Menu; 91d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.MenuInflater; 92eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.view.MenuItem; 93f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chenimport android.view.MotionEvent; 94edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View; 95edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View.OnClickListener; 962a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.View.OnCreateContextMenuListener; 9710d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawaimport android.view.WindowManager; 98edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.widget.Toast; 99d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.widget.Toolbar; 100edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1010a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.CallUtil; 1020a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.ClipboardUtils; 1030a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.Collapser; 10472b3ab1d8a62f228a540b05f4ed6373e494c7d72Christine Chenimport com.android.contacts.ContactSaveService; 105d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.ContactsActivity; 1060a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.ContactsUtils; 107d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerottimport com.android.contacts.DynamicShortcuts; 1082d150da246632b1649999cfabed776133b097775Brian Attwellimport com.android.contacts.NfcHandler; 109e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.R; 110363af60ea23e5a3b945005712a16564ab69db18bGary Maiimport com.android.contacts.activities.ContactEditorActivity; 1112de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaoluimport com.android.contacts.activities.ContactSelectionActivity; 1120a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.activities.RequestDesiredPermissionsActivity; 1130a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.activities.RequestPermissionsActivity; 11469c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.compat.CompatUtils; 11569c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.compat.EventCompat; 11669c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.compat.MultiWindowCompat; 1170a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.detail.ContactDisplayUtils; 11869c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.dialog.CallSubjectDialog; 1190a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.editor.ContactEditorFragment; 1200a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.editor.EditorIntents; 1210a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.editor.EditorUiUtils; 1220a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.interactions.CalendarInteractionsLoader; 1230a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.interactions.CallLogInteractionsLoader; 1240a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.interactions.ContactDeletionInteraction; 1250a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.interactions.ContactInteraction; 1260a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.interactions.SmsInteractionsLoader; 12769c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.interactions.TouchPointManager; 12869c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.lettertiles.LetterTileDrawable; 12908d87ee355cdac231c9ca4ef16bcfa5451a1a0b4Gary Maiimport com.android.contacts.ShortcutIntentBuilder; 13008d87ee355cdac231c9ca4ef16bcfa5451a1a0b4Gary Maiimport com.android.contacts.ShortcutIntentBuilder.OnShortcutIntentCreatedListener; 1310a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.list.UiIntentActions; 13269c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.logging.Logger; 13369c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.logging.QuickContactEvent.ActionType; 13469c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.logging.QuickContactEvent.CardType; 13569c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.logging.QuickContactEvent.ContactType; 13669c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.logging.ScreenEvent.ScreenType; 13769c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.AccountTypeManager; 13869c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.Contact; 13969c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.ContactLoader; 14069c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.RawContact; 14169c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.account.AccountType; 14269c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.CustomDataItem; 14369c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.DataItem; 14469c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.DataKind; 14569c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.EmailDataItem; 14669c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.EventDataItem; 14769c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.ImDataItem; 14869c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.NicknameDataItem; 14969c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.NoteDataItem; 15069c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.OrganizationDataItem; 15169c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.PhoneDataItem; 15269c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.RelationDataItem; 15369c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.SipAddressDataItem; 15469c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.StructuredNameDataItem; 15569c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.StructuredPostalDataItem; 15669c182afb0e6d82a341a28b4317aa703af768906Gary Maiimport com.android.contacts.model.dataitem.WebsiteDataItem; 1572d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.Entry; 1582a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryContextMenuInfo; 1592ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryTag; 160e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwellimport com.android.contacts.quickcontact.ExpandingEntryCardView.ExpandingEntryCardViewListener; 161493f8d14b1d974a2939a110ce89fa68e0c915c36Brian Attwellimport com.android.contacts.quickcontact.WebAddress.ParseException; 1620a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.util.DateUtils; 163e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.util.ImageViewDrawableSetter; 1640a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.util.ImplicitIntentsUtil; 1650a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.util.MaterialColorMapUtils; 1660a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.util.MaterialColorMapUtils.MaterialPalette; 1670a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.util.PermissionsUtil; 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; 1720a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.util.UriUtils; 1730a49afa2ad697307cc04ef4cb86570574fa720f2Gary Maiimport com.android.contacts.util.ViewUtil; 174b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller; 175b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener; 17602eaf11669d25fd885606b3b0700358323532cddBrian Attwellimport com.android.contacts.widget.QuickContactImageView; 17756bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwellimport com.android.contactsbind.HelpUtils; 178678108ebb9926a79ad0d7ac4f11417dec1583d42Gary Mai 179e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.google.common.collect.Lists; 180e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng 1812d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport java.util.ArrayList; 182899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport java.util.Arrays; 183eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Calendar; 184b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Collections; 185b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Comparator; 186eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Date; 187edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.HashMap; 188edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.List; 189b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Map; 19012ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shraunerimport java.util.concurrent.ConcurrentHashMap; 191edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 192edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/** 193edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Mostly translucent {@link Activity} that shows QuickContact dialog. It loads 194edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * data asynchronously, and then shows a popup with details centered around 195edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * {@link Intent#getSourceBounds()}. 196edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 197b9065ddb28a2040cabda251891be2062b5260217Gary Maipublic class QuickContactActivity extends ContactsActivity { 1988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell /** 2008a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * QuickContacts immediately takes up the full screen. All possible information is shown. 2018a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * This value for {@link android.provider.ContactsContract.QuickContact#EXTRA_MODE} 2028a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * should only be used by the Contacts app. 2038a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell */ 2048a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public static final int MODE_FULLY_EXPANDED = 4; 2058a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 20662a2074bb3b8dc66996e9fc6a8748b999ab2b51cWalter Jang /** Used to pass the screen where the user came before launching this Activity. */ 20762a2074bb3b8dc66996e9fc6a8748b999ab2b51cWalter Jang public static final String EXTRA_PREVIOUS_SCREEN_TYPE = "previous_screen_type"; 20879525d024526e0f26b9dff40162b91f7c53f17a6yaolu /** Used to pass the Contact card action. */ 20979525d024526e0f26b9dff40162b91f7c53f17a6yaolu public static final String EXTRA_ACTION_TYPE = "action_type"; 21079525d024526e0f26b9dff40162b91f7c53f17a6yaolu public static final String EXTRA_THIRD_PARTY_ACTION = "third_party_action"; 21179525d024526e0f26b9dff40162b91f7c53f17a6yaolu 212250fc1699c72966a5118b9afd814ca2445628ae3Gary Mai /** Used to tell the QuickContact that the previous contact was edited, so it can return an 213250fc1699c72966a5118b9afd814ca2445628ae3Gary Mai * activity result back to the original Activity that launched it. */ 214250fc1699c72966a5118b9afd814ca2445628ae3Gary Mai public static final String EXTRA_CONTACT_EDITED = "contact_edited"; 21562a2074bb3b8dc66996e9fc6a8748b999ab2b51cWalter Jang 216edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String TAG = "QuickContact"; 217edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 2189b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final String KEY_THEME_COLOR = "theme_color"; 21918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private static final String KEY_PREVIOUS_CONTACT_ID = "previous_contact_id"; 2209b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 22158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private static final String KEY_SEND_TO_VOICE_MAIL_STATE = "sendToVoicemailState"; 22258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private static final String KEY_ARE_PHONE_OPTIONS_CHANGEABLE = "arePhoneOptionsChangable"; 22358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private static final String KEY_CUSTOM_RINGTONE = "customRingtone"; 22458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 2259b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final int ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION = 150; 2268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private static final int REQUEST_CODE_CONTACT_EDITOR_ACTIVITY = 1; 2270b267fec5cb5b2d836057b16d0085be349be5243Brian Attwell private static final int SCRIM_COLOR = Color.argb(0xC8, 0, 0, 0); 228ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos private static final int REQUEST_CODE_CONTACT_SELECTION_ACTIVITY = 2; 229ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos private static final String MIMETYPE_SMS = "vnd.android-dir/mms-sms"; 2302de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu private static final int REQUEST_CODE_JOIN = 3; 23158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private static final int REQUEST_CODE_PICK_RINGTONE = 4; 23258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 23358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private static final int CURRENT_API_VERSION = android.os.Build.VERSION.SDK_INT; 234dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 235752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** This is the Intent action to install a shortcut in the launcher. */ 236752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private static final String ACTION_INSTALL_SHORTCUT = 237752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell "com.android.launcher.action.INSTALL_SHORTCUT"; 238edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 2392de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu public static final String ACTION_SPLIT_COMPLETED = "splitCompleted"; 2402de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 24158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Phone specific option menu items 24258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private boolean mSendToVoicemailState; 24358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private boolean mArePhoneOptionsChangable; 24458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private String mCustomRingtone; 24558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 246edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @SuppressWarnings("deprecation") 247edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String LEGACY_AUTHORITY = android.provider.Contacts.AUTHORITY; 248edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 249e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String MIMETYPE_GPLUS_PROFILE = 250e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos "vnd.android.cursor.item/vnd.googleplus.profile"; 2516a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String GPLUS_PROFILE_DATA_5_VIEW_PROFILE = "view"; 252e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String MIMETYPE_HANGOUTS = 253e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos "vnd.android.cursor.item/vnd.googleplus.profile.comm"; 2546a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String HANGOUTS_DATA_5_VIDEO = "hangout"; 2556a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String HANGOUTS_DATA_5_MESSAGE = "conversation"; 25648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos private static final String CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY = 25748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos "com.android.contacts.quickcontact.QuickContactActivity"; 258e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 25979525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Set true in {@link #onCreate} after orientation change for later use in processIntent(). 26079525d024526e0f26b9dff40162b91f7c53f17a6yaolu private boolean mIsRecreatedInstance; 261d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerott private boolean mShortcutUsageReported = false; 26279525d024526e0f26b9dff40162b91f7c53f17a6yaolu 26379525d024526e0f26b9dff40162b91f7c53f17a6yaolu private boolean mShouldLog; 26479525d024526e0f26b9dff40162b91f7c53f17a6yaolu 26579525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Used to store and log the referrer package name and the contact type. 26679525d024526e0f26b9dff40162b91f7c53f17a6yaolu private String mReferrer; 26779525d024526e0f26b9dff40162b91f7c53f17a6yaolu private int mContactType; 26879525d024526e0f26b9dff40162b91f7c53f17a6yaolu 26963176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell /** 27063176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell * The URI used to load the the Contact. Once the contact is loaded, use Contact#getLookupUri() 27163176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell * instead of referencing this URI. 27263176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell */ 273edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private Uri mLookupUri; 274edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private String[] mExcludeMimes; 2758a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mExtraMode; 27605287bf0cea303b93802a629aa883fb6322ca342Brian Attwell private String mExtraPrioritizedMimeType; 2778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mStatusBarColor; 2788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private boolean mHasAlreadyBeenOpened; 27997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos private boolean mOnlyOnePhoneNumber; 28097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos private boolean mOnlyOneEmail; 281b9065ddb28a2040cabda251891be2062b5260217Gary Mai private ProgressDialog mProgressDialog; 282b9065ddb28a2040cabda251891be2062b5260217Gary Mai private SaveServiceListener mListener; 283edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 28402eaf11669d25fd885606b3b0700358323532cddBrian Attwell private QuickContactImageView mPhotoView; 285eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mContactCard; 2866095369885edcca566a812b551886e29c7ff8039Brian Attwell private ExpandingEntryCardView mNoContactDetailsCard; 287b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private ExpandingEntryCardView mRecentCard; 288eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mAboutCard; 28904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu private ExpandingEntryCardView mPermissionExplanationCard; 290e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 29118906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private long mPreviousContactId = 0; 29204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu // Permission explanation card. 29304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu private boolean mShouldShowPermissionExplanation = false; 29404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu private String mPermissionExplanationCardSubHeader = ""; 29504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 296b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private MultiShrinkScroller mScroller; 2976bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private AsyncTask<Void, Void, Cp2DataCardModel> mEntriesAndActionsTask; 29830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell private AsyncTask<Void, Void, Void> mRecentDataTask; 299e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 3006bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 3016bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * The last copy of Cp2DataCardModel that was passed to {@link #populateContactAndAboutCard}. 3026bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 3036bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private Cp2DataCardModel mCachedCp2DataCardModel; 304f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell /** 305f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * This scrim's opacity is controlled in two different ways. 1) Before the initial entrance 306f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * animation finishes, the opacity is animated by a value animator. This is designed to 307f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * distract the user from the length of the initial loading time. 2) After the initial 308f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * entrance animation, the opacity is directly related to scroll position. 309f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell */ 3109b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private ColorDrawable mWindowScrim; 311f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell private boolean mIsEntranceAnimationFinished; 312a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell private MaterialColorMapUtils mMaterialColorMapUtils; 3138477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell private boolean mIsExitAnimationInProgress; 3148571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell private boolean mHasComputedThemeColor; 315edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 316a42ef76251778161d27bc07db214b8c81720e476Paul Soulos /** 317a42ef76251778161d27bc07db214b8c81720e476Paul Soulos * Used to stop the ExpandingEntry cards from adjusting between an entry click and the intent 318a42ef76251778161d27bc07db214b8c81720e476Paul Soulos * being launched. 319a42ef76251778161d27bc07db214b8c81720e476Paul Soulos */ 320a42ef76251778161d27bc07db214b8c81720e476Paul Soulos private boolean mHasIntentLaunched; 321a42ef76251778161d27bc07db214b8c81720e476Paul Soulos 3226cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee private Contact mContactData; 3239815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann private ContactLoader mContactLoader; 3249b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private PorterDuffColorFilter mColorFilter; 3258e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell private int mColorFilterColor; 3269815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann 3279758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter(); 3289758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus 329edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 330cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * {@link #LEADING_MIMETYPES} is used to sort MIME-types. 331edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 332edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * <p>The MIME-types in {@link #LEADING_MIMETYPES} appear in the front of the dialog, 333edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * in the order specified here.</p> 334edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 335edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final List<String> LEADING_MIMETYPES = Lists.newArrayList( 336cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos Phone.CONTENT_ITEM_TYPE, SipAddress.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE, 337405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos StructuredPostal.CONTENT_ITEM_TYPE); 338edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 339a153dba33c2152332c5706178a367f52b0550723Paul Soulos private static final List<String> SORTED_ABOUT_CARD_MIMETYPES = Lists.newArrayList( 340a153dba33c2152332c5706178a367f52b0550723Paul Soulos Nickname.CONTENT_ITEM_TYPE, 341a153dba33c2152332c5706178a367f52b0550723Paul Soulos // Phonetic name is inserted after nickname if it is available. 342a153dba33c2152332c5706178a367f52b0550723Paul Soulos // No mimetype for phonetic name exists. 343a153dba33c2152332c5706178a367f52b0550723Paul Soulos Website.CONTENT_ITEM_TYPE, 344a153dba33c2152332c5706178a367f52b0550723Paul Soulos Organization.CONTENT_ITEM_TYPE, 345a153dba33c2152332c5706178a367f52b0550723Paul Soulos Event.CONTENT_ITEM_TYPE, 346a153dba33c2152332c5706178a367f52b0550723Paul Soulos Relation.CONTENT_ITEM_TYPE, 347a153dba33c2152332c5706178a367f52b0550723Paul Soulos Im.CONTENT_ITEM_TYPE, 348a153dba33c2152332c5706178a367f52b0550723Paul Soulos GroupMembership.CONTENT_ITEM_TYPE, 349a153dba33c2152332c5706178a367f52b0550723Paul Soulos Identity.CONTENT_ITEM_TYPE, 3501bd8826c81eff79551c79c3042aca22a1d905524yaolu CustomDataItem.MIMETYPE_CUSTOM_FIELD, 351a153dba33c2152332c5706178a367f52b0550723Paul Soulos Note.CONTENT_ITEM_TYPE); 352eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 353c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwell private static final BidiFormatter sBidiFormatter = BidiFormatter.getInstance(); 354c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwell 355b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background contact loader */ 356b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_CONTACT_ID = 0; 357b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 358b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background Sms Loader */ 359b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_SMS_ID = 1; 360b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int MAX_SMS_RETRIEVE = 3; 361ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 362ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the back Calendar Loader */ 363899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int LOADER_CALENDAR_ID = 2; 364ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final String KEY_LOADER_EXTRA_EMAILS = 365ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_EMAILS"; 366899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_PAST_CALENDAR_RETRIEVE = 3; 367899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_FUTURE_CALENDAR_RETRIEVE = 3; 368899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 36940d7a65c6e68967f3f486715b194c144d93c296fPaul Soulos 1L * 24L * 60L * 60L * 1000L /* 1 day */; 370899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 37140d7a65c6e68967f3f486715b194c144d93c296fPaul Soulos 7L * 24L * 60L * 60L * 1000L /* 7 days */; 372899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 373ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the background Call Log Loader */ 374ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int LOADER_CALL_LOG_ID = 3; 375ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int MAX_CALL_LOG_RETRIEVE = 3; 3766095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int MIN_NUM_CONTACT_ENTRIES_SHOWN = 3; 3776095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN = 3; 3786095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int CARD_ENTRY_ID_EDIT_CONTACT = -2; 37904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu private static final int CARD_ENTRY_ID_REQUEST_PERMISSION = -3; 380c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu private static final String KEY_LOADER_EXTRA_PHONES = 381c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_PHONES"; 382c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu private static final String KEY_LOADER_EXTRA_SIP_NUMBERS = 383c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_SIP_NUMBERS"; 384ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 385ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int[] mRecentLoaderIds = new int[]{ 386ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_SMS_ID, 387ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALENDAR_ID, 388ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID}; 38912ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner /** 39012ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner * ConcurrentHashMap constructor params: 4 is initial table size, 0.9f is 39112ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner * load factor before resizing, 1 means we only expect a single thread to 39212ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner * write to the map so make only a single shard 39312ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner */ 39412ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner private Map<Integer, List<ContactInteraction>> mRecentLoaderResults = 39512ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner new ConcurrentHashMap<>(4, 0.9f, 1); 396b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 397d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private static final String FRAGMENT_TAG_SELECT_ACCOUNT = "select_account_fragment"; 3986cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee 3992d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos final OnClickListener mEntryClickHandler = new OnClickListener() { 4002d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos @Override 4012d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos public void onClick(View v) { 4022ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final Object entryTagObject = v.getTag(); 4032ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos if (entryTagObject == null || !(entryTagObject instanceof EntryTag)) { 4042ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos Log.w(TAG, "EntryTag was not used correctly"); 4056095369885edcca566a812b551886e29c7ff8039Brian Attwell return; 4066095369885edcca566a812b551886e29c7ff8039Brian Attwell } 4072ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final EntryTag entryTag = (EntryTag) entryTagObject; 4082ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final Intent intent = entryTag.getIntent(); 4092ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final int dataId = entryTag.getId(); 4102ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos 4112ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos if (dataId == CARD_ENTRY_ID_EDIT_CONTACT) { 4122ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos editContact(); 4132d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos return; 4142d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 415ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 41604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu if (dataId == CARD_ENTRY_ID_REQUEST_PERMISSION) { 41704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu finish(); 41804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu RequestDesiredPermissionsActivity.startPermissionActivity( 41904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu QuickContactActivity.this); 42004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu return; 42104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu } 42204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 42319c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO // Pass the touch point through the intent for use in the InCallUI 42419c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO if (Intent.ACTION_CALL.equals(intent.getAction())) { 42519c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO if (TouchPointManager.getInstance().hasValidPoint()) { 42619c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Bundle extras = new Bundle(); 42719c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO extras.putParcelable(TouchPointManager.TOUCH_POINT, 42819c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO TouchPointManager.getInstance().getPoint()); 42919c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras); 43019c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } 43119c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } 43219c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO 43319c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 43419c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO 43519c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO mHasIntentLaunched = true; 43619c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO try { 43779525d024526e0f26b9dff40162b91f7c53f17a6yaolu final int actionType = intent.getIntExtra(EXTRA_ACTION_TYPE, 43879525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION); 43979525d024526e0f26b9dff40162b91f7c53f17a6yaolu final String thirdPartyAction = intent.getStringExtra(EXTRA_THIRD_PARTY_ACTION); 44079525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, 44179525d024526e0f26b9dff40162b91f7c53f17a6yaolu CardType.UNKNOWN_CARD, actionType, thirdPartyAction); 4428c434e5bcc92963f34200634ae5e0ccbe0e7c473Tingting Wang ImplicitIntentsUtil.startActivityInAppIfPossible(QuickContactActivity.this, intent); 44319c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } catch (SecurityException ex) { 44419c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.makeText(QuickContactActivity.this, R.string.missing_app, 44519c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.LENGTH_SHORT).show(); 44619c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Log.e(TAG, "QuickContacts does not have permission to launch " 44719c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO + intent); 44819c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } catch (ActivityNotFoundException ex) { 44919c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.makeText(QuickContactActivity.this, R.string.missing_app, 45019c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.LENGTH_SHORT).show(); 45119c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } 45219c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO 453ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Default to USAGE_TYPE_CALL. Usage is summed among all types for sorting each data id 454ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // so the exact usage type is not necessary in all cases 455ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos String usageType = DataUsageFeedback.USAGE_TYPE_CALL; 456ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 45720bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos final Uri intentUri = intent.getData(); 45820bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos if ((intentUri != null && intentUri.getScheme() != null && 4591cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner intentUri.getScheme().equals(ContactsUtils.SCHEME_SMSTO)) || 460ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos (intent.getType() != null && intent.getType().equals(MIMETYPE_SMS))) { 461ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos usageType = DataUsageFeedback.USAGE_TYPE_SHORT_TEXT; 462ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 463ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 464ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Data IDs start at 1 so anything less is invalid 465ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (dataId > 0) { 46620bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos final Uri dataUsageUri = DataUsageFeedback.FEEDBACK_URI.buildUpon() 467ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendPath(String.valueOf(dataId)) 468ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, usageType) 469ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .build(); 4709881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner try { 4719881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner final boolean successful = getContentResolver().update( 4729881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner dataUsageUri, new ContentValues(), null, null) > 0; 4739881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner if (!successful) { 4749881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner Log.w(TAG, "DataUsageFeedback increment failed"); 4759881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner } 4769881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner } catch (SecurityException ex) { 4779881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner Log.w(TAG, "DataUsageFeedback increment failed", ex); 478ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 479ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } else { 480ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Log.w(TAG, "Invalid Data ID"); 481ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 4822d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 4832d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos }; 4842d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos 485e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell final ExpandingEntryCardViewListener mExpandingEntryCardViewListener 486e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell = new ExpandingEntryCardViewListener() { 487e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell @Override 488e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell public void onCollapse(int heightDelta) { 489e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell mScroller.prepareForShrinkingScrollChild(heightDelta); 490e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell } 4910cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos 4920cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos @Override 493245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell public void onExpand() { 494245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell mScroller.setDisableTouchesForSuppressLayout(/* areTouchesDisabled = */ true); 495245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell } 496245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell 497245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell @Override 498245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell public void onExpandDone() { 499245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell mScroller.setDisableTouchesForSuppressLayout(/* areTouchesDisabled = */ false); 5000cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos } 501e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell }; 502e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell 50397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos private interface ContextMenuIds { 50497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos static final int COPY_TEXT = 0; 50597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos static final int CLEAR_DEFAULT = 1; 50697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos static final int SET_DEFAULT = 2; 50797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 50897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 5092a4207fb39330e840436215c896cde911489e111Paul Soulos private final OnCreateContextMenuListener mEntryContextMenuListener = 5102a4207fb39330e840436215c896cde911489e111Paul Soulos new OnCreateContextMenuListener() { 5112a4207fb39330e840436215c896cde911489e111Paul Soulos @Override 5122a4207fb39330e840436215c896cde911489e111Paul Soulos public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 5132a4207fb39330e840436215c896cde911489e111Paul Soulos if (menuInfo == null) { 5142a4207fb39330e840436215c896cde911489e111Paul Soulos return; 5152a4207fb39330e840436215c896cde911489e111Paul Soulos } 51697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final EntryContextMenuInfo info = (EntryContextMenuInfo) menuInfo; 5172a4207fb39330e840436215c896cde911489e111Paul Soulos menu.setHeaderTitle(info.getCopyText()); 51897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menu.add(ContextMenu.NONE, ContextMenuIds.COPY_TEXT, 51997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ContextMenu.NONE, getString(R.string.copy_text)); 52097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 52197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Don't allow setting or clearing of defaults for non-editable contacts 52297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (!isContactEditable()) { 52397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return; 52497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 52597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 52697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final String selectedMimeType = info.getMimeType(); 52797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 52897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Defaults to true will only enable the detail to be copied to the clipboard. 52997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos boolean onlyOneOfMimeType = true; 53097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 53197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Only allow primary support for Phone and Email content types 53297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (Phone.CONTENT_ITEM_TYPE.equals(selectedMimeType)) { 53397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos onlyOneOfMimeType = mOnlyOnePhoneNumber; 53497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } else if (Email.CONTENT_ITEM_TYPE.equals(selectedMimeType)) { 53597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos onlyOneOfMimeType = mOnlyOneEmail; 53697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 53797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 53897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Checking for previously set default 53997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (info.isSuperPrimary()) { 54097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menu.add(ContextMenu.NONE, ContextMenuIds.CLEAR_DEFAULT, 54197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ContextMenu.NONE, getString(R.string.clear_default)); 54297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } else if (!onlyOneOfMimeType) { 54397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menu.add(ContextMenu.NONE, ContextMenuIds.SET_DEFAULT, 54497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ContextMenu.NONE, getString(R.string.set_default)); 54597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 5462a4207fb39330e840436215c896cde911489e111Paul Soulos } 5472a4207fb39330e840436215c896cde911489e111Paul Soulos }; 5482a4207fb39330e840436215c896cde911489e111Paul Soulos 5492a4207fb39330e840436215c896cde911489e111Paul Soulos @Override 5502a4207fb39330e840436215c896cde911489e111Paul Soulos public boolean onContextItemSelected(MenuItem item) { 5512a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo menuInfo; 5522a4207fb39330e840436215c896cde911489e111Paul Soulos try { 5532a4207fb39330e840436215c896cde911489e111Paul Soulos menuInfo = (EntryContextMenuInfo) item.getMenuInfo(); 5542a4207fb39330e840436215c896cde911489e111Paul Soulos } catch (ClassCastException e) { 5552a4207fb39330e840436215c896cde911489e111Paul Soulos Log.e(TAG, "bad menuInfo", e); 5562a4207fb39330e840436215c896cde911489e111Paul Soulos return false; 5572a4207fb39330e840436215c896cde911489e111Paul Soulos } 5582a4207fb39330e840436215c896cde911489e111Paul Soulos 55997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos switch (item.getItemId()) { 56097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos case ContextMenuIds.COPY_TEXT: 56197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ClipboardUtils.copyText(this, menuInfo.getCopyLabel(), menuInfo.getCopyText(), 56297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos true); 56397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return true; 56497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos case ContextMenuIds.SET_DEFAULT: 56597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final Intent setIntent = ContactSaveService.createSetSuperPrimaryIntent(this, 56697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menuInfo.getId()); 56797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos this.startService(setIntent); 56897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return true; 56997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos case ContextMenuIds.CLEAR_DEFAULT: 57097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final Intent clearIntent = ContactSaveService.createClearPrimaryIntent(this, 57197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menuInfo.getId()); 57297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos this.startService(clearIntent); 57397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return true; 57497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos default: 57597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos throw new IllegalArgumentException("Unknown menu option " + item.getItemId()); 57697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 5772a4207fb39330e840436215c896cde911489e111Paul Soulos } 5782a4207fb39330e840436215c896cde911489e111Paul Soulos 579b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell final MultiShrinkScrollerListener mMultiShrinkScrollerListener 580b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell = new MultiShrinkScrollerListener() { 581b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 582b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onScrolledOffBottom() { 583f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell finish(); 584b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 5858a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 5868a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 5878a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onEnterFullscreen() { 5888a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 5898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 5908a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 5918a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 5928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onExitFullscreen() { 5938a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 5948a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 5958477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 5968477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 5978477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell public void onStartScrollOffBottom() { 5988477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mIsExitAnimationInProgress = true; 5998477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 6008477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 6018477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 602f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void onEntranceAnimationDone() { 603f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = true; 604f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 605f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 606f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell @Override 607f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void onTransparentViewHeightChange(float ratio) { 608f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell if (mIsEntranceAnimationFinished) { 609f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mWindowScrim.setAlpha((int) (0xFF * ratio)); 6108477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 6118477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 612b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell }; 613b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 614eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 615eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 616eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Data items are compared to the same mimetype based off of three qualities: 617eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 1. Super primary 618eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 2. Primary 619eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 3. Times used 620eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 621eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<DataItem> mWithinMimeTypeDataItemComparator = 622eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<DataItem>() { 623eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 624eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(DataItem lhs, DataItem rhs) { 625eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!lhs.getMimeType().equals(rhs.getMimeType())) { 626eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Log.wtf(TAG, "Comparing DataItems with different mimetypes lhs.getMimeType(): " + 627eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getMimeType() + " rhs.getMimeType(): " + rhs.getMimeType()); 628eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 629eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 630eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 631eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lhs.isSuperPrimary()) { 632eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 633eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (rhs.isSuperPrimary()) { 634eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 635eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lhs.isPrimary() && !rhs.isPrimary()) { 636eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 637eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (!lhs.isPrimary() && rhs.isPrimary()) { 638eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 639eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 640eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = 641eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 642eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = 643eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 644eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 645eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return rhsTimesUsed - lhsTimesUsed; 646eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 647eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 648eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 649eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 650cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos /** 651cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * Sorts among different mimetypes based off: 65205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 1. Whether one of the mimetypes is the prioritized mimetype 65305287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 2. Number of times used 65405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 3. Last time used 65505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 4. Statically defined 656cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos */ 657eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<List<DataItem>> mAmongstMimeTypeDataItemComparator = 658eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<List<DataItem>> () { 659eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 660eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(List<DataItem> lhsList, List<DataItem> rhsList) { 66105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final DataItem lhs = lhsList.get(0); 66205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final DataItem rhs = rhsList.get(0); 66305287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final String lhsMimeType = lhs.getMimeType(); 66405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final String rhsMimeType = rhs.getMimeType(); 66505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell 66605287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 1. Whether one of the mimetypes is the prioritized mimetype 66705287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (!TextUtils.isEmpty(mExtraPrioritizedMimeType) && !lhsMimeType.equals(rhsMimeType)) { 66805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (rhsMimeType.equals(mExtraPrioritizedMimeType)) { 66905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return 1; 67005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 67105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (lhsMimeType.equals(mExtraPrioritizedMimeType)) { 67205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return -1; 67305287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 67405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 67505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell 67605287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 2. Number of times used 677eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 678eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 679eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int timesUsedDifference = rhsTimesUsed - lhsTimesUsed; 680eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (timesUsedDifference != 0) { 681eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return timesUsedDifference; 682eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 683eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 68405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 3. Last time used 685eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lhsLastTimeUsed = 686eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getLastTimeUsed() == null ? 0 : lhs.getLastTimeUsed(); 687eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long rhsLastTimeUsed = 688eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getLastTimeUsed() == null ? 0 : rhs.getLastTimeUsed(); 689eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lastTimeUsedDifference = rhsLastTimeUsed - lhsLastTimeUsed; 690eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lastTimeUsedDifference > 0) { 691eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 692eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lastTimeUsedDifference < 0) { 693eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 694eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 695eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 69605287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 4. Resort to a statically defined mimetype order. 69705287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (!lhsMimeType.equals(rhsMimeType)) { 69805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell for (String mimeType : LEADING_MIMETYPES) { 69905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (lhsMimeType.equals(mimeType)) { 70005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return -1; 70105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } else if (rhsMimeType.equals(mimeType)) { 70205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return 1; 70305287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 704eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 705eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 706eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 707eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 708eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 709eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 710edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @Override 711f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen public boolean dispatchTouchEvent(MotionEvent ev) { 712f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen if (ev.getAction() == MotionEvent.ACTION_DOWN) { 713f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); 714f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen } 715f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen return super.dispatchTouchEvent(ev); 716f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen } 717f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen 718f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen @Override 7198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onCreate(Bundle savedInstanceState) { 7208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onCreate()"); 7218a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onCreate(savedInstanceState); 722edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 7231e899dc127a212bfd2198fe7adba5c33eb4cd751Gary Mai if (RequestPermissionsActivity.startPermissionActivityIfNeeded(this)) { 724bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell return; 725bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell } 726bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell 7277a09c70af86b9f3bae52c102ebfb6a32b99e7409yaolu mIsRecreatedInstance = savedInstanceState != null; 7282de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu if (mIsRecreatedInstance) { 7292de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu mPreviousContactId = savedInstanceState.getLong(KEY_PREVIOUS_CONTACT_ID); 73058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 73158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Phone specific options menus 73258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mSendToVoicemailState = savedInstanceState.getBoolean(KEY_SEND_TO_VOICE_MAIL_STATE); 73358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mArePhoneOptionsChangable = 73458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu savedInstanceState.getBoolean(KEY_ARE_PHONE_OPTIONS_CHANGEABLE); 73558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mCustomRingtone = savedInstanceState.getString(KEY_CUSTOM_RINGTONE); 7362de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } 737b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog = new ProgressDialog(this); 738b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.setIndeterminate(true); 739b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.setCancelable(false); 740b9065ddb28a2040cabda251891be2062b5260217Gary Mai 741b9065ddb28a2040cabda251891be2062b5260217Gary Mai mListener = new SaveServiceListener(); 742b9065ddb28a2040cabda251891be2062b5260217Gary Mai final IntentFilter intentFilter = new IntentFilter(); 743b9065ddb28a2040cabda251891be2062b5260217Gary Mai intentFilter.addAction(ContactSaveService.BROADCAST_LINK_COMPLETE); 744b9065ddb28a2040cabda251891be2062b5260217Gary Mai intentFilter.addAction(ContactSaveService.BROADCAST_UNLINK_COMPLETE); 745b9065ddb28a2040cabda251891be2062b5260217Gary Mai LocalBroadcastManager.getInstance(this).registerReceiver(mListener, 746b9065ddb28a2040cabda251891be2062b5260217Gary Mai intentFilter); 747b9065ddb28a2040cabda251891be2062b5260217Gary Mai 748b9065ddb28a2040cabda251891be2062b5260217Gary Mai 74979525d024526e0f26b9dff40162b91f7c53f17a6yaolu mShouldLog = true; 75079525d024526e0f26b9dff40162b91f7c53f17a6yaolu 75104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu // There're 3 states for each permission: 75204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu // 1. App doesn't have permission, not asked user yet. 75304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu // 2. App doesn't have permission, user denied it previously. 75404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu // 3. App has permission. 75504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu // Permission explanation card is displayed only for case 1. 7565a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang final boolean hasTelephonyFeature = 7575a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY); 7585a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang 75904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final boolean hasCalendarPermission = PermissionsUtil.hasPermission( 7600e723d937f3fc9a0bda2602d97d9fbeda7300d51Walter Jang this, Manifest.permission.READ_CALENDAR); 7615a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang final boolean hasSMSPermission = hasTelephonyFeature 7625a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang && PermissionsUtil.hasPermission(this, Manifest.permission.READ_SMS); 76304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 76404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final boolean wasCalendarPermissionDenied = 76504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu ActivityCompat.shouldShowRequestPermissionRationale( 7660e723d937f3fc9a0bda2602d97d9fbeda7300d51Walter Jang this, Manifest.permission.READ_CALENDAR); 76704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final boolean wasSMSPermissionDenied = 7685a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang hasTelephonyFeature && ActivityCompat.shouldShowRequestPermissionRationale( 7690e723d937f3fc9a0bda2602d97d9fbeda7300d51Walter Jang this, Manifest.permission.READ_SMS); 77004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 77104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final boolean shouldDisplayCalendarMessage = 77204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu !hasCalendarPermission && !wasCalendarPermissionDenied; 7735a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang final boolean shouldDisplaySMSMessage = 7745a16ef8637b16ef7c2032ea15a9dbead2314e356Walter Jang hasTelephonyFeature && !hasSMSPermission && !wasSMSPermissionDenied; 77504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mShouldShowPermissionExplanation = shouldDisplayCalendarMessage || shouldDisplaySMSMessage; 77604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 77704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu if (shouldDisplayCalendarMessage && shouldDisplaySMSMessage) { 77804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCardSubHeader = 77904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu getString(R.string.permission_explanation_subheader_calendar_and_SMS); 78004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu } else if (shouldDisplayCalendarMessage) { 78104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCardSubHeader = 78204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu getString(R.string.permission_explanation_subheader_calendar); 78304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu } else if (shouldDisplaySMSMessage) { 78404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCardSubHeader = 78504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu getString(R.string.permission_explanation_subheader_SMS); 78604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu } 78704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 7881bb6c29245bbef5b8dd1c68607acf14aec639be6Walter Jang final int previousScreenType = getIntent().getIntExtra 7891bb6c29245bbef5b8dd1c68607acf14aec639be6Walter Jang (EXTRA_PREVIOUS_SCREEN_TYPE, ScreenType.UNKNOWN); 79062a2074bb3b8dc66996e9fc6a8748b999ab2b51cWalter Jang Logger.logScreenView(this, ScreenType.QUICK_CONTACT, previousScreenType); 79162a2074bb3b8dc66996e9fc6a8748b999ab2b51cWalter Jang 79279525d024526e0f26b9dff40162b91f7c53f17a6yaolu mReferrer = getCallingPackage(); 79379525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mReferrer == null && CompatUtils.isLollipopMr1Compatible() && getReferrer() != null) { 79479525d024526e0f26b9dff40162b91f7c53f17a6yaolu mReferrer = getReferrer().getAuthority(); 79579525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 79679525d024526e0f26b9dff40162b91f7c53f17a6yaolu mContactType = ContactType.UNKNOWN_TYPE; 79779525d024526e0f26b9dff40162b91f7c53f17a6yaolu 7984c3d3e24b0de8b4170106e312f6a4ac8139e1242Wenyi Wang if (CompatUtils.isLollipopCompatible()) { 7994c3d3e24b0de8b4170106e312f6a4ac8139e1242Wenyi Wang getWindow().setStatusBarColor(Color.TRANSPARENT); 8004c3d3e24b0de8b4170106e312f6a4ac8139e1242Wenyi Wang } 8012426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann 802d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(getIntent()); 803dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 80410d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa // Show QuickContact in front of soft input 80510d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 80610d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 80710d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa 808edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann setContentView(R.layout.quickcontact_activity); 809edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 810a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell mMaterialColorMapUtils = new MaterialColorMapUtils(getResources()); 811a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell 8120cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mScroller = (MultiShrinkScroller) findViewById(R.id.multiscroller); 8130cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos 814eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard = (ExpandingEntryCardView) findViewById(R.id.communication_card); 8156095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard = (ExpandingEntryCardView) findViewById(R.id.no_contact_data_card); 816b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card); 817eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard = (ExpandingEntryCardView) findViewById(R.id.about_card); 81804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard = 81904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu (ExpandingEntryCardView) findViewById(R.id.permission_explanation_card); 820edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 82104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setOnClickListener(mEntryClickHandler); 8226095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setOnClickListener(mEntryClickHandler); 823eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setOnClickListener(mEntryClickHandler); 8242a4207fb39330e840436215c896cde911489e111Paul Soulos mContactCard.setOnCreateContextMenuListener(mEntryContextMenuListener); 825b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 826b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setOnClickListener(mEntryClickHandler); 827b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setTitle(getResources().getString(R.string.recent_card_title)); 828edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 829eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setOnClickListener(mEntryClickHandler); 8302a4207fb39330e840436215c896cde911489e111Paul Soulos mAboutCard.setOnCreateContextMenuListener(mEntryContextMenuListener); 831eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 83202eaf11669d25fd885606b3b0700358323532cddBrian Attwell mPhotoView = (QuickContactImageView) findViewById(R.id.photo); 83363176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell final View transparentView = findViewById(R.id.transparent_view); 8340d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell if (mScroller != null) { 83563176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell transparentView.setOnClickListener(new OnClickListener() { 8360d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell @Override 8370d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell public void onClick(View v) { 8380d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell mScroller.scrollOffBottom(); 8390d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 8400d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell }); 8410d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 842edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 843d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell // Allow a shadow to be shown under the toolbar. 844d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell ViewUtil.addRectangularOutlineProvider(findViewById(R.id.toolbar_parent), getResources()); 845d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell 846d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 847d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell setActionBar(toolbar); 8489b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getActionBar().setTitle(null); 8499b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // Put a TextView with a known resource id into the ActionBar. This allows us to easily 8509b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // find the correct TextView location & size later. 8519b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell toolbar.addView(getLayoutInflater().inflate(R.layout.quickcontact_title_placeholder, null)); 8526219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee 8538a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = savedInstanceState != null; 854f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = mHasAlreadyBeenOpened; 8559b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mWindowScrim = new ColorDrawable(SCRIM_COLOR); 856f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mWindowScrim.setAlpha(0); 8579b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getWindow().setBackgroundDrawable(mWindowScrim); 858edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 859caf26197087343fdc18739e20e217236ff26831eWenyi Wang mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED, 860caf26197087343fdc18739e20e217236ff26831eWenyi Wang /* maximumHeaderTextSize */ -1, 861caf26197087343fdc18739e20e217236ff26831eWenyi Wang /* shouldUpdateNameViewHeight */ true); 862ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // mScroller needs to perform asynchronous measurements after initalize(), therefore 863ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // we can't mark this as GONE. 864ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.INVISIBLE); 8658a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 8669b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell setHeaderNameText(R.string.missing_name); 8679b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 868f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ true, 869f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell new Runnable() { 870f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell @Override 871f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void run() { 872f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell if (!mHasAlreadyBeenOpened) { 873f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell // The initial scrim opacity must match the scrim opacity that would be 874f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell // achieved by scrolling to the starting position. 875f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final float alphaRatio = mExtraMode == MODE_FULLY_EXPANDED ? 876f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 1 : mScroller.getStartingTransparentHeightRatio(); 877f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final int duration = getResources().getInteger( 878f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell android.R.integer.config_shortAnimTime); 879f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final int desiredAlpha = (int) (0xFF * alphaRatio); 880f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell ObjectAnimator o = ObjectAnimator.ofInt(mWindowScrim, "alpha", 0, 881f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell desiredAlpha).setDuration(duration); 882f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 883f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell o.start(); 884f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 885f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 886f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell }); 887f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 8889b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (savedInstanceState != null) { 8899b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell final int color = savedInstanceState.getInt(KEY_THEME_COLOR, 0); 890ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 891ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell new Runnable() { 892ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell @Override 893ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell public void run() { 894ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for the pre draw before setting the initial scroll 895ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // value. Prior to pre draw all scroll values are invalid. 896ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (mHasAlreadyBeenOpened) { 897ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.VISIBLE); 898ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setScroll(mScroller.getScrollNeededToBeFullScreen()); 899ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 900ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for pre draw for setting the theme color. Setting the 901ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // header tint before the MultiShrinkScroller has been measured will 902ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // cause incorrect tinting calculations. 903ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (color != 0) { 904a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell setThemeColor(mMaterialColorMapUtils 905a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell .calculatePrimaryAndSecondaryColor(color)); 9069b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 907ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 908ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell }); 9099b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 9109b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 9118a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 9128a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 9138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 914405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos @Override 915405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos protected void onActivityResult(int requestCode, int resultCode, Intent data) { 916d1cb9045bffc3843f5a294d41ce4608c701bccccWenyi Wang final boolean deletedOrSplit = requestCode == REQUEST_CODE_CONTACT_EDITOR_ACTIVITY && 917d1cb9045bffc3843f5a294d41ce4608c701bccccWenyi Wang (resultCode == ContactDeletionInteraction.RESULT_CODE_DELETED || 918363af60ea23e5a3b945005712a16564ab69db18bGary Mai resultCode == ContactEditorActivity.RESULT_CODE_SPLIT); 9190d76abcea3e2b5ef950870d4d5cf8685524ce23eGary Mai setResult(resultCode, data); 920d1cb9045bffc3843f5a294d41ce4608c701bccccWenyi Wang if (deletedOrSplit) { 9218a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell finish(); 922ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } else if (requestCode == REQUEST_CODE_CONTACT_SELECTION_ACTIVITY && 923ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos resultCode != RESULT_CANCELED) { 924ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos processIntent(data); 9252de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } else if (requestCode == REQUEST_CODE_JOIN) { 9262de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu // Ignore failed requests 9272de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu if (resultCode != Activity.RESULT_OK) { 928f83db43ccf5250574ac521bbcc642ea3c4b8278cyaolu return; 9292de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } 9302de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu if (data != null) { 9312de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu joinAggregate(ContentUris.parseId(data.getData())); 9322de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } 93358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } else if (requestCode == REQUEST_CODE_PICK_RINGTONE && data != null) { 93458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu final Uri pickedUri = data.getParcelableExtra( 93558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu RingtoneManager.EXTRA_RINGTONE_PICKED_URI); 93658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu onRingtonePicked(pickedUri); 937b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 9388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 939dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 94058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private void onRingtonePicked(Uri pickedUri) { 94158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mCustomRingtone = EditorUiUtils.getRingtoneStringFromUri(pickedUri, CURRENT_API_VERSION); 94258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu Intent intent = ContactSaveService.createSetRingtone( 94358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu this, mLookupUri, mCustomRingtone); 94458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu this.startService(intent); 94558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } 94658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 9478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 9488a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onNewIntent(Intent intent) { 9498a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onNewIntent(intent); 9508a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 951f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = true; 9528571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = false; 953d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(intent); 954d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 955d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 9569b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell @Override 9579b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell public void onSaveInstanceState(Bundle savedInstanceState) { 9589b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell super.onSaveInstanceState(savedInstanceState); 9599b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mColorFilter != null) { 9608e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell savedInstanceState.putInt(KEY_THEME_COLOR, mColorFilterColor); 9619b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 96218906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang savedInstanceState.putLong(KEY_PREVIOUS_CONTACT_ID, mPreviousContactId); 96358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 96458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Phone specific options 96558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu savedInstanceState.putBoolean(KEY_SEND_TO_VOICE_MAIL_STATE, mSendToVoicemailState); 96658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu savedInstanceState.putBoolean(KEY_ARE_PHONE_OPTIONS_CHANGEABLE, mArePhoneOptionsChangable); 96758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu savedInstanceState.putString(KEY_CUSTOM_RINGTONE, mCustomRingtone); 9689b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 9699b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 970d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void processIntent(Intent intent) { 971f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos if (intent == null) { 972f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos finish(); 973f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos return; 974f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos } 9752de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu if (ACTION_SPLIT_COMPLETED.equals(intent.getAction())) { 9762de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu Toast.makeText(this, R.string.contactUnlinkedToast, Toast.LENGTH_SHORT).show(); 9772de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu finish(); 9782de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu return; 9792de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } 9802de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 981d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell Uri lookupUri = intent.getData(); 982250fc1699c72966a5118b9afd814ca2445628ae3Gary Mai if (intent.getBooleanExtra(EXTRA_CONTACT_EDITED, false)) { 983363af60ea23e5a3b945005712a16564ab69db18bGary Mai setResult(ContactEditorActivity.RESULT_CODE_EDITED); 984250fc1699c72966a5118b9afd814ca2445628ae3Gary Mai } 985d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 986d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Check to see whether it comes from the old version. 987d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) { 988d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final long rawContactId = ContentUris.parseId(lookupUri); 989d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell lookupUri = RawContacts.getContactLookupUri(getContentResolver(), 990d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); 991d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 99205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, QuickContact.MODE_LARGE); 993caf26197087343fdc18739e20e217236ff26831eWenyi Wang if (isMultiWindowOnPhone()) { 994caf26197087343fdc18739e20e217236ff26831eWenyi Wang mExtraMode = QuickContact.MODE_LARGE; 995caf26197087343fdc18739e20e217236ff26831eWenyi Wang } 996caf26197087343fdc18739e20e217236ff26831eWenyi Wang mExtraPrioritizedMimeType = 997caf26197087343fdc18739e20e217236ff26831eWenyi Wang getIntent().getStringExtra(QuickContact.EXTRA_PRIORITIZED_MIMETYPE); 998d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Uri oldLookupUri = mLookupUri; 999d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1000d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerott 1001fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner if (lookupUri == null) { 1002fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner finish(); 1003fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner return; 1004fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner } 1005fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner mLookupUri = lookupUri; 1006d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES); 1007d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (oldLookupUri == null) { 100879525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Should not log if only orientation changes. 100979525d024526e0f26b9dff40162b91f7c53f17a6yaolu mShouldLog = !mIsRecreatedInstance; 1010d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactLoader = (ContactLoader) getLoaderManager().initLoader( 1011d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell LOADER_CONTACT_ID, null, mLoaderContactCallbacks); 1012d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (oldLookupUri != mLookupUri) { 101379525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Should log when reload happens, regardless of orientation change. 101479525d024526e0f26b9dff40162b91f7c53f17a6yaolu mShouldLog = true; 1015d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // After copying a directory contact, the contact URI changes. Therefore, 1016144a4d16daf88dded258063bc33810b20c57f81dWenyi Wang // we need to reload the new contact. 101759a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell destroyInteractionLoaders(); 1018144a4d16daf88dded258063bc33810b20c57f81dWenyi Wang mContactLoader = (ContactLoader) (Loader<?>) getLoaderManager().getLoader( 1019144a4d16daf88dded258063bc33810b20c57f81dWenyi Wang LOADER_CONTACT_ID); 10204861031d5f0ac3707fe089c1efd559260672df39yaolu mContactLoader.setNewLookup(mLookupUri); 102159a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell mCachedCp2DataCardModel = null; 1022d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1023144a4d16daf88dded258063bc33810b20c57f81dWenyi Wang mContactLoader.forceLoad(); 10242d150da246632b1649999cfabed776133b097775Brian Attwell 10252d150da246632b1649999cfabed776133b097775Brian Attwell NfcHandler.register(this, mLookupUri); 10262426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann } 1027edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 102859a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell private void destroyInteractionLoaders() { 102959a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell for (int interactionLoaderId : mRecentLoaderIds) { 103059a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell getLoaderManager().destroyLoader(interactionLoaderId); 103159a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell } 103259a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell } 103359a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell 1034b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private void runEntranceAnimation() { 10358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mHasAlreadyBeenOpened) { 10368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 10378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 10388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 1039caf26197087343fdc18739e20e217236ff26831eWenyi Wang mScroller.scrollUpForEntranceAnimation(/* scrollToCurrentPosition */ !isMultiWindowOnPhone() 1040caf26197087343fdc18739e20e217236ff26831eWenyi Wang && (mExtraMode != MODE_FULLY_EXPANDED)); 1041caf26197087343fdc18739e20e217236ff26831eWenyi Wang } 1042caf26197087343fdc18739e20e217236ff26831eWenyi Wang 1043caf26197087343fdc18739e20e217236ff26831eWenyi Wang private boolean isMultiWindowOnPhone() { 1044caf26197087343fdc18739e20e217236ff26831eWenyi Wang return MultiWindowCompat.isInMultiWindowMode(this) && PhoneCapabilityTester.isPhone(this); 1045b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 1046b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 104781281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 1048d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void setHeaderNameText(int resId) { 10499b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 10509f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang mScroller.setTitle(getText(resId) == null ? null : getText(resId).toString(), 10519f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang /* isPhoneNumber= */ false); 10529b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 105381281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 105481281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 105581281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 10569f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang private void setHeaderNameText(String value, boolean isPhoneNumber) { 1057d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (!TextUtils.isEmpty(value)) { 10589b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 10599f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang mScroller.setTitle(value, isPhoneNumber); 10609b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 106181281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 106281281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 106381281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 106481281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** 1065edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Check if the given MIME-type appears in the list of excluded MIME-types 1066edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * that the most-recent caller requested. 1067edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 1068edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private boolean isMimeExcluded(String mimeType) { 1069edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (mExcludeMimes == null) return false; 1070edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann for (String excludedMime : mExcludeMimes) { 1071edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (TextUtils.equals(excludedMime, mimeType)) { 1072edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return true; 1073edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1074edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1075edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return false; 1076edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1077edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1078edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 1079cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann * Handle the result from the ContactLoader 1080edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 10818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void bindContactData(final Contact data) { 10828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("bindContactData"); 108379525d024526e0f26b9dff40162b91f7c53f17a6yaolu 108479525d024526e0f26b9dff40162b91f7c53f17a6yaolu final int actionType = mContactData == null ? ActionType.START : ActionType.UNKNOWN_ACTION; 10856cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee mContactData = data; 108679525d024526e0f26b9dff40162b91f7c53f17a6yaolu 108779525d024526e0f26b9dff40162b91f7c53f17a6yaolu final int newContactType; 108879525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (DirectoryContactUtil.isDirectoryContact(mContactData)) { 108979525d024526e0f26b9dff40162b91f7c53f17a6yaolu newContactType = ContactType.DIRECTORY; 109079525d024526e0f26b9dff40162b91f7c53f17a6yaolu } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { 109179525d024526e0f26b9dff40162b91f7c53f17a6yaolu newContactType = ContactType.INVISIBLE_AND_ADDABLE; 109279525d024526e0f26b9dff40162b91f7c53f17a6yaolu } else if (isContactEditable()) { 109379525d024526e0f26b9dff40162b91f7c53f17a6yaolu newContactType = ContactType.EDITABLE; 109479525d024526e0f26b9dff40162b91f7c53f17a6yaolu } else { 109579525d024526e0f26b9dff40162b91f7c53f17a6yaolu newContactType = ContactType.UNKNOWN_TYPE; 109679525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 109779525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mShouldLog && mContactType != newContactType) { 10987a09c70af86b9f3bae52c102ebfb6a32b99e7409yaolu Logger.logQuickContactEvent(mReferrer, newContactType, CardType.UNKNOWN_CARD, 109979525d024526e0f26b9dff40162b91f7c53f17a6yaolu actionType, /* thirdPartyAction */ null); 110079525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 110179525d024526e0f26b9dff40162b91f7c53f17a6yaolu mContactType = newContactType; 110279525d024526e0f26b9dff40162b91f7c53f17a6yaolu 110358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu setStateForPhoneMenuItems(mContactData); 1104d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell invalidateOptionsMenu(); 1105edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 11068a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 11078a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("Set display photo & name"); 1108dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 110902eaf11669d25fd885606b3b0700358323532cddBrian Attwell mPhotoView.setIsBusiness(mContactData.isDisplayNameFromOrganization()); 11106219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee mPhotoSetter.setupContactPhoto(data, mPhotoView); 111131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell extractAndApplyTintFromPhotoViewAsynchronously(); 1112df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang final String displayName = ContactDisplayUtils.getDisplayName(this, data).toString(); 11139f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang setHeaderNameText( 11149f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang displayName, mContactData.getDisplayNameSource() == DisplayNameSources.PHONE); 1115df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang final String phoneticName = ContactDisplayUtils.getPhoneticName(this, data); 1116df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang if (mScroller != null) { 1117469a70fea3ce1e24ea87df3d9e325e865d5bf07fTingting Wang // Show phonetic name only when it doesn't equal the display name. 1118469a70fea3ce1e24ea87df3d9e325e865d5bf07fTingting Wang if (!TextUtils.isEmpty(phoneticName) && !phoneticName.equals(displayName)) { 1119df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang mScroller.setPhoneticName(phoneticName); 1120df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang } else { 1121df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang mScroller.setPhoneticNameGone(); 1122df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang } 1123d5b686e73dc50d90fd44dc5c738d243a81a6cc31Tingting Wang } 1124edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 11258a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 1126dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 11276bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mEntriesAndActionsTask = new AsyncTask<Void, Void, Cp2DataCardModel>() { 11288a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 11298a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 11306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell protected Cp2DataCardModel doInBackground( 1131eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Void... params) { 1132eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return generateDataModelFromContact(data); 11338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 11348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 11358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 11366bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell protected void onPostExecute(Cp2DataCardModel cardDataModel) { 11376bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell super.onPostExecute(cardDataModel); 11388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Check that original AsyncTask parameters are still valid and the activity 11398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // is still running before binding to UI. A new intent could invalidate 11408a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the results, for example. 11418a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (data == mContactData && !isCancelled()) { 11426bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell bindDataToCards(cardDataModel); 11438a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell showActivity(); 11448a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 11458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 11468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }; 11478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.execute(); 11488a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 11498a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 11506bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void bindDataToCards(Cp2DataCardModel cp2DataCardModel) { 11516bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell startInteractionLoaders(cp2DataCardModel); 1152a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang populateContactAndAboutCard(cp2DataCardModel, /* shouldAddPhoneticName */ true); 1153eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1154eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 11556bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void startInteractionLoaders(Cp2DataCardModel cp2DataCardModel) { 11566bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final Map<String, List<DataItem>> dataItemsMap = cp2DataCardModel.dataItemsMap; 11576bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> phoneDataItems = dataItemsMap.get(Phone.CONTENT_ITEM_TYPE); 1158c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu final List<DataItem> sipCallDataItems = dataItemsMap.get(SipAddress.CONTENT_ITEM_TYPE); 115997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (phoneDataItems != null && phoneDataItems.size() == 1) { 116097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos mOnlyOnePhoneNumber = true; 116197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 1162eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] phoneNumbers = null; 1163eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (phoneDataItems != null) { 1164eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers = new String[phoneDataItems.size()]; 1165eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < phoneDataItems.size(); ++i) { 1166eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers[i] = ((PhoneDataItem) phoneDataItems.get(i)).getNumber(); 1167eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1168eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1169c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu String[] sipNumbers = null; 1170c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu if (sipCallDataItems != null) { 1171c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu sipNumbers = new String[sipCallDataItems.size()]; 1172c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu for (int i = 0; i < sipCallDataItems.size(); ++i) { 1173c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu sipNumbers[i] = ((SipAddressDataItem) sipCallDataItems.get(i)).getSipAddress(); 1174c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu } 1175c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu } 1176ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle phonesExtraBundle = new Bundle(); 1177eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_PHONES, phoneNumbers); 1178c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_SIP_NUMBERS, sipNumbers); 1179eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1180eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("start sms loader"); 11818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getLoaderManager().initLoader( 11828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell LOADER_SMS_ID, 1183ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 1184ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos mLoaderInteractionsCallbacks); 1185ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.endSection(); 1186ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 1187ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.beginSection("start call log loader"); 1188ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos getLoaderManager().initLoader( 1189ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID, 1190ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 11918a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mLoaderInteractionsCallbacks); 1192899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.endSection(); 11938a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1194eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1195899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.beginSection("start calendar loader"); 11966bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> emailDataItems = dataItemsMap.get(Email.CONTENT_ITEM_TYPE); 119797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (emailDataItems != null && emailDataItems.size() == 1) { 119897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos mOnlyOneEmail = true; 119997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 1200eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] emailAddresses = null; 1201eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (emailDataItems != null) { 1202eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses = new String[emailDataItems.size()]; 1203eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < emailDataItems.size(); ++i) { 1204eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses[i] = ((EmailDataItem) emailDataItems.get(i)).getAddress(); 1205eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1206eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1207ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle emailsExtraBundle = new Bundle(); 1208eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailsExtraBundle.putStringArray(KEY_LOADER_EXTRA_EMAILS, emailAddresses); 1209899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos getLoaderManager().initLoader( 1210899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos LOADER_CALENDAR_ID, 1211ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos emailsExtraBundle, 1212899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos mLoaderInteractionsCallbacks); 12138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 12148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 12168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void showActivity() { 12178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller != null) { 12188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mScroller.setVisibility(View.VISIBLE); 12198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 12208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell new Runnable() { 12218a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 12228a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void run() { 12238a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell runEntranceAnimation(); 12248a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12258a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }); 12268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12278a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12288a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 12296bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private List<List<Entry>> buildAboutCardEntries(Map<String, List<DataItem>> dataItemsMap) { 1230a153dba33c2152332c5706178a367f52b0550723Paul Soulos final List<List<Entry>> aboutCardEntries = new ArrayList<>(); 1231a153dba33c2152332c5706178a367f52b0550723Paul Soulos for (String mimetype : SORTED_ABOUT_CARD_MIMETYPES) { 12326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> mimeTypeItems = dataItemsMap.get(mimetype); 1233a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (mimeTypeItems == null) { 1234a153dba33c2152332c5706178a367f52b0550723Paul Soulos continue; 1235a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 12366bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // Set aboutCardTitleOut = null, since SORTED_ABOUT_CARD_MIMETYPES doesn't contain 12376bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // the name mimetype. 12386bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<Entry> aboutEntries = dataItemsToEntries(mimeTypeItems, 12396bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /* aboutCardTitleOut = */ null); 1240a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (aboutEntries.size() > 0) { 1241a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(aboutEntries); 1242a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1243a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1244a153dba33c2152332c5706178a367f52b0550723Paul Soulos return aboutCardEntries; 1245a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1246a153dba33c2152332c5706178a367f52b0550723Paul Soulos 1247a42ef76251778161d27bc07db214b8c81720e476Paul Soulos @Override 1248a42ef76251778161d27bc07db214b8c81720e476Paul Soulos protected void onResume() { 1249a42ef76251778161d27bc07db214b8c81720e476Paul Soulos super.onResume(); 1250a42ef76251778161d27bc07db214b8c81720e476Paul Soulos // If returning from a launched activity, repopulate the contact and about card 1251a42ef76251778161d27bc07db214b8c81720e476Paul Soulos if (mHasIntentLaunched) { 1252a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = false; 1253a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang populateContactAndAboutCard(mCachedCp2DataCardModel, /* shouldAddPhoneticName */ false); 1254a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 125559a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell 125659a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell // When exiting the activity and resuming, we want to force a full reload of all the 125759a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell // interaction data in case something changed in the background. On screen rotation, 125859a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell // we don't need to do this. And, mCachedCp2DataCardModel will be null, so we won't. 125959a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell if (mCachedCp2DataCardModel != null) { 126059a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell destroyInteractionLoaders(); 126159a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell startInteractionLoaders(mCachedCp2DataCardModel); 126259a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell } 1263b9065ddb28a2040cabda251891be2062b5260217Gary Mai maybeShowProgressDialog(); 1264b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 1265b9065ddb28a2040cabda251891be2062b5260217Gary Mai 1266b9065ddb28a2040cabda251891be2062b5260217Gary Mai 1267b9065ddb28a2040cabda251891be2062b5260217Gary Mai @Override 1268b9065ddb28a2040cabda251891be2062b5260217Gary Mai protected void onPause() { 1269b9065ddb28a2040cabda251891be2062b5260217Gary Mai super.onPause(); 1270b9065ddb28a2040cabda251891be2062b5260217Gary Mai dismissProgressBar(); 1271a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 1272a42ef76251778161d27bc07db214b8c81720e476Paul Soulos 1273a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang private void populateContactAndAboutCard(Cp2DataCardModel cp2DataCardModel, 1274a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang boolean shouldAddPhoneticName) { 12756bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mCachedCp2DataCardModel = cp2DataCardModel; 12766bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (mHasIntentLaunched || cp2DataCardModel == null) { 1277a42ef76251778161d27bc07db214b8c81720e476Paul Soulos return; 1278a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 1279eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind contact card"); 1280eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 12816bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> contactCardEntries = cp2DataCardModel.contactCardEntries; 12826bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> aboutCardEntries = cp2DataCardModel.aboutCardEntries; 12836bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final String customAboutCardName = cp2DataCardModel.customAboutCardName; 1284eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1285eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (contactCardEntries.size() > 0) { 1286eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.initialize(contactCardEntries, 1287eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* numInitialVisibleEntries = */ MIN_NUM_CONTACT_ENTRIES_SHOWN, 1288c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos /* isExpanded = */ mContactCard.isExpanded(), 1289139a03bd82f45338402e747154dd7b3d61bf1747yaolu /* isAlwaysExpanded = */ true, 12900cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mExpandingEntryCardViewListener, 1291139a03bd82f45338402e747154dd7b3d61bf1747yaolu mScroller); 129279525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mContactCard.getVisibility() == View.GONE && mShouldLog) { 129379525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.CONTACT, 129479525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); 129579525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 1296eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.VISIBLE); 1297eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1298eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.GONE); 1299eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1300eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 13018a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1302eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind about card"); 1303c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos // Phonetic name is not a data item, so the entry needs to be created separately 1304a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang // But if mCachedCp2DataCardModel is passed to this method (e.g. returning from editor 1305a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang // without saving any changes), then it should include phoneticName and the phoneticName 1306a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang // shouldn't be changed. If this is the case, we shouldn't add it again. b/27459294 1307c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos final String phoneticName = mContactData.getPhoneticName(); 1308a26a57a6c1a3e2c81d58caf20314b2379bb47b33Wenyi Wang if (shouldAddPhoneticName && !TextUtils.isEmpty(phoneticName)) { 1309c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos Entry phoneticEntry = new Entry(/* viewId = */ -1, 1310c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* icon = */ null, 1311c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos getResources().getString(R.string.name_phonetic), 1312c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos phoneticName, 13138a3fe52802135be2402a5b216325615fb796a509Walter Jang /* subHeaderIcon = */ null, 1314c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* text = */ null, 13158a3fe52802135be2402a5b216325615fb796a509Walter Jang /* textIcon = */ null, 131623e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos /* primaryContentDescription = */ null, 1317c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* intent = */ null, 1318c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateIcon = */ null, 1319c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateIntent = */ null, 1320c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateContentDescription = */ null, 1321c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* shouldApplyColor = */ false, 13222a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, 13232a4207fb39330e840436215c896cde911489e111Paul Soulos /* EntryContextMenuInfo = */ new EntryContextMenuInfo(phoneticName, 132497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos getResources().getString(R.string.name_phonetic), 132597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos /* mimeType = */ null, /* id = */ -1, /* isPrimary = */ false), 132648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, 132748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIntent = */ null, 132848290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos /* thirdContentDescription = */ null, 13295f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdAction = */ Entry.ACTION_NONE, 13305f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdExtras = */ null, 13315f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* iconResourceId = */ 0); 1332c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos List<Entry> phoneticList = new ArrayList<>(); 1333c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos phoneticList.add(phoneticEntry); 1334a153dba33c2152332c5706178a367f52b0550723Paul Soulos // Phonetic name comes after nickname. Check to see if the first entry type is nickname 1335a0fa4c18dc111ceea9ff47f35ee01fecc1003578Paul Soulos if (aboutCardEntries.size() > 0 && aboutCardEntries.get(0).get(0).getHeader().equals( 1336a153dba33c2152332c5706178a367f52b0550723Paul Soulos getResources().getString(R.string.header_nickname_entry))) { 1337a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(1, phoneticList); 1338a153dba33c2152332c5706178a367f52b0550723Paul Soulos } else { 1339a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(0, phoneticList); 1340a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1341c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos } 1342c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos 13436bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!TextUtils.isEmpty(customAboutCardName)) { 13446bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mAboutCard.setTitle(customAboutCardName); 13456bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 13466bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 13473b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox mAboutCard.initialize(aboutCardEntries, 13483b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox /* numInitialVisibleEntries = */ 1, 13493b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox /* isExpanded = */ true, 13503b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox /* isAlwaysExpanded = */ true, 13513b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox mExpandingEntryCardViewListener, 13523b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox mScroller); 13536095369885edcca566a812b551886e29c7ff8039Brian Attwell 13546095369885edcca566a812b551886e29c7ff8039Brian Attwell if (contactCardEntries.size() == 0 && aboutCardEntries.size() == 0) { 135595a134512bcdca22f3cb149967acb9dbfea309b5yaolu initializeNoContactDetailCard(cp2DataCardModel.areAllRawContactsSimAccounts); 13566095369885edcca566a812b551886e29c7ff8039Brian Attwell } else { 13576095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setVisibility(View.GONE); 13586095369885edcca566a812b551886e29c7ff8039Brian Attwell } 13596095369885edcca566a812b551886e29c7ff8039Brian Attwell 1360a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos // If the Recent card is already initialized (all recent data is loaded), show the About 1361a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos // card if it has entries. Otherwise About card visibility will be set in bindRecentData() 136279525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (aboutCardEntries.size() > 0) { 136379525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mAboutCard.getVisibility() == View.GONE && mShouldLog) { 136479525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.ABOUT, 136579525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); 136679525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 136779525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (isAllRecentDataLoaded()) { 136879525d024526e0f26b9dff40162b91f7c53f17a6yaolu mAboutCard.setVisibility(View.VISIBLE); 136979525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 1370a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos } 1371eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 1372eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1373eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1374eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 13756095369885edcca566a812b551886e29c7ff8039Brian Attwell * Create a card that shows "Add email" and "Add phone number" entries in grey. 137695a134512bcdca22f3cb149967acb9dbfea309b5yaolu * When contact is a SIM contact, only shows "Add phone number". 13776095369885edcca566a812b551886e29c7ff8039Brian Attwell */ 137895a134512bcdca22f3cb149967acb9dbfea309b5yaolu private void initializeNoContactDetailCard(boolean areAllRawContactsSimAccounts) { 13793cbc7482cf5eb745f9ac0b51420a295f51aa46b3Marcus Hagerott final Drawable phoneIcon = ResourcesCompat.getDrawable(getResources(), 13803cbc7482cf5eb745f9ac0b51420a295f51aa46b3Marcus Hagerott R.drawable.quantum_ic_phone_vd_theme_24, null).mutate(); 13816095369885edcca566a812b551886e29c7ff8039Brian Attwell final Entry phonePromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, 13826095369885edcca566a812b551886e29c7ff8039Brian Attwell phoneIcon, getString(R.string.quickcontact_add_phone_number), 13838a3fe52802135be2402a5b216325615fb796a509Walter Jang /* subHeader = */ null, /* subHeaderIcon = */ null, /* text = */ null, 13848a3fe52802135be2402a5b216325615fb796a509Walter Jang /* textIcon = */ null, /* primaryContentDescription = */ null, 138523e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos getEditContactIntent(), 1386dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIcon = */ null, /* alternateIntent = */ null, 1387714455bba22b99d168a2e864dfbc74a6e30dfdb6Paul Soulos /* alternateContentDescription = */ null, /* shouldApplyColor = */ true, 138848fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* isEditable = */ false, /* EntryContextMenuInfo = */ null, 138948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, /* thirdIntent = */ null, 13905f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdContentDescription = */ null, 13915f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdAction = */ Entry.ACTION_NONE, 13925f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdExtras = */ null, 1393bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao R.drawable.quantum_ic_phone_vd_theme_24); 13946095369885edcca566a812b551886e29c7ff8039Brian Attwell 13956095369885edcca566a812b551886e29c7ff8039Brian Attwell final List<List<Entry>> promptEntries = new ArrayList<>(); 13966095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.add(new ArrayList<Entry>(1)); 13976095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.get(0).add(phonePromptEntry); 139895a134512bcdca22f3cb149967acb9dbfea309b5yaolu 139995a134512bcdca22f3cb149967acb9dbfea309b5yaolu if (!areAllRawContactsSimAccounts) { 14003cbc7482cf5eb745f9ac0b51420a295f51aa46b3Marcus Hagerott final Drawable emailIcon = ResourcesCompat.getDrawable(getResources(), 14013cbc7482cf5eb745f9ac0b51420a295f51aa46b3Marcus Hagerott R.drawable.quantum_ic_email_vd_theme_24, null).mutate(); 140295a134512bcdca22f3cb149967acb9dbfea309b5yaolu final Entry emailPromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, 140395a134512bcdca22f3cb149967acb9dbfea309b5yaolu emailIcon, getString(R.string.quickcontact_add_email), /* subHeader = */ null, 140495a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* subHeaderIcon = */ null, 140595a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* text = */ null, /* textIcon = */ null, /* primaryContentDescription = */ null, 140695a134512bcdca22f3cb149967acb9dbfea309b5yaolu getEditContactIntent(), /* alternateIcon = */ null, 140795a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* alternateIntent = */ null, /* alternateContentDescription = */ null, 140895a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* shouldApplyColor = */ true, /* isEditable = */ false, 140995a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* EntryContextMenuInfo = */ null, /* thirdIcon = */ null, 141095a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* thirdIntent = */ null, /* thirdContentDescription = */ null, 141195a134512bcdca22f3cb149967acb9dbfea309b5yaolu /* thirdAction = */ Entry.ACTION_NONE, /* thirdExtras = */ null, 1412bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao R.drawable.quantum_ic_email_vd_theme_24); 141395a134512bcdca22f3cb149967acb9dbfea309b5yaolu 141495a134512bcdca22f3cb149967acb9dbfea309b5yaolu promptEntries.add(new ArrayList<Entry>(1)); 141595a134512bcdca22f3cb149967acb9dbfea309b5yaolu promptEntries.get(1).add(emailPromptEntry); 141695a134512bcdca22f3cb149967acb9dbfea309b5yaolu } 14176095369885edcca566a812b551886e29c7ff8039Brian Attwell 14186095369885edcca566a812b551886e29c7ff8039Brian Attwell final int subHeaderTextColor = getResources().getColor( 14196095369885edcca566a812b551886e29c7ff8039Brian Attwell R.color.quickcontact_entry_sub_header_text_color); 14206095369885edcca566a812b551886e29c7ff8039Brian Attwell final PorterDuffColorFilter greyColorFilter = 14216095369885edcca566a812b551886e29c7ff8039Brian Attwell new PorterDuffColorFilter(subHeaderTextColor, PorterDuff.Mode.SRC_ATOP); 1422c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos mNoContactDetailsCard.initialize(promptEntries, 2, /* isExpanded = */ true, 14230cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos /* isAlwaysExpanded = */ true, mExpandingEntryCardViewListener, mScroller); 142479525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mNoContactDetailsCard.getVisibility() == View.GONE && mShouldLog) { 142579525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.NO_CONTACT, 142679525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); 142779525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 14286095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setVisibility(View.VISIBLE); 14296095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setEntryHeaderColor(subHeaderTextColor); 14306095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setColorAndFilter(subHeaderTextColor, greyColorFilter); 14316095369885edcca566a812b551886e29c7ff8039Brian Attwell } 14326095369885edcca566a812b551886e29c7ff8039Brian Attwell 14336095369885edcca566a812b551886e29c7ff8039Brian Attwell /** 1434eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Builds the {@link DataItem}s Map out of the Contact. 1435eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param data The contact to build the data from. 1436eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return A pair containing a list of data items sorted within mimetype and sorted 1437eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * amongst mimetype. The map goes from mimetype string to the sorted list of data items within 1438eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * mimetype 1439eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 14406bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private Cp2DataCardModel generateDataModelFromContact( 1441eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Contact data) { 1442eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("Build data items map"); 1443eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1444eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Map<String, List<DataItem>> dataItemsMap = new HashMap<>(); 14458bf96e78497ea9c8c893bcb357fc1e3175fb2e9bBrian Attwell 14468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final ResolveCache cache = ResolveCache.getInstance(this); 1447851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (RawContact rawContact : data.getRawContacts()) { 1448851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (DataItem dataItem : rawContact.getDataItems()) { 1449eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setRawContactId(rawContact.getId()); 1450eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1451851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final String mimeType = dataItem.getMimeType(); 1452eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (mimeType == null) continue; 1453eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 145447b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final AccountType accountType = rawContact.getAccountType(this); 145547b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final DataKind dataKind = AccountTypeManager.getInstance(this) 145647b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng .getKindOrFallback(accountType, mimeType); 1457eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataKind == null) continue; 1458cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1459eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setDataKind(dataKind); 1460b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1461eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean hasData = !TextUtils.isEmpty(dataItem.buildDataString(this, 1462eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataKind)); 1463899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 1464eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (isMimeExcluded(mimeType) || !hasData) continue; 1465edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1466eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos List<DataItem> dataItemListByType = dataItemsMap.get(mimeType); 1467eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItemListByType == null) { 1468eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType = new ArrayList<>(); 1469eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsMap.put(mimeType, dataItemListByType); 1470edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1471eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType.add(dataItem); 1472edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1473edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 14748a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 1475edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1476eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort within mimetypes"); 147716339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos /* 147816339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos * Sorting is a multi part step. The end result is to a have a sorted list of the most 1479eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * used data items, one per mimetype. Then, within each mimetype, the list of data items 1480eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * for that type is also sorted, based off of {super primary, primary, times used} in that 1481eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * order. 148216339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos */ 1483eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<List<DataItem>> dataItemsList = new ArrayList<>(); 1484eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (List<DataItem> mimeTypeDataItems : dataItemsMap.values()) { 1485eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Remove duplicate data items 1486eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collapser.collapseList(mimeTypeDataItems, this); 1487eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort within mimetype 1488eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(mimeTypeDataItems, mWithinMimeTypeDataItemComparator); 1489eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Add to the list of data item lists 1490eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsList.add(mimeTypeDataItems); 1491edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1492eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 1493edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1494eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort amongst mimetypes"); 1495eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort amongst mimetypes to bubble up the top data items for the contact card 1496eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(dataItemsList, mAmongstMimeTypeDataItemComparator); 1497eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 149816339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos 14996bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Trace.beginSection("cp2 data items to entries"); 15006bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 15016bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> contactCardEntries = new ArrayList<>(); 15026bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> aboutCardEntries = buildAboutCardEntries(dataItemsMap); 15036bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final MutableString aboutCardName = new MutableString(); 15046bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 15056bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell for (int i = 0; i < dataItemsList.size(); ++i) { 15066bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> dataItemsByMimeType = dataItemsList.get(i); 15076bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final DataItem topDataItem = dataItemsByMimeType.get(0); 15086bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (SORTED_ABOUT_CARD_MIMETYPES.contains(topDataItem.getMimeType())) { 15096bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // About card mimetypes are built in buildAboutCardEntries, skip here 15106bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell continue; 15116bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } else { 15126bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell List<Entry> contactEntries = dataItemsToEntries(dataItemsList.get(i), 15136bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell aboutCardName); 15146bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (contactEntries.size() > 0) { 15156bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell contactCardEntries.add(contactEntries); 15166bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 15176bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 15186bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 15196bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 15206bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Trace.endSection(); 15216bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 15226bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final Cp2DataCardModel dataModel = new Cp2DataCardModel(); 15236bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.customAboutCardName = aboutCardName.value; 15246bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.aboutCardEntries = aboutCardEntries; 15256bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.contactCardEntries = contactCardEntries; 15266bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.dataItemsMap = dataItemsMap; 152795a134512bcdca22f3cb149967acb9dbfea309b5yaolu dataModel.areAllRawContactsSimAccounts = data.areAllRawContactsSimAccounts(this); 15286bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell return dataModel; 15296bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 15306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 15316bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 15326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * Class used to hold the About card and Contact cards' data model that gets generated 15336bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * on a background thread. All data is from CP2. 15346bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 15356bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static class Cp2DataCardModel { 15366bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 15376bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * A map between a mimetype string and the corresponding list of data items. The data items 15386bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * are in sorted order using mWithinMimeTypeDataItemComparator. 15396bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 15406bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public Map<String, List<DataItem>> dataItemsMap; 15416bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public List<List<Entry>> aboutCardEntries; 15426bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public List<List<Entry>> contactCardEntries; 15436bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public String customAboutCardName; 154495a134512bcdca22f3cb149967acb9dbfea309b5yaolu public boolean areAllRawContactsSimAccounts; 15456bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 15466bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 15476bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static class MutableString { 15486bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public String value; 1549eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1550edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1551eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 1552eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Converts a {@link DataItem} into an {@link ExpandingEntryCardView.Entry} for display. 1553eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * If the {@link ExpandingEntryCardView.Entry} has no visual elements, null is returned. 15546bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * 15556bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * This runs on a background thread. This is set as static to avoid accidentally adding 15566bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * additional dependencies on unsafe things (like the Activity). 15576bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * 1558eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param dataItem The {@link DataItem} to convert. 15596a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * @param secondDataItem A second {@link DataItem} to help build a full entry for some 15606a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * mimetypes 1561eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return The {@link ExpandingEntryCardView.Entry}, or null if no visual elements are present. 1562eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 15636a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static Entry dataItemToEntry(DataItem dataItem, DataItem secondDataItem, 15646bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Context context, Contact contactData, 15656bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final MutableString aboutCardName) { 1566eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable icon = null; 1567eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String header = null; 1568eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String subHeader = null; 1569eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable subHeaderIcon = null; 1570eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String text = null; 1571eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable textIcon = null; 157223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos StringBuilder primaryContentDescription = new StringBuilder(); 1573b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang Spannable phoneContentDescription = null; 15745da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang Spannable smsContentDescription = null; 1575eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Intent intent = null; 157648ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos boolean shouldApplyColor = true; 1577dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Drawable alternateIcon = null; 1578dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Intent alternateIntent = null; 157923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos StringBuilder alternateContentDescription = new StringBuilder(); 1580eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEditable = false; 15812a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo entryContextMenuInfo = null; 158248fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos Drawable thirdIcon = null; 158348fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos Intent thirdIntent = null; 15845f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn int thirdAction = Entry.ACTION_NONE; 158548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos String thirdContentDescription = null; 15865f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn Bundle thirdExtras = null; 158748290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos int iconResourceId = 0; 1588eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 15896bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell context = context.getApplicationContext(); 159023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos final Resources res = context.getResources(); 1591eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataKind kind = dataItem.getDataKind(); 1592eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1593eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItem instanceof ImDataItem) { 1594eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final ImDataItem im = (ImDataItem) dataItem; 15956bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell intent = ContactsUtils.buildImIntent(context, im).first; 1596eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEmail = im.isCreatedFromEmail(); 15977de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos final int protocol; 15987de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos if (!im.isProtocolValid()) { 15997de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos protocol = Im.PROTOCOL_CUSTOM; 16007de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } else { 16017de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol(); 16027de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } 16037de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos if (protocol == Im.PROTOCOL_CUSTOM) { 16047de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos // If the protocol is custom, display the "IM" entry header as well to distinguish 16057de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos // this entry from other ones 160623e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_im_entry); 160723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos subHeader = Im.getProtocolLabel(res, protocol, 16087de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos im.getCustomProtocol()).toString(); 16097de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos text = im.getData(); 16107de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } else { 161123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = Im.getProtocolLabel(res, protocol, 16127de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos im.getCustomProtocol()).toString(); 16137de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos subHeader = im.getData(); 16147de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } 161597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(im.getData(), header, 161697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1617eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof OrganizationDataItem) { 1618eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final OrganizationDataItem organization = (OrganizationDataItem) dataItem; 161923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_organization_entry); 1620eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = organization.getCompany(); 162197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 162297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1623eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = organization.getTitle(); 1624eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NicknameDataItem) { 1625eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NicknameDataItem nickname = (NicknameDataItem) dataItem; 1626eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Build nickname entries 1627eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isNameRawContact = 16286bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell (contactData.getNameRawContactId() == dataItem.getRawContactId()); 1629eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1630eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean duplicatesTitle = 1631eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos isNameRawContact 16326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell && contactData.getDisplayNameSource() == DisplayNameSources.NICKNAME; 1633eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1634eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!duplicatesTitle) { 163523e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_nickname_entry); 1636eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = nickname.getName(); 163797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 163897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1639eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 16401bd8826c81eff79551c79c3042aca22a1d905524yaolu } else if (dataItem instanceof CustomDataItem) { 16411bd8826c81eff79551c79c3042aca22a1d905524yaolu final CustomDataItem customDataItem = (CustomDataItem) dataItem; 16421bd8826c81eff79551c79c3042aca22a1d905524yaolu final String summary = customDataItem.getSummary(); 16431bd8826c81eff79551c79c3042aca22a1d905524yaolu header = TextUtils.isEmpty(summary) 16441bd8826c81eff79551c79c3042aca22a1d905524yaolu ? res.getString(R.string.label_custom_field) : summary; 16451bd8826c81eff79551c79c3042aca22a1d905524yaolu subHeader = customDataItem.getContent(); 16461bd8826c81eff79551c79c3042aca22a1d905524yaolu entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 16471bd8826c81eff79551c79c3042aca22a1d905524yaolu dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1648eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NoteDataItem) { 1649eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NoteDataItem note = (NoteDataItem) dataItem; 165023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_note_entry); 1651eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = note.getNote(); 165297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 165397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1654eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof WebsiteDataItem) { 1655eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final WebsiteDataItem website = (WebsiteDataItem) dataItem; 165623e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_website_entry); 1657eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = website.getUrl(); 165897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 165997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1660eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos try { 16613bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell final WebAddress webAddress = new WebAddress(website.buildDataStringForDisplay 16623bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell (context, kind)); 1663eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString())); 1664eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ParseException e) { 16653bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell Log.e(TAG, "Couldn't parse website: " + website.buildDataStringForDisplay( 16663bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell context, kind)); 1667eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1668eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EventDataItem) { 1669eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EventDataItem event = (EventDataItem) dataItem; 16703bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell final String dataString = event.buildDataStringForDisplay(context, kind); 1671eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Calendar cal = DateUtils.parseDate(dataString, false); 1672eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (cal != null) { 1673eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Date nextAnniversary = 1674eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DateUtils.getNextAnnualDate(cal); 1675eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); 1676eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos builder.appendPath("time"); 1677eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos ContentUris.appendId(builder, nextAnniversary.getTime()); 1678eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW).setData(builder.build()); 1679eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 168023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_event_entry); 1681f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (event.hasKindTypeColumn(kind)) { 1682c85af2872f231f48b586c30f6306083a039dd6c6Wenyi Wang subHeader = EventCompat.getTypeLabel(res, event.getKindTypeColumn(kind), 16837de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos event.getLabel()).toString(); 1684f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 16856bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell text = DateUtils.formatDate(context, dataString); 168697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(text, header, 168797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1688eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof RelationDataItem) { 1689eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final RelationDataItem relation = (RelationDataItem) dataItem; 16903bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell final String dataString = relation.buildDataStringForDisplay(context, kind); 1691eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(dataString)) { 1692eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SEARCH); 1693eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.putExtra(SearchManager.QUERY, dataString); 1694eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.setType(Contacts.CONTENT_TYPE); 1695eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 169623e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_relation_entry); 1697eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = relation.getName(); 169897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 169997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1700f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (relation.hasKindTypeColumn(kind)) { 170123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = Relation.getTypeLabel(res, 17026bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell relation.getKindTypeColumn(kind), 1703f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos relation.getLabel()).toString(); 1704f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1705eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof PhoneDataItem) { 1706eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final PhoneDataItem phone = (PhoneDataItem) dataItem; 17075f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn String phoneLabel = null; 1708eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(phone.getNumber())) { 170923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(res.getString(R.string.call_other)).append(" "); 17103bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell header = sBidiFormatter.unicodeWrap(phone.buildDataStringForDisplay(context, kind), 1711c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwell TextDirectionHeuristics.LTR); 17122a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 171397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), 171497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getId(), dataItem.isSuperPrimary()); 1715f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (phone.hasKindTypeColumn(kind)) { 171601b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang final int kindTypeColumn = phone.getKindTypeColumn(kind); 171701b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang final String label = phone.getLabel(); 17185f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phoneLabel = label; 171901b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang if (kindTypeColumn == Phone.TYPE_CUSTOM && TextUtils.isEmpty(label)) { 172001b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang text = ""; 172101b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang } else { 172201b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang text = Phone.getTypeLabel(res, kindTypeColumn, label).toString(); 17235f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phoneLabel= text; 17243df785b0ad0c0292adfc03a4f804d1b38053de63Tingting Wang primaryContentDescription.append(text).append(" "); 17253df785b0ad0c0292adfc03a4f804d1b38053de63Tingting Wang } 1726f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 172723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(header); 172869c182afb0e6d82a341a28b4317aa703af768906Gary Mai phoneContentDescription = com.android.contacts.util.ContactDisplayUtils 1729b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang .getTelephoneTtsSpannable(primaryContentDescription.toString(), header); 1730bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao iconResourceId = R.drawable.quantum_ic_phone_vd_theme_24; 1731bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao icon = res.getDrawable(iconResourceId); 17326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (PhoneCapabilityTester.isPhone(context)) { 1733eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(phone.getNumber()); 173479525d024526e0f26b9dff40162b91f7c53f17a6yaolu intent.putExtra(EXTRA_ACTION_TYPE, ActionType.CALL); 173516339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1736dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIntent = new Intent(Intent.ACTION_SENDTO, 17371cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phone.getNumber(), null)); 173879525d024526e0f26b9dff40162b91f7c53f17a6yaolu alternateIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.SMS); 173948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos 1740bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao alternateIcon = res.getDrawable(R.drawable.quantum_ic_message_vd_theme_24); 174123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.append(res.getString(R.string.sms_custom, header)); 174269c182afb0e6d82a341a28b4317aa703af768906Gary Mai smsContentDescription = com.android.contacts.util.ContactDisplayUtils 17435da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang .getTelephoneTtsSpannable(alternateContentDescription.toString(), header); 174448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos 17450a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn int videoCapability = CallUtil.getVideoCallingAvailability(context); 17460a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn boolean isPresenceEnabled = 17470a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn (videoCapability & CallUtil.VIDEO_CALLING_PRESENCE) != 0; 17480a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn boolean isVideoEnabled = (videoCapability & CallUtil.VIDEO_CALLING_ENABLED) != 0; 17490a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn 17505f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn if (CallUtil.isCallWithSubjectSupported(context)) { 1751bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao thirdIcon = res.getDrawable(R.drawable.quantum_ic_perm_phone_msg_vd_theme_24); 17525f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdAction = Entry.ACTION_CALL_WITH_SUBJECT; 17535f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdContentDescription = 17545f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn res.getString(R.string.call_with_a_note); 17555f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn // Create a bundle containing the data the call subject dialog requires. 17565f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras = new Bundle(); 17575f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putLong(CallSubjectDialog.ARG_PHOTO_ID, 17585f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn contactData.getPhotoId()); 17595f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putParcelable(CallSubjectDialog.ARG_PHOTO_URI, 17605f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn UriUtils.parseUriOrNull(contactData.getPhotoUri())); 17615f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putParcelable(CallSubjectDialog.ARG_CONTACT_URI, 17625f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn contactData.getLookupUri()); 17635f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putString(CallSubjectDialog.ARG_NAME_OR_NUMBER, 17645f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn contactData.getDisplayName()); 17655f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putBoolean(CallSubjectDialog.ARG_IS_BUSINESS, false); 17665f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putString(CallSubjectDialog.ARG_NUMBER, 17675f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phone.getNumber()); 17685f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putString(CallSubjectDialog.ARG_DISPLAY_NUMBER, 17695f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phone.getFormattedPhoneNumber()); 17705f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putString(CallSubjectDialog.ARG_NUMBER_LABEL, 17715f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phoneLabel); 17720a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn } else if (isVideoEnabled) { 17730a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn // Check to ensure carrier presence indicates the number supports video calling. 17740a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn int carrierPresence = dataItem.getCarrierPresence(); 17750a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn boolean isPresent = (carrierPresence & Phone.CARRIER_PRESENCE_VT_CAPABLE) != 0; 17760a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn 17770a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn if ((isPresenceEnabled && isPresent) || !isPresenceEnabled) { 1778bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao thirdIcon = res.getDrawable(R.drawable.quantum_ic_videocam_vd_theme_24); 17790a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn thirdAction = Entry.ACTION_INTENT; 17800a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn thirdIntent = CallUtil.getVideoCallIntent(phone.getNumber(), 17810a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY); 178279525d024526e0f26b9dff40162b91f7c53f17a6yaolu thirdIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.VIDEOCALL); 17830a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn thirdContentDescription = 17840a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn res.getString(R.string.description_video_call); 17850a8f9736d1af8903674c412cf88c1233b60a156eTyler Gunn } 178648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos } 1787eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1788eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EmailDataItem) { 1789eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EmailDataItem email = (EmailDataItem) dataItem; 1790eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String address = email.getData(); 1791eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(address)) { 179223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(res.getString(R.string.email_other)).append(" "); 17931cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner final Uri mailUri = Uri.fromParts(ContactsUtils.SCHEME_MAILTO, address, null); 1794eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SENDTO, mailUri); 179579525d024526e0f26b9dff40162b91f7c53f17a6yaolu intent.putExtra(EXTRA_ACTION_TYPE, ActionType.EMAIL); 1796eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = email.getAddress(); 17972a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 179897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos res.getString(R.string.emailLabelsGroup), dataItem.getMimeType(), 179997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getId(), dataItem.isSuperPrimary()); 1800f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (email.hasKindTypeColumn(kind)) { 180123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = Email.getTypeLabel(res, email.getKindTypeColumn(kind), 1802f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos email.getLabel()).toString(); 180323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(text).append(" "); 1804f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 180523e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(header); 1806bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao iconResourceId = R.drawable.quantum_ic_email_vd_theme_24; 1807bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao icon = res.getDrawable(iconResourceId); 1808eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1809eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredPostalDataItem) { 1810eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos StructuredPostalDataItem postal = (StructuredPostalDataItem) dataItem; 1811eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String postalAddress = postal.getFormattedAddress(); 1812eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(postalAddress)) { 181323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(res.getString(R.string.map_other)).append(" "); 1814eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress); 18157a09c70af86b9f3bae52c102ebfb6a32b99e7409yaolu intent.putExtra(EXTRA_ACTION_TYPE, ActionType.ADDRESS); 1816eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = postal.getFormattedAddress(); 18172a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 181897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos res.getString(R.string.postalLabelsGroup), dataItem.getMimeType(), 181997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getId(), dataItem.isSuperPrimary()); 1820f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (postal.hasKindTypeColumn(kind)) { 182123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = StructuredPostal.getTypeLabel(res, 1822f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos postal.getKindTypeColumn(kind), postal.getLabel()).toString(); 182323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(text).append(" "); 1824f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 182523e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(header); 18266a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos alternateIntent = 18276a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos StructuredPostalUtils.getViewPostalAddressDirectionsIntent(postalAddress); 182879525d024526e0f26b9dff40162b91f7c53f17a6yaolu alternateIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.DIRECTIONS); 1829bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao alternateIcon = res.getDrawable(R.drawable.quantum_ic_directions_vd_theme_24); 183023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.append(res.getString( 183123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos R.string.content_description_directions)).append(" ").append(header); 1832bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao iconResourceId = R.drawable.quantum_ic_place_vd_theme_24; 1833bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao icon = res.getDrawable(iconResourceId); 1834eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1835eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof SipAddressDataItem) { 1836593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell final SipAddressDataItem sip = (SipAddressDataItem) dataItem; 1837593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell final String address = sip.getSipAddress(); 1838593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell if (!TextUtils.isEmpty(address)) { 1839593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell primaryContentDescription.append(res.getString(R.string.call_other)).append( 1840593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell " "); 1841593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell if (PhoneCapabilityTester.isSipPhone(context)) { 18421cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner final Uri callUri = Uri.fromParts(PhoneAccount.SCHEME_SIP, address, null); 1843eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(callUri); 184479525d024526e0f26b9dff40162b91f7c53f17a6yaolu intent.putExtra(EXTRA_ACTION_TYPE, ActionType.SIPCALL); 184516339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1846593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell header = address; 1847593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell entryContextMenuInfo = new EntryContextMenuInfo(header, 1848593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), 1849593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell dataItem.getId(), dataItem.isSuperPrimary()); 1850593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell if (sip.hasKindTypeColumn(kind)) { 1851593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell text = SipAddress.getTypeLabel(res, 1852593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell sip.getKindTypeColumn(kind), sip.getLabel()).toString(); 1853593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell primaryContentDescription.append(text).append(" "); 1854593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell } 1855593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell primaryContentDescription.append(header); 1856bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao iconResourceId = R.drawable.quantum_ic_dialer_sip_vd_theme_24; 1857bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao icon = res.getDrawable(iconResourceId); 1858edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1859eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredNameDataItem) { 18608025f801f5153917781a9496cabdd81ae1b6deafWalter Jang // If the name is already set and this is not the super primary value then leave the 18618025f801f5153917781a9496cabdd81ae1b6deafWalter Jang // current value. This way we show the super primary value when we are able to. 18628025f801f5153917781a9496cabdd81ae1b6deafWalter Jang if (dataItem.isSuperPrimary() || aboutCardName.value == null 18638025f801f5153917781a9496cabdd81ae1b6deafWalter Jang || aboutCardName.value.isEmpty()) { 18648025f801f5153917781a9496cabdd81ae1b6deafWalter Jang final String givenName = ((StructuredNameDataItem) dataItem).getGivenName(); 18658025f801f5153917781a9496cabdd81ae1b6deafWalter Jang if (!TextUtils.isEmpty(givenName)) { 18668025f801f5153917781a9496cabdd81ae1b6deafWalter Jang aboutCardName.value = res.getString(R.string.about_card_title) + 18678025f801f5153917781a9496cabdd81ae1b6deafWalter Jang " " + givenName; 18688025f801f5153917781a9496cabdd81ae1b6deafWalter Jang } else { 18698025f801f5153917781a9496cabdd81ae1b6deafWalter Jang aboutCardName.value = res.getString(R.string.about_card_title); 18708025f801f5153917781a9496cabdd81ae1b6deafWalter Jang } 1871eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1872eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1873eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Custom DataItem 18746bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = dataItem.buildDataStringForDisplay(context, kind); 1875eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = kind.typeColumn; 1876eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW); 187760e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, dataItem.getId()); 187860e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos intent.setDataAndType(uri, dataItem.getMimeType()); 187979525d024526e0f26b9dff40162b91f7c53f17a6yaolu intent.putExtra(EXTRA_ACTION_TYPE, ActionType.THIRD_PARTY); 1880a92b2d193ddab97597334075a824a3575d71cb8ayaolu intent.putExtra(EXTRA_THIRD_PARTY_ACTION, dataItem.getMimeType()); 1881e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 1882e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (intent != null) { 1883e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos final String mimetype = intent.getType(); 1884e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 18856a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Build advanced entry for known 3p types. Otherwise default to ResolveCache icon. 18868c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu if (MIMETYPE_HANGOUTS.equals(mimetype)) { 18878c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu // If a secondDataItem is available, use it to build an entry with 18888c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu // alternate actions 18898c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu if (secondDataItem != null) { 1890bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao icon = res.getDrawable(R.drawable.quantum_ic_hangout_vd_theme_24); 1891bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao alternateIcon = res.getDrawable( 1892bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao R.drawable.quantum_ic_hangout_video_vd_theme_24); 18938c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu final HangoutsDataItemModel itemModel = 18948c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu new HangoutsDataItemModel(intent, alternateIntent, 18958c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu dataItem, secondDataItem, alternateContentDescription, 18968c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu header, text, context); 18978c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu 18988c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu populateHangoutsDataItemModel(itemModel); 18998c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu intent = itemModel.intent; 19008c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu alternateIntent = itemModel.alternateIntent; 19018c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu alternateContentDescription = itemModel.alternateContentDescription; 19028c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu header = itemModel.header; 19038c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu text = itemModel.text; 19048c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu } else { 19058c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu if (HANGOUTS_DATA_5_VIDEO.equals(intent.getDataString())) { 1906bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao icon = res.getDrawable(R.drawable.quantum_ic_hangout_video_vd_theme_24); 19076a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 1908bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao icon = res.getDrawable(R.drawable.quantum_ic_hangout_vd_theme_24); 1909e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 19108c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu } 19118c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu } else { 19128c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu icon = ResolveCache.getInstance(context).getIcon( 19138c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu dataItem.getMimeType(), intent); 19148c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu // Call mutate to create a new Drawable.ConstantState for color filtering 19158c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu if (icon != null) { 19168c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu icon.mutate(); 19178c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu } 19188c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu shouldApplyColor = false; 19198c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu 19208c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu if (!MIMETYPE_GPLUS_PROFILE.equals(mimetype)) { 192197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, mimetype, 192297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), 192397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.isSuperPrimary()); 19248c3ff2c7fdff3c82e927b43fd3bdcab1b0a8b866yaolu } 1925e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1926e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1927eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1928b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1929eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (intent != null) { 1930eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Do not set the intent is there are no resolves 19316bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!PhoneCapabilityTester.isIntentRegistered(context, intent)) { 1932eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = null; 1933eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1934eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1935eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1936dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (alternateIntent != null) { 1937dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Do not set the alternate intent is there are no resolves 19386bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!PhoneCapabilityTester.isIntentRegistered(context, alternateIntent)) { 1939dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIntent = null; 1940f0d04c11b649e953177e79722d05fa048e53273dJay Shrauner } else if (TextUtils.isEmpty(alternateContentDescription)) { 1941f0d04c11b649e953177e79722d05fa048e53273dJay Shrauner // Attempt to use package manager to find a suitable content description if needed 194223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.append(getIntentResolveLabel(alternateIntent, context)); 1943dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1944dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1945dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1946eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // If the Entry has no visual elements, return null 1947eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) && 1948eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeaderIcon == null && TextUtils.isEmpty(text) && textIcon == null) { 1949eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return null; 1950eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1951eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1952fa238949855fba3b28a57fad3d585b13e80362bbBrian Attwell // Ignore dataIds from the Me profile. 1953ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final int dataId = dataItem.getId() > Integer.MAX_VALUE ? 1954ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos -1 : (int) dataItem.getId(); 1955ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 195623e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon, 1957b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang phoneContentDescription == null 1958b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang ? new SpannableString(primaryContentDescription.toString()) 1959b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang : phoneContentDescription, 19607ce5352a70e8aaf120bf4f7bd05d595f46abb080Walter Jang intent, alternateIcon, alternateIntent, 19615da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang smsContentDescription == null 19625da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang ? new SpannableString(alternateContentDescription.toString()) 19635da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang : smsContentDescription, 19645da55ff837f57a63b409cd495cc25f61ed6fd709Wenyi Wang shouldApplyColor, isEditable, 19655f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn entryContextMenuInfo, thirdIcon, thirdIntent, thirdContentDescription, thirdAction, 19665f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras, iconResourceId); 1967eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1968eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 19696bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private List<Entry> dataItemsToEntries(List<DataItem> dataItems, 19706bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell MutableString aboutCardTitleOut) { 19716a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Hangouts and G+ use two data items to create one entry. 19723904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu if (dataItems.get(0).getMimeType().equals(MIMETYPE_GPLUS_PROFILE)) { 19733904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu return gPlusDataItemsToEntries(dataItems); 19743904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } else if (dataItems.get(0).getMimeType().equals(MIMETYPE_HANGOUTS)) { 19753904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu return hangoutsDataItemsToEntries(dataItems); 19766a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 19776a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final List<Entry> entries = new ArrayList<>(); 19786a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos for (DataItem dataItem : dataItems) { 19796a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, 19806a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this, mContactData, aboutCardTitleOut); 19816a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (entry != null) { 19826a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos entries.add(entry); 19836a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 19846a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 19856a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos return entries; 19866a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 19876a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 19886a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 19896a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /** 19903904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * Put the data items into buckets based on the raw contact id 19916a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos */ 19923904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu private Map<Long, List<DataItem>> dataItemsToBucket(List<DataItem> dataItems) { 19936a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Map<Long, List<DataItem>> buckets = new HashMap<>(); 1994eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (DataItem dataItem : dataItems) { 19956a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos List<DataItem> bucket = buckets.get(dataItem.getRawContactId()); 19966a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (bucket == null) { 19976a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos bucket = new ArrayList<>(); 19986a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos buckets.put(dataItem.getRawContactId(), bucket); 19996a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 20006a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos bucket.add(dataItem); 20016a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 20023904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu return buckets; 20033904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } 20043904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu 20053904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu /** 20063904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * For G+ entries, a single ExpandingEntryCardView.Entry consists of two data items. This 20073904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * method use only the View profile to build entry. 20083904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu */ 20093904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu private List<Entry> gPlusDataItemsToEntries(List<DataItem> dataItems) { 20103904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu final List<Entry> entries = new ArrayList<>(); 20113904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu 20123904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu for (List<DataItem> bucket : dataItemsToBucket(dataItems).values()) { 20133904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu for (DataItem dataItem : bucket) { 20143904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu if (GPLUS_PROFILE_DATA_5_VIEW_PROFILE.equals( 20153904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu dataItem.getContentValues().getAsString(Data.DATA5))) { 20163904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, 20173904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu this, mContactData, /* aboutCardName = */ null); 20183904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu if (entry != null) { 20193904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu entries.add(entry); 20203904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } 20213904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } 20223904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } 20233904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } 20243904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu return entries; 20253904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu } 20263904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu 20273904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu /** 20283904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * For Hangouts entries, a single ExpandingEntryCardView.Entry consists of two data items. This 20293904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * method attempts to build each entry using the two data items if they are available. If there 20303904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * are more or less than two data items, a fall back is used and each data item gets its own 20313904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * entry. 20323904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu */ 20333904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu private List<Entry> hangoutsDataItemsToEntries(List<DataItem> dataItems) { 20343904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu final List<Entry> entries = new ArrayList<>(); 20356a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 20366a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Use the buckets to build entries. If a bucket contains two data items, build the special 20376a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // entry, otherwise fall back to the normal entry. 20383904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu for (List<DataItem> bucket : dataItemsToBucket(dataItems).values()) { 20396a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (bucket.size() == 2) { 20406a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Use the pair to build an entry 20416a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Entry entry = dataItemToEntry(bucket.get(0), 20426a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /* secondDataItem = */ bucket.get(1), this, mContactData, 20436a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /* aboutCardName = */ null); 20446a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (entry != null) { 20456a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos entries.add(entry); 20466a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 20476a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 20486a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos for (DataItem dataItem : bucket) { 20496a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, 20506a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this, mContactData, /* aboutCardName = */ null); 20516a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (entry != null) { 20526a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos entries.add(entry); 20536a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 20546a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 2055eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 2056eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 2057eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return entries; 2058edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 2059edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 20606a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /** 20613904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * Used for statically passing around Hangouts data items and entry fields to 20623904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu * populateHangoutsDataItemModel. 20636a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos */ 20643904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu private static final class HangoutsDataItemModel { 20656a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public Intent intent; 20666a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public Intent alternateIntent; 20676a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public DataItem dataItem; 20686a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public DataItem secondDataItem; 20696a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public StringBuilder alternateContentDescription; 20706a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public String header; 20716a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public String text; 20726a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public Context context; 20736a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 20743904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu public HangoutsDataItemModel(Intent intent, Intent alternateIntent, DataItem dataItem, 20756a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos DataItem secondDataItem, StringBuilder alternateContentDescription, String header, 20766a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos String text, Context context) { 20776a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.intent = intent; 20786a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.alternateIntent = alternateIntent; 20796a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.dataItem = dataItem; 20806a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.secondDataItem = secondDataItem; 20816a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.alternateContentDescription = alternateContentDescription; 20826a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.header = header; 20836a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.text = text; 20846a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.context = context; 20856a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 20866a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 20876a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 20883904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu private static void populateHangoutsDataItemModel( 20893904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu HangoutsDataItemModel dataModel) { 20906a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Intent secondIntent = new Intent(Intent.ACTION_VIEW); 20916a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos secondIntent.setDataAndType(ContentUris.withAppendedId(Data.CONTENT_URI, 20926a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.getId()), dataModel.secondDataItem.getMimeType()); 209379525d024526e0f26b9dff40162b91f7c53f17a6yaolu secondIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.THIRD_PARTY); 2094a92b2d193ddab97597334075a824a3575d71cb8ayaolu secondIntent.putExtra(EXTRA_THIRD_PARTY_ACTION, dataModel.secondDataItem.getMimeType()); 209579525d024526e0f26b9dff40162b91f7c53f17a6yaolu 20966a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // There is no guarantee the order the data items come in. Second 20976a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // data item does not necessarily mean it's the alternate. 20983904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu // Hangouts video should be alternate. Swap if needed 20996a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (HANGOUTS_DATA_5_VIDEO.equals( 21003904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu dataModel.dataItem.getContentValues().getAsString(Data.DATA5))) { 21016a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateIntent = dataModel.intent; 21026a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateContentDescription = new StringBuilder(dataModel.header); 21036a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 21046a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.intent = secondIntent; 2105a92b2d193ddab97597334075a824a3575d71cb8ayaolu dataModel.header = dataModel.secondDataItem.buildDataStringForDisplay( 2106a92b2d193ddab97597334075a824a3575d71cb8ayaolu dataModel.context, dataModel.secondDataItem.getDataKind()); 21076a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.text = dataModel.secondDataItem.getDataKind().typeColumn; 21086a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else if (HANGOUTS_DATA_5_MESSAGE.equals( 21093904fb54a1ab93992eacc03d29c93cf57337ea7fyaolu dataModel.dataItem.getContentValues().getAsString(Data.DATA5))) { 21106a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateIntent = secondIntent; 21116a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateContentDescription = new StringBuilder( 21126a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.buildDataStringForDisplay(dataModel.context, 21136a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.getDataKind())); 21146a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21156a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21166a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 21176bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static String getIntentResolveLabel(Intent intent, Context context) { 21186bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, 2119dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos PackageManager.MATCH_DEFAULT_ONLY); 2120dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 2121dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Pick first match, otherwise best found 2122dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos ResolveInfo bestResolve = null; 2123dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos final int size = matches.size(); 2124dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (size == 1) { 2125dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos bestResolve = matches.get(0); 2126dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } else if (size > 1) { 21276bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell bestResolve = ResolveCache.getInstance(context).getBestResolve(intent, matches); 2128dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 2129dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 2130dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (bestResolve == null) { 2131dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos return null; 2132dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 2133dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 21346bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell return String.valueOf(bestResolve.loadLabel(context.getPackageManager())); 2135dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 2136dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 2137edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 213831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * Asynchronously extract the most vibrant color from the PhotoView. Once extracted, 213931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms 214031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * on a Nexus 5. 214131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell */ 214231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell private void extractAndApplyTintFromPhotoViewAsynchronously() { 214331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell if (mScroller == null) { 214431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell return; 214531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 214631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell final Drawable imageViewDrawable = mPhotoView.getDrawable(); 2147faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell new AsyncTask<Void, Void, MaterialPalette>() { 214831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 2149faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell protected MaterialPalette doInBackground(Void... params) { 2150faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell 2151929a62f5c1bcdc3773270f7d189d88c0464b36adJay Shrauner if (imageViewDrawable instanceof BitmapDrawable && mContactData != null 215295c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell && mContactData.getThumbnailPhotoBinaryData() != null 215395c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell && mContactData.getThumbnailPhotoBinaryData().length > 0) { 215495c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell // Perform the color analysis on the thumbnail instead of the full sized 215595c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell // image, so that our results will be as similar as possible to the Bugle 215695c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell // app. 215795c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell final Bitmap bitmap = BitmapFactory.decodeByteArray( 215895c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell mContactData.getThumbnailPhotoBinaryData(), 0, 215995c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell mContactData.getThumbnailPhotoBinaryData().length); 216095c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell try { 216195c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell final int primaryColor = colorFromBitmap(bitmap); 216295c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell if (primaryColor != 0) { 216395c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor( 216495c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell primaryColor); 216595c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell } 216695c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell } finally { 216795c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell bitmap.recycle(); 2168faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell } 21698a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 21708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (imageViewDrawable instanceof LetterTileDrawable) { 2171faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell final int primaryColor = ((LetterTileDrawable) imageViewDrawable).getColor(); 2172a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(primaryColor); 217331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 2174a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return MaterialColorMapUtils.getDefaultPrimaryAndSecondaryColors(getResources()); 217531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 217631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 217731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 2178faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell protected void onPostExecute(MaterialPalette palette) { 2179faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell super.onPostExecute(palette); 21808571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (mHasComputedThemeColor) { 21818571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // If we had previously computed a theme color from the contact photo, 21828571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // then do not update the theme color. Changing the theme color several 21838571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // seconds after QC has started, as a result of an updated/upgraded photo, 21848571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // is a jarring experience. On the other hand, changing the theme color after 21858571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // a rotation or onNewIntent() is perfectly fine. 21868571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell return; 21878571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell } 21888571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // Check that the Photo has not changed. If it has changed, the new tint 21898571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // color needs to be extracted 21908571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (imageViewDrawable == mPhotoView.getDrawable()) { 21918571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = true; 2192faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell setThemeColor(palette); 219331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 219431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 219531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell }.execute(); 219631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 219731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 2198faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell private void setThemeColor(MaterialPalette palette) { 21999b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // If the color is invalid, use the predefined default 22008e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mColorFilterColor = palette.mPrimaryColor; 22018e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mScroller.setHeaderTintColor(mColorFilterColor); 2202faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mStatusBarColor = palette.mSecondaryColor; 22039b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell updateStatusBarColor(); 22048571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell 22059b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mColorFilter = 22068e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell new PorterDuffColorFilter(mColorFilterColor, PorterDuff.Mode.SRC_ATOP); 22078e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mContactCard.setColorAndFilter(mColorFilterColor, mColorFilter); 22088e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mRecentCard.setColorAndFilter(mColorFilterColor, mColorFilter); 22098e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mAboutCard.setColorAndFilter(mColorFilterColor, mColorFilter); 22109b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 22119b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 22128a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void updateStatusBarColor() { 22134c3d3e24b0de8b4170106e312f6a4ac8139e1242Wenyi Wang if (mScroller == null || !CompatUtils.isLollipopCompatible()) { 22148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 22158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 22168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int desiredStatusBarColor; 22178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Only use a custom status bar color if QuickContacts touches the top of the viewport. 22188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller.getScrollNeededToBeFullScreen() <= 0) { 22198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = mStatusBarColor; 22208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } else { 22218a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = Color.TRANSPARENT; 22228a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 22238a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Animate to the new color. 2224847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor", 2225847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell getWindow().getStatusBarColor(), desiredStatusBarColor); 2226847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION); 2227847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.setEvaluator(new ArgbEvaluator()); 2228847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.start(); 22298a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 22308a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 22318a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int colorFromBitmap(Bitmap bitmap) { 22328a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Author of Palette recommends using 24 colors when analyzing profile photos. 22338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int NUMBER_OF_PALETTE_COLORS = 24; 22348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final Palette palette = Palette.generate(bitmap, NUMBER_OF_PALETTE_COLORS); 2235a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell if (palette != null && palette.getVibrantSwatch() != null) { 2236a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell return palette.getVibrantSwatch().getRgb(); 22378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 22388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return 0; 22398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 22408a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 2241b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) { 2242eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> entries = new ArrayList<>(); 2243b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos for (ContactInteraction interaction : interactions) { 2244ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (interaction == null) { 2245ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell continue; 2246ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2247ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos entries.add(new Entry(/* id = */ -1, 2248ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos interaction.getIcon(this), 2249b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewHeader(this), 2250b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewBody(this), 2251b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getBodyIcon(this), 2252b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewFooter(this), 2253b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getFooterIcon(this), 225423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos interaction.getContentDescription(this), 2255b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getIntent(), 2256dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIcon = */ null, 2257dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIntent = */ null, 2258dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateContentDescription = */ null, 225948ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos /* shouldApplyColor = */ true, 22602a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, 226148fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* EntryContextMenuInfo = */ null, 226248fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, 226348fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIntent = */ null, 226448290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos /* thirdContentDescription = */ null, 22655f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdAction = */ Entry.ACTION_NONE, 22665f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdActionExtras = */ null, 226748290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos interaction.getIconResourceId())); 2268b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2269b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return entries; 2270b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2271b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2272eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<Contact> mLoaderContactCallbacks = 2273851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu new LoaderCallbacks<Contact>() { 2274cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 2275851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoaderReset(Loader<Contact> loader) { 2276405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos mContactData = null; 2277cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2278cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2279cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 2280851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoadFinished(Loader<Contact> loader, Contact data) { 22818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onLoadFinished()"); 2282930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell try { 22838a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 2284930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell if (isFinishing()) { 2285930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell return; 2286930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } 2287930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell if (data.isError()) { 228802ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner // This means either the contact is invalid or we had an 228902ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner // internal error such as an acore crash. 229002ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner Log.i(TAG, "Failed to load contact: " + ((ContactLoader)loader).getLookupUri()); 229102ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, 229202ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner Toast.LENGTH_LONG).show(); 229302ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner finish(); 229402ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner return; 2295930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } 2296930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell if (data.isNotFound()) { 22978a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri()); 22988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, 22998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.LENGTH_LONG).show(); 2300930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell finish(); 2301930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell return; 23028a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 2303cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2304677ee2bd9c37f3bc4cbfd1f05b3c93f12a7299f3Marcus Hagerott if (!mIsRecreatedInstance && !mShortcutUsageReported && data != null) { 2305d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerott mShortcutUsageReported = true; 2306d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerott DynamicShortcuts.reportShortcutUsed(QuickContactActivity.this, 2307d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerott data.getLookupKey()); 2308d105c1e23485927b408ee6041d6fac8a71267768Marcus Hagerott } 2309930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell bindContactData(data); 2310cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2311930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } finally { 2312930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell Trace.endSection(); 2313930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } 2314cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2315cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2316cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 2317851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public Loader<Contact> onCreateLoader(int id, Bundle args) { 2318cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (mLookupUri == null) { 2319cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann Log.wtf(TAG, "Lookup uri wasn't initialized. Loader was started too early"); 2320cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2321d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Load all contact data. We need loadGroupMetaData=true to determine whether the 2322d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // contact is invisible. If it is, we need to display an "Add to Contacts" MenuItem. 2323b2b435a944947fbf1965c3bb7c202a97f0273259Yorke Lee return new ContactLoader(getApplicationContext(), mLookupUri, 2324881ffc06e71730db2e6f8e306333241d8ca64bf8Marcus Hagerott true /*loadGroupMetaData*/, true /*postViewNotification*/, 2325881ffc06e71730db2e6f8e306333241d8ca64bf8Marcus Hagerott true /*computeFormattedPhoneNumber*/); 2326cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2327cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann }; 2328b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2329b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 2330b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onBackPressed() { 2331ac9596e825bf8256487d836a266862e79a24206dTingting Wang final int previousScreenType = getIntent().getIntExtra 2332ac9596e825bf8256487d836a266862e79a24206dTingting Wang (EXTRA_PREVIOUS_SCREEN_TYPE, ScreenType.UNKNOWN); 2333ac9596e825bf8256487d836a266862e79a24206dTingting Wang if ((previousScreenType == ScreenType.ALL_CONTACTS 2334ac9596e825bf8256487d836a266862e79a24206dTingting Wang || previousScreenType == ScreenType.FAVORITES) 2335ac9596e825bf8256487d836a266862e79a24206dTingting Wang && !SharedPreferenceUtil.getHamburgerPromoTriggerActionHappenedBefore(this)) { 2336ac9596e825bf8256487d836a266862e79a24206dTingting Wang SharedPreferenceUtil.setHamburgerPromoTriggerActionHappenedBefore(this); 2337ac9596e825bf8256487d836a266862e79a24206dTingting Wang } 2338b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell if (mScroller != null) { 23398477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell if (!mIsExitAnimationInProgress) { 23408477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mScroller.scrollOffBottom(); 23418477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 2342b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } else { 2343b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell super.onBackPressed(); 2344b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 2345b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 2346b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 23478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 23488a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void finish() { 23498a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.finish(); 23508a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 23518a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // override transitions to skip the standard window animations 23528a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell overridePendingTransition(0, 0); 23538a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 23548a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 2355eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<List<ContactInteraction>> mLoaderInteractionsCallbacks = 2356b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos new LoaderCallbacks<List<ContactInteraction>>() { 2357b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2358b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 2359b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public Loader<List<ContactInteraction>> onCreateLoader(int id, Bundle args) { 2360b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Loader<List<ContactInteraction>> loader = null; 2361b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos switch (id) { 2362b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos case LOADER_SMS_ID: 2363b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos loader = new SmsInteractionsLoader( 2364b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos QuickContactActivity.this, 2365ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 2366b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos MAX_SMS_RETRIEVE); 2367b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos break; 2368899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos case LOADER_CALENDAR_ID: 2369ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos final String[] emailsArray = args.getStringArray(KEY_LOADER_EXTRA_EMAILS); 2370ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos List<String> emailsList = null; 2371ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos if (emailsArray != null) { 2372ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos emailsList = Arrays.asList(args.getStringArray(KEY_LOADER_EXTRA_EMAILS)); 2373ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos } 2374899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos loader = new CalendarInteractionsLoader( 2375899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos QuickContactActivity.this, 2376ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos emailsList, 2377899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_FUTURE_CALENDAR_RETRIEVE, 2378899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_PAST_CALENDAR_RETRIEVE, 2379899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR, 2380899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR); 2381899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos break; 2382ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos case LOADER_CALL_LOG_ID: 2383ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos loader = new CallLogInteractionsLoader( 2384ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.this, 2385ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 2386c7a4b9c2c76cb5a762db84677d01fb528da58ec3guanxiongliu args.getStringArray(KEY_LOADER_EXTRA_SIP_NUMBERS), 2387ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos MAX_CALL_LOG_RETRIEVE); 2388b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2389b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return loader; 2390b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2391b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2392b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 2393b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoadFinished(Loader<List<ContactInteraction>> loader, 2394b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos List<ContactInteraction> data) { 2395b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.put(loader.getId(), data); 2396b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2397b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos if (isAllRecentDataLoaded()) { 2398b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos bindRecentData(); 2399b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2400b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2401b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2402b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 2403b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoaderReset(Loader<List<ContactInteraction>> loader) { 2404b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.remove(loader.getId()); 2405b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2406b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos }; 2407b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2408b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private boolean isAllRecentDataLoaded() { 2409b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return mRecentLoaderResults.size() == mRecentLoaderIds.length; 2410b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2411b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2412b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private void bindRecentData() { 2413eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<ContactInteraction> allInteractions = new ArrayList<>(); 241430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell final List<List<Entry>> interactionsWrapper = new ArrayList<>(); 2415b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2416ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell // Serialize mRecentLoaderResults into a single list. This should be done on the main 2417ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell // thread to avoid races against mRecentLoaderResults edits. 2418ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) { 2419ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell allInteractions.addAll(loaderInteractions); 2420ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2421ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell 242230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask = new AsyncTask<Void, Void, Void>() { 2423b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 242430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell protected Void doInBackground(Void... params) { 242530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.beginSection("sort recent loader results"); 242630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 242730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // Sort the interactions by most recent 242830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Collections.sort(allInteractions, new Comparator<ContactInteraction>() { 242930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell @Override 243030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell public int compare(ContactInteraction a, ContactInteraction b) { 2431ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a == null && b == null) { 2432ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 0; 2433ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2434ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a == null) { 2435ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 1; 2436ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2437ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (b == null) { 2438ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return -1; 2439ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2440ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a.getInteractionDate() > b.getInteractionDate()) { 2441ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return -1; 2442ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2443ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a.getInteractionDate() == b.getInteractionDate()) { 2444ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 0; 2445ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2446ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 1; 244730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 244830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell }); 244930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 245030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.endSection(); 245130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.beginSection("contactInteractionsToEntries"); 245230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 245330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // Wrap each interaction in its own list so that an icon is displayed for each entry 245430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell for (Entry contactInteraction : contactInteractionsToEntries(allInteractions)) { 245530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell List<Entry> entryListWrapper = new ArrayList<>(1); 245630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell entryListWrapper.add(contactInteraction); 245730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell interactionsWrapper.add(entryListWrapper); 245830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 245930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 246030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.endSection(); 246130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell return null; 2462b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 246330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 246430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell @Override 246530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell protected void onPostExecute(Void aVoid) { 246630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell super.onPostExecute(aVoid); 246730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.beginSection("initialize recents card"); 246830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 246930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell if (allInteractions.size() > 0) { 247030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentCard.initialize(interactionsWrapper, 2471b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN, 2472c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos /* isExpanded = */ mRecentCard.isExpanded(), /* isAlwaysExpanded = */ false, 247330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mExpandingEntryCardViewListener, mScroller); 247479525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mRecentCard.getVisibility() == View.GONE && mShouldLog) { 247579525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.RECENT, 247679525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); 247779525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 247830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentCard.setVisibility(View.VISIBLE); 247938fa285d8a1f24182bc279dfcced595b4b5c4d68yaolu } else { 248038fa285d8a1f24182bc279dfcced595b4b5c4d68yaolu mRecentCard.setVisibility(View.GONE); 248130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 2482eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 248330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.endSection(); 248404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu Trace.beginSection("initialize permission explanation card"); 248504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 24863cbc7482cf5eb745f9ac0b51420a295f51aa46b3Marcus Hagerott final Drawable historyIcon = ResourcesCompat.getDrawable(getResources(), 24873cbc7482cf5eb745f9ac0b51420a295f51aa46b3Marcus Hagerott R.drawable.quantum_ic_history_vd_theme_24, null); 24888e56edfe8ac14879e40825cc10a73a9e2626803dguanxiongliu 248904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final Entry permissionExplanationEntry = new Entry(CARD_ENTRY_ID_REQUEST_PERMISSION, 249004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu historyIcon, getString(R.string.permission_explanation_header), 249104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCardSubHeader, /* subHeaderIcon = */ null, 249204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* text = */ null, /* textIcon = */ null, 249304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* primaryContentDescription = */ null, getIntent(), 249404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* alternateIcon = */ null, /* alternateIntent = */ null, 249504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* alternateContentDescription = */ null, /* shouldApplyColor = */ true, 249604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* isEditable = */ false, /* EntryContextMenuInfo = */ null, 249704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* thirdIcon = */ null, /* thirdIntent = */ null, 249804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* thirdContentDescription = */ null, /* thirdAction = */ Entry.ACTION_NONE, 2499bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao /* thirdExtras = */ null, R.drawable.quantum_ic_history_vd_theme_24); 250004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 250104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final List<List<Entry>> permissionExplanationEntries = new ArrayList<>(); 250204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu permissionExplanationEntries.add(new ArrayList<Entry>()); 250304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu permissionExplanationEntries.get(0).add(permissionExplanationEntry); 250404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 250504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final int subHeaderTextColor = getResources().getColor(android.R.color.white); 250604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu final PorterDuffColorFilter whiteColorFilter = 250704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu new PorterDuffColorFilter(subHeaderTextColor, PorterDuff.Mode.SRC_ATOP); 250804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 250904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.initialize(permissionExplanationEntries, 251004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* numInitialVisibleEntries = */ 1, 251104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* isExpanded = */ true, 251204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* isAlwaysExpanded = */ true, 251304a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu /* listener = */ null, 251404a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mScroller); 251504a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 251604a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setColorAndFilter(subHeaderTextColor, whiteColorFilter); 251704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setBackgroundColor(mColorFilterColor); 251804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setEntryHeaderColor(subHeaderTextColor); 251904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setEntrySubHeaderColor(subHeaderTextColor); 252004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 252104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu if (mShouldShowPermissionExplanation) { 252279525d024526e0f26b9dff40162b91f7c53f17a6yaolu if (mPermissionExplanationCard.getVisibility() == View.GONE 252379525d024526e0f26b9dff40162b91f7c53f17a6yaolu && mShouldLog) { 252479525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.PERMISSION, 252579525d024526e0f26b9dff40162b91f7c53f17a6yaolu ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); 252679525d024526e0f26b9dff40162b91f7c53f17a6yaolu } 252704a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setVisibility(View.VISIBLE); 252804a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu } else { 252904a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu mPermissionExplanationCard.setVisibility(View.GONE); 253004a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu } 253104a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu 253204a1936c4f1f9f414551047c68e7a344d22fddc1guanxiongliu Trace.endSection(); 253330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 253430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // About card is initialized along with the contact card, but since it appears after 253530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // the recent card in the UI, we hold off until making it visible until the recent 253630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // card is also ready to avoid stuttering. 253730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell if (mAboutCard.shouldShow()) { 253830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mAboutCard.setVisibility(View.VISIBLE); 253930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } else { 254030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mAboutCard.setVisibility(View.GONE); 254130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 254230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask = null; 254330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 254430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell }; 254530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask.execute(); 2546b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 25478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 25488a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 25498a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onStop() { 25508a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onStop(); 25518a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 25528a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mEntriesAndActionsTask != null) { 25538a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Once the activity is stopped, we will no longer want to bind mEntriesAndActionsTask's 25548a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // results on the UI thread. In some circumstances Activities are killed without 25558a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // onStop() being called. This is not a problem, because in these circumstances 25568a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the entire process will be killed. 25578a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.cancel(/* mayInterruptIfRunning = */ false); 25588a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 255930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell if (mRecentDataTask != null) { 256030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask.cancel(/* mayInterruptIfRunning = */ false); 256130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 25628a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 256323889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos 2564e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang @Override 2565e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang public void onDestroy() { 25661e5b77f73c324e2e437400e2e1f73065ca6473a5Wenyi Wang LocalBroadcastManager.getInstance(this).unregisterReceiver(mListener); 2567e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang super.onDestroy(); 2568e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 2569e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 257023889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos /** 2571d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Returns true if it is possible to edit the current contact. 2572d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 2573d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private boolean isContactEditable() { 2574d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 2575d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2576d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2577a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell /** 2578a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell * Returns true if it is possible to share the current contact. 2579a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell */ 2580a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell private boolean isContactShareable() { 2581a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 2582a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell } 2583a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 25846095369885edcca566a812b551886e29c7ff8039Brian Attwell private Intent getEditContactIntent() { 2585363af60ea23e5a3b945005712a16564ab69db18bGary Mai return EditorIntents.createEditContactIntent(QuickContactActivity.this, 25861e8801bc9bc60bdd1c95f582c460590272cfad64Walter Jang mContactData.getLookupUri(), 25871e8801bc9bc60bdd1c95f582c460590272cfad64Walter Jang mHasComputedThemeColor 25881e8801bc9bc60bdd1c95f582c460590272cfad64Walter Jang ? new MaterialPalette(mColorFilterColor, mStatusBarColor) : null, 2589c41a1e5f5f4872c3a0da5dec7671b66d9d80eb4eWenyi Wang mContactData.getPhotoId()); 25906095369885edcca566a812b551886e29c7ff8039Brian Attwell } 25916095369885edcca566a812b551886e29c7ff8039Brian Attwell 25926095369885edcca566a812b551886e29c7ff8039Brian Attwell private void editContact() { 2593a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 2594c00a0b5370f0714f6af1ea9b3e29b10f25e91af0Zheng Fu mContactLoader.cacheResult(); 25956095369885edcca566a812b551886e29c7ff8039Brian Attwell startActivityForResult(getEditContactIntent(), REQUEST_CODE_CONTACT_EDITOR_ACTIVITY); 2596d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2597d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 25985d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang private void deleteContact() { 25995d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang final Uri contactUri = mContactData.getLookupUri(); 26005d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang ContactDeletionInteraction.start(this, contactUri, /* finishActivityWhenDone =*/ true); 26015d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang } 26025d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang 260379525d024526e0f26b9dff40162b91f7c53f17a6yaolu private void toggleStar(MenuItem starredMenuItem, boolean isStarred) { 260479525d024526e0f26b9dff40162b91f7c53f17a6yaolu // To improve responsiveness, swap out the picture (and tag) in the UI already 260579525d024526e0f26b9dff40162b91f7c53f17a6yaolu ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, 260679525d024526e0f26b9dff40162b91f7c53f17a6yaolu mContactData.isDirectoryEntry(), mContactData.isUserProfile(), !isStarred); 2607d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 260879525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Now perform the real save 260979525d024526e0f26b9dff40162b91f7c53f17a6yaolu final Intent intent = ContactSaveService.createSetStarredIntent( 261079525d024526e0f26b9dff40162b91f7c53f17a6yaolu QuickContactActivity.this, mContactData.getLookupUri(), !isStarred); 261179525d024526e0f26b9dff40162b91f7c53f17a6yaolu startService(intent); 261235ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell 261379525d024526e0f26b9dff40162b91f7c53f17a6yaolu final CharSequence accessibilityText = !isStarred 261479525d024526e0f26b9dff40162b91f7c53f17a6yaolu ? getResources().getText(R.string.description_action_menu_add_star) 261579525d024526e0f26b9dff40162b91f7c53f17a6yaolu : getResources().getText(R.string.description_action_menu_remove_star); 261679525d024526e0f26b9dff40162b91f7c53f17a6yaolu // Accessibility actions need to have an associated view. We can't access the MenuItem's 261779525d024526e0f26b9dff40162b91f7c53f17a6yaolu // underlying view, so put this accessibility action on the root view. 261879525d024526e0f26b9dff40162b91f7c53f17a6yaolu mScroller.announceForAccessibility(accessibilityText); 2619d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2620d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2621752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void shareContact() { 2622752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final String lookupKey = mContactData.getLookupKey(); 2623652936f204b15097d030e870dda5054d8115cbf3Brian Attwell final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); 2624752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent intent = new Intent(Intent.ACTION_SEND); 2625552ee569d46ae5c63207a162157171b249243e56Yorke Lee intent.setType(Contacts.CONTENT_VCARD_TYPE); 26268dcb4ed13da40fc609e6913708c3d730ba4f0574Brian Attwell intent.putExtra(Intent.EXTRA_STREAM, shareUri); 2627752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2628752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Launch chooser to share contact via 2629281689f7b6e932e15f138645dbadd19d746e2740Wenyi Wang final CharSequence chooseTitle = getResources().getQuantityString( 2630281689f7b6e932e15f138645dbadd19d746e2740Wenyi Wang R.plurals.title_share_via, /* quantity */ 1); 2631752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent chooseIntent = Intent.createChooser(intent, chooseTitle); 2632752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2633752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell try { 2634a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 2635652936f204b15097d030e870dda5054d8115cbf3Brian Attwell ImplicitIntentsUtil.startActivityOutsideApp(this, chooseIntent); 2636eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ActivityNotFoundException ex) { 2637752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show(); 2638752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2639752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2640752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2641752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** 2642752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell * Creates a launcher shortcut with the current contact. 2643752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell */ 2644752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void createLauncherShortcutWithContact() { 2645752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this, 2646752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell new OnShortcutIntentCreatedListener() { 2647752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2648752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell @Override 2649752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) { 265091520d763209fa61de58fa54ba4864ed87a2df6fGary Mai if (BuildCompat.isAtLeastO()) { 265191520d763209fa61de58fa54ba4864ed87a2df6fGary Mai final ShortcutManager shortcutManager = (ShortcutManager) 265291520d763209fa61de58fa54ba4864ed87a2df6fGary Mai getSystemService(SHORTCUT_SERVICE); 265391520d763209fa61de58fa54ba4864ed87a2df6fGary Mai final DynamicShortcuts shortcuts = 265491520d763209fa61de58fa54ba4864ed87a2df6fGary Mai new DynamicShortcuts(QuickContactActivity.this); 265591520d763209fa61de58fa54ba4864ed87a2df6fGary Mai shortcutManager.requestPinShortcut( 265691520d763209fa61de58fa54ba4864ed87a2df6fGary Mai shortcuts.getQuickContactShortcutInfo( 265791520d763209fa61de58fa54ba4864ed87a2df6fGary Mai mContactData.getId(), mContactData.getLookupKey(), 265891520d763209fa61de58fa54ba4864ed87a2df6fGary Mai mContactData.getDisplayName()), null); 265991520d763209fa61de58fa54ba4864ed87a2df6fGary Mai } else { 266091520d763209fa61de58fa54ba4864ed87a2df6fGary Mai // Broadcast the shortcutIntent to the launcher to create a 266191520d763209fa61de58fa54ba4864ed87a2df6fGary Mai // shortcut to this contact 266291520d763209fa61de58fa54ba4864ed87a2df6fGary Mai shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); 266391520d763209fa61de58fa54ba4864ed87a2df6fGary Mai QuickContactActivity.this.sendBroadcast(shortcutIntent); 266491520d763209fa61de58fa54ba4864ed87a2df6fGary Mai // Send a toast to give feedback to the user that a shortcut to this 266591520d763209fa61de58fa54ba4864ed87a2df6fGary Mai // contact was added to the launcher. 266691520d763209fa61de58fa54ba4864ed87a2df6fGary Mai final String displayName = shortcutIntent 266791520d763209fa61de58fa54ba4864ed87a2df6fGary Mai .getStringExtra(Intent.EXTRA_SHORTCUT_NAME); 266891520d763209fa61de58fa54ba4864ed87a2df6fGary Mai final String toastMessage = TextUtils.isEmpty(displayName) 266991520d763209fa61de58fa54ba4864ed87a2df6fGary Mai ? getString(R.string.createContactShortcutSuccessful_NoName) 267091520d763209fa61de58fa54ba4864ed87a2df6fGary Mai : getString(R.string.createContactShortcutSuccessful, 267191520d763209fa61de58fa54ba4864ed87a2df6fGary Mai displayName); 267291520d763209fa61de58fa54ba4864ed87a2df6fGary Mai Toast.makeText(QuickContactActivity.this, toastMessage, 267391520d763209fa61de58fa54ba4864ed87a2df6fGary Mai Toast.LENGTH_SHORT).show(); 267491520d763209fa61de58fa54ba4864ed87a2df6fGary Mai } 2675752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2676752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell }); 267763176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell builder.createContactShortcutIntent(mContactData.getLookupUri()); 2678752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2679752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 268066965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell private boolean isShortcutCreatable() { 26811c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner if (mContactData == null || mContactData.isUserProfile() || 26821c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner mContactData.isDirectoryEntry()) { 26838d0557eb013b2808402e491271fe0f13ffcfabefBrian Attwell return false; 26848d0557eb013b2808402e491271fe0f13ffcfabefBrian Attwell } 268591520d763209fa61de58fa54ba4864ed87a2df6fGary Mai 268691520d763209fa61de58fa54ba4864ed87a2df6fGary Mai if (BuildCompat.isAtLeastO()) { 268791520d763209fa61de58fa54ba4864ed87a2df6fGary Mai final ShortcutManager manager = (ShortcutManager) 268891520d763209fa61de58fa54ba4864ed87a2df6fGary Mai getSystemService(Context.SHORTCUT_SERVICE); 268991520d763209fa61de58fa54ba4864ed87a2df6fGary Mai return manager.isRequestPinShortcutSupported(); 269091520d763209fa61de58fa54ba4864ed87a2df6fGary Mai } 269191520d763209fa61de58fa54ba4864ed87a2df6fGary Mai 269266965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell final Intent createShortcutIntent = new Intent(); 269366965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell createShortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); 269466965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell final List<ResolveInfo> receivers = getPackageManager() 269566965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell .queryBroadcastReceivers(createShortcutIntent, 0); 269666965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell return receivers != null && receivers.size() > 0; 269766965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell } 269866965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell 269958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private void setStateForPhoneMenuItems(Contact contact) { 270058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu if (contact != null) { 270158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mSendToVoicemailState = contact.isSendToVoicemail(); 270258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mCustomRingtone = contact.getCustomRingtone(); 270358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu mArePhoneOptionsChangable = isContactEditable() 270458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu && PhoneCapabilityTester.isPhone(this); 270558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } 270658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } 270758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 2708d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 2709d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onCreateOptionsMenu(Menu menu) { 2710eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final MenuInflater inflater = getMenuInflater(); 2711d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell inflater.inflate(R.menu.quickcontact, menu); 2712d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 2713d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2714d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2715d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 2716d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onPrepareOptionsMenu(Menu menu) { 2717d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mContactData != null) { 2718d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem starredMenuItem = menu.findItem(R.id.menu_star); 2719333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, 2720d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.isDirectoryEntry(), mContactData.isUserProfile(), 2721d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.getStarred()); 2722a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 2723d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Configure edit MenuItem 2724d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem editMenuItem = menu.findItem(R.id.menu_edit); 2725d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(true); 2726d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData) || InvisibleContactUtil 2727d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell .isInvisibleAndAddable(mContactData, this)) { 2728bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao editMenuItem.setIcon(R.drawable.quantum_ic_person_add_vd_theme_24); 27292e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell editMenuItem.setTitle(R.string.menu_add_contact); 2730d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 2731bd9ef3c60669d71543b3506d4959c1fe4be409dcJohn Shao editMenuItem.setIcon(R.drawable.quantum_ic_create_vd_theme_24); 27322e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell editMenuItem.setTitle(R.string.menu_editContact); 2733d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else { 2734d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(false); 2735d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2736a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 2737b9065ddb28a2040cabda251891be2062b5260217Gary Mai // The link menu item is only visible if this has a single raw contact. 27382de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu final MenuItem joinMenuItem = menu.findItem(R.id.menu_join); 27392de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu joinMenuItem.setVisible(!InvisibleContactUtil.isInvisibleAndAddable(mContactData, this) 2740b9065ddb28a2040cabda251891be2062b5260217Gary Mai && isContactEditable() && !mContactData.isUserProfile() 2741b9065ddb28a2040cabda251891be2062b5260217Gary Mai && !mContactData.isMultipleRawContacts()); 2742b9065ddb28a2040cabda251891be2062b5260217Gary Mai 2743b9065ddb28a2040cabda251891be2062b5260217Gary Mai // Viewing linked contacts can only happen if there are multiple raw contacts and 2744b9065ddb28a2040cabda251891be2062b5260217Gary Mai // the link menu isn't available. 2745b9065ddb28a2040cabda251891be2062b5260217Gary Mai final MenuItem linkedContactsMenuItem = menu.findItem(R.id.menu_linked_contacts); 2746b9065ddb28a2040cabda251891be2062b5260217Gary Mai linkedContactsMenuItem.setVisible(mContactData.isMultipleRawContacts() 2747b9065ddb28a2040cabda251891be2062b5260217Gary Mai && !joinMenuItem.isVisible()); 27482de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 27495d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang final MenuItem deleteMenuItem = menu.findItem(R.id.menu_delete); 275082ed2b5380e134705f96e7e1f1586a25f8ac403fWalter Jang deleteMenuItem.setVisible(isContactEditable() && !mContactData.isUserProfile()); 27515d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang 2752a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell final MenuItem shareMenuItem = menu.findItem(R.id.menu_share); 2753a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell shareMenuItem.setVisible(isContactShareable()); 2754a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 275566965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell final MenuItem shortcutMenuItem = menu.findItem(R.id.menu_create_contact_shortcut); 275666965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell shortcutMenuItem.setVisible(isShortcutCreatable()); 275766965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell 275858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Hide telephony-related settings (ringtone, send to voicemail) 275958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // if we don't have a telephone 276058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu final MenuItem ringToneMenuItem = menu.findItem(R.id.menu_set_ringtone); 276158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu ringToneMenuItem.setVisible(!mContactData.isUserProfile() && mArePhoneOptionsChangable); 276258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 276358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu final MenuItem sendToVoiceMailMenuItem = menu.findItem(R.id.menu_send_to_voicemail); 276458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu sendToVoiceMailMenuItem.setVisible(!mContactData.isUserProfile() 276558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu && mArePhoneOptionsChangable); 276658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu sendToVoiceMailMenuItem.setTitle(mSendToVoicemailState 276758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu ? R.string.menu_unredirect_calls_to_vm : R.string.menu_redirect_calls_to_vm); 276858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 276956bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell final MenuItem helpMenu = menu.findItem(R.id.menu_help); 277056bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell helpMenu.setVisible(HelpUtils.isHelpAndFeedbackAvailable()); 277156bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell 27728a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return true; 2773d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 27748a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return false; 2775d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2776d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2777d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 2778d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onOptionsItemSelected(MenuItem item) { 2779b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott final int id = item.getItemId(); 2780b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott if (id == R.id.menu_star) {// Make sure there is a contact 2781b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott if (mContactData != null) { 2782b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // Read the current starred value from the UI instead of using the last 2783b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // loaded state. This allows rapid tapping without writing the same 2784b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // value several times 2785b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott final boolean isStarred = item.isChecked(); 2786b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 2787b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott isStarred ? ActionType.UNSTAR : ActionType.STAR, 278879525d024526e0f26b9dff40162b91f7c53f17a6yaolu /* thirdPartyAction */ null); 2789b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott toggleStar(item, isStarred); 2790b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } 2791b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else if (id == R.id.menu_edit) { 2792b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott if (DirectoryContactUtil.isDirectoryContact(mContactData)) { 279379525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 2794b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott ActionType.ADD, /* thirdPartyAction */ null); 2795b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott 2796b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // This action is used to launch the contact selector, with the option of 2797b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // creating a new contact. Creating a new contact is an INSERT, while selecting 2798b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // an exisiting one is an edit. The fields in the edit screen will be 2799b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // prepopulated with data. 2800b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott 2801b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); 2802b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott intent.setType(Contacts.CONTENT_ITEM_TYPE); 2803b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott 2804b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott ArrayList<ContentValues> values = mContactData.getContentValues(); 2805b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott 2806b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // Only pre-fill the name field if the provided display name is an nickname 2807b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // or better (e.g. structured name, nickname) 2808b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott if (mContactData.getDisplayNameSource() >= DisplayNameSources.NICKNAME) { 2809b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott intent.putExtra(Intents.Insert.NAME, mContactData.getDisplayName()); 2810b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else if (mContactData.getDisplayNameSource() 2811b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott == DisplayNameSources.ORGANIZATION) { 2812b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // This is probably an organization. Instead of copying the organization 2813b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // name into a name entry, copy it into the organization entry. This 2814b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // way we will still consider the contact an organization. 2815b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott final ContentValues organization = new ContentValues(); 2816b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott organization.put(Organization.COMPANY, mContactData.getDisplayName()); 2817b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott organization.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE); 2818b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott values.add(organization); 28191c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner } 2820b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott 2821b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // Last time used and times used are aggregated values from the usage stat 2822b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // table. They need to be removed from data values so the SQL table can insert 2823b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // properly 2824b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott for (ContentValues value : values) { 2825b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott value.remove(Data.LAST_TIME_USED); 2826b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott value.remove(Data.TIMES_USED); 282749de62f06d24653484adebd69123eeff2850a757Jay Shrauner } 2828b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott intent.putExtra(Intents.Insert.DATA, values); 2829b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott 2830b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // If the contact can only export to the same account, add it to the intent. 2831b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // Otherwise the ContactEditorFragment will show a dialog for selecting 2832b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // an account. 2833b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott if (mContactData.getDirectoryExportSupport() == 2834b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott Directory.EXPORT_SUPPORT_SAME_ACCOUNT_ONLY) { 2835b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott intent.putExtra(Intents.Insert.EXTRA_ACCOUNT, 2836b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott new Account(mContactData.getDirectoryAccountName(), 2837b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott mContactData.getDirectoryAccountType())); 2838b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott intent.putExtra(Intents.Insert.EXTRA_DATA_SET, 2839b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott mContactData.getRawContacts().get(0).getDataSet()); 28401c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner } 2841b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott 2842b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // Add this flag to disable the delete menu option on directory contact joins 2843b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott // with local contacts. The delete option is ambiguous when joining contacts. 2844b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott intent.putExtra( 2845b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott ContactEditorFragment.INTENT_EXTRA_DISABLE_DELETE_MENU_OPTION, 2846b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott true); 2847b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott 2848b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott intent.setPackage(getPackageName()); 2849b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott startActivityForResult(intent, REQUEST_CODE_CONTACT_SELECTION_ACTIVITY); 2850b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { 285179525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 2852b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott ActionType.ADD, /* thirdPartyAction */ null); 2853b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott InvisibleContactUtil.addToDefaultGroup(mContactData, this); 2854b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else if (isContactEditable()) { 285579525d024526e0f26b9dff40162b91f7c53f17a6yaolu Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 2856b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott ActionType.EDIT, /* thirdPartyAction */ null); 2857b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott editContact(); 2858b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } 2859b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else if (id == R.id.menu_join) { 2860b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott return doJoinContactAction(); 2861b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else if (id == R.id.menu_linked_contacts) { 2862b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott return showRawContactPickerDialog(); 2863b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else if (id == R.id.menu_delete) { 2864b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 2865b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott ActionType.REMOVE, /* thirdPartyAction */ null); 2866b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott if (isContactEditable()) { 2867b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott deleteContact(); 2868b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } 2869b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else if (id == R.id.menu_share) { 2870b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 2871b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott ActionType.SHARE, /* thirdPartyAction */ null); 2872b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott if (isContactShareable()) { 2873b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott shareContact(); 2874b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } 2875b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else if (id == R.id.menu_create_contact_shortcut) { 2876b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 2877b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott ActionType.SHORTCUT, /* thirdPartyAction */ null); 2878b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott if (isShortcutCreatable()) { 2879b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott createLauncherShortcutWithContact(); 2880b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } 2881b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else if (id == R.id.menu_set_ringtone) { 2882b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott doPickRingtone(); 2883b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else if (id == R.id.menu_send_to_voicemail) {// Update state and save 2884b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott mSendToVoicemailState = !mSendToVoicemailState; 2885b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott item.setTitle(mSendToVoicemailState 2886b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott ? R.string.menu_unredirect_calls_to_vm 2887b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott : R.string.menu_redirect_calls_to_vm); 2888b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott final Intent intent = ContactSaveService.createSetSendToVoicemail( 2889b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott this, mLookupUri, mSendToVoicemailState); 2890b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott this.startService(intent); 2891b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else if (id == R.id.menu_help) { 2892b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 2893b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott ActionType.HELP, /* thirdPartyAction */ null); 2894b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott HelpUtils.launchHelpAndFeedbackForContactScreen(this); 2895b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott } else { 2896b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, 2897b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); 2898b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott return super.onOptionsItemSelected(item); 2899d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2900b697ed768fb817f94524f6c3992547665df331c4Marcus Hagerott return true; 290123889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos } 29022de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 2903b9065ddb28a2040cabda251891be2062b5260217Gary Mai private boolean showRawContactPickerDialog() { 2904b9065ddb28a2040cabda251891be2062b5260217Gary Mai if (mContactData == null) return false; 2905b9065ddb28a2040cabda251891be2062b5260217Gary Mai startActivityForResult(EditorIntents.createViewLinkedContactsIntent( 2906b9065ddb28a2040cabda251891be2062b5260217Gary Mai QuickContactActivity.this, 2907b9065ddb28a2040cabda251891be2062b5260217Gary Mai mContactData.getLookupUri(), 2908b9065ddb28a2040cabda251891be2062b5260217Gary Mai mHasComputedThemeColor 2909b9065ddb28a2040cabda251891be2062b5260217Gary Mai ? new MaterialPalette(mColorFilterColor, mStatusBarColor) 2910b9065ddb28a2040cabda251891be2062b5260217Gary Mai : null), 2911b9065ddb28a2040cabda251891be2062b5260217Gary Mai REQUEST_CODE_CONTACT_EDITOR_ACTIVITY); 2912b9065ddb28a2040cabda251891be2062b5260217Gary Mai return true; 2913b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2914b9065ddb28a2040cabda251891be2062b5260217Gary Mai 29152de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu private boolean doJoinContactAction() { 29162de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu if (mContactData == null) return false; 29172de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 29182de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu mPreviousContactId = mContactData.getId(); 29192de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu final Intent intent = new Intent(this, ContactSelectionActivity.class); 29202de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu intent.setAction(UiIntentActions.PICK_JOIN_CONTACT_ACTION); 29212de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu intent.putExtra(UiIntentActions.TARGET_CONTACT_ID_EXTRA_KEY, mPreviousContactId); 29222de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu startActivityForResult(intent, REQUEST_CODE_JOIN); 29232de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu return true; 29242de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } 29252de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 29262de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu /** 29272de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu * Performs aggregation with the contact selected by the user from suggestions or A-Z list. 29282de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu */ 29292de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu private void joinAggregate(final long contactId) { 29302de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu final Intent intent = ContactSaveService.createJoinContactsIntent( 29312de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu this, mPreviousContactId, contactId, QuickContactActivity.class, 29322de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu Intent.ACTION_VIEW); 29332de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu this.startService(intent); 2934b9065ddb28a2040cabda251891be2062b5260217Gary Mai showLinkProgressBar(); 29352de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu } 29362de7c8e0d319b977bdaf665abbd5a8a5ed41b7bfyaolu 293758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 293858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu private void doPickRingtone() { 293958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu final Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); 294058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Allow user to pick 'Default' 294158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); 294258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Show only ringtones 294358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE); 294458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Allow the user to pick a silent ringtone 294558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); 294658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 294758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu final Uri ringtoneUri = EditorUiUtils.getRingtoneUriFromString(mCustomRingtone, 294858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu CURRENT_API_VERSION); 294958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 295058a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Put checkmark next to the current ringtone for this contact 295158a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtoneUri); 295258a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu 295358a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu // Launch! 295458a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu try { 295558a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu startActivityForResult(intent, REQUEST_CODE_PICK_RINGTONE); 295658a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } catch (ActivityNotFoundException ex) { 295758a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu Toast.makeText(this, R.string.missing_app, Toast.LENGTH_SHORT).show(); 295858a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } 295958a1ac2d418c716599b06bed1fa1aad1160dbf54yaolu } 2960b9065ddb28a2040cabda251891be2062b5260217Gary Mai 2961b9065ddb28a2040cabda251891be2062b5260217Gary Mai private void dismissProgressBar() { 2962b9065ddb28a2040cabda251891be2062b5260217Gary Mai if (mProgressDialog != null && mProgressDialog.isShowing()) { 2963b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.dismiss(); 2964b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2965b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2966b9065ddb28a2040cabda251891be2062b5260217Gary Mai 2967b9065ddb28a2040cabda251891be2062b5260217Gary Mai private void showLinkProgressBar() { 2968b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.setMessage(getString(R.string.contacts_linking_progress_bar)); 2969b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.show(); 2970b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2971b9065ddb28a2040cabda251891be2062b5260217Gary Mai 2972b9065ddb28a2040cabda251891be2062b5260217Gary Mai private void showUnlinkProgressBar() { 2973b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.setMessage(getString(R.string.contacts_unlinking_progress_bar)); 2974b9065ddb28a2040cabda251891be2062b5260217Gary Mai mProgressDialog.show(); 2975b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2976b9065ddb28a2040cabda251891be2062b5260217Gary Mai 2977b9065ddb28a2040cabda251891be2062b5260217Gary Mai private void maybeShowProgressDialog() { 2978b9065ddb28a2040cabda251891be2062b5260217Gary Mai if (ContactSaveService.getState().isActionPending( 2979b9065ddb28a2040cabda251891be2062b5260217Gary Mai ContactSaveService.ACTION_SPLIT_CONTACT)) { 2980b9065ddb28a2040cabda251891be2062b5260217Gary Mai showUnlinkProgressBar(); 2981b9065ddb28a2040cabda251891be2062b5260217Gary Mai } else if (ContactSaveService.getState().isActionPending( 2982b9065ddb28a2040cabda251891be2062b5260217Gary Mai ContactSaveService.ACTION_JOIN_CONTACTS)) { 2983b9065ddb28a2040cabda251891be2062b5260217Gary Mai showLinkProgressBar(); 2984b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2985b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2986b9065ddb28a2040cabda251891be2062b5260217Gary Mai 2987b9065ddb28a2040cabda251891be2062b5260217Gary Mai private class SaveServiceListener extends BroadcastReceiver { 2988b9065ddb28a2040cabda251891be2062b5260217Gary Mai @Override 2989b9065ddb28a2040cabda251891be2062b5260217Gary Mai public void onReceive(Context context, Intent intent) { 2990b9065ddb28a2040cabda251891be2062b5260217Gary Mai if (Log.isLoggable(TAG, Log.DEBUG)) { 2991b9065ddb28a2040cabda251891be2062b5260217Gary Mai Log.d(TAG, "Got broadcast from save service " + intent); 2992b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2993b9065ddb28a2040cabda251891be2062b5260217Gary Mai if (ContactSaveService.BROADCAST_LINK_COMPLETE.equals(intent.getAction()) 2994b9065ddb28a2040cabda251891be2062b5260217Gary Mai || ContactSaveService.BROADCAST_UNLINK_COMPLETE.equals(intent.getAction())) { 2995b9065ddb28a2040cabda251891be2062b5260217Gary Mai dismissProgressBar(); 2996b9065ddb28a2040cabda251891be2062b5260217Gary Mai if (ContactSaveService.BROADCAST_UNLINK_COMPLETE.equals(intent.getAction())) { 2997b9065ddb28a2040cabda251891be2062b5260217Gary Mai finish(); 2998b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 2999b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 3000b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 3001b9065ddb28a2040cabda251891be2062b5260217Gary Mai } 3002edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann} 3003