QuickContactActivity.java revision 3d65ea5f6113c497f09abf18d3f11abdcd1c894f
1edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/* 2edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Copyright (C) 2009 The Android Open Source Project 3edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 4edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Licensed under the Apache License, Version 2.0 (the "License"); 5edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * you may not use this file except in compliance with the License. 6edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * You may obtain a copy of the License at 7edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 8edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * http://www.apache.org/licenses/LICENSE-2.0 9edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 10edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Unless required by applicable law or agreed to in writing, software 11edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * distributed under the License is distributed on an "AS IS" BASIS, 12edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * See the License for the specific language governing permissions and 14edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * limitations under the License. 15edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 16edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 17edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannpackage com.android.contacts.quickcontact; 18edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 19ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulosimport android.accounts.Account; 208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.animation.ArgbEvaluator; 21b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport android.animation.ObjectAnimator; 22edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.app.Activity; 23d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.app.Fragment; 24cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.app.LoaderManager.LoaderCallbacks; 25eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.app.SearchManager; 26752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.content.ActivityNotFoundException; 27edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.ContentUris; 28ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulosimport android.content.ContentValues; 296bb01347eab60f95deafdfe523b0c368707210f3Brian Attwellimport android.content.Context; 30edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.Intent; 31cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.content.Loader; 32dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulosimport android.content.pm.PackageManager; 33dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulosimport android.content.pm.ResolveInfo; 3423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulosimport android.content.res.Resources; 3531b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.Bitmap; 3695c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwellimport android.graphics.BitmapFactory; 378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.Color; 38eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuff; 39eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuffColorFilter; 4031b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.BitmapDrawable; 418a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.drawable.ColorDrawable; 4231b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.Drawable; 43edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.net.Uri; 4431b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.os.AsyncTask; 45edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.os.Bundle; 468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.os.Trace; 47eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.CalendarContract; 48e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport android.provider.ContactsContract; 49edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Email; 50eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Event; 51eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.GroupMembership; 52eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Identity; 53eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Im; 54eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Nickname; 55eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Note; 56eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Organization; 57edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Phone; 58eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Relation; 59edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.SipAddress; 60edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.StructuredPostal; 61edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Website; 62752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.provider.ContactsContract.Contacts; 6360e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulosimport android.provider.ContactsContract.Data; 64ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulosimport android.provider.ContactsContract.Directory; 65eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.DisplayNameSources; 66ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulosimport android.provider.ContactsContract.DataUsageFeedback; 67ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulosimport android.provider.ContactsContract.Intents; 68edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.QuickContact; 69edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.RawContacts; 7031b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.support.v7.graphics.Palette; 71e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport android.support.v7.widget.CardView; 720319222b43927d4d9ce7e2a9070f3543661b5782Tyler Gunnimport android.telecom.PhoneAccount; 730319222b43927d4d9ce7e2a9070f3543661b5782Tyler Gunnimport android.telecom.TelecomManager; 74c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwellimport android.text.BidiFormatter; 75b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wangimport android.text.Spannable; 767ce5352a70e8aaf120bf4f7bd05d595f46abb080Walter Jangimport android.text.SpannableString; 77c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwellimport android.text.TextDirectionHeuristics; 78edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.text.TextUtils; 79edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.util.Log; 802a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu; 812a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu.ContextMenuInfo; 82e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport android.view.LayoutInflater; 83d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.Menu; 84d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.MenuInflater; 85eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.view.MenuItem; 86f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chenimport android.view.MotionEvent; 87edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View; 88edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View.OnClickListener; 892a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.View.OnCreateContextMenuListener; 9010d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawaimport android.view.WindowManager; 91e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport android.widget.Button; 92e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport android.widget.CheckBox; 93e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport android.widget.ImageView; 94e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport android.widget.LinearLayout; 95e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport android.widget.TextView; 96edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.widget.Toast; 97d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.widget.Toolbar; 98edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 9972b3ab1d8a62f228a540b05f4ed6373e494c7d72Christine Chenimport com.android.contacts.ContactSaveService; 100d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.ContactsActivity; 1012d150da246632b1649999cfabed776133b097775Brian Attwellimport com.android.contacts.NfcHandler; 102e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.R; 103d1cb9045bffc3843f5a294d41ce4608c701bccccWenyi Wangimport com.android.contacts.activities.ContactEditorBaseActivity; 104eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.CallUtil; 1052a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.common.ClipboardUtils; 106eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.Collapser; 107e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport com.android.contacts.common.ContactPhotoManager; 108eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.ContactsUtils; 109bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwellimport com.android.contacts.common.activity.RequestPermissionsActivity; 1105f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunnimport com.android.contacts.common.dialog.CallSubjectDialog; 111d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.common.editor.SelectAccountDialogFragment; 11270e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chenimport com.android.contacts.common.interactions.TouchPointManager; 11331b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport com.android.contacts.common.lettertiles.LetterTileDrawable; 114752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder; 115752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder.OnShortcutIntentCreatedListener; 1160d5588da244d0992c3ff8f25d0875fdf95a8c644Chiao Chengimport com.android.contacts.common.model.AccountTypeManager; 117cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.Contact; 118cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.ContactLoader; 119cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.RawContact; 120428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.account.AccountType; 121d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.common.model.account.AccountWithDataSet; 122cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.DataItem; 123428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.dataitem.DataKind; 124cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.EmailDataItem; 125eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.EventDataItem; 126cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.ImDataItem; 127eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NicknameDataItem; 128eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NoteDataItem; 129eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.OrganizationDataItem; 130b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.common.model.dataitem.PhoneDataItem; 131eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.RelationDataItem; 132eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.SipAddressDataItem; 133eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredNameDataItem; 134eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredPostalDataItem; 135eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.WebsiteDataItem; 136e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport com.android.contacts.common.model.ValuesDelta; 137c6100ffd22ae176a3e84a1062d8cb92d955faef2Brian Attwellimport com.android.contacts.common.util.ImplicitIntentsUtil; 138eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.util.DateUtils; 139faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwellimport com.android.contacts.common.util.MaterialColorMapUtils; 140faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwellimport com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette; 1415f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunnimport com.android.contacts.common.util.UriUtils; 142d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwellimport com.android.contacts.common.util.ViewUtil; 143333091ae754ddfc25714c14b9b89534be24379f9Paul Soulosimport com.android.contacts.detail.ContactDisplayUtils; 144e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport com.android.contacts.editor.AggregationSuggestionEngine; 145e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport com.android.contacts.editor.AggregationSuggestionEngine.Suggestion; 146f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulosimport com.android.contacts.editor.ContactEditorFragment; 1475a7a23bdb698b8e741a425c9617c5e33e6314cddWalter Jangimport com.android.contacts.editor.EditorIntents; 148899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport com.android.contacts.interactions.CalendarInteractionsLoader; 149ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulosimport com.android.contacts.interactions.CallLogInteractionsLoader; 1508a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport com.android.contacts.interactions.ContactDeletionInteraction; 151b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.ContactInteraction; 152e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport com.android.contacts.interactions.JoinContactsDialogFragment; 1535368489acaadac82706ca0e678ec04d662db702eWenyi Wangimport com.android.contacts.interactions.JoinContactsDialogFragment.JoinContactsListener; 154b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.SmsInteractionsLoader; 1552d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.Entry; 1562a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryContextMenuInfo; 1572ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryTag; 158e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwellimport com.android.contacts.quickcontact.ExpandingEntryCardView.ExpandingEntryCardViewListener; 159493f8d14b1d974a2939a110ce89fa68e0c915c36Brian Attwellimport com.android.contacts.quickcontact.WebAddress.ParseException; 160e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.util.ImageViewDrawableSetter; 161eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.PhoneCapabilityTester; 162b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.util.SchedulingUtils; 163eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.StructuredPostalUtils; 164b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller; 165b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener; 16602eaf11669d25fd885606b3b0700358323532cddBrian Attwellimport com.android.contacts.widget.QuickContactImageView; 16756bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwellimport com.android.contactsbind.HelpUtils; 16856bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell 169e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.google.common.collect.Lists; 170e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng 17182a5a35c1a2b83b4118bcba56625f6f25e9663d0Jay Shraunerimport java.lang.SecurityException; 1722d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport java.util.ArrayList; 173899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport java.util.Arrays; 174eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Calendar; 175b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Collections; 176b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Comparator; 177eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Date; 178edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.HashMap; 179e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport java.util.HashSet; 180edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.List; 181b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Map; 182e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport java.util.Set; 183e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangimport java.util.TreeSet; 18412ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shraunerimport java.util.concurrent.ConcurrentHashMap; 185edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1865368489acaadac82706ca0e678ec04d662db702eWenyi Wangimport android.graphics.PorterDuff; 1875368489acaadac82706ca0e678ec04d662db702eWenyi Wangimport android.support.v4.content.ContextCompat; 1885368489acaadac82706ca0e678ec04d662db702eWenyi Wang 189edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/** 190edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Mostly translucent {@link Activity} that shows QuickContact dialog. It loads 191edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * data asynchronously, and then shows a popup with details centered around 192edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * {@link Intent#getSourceBounds()}. 193edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 194e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wangpublic class QuickContactActivity extends ContactsActivity 1955368489acaadac82706ca0e678ec04d662db702eWenyi Wang implements AggregationSuggestionEngine.Listener, JoinContactsListener { 1968a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1978a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell /** 1988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * QuickContacts immediately takes up the full screen. All possible information is shown. 1998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * This value for {@link android.provider.ContactsContract.QuickContact#EXTRA_MODE} 2008a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * should only be used by the Contacts app. 2018a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell */ 2028a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public static final int MODE_FULLY_EXPANDED = 4; 2038a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 204edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String TAG = "QuickContact"; 205edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 2069b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final String KEY_THEME_COLOR = "theme_color"; 207e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang private static final String KEY_IS_SUGGESTION_LIST_COLLAPSED = "is_suggestion_list_collapsed"; 208e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang private static final String KEY_SELECTED_SUGGESTION_CONTACTS = "selected_suggestion_contacts"; 20918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private static final String KEY_PREVIOUS_CONTACT_ID = "previous_contact_id"; 21018906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private static final String KEY_SUGGESTIONS_AUTO_SELECTED = "suggestions_auto_seleted"; 2115368489acaadac82706ca0e678ec04d662db702eWenyi Wang private static final String KEY_SELECTED_SUGGESTION_NUMBER = "selected_suggestion_number"; 2129b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 2139b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final int ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION = 150; 2148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private static final int REQUEST_CODE_CONTACT_EDITOR_ACTIVITY = 1; 2150b267fec5cb5b2d836057b16d0085be349be5243Brian Attwell private static final int SCRIM_COLOR = Color.argb(0xC8, 0, 0, 0); 216ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos private static final int REQUEST_CODE_CONTACT_SELECTION_ACTIVITY = 2; 217ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos private static final String MIMETYPE_SMS = "vnd.android-dir/mms-sms"; 218dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 219752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** This is the Intent action to install a shortcut in the launcher. */ 220752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private static final String ACTION_INSTALL_SHORTCUT = 221752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell "com.android.launcher.action.INSTALL_SHORTCUT"; 222edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 223edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @SuppressWarnings("deprecation") 224edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String LEGACY_AUTHORITY = android.provider.Contacts.AUTHORITY; 225edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 226e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String MIMETYPE_GPLUS_PROFILE = 227e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos "vnd.android.cursor.item/vnd.googleplus.profile"; 2286a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String GPLUS_PROFILE_DATA_5_ADD_TO_CIRCLE = "addtocircle"; 2296a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String GPLUS_PROFILE_DATA_5_VIEW_PROFILE = "view"; 230e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String MIMETYPE_HANGOUTS = 231e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos "vnd.android.cursor.item/vnd.googleplus.profile.comm"; 2326a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String HANGOUTS_DATA_5_VIDEO = "hangout"; 2336a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String HANGOUTS_DATA_5_MESSAGE = "conversation"; 23448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos private static final String CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY = 23548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos "com.android.contacts.quickcontact.QuickContactActivity"; 236e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 23763176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell /** 23863176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell * The URI used to load the the Contact. Once the contact is loaded, use Contact#getLookupUri() 23963176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell * instead of referencing this URI. 24063176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell */ 241edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private Uri mLookupUri; 242edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private String[] mExcludeMimes; 2438a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mExtraMode; 24405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell private String mExtraPrioritizedMimeType; 2458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mStatusBarColor; 2468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private boolean mHasAlreadyBeenOpened; 24797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos private boolean mOnlyOnePhoneNumber; 24897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos private boolean mOnlyOneEmail; 249edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 25002eaf11669d25fd885606b3b0700358323532cddBrian Attwell private QuickContactImageView mPhotoView; 251eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mContactCard; 2526095369885edcca566a812b551886e29c7ff8039Brian Attwell private ExpandingEntryCardView mNoContactDetailsCard; 253b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private ExpandingEntryCardView mRecentCard; 254eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mAboutCard; 255e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 256e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang // Suggestion card. 25718906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private CardView mCollapsedSuggestionCardView; 25818906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private CardView mExpandSuggestionCardView; 25918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private View mCollapasedSuggestionHeader; 26018906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private TextView mCollapsedSuggestionCardTitle; 26118906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private TextView mExpandSuggestionCardTitle; 262e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang private ImageView mSuggestionSummaryPhoto; 263e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang private TextView mSuggestionForName; 2645368489acaadac82706ca0e678ec04d662db702eWenyi Wang private TextView mSuggestionContactsNumber; 265e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang private LinearLayout mSuggestionList; 26618906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private Button mSuggestionsCancelButton; 2675585c6ef5e8f075bdc3d514887322c6fa683f4cbTingting Wang private Button mSuggestionsLinkButton; 268e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang private boolean mIsSuggestionListCollapsed; 26918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private boolean mSuggestionsShouldAutoSelected = true; 27018906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private long mPreviousContactId = 0; 271e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 272b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private MultiShrinkScroller mScroller; 273d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private SelectAccountDialogFragmentListener mSelectAccountFragmentListener; 2746bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private AsyncTask<Void, Void, Cp2DataCardModel> mEntriesAndActionsTask; 27530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell private AsyncTask<Void, Void, Void> mRecentDataTask; 276e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 277e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang private AggregationSuggestionEngine mAggregationSuggestionEngine; 278e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang private List<Suggestion> mSuggestions; 279e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 280e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang private TreeSet<Long> mSelectedAggregationIds = new TreeSet<>(); 2816bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 2826bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * The last copy of Cp2DataCardModel that was passed to {@link #populateContactAndAboutCard}. 2836bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 2846bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private Cp2DataCardModel mCachedCp2DataCardModel; 285f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell /** 286f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * This scrim's opacity is controlled in two different ways. 1) Before the initial entrance 287f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * animation finishes, the opacity is animated by a value animator. This is designed to 288f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * distract the user from the length of the initial loading time. 2) After the initial 289f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * entrance animation, the opacity is directly related to scroll position. 290f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell */ 2919b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private ColorDrawable mWindowScrim; 292f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell private boolean mIsEntranceAnimationFinished; 293a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell private MaterialColorMapUtils mMaterialColorMapUtils; 2948477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell private boolean mIsExitAnimationInProgress; 2958571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell private boolean mHasComputedThemeColor; 296edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 297a42ef76251778161d27bc07db214b8c81720e476Paul Soulos /** 298a42ef76251778161d27bc07db214b8c81720e476Paul Soulos * Used to stop the ExpandingEntry cards from adjusting between an entry click and the intent 299a42ef76251778161d27bc07db214b8c81720e476Paul Soulos * being launched. 300a42ef76251778161d27bc07db214b8c81720e476Paul Soulos */ 301a42ef76251778161d27bc07db214b8c81720e476Paul Soulos private boolean mHasIntentLaunched; 302a42ef76251778161d27bc07db214b8c81720e476Paul Soulos 3036cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee private Contact mContactData; 3049815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann private ContactLoader mContactLoader; 3059b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private PorterDuffColorFilter mColorFilter; 3068e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell private int mColorFilterColor; 3079815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann 3089758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter(); 3099758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus 310edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 311cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * {@link #LEADING_MIMETYPES} is used to sort MIME-types. 312edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 313edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * <p>The MIME-types in {@link #LEADING_MIMETYPES} appear in the front of the dialog, 314edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * in the order specified here.</p> 315edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 316edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final List<String> LEADING_MIMETYPES = Lists.newArrayList( 317cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos Phone.CONTENT_ITEM_TYPE, SipAddress.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE, 318405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos StructuredPostal.CONTENT_ITEM_TYPE); 319edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 320a153dba33c2152332c5706178a367f52b0550723Paul Soulos private static final List<String> SORTED_ABOUT_CARD_MIMETYPES = Lists.newArrayList( 321a153dba33c2152332c5706178a367f52b0550723Paul Soulos Nickname.CONTENT_ITEM_TYPE, 322a153dba33c2152332c5706178a367f52b0550723Paul Soulos // Phonetic name is inserted after nickname if it is available. 323a153dba33c2152332c5706178a367f52b0550723Paul Soulos // No mimetype for phonetic name exists. 324a153dba33c2152332c5706178a367f52b0550723Paul Soulos Website.CONTENT_ITEM_TYPE, 325a153dba33c2152332c5706178a367f52b0550723Paul Soulos Organization.CONTENT_ITEM_TYPE, 326a153dba33c2152332c5706178a367f52b0550723Paul Soulos Event.CONTENT_ITEM_TYPE, 327a153dba33c2152332c5706178a367f52b0550723Paul Soulos Relation.CONTENT_ITEM_TYPE, 328a153dba33c2152332c5706178a367f52b0550723Paul Soulos Im.CONTENT_ITEM_TYPE, 329a153dba33c2152332c5706178a367f52b0550723Paul Soulos GroupMembership.CONTENT_ITEM_TYPE, 330a153dba33c2152332c5706178a367f52b0550723Paul Soulos Identity.CONTENT_ITEM_TYPE, 331a153dba33c2152332c5706178a367f52b0550723Paul Soulos Note.CONTENT_ITEM_TYPE); 332eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 333c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwell private static final BidiFormatter sBidiFormatter = BidiFormatter.getInstance(); 334c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwell 335b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background contact loader */ 336b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_CONTACT_ID = 0; 337b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 338ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final String KEY_LOADER_EXTRA_PHONES = 339ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_PHONES"; 340ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 341b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background Sms Loader */ 342b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_SMS_ID = 1; 343b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int MAX_SMS_RETRIEVE = 3; 344ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 345ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the back Calendar Loader */ 346899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int LOADER_CALENDAR_ID = 2; 347ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final String KEY_LOADER_EXTRA_EMAILS = 348ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_EMAILS"; 349899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_PAST_CALENDAR_RETRIEVE = 3; 350899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_FUTURE_CALENDAR_RETRIEVE = 3; 351899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 35240d7a65c6e68967f3f486715b194c144d93c296fPaul Soulos 1L * 24L * 60L * 60L * 1000L /* 1 day */; 353899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 35440d7a65c6e68967f3f486715b194c144d93c296fPaul Soulos 7L * 24L * 60L * 60L * 1000L /* 7 days */; 355899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 356ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the background Call Log Loader */ 357ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int LOADER_CALL_LOG_ID = 3; 358ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int MAX_CALL_LOG_RETRIEVE = 3; 3596095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int MIN_NUM_CONTACT_ENTRIES_SHOWN = 3; 3606095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN = 3; 3616095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int CARD_ENTRY_ID_EDIT_CONTACT = -2; 362ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 363ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 364ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int[] mRecentLoaderIds = new int[]{ 365ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_SMS_ID, 366ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALENDAR_ID, 367ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID}; 36812ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner /** 36912ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner * ConcurrentHashMap constructor params: 4 is initial table size, 0.9f is 37012ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner * load factor before resizing, 1 means we only expect a single thread to 37112ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner * write to the map so make only a single shard 37212ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner */ 37312ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner private Map<Integer, List<ContactInteraction>> mRecentLoaderResults = 37412ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner new ConcurrentHashMap<>(4, 0.9f, 1); 375b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 376d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private static final String FRAGMENT_TAG_SELECT_ACCOUNT = "select_account_fragment"; 3776cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee 3782d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos final OnClickListener mEntryClickHandler = new OnClickListener() { 3792d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos @Override 3802d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos public void onClick(View v) { 3812ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final Object entryTagObject = v.getTag(); 3822ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos if (entryTagObject == null || !(entryTagObject instanceof EntryTag)) { 3832ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos Log.w(TAG, "EntryTag was not used correctly"); 3846095369885edcca566a812b551886e29c7ff8039Brian Attwell return; 3856095369885edcca566a812b551886e29c7ff8039Brian Attwell } 3862ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final EntryTag entryTag = (EntryTag) entryTagObject; 3872ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final Intent intent = entryTag.getIntent(); 3882ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final int dataId = entryTag.getId(); 3892ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos 3902ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos if (dataId == CARD_ENTRY_ID_EDIT_CONTACT) { 3912ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos editContact(); 3922d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos return; 3932d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 394ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 39519c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO // Pass the touch point through the intent for use in the InCallUI 39619c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO if (Intent.ACTION_CALL.equals(intent.getAction())) { 39719c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO if (TouchPointManager.getInstance().hasValidPoint()) { 39819c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Bundle extras = new Bundle(); 39919c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO extras.putParcelable(TouchPointManager.TOUCH_POINT, 40019c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO TouchPointManager.getInstance().getPoint()); 40119c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras); 40219c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } 40319c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } 40419c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO 40519c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 40619c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO 40719c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO mHasIntentLaunched = true; 40819c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO try { 40919c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO startActivity(intent); 41019c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } catch (SecurityException ex) { 41119c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.makeText(QuickContactActivity.this, R.string.missing_app, 41219c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.LENGTH_SHORT).show(); 41319c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Log.e(TAG, "QuickContacts does not have permission to launch " 41419c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO + intent); 41519c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } catch (ActivityNotFoundException ex) { 41619c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.makeText(QuickContactActivity.this, R.string.missing_app, 41719c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.LENGTH_SHORT).show(); 41819c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } 41919c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO 420ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Default to USAGE_TYPE_CALL. Usage is summed among all types for sorting each data id 421ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // so the exact usage type is not necessary in all cases 422ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos String usageType = DataUsageFeedback.USAGE_TYPE_CALL; 423ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 42420bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos final Uri intentUri = intent.getData(); 42520bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos if ((intentUri != null && intentUri.getScheme() != null && 4261cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner intentUri.getScheme().equals(ContactsUtils.SCHEME_SMSTO)) || 427ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos (intent.getType() != null && intent.getType().equals(MIMETYPE_SMS))) { 428ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos usageType = DataUsageFeedback.USAGE_TYPE_SHORT_TEXT; 429ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 430ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 431ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Data IDs start at 1 so anything less is invalid 432ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (dataId > 0) { 43320bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos final Uri dataUsageUri = DataUsageFeedback.FEEDBACK_URI.buildUpon() 434ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendPath(String.valueOf(dataId)) 435ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, usageType) 436ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .build(); 4379881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner try { 4389881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner final boolean successful = getContentResolver().update( 4399881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner dataUsageUri, new ContentValues(), null, null) > 0; 4409881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner if (!successful) { 4419881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner Log.w(TAG, "DataUsageFeedback increment failed"); 4429881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner } 4439881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner } catch (SecurityException ex) { 4449881882e769fbf66d728159322e1d8b5e572e36cJay Shrauner Log.w(TAG, "DataUsageFeedback increment failed", ex); 445ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 446ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } else { 447ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Log.w(TAG, "Invalid Data ID"); 448ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 449ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 45070e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen // Pass the touch point through the intent for use in the InCallUI 45170e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen if (Intent.ACTION_CALL.equals(intent.getAction())) { 4521f8a3fda87bf61e579d61e3fdd246548943d070aNancy Chen if (TouchPointManager.getInstance().hasValidPoint()) { 45370e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen Bundle extras = new Bundle(); 4541f8a3fda87bf61e579d61e3fdd246548943d070aNancy Chen extras.putParcelable(TouchPointManager.TOUCH_POINT, 4551f8a3fda87bf61e579d61e3fdd246548943d070aNancy Chen TouchPointManager.getInstance().getPoint()); 4560319222b43927d4d9ce7e2a9070f3543661b5782Tyler Gunn intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras); 45770e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen } 45870e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen } 45970e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen 460793e73c859ed839c28cc37d80d62bde0a361c78aPaul Soulos intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 461793e73c859ed839c28cc37d80d62bde0a361c78aPaul Soulos 462a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 463417309a770568d7b278abc91c46a739020e48157Jay Shrauner try { 464c6100ffd22ae176a3e84a1062d8cb92d955faef2Brian Attwell ImplicitIntentsUtil.startActivityInAppIfPossible(QuickContactActivity.this, intent); 46582a5a35c1a2b83b4118bcba56625f6f25e9663d0Jay Shrauner } catch (SecurityException ex) { 46682a5a35c1a2b83b4118bcba56625f6f25e9663d0Jay Shrauner Toast.makeText(QuickContactActivity.this, R.string.missing_app, 46782a5a35c1a2b83b4118bcba56625f6f25e9663d0Jay Shrauner Toast.LENGTH_SHORT).show(); 46882a5a35c1a2b83b4118bcba56625f6f25e9663d0Jay Shrauner Log.e(TAG, "QuickContacts does not have permission to launch " 46982a5a35c1a2b83b4118bcba56625f6f25e9663d0Jay Shrauner + intent); 470417309a770568d7b278abc91c46a739020e48157Jay Shrauner } catch (ActivityNotFoundException ex) { 471417309a770568d7b278abc91c46a739020e48157Jay Shrauner Toast.makeText(QuickContactActivity.this, R.string.missing_app, 472417309a770568d7b278abc91c46a739020e48157Jay Shrauner Toast.LENGTH_SHORT).show(); 473417309a770568d7b278abc91c46a739020e48157Jay Shrauner } 4742d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 4752d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos }; 4762d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos 477e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell final ExpandingEntryCardViewListener mExpandingEntryCardViewListener 478e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell = new ExpandingEntryCardViewListener() { 479e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell @Override 480e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell public void onCollapse(int heightDelta) { 481e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell mScroller.prepareForShrinkingScrollChild(heightDelta); 482e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell } 4830cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos 4840cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos @Override 485245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell public void onExpand() { 486245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell mScroller.setDisableTouchesForSuppressLayout(/* areTouchesDisabled = */ true); 487245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell } 488245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell 489245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell @Override 490245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell public void onExpandDone() { 491245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell mScroller.setDisableTouchesForSuppressLayout(/* areTouchesDisabled = */ false); 4920cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos } 493e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell }; 494e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell 495e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang @Override 496e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang public void onAggregationSuggestionChange() { 497e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mSuggestions = mAggregationSuggestionEngine.getSuggestions(); 49818906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mCollapsedSuggestionCardView.setVisibility(View.GONE); 49918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mExpandSuggestionCardView.setVisibility(View.GONE); 500e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mSuggestionList.removeAllViews(); 501e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 50296efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang if (mContactData == null) { 50396efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang return; 50496efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang } 50596efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang 506e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang final String suggestionForName = mContactData.getDisplayName(); 507e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang final int suggestionNumber = mSuggestions.size(); 508e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 509e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang if (suggestionNumber <= 0) { 510e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang mSelectedAggregationIds.clear(); 511e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang return; 512e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang } 513e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 5145368489acaadac82706ca0e678ec04d662db702eWenyi Wang ContactPhotoManager.DefaultImageRequest 5155368489acaadac82706ca0e678ec04d662db702eWenyi Wang request = new ContactPhotoManager.DefaultImageRequest( 5165368489acaadac82706ca0e678ec04d662db702eWenyi Wang suggestionForName, mContactData.getLookupKey(), ContactPhotoManager.TYPE_DEFAULT, 5175368489acaadac82706ca0e678ec04d662db702eWenyi Wang /* isCircular */ true ); 5185368489acaadac82706ca0e678ec04d662db702eWenyi Wang final long photoId = mContactData.getPhotoId(); 51918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang final byte[] photoBytes = mContactData.getThumbnailPhotoBinaryData(); 52018906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang if (photoBytes != null) { 5215368489acaadac82706ca0e678ec04d662db702eWenyi Wang ContactPhotoManager.getInstance(this).loadThumbnail(mSuggestionSummaryPhoto, photoId, 5225cf746f679b7866505f8b057565a648d65d1cad8Wenyi Wang /* darkTheme */ false , /* isCircular */ true , request); 523e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang } else { 5245368489acaadac82706ca0e678ec04d662db702eWenyi Wang ContactPhotoManager.DEFAULT_AVATAR.applyDefaultImage(mSuggestionSummaryPhoto, 5255368489acaadac82706ca0e678ec04d662db702eWenyi Wang -1, false, request); 526e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang } 527e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 52818906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang final String suggestionTitle = getResources().getQuantityString( 52918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang R.plurals.quickcontact_suggestion_card_title, suggestionNumber, suggestionNumber); 53018906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mCollapsedSuggestionCardTitle.setText(suggestionTitle); 53118906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mExpandSuggestionCardTitle.setText(suggestionTitle); 53218906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang 533e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang mSuggestionForName.setText(suggestionForName); 5345368489acaadac82706ca0e678ec04d662db702eWenyi Wang final int linkedContactsNumber = mContactData.getRawContacts().size(); 5355368489acaadac82706ca0e678ec04d662db702eWenyi Wang final String contactsInfo; 53696efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang final String accountName = mContactData.getRawContacts().get(0).getAccountName(); 53796efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang if (linkedContactsNumber == 1 && accountName == null) { 53896efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang mSuggestionContactsNumber.setVisibility(View.INVISIBLE); 53996efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang } 54096efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang if (linkedContactsNumber == 1 && accountName != null) { 5415368489acaadac82706ca0e678ec04d662db702eWenyi Wang contactsInfo = getResources().getString(R.string.contact_from_account_name, 54296efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang accountName); 5435368489acaadac82706ca0e678ec04d662db702eWenyi Wang } else { 5445368489acaadac82706ca0e678ec04d662db702eWenyi Wang contactsInfo = getResources().getString( 5455368489acaadac82706ca0e678ec04d662db702eWenyi Wang R.string.quickcontact_contacts_number, linkedContactsNumber); 5465368489acaadac82706ca0e678ec04d662db702eWenyi Wang } 5475368489acaadac82706ca0e678ec04d662db702eWenyi Wang mSuggestionContactsNumber.setText(contactsInfo); 548e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 549e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang final Set<Long> suggestionContactIds = new HashSet<>(); 550e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang for (Suggestion suggestion : mSuggestions) { 551e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang mSuggestionList.addView(inflateSuggestionListView(suggestion)); 552e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang suggestionContactIds.add(suggestion.contactId); 553e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 554e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang 55518906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang if (mIsSuggestionListCollapsed) { 55618906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang collapseSuggestionList(); 55718906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang } else { 55818906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang expandSuggestionList(); 55918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang } 56018906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang 561e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang // Remove contact Ids that are not suggestions. 562e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang final Set<Long> selectedSuggestionIds = com.google.common.collect.Sets.intersection( 563e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang mSelectedAggregationIds, suggestionContactIds); 564e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang mSelectedAggregationIds = new TreeSet<>(selectedSuggestionIds); 56596efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang if (!mSelectedAggregationIds.isEmpty()) { 56696efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang enableLinkButton(); 56796efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang } 568e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 569e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 570e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang private void collapseSuggestionList() { 57118906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mCollapsedSuggestionCardView.setVisibility(View.VISIBLE); 57218906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mExpandSuggestionCardView.setVisibility(View.GONE); 573e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mIsSuggestionListCollapsed = true; 574e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 575e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 576e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang private void expandSuggestionList() { 57718906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mCollapsedSuggestionCardView.setVisibility(View.GONE); 57818906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mExpandSuggestionCardView.setVisibility(View.VISIBLE); 579e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mIsSuggestionListCollapsed = false; 580e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 581e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 58218906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang private View inflateSuggestionListView(final Suggestion suggestion) { 583e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang final LayoutInflater layoutInflater = LayoutInflater.from(this); 584e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang final View suggestionView = layoutInflater.inflate( 585e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang R.layout.quickcontact_suggestion_contact_item, null); 586e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 5875368489acaadac82706ca0e678ec04d662db702eWenyi Wang ContactPhotoManager.DefaultImageRequest 5885368489acaadac82706ca0e678ec04d662db702eWenyi Wang request = new ContactPhotoManager.DefaultImageRequest( 5895368489acaadac82706ca0e678ec04d662db702eWenyi Wang suggestion.name, suggestion.lookupKey, ContactPhotoManager.TYPE_DEFAULT, /* 5905368489acaadac82706ca0e678ec04d662db702eWenyi Wang isCircular */ true); 591e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang final ImageView photo = (ImageView) suggestionView.findViewById( 592e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang R.id.aggregation_suggestion_photo); 593e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang if (suggestion.photo != null) { 5945368489acaadac82706ca0e678ec04d662db702eWenyi Wang ContactPhotoManager.getInstance(this).loadThumbnail(photo, suggestion.photoId, 5955cf746f679b7866505f8b057565a648d65d1cad8Wenyi Wang /* darkTheme */ false, /* isCircular */ true, request); 596e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } else { 5975368489acaadac82706ca0e678ec04d662db702eWenyi Wang ContactPhotoManager.DEFAULT_AVATAR.applyDefaultImage(photo, -1, false, request); 598e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 599e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 600e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang final TextView name = (TextView) suggestionView.findViewById(R.id.aggregation_suggestion_name); 601e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang name.setText(suggestion.name); 602e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 60318906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang final TextView accountNameView = (TextView) suggestionView.findViewById( 60418906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang R.id.aggregation_suggestion_account_name); 60518906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang final String accountName = suggestion.rawContacts.get(0).accountName; 60618906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang if (!TextUtils.isEmpty(accountName)) { 6075368489acaadac82706ca0e678ec04d662db702eWenyi Wang accountNameView.setText( 6085368489acaadac82706ca0e678ec04d662db702eWenyi Wang getResources().getString(R.string.contact_from_account_name, accountName)); 60918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang } else { 61096efbb85af828e3dac9c4e09048c9ef9a7cfdde4Wenyi Wang accountNameView.setVisibility(View.INVISIBLE); 611e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 612e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 613e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang final CheckBox checkbox = (CheckBox) suggestionView.findViewById(R.id.suggestion_checkbox); 61418906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang checkbox.setChecked(mSuggestionsShouldAutoSelected || 61518906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mSelectedAggregationIds.contains(suggestion.contactId)); 61618906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang if (checkbox.isChecked()) { 61718906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mSelectedAggregationIds.add(suggestion.contactId); 61818906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang } 619e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang checkbox.setTag(suggestion.contactId); 620e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang checkbox.setOnClickListener(new OnClickListener() { 621e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang @Override 622e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang public void onClick(View v) { 623e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang final CheckBox checkBox = (CheckBox) v; 624e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang final Long contactId = (Long) checkBox.getTag(); 6255368489acaadac82706ca0e678ec04d662db702eWenyi Wang if (mSelectedAggregationIds.contains(mContactData.getId())) { 6265368489acaadac82706ca0e678ec04d662db702eWenyi Wang mSelectedAggregationIds.remove(mContactData.getId()); 6275368489acaadac82706ca0e678ec04d662db702eWenyi Wang } 628e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang if (checkBox.isChecked()) { 629e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mSelectedAggregationIds.add(contactId); 6305368489acaadac82706ca0e678ec04d662db702eWenyi Wang if (mSelectedAggregationIds.size() >= 1) { 6315368489acaadac82706ca0e678ec04d662db702eWenyi Wang enableLinkButton(); 6325368489acaadac82706ca0e678ec04d662db702eWenyi Wang } 633e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } else { 634e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mSelectedAggregationIds.remove(contactId); 63518906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mSuggestionsShouldAutoSelected = false; 6365368489acaadac82706ca0e678ec04d662db702eWenyi Wang if (mSelectedAggregationIds.isEmpty()) { 6375368489acaadac82706ca0e678ec04d662db702eWenyi Wang disableLinkButton(); 6385368489acaadac82706ca0e678ec04d662db702eWenyi Wang } 639e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 640e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 641e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang }); 64218906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang 643e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang return suggestionView; 644e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 645e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 6465368489acaadac82706ca0e678ec04d662db702eWenyi Wang private void enableLinkButton() { 6475368489acaadac82706ca0e678ec04d662db702eWenyi Wang mSuggestionsLinkButton.setClickable(true); 64833f60d35a16407868de09ca898028e5eca6c6de3Wenyi Wang mSuggestionsLinkButton.getBackground().setColorFilter(getResources().getColor( 64933f60d35a16407868de09ca898028e5eca6c6de3Wenyi Wang R.color.primary_color, getTheme()), PorterDuff.Mode.SRC_ATOP); 65033f60d35a16407868de09ca898028e5eca6c6de3Wenyi Wang mSuggestionsLinkButton.setTextColor(getResources().getColor(android.R.color.white, 65133f60d35a16407868de09ca898028e5eca6c6de3Wenyi Wang getTheme())); 6525368489acaadac82706ca0e678ec04d662db702eWenyi Wang mSuggestionsLinkButton.setOnClickListener(new OnClickListener() { 6535368489acaadac82706ca0e678ec04d662db702eWenyi Wang @Override 6545368489acaadac82706ca0e678ec04d662db702eWenyi Wang public void onClick(View view) { 6555368489acaadac82706ca0e678ec04d662db702eWenyi Wang // Join selected contacts. 6565368489acaadac82706ca0e678ec04d662db702eWenyi Wang if (!mSelectedAggregationIds.contains(mContactData.getId())) { 6575368489acaadac82706ca0e678ec04d662db702eWenyi Wang mSelectedAggregationIds.add(mContactData.getId()); 6585368489acaadac82706ca0e678ec04d662db702eWenyi Wang } 6595368489acaadac82706ca0e678ec04d662db702eWenyi Wang JoinContactsDialogFragment.start( 6605368489acaadac82706ca0e678ec04d662db702eWenyi Wang QuickContactActivity.this, mSelectedAggregationIds); 6615368489acaadac82706ca0e678ec04d662db702eWenyi Wang } 6625368489acaadac82706ca0e678ec04d662db702eWenyi Wang }); 6635368489acaadac82706ca0e678ec04d662db702eWenyi Wang } 6645368489acaadac82706ca0e678ec04d662db702eWenyi Wang 6655368489acaadac82706ca0e678ec04d662db702eWenyi Wang @Override 6665368489acaadac82706ca0e678ec04d662db702eWenyi Wang public void onContactsJoined() { 6675368489acaadac82706ca0e678ec04d662db702eWenyi Wang disableLinkButton(); 6685368489acaadac82706ca0e678ec04d662db702eWenyi Wang } 6695368489acaadac82706ca0e678ec04d662db702eWenyi Wang 6705368489acaadac82706ca0e678ec04d662db702eWenyi Wang private void disableLinkButton() { 6715368489acaadac82706ca0e678ec04d662db702eWenyi Wang mSuggestionsLinkButton.setClickable(false); 6725368489acaadac82706ca0e678ec04d662db702eWenyi Wang mSuggestionsLinkButton.getBackground().setColorFilter( 67333f60d35a16407868de09ca898028e5eca6c6de3Wenyi Wang getResources().getColor(R.color.disabled_button_background, getTheme()), 67433f60d35a16407868de09ca898028e5eca6c6de3Wenyi Wang PorterDuff.Mode.SRC_ATOP); 6755368489acaadac82706ca0e678ec04d662db702eWenyi Wang mSuggestionsLinkButton.setTextColor( 67633f60d35a16407868de09ca898028e5eca6c6de3Wenyi Wang getResources().getColor(R.color.disabled_button_text, getTheme())); 6775368489acaadac82706ca0e678ec04d662db702eWenyi Wang } 6785368489acaadac82706ca0e678ec04d662db702eWenyi Wang 67997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos private interface ContextMenuIds { 68097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos static final int COPY_TEXT = 0; 68197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos static final int CLEAR_DEFAULT = 1; 68297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos static final int SET_DEFAULT = 2; 68397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 68497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 6852a4207fb39330e840436215c896cde911489e111Paul Soulos private final OnCreateContextMenuListener mEntryContextMenuListener = 6862a4207fb39330e840436215c896cde911489e111Paul Soulos new OnCreateContextMenuListener() { 6872a4207fb39330e840436215c896cde911489e111Paul Soulos @Override 6882a4207fb39330e840436215c896cde911489e111Paul Soulos public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 6892a4207fb39330e840436215c896cde911489e111Paul Soulos if (menuInfo == null) { 6902a4207fb39330e840436215c896cde911489e111Paul Soulos return; 6912a4207fb39330e840436215c896cde911489e111Paul Soulos } 69297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final EntryContextMenuInfo info = (EntryContextMenuInfo) menuInfo; 6932a4207fb39330e840436215c896cde911489e111Paul Soulos menu.setHeaderTitle(info.getCopyText()); 69497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menu.add(ContextMenu.NONE, ContextMenuIds.COPY_TEXT, 69597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ContextMenu.NONE, getString(R.string.copy_text)); 69697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 69797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Don't allow setting or clearing of defaults for non-editable contacts 69897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (!isContactEditable()) { 69997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return; 70097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 70197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 70297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final String selectedMimeType = info.getMimeType(); 70397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 70497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Defaults to true will only enable the detail to be copied to the clipboard. 70597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos boolean onlyOneOfMimeType = true; 70697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 70797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Only allow primary support for Phone and Email content types 70897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (Phone.CONTENT_ITEM_TYPE.equals(selectedMimeType)) { 70997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos onlyOneOfMimeType = mOnlyOnePhoneNumber; 71097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } else if (Email.CONTENT_ITEM_TYPE.equals(selectedMimeType)) { 71197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos onlyOneOfMimeType = mOnlyOneEmail; 71297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 71397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 71497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Checking for previously set default 71597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (info.isSuperPrimary()) { 71697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menu.add(ContextMenu.NONE, ContextMenuIds.CLEAR_DEFAULT, 71797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ContextMenu.NONE, getString(R.string.clear_default)); 71897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } else if (!onlyOneOfMimeType) { 71997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menu.add(ContextMenu.NONE, ContextMenuIds.SET_DEFAULT, 72097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ContextMenu.NONE, getString(R.string.set_default)); 72197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 7222a4207fb39330e840436215c896cde911489e111Paul Soulos } 7232a4207fb39330e840436215c896cde911489e111Paul Soulos }; 7242a4207fb39330e840436215c896cde911489e111Paul Soulos 7252a4207fb39330e840436215c896cde911489e111Paul Soulos @Override 7262a4207fb39330e840436215c896cde911489e111Paul Soulos public boolean onContextItemSelected(MenuItem item) { 7272a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo menuInfo; 7282a4207fb39330e840436215c896cde911489e111Paul Soulos try { 7292a4207fb39330e840436215c896cde911489e111Paul Soulos menuInfo = (EntryContextMenuInfo) item.getMenuInfo(); 7302a4207fb39330e840436215c896cde911489e111Paul Soulos } catch (ClassCastException e) { 7312a4207fb39330e840436215c896cde911489e111Paul Soulos Log.e(TAG, "bad menuInfo", e); 7322a4207fb39330e840436215c896cde911489e111Paul Soulos return false; 7332a4207fb39330e840436215c896cde911489e111Paul Soulos } 7342a4207fb39330e840436215c896cde911489e111Paul Soulos 73597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos switch (item.getItemId()) { 73697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos case ContextMenuIds.COPY_TEXT: 73797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ClipboardUtils.copyText(this, menuInfo.getCopyLabel(), menuInfo.getCopyText(), 73897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos true); 73997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return true; 74097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos case ContextMenuIds.SET_DEFAULT: 74197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final Intent setIntent = ContactSaveService.createSetSuperPrimaryIntent(this, 74297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menuInfo.getId()); 74397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos this.startService(setIntent); 74497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return true; 74597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos case ContextMenuIds.CLEAR_DEFAULT: 74697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final Intent clearIntent = ContactSaveService.createClearPrimaryIntent(this, 74797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menuInfo.getId()); 74897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos this.startService(clearIntent); 74997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return true; 75097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos default: 75197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos throw new IllegalArgumentException("Unknown menu option " + item.getItemId()); 75297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 7532a4207fb39330e840436215c896cde911489e111Paul Soulos } 7542a4207fb39330e840436215c896cde911489e111Paul Soulos 755d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell /** 756d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Headless fragment used to handle account selection callbacks invoked from 757d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * {@link DirectoryContactUtil}. 758d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 759d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public static class SelectAccountDialogFragmentListener extends Fragment 760d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell implements SelectAccountDialogFragment.Listener { 761d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 762d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private QuickContactActivity mQuickContactActivity; 763d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 764d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public SelectAccountDialogFragmentListener() {} 765d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 766d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 767d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void onAccountChosen(AccountWithDataSet account, Bundle extraArgs) { 768d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell DirectoryContactUtil.createCopy(mQuickContactActivity.mContactData.getContentValues(), 769d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell account, mQuickContactActivity); 770d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 771d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 772d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 773d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void onAccountSelectorCancelled() {} 774d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 775d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell /** 776d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Set the parent activity. Since rotation can cause this fragment to be used across 777d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * more than one activity instance, we need to explicitly set this value instead 778d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * of making this class non-static. 779d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 780d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void setQuickContactActivity(QuickContactActivity quickContactActivity) { 781d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mQuickContactActivity = quickContactActivity; 782d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 783d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 784d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 785b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell final MultiShrinkScrollerListener mMultiShrinkScrollerListener 786b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell = new MultiShrinkScrollerListener() { 787b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 788b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onScrolledOffBottom() { 789f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell finish(); 790b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 7918a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 7928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 7938a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onEnterFullscreen() { 7948a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 7958a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 7968a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 7978a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 7988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onExitFullscreen() { 7998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 8008a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8018477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 8028477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 8038477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell public void onStartScrollOffBottom() { 8048477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mIsExitAnimationInProgress = true; 8058477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 8068477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 8078477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 808f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void onEntranceAnimationDone() { 809f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = true; 810f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 811f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 812f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell @Override 813f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void onTransparentViewHeightChange(float ratio) { 814f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell if (mIsEntranceAnimationFinished) { 815f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mWindowScrim.setAlpha((int) (0xFF * ratio)); 8168477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 8178477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 818b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell }; 819b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 820eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 821eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 822eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Data items are compared to the same mimetype based off of three qualities: 823eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 1. Super primary 824eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 2. Primary 825eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 3. Times used 826eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 827eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<DataItem> mWithinMimeTypeDataItemComparator = 828eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<DataItem>() { 829eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 830eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(DataItem lhs, DataItem rhs) { 831eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!lhs.getMimeType().equals(rhs.getMimeType())) { 832eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Log.wtf(TAG, "Comparing DataItems with different mimetypes lhs.getMimeType(): " + 833eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getMimeType() + " rhs.getMimeType(): " + rhs.getMimeType()); 834eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 835eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 836eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 837eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lhs.isSuperPrimary()) { 838eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 839eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (rhs.isSuperPrimary()) { 840eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 841eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lhs.isPrimary() && !rhs.isPrimary()) { 842eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 843eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (!lhs.isPrimary() && rhs.isPrimary()) { 844eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 845eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 846eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = 847eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 848eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = 849eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 850eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 851eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return rhsTimesUsed - lhsTimesUsed; 852eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 853eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 854eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 855eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 856cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos /** 857cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * Sorts among different mimetypes based off: 85805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 1. Whether one of the mimetypes is the prioritized mimetype 85905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 2. Number of times used 86005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 3. Last time used 86105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 4. Statically defined 862cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos */ 863eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<List<DataItem>> mAmongstMimeTypeDataItemComparator = 864eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<List<DataItem>> () { 865eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 866eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(List<DataItem> lhsList, List<DataItem> rhsList) { 86705287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final DataItem lhs = lhsList.get(0); 86805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final DataItem rhs = rhsList.get(0); 86905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final String lhsMimeType = lhs.getMimeType(); 87005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final String rhsMimeType = rhs.getMimeType(); 87105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell 87205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 1. Whether one of the mimetypes is the prioritized mimetype 87305287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (!TextUtils.isEmpty(mExtraPrioritizedMimeType) && !lhsMimeType.equals(rhsMimeType)) { 87405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (rhsMimeType.equals(mExtraPrioritizedMimeType)) { 87505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return 1; 87605287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 87705287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (lhsMimeType.equals(mExtraPrioritizedMimeType)) { 87805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return -1; 87905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 88005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 88105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell 88205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 2. Number of times used 883eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 884eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 885eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int timesUsedDifference = rhsTimesUsed - lhsTimesUsed; 886eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (timesUsedDifference != 0) { 887eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return timesUsedDifference; 888eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 889eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 89005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 3. Last time used 891eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lhsLastTimeUsed = 892eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getLastTimeUsed() == null ? 0 : lhs.getLastTimeUsed(); 893eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long rhsLastTimeUsed = 894eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getLastTimeUsed() == null ? 0 : rhs.getLastTimeUsed(); 895eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lastTimeUsedDifference = rhsLastTimeUsed - lhsLastTimeUsed; 896eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lastTimeUsedDifference > 0) { 897eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 898eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lastTimeUsedDifference < 0) { 899eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 900eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 901eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 90205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 4. Resort to a statically defined mimetype order. 90305287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (!lhsMimeType.equals(rhsMimeType)) { 90405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell for (String mimeType : LEADING_MIMETYPES) { 90505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (lhsMimeType.equals(mimeType)) { 90605287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return -1; 90705287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } else if (rhsMimeType.equals(mimeType)) { 90805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return 1; 90905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 910eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 911eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 912eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 913eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 914eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 915eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 916edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @Override 917f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen public boolean dispatchTouchEvent(MotionEvent ev) { 918f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen if (ev.getAction() == MotionEvent.ACTION_DOWN) { 919f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); 920f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen } 921f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen return super.dispatchTouchEvent(ev); 922f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen } 923f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen 924f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen @Override 9258a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onCreate(Bundle savedInstanceState) { 9268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onCreate()"); 9278a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onCreate(savedInstanceState); 928edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 929bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell if (RequestPermissionsActivity.startPermissionActivity(this)) { 930bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell return; 931bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell } 932bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell 9338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getWindow().setStatusBarColor(Color.TRANSPARENT); 9342426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann 935d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(getIntent()); 936dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 93710d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa // Show QuickContact in front of soft input 93810d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 93910d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 94010d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa 941edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann setContentView(R.layout.quickcontact_activity); 942edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 943a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell mMaterialColorMapUtils = new MaterialColorMapUtils(getResources()); 944a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell 9450cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mScroller = (MultiShrinkScroller) findViewById(R.id.multiscroller); 9460cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos 947eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard = (ExpandingEntryCardView) findViewById(R.id.communication_card); 9486095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard = (ExpandingEntryCardView) findViewById(R.id.no_contact_data_card); 949b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card); 950eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard = (ExpandingEntryCardView) findViewById(R.id.about_card); 951edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 95218906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mCollapsedSuggestionCardView = (CardView) findViewById(R.id.collapsed_suggestion_card); 95318906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mExpandSuggestionCardView = (CardView) findViewById(R.id.expand_suggestion_card); 95418906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mCollapasedSuggestionHeader = findViewById(R.id.collapsed_suggestion_header); 95518906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mCollapsedSuggestionCardTitle = (TextView) findViewById( 95618906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang R.id.collapsed_suggestion_card_title); 95718906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mExpandSuggestionCardTitle = (TextView) findViewById(R.id.expand_suggestion_card_title); 958e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mSuggestionSummaryPhoto = (ImageView) findViewById(R.id.suggestion_icon); 959e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mSuggestionForName = (TextView) findViewById(R.id.suggestion_for_name); 9605368489acaadac82706ca0e678ec04d662db702eWenyi Wang mSuggestionContactsNumber = (TextView) findViewById(R.id.suggestion_for_contacts_number); 961e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mSuggestionList = (LinearLayout) findViewById(R.id.suggestion_list); 96218906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mSuggestionsCancelButton= (Button) findViewById(R.id.cancel_button); 9635585c6ef5e8f075bdc3d514887322c6fa683f4cbTingting Wang mSuggestionsLinkButton = (Button) findViewById(R.id.link_button); 9645368489acaadac82706ca0e678ec04d662db702eWenyi Wang final int previousSelectedSuggestion; 965e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang if (savedInstanceState != null) { 966e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mIsSuggestionListCollapsed = savedInstanceState.getBoolean( 967e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang KEY_IS_SUGGESTION_LIST_COLLAPSED, true); 96818906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mPreviousContactId = savedInstanceState.getLong(KEY_PREVIOUS_CONTACT_ID); 96918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mSuggestionsShouldAutoSelected = savedInstanceState.getBoolean( 97018906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang KEY_SUGGESTIONS_AUTO_SELECTED, true); 971e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mSelectedAggregationIds = (TreeSet<Long>) 972e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang savedInstanceState.getSerializable(KEY_SELECTED_SUGGESTION_CONTACTS); 9735368489acaadac82706ca0e678ec04d662db702eWenyi Wang previousSelectedSuggestion = savedInstanceState.getInt(KEY_SELECTED_SUGGESTION_NUMBER); 974e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } else { 975e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mIsSuggestionListCollapsed = true; 976e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mSelectedAggregationIds.clear(); 9775368489acaadac82706ca0e678ec04d662db702eWenyi Wang previousSelectedSuggestion = -1; 9785368489acaadac82706ca0e678ec04d662db702eWenyi Wang } 9795368489acaadac82706ca0e678ec04d662db702eWenyi Wang if (previousSelectedSuggestion == -1 || previousSelectedSuggestion > 0) { 9805368489acaadac82706ca0e678ec04d662db702eWenyi Wang enableLinkButton(); 9815368489acaadac82706ca0e678ec04d662db702eWenyi Wang } else { 9825368489acaadac82706ca0e678ec04d662db702eWenyi Wang disableLinkButton(); 983e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 98418906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mCollapasedSuggestionHeader.setOnClickListener(new OnClickListener() { 98518906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang @Override 98618906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang public void onClick(View view) { 98718906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mCollapsedSuggestionCardView.setVisibility(View.GONE); 98818906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mExpandSuggestionCardView.setVisibility(View.VISIBLE); 98918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mIsSuggestionListCollapsed = false; 99018906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mSuggestionsShouldAutoSelected = true; 99118906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang } 99218906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang }); 99318906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang 99418906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mSuggestionsCancelButton.setOnClickListener(new OnClickListener() { 99518906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang @Override 99618906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang public void onClick(View view) { 99718906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mCollapsedSuggestionCardView.setVisibility(View.VISIBLE); 99818906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mExpandSuggestionCardView.setVisibility(View.GONE); 99918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mIsSuggestionListCollapsed = true; 100018906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang } 100118906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang }); 100218906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang 10036095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setOnClickListener(mEntryClickHandler); 1004eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setOnClickListener(mEntryClickHandler); 1005eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setExpandButtonText( 100623889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos getResources().getString(R.string.expanding_entry_card_view_see_all)); 10072a4207fb39330e840436215c896cde911489e111Paul Soulos mContactCard.setOnCreateContextMenuListener(mEntryContextMenuListener); 1008b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1009b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setOnClickListener(mEntryClickHandler); 1010b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setTitle(getResources().getString(R.string.recent_card_title)); 1011edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1012eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setOnClickListener(mEntryClickHandler); 10132a4207fb39330e840436215c896cde911489e111Paul Soulos mAboutCard.setOnCreateContextMenuListener(mEntryContextMenuListener); 1014eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 101502eaf11669d25fd885606b3b0700358323532cddBrian Attwell mPhotoView = (QuickContactImageView) findViewById(R.id.photo); 101663176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell final View transparentView = findViewById(R.id.transparent_view); 10170d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell if (mScroller != null) { 101863176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell transparentView.setOnClickListener(new OnClickListener() { 10190d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell @Override 10200d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell public void onClick(View v) { 10210d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell mScroller.scrollOffBottom(); 10220d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 10230d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell }); 10240d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 1025edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1026d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell // Allow a shadow to be shown under the toolbar. 1027d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell ViewUtil.addRectangularOutlineProvider(findViewById(R.id.toolbar_parent), getResources()); 1028d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell 1029d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 1030d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell setActionBar(toolbar); 10319b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getActionBar().setTitle(null); 10329b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // Put a TextView with a known resource id into the ActionBar. This allows us to easily 10339b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // find the correct TextView location & size later. 10349b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell toolbar.addView(getLayoutInflater().inflate(R.layout.quickcontact_title_placeholder, null)); 10356219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee 10368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = savedInstanceState != null; 1037f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = mHasAlreadyBeenOpened; 10389b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mWindowScrim = new ColorDrawable(SCRIM_COLOR); 1039f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mWindowScrim.setAlpha(0); 10409b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getWindow().setBackgroundDrawable(mWindowScrim); 1041edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1042c33ae17c9816b770041ee1f9ccde10e7c7eee491Brian Attwell mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED); 1043ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // mScroller needs to perform asynchronous measurements after initalize(), therefore 1044ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // we can't mark this as GONE. 1045ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.INVISIBLE); 10468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 10479b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell setHeaderNameText(R.string.missing_name); 10489b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 1049d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener= (SelectAccountDialogFragmentListener) getFragmentManager() 1050d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell .findFragmentByTag(FRAGMENT_TAG_SELECT_ACCOUNT); 1051d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mSelectAccountFragmentListener == null) { 1052d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener = new SelectAccountDialogFragmentListener(); 1053d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell getFragmentManager().beginTransaction().add(0, mSelectAccountFragmentListener, 1054d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell FRAGMENT_TAG_SELECT_ACCOUNT).commit(); 1055d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener.setRetainInstance(true); 1056d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1057d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener.setQuickContactActivity(this); 105823889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos 1059f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ true, 1060f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell new Runnable() { 1061f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell @Override 1062f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void run() { 1063f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell if (!mHasAlreadyBeenOpened) { 1064f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell // The initial scrim opacity must match the scrim opacity that would be 1065f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell // achieved by scrolling to the starting position. 1066f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final float alphaRatio = mExtraMode == MODE_FULLY_EXPANDED ? 1067f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 1 : mScroller.getStartingTransparentHeightRatio(); 1068f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final int duration = getResources().getInteger( 1069f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell android.R.integer.config_shortAnimTime); 1070f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final int desiredAlpha = (int) (0xFF * alphaRatio); 1071f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell ObjectAnimator o = ObjectAnimator.ofInt(mWindowScrim, "alpha", 0, 1072f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell desiredAlpha).setDuration(duration); 1073f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 1074f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell o.start(); 1075f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 1076f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 1077f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell }); 1078f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 10799b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (savedInstanceState != null) { 10809b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell final int color = savedInstanceState.getInt(KEY_THEME_COLOR, 0); 1081ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 1082ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell new Runnable() { 1083ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell @Override 1084ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell public void run() { 1085ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for the pre draw before setting the initial scroll 1086ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // value. Prior to pre draw all scroll values are invalid. 1087ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (mHasAlreadyBeenOpened) { 1088ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.VISIBLE); 1089ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setScroll(mScroller.getScrollNeededToBeFullScreen()); 1090ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 1091ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for pre draw for setting the theme color. Setting the 1092ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // header tint before the MultiShrinkScroller has been measured will 1093ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // cause incorrect tinting calculations. 1094ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (color != 0) { 1095a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell setThemeColor(mMaterialColorMapUtils 1096a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell .calculatePrimaryAndSecondaryColor(color)); 10979b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 1098ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 1099ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell }); 11009b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 11019b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 11028a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 11038a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 11048a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1105405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos @Override 1106405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos protected void onActivityResult(int requestCode, int resultCode, Intent data) { 1107d1cb9045bffc3843f5a294d41ce4608c701bccccWenyi Wang final boolean deletedOrSplit = requestCode == REQUEST_CODE_CONTACT_EDITOR_ACTIVITY && 1108d1cb9045bffc3843f5a294d41ce4608c701bccccWenyi Wang (resultCode == ContactDeletionInteraction.RESULT_CODE_DELETED || 1109d1cb9045bffc3843f5a294d41ce4608c701bccccWenyi Wang resultCode == ContactEditorBaseActivity.RESULT_CODE_SPLIT); 1110d1cb9045bffc3843f5a294d41ce4608c701bccccWenyi Wang if (deletedOrSplit) { 11118a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell finish(); 1112ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } else if (requestCode == REQUEST_CODE_CONTACT_SELECTION_ACTIVITY && 1113ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos resultCode != RESULT_CANCELED) { 1114ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos processIntent(data); 1115b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 11168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 1117dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 11188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 11198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onNewIntent(Intent intent) { 11208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onNewIntent(intent); 11218a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 1122f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = true; 11238571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = false; 1124d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(intent); 1125d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1126d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 11279b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell @Override 11289b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell public void onSaveInstanceState(Bundle savedInstanceState) { 11299b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell super.onSaveInstanceState(savedInstanceState); 11309b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mColorFilter != null) { 11318e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell savedInstanceState.putInt(KEY_THEME_COLOR, mColorFilterColor); 11329b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 1133e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang savedInstanceState.putBoolean(KEY_IS_SUGGESTION_LIST_COLLAPSED, mIsSuggestionListCollapsed); 113418906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang savedInstanceState.putLong(KEY_PREVIOUS_CONTACT_ID, mPreviousContactId); 113518906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang savedInstanceState.putBoolean( 113618906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang KEY_SUGGESTIONS_AUTO_SELECTED, mSuggestionsShouldAutoSelected); 1137e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang savedInstanceState.putSerializable( 1138e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang KEY_SELECTED_SUGGESTION_CONTACTS, mSelectedAggregationIds); 11395368489acaadac82706ca0e678ec04d662db702eWenyi Wang final int selectedSuggestion; 11405368489acaadac82706ca0e678ec04d662db702eWenyi Wang if (mSelectedAggregationIds.contains(mContactData.getId())) { 11415368489acaadac82706ca0e678ec04d662db702eWenyi Wang selectedSuggestion = mSelectedAggregationIds.size() - 1; 11425368489acaadac82706ca0e678ec04d662db702eWenyi Wang } else { 11435368489acaadac82706ca0e678ec04d662db702eWenyi Wang selectedSuggestion = mSelectedAggregationIds.size(); 11445368489acaadac82706ca0e678ec04d662db702eWenyi Wang } 11455368489acaadac82706ca0e678ec04d662db702eWenyi Wang savedInstanceState.putInt(KEY_SELECTED_SUGGESTION_NUMBER, selectedSuggestion); 11469b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 11479b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 1148d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void processIntent(Intent intent) { 1149f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos if (intent == null) { 1150f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos finish(); 1151f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos return; 1152f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos } 1153d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell Uri lookupUri = intent.getData(); 1154d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1155d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Check to see whether it comes from the old version. 1156d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) { 1157d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final long rawContactId = ContentUris.parseId(lookupUri); 1158d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell lookupUri = RawContacts.getContactLookupUri(getContentResolver(), 1159d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); 1160d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 116105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, QuickContact.MODE_LARGE); 116205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell mExtraPrioritizedMimeType = getIntent().getStringExtra(QuickContact.EXTRA_PRIORITIZED_MIMETYPE); 1163d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Uri oldLookupUri = mLookupUri; 1164d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1165fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner if (lookupUri == null) { 1166fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner finish(); 1167fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner return; 1168fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner } 1169fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner mLookupUri = lookupUri; 1170d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES); 1171d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (oldLookupUri == null) { 1172d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactLoader = (ContactLoader) getLoaderManager().initLoader( 1173d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell LOADER_CONTACT_ID, null, mLoaderContactCallbacks); 1174d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (oldLookupUri != mLookupUri) { 1175d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // After copying a directory contact, the contact URI changes. Therefore, 1176d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // we need to restart the loader and reload the new contact. 117759a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell destroyInteractionLoaders(); 1178405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos mContactLoader = (ContactLoader) getLoaderManager().restartLoader( 1179405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos LOADER_CONTACT_ID, null, mLoaderContactCallbacks); 118059a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell mCachedCp2DataCardModel = null; 1181d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 11822d150da246632b1649999cfabed776133b097775Brian Attwell 11832d150da246632b1649999cfabed776133b097775Brian Attwell NfcHandler.register(this, mLookupUri); 11842426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann } 1185edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 118659a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell private void destroyInteractionLoaders() { 118759a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell for (int interactionLoaderId : mRecentLoaderIds) { 118859a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell getLoaderManager().destroyLoader(interactionLoaderId); 118959a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell } 119059a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell } 119159a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell 1192b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private void runEntranceAnimation() { 11938a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mHasAlreadyBeenOpened) { 11948a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 11958a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 11968a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 1197c33ae17c9816b770041ee1f9ccde10e7c7eee491Brian Attwell mScroller.scrollUpForEntranceAnimation(mExtraMode != MODE_FULLY_EXPANDED); 1198b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 1199b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 120081281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 1201d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void setHeaderNameText(int resId) { 12029b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 12039f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang mScroller.setTitle(getText(resId) == null ? null : getText(resId).toString(), 12049f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang /* isPhoneNumber= */ false); 12059b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 120681281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 120781281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 120881281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 12099f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang private void setHeaderNameText(String value, boolean isPhoneNumber) { 1210d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (!TextUtils.isEmpty(value)) { 12119b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 12129f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang mScroller.setTitle(value, isPhoneNumber); 12139b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 121481281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 121581281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 121681281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 121781281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** 1218edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Check if the given MIME-type appears in the list of excluded MIME-types 1219edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * that the most-recent caller requested. 1220edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 1221edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private boolean isMimeExcluded(String mimeType) { 1222edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (mExcludeMimes == null) return false; 1223edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann for (String excludedMime : mExcludeMimes) { 1224edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (TextUtils.equals(excludedMime, mimeType)) { 1225edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return true; 1226edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1227edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1228edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return false; 1229edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1230edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1231edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 1232cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann * Handle the result from the ContactLoader 1233edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 12348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void bindContactData(final Contact data) { 12358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("bindContactData"); 12366cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee mContactData = data; 1237d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell invalidateOptionsMenu(); 1238edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 12398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 12408a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("Set display photo & name"); 1241dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 124202eaf11669d25fd885606b3b0700358323532cddBrian Attwell mPhotoView.setIsBusiness(mContactData.isDisplayNameFromOrganization()); 12436219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee mPhotoSetter.setupContactPhoto(data, mPhotoView); 124431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell extractAndApplyTintFromPhotoViewAsynchronously(); 1245df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang final String displayName = ContactDisplayUtils.getDisplayName(this, data).toString(); 12469f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang setHeaderNameText( 12479f153a02a56b9d97dc51371243c52e79fbce5813Tingting Wang displayName, mContactData.getDisplayNameSource() == DisplayNameSources.PHONE); 1248df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang final String phoneticName = ContactDisplayUtils.getPhoneticName(this, data); 1249df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang if (mScroller != null) { 1250df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang if (mContactData.getDisplayNameSource() != DisplayNameSources.STRUCTURED_PHONETIC_NAME 1251df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang && !TextUtils.isEmpty(phoneticName)) { 1252df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang mScroller.setPhoneticName(phoneticName); 1253df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang } else { 1254df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang mScroller.setPhoneticNameGone(); 1255df65d168660ce7ebd4961335e3363eb7c267e0c6Tingting Wang } 1256d5b686e73dc50d90fd44dc5c738d243a81a6cc31Tingting Wang } 1257edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 12588a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 1259dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 12606bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mEntriesAndActionsTask = new AsyncTask<Void, Void, Cp2DataCardModel>() { 12618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 12628a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 12636bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell protected Cp2DataCardModel doInBackground( 1264eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Void... params) { 1265eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return generateDataModelFromContact(data); 12668a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12678a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 12688a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 12696bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell protected void onPostExecute(Cp2DataCardModel cardDataModel) { 12706bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell super.onPostExecute(cardDataModel); 12718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Check that original AsyncTask parameters are still valid and the activity 12728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // is still running before binding to UI. A new intent could invalidate 12738a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the results, for example. 12748a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (data == mContactData && !isCancelled()) { 12756bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell bindDataToCards(cardDataModel); 12768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell showActivity(); 12778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }; 12808a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.execute(); 12818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 12828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 12836bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void bindDataToCards(Cp2DataCardModel cp2DataCardModel) { 12846bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell startInteractionLoaders(cp2DataCardModel); 12856bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell populateContactAndAboutCard(cp2DataCardModel); 1286e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang populateSuggestionCard(); 1287eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1288eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 12896bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void startInteractionLoaders(Cp2DataCardModel cp2DataCardModel) { 12906bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final Map<String, List<DataItem>> dataItemsMap = cp2DataCardModel.dataItemsMap; 12916bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> phoneDataItems = dataItemsMap.get(Phone.CONTENT_ITEM_TYPE); 129297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (phoneDataItems != null && phoneDataItems.size() == 1) { 129397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos mOnlyOnePhoneNumber = true; 129497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 1295eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] phoneNumbers = null; 1296eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (phoneDataItems != null) { 1297eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers = new String[phoneDataItems.size()]; 1298eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < phoneDataItems.size(); ++i) { 1299eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers[i] = ((PhoneDataItem) phoneDataItems.get(i)).getNumber(); 1300eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1301eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1302ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle phonesExtraBundle = new Bundle(); 1303eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_PHONES, phoneNumbers); 1304eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1305eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("start sms loader"); 13068a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getLoaderManager().initLoader( 13078a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell LOADER_SMS_ID, 1308ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 1309ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos mLoaderInteractionsCallbacks); 1310ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.endSection(); 1311ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 1312ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.beginSection("start call log loader"); 1313ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos getLoaderManager().initLoader( 1314ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID, 1315ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 13168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mLoaderInteractionsCallbacks); 1317899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.endSection(); 13188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1319eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1320899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.beginSection("start calendar loader"); 13216bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> emailDataItems = dataItemsMap.get(Email.CONTENT_ITEM_TYPE); 132297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (emailDataItems != null && emailDataItems.size() == 1) { 132397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos mOnlyOneEmail = true; 132497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 1325eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] emailAddresses = null; 1326eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (emailDataItems != null) { 1327eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses = new String[emailDataItems.size()]; 1328eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < emailDataItems.size(); ++i) { 1329eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses[i] = ((EmailDataItem) emailDataItems.get(i)).getAddress(); 1330eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1331eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1332ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle emailsExtraBundle = new Bundle(); 1333eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailsExtraBundle.putStringArray(KEY_LOADER_EXTRA_EMAILS, emailAddresses); 1334899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos getLoaderManager().initLoader( 1335899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos LOADER_CALENDAR_ID, 1336ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos emailsExtraBundle, 1337899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos mLoaderInteractionsCallbacks); 13388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 13398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 13408a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 13418a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void showActivity() { 13428a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller != null) { 13438a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mScroller.setVisibility(View.VISIBLE); 13448a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 13458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell new Runnable() { 13468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 13478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void run() { 13488a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell runEntranceAnimation(); 13498a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 13508a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }); 13518a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 13528a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 13538a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 13546bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private List<List<Entry>> buildAboutCardEntries(Map<String, List<DataItem>> dataItemsMap) { 1355a153dba33c2152332c5706178a367f52b0550723Paul Soulos final List<List<Entry>> aboutCardEntries = new ArrayList<>(); 1356a153dba33c2152332c5706178a367f52b0550723Paul Soulos for (String mimetype : SORTED_ABOUT_CARD_MIMETYPES) { 13576bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> mimeTypeItems = dataItemsMap.get(mimetype); 1358a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (mimeTypeItems == null) { 1359a153dba33c2152332c5706178a367f52b0550723Paul Soulos continue; 1360a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 13616bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // Set aboutCardTitleOut = null, since SORTED_ABOUT_CARD_MIMETYPES doesn't contain 13626bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // the name mimetype. 13636bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<Entry> aboutEntries = dataItemsToEntries(mimeTypeItems, 13646bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /* aboutCardTitleOut = */ null); 1365a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (aboutEntries.size() > 0) { 1366a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(aboutEntries); 1367a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1368a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1369a153dba33c2152332c5706178a367f52b0550723Paul Soulos return aboutCardEntries; 1370a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1371a153dba33c2152332c5706178a367f52b0550723Paul Soulos 1372a42ef76251778161d27bc07db214b8c81720e476Paul Soulos @Override 1373a42ef76251778161d27bc07db214b8c81720e476Paul Soulos protected void onResume() { 1374a42ef76251778161d27bc07db214b8c81720e476Paul Soulos super.onResume(); 1375a42ef76251778161d27bc07db214b8c81720e476Paul Soulos // If returning from a launched activity, repopulate the contact and about card 1376a42ef76251778161d27bc07db214b8c81720e476Paul Soulos if (mHasIntentLaunched) { 1377a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = false; 13786bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell populateContactAndAboutCard(mCachedCp2DataCardModel); 1379a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 138059a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell 138159a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell // When exiting the activity and resuming, we want to force a full reload of all the 138259a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell // interaction data in case something changed in the background. On screen rotation, 138359a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell // we don't need to do this. And, mCachedCp2DataCardModel will be null, so we won't. 138459a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell if (mCachedCp2DataCardModel != null) { 138559a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell destroyInteractionLoaders(); 138659a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell startInteractionLoaders(mCachedCp2DataCardModel); 138759a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell } 1388a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 1389a42ef76251778161d27bc07db214b8c81720e476Paul Soulos 1390e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang private void populateSuggestionCard() { 1391e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang // Initialize suggestion related view and data. 139218906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang if (mPreviousContactId != mContactData.getId()) { 139318906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mCollapsedSuggestionCardView.setVisibility(View.GONE); 139418906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mExpandSuggestionCardView.setVisibility(View.GONE); 139518906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mIsSuggestionListCollapsed = true; 13960fafb0e2813a28b31a71e908d30e18a6edaa3d95Tingting Wang mSuggestionList.removeAllViews(); 13970fafb0e2813a28b31a71e908d30e18a6edaa3d95Tingting Wang } 1398e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 13993d65ea5f6113c497f09abf18d3f11abdcd1c894fTingting Wang // Do not show the card when it's directory contact or invisible. 14003d65ea5f6113c497f09abf18d3f11abdcd1c894fTingting Wang if (DirectoryContactUtil.isDirectoryContact(mContactData) 14013d65ea5f6113c497f09abf18d3f11abdcd1c894fTingting Wang || InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { 14023d65ea5f6113c497f09abf18d3f11abdcd1c894fTingting Wang return; 14033d65ea5f6113c497f09abf18d3f11abdcd1c894fTingting Wang } 14043d65ea5f6113c497f09abf18d3f11abdcd1c894fTingting Wang 1405e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang if (mAggregationSuggestionEngine == null) { 1406e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mAggregationSuggestionEngine = new AggregationSuggestionEngine(this); 1407e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mAggregationSuggestionEngine.setListener(this); 1408e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang mAggregationSuggestionEngine.setSuggestionsLimit(getResources().getInteger( 1409e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang R.integer.quickcontact_suggestions_limit)); 1410e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mAggregationSuggestionEngine.start(); 1411e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 1412e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 1413e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mAggregationSuggestionEngine.setContactId(mContactData.getId()); 141418906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang if (mPreviousContactId != 0 141518906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang && mPreviousContactId != mContactData.getId()) { 1416e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang // Clear selected Ids when listing suggestions for new contact Id. 1417e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang mSelectedAggregationIds.clear(); 1418e29b6943ade6f5e32b7caf85dd127673d710f7e3Tingting Wang } 141918906c03230be7de5b8e8bf663312cbc9a7c3097Tingting Wang mPreviousContactId = mContactData.getId(); 1420e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 1421e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang // Trigger suggestion engine to compute suggestions. 1422a1af0c833e7b4113126131e9949c3d4c9579e5dfTingting Wang if (mContactData.getId() <= 0) { 1423a1af0c833e7b4113126131e9949c3d4c9579e5dfTingting Wang return; 1424a1af0c833e7b4113126131e9949c3d4c9579e5dfTingting Wang } 1425e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang final ContentValues values = new ContentValues(); 1426e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, 1427e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mContactData.getDisplayName()); 1428e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang values.put(ContactsContract.CommonDataKinds.StructuredName.PHONETIC_FAMILY_NAME, 1429e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mContactData.getPhoneticName()); 1430e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mAggregationSuggestionEngine.onNameChange(ValuesDelta.fromBefore(values)); 1431e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 1432e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 14336bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void populateContactAndAboutCard(Cp2DataCardModel cp2DataCardModel) { 14346bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mCachedCp2DataCardModel = cp2DataCardModel; 14356bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (mHasIntentLaunched || cp2DataCardModel == null) { 1436a42ef76251778161d27bc07db214b8c81720e476Paul Soulos return; 1437a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 1438eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind contact card"); 1439eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 14406bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> contactCardEntries = cp2DataCardModel.contactCardEntries; 14416bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> aboutCardEntries = cp2DataCardModel.aboutCardEntries; 14426bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final String customAboutCardName = cp2DataCardModel.customAboutCardName; 1443eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1444eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (contactCardEntries.size() > 0) { 144505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final boolean firstEntriesArePrioritizedMimeType = 144605287bf0cea303b93802a629aa883fb6322ca342Brian Attwell !TextUtils.isEmpty(mExtraPrioritizedMimeType) && 144705287bf0cea303b93802a629aa883fb6322ca342Brian Attwell mCachedCp2DataCardModel.dataItemsMap.containsKey(mExtraPrioritizedMimeType) && 144805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell mCachedCp2DataCardModel.dataItemsMap.get(mExtraPrioritizedMimeType).size() != 0; 1449eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.initialize(contactCardEntries, 1450eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* numInitialVisibleEntries = */ MIN_NUM_CONTACT_ENTRIES_SHOWN, 1451c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos /* isExpanded = */ mContactCard.isExpanded(), 145289966b4ed8cc9d385e5ac6b4a7e9e08ada387eb0Paul Soulos /* isAlwaysExpanded = */ false, 14530cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mExpandingEntryCardViewListener, 145405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell mScroller, 145505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell firstEntriesArePrioritizedMimeType); 1456eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.VISIBLE); 1457eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1458eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.GONE); 1459eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1460eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 14618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1462eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind about card"); 1463c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos // Phonetic name is not a data item, so the entry needs to be created separately 1464c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos final String phoneticName = mContactData.getPhoneticName(); 1465c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos if (!TextUtils.isEmpty(phoneticName)) { 1466c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos Entry phoneticEntry = new Entry(/* viewId = */ -1, 1467c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* icon = */ null, 1468c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos getResources().getString(R.string.name_phonetic), 1469c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos phoneticName, 14708a3fe52802135be2402a5b216325615fb796a509Walter Jang /* subHeaderIcon = */ null, 1471c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* text = */ null, 14728a3fe52802135be2402a5b216325615fb796a509Walter Jang /* textIcon = */ null, 147323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos /* primaryContentDescription = */ null, 1474c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* intent = */ null, 1475c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateIcon = */ null, 1476c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateIntent = */ null, 1477c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateContentDescription = */ null, 1478c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* shouldApplyColor = */ false, 14792a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, 14802a4207fb39330e840436215c896cde911489e111Paul Soulos /* EntryContextMenuInfo = */ new EntryContextMenuInfo(phoneticName, 148197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos getResources().getString(R.string.name_phonetic), 148297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos /* mimeType = */ null, /* id = */ -1, /* isPrimary = */ false), 148348fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, 148448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIntent = */ null, 148548290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos /* thirdContentDescription = */ null, 14865f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdAction = */ Entry.ACTION_NONE, 14875f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdExtras = */ null, 14885f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* iconResourceId = */ 0); 1489c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos List<Entry> phoneticList = new ArrayList<>(); 1490c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos phoneticList.add(phoneticEntry); 1491a153dba33c2152332c5706178a367f52b0550723Paul Soulos // Phonetic name comes after nickname. Check to see if the first entry type is nickname 1492a0fa4c18dc111ceea9ff47f35ee01fecc1003578Paul Soulos if (aboutCardEntries.size() > 0 && aboutCardEntries.get(0).get(0).getHeader().equals( 1493a153dba33c2152332c5706178a367f52b0550723Paul Soulos getResources().getString(R.string.header_nickname_entry))) { 1494a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(1, phoneticList); 1495a153dba33c2152332c5706178a367f52b0550723Paul Soulos } else { 1496a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(0, phoneticList); 1497a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1498c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos } 1499c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos 15006bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!TextUtils.isEmpty(customAboutCardName)) { 15016bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mAboutCard.setTitle(customAboutCardName); 15026bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 15036bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 15043b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox mAboutCard.initialize(aboutCardEntries, 15053b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox /* numInitialVisibleEntries = */ 1, 15063b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox /* isExpanded = */ true, 15073b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox /* isAlwaysExpanded = */ true, 15083b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox mExpandingEntryCardViewListener, 15093b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox mScroller); 15106095369885edcca566a812b551886e29c7ff8039Brian Attwell 15116095369885edcca566a812b551886e29c7ff8039Brian Attwell if (contactCardEntries.size() == 0 && aboutCardEntries.size() == 0) { 15126095369885edcca566a812b551886e29c7ff8039Brian Attwell initializeNoContactDetailCard(); 15136095369885edcca566a812b551886e29c7ff8039Brian Attwell } else { 15146095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setVisibility(View.GONE); 15156095369885edcca566a812b551886e29c7ff8039Brian Attwell } 15166095369885edcca566a812b551886e29c7ff8039Brian Attwell 1517a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos // If the Recent card is already initialized (all recent data is loaded), show the About 1518a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos // card if it has entries. Otherwise About card visibility will be set in bindRecentData() 1519a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos if (isAllRecentDataLoaded() && aboutCardEntries.size() > 0) { 1520a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos mAboutCard.setVisibility(View.VISIBLE); 1521a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos } 1522eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 1523eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1524eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1525eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 15266095369885edcca566a812b551886e29c7ff8039Brian Attwell * Create a card that shows "Add email" and "Add phone number" entries in grey. 15276095369885edcca566a812b551886e29c7ff8039Brian Attwell */ 15286095369885edcca566a812b551886e29c7ff8039Brian Attwell private void initializeNoContactDetailCard() { 15296095369885edcca566a812b551886e29c7ff8039Brian Attwell final Drawable phoneIcon = getResources().getDrawable( 15306095369885edcca566a812b551886e29c7ff8039Brian Attwell R.drawable.ic_phone_24dp).mutate(); 15316095369885edcca566a812b551886e29c7ff8039Brian Attwell final Entry phonePromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, 15326095369885edcca566a812b551886e29c7ff8039Brian Attwell phoneIcon, getString(R.string.quickcontact_add_phone_number), 15338a3fe52802135be2402a5b216325615fb796a509Walter Jang /* subHeader = */ null, /* subHeaderIcon = */ null, /* text = */ null, 15348a3fe52802135be2402a5b216325615fb796a509Walter Jang /* textIcon = */ null, /* primaryContentDescription = */ null, 153523e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos getEditContactIntent(), 1536dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIcon = */ null, /* alternateIntent = */ null, 1537714455bba22b99d168a2e864dfbc74a6e30dfdb6Paul Soulos /* alternateContentDescription = */ null, /* shouldApplyColor = */ true, 153848fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* isEditable = */ false, /* EntryContextMenuInfo = */ null, 153948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, /* thirdIntent = */ null, 15405f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdContentDescription = */ null, 15415f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdAction = */ Entry.ACTION_NONE, 15425f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdExtras = */ null, 15435f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn R.drawable.ic_phone_24dp); 15446095369885edcca566a812b551886e29c7ff8039Brian Attwell 15456095369885edcca566a812b551886e29c7ff8039Brian Attwell final Drawable emailIcon = getResources().getDrawable( 15466095369885edcca566a812b551886e29c7ff8039Brian Attwell R.drawable.ic_email_24dp).mutate(); 15476095369885edcca566a812b551886e29c7ff8039Brian Attwell final Entry emailPromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, 15486095369885edcca566a812b551886e29c7ff8039Brian Attwell emailIcon, getString(R.string.quickcontact_add_email), /* subHeader = */ null, 15498a3fe52802135be2402a5b216325615fb796a509Walter Jang /* subHeaderIcon = */ null, 15508a3fe52802135be2402a5b216325615fb796a509Walter Jang /* text = */ null, /* textIcon = */ null, /* primaryContentDescription = */ null, 155123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos getEditContactIntent(), /* alternateIcon = */ null, 1552dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIntent = */ null, /* alternateContentDescription = */ null, 15532a4207fb39330e840436215c896cde911489e111Paul Soulos /* shouldApplyColor = */ true, /* isEditable = */ false, 155448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* EntryContextMenuInfo = */ null, /* thirdIcon = */ null, 155548290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos /* thirdIntent = */ null, /* thirdContentDescription = */ null, 15565f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdAction = */ Entry.ACTION_NONE, /* thirdExtras = */ null, 155748290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos R.drawable.ic_email_24dp); 15586095369885edcca566a812b551886e29c7ff8039Brian Attwell 15596095369885edcca566a812b551886e29c7ff8039Brian Attwell final List<List<Entry>> promptEntries = new ArrayList<>(); 15606095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.add(new ArrayList<Entry>(1)); 15616095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.add(new ArrayList<Entry>(1)); 15626095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.get(0).add(phonePromptEntry); 15636095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.get(1).add(emailPromptEntry); 15646095369885edcca566a812b551886e29c7ff8039Brian Attwell 15656095369885edcca566a812b551886e29c7ff8039Brian Attwell final int subHeaderTextColor = getResources().getColor( 15666095369885edcca566a812b551886e29c7ff8039Brian Attwell R.color.quickcontact_entry_sub_header_text_color); 15676095369885edcca566a812b551886e29c7ff8039Brian Attwell final PorterDuffColorFilter greyColorFilter = 15686095369885edcca566a812b551886e29c7ff8039Brian Attwell new PorterDuffColorFilter(subHeaderTextColor, PorterDuff.Mode.SRC_ATOP); 1569c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos mNoContactDetailsCard.initialize(promptEntries, 2, /* isExpanded = */ true, 15700cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos /* isAlwaysExpanded = */ true, mExpandingEntryCardViewListener, mScroller); 15716095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setVisibility(View.VISIBLE); 15726095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setEntryHeaderColor(subHeaderTextColor); 15736095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setColorAndFilter(subHeaderTextColor, greyColorFilter); 15746095369885edcca566a812b551886e29c7ff8039Brian Attwell } 15756095369885edcca566a812b551886e29c7ff8039Brian Attwell 15766095369885edcca566a812b551886e29c7ff8039Brian Attwell /** 1577eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Builds the {@link DataItem}s Map out of the Contact. 1578eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param data The contact to build the data from. 1579eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return A pair containing a list of data items sorted within mimetype and sorted 1580eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * amongst mimetype. The map goes from mimetype string to the sorted list of data items within 1581eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * mimetype 1582eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 15836bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private Cp2DataCardModel generateDataModelFromContact( 1584eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Contact data) { 1585eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("Build data items map"); 1586eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1587eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Map<String, List<DataItem>> dataItemsMap = new HashMap<>(); 15888bf96e78497ea9c8c893bcb357fc1e3175fb2e9bBrian Attwell 15898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final ResolveCache cache = ResolveCache.getInstance(this); 1590851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (RawContact rawContact : data.getRawContacts()) { 1591851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (DataItem dataItem : rawContact.getDataItems()) { 1592eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setRawContactId(rawContact.getId()); 1593eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1594851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final String mimeType = dataItem.getMimeType(); 1595eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (mimeType == null) continue; 1596eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 159747b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final AccountType accountType = rawContact.getAccountType(this); 159847b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final DataKind dataKind = AccountTypeManager.getInstance(this) 159947b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng .getKindOrFallback(accountType, mimeType); 1600eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataKind == null) continue; 1601cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1602eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setDataKind(dataKind); 1603b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1604eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean hasData = !TextUtils.isEmpty(dataItem.buildDataString(this, 1605eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataKind)); 1606899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 1607eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (isMimeExcluded(mimeType) || !hasData) continue; 1608edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1609eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos List<DataItem> dataItemListByType = dataItemsMap.get(mimeType); 1610eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItemListByType == null) { 1611eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType = new ArrayList<>(); 1612eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsMap.put(mimeType, dataItemListByType); 1613edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1614eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType.add(dataItem); 1615edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1616edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 16178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 1618edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1619eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort within mimetypes"); 162016339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos /* 162116339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos * Sorting is a multi part step. The end result is to a have a sorted list of the most 1622eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * used data items, one per mimetype. Then, within each mimetype, the list of data items 1623eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * for that type is also sorted, based off of {super primary, primary, times used} in that 1624eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * order. 162516339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos */ 1626eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<List<DataItem>> dataItemsList = new ArrayList<>(); 1627eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (List<DataItem> mimeTypeDataItems : dataItemsMap.values()) { 1628eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Remove duplicate data items 1629eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collapser.collapseList(mimeTypeDataItems, this); 1630eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort within mimetype 1631eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(mimeTypeDataItems, mWithinMimeTypeDataItemComparator); 1632eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Add to the list of data item lists 1633eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsList.add(mimeTypeDataItems); 1634edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1635eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 1636edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1637eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort amongst mimetypes"); 1638eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort amongst mimetypes to bubble up the top data items for the contact card 1639eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(dataItemsList, mAmongstMimeTypeDataItemComparator); 1640eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 164116339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos 16426bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Trace.beginSection("cp2 data items to entries"); 16436bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 16446bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> contactCardEntries = new ArrayList<>(); 16456bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> aboutCardEntries = buildAboutCardEntries(dataItemsMap); 16466bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final MutableString aboutCardName = new MutableString(); 16476bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 16486bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell for (int i = 0; i < dataItemsList.size(); ++i) { 16496bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> dataItemsByMimeType = dataItemsList.get(i); 16506bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final DataItem topDataItem = dataItemsByMimeType.get(0); 16516bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (SORTED_ABOUT_CARD_MIMETYPES.contains(topDataItem.getMimeType())) { 16526bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // About card mimetypes are built in buildAboutCardEntries, skip here 16536bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell continue; 16546bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } else { 16556bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell List<Entry> contactEntries = dataItemsToEntries(dataItemsList.get(i), 16566bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell aboutCardName); 16576bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (contactEntries.size() > 0) { 16586bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell contactCardEntries.add(contactEntries); 16596bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 16606bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 16616bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 16626bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 16636bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Trace.endSection(); 16646bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 16656bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final Cp2DataCardModel dataModel = new Cp2DataCardModel(); 16666bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.customAboutCardName = aboutCardName.value; 16676bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.aboutCardEntries = aboutCardEntries; 16686bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.contactCardEntries = contactCardEntries; 16696bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.dataItemsMap = dataItemsMap; 16706bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell return dataModel; 16716bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 16726bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 16736bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 16746bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * Class used to hold the About card and Contact cards' data model that gets generated 16756bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * on a background thread. All data is from CP2. 16766bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 16776bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static class Cp2DataCardModel { 16786bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 16796bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * A map between a mimetype string and the corresponding list of data items. The data items 16806bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * are in sorted order using mWithinMimeTypeDataItemComparator. 16816bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 16826bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public Map<String, List<DataItem>> dataItemsMap; 16836bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public List<List<Entry>> aboutCardEntries; 16846bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public List<List<Entry>> contactCardEntries; 16856bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public String customAboutCardName; 16866bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 16876bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 16886bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static class MutableString { 16896bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public String value; 1690eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1691edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1692eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 1693eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Converts a {@link DataItem} into an {@link ExpandingEntryCardView.Entry} for display. 1694eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * If the {@link ExpandingEntryCardView.Entry} has no visual elements, null is returned. 16956bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * 16966bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * This runs on a background thread. This is set as static to avoid accidentally adding 16976bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * additional dependencies on unsafe things (like the Activity). 16986bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * 1699eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param dataItem The {@link DataItem} to convert. 17006a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * @param secondDataItem A second {@link DataItem} to help build a full entry for some 17016a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * mimetypes 1702eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return The {@link ExpandingEntryCardView.Entry}, or null if no visual elements are present. 1703eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 17046a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static Entry dataItemToEntry(DataItem dataItem, DataItem secondDataItem, 17056bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Context context, Contact contactData, 17066bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final MutableString aboutCardName) { 1707eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable icon = null; 1708eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String header = null; 1709eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String subHeader = null; 1710eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable subHeaderIcon = null; 1711eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String text = null; 1712eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable textIcon = null; 171323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos StringBuilder primaryContentDescription = new StringBuilder(); 1714b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang Spannable phoneContentDescription = null; 1715eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Intent intent = null; 171648ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos boolean shouldApplyColor = true; 1717dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Drawable alternateIcon = null; 1718dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Intent alternateIntent = null; 171923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos StringBuilder alternateContentDescription = new StringBuilder(); 1720eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEditable = false; 17212a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo entryContextMenuInfo = null; 172248fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos Drawable thirdIcon = null; 172348fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos Intent thirdIntent = null; 17245f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn int thirdAction = Entry.ACTION_NONE; 172548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos String thirdContentDescription = null; 17265f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn Bundle thirdExtras = null; 172748290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos int iconResourceId = 0; 1728eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 17296bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell context = context.getApplicationContext(); 173023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos final Resources res = context.getResources(); 1731eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataKind kind = dataItem.getDataKind(); 1732eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1733eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItem instanceof ImDataItem) { 1734eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final ImDataItem im = (ImDataItem) dataItem; 17356bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell intent = ContactsUtils.buildImIntent(context, im).first; 1736eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEmail = im.isCreatedFromEmail(); 17377de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos final int protocol; 17387de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos if (!im.isProtocolValid()) { 17397de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos protocol = Im.PROTOCOL_CUSTOM; 17407de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } else { 17417de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol(); 17427de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } 17437de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos if (protocol == Im.PROTOCOL_CUSTOM) { 17447de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos // If the protocol is custom, display the "IM" entry header as well to distinguish 17457de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos // this entry from other ones 174623e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_im_entry); 174723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos subHeader = Im.getProtocolLabel(res, protocol, 17487de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos im.getCustomProtocol()).toString(); 17497de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos text = im.getData(); 17507de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } else { 175123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = Im.getProtocolLabel(res, protocol, 17527de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos im.getCustomProtocol()).toString(); 17537de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos subHeader = im.getData(); 17547de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } 175597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(im.getData(), header, 175697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1757eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof OrganizationDataItem) { 1758eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final OrganizationDataItem organization = (OrganizationDataItem) dataItem; 175923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_organization_entry); 1760eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = organization.getCompany(); 176197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 176297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1763eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = organization.getTitle(); 1764eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NicknameDataItem) { 1765eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NicknameDataItem nickname = (NicknameDataItem) dataItem; 1766eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Build nickname entries 1767eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isNameRawContact = 17686bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell (contactData.getNameRawContactId() == dataItem.getRawContactId()); 1769eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1770eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean duplicatesTitle = 1771eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos isNameRawContact 17726bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell && contactData.getDisplayNameSource() == DisplayNameSources.NICKNAME; 1773eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1774eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!duplicatesTitle) { 177523e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_nickname_entry); 1776eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = nickname.getName(); 177797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 177897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1779eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1780eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NoteDataItem) { 1781eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NoteDataItem note = (NoteDataItem) dataItem; 178223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_note_entry); 1783eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = note.getNote(); 178497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 178597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1786eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof WebsiteDataItem) { 1787eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final WebsiteDataItem website = (WebsiteDataItem) dataItem; 178823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_website_entry); 1789eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = website.getUrl(); 179097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 179197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1792eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos try { 17933bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell final WebAddress webAddress = new WebAddress(website.buildDataStringForDisplay 17943bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell (context, kind)); 1795eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString())); 1796eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ParseException e) { 17973bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell Log.e(TAG, "Couldn't parse website: " + website.buildDataStringForDisplay( 17983bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell context, kind)); 1799eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1800eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EventDataItem) { 1801eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EventDataItem event = (EventDataItem) dataItem; 18023bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell final String dataString = event.buildDataStringForDisplay(context, kind); 1803eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Calendar cal = DateUtils.parseDate(dataString, false); 1804eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (cal != null) { 1805eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Date nextAnniversary = 1806eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DateUtils.getNextAnnualDate(cal); 1807eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); 1808eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos builder.appendPath("time"); 1809eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos ContentUris.appendId(builder, nextAnniversary.getTime()); 1810eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW).setData(builder.build()); 1811eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 181223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_event_entry); 1813f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (event.hasKindTypeColumn(kind)) { 181423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos subHeader = Event.getTypeLabel(res, event.getKindTypeColumn(kind), 18157de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos event.getLabel()).toString(); 1816f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 18176bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell text = DateUtils.formatDate(context, dataString); 181897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(text, header, 181997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1820eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof RelationDataItem) { 1821eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final RelationDataItem relation = (RelationDataItem) dataItem; 18223bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell final String dataString = relation.buildDataStringForDisplay(context, kind); 1823eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(dataString)) { 1824eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SEARCH); 1825eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.putExtra(SearchManager.QUERY, dataString); 1826eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.setType(Contacts.CONTENT_TYPE); 1827eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 182823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_relation_entry); 1829eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = relation.getName(); 183097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 183197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1832f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (relation.hasKindTypeColumn(kind)) { 183323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = Relation.getTypeLabel(res, 18346bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell relation.getKindTypeColumn(kind), 1835f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos relation.getLabel()).toString(); 1836f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1837eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof PhoneDataItem) { 1838eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final PhoneDataItem phone = (PhoneDataItem) dataItem; 18395f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn String phoneLabel = null; 1840eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(phone.getNumber())) { 184123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(res.getString(R.string.call_other)).append(" "); 18423bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell header = sBidiFormatter.unicodeWrap(phone.buildDataStringForDisplay(context, kind), 1843c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwell TextDirectionHeuristics.LTR); 18442a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 184597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), 184697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getId(), dataItem.isSuperPrimary()); 1847f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (phone.hasKindTypeColumn(kind)) { 184801b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang final int kindTypeColumn = phone.getKindTypeColumn(kind); 184901b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang final String label = phone.getLabel(); 18505f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phoneLabel = label; 185101b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang if (kindTypeColumn == Phone.TYPE_CUSTOM && TextUtils.isEmpty(label)) { 185201b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang text = ""; 185301b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang } else { 185401b376805a56281f4b18e041e9676c8ee1ecd235Tingting Wang text = Phone.getTypeLabel(res, kindTypeColumn, label).toString(); 18555f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phoneLabel= text; 18563df785b0ad0c0292adfc03a4f804d1b38053de63Tingting Wang primaryContentDescription.append(text).append(" "); 18573df785b0ad0c0292adfc03a4f804d1b38053de63Tingting Wang } 1858f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 185923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(header); 1860b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang phoneContentDescription = com.android.contacts.common.util.ContactDisplayUtils 1861b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang .getTelephoneTtsSpannable(primaryContentDescription.toString(), header); 186223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_phone_24dp); 186348290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos iconResourceId = R.drawable.ic_phone_24dp; 18646bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (PhoneCapabilityTester.isPhone(context)) { 1865eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(phone.getNumber()); 186616339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1867dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIntent = new Intent(Intent.ACTION_SENDTO, 18681cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phone.getNumber(), null)); 186948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos 187023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateIcon = res.getDrawable(R.drawable.ic_message_24dp); 187123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.append(res.getString(R.string.sms_custom, header)); 187248fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos 18735f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn if (CallUtil.isCallWithSubjectSupported(context)) { 18745f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdIcon = res.getDrawable(R.drawable.ic_call_note_white_24dp); 18755f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdAction = Entry.ACTION_CALL_WITH_SUBJECT; 18765f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdContentDescription = 18775f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn res.getString(R.string.call_with_a_note); 18785f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn 18795f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn // Create a bundle containing the data the call subject dialog requires. 18805f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras = new Bundle(); 18815f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putLong(CallSubjectDialog.ARG_PHOTO_ID, 18825f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn contactData.getPhotoId()); 18835f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putParcelable(CallSubjectDialog.ARG_PHOTO_URI, 18845f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn UriUtils.parseUriOrNull(contactData.getPhotoUri())); 18855f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putParcelable(CallSubjectDialog.ARG_CONTACT_URI, 18865f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn contactData.getLookupUri()); 18875f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putString(CallSubjectDialog.ARG_NAME_OR_NUMBER, 18885f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn contactData.getDisplayName()); 18895f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putBoolean(CallSubjectDialog.ARG_IS_BUSINESS, false); 18905f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putString(CallSubjectDialog.ARG_NUMBER, 18915f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phone.getNumber()); 18925f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putString(CallSubjectDialog.ARG_DISPLAY_NUMBER, 18935f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phone.getFormattedPhoneNumber()); 18945f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras.putString(CallSubjectDialog.ARG_NUMBER_LABEL, 18955f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn phoneLabel); 18965f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn } else if (CallUtil.isVideoEnabled(context)) { 18975f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn // Add video call button if supported 189823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos thirdIcon = res.getDrawable(R.drawable.ic_videocam); 18995f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdAction = Entry.ACTION_INTENT; 190048fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos thirdIntent = CallUtil.getVideoCallIntent(phone.getNumber(), 190148fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY); 190248fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos thirdContentDescription = 190323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos res.getString(R.string.description_video_call); 190448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos } 1905eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1906eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EmailDataItem) { 1907eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EmailDataItem email = (EmailDataItem) dataItem; 1908eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String address = email.getData(); 1909eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(address)) { 191023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(res.getString(R.string.email_other)).append(" "); 19111cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner final Uri mailUri = Uri.fromParts(ContactsUtils.SCHEME_MAILTO, address, null); 1912eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SENDTO, mailUri); 1913eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = email.getAddress(); 19142a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 191597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos res.getString(R.string.emailLabelsGroup), dataItem.getMimeType(), 191697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getId(), dataItem.isSuperPrimary()); 1917f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (email.hasKindTypeColumn(kind)) { 191823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = Email.getTypeLabel(res, email.getKindTypeColumn(kind), 1919f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos email.getLabel()).toString(); 192023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(text).append(" "); 1921f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 192223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(header); 192323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_email_24dp); 192448290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos iconResourceId = R.drawable.ic_email_24dp; 1925eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1926eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredPostalDataItem) { 1927eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos StructuredPostalDataItem postal = (StructuredPostalDataItem) dataItem; 1928eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String postalAddress = postal.getFormattedAddress(); 1929eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(postalAddress)) { 193023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(res.getString(R.string.map_other)).append(" "); 1931eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress); 1932eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = postal.getFormattedAddress(); 19332a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 193497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos res.getString(R.string.postalLabelsGroup), dataItem.getMimeType(), 193597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getId(), dataItem.isSuperPrimary()); 1936f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (postal.hasKindTypeColumn(kind)) { 193723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = StructuredPostal.getTypeLabel(res, 1938f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos postal.getKindTypeColumn(kind), postal.getLabel()).toString(); 193923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(text).append(" "); 1940f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 194123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(header); 19426a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos alternateIntent = 19436a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos StructuredPostalUtils.getViewPostalAddressDirectionsIntent(postalAddress); 194423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateIcon = res.getDrawable(R.drawable.ic_directions_24dp); 194523e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.append(res.getString( 194623e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos R.string.content_description_directions)).append(" ").append(header); 194723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_place_24dp); 194848290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos iconResourceId = R.drawable.ic_place_24dp; 1949eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1950eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof SipAddressDataItem) { 1951593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell final SipAddressDataItem sip = (SipAddressDataItem) dataItem; 1952593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell final String address = sip.getSipAddress(); 1953593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell if (!TextUtils.isEmpty(address)) { 1954593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell primaryContentDescription.append(res.getString(R.string.call_other)).append( 1955593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell " "); 1956593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell if (PhoneCapabilityTester.isSipPhone(context)) { 19571cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner final Uri callUri = Uri.fromParts(PhoneAccount.SCHEME_SIP, address, null); 1958eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(callUri); 195916339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1960593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell header = address; 1961593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell entryContextMenuInfo = new EntryContextMenuInfo(header, 1962593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), 1963593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell dataItem.getId(), dataItem.isSuperPrimary()); 1964593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell if (sip.hasKindTypeColumn(kind)) { 1965593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell text = SipAddress.getTypeLabel(res, 1966593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell sip.getKindTypeColumn(kind), sip.getLabel()).toString(); 1967593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell primaryContentDescription.append(text).append(" "); 1968593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell } 1969593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell primaryContentDescription.append(header); 1970593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell icon = res.getDrawable(R.drawable.ic_dialer_sip_black_24dp); 1971593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell iconResourceId = R.drawable.ic_dialer_sip_black_24dp; 1972edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1973eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredNameDataItem) { 19748025f801f5153917781a9496cabdd81ae1b6deafWalter Jang // If the name is already set and this is not the super primary value then leave the 19758025f801f5153917781a9496cabdd81ae1b6deafWalter Jang // current value. This way we show the super primary value when we are able to. 19768025f801f5153917781a9496cabdd81ae1b6deafWalter Jang if (dataItem.isSuperPrimary() || aboutCardName.value == null 19778025f801f5153917781a9496cabdd81ae1b6deafWalter Jang || aboutCardName.value.isEmpty()) { 19788025f801f5153917781a9496cabdd81ae1b6deafWalter Jang final String givenName = ((StructuredNameDataItem) dataItem).getGivenName(); 19798025f801f5153917781a9496cabdd81ae1b6deafWalter Jang if (!TextUtils.isEmpty(givenName)) { 19808025f801f5153917781a9496cabdd81ae1b6deafWalter Jang aboutCardName.value = res.getString(R.string.about_card_title) + 19818025f801f5153917781a9496cabdd81ae1b6deafWalter Jang " " + givenName; 19828025f801f5153917781a9496cabdd81ae1b6deafWalter Jang } else { 19838025f801f5153917781a9496cabdd81ae1b6deafWalter Jang aboutCardName.value = res.getString(R.string.about_card_title); 19848025f801f5153917781a9496cabdd81ae1b6deafWalter Jang } 1985eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1986eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1987eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Custom DataItem 19886bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = dataItem.buildDataStringForDisplay(context, kind); 1989eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = kind.typeColumn; 1990eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW); 199160e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, dataItem.getId()); 199260e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos intent.setDataAndType(uri, dataItem.getMimeType()); 1993e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 1994e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (intent != null) { 1995e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos final String mimetype = intent.getType(); 1996e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 19976a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Build advanced entry for known 3p types. Otherwise default to ResolveCache icon. 1998e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos switch (mimetype) { 1999e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos case MIMETYPE_GPLUS_PROFILE: 20006a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // If a secondDataItem is available, use it to build an entry with 20016a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // alternate actions 20026a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (secondDataItem != null) { 200323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_google_plus_24dp); 20046a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos alternateIcon = res.getDrawable(R.drawable.ic_add_to_circles_black_24); 20056a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final GPlusOrHangoutsDataItemModel itemModel = 20066a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos new GPlusOrHangoutsDataItemModel(intent, alternateIntent, 20076a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataItem, secondDataItem, alternateContentDescription, 20086a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos header, text, context); 20096a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 201097b1e2d6206ad8f64af6bc935451654204706661Paul Soulos populateGPlusOrHangoutsDataItemModel(itemModel); 201197b1e2d6206ad8f64af6bc935451654204706661Paul Soulos intent = itemModel.intent; 201297b1e2d6206ad8f64af6bc935451654204706661Paul Soulos alternateIntent = itemModel.alternateIntent; 201397b1e2d6206ad8f64af6bc935451654204706661Paul Soulos alternateContentDescription = itemModel.alternateContentDescription; 201497b1e2d6206ad8f64af6bc935451654204706661Paul Soulos header = itemModel.header; 201597b1e2d6206ad8f64af6bc935451654204706661Paul Soulos text = itemModel.text; 20166a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 20176a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (GPLUS_PROFILE_DATA_5_ADD_TO_CIRCLE.equals( 20186a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos intent.getDataString())) { 20196a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos icon = res.getDrawable(R.drawable.ic_add_to_circles_black_24); 20206a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 20216a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos icon = res.getDrawable(R.drawable.ic_google_plus_24dp); 20226a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 2023e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 2024e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos break; 2025e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos case MIMETYPE_HANGOUTS: 20266a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // If a secondDataItem is available, use it to build an entry with 20276a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // alternate actions 20286a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (secondDataItem != null) { 202923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_hangout_24dp); 20306a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos alternateIcon = res.getDrawable(R.drawable.ic_hangout_video_24dp); 203197b1e2d6206ad8f64af6bc935451654204706661Paul Soulos final GPlusOrHangoutsDataItemModel itemModel = 20326a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos new GPlusOrHangoutsDataItemModel(intent, alternateIntent, 20336a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataItem, secondDataItem, alternateContentDescription, 20346a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos header, text, context); 20356a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 203697b1e2d6206ad8f64af6bc935451654204706661Paul Soulos populateGPlusOrHangoutsDataItemModel(itemModel); 203797b1e2d6206ad8f64af6bc935451654204706661Paul Soulos intent = itemModel.intent; 203897b1e2d6206ad8f64af6bc935451654204706661Paul Soulos alternateIntent = itemModel.alternateIntent; 203997b1e2d6206ad8f64af6bc935451654204706661Paul Soulos alternateContentDescription = itemModel.alternateContentDescription; 204097b1e2d6206ad8f64af6bc935451654204706661Paul Soulos header = itemModel.header; 204197b1e2d6206ad8f64af6bc935451654204706661Paul Soulos text = itemModel.text; 20426a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 20436a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (HANGOUTS_DATA_5_VIDEO.equals(intent.getDataString())) { 20446a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos icon = res.getDrawable(R.drawable.ic_hangout_video_24dp); 20456a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 20466a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos icon = res.getDrawable(R.drawable.ic_hangout_24dp); 20476a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 2048e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 2049e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos break; 2050e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos default: 205197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, mimetype, 205297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), 205397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.isSuperPrimary()); 20546bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell icon = ResolveCache.getInstance(context).getIcon( 2055e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos dataItem.getMimeType(), intent); 2056e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos // Call mutate to create a new Drawable.ConstantState for color filtering 2057e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (icon != null) { 2058e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos icon.mutate(); 2059e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 206048ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos shouldApplyColor = false; 2061e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 2062e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 2063eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 2064b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2065eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (intent != null) { 2066eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Do not set the intent is there are no resolves 20676bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!PhoneCapabilityTester.isIntentRegistered(context, intent)) { 2068eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = null; 2069eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 2070eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 2071eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 2072dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (alternateIntent != null) { 2073dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Do not set the alternate intent is there are no resolves 20746bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!PhoneCapabilityTester.isIntentRegistered(context, alternateIntent)) { 2075dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIntent = null; 2076f0d04c11b649e953177e79722d05fa048e53273dJay Shrauner } else if (TextUtils.isEmpty(alternateContentDescription)) { 2077f0d04c11b649e953177e79722d05fa048e53273dJay Shrauner // Attempt to use package manager to find a suitable content description if needed 207823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.append(getIntentResolveLabel(alternateIntent, context)); 2079dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 2080dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 2081dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 2082eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // If the Entry has no visual elements, return null 2083eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) && 2084eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeaderIcon == null && TextUtils.isEmpty(text) && textIcon == null) { 2085eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return null; 2086eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 2087eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 2088fa238949855fba3b28a57fad3d585b13e80362bbBrian Attwell // Ignore dataIds from the Me profile. 2089ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final int dataId = dataItem.getId() > Integer.MAX_VALUE ? 2090ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos -1 : (int) dataItem.getId(); 2091ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 209223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon, 2093b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang phoneContentDescription == null 2094b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang ? new SpannableString(primaryContentDescription.toString()) 2095b6949dc7ed1b0ab47dc6a39b3ae0d42e029be2b4Tingting Wang : phoneContentDescription, 20967ce5352a70e8aaf120bf4f7bd05d595f46abb080Walter Jang intent, alternateIcon, alternateIntent, 209723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.toString(), shouldApplyColor, isEditable, 20985f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn entryContextMenuInfo, thirdIcon, thirdIntent, thirdContentDescription, thirdAction, 20995f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn thirdExtras, iconResourceId); 2100eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 2101eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 21026bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private List<Entry> dataItemsToEntries(List<DataItem> dataItems, 21036bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell MutableString aboutCardTitleOut) { 21046a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Hangouts and G+ use two data items to create one entry. 21056a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (dataItems.get(0).getMimeType().equals(MIMETYPE_GPLUS_PROFILE) || 21066a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataItems.get(0).getMimeType().equals(MIMETYPE_HANGOUTS)) { 21076a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos return gPlusOrHangoutsDataItemsToEntries(dataItems); 21086a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 21096a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final List<Entry> entries = new ArrayList<>(); 21106a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos for (DataItem dataItem : dataItems) { 21116a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, 21126a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this, mContactData, aboutCardTitleOut); 21136a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (entry != null) { 21146a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos entries.add(entry); 21156a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21166a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21176a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos return entries; 21186a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21196a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21206a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 21216a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /** 21226a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * G+ and Hangout entries are unique in that a single ExpandingEntryCardView.Entry consists 21236a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * of two data items. This method attempts to build each entry using the two data items if 21246a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * they are available. If there are more or less than two data items, a fall back is used 21256a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * and each data item gets its own entry. 21266a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos */ 21276a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private List<Entry> gPlusOrHangoutsDataItemsToEntries(List<DataItem> dataItems) { 2128eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> entries = new ArrayList<>(); 21296a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Map<Long, List<DataItem>> buckets = new HashMap<>(); 21306a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Put the data items into buckets based on the raw contact id 2131eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (DataItem dataItem : dataItems) { 21326a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos List<DataItem> bucket = buckets.get(dataItem.getRawContactId()); 21336a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (bucket == null) { 21346a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos bucket = new ArrayList<>(); 21356a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos buckets.put(dataItem.getRawContactId(), bucket); 21366a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21376a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos bucket.add(dataItem); 21386a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21396a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 21406a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Use the buckets to build entries. If a bucket contains two data items, build the special 21416a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // entry, otherwise fall back to the normal entry. 21426a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos for (List<DataItem> bucket : buckets.values()) { 21436a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (bucket.size() == 2) { 21446a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Use the pair to build an entry 21456a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Entry entry = dataItemToEntry(bucket.get(0), 21466a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /* secondDataItem = */ bucket.get(1), this, mContactData, 21476a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /* aboutCardName = */ null); 21486a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (entry != null) { 21496a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos entries.add(entry); 21506a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21516a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 21526a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos for (DataItem dataItem : bucket) { 21536a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, 21546a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this, mContactData, /* aboutCardName = */ null); 21556a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (entry != null) { 21566a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos entries.add(entry); 21576a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21586a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 2159eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 2160eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 2161eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return entries; 2162edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 2163edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 21646a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /** 21656a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * Used for statically passing around G+ or Hangouts data items and entry fields to 21666a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * populateGPlusOrHangoutsDataItemModel. 21676a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos */ 21686a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final class GPlusOrHangoutsDataItemModel { 21696a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public Intent intent; 21706a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public Intent alternateIntent; 21716a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public DataItem dataItem; 21726a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public DataItem secondDataItem; 21736a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public StringBuilder alternateContentDescription; 21746a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public String header; 21756a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public String text; 21766a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public Context context; 21776a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 21786a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public GPlusOrHangoutsDataItemModel(Intent intent, Intent alternateIntent, DataItem dataItem, 21796a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos DataItem secondDataItem, StringBuilder alternateContentDescription, String header, 21806a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos String text, Context context) { 21816a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.intent = intent; 21826a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.alternateIntent = alternateIntent; 21836a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.dataItem = dataItem; 21846a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.secondDataItem = secondDataItem; 21856a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.alternateContentDescription = alternateContentDescription; 21866a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.header = header; 21876a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.text = text; 21886a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.context = context; 21896a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21906a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 21916a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 21926a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static void populateGPlusOrHangoutsDataItemModel( 21936a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos GPlusOrHangoutsDataItemModel dataModel) { 21946a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Intent secondIntent = new Intent(Intent.ACTION_VIEW); 21956a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos secondIntent.setDataAndType(ContentUris.withAppendedId(Data.CONTENT_URI, 21966a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.getId()), dataModel.secondDataItem.getMimeType()); 21976a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // There is no guarantee the order the data items come in. Second 21986a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // data item does not necessarily mean it's the alternate. 21996a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Hangouts video and Add to circles should be alternate. Swap if needed 22006a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (HANGOUTS_DATA_5_VIDEO.equals( 22016a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.dataItem.getContentValues().getAsString(Data.DATA5)) || 22026a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos GPLUS_PROFILE_DATA_5_ADD_TO_CIRCLE.equals( 22036a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.dataItem.getContentValues().getAsString(Data.DATA5))) { 22046a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateIntent = dataModel.intent; 22056a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateContentDescription = new StringBuilder(dataModel.header); 22066a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 22076a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.intent = secondIntent; 22086a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.header = dataModel.secondDataItem.buildDataStringForDisplay(dataModel.context, 22096a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.getDataKind()); 22106a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.text = dataModel.secondDataItem.getDataKind().typeColumn; 22116a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else if (HANGOUTS_DATA_5_MESSAGE.equals( 22126a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.dataItem.getContentValues().getAsString(Data.DATA5)) || 22136a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos GPLUS_PROFILE_DATA_5_VIEW_PROFILE.equals( 22146a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.dataItem.getContentValues().getAsString(Data.DATA5))) { 22156a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateIntent = secondIntent; 22166a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateContentDescription = new StringBuilder( 22176a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.buildDataStringForDisplay(dataModel.context, 22186a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.getDataKind())); 22196a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 22206a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 22216a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 22226bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static String getIntentResolveLabel(Intent intent, Context context) { 22236bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, 2224dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos PackageManager.MATCH_DEFAULT_ONLY); 2225dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 2226dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Pick first match, otherwise best found 2227dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos ResolveInfo bestResolve = null; 2228dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos final int size = matches.size(); 2229dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (size == 1) { 2230dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos bestResolve = matches.get(0); 2231dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } else if (size > 1) { 22326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell bestResolve = ResolveCache.getInstance(context).getBestResolve(intent, matches); 2233dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 2234dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 2235dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (bestResolve == null) { 2236dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos return null; 2237dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 2238dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 22396bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell return String.valueOf(bestResolve.loadLabel(context.getPackageManager())); 2240dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 2241dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 2242edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 224331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * Asynchronously extract the most vibrant color from the PhotoView. Once extracted, 224431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms 224531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * on a Nexus 5. 224631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell */ 224731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell private void extractAndApplyTintFromPhotoViewAsynchronously() { 224831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell if (mScroller == null) { 224931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell return; 225031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 225131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell final Drawable imageViewDrawable = mPhotoView.getDrawable(); 2252faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell new AsyncTask<Void, Void, MaterialPalette>() { 225331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 2254faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell protected MaterialPalette doInBackground(Void... params) { 2255faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell 2256929a62f5c1bcdc3773270f7d189d88c0464b36adJay Shrauner if (imageViewDrawable instanceof BitmapDrawable && mContactData != null 225795c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell && mContactData.getThumbnailPhotoBinaryData() != null 225895c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell && mContactData.getThumbnailPhotoBinaryData().length > 0) { 225995c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell // Perform the color analysis on the thumbnail instead of the full sized 226095c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell // image, so that our results will be as similar as possible to the Bugle 226195c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell // app. 226295c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell final Bitmap bitmap = BitmapFactory.decodeByteArray( 226395c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell mContactData.getThumbnailPhotoBinaryData(), 0, 226495c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell mContactData.getThumbnailPhotoBinaryData().length); 226595c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell try { 226695c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell final int primaryColor = colorFromBitmap(bitmap); 226795c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell if (primaryColor != 0) { 226895c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor( 226995c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell primaryColor); 227095c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell } 227195c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell } finally { 227295c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell bitmap.recycle(); 2273faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell } 22748a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 22758a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (imageViewDrawable instanceof LetterTileDrawable) { 2276faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell final int primaryColor = ((LetterTileDrawable) imageViewDrawable).getColor(); 2277a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(primaryColor); 227831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 2279a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return MaterialColorMapUtils.getDefaultPrimaryAndSecondaryColors(getResources()); 228031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 228131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 228231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 2283faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell protected void onPostExecute(MaterialPalette palette) { 2284faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell super.onPostExecute(palette); 22858571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (mHasComputedThemeColor) { 22868571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // If we had previously computed a theme color from the contact photo, 22878571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // then do not update the theme color. Changing the theme color several 22888571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // seconds after QC has started, as a result of an updated/upgraded photo, 22898571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // is a jarring experience. On the other hand, changing the theme color after 22908571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // a rotation or onNewIntent() is perfectly fine. 22918571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell return; 22928571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell } 22938571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // Check that the Photo has not changed. If it has changed, the new tint 22948571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // color needs to be extracted 22958571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (imageViewDrawable == mPhotoView.getDrawable()) { 22968571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = true; 2297faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell setThemeColor(palette); 229831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 229931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 230031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell }.execute(); 230131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 230231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 2303faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell private void setThemeColor(MaterialPalette palette) { 23049b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // If the color is invalid, use the predefined default 23058e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mColorFilterColor = palette.mPrimaryColor; 23068e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mScroller.setHeaderTintColor(mColorFilterColor); 2307faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mStatusBarColor = palette.mSecondaryColor; 23089b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell updateStatusBarColor(); 23098571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell 23109b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mColorFilter = 23118e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell new PorterDuffColorFilter(mColorFilterColor, PorterDuff.Mode.SRC_ATOP); 23128e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mContactCard.setColorAndFilter(mColorFilterColor, mColorFilter); 23138e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mRecentCard.setColorAndFilter(mColorFilterColor, mColorFilter); 23148e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mAboutCard.setColorAndFilter(mColorFilterColor, mColorFilter); 23159b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 23169b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 23178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void updateStatusBarColor() { 23188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller == null) { 23198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 23208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 23218a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int desiredStatusBarColor; 23228a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Only use a custom status bar color if QuickContacts touches the top of the viewport. 23238a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller.getScrollNeededToBeFullScreen() <= 0) { 23248a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = mStatusBarColor; 23258a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } else { 23268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = Color.TRANSPARENT; 23278a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 23288a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Animate to the new color. 2329847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor", 2330847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell getWindow().getStatusBarColor(), desiredStatusBarColor); 2331847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION); 2332847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.setEvaluator(new ArgbEvaluator()); 2333847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.start(); 23348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 23358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 23368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int colorFromBitmap(Bitmap bitmap) { 23378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Author of Palette recommends using 24 colors when analyzing profile photos. 23388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int NUMBER_OF_PALETTE_COLORS = 24; 23398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final Palette palette = Palette.generate(bitmap, NUMBER_OF_PALETTE_COLORS); 2340a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell if (palette != null && palette.getVibrantSwatch() != null) { 2341a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell return palette.getVibrantSwatch().getRgb(); 23428a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 23438a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return 0; 23448a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 23458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 2346b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) { 2347eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> entries = new ArrayList<>(); 2348b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos for (ContactInteraction interaction : interactions) { 2349ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (interaction == null) { 2350ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell continue; 2351ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2352ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos entries.add(new Entry(/* id = */ -1, 2353ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos interaction.getIcon(this), 2354b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewHeader(this), 2355b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewBody(this), 2356b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getBodyIcon(this), 2357b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewFooter(this), 2358b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getFooterIcon(this), 235923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos interaction.getContentDescription(this), 2360b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getIntent(), 2361dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIcon = */ null, 2362dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIntent = */ null, 2363dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateContentDescription = */ null, 236448ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos /* shouldApplyColor = */ true, 23652a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, 236648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* EntryContextMenuInfo = */ null, 236748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, 236848fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIntent = */ null, 236948290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos /* thirdContentDescription = */ null, 23705f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdAction = */ Entry.ACTION_NONE, 23715f87e923b0300173ad68f73a47b0dca7348d6a1fTyler Gunn /* thirdActionExtras = */ null, 237248290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos interaction.getIconResourceId())); 2373b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2374b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return entries; 2375b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2376b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2377eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<Contact> mLoaderContactCallbacks = 2378851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu new LoaderCallbacks<Contact>() { 2379cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 2380851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoaderReset(Loader<Contact> loader) { 2381405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos mContactData = null; 2382cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2383cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2384cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 2385851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoadFinished(Loader<Contact> loader, Contact data) { 23868a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onLoadFinished()"); 2387930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell try { 23888a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 2389930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell if (isFinishing()) { 2390930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell return; 2391930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } 2392930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell if (data.isError()) { 239302ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner // This means either the contact is invalid or we had an 239402ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner // internal error such as an acore crash. 239502ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner Log.i(TAG, "Failed to load contact: " + ((ContactLoader)loader).getLookupUri()); 239602ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, 239702ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner Toast.LENGTH_LONG).show(); 239802ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner finish(); 239902ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner return; 2400930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } 2401930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell if (data.isNotFound()) { 24028a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri()); 24038a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, 24048a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.LENGTH_LONG).show(); 2405930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell finish(); 2406930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell return; 24078a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 2408cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2409930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell bindContactData(data); 2410cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2411930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } finally { 2412930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell Trace.endSection(); 2413930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } 2414cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2415cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2416cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 2417851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public Loader<Contact> onCreateLoader(int id, Bundle args) { 2418cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (mLookupUri == null) { 2419cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann Log.wtf(TAG, "Lookup uri wasn't initialized. Loader was started too early"); 2420cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2421d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Load all contact data. We need loadGroupMetaData=true to determine whether the 2422d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // contact is invisible. If it is, we need to display an "Add to Contacts" MenuItem. 2423b2b435a944947fbf1965c3bb7c202a97f0273259Yorke Lee return new ContactLoader(getApplicationContext(), mLookupUri, 2424d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell true /*loadGroupMetaData*/, false /*loadInvitableAccountTypes*/, 24258571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell true /*postViewNotification*/, true /*computeFormattedPhoneNumber*/); 2426cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2427cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann }; 2428b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2429b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 2430b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onBackPressed() { 2431b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell if (mScroller != null) { 24328477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell if (!mIsExitAnimationInProgress) { 24338477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mScroller.scrollOffBottom(); 24348477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 2435b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } else { 2436b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell super.onBackPressed(); 2437b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 2438b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 2439b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 24408a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 24418a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void finish() { 24428a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.finish(); 24438a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 24448a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // override transitions to skip the standard window animations 24458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell overridePendingTransition(0, 0); 24468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 24478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 2448eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<List<ContactInteraction>> mLoaderInteractionsCallbacks = 2449b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos new LoaderCallbacks<List<ContactInteraction>>() { 2450b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2451b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 2452b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public Loader<List<ContactInteraction>> onCreateLoader(int id, Bundle args) { 2453b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Loader<List<ContactInteraction>> loader = null; 2454b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos switch (id) { 2455b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos case LOADER_SMS_ID: 2456b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos loader = new SmsInteractionsLoader( 2457b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos QuickContactActivity.this, 2458ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 2459b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos MAX_SMS_RETRIEVE); 2460b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos break; 2461899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos case LOADER_CALENDAR_ID: 2462ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos final String[] emailsArray = args.getStringArray(KEY_LOADER_EXTRA_EMAILS); 2463ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos List<String> emailsList = null; 2464ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos if (emailsArray != null) { 2465ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos emailsList = Arrays.asList(args.getStringArray(KEY_LOADER_EXTRA_EMAILS)); 2466ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos } 2467899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos loader = new CalendarInteractionsLoader( 2468899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos QuickContactActivity.this, 2469ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos emailsList, 2470899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_FUTURE_CALENDAR_RETRIEVE, 2471899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_PAST_CALENDAR_RETRIEVE, 2472899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR, 2473899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR); 2474899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos break; 2475ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos case LOADER_CALL_LOG_ID: 2476ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos loader = new CallLogInteractionsLoader( 2477ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.this, 2478ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 2479ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos MAX_CALL_LOG_RETRIEVE); 2480b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2481b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return loader; 2482b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2483b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2484b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 2485b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoadFinished(Loader<List<ContactInteraction>> loader, 2486b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos List<ContactInteraction> data) { 2487b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.put(loader.getId(), data); 2488b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2489b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos if (isAllRecentDataLoaded()) { 2490b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos bindRecentData(); 2491b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2492b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2493b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2494b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 2495b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoaderReset(Loader<List<ContactInteraction>> loader) { 2496b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.remove(loader.getId()); 2497b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2498b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos }; 2499b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2500b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private boolean isAllRecentDataLoaded() { 2501b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return mRecentLoaderResults.size() == mRecentLoaderIds.length; 2502b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2503b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2504b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private void bindRecentData() { 2505eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<ContactInteraction> allInteractions = new ArrayList<>(); 250630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell final List<List<Entry>> interactionsWrapper = new ArrayList<>(); 2507b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2508ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell // Serialize mRecentLoaderResults into a single list. This should be done on the main 2509ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell // thread to avoid races against mRecentLoaderResults edits. 2510ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) { 2511ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell allInteractions.addAll(loaderInteractions); 2512ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2513ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell 251430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask = new AsyncTask<Void, Void, Void>() { 2515b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 251630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell protected Void doInBackground(Void... params) { 251730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.beginSection("sort recent loader results"); 251830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 251930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // Sort the interactions by most recent 252030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Collections.sort(allInteractions, new Comparator<ContactInteraction>() { 252130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell @Override 252230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell public int compare(ContactInteraction a, ContactInteraction b) { 2523ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a == null && b == null) { 2524ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 0; 2525ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2526ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a == null) { 2527ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 1; 2528ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2529ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (b == null) { 2530ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return -1; 2531ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2532ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a.getInteractionDate() > b.getInteractionDate()) { 2533ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return -1; 2534ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2535ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a.getInteractionDate() == b.getInteractionDate()) { 2536ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 0; 2537ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2538ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 1; 253930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 254030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell }); 254130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 254230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.endSection(); 254330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.beginSection("contactInteractionsToEntries"); 254430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 254530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // Wrap each interaction in its own list so that an icon is displayed for each entry 254630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell for (Entry contactInteraction : contactInteractionsToEntries(allInteractions)) { 254730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell List<Entry> entryListWrapper = new ArrayList<>(1); 254830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell entryListWrapper.add(contactInteraction); 254930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell interactionsWrapper.add(entryListWrapper); 255030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 255130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 255230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.endSection(); 255330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell return null; 2554b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 255530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 255630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell @Override 255730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell protected void onPostExecute(Void aVoid) { 255830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell super.onPostExecute(aVoid); 255930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.beginSection("initialize recents card"); 256030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 256130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell if (allInteractions.size() > 0) { 256230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentCard.initialize(interactionsWrapper, 2563b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN, 2564c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos /* isExpanded = */ mRecentCard.isExpanded(), /* isAlwaysExpanded = */ false, 256530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mExpandingEntryCardViewListener, mScroller); 256630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentCard.setVisibility(View.VISIBLE); 256730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 2568eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 256930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.endSection(); 257030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 257130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // About card is initialized along with the contact card, but since it appears after 257230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // the recent card in the UI, we hold off until making it visible until the recent 257330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // card is also ready to avoid stuttering. 257430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell if (mAboutCard.shouldShow()) { 257530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mAboutCard.setVisibility(View.VISIBLE); 257630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } else { 257730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mAboutCard.setVisibility(View.GONE); 257830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 257930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask = null; 258030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 258130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell }; 258230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask.execute(); 2583b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 25848a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 25858a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 25868a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onStop() { 25878a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onStop(); 25888a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 25898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mEntriesAndActionsTask != null) { 25908a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Once the activity is stopped, we will no longer want to bind mEntriesAndActionsTask's 25918a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // results on the UI thread. In some circumstances Activities are killed without 25928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // onStop() being called. This is not a problem, because in these circumstances 25938a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the entire process will be killed. 25948a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.cancel(/* mayInterruptIfRunning = */ false); 25958a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 259630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell if (mRecentDataTask != null) { 259730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask.cancel(/* mayInterruptIfRunning = */ false); 259830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 25998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 260023889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos 2601e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang @Override 2602e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang public void onDestroy() { 2603e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang super.onDestroy(); 2604e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang if (mAggregationSuggestionEngine != null) { 2605e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang mAggregationSuggestionEngine.quit(); 2606e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 2607e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang } 2608e3a7c4f3215294b7699c2960ffe0128d3401745fTingting Wang 260923889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos /** 2610d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Returns true if it is possible to edit the current contact. 2611d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 2612d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private boolean isContactEditable() { 2613d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 2614d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2615d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2616a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell /** 2617a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell * Returns true if it is possible to share the current contact. 2618a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell */ 2619a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell private boolean isContactShareable() { 2620a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 2621a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell } 2622a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 26236095369885edcca566a812b551886e29c7ff8039Brian Attwell private Intent getEditContactIntent() { 26245a7a23bdb698b8e741a425c9617c5e33e6314cddWalter Jang return EditorIntents.createCompactEditContactIntent( 26251e8801bc9bc60bdd1c95f582c460590272cfad64Walter Jang mContactData.getLookupUri(), 26261e8801bc9bc60bdd1c95f582c460590272cfad64Walter Jang mHasComputedThemeColor 26271e8801bc9bc60bdd1c95f582c460590272cfad64Walter Jang ? new MaterialPalette(mColorFilterColor, mStatusBarColor) : null, 26283e5ae0db65e842d49d047568fb5d6f331298da32Walter Jang mContactData.getPhotoId()); 26296095369885edcca566a812b551886e29c7ff8039Brian Attwell } 26306095369885edcca566a812b551886e29c7ff8039Brian Attwell 26316095369885edcca566a812b551886e29c7ff8039Brian Attwell private void editContact() { 2632a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 2633c00a0b5370f0714f6af1ea9b3e29b10f25e91af0Zheng Fu mContactLoader.cacheResult(); 26346095369885edcca566a812b551886e29c7ff8039Brian Attwell startActivityForResult(getEditContactIntent(), REQUEST_CODE_CONTACT_EDITOR_ACTIVITY); 2635d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2636d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 26375d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang private void deleteContact() { 26385d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang final Uri contactUri = mContactData.getLookupUri(); 26395d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang ContactDeletionInteraction.start(this, contactUri, /* finishActivityWhenDone =*/ true); 26405d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang } 26415d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang 2642d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void toggleStar(MenuItem starredMenuItem) { 2643d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Make sure there is a contact 264463176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell if (mContactData != null) { 2645d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Read the current starred value from the UI instead of using the last 2646d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // loaded state. This allows rapid tapping without writing the same 2647d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // value several times 2648d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final boolean isStarred = starredMenuItem.isChecked(); 2649d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2650d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // To improve responsiveness, swap out the picture (and tag) in the UI already 2651333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, 2652d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.isDirectoryEntry(), mContactData.isUserProfile(), 2653d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell !isStarred); 2654d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2655d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Now perform the real save 2656eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Intent intent = ContactSaveService.createSetStarredIntent( 265763176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell QuickContactActivity.this, mContactData.getLookupUri(), !isStarred); 2658d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell startService(intent); 265935ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell 266035ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell final CharSequence accessibilityText = !isStarred 266135ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell ? getResources().getText(R.string.description_action_menu_add_star) 266235ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell : getResources().getText(R.string.description_action_menu_remove_star); 266335ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell // Accessibility actions need to have an associated view. We can't access the MenuItem's 266435ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell // underlying view, so put this accessibility action on the root view. 266535ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell mScroller.announceForAccessibility(accessibilityText); 2666d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2667d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2668d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2669752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void shareContact() { 2670752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final String lookupKey = mContactData.getLookupKey(); 2671652936f204b15097d030e870dda5054d8115cbf3Brian Attwell final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); 2672752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent intent = new Intent(Intent.ACTION_SEND); 2673552ee569d46ae5c63207a162157171b249243e56Yorke Lee intent.setType(Contacts.CONTENT_VCARD_TYPE); 26748dcb4ed13da40fc609e6913708c3d730ba4f0574Brian Attwell intent.putExtra(Intent.EXTRA_STREAM, shareUri); 2675752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2676752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Launch chooser to share contact via 2677752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final CharSequence chooseTitle = getText(R.string.share_via); 2678752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent chooseIntent = Intent.createChooser(intent, chooseTitle); 2679752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2680752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell try { 2681a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 2682652936f204b15097d030e870dda5054d8115cbf3Brian Attwell ImplicitIntentsUtil.startActivityOutsideApp(this, chooseIntent); 2683eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ActivityNotFoundException ex) { 2684752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show(); 2685752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2686752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2687752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2688752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** 2689752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell * Creates a launcher shortcut with the current contact. 2690752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell */ 2691752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void createLauncherShortcutWithContact() { 2692752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this, 2693752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell new OnShortcutIntentCreatedListener() { 2694752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2695752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell @Override 2696752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) { 2697752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Broadcast the shortcutIntent to the launcher to create a 2698752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // shortcut to this contact 2699752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); 2700752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell QuickContactActivity.this.sendBroadcast(shortcutIntent); 2701752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2702752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Send a toast to give feedback to the user that a shortcut to this 2703752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // contact was added to the launcher. 2704168331d85c5be43a816eb24fd37a2ebdbe61ac53Tingting Wang final String displayName = mContactData.getDisplayName(); 2705168331d85c5be43a816eb24fd37a2ebdbe61ac53Tingting Wang final String toastMessage = TextUtils.isEmpty(displayName) 2706168331d85c5be43a816eb24fd37a2ebdbe61ac53Tingting Wang ? getString(R.string.createContactShortcutSuccessful_NoName) 2707168331d85c5be43a816eb24fd37a2ebdbe61ac53Tingting Wang : getString(R.string.createContactShortcutSuccessful, displayName); 2708168331d85c5be43a816eb24fd37a2ebdbe61ac53Tingting Wang Toast.makeText(QuickContactActivity.this, toastMessage, 2709752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.LENGTH_SHORT).show(); 2710752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2711752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2712752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell }); 271363176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell builder.createContactShortcutIntent(mContactData.getLookupUri()); 2714752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2715752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 271666965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell private boolean isShortcutCreatable() { 27171c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner if (mContactData == null || mContactData.isUserProfile() || 27181c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner mContactData.isDirectoryEntry()) { 27198d0557eb013b2808402e491271fe0f13ffcfabefBrian Attwell return false; 27208d0557eb013b2808402e491271fe0f13ffcfabefBrian Attwell } 272166965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell final Intent createShortcutIntent = new Intent(); 272266965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell createShortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); 272366965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell final List<ResolveInfo> receivers = getPackageManager() 272466965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell .queryBroadcastReceivers(createShortcutIntent, 0); 272566965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell return receivers != null && receivers.size() > 0; 272666965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell } 272766965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell 2728d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 2729d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onCreateOptionsMenu(Menu menu) { 2730eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final MenuInflater inflater = getMenuInflater(); 2731d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell inflater.inflate(R.menu.quickcontact, menu); 2732d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 2733d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2734d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2735d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 2736d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onPrepareOptionsMenu(Menu menu) { 2737d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mContactData != null) { 2738d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem starredMenuItem = menu.findItem(R.id.menu_star); 2739333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, 2740d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.isDirectoryEntry(), mContactData.isUserProfile(), 2741d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.getStarred()); 2742a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 2743d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Configure edit MenuItem 2744d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem editMenuItem = menu.findItem(R.id.menu_edit); 2745d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(true); 2746d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData) || InvisibleContactUtil 2747d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell .isInvisibleAndAddable(mContactData, this)) { 274830cfd121ad8c8adb83cf417ff1d40a8ba1e3761dBrian Attwell editMenuItem.setIcon(R.drawable.ic_person_add_tinted_24dp); 27492e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell editMenuItem.setTitle(R.string.menu_add_contact); 2750d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 2751d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setIcon(R.drawable.ic_create_24dp); 27522e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell editMenuItem.setTitle(R.string.menu_editContact); 2753d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else { 2754d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(false); 2755d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2756a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 27575d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang final MenuItem deleteMenuItem = menu.findItem(R.id.menu_delete); 275882ed2b5380e134705f96e7e1f1586a25f8ac403fWalter Jang deleteMenuItem.setVisible(isContactEditable() && !mContactData.isUserProfile()); 27595d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang 2760a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell final MenuItem shareMenuItem = menu.findItem(R.id.menu_share); 2761a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell shareMenuItem.setVisible(isContactShareable()); 2762a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 276366965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell final MenuItem shortcutMenuItem = menu.findItem(R.id.menu_create_contact_shortcut); 276466965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell shortcutMenuItem.setVisible(isShortcutCreatable()); 276566965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell 276656bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell final MenuItem helpMenu = menu.findItem(R.id.menu_help); 276756bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell helpMenu.setVisible(HelpUtils.isHelpAndFeedbackAvailable()); 276856bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell 27698a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return true; 2770d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 27718a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return false; 2772d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2773d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2774d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 2775d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onOptionsItemSelected(MenuItem item) { 2776d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell switch (item.getItemId()) { 2777d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell case R.id.menu_star: 2778d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell toggleStar(item); 2779d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 2780d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell case R.id.menu_edit: 2781d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData)) { 2782ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // This action is used to launch the contact selector, with the option of 2783ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // creating a new contact. Creating a new contact is an INSERT, while selecting 2784ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // an exisiting one is an edit. The fields in the edit screen will be 2785ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // prepopulated with data. 2786ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos 2787ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); 2788ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos intent.setType(Contacts.CONTENT_ITEM_TYPE); 2789ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos 2790fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell ArrayList<ContentValues> values = mContactData.getContentValues(); 2791fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell 2792fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // Only pre-fill the name field if the provided display name is an nickname 2793fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // or better (e.g. structured name, nickname) 2794fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell if (mContactData.getDisplayNameSource() >= DisplayNameSources.NICKNAME) { 2795ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos intent.putExtra(Intents.Insert.NAME, mContactData.getDisplayName()); 2796fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell } else if (mContactData.getDisplayNameSource() 2797fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell == DisplayNameSources.ORGANIZATION) { 2798fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // This is probably an organization. Instead of copying the organization 2799fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // name into a name entry, copy it into the organization entry. This 2800fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // way we will still consider the contact an organization. 2801fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell final ContentValues organization = new ContentValues(); 2802fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell organization.put(Organization.COMPANY, mContactData.getDisplayName()); 2803fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell organization.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE); 2804fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell values.add(organization); 2805ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } 2806fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell 2807ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // Last time used and times used are aggregated values from the usage stat 2808ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // table. They need to be removed from data values so the SQL table can insert 2809ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // properly 2810ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos for (ContentValues value : values) { 2811ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos value.remove(Data.LAST_TIME_USED); 2812ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos value.remove(Data.TIMES_USED); 2813ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } 2814ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos intent.putExtra(Intents.Insert.DATA, values); 2815ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos 2816ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // If the contact can only export to the same account, add it to the intent. 2817ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // Otherwise the ContactEditorFragment will show a dialog for selecting an 2818ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // account. 2819ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos if (mContactData.getDirectoryExportSupport() == 2820ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos Directory.EXPORT_SUPPORT_SAME_ACCOUNT_ONLY) { 28214a1c574cd62eb7ca1e0fcc3a61e5378e5e0787feBrian Attwell intent.putExtra(Intents.Insert.EXTRA_ACCOUNT, 2822ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos new Account(mContactData.getDirectoryAccountName(), 2823ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos mContactData.getDirectoryAccountType())); 28244a1c574cd62eb7ca1e0fcc3a61e5378e5e0787feBrian Attwell intent.putExtra(Intents.Insert.EXTRA_DATA_SET, 2825ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos mContactData.getRawContacts().get(0).getDataSet()); 2826ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } 2827ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos 2828f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos // Add this flag to disable the delete menu option on directory contact joins 2829f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos // with local contacts. The delete option is ambiguous when joining contacts. 2830f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos intent.putExtra(ContactEditorFragment.INTENT_EXTRA_DISABLE_DELETE_MENU_OPTION, 2831f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos true); 2832f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos 2833ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos startActivityForResult(intent, REQUEST_CODE_CONTACT_SELECTION_ACTIVITY); 2834d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { 2835d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell InvisibleContactUtil.addToDefaultGroup(mContactData, this); 2836d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 2837d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editContact(); 2838d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2839d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 28405d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang case R.id.menu_delete: 28411c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner if (isContactEditable()) { 28421c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner deleteContact(); 28431c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner } 28445d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang return true; 2845752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell case R.id.menu_share: 284649de62f06d24653484adebd69123eeff2850a757Jay Shrauner if (isContactShareable()) { 284749de62f06d24653484adebd69123eeff2850a757Jay Shrauner shareContact(); 284849de62f06d24653484adebd69123eeff2850a757Jay Shrauner } 2849752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return true; 2850752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell case R.id.menu_create_contact_shortcut: 28511c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner if (isShortcutCreatable()) { 28521c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner createLauncherShortcutWithContact(); 28531c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner } 2854752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return true; 285556bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell case R.id.menu_help: 285656bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell HelpUtils.launchHelpAndFeedbackForContactScreen(this); 285756bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell return true; 2858d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell default: 2859d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return super.onOptionsItemSelected(item); 2860d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 286123889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos } 2862edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann} 2863