QuickContactActivity.java revision f764730a34da560db87206f9a48390d4c8085365
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 198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.animation.ArgbEvaluator; 20b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport android.animation.ObjectAnimator; 21edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.app.Activity; 22d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.app.Fragment; 23cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.app.LoaderManager.LoaderCallbacks; 24eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.app.SearchManager; 25752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.content.ActivityNotFoundException; 26edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.ContentUris; 27ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulosimport android.content.ContentValues; 286bb01347eab60f95deafdfe523b0c368707210f3Brian Attwellimport android.content.Context; 29edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.Intent; 30cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.content.Loader; 31dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulosimport android.content.pm.PackageManager; 32dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulosimport android.content.pm.ResolveInfo; 3331b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.Bitmap; 348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.Color; 35eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuff; 36eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuffColorFilter; 3731b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.BitmapDrawable; 388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.drawable.ColorDrawable; 3931b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.Drawable; 40eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.net.ParseException; 41edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.net.Uri; 42eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.net.WebAddress; 4331b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.os.AsyncTask; 44edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.os.Bundle; 458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.os.Trace; 46eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.CalendarContract; 47752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.provider.ContactsContract; 48edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Email; 49eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Event; 50eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.GroupMembership; 51eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Identity; 52eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Im; 53eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Nickname; 54eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Note; 55eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Organization; 56edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Phone; 57eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Relation; 58edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.SipAddress; 59edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.StructuredPostal; 60edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Website; 61752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.provider.ContactsContract.Contacts; 6260e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulosimport android.provider.ContactsContract.Data; 63eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.DisplayNameSources; 64ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulosimport android.provider.ContactsContract.DataUsageFeedback; 65edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.QuickContact; 66edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.RawContacts; 6731b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.support.v7.graphics.Palette; 6870e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chenimport android.telecomm.TelecommManager; 69edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.text.TextUtils; 70edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.util.Log; 712a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu; 722a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu.ContextMenuInfo; 73d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.Menu; 74d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.MenuInflater; 75eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.view.MenuItem; 76f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chenimport android.view.MotionEvent; 77edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View; 78edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View.OnClickListener; 792a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.View.OnCreateContextMenuListener; 8010d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawaimport android.view.WindowManager; 81edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.widget.ImageView; 82edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.widget.Toast; 83d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.widget.Toolbar; 84edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 8572b3ab1d8a62f228a540b05f4ed6373e494c7d72Christine Chenimport com.android.contacts.ContactSaveService; 86d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.ContactsActivity; 872d150da246632b1649999cfabed776133b097775Brian Attwellimport com.android.contacts.NfcHandler; 88e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.R; 89eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.CallUtil; 902a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.common.ClipboardUtils; 91eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.Collapser; 92eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.ContactsUtils; 93d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.common.editor.SelectAccountDialogFragment; 9470e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chenimport com.android.contacts.common.interactions.TouchPointManager; 9531b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport com.android.contacts.common.lettertiles.LetterTileDrawable; 96752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder; 97752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder.OnShortcutIntentCreatedListener; 980d5588da244d0992c3ff8f25d0875fdf95a8c644Chiao Chengimport com.android.contacts.common.model.AccountTypeManager; 99cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.Contact; 100cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.ContactLoader; 101cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.RawContact; 102428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.account.AccountType; 103d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.common.model.account.AccountWithDataSet; 104cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.DataItem; 105428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.dataitem.DataKind; 106cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.EmailDataItem; 107eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.EventDataItem; 108cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.ImDataItem; 109eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NicknameDataItem; 110eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NoteDataItem; 111eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.OrganizationDataItem; 112b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.common.model.dataitem.PhoneDataItem; 113eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.RelationDataItem; 114eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.SipAddressDataItem; 115eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredNameDataItem; 116eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredPostalDataItem; 117eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.WebsiteDataItem; 118eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.util.DateUtils; 119faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwellimport com.android.contacts.common.util.MaterialColorMapUtils; 120faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwellimport com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette; 121d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwellimport com.android.contacts.common.util.ViewUtil; 122333091ae754ddfc25714c14b9b89534be24379f9Paul Soulosimport com.android.contacts.detail.ContactDisplayUtils; 123899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport com.android.contacts.interactions.CalendarInteractionsLoader; 124ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulosimport com.android.contacts.interactions.CallLogInteractionsLoader; 1258a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport com.android.contacts.interactions.ContactDeletionInteraction; 126b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.ContactInteraction; 127b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.SmsInteractionsLoader; 1282d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.Entry; 1292a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryContextMenuInfo; 1302ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryTag; 131e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwellimport com.android.contacts.quickcontact.ExpandingEntryCardView.ExpandingEntryCardViewListener; 132e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.util.ImageViewDrawableSetter; 133eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.PhoneCapabilityTester; 134b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.util.SchedulingUtils; 135eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.StructuredPostalUtils; 136b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller; 137b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener; 138e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.google.common.base.Preconditions; 139e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.google.common.collect.Lists; 140e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng 1412d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport java.util.ArrayList; 142899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport java.util.Arrays; 143eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Calendar; 144b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Collections; 145b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Comparator; 146eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Date; 147edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.HashMap; 148edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.List; 149b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Map; 150edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 151edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/** 152edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Mostly translucent {@link Activity} that shows QuickContact dialog. It loads 153edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * data asynchronously, and then shows a popup with details centered around 154edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * {@link Intent#getSourceBounds()}. 155edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 156d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellpublic class QuickContactActivity extends ContactsActivity { 1578a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1588a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell /** 1598a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * QuickContacts immediately takes up the full screen. All possible information is shown. 1608a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * This value for {@link android.provider.ContactsContract.QuickContact#EXTRA_MODE} 1618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * should only be used by the Contacts app. 1628a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell */ 1638a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public static final int MODE_FULLY_EXPANDED = 4; 1648a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 165edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String TAG = "QuickContact"; 166edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1679b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final String KEY_THEME_COLOR = "theme_color"; 1689b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 1699b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final int ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION = 150; 1708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private static final int REQUEST_CODE_CONTACT_EDITOR_ACTIVITY = 1; 171bfa9442453c1d86e11e56702f9b8ef0e8e0da0b1Brian Attwell private static final int SCRIM_COLOR = Color.argb(0xC8, 0, 0, 0); 172ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos private static final String MIMETYPE_SMS = "vnd.android-dir/mms-sms"; 173dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 174752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** This is the Intent action to install a shortcut in the launcher. */ 175752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private static final String ACTION_INSTALL_SHORTCUT = 176752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell "com.android.launcher.action.INSTALL_SHORTCUT"; 177edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 178edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @SuppressWarnings("deprecation") 179edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String LEGACY_AUTHORITY = android.provider.Contacts.AUTHORITY; 180edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 181e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String MIMETYPE_GPLUS_PROFILE = 182e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos "vnd.android.cursor.item/vnd.googleplus.profile"; 183e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String INTENT_DATA_GPLUS_PROFILE_ADD_TO_CIRCLE = "Add to circle"; 184e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String MIMETYPE_HANGOUTS = 185e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos "vnd.android.cursor.item/vnd.googleplus.profile.comm"; 186e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String INTENT_DATA_HANGOUTS_VIDEO = "Start video call"; 18748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos private static final String CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY = 18848fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos "com.android.contacts.quickcontact.QuickContactActivity"; 189e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 19063176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell /** 19163176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell * The URI used to load the the Contact. Once the contact is loaded, use Contact#getLookupUri() 19263176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell * instead of referencing this URI. 19363176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell */ 194edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private Uri mLookupUri; 195edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private String[] mExcludeMimes; 1968a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mExtraMode; 1978a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mStatusBarColor; 1988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private boolean mHasAlreadyBeenOpened; 199edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 2006219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee private ImageView mPhotoView; 201eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mContactCard; 2026095369885edcca566a812b551886e29c7ff8039Brian Attwell private ExpandingEntryCardView mNoContactDetailsCard; 203b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private ExpandingEntryCardView mRecentCard; 204eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mAboutCard; 205b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private MultiShrinkScroller mScroller; 206d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private SelectAccountDialogFragmentListener mSelectAccountFragmentListener; 2076bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private AsyncTask<Void, Void, Cp2DataCardModel> mEntriesAndActionsTask; 2086bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 2096bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * The last copy of Cp2DataCardModel that was passed to {@link #populateContactAndAboutCard}. 2106bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 2116bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private Cp2DataCardModel mCachedCp2DataCardModel; 212f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell /** 213f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * This scrim's opacity is controlled in two different ways. 1) Before the initial entrance 214f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * animation finishes, the opacity is animated by a value animator. This is designed to 215f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * distract the user from the length of the initial loading time. 2) After the initial 216f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * entrance animation, the opacity is directly related to scroll position. 217f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell */ 2189b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private ColorDrawable mWindowScrim; 219f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell private boolean mIsEntranceAnimationFinished; 220a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell private MaterialColorMapUtils mMaterialColorMapUtils; 2218477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell private boolean mIsExitAnimationInProgress; 2228571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell private boolean mHasComputedThemeColor; 223edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 224a42ef76251778161d27bc07db214b8c81720e476Paul Soulos /** 225a42ef76251778161d27bc07db214b8c81720e476Paul Soulos * Used to stop the ExpandingEntry cards from adjusting between an entry click and the intent 226a42ef76251778161d27bc07db214b8c81720e476Paul Soulos * being launched. 227a42ef76251778161d27bc07db214b8c81720e476Paul Soulos */ 228a42ef76251778161d27bc07db214b8c81720e476Paul Soulos private boolean mHasIntentLaunched; 229a42ef76251778161d27bc07db214b8c81720e476Paul Soulos 2306cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee private Contact mContactData; 2319815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann private ContactLoader mContactLoader; 2329b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private PorterDuffColorFilter mColorFilter; 2339815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann 2349758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter(); 2359758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus 236edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 237cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * {@link #LEADING_MIMETYPES} is used to sort MIME-types. 238edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 239edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * <p>The MIME-types in {@link #LEADING_MIMETYPES} appear in the front of the dialog, 240edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * in the order specified here.</p> 241edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 242edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final List<String> LEADING_MIMETYPES = Lists.newArrayList( 243cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos Phone.CONTENT_ITEM_TYPE, SipAddress.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE, 244405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos StructuredPostal.CONTENT_ITEM_TYPE); 245edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 246a153dba33c2152332c5706178a367f52b0550723Paul Soulos private static final List<String> SORTED_ABOUT_CARD_MIMETYPES = Lists.newArrayList( 247a153dba33c2152332c5706178a367f52b0550723Paul Soulos Nickname.CONTENT_ITEM_TYPE, 248a153dba33c2152332c5706178a367f52b0550723Paul Soulos // Phonetic name is inserted after nickname if it is available. 249a153dba33c2152332c5706178a367f52b0550723Paul Soulos // No mimetype for phonetic name exists. 250a153dba33c2152332c5706178a367f52b0550723Paul Soulos Website.CONTENT_ITEM_TYPE, 251a153dba33c2152332c5706178a367f52b0550723Paul Soulos Organization.CONTENT_ITEM_TYPE, 252a153dba33c2152332c5706178a367f52b0550723Paul Soulos Event.CONTENT_ITEM_TYPE, 253a153dba33c2152332c5706178a367f52b0550723Paul Soulos Relation.CONTENT_ITEM_TYPE, 254a153dba33c2152332c5706178a367f52b0550723Paul Soulos Im.CONTENT_ITEM_TYPE, 255a153dba33c2152332c5706178a367f52b0550723Paul Soulos GroupMembership.CONTENT_ITEM_TYPE, 256a153dba33c2152332c5706178a367f52b0550723Paul Soulos Identity.CONTENT_ITEM_TYPE, 257a153dba33c2152332c5706178a367f52b0550723Paul Soulos Note.CONTENT_ITEM_TYPE); 258eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 259b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background contact loader */ 260b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_CONTACT_ID = 0; 261b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 262ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final String KEY_LOADER_EXTRA_PHONES = 263ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_PHONES"; 264ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 265b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background Sms Loader */ 266b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_SMS_ID = 1; 267b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int MAX_SMS_RETRIEVE = 3; 268ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 269ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the back Calendar Loader */ 270899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int LOADER_CALENDAR_ID = 2; 271ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final String KEY_LOADER_EXTRA_EMAILS = 272ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_EMAILS"; 273899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_PAST_CALENDAR_RETRIEVE = 3; 274899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_FUTURE_CALENDAR_RETRIEVE = 3; 275899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 276899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 180L * 24L * 60L * 60L * 1000L /* 180 days */; 277899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 278899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 36L * 60L * 60L * 1000L /* 36 hours */; 279899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 280ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the background Call Log Loader */ 281ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int LOADER_CALL_LOG_ID = 3; 282ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int MAX_CALL_LOG_RETRIEVE = 3; 2836095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int MIN_NUM_CONTACT_ENTRIES_SHOWN = 3; 2846095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN = 3; 2856095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int CARD_ENTRY_ID_EDIT_CONTACT = -2; 286ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 287ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 288ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int[] mRecentLoaderIds = new int[]{ 289ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_SMS_ID, 290ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALENDAR_ID, 291ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID}; 292a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos private Map<Integer, List<ContactInteraction>> mRecentLoaderResults = new HashMap<>(); 293b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 294d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private static final String FRAGMENT_TAG_SELECT_ACCOUNT = "select_account_fragment"; 2956cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee 2962d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos final OnClickListener mEntryClickHandler = new OnClickListener() { 2972d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos @Override 2982d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos public void onClick(View v) { 2992ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final Object entryTagObject = v.getTag(); 3002ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos if (entryTagObject == null || !(entryTagObject instanceof EntryTag)) { 3012ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos Log.w(TAG, "EntryTag was not used correctly"); 3026095369885edcca566a812b551886e29c7ff8039Brian Attwell return; 3036095369885edcca566a812b551886e29c7ff8039Brian Attwell } 3042ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final EntryTag entryTag = (EntryTag) entryTagObject; 3052ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final Intent intent = entryTag.getIntent(); 3062ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final int dataId = entryTag.getId(); 3072ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos 3082ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos if (dataId == CARD_ENTRY_ID_EDIT_CONTACT) { 3092ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos editContact(); 3102d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos return; 3112d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 312ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 313ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Default to USAGE_TYPE_CALL. Usage is summed among all types for sorting each data id 314ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // so the exact usage type is not necessary in all cases 315ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos String usageType = DataUsageFeedback.USAGE_TYPE_CALL; 316ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 31720bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos final Uri intentUri = intent.getData(); 31820bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos if ((intentUri != null && intentUri.getScheme() != null && 31920bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos intentUri.getScheme().equals(CallUtil.SCHEME_SMSTO)) || 320ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos (intent.getType() != null && intent.getType().equals(MIMETYPE_SMS))) { 321ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos usageType = DataUsageFeedback.USAGE_TYPE_SHORT_TEXT; 322ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 323ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 324ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Data IDs start at 1 so anything less is invalid 325ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (dataId > 0) { 32620bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos final Uri dataUsageUri = DataUsageFeedback.FEEDBACK_URI.buildUpon() 327ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendPath(String.valueOf(dataId)) 328ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, usageType) 329ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .build(); 330ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final boolean successful = getContentResolver().update( 33120bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos dataUsageUri, new ContentValues(), null, null) > 0; 332ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (!successful) { 333ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Log.w(TAG, "DataUsageFeedback increment failed"); 334ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 335ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } else { 336ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Log.w(TAG, "Invalid Data ID"); 337ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 338ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 33970e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen // Pass the touch point through the intent for use in the InCallUI 34070e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen if (Intent.ACTION_CALL.equals(intent.getAction())) { 3411f8a3fda87bf61e579d61e3fdd246548943d070aNancy Chen if (TouchPointManager.getInstance().hasValidPoint()) { 34270e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen Bundle extras = new Bundle(); 3431f8a3fda87bf61e579d61e3fdd246548943d070aNancy Chen extras.putParcelable(TouchPointManager.TOUCH_POINT, 3441f8a3fda87bf61e579d61e3fdd246548943d070aNancy Chen TouchPointManager.getInstance().getPoint()); 34570e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen intent.putExtra(TelecommManager.EXTRA_OUTGOING_CALL_EXTRAS, extras); 34670e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen } 34770e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen } 34870e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen 349a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 350ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos startActivity(intent); 3512d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 3522d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos }; 3532d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos 354e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell final ExpandingEntryCardViewListener mExpandingEntryCardViewListener 355e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell = new ExpandingEntryCardViewListener() { 356e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell @Override 357e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell public void onCollapse(int heightDelta) { 358e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell mScroller.prepareForShrinkingScrollChild(heightDelta); 359e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell } 3600cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos 3610cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos @Override 3620cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos public void onExpand(int heightDelta) { 3630cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mScroller.prepareForExpandingScrollChild(); 3640cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos } 365e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell }; 366e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell 3672a4207fb39330e840436215c896cde911489e111Paul Soulos private final OnCreateContextMenuListener mEntryContextMenuListener = 3682a4207fb39330e840436215c896cde911489e111Paul Soulos new OnCreateContextMenuListener() { 3692a4207fb39330e840436215c896cde911489e111Paul Soulos @Override 3702a4207fb39330e840436215c896cde911489e111Paul Soulos public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 3712a4207fb39330e840436215c896cde911489e111Paul Soulos if (menuInfo == null) { 3722a4207fb39330e840436215c896cde911489e111Paul Soulos return; 3732a4207fb39330e840436215c896cde911489e111Paul Soulos } 3742a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo info = (EntryContextMenuInfo) menuInfo; 3752a4207fb39330e840436215c896cde911489e111Paul Soulos menu.setHeaderTitle(info.getCopyText()); 3762a4207fb39330e840436215c896cde911489e111Paul Soulos menu.add(R.string.copy_text); 3772a4207fb39330e840436215c896cde911489e111Paul Soulos } 3782a4207fb39330e840436215c896cde911489e111Paul Soulos }; 3792a4207fb39330e840436215c896cde911489e111Paul Soulos 3802a4207fb39330e840436215c896cde911489e111Paul Soulos @Override 3812a4207fb39330e840436215c896cde911489e111Paul Soulos public boolean onContextItemSelected(MenuItem item) { 3822a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo menuInfo; 3832a4207fb39330e840436215c896cde911489e111Paul Soulos try { 3842a4207fb39330e840436215c896cde911489e111Paul Soulos menuInfo = (EntryContextMenuInfo) item.getMenuInfo(); 3852a4207fb39330e840436215c896cde911489e111Paul Soulos } catch (ClassCastException e) { 3862a4207fb39330e840436215c896cde911489e111Paul Soulos Log.e(TAG, "bad menuInfo", e); 3872a4207fb39330e840436215c896cde911489e111Paul Soulos return false; 3882a4207fb39330e840436215c896cde911489e111Paul Soulos } 3892a4207fb39330e840436215c896cde911489e111Paul Soulos 3902a4207fb39330e840436215c896cde911489e111Paul Soulos ClipboardUtils.copyText(this, menuInfo.getCopyLabel(), menuInfo.getCopyText(), true); 3912a4207fb39330e840436215c896cde911489e111Paul Soulos return true; 3922a4207fb39330e840436215c896cde911489e111Paul Soulos } 3932a4207fb39330e840436215c896cde911489e111Paul Soulos 394d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell /** 395d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Headless fragment used to handle account selection callbacks invoked from 396d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * {@link DirectoryContactUtil}. 397d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 398d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public static class SelectAccountDialogFragmentListener extends Fragment 399d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell implements SelectAccountDialogFragment.Listener { 400d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 401d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private QuickContactActivity mQuickContactActivity; 402d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 403d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public SelectAccountDialogFragmentListener() {} 404d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 405d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 406d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void onAccountChosen(AccountWithDataSet account, Bundle extraArgs) { 407d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell DirectoryContactUtil.createCopy(mQuickContactActivity.mContactData.getContentValues(), 408d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell account, mQuickContactActivity); 409d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 410d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 411d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 412d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void onAccountSelectorCancelled() {} 413d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 414d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell /** 415d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Set the parent activity. Since rotation can cause this fragment to be used across 416d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * more than one activity instance, we need to explicitly set this value instead 417d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * of making this class non-static. 418d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 419d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void setQuickContactActivity(QuickContactActivity quickContactActivity) { 420d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mQuickContactActivity = quickContactActivity; 421d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 422d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 423d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 424b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell final MultiShrinkScrollerListener mMultiShrinkScrollerListener 425b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell = new MultiShrinkScrollerListener() { 426b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 427b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onScrolledOffBottom() { 428f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell finish(); 429b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 4308a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 4318a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 4328a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onEnterFullscreen() { 4338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 4348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 4358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 4368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 4378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onExitFullscreen() { 4388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 4398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 4408477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 4418477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 4428477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell public void onStartScrollOffBottom() { 4438477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mIsExitAnimationInProgress = true; 4448477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 4458477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 4468477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 447f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void onEntranceAnimationDone() { 448f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = true; 449f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 450f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 451f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell @Override 452f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void onTransparentViewHeightChange(float ratio) { 453f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell if (mIsEntranceAnimationFinished) { 454f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mWindowScrim.setAlpha((int) (0xFF * ratio)); 4558477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 4568477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 457b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell }; 458b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 459eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 460eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 461eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Data items are compared to the same mimetype based off of three qualities: 462eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 1. Super primary 463eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 2. Primary 464eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 3. Times used 465eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 466eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<DataItem> mWithinMimeTypeDataItemComparator = 467eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<DataItem>() { 468eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 469eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(DataItem lhs, DataItem rhs) { 470eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!lhs.getMimeType().equals(rhs.getMimeType())) { 471eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Log.wtf(TAG, "Comparing DataItems with different mimetypes lhs.getMimeType(): " + 472eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getMimeType() + " rhs.getMimeType(): " + rhs.getMimeType()); 473eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 474eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 475eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 476eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lhs.isSuperPrimary()) { 477eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 478eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (rhs.isSuperPrimary()) { 479eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 480eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lhs.isPrimary() && !rhs.isPrimary()) { 481eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 482eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (!lhs.isPrimary() && rhs.isPrimary()) { 483eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 484eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 485eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = 486eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 487eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = 488eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 489eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 490eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return rhsTimesUsed - lhsTimesUsed; 491eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 492eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 493eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 494eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 495cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos /** 496cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * Sorts among different mimetypes based off: 497cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * 1. Times used 498cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * 2. Last time used 499cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * 3. Statically defined 500cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos */ 501eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<List<DataItem>> mAmongstMimeTypeDataItemComparator = 502eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<List<DataItem>> () { 503eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 504eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(List<DataItem> lhsList, List<DataItem> rhsList) { 505eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataItem lhs = lhsList.get(0); 506eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataItem rhs = rhsList.get(0); 507eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 508eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 509eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int timesUsedDifference = rhsTimesUsed - lhsTimesUsed; 510eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (timesUsedDifference != 0) { 511eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return timesUsedDifference; 512eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 513eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 514eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lhsLastTimeUsed = 515eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getLastTimeUsed() == null ? 0 : lhs.getLastTimeUsed(); 516eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long rhsLastTimeUsed = 517eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getLastTimeUsed() == null ? 0 : rhs.getLastTimeUsed(); 518eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lastTimeUsedDifference = rhsLastTimeUsed - lhsLastTimeUsed; 519eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lastTimeUsedDifference > 0) { 520eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 521eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lastTimeUsedDifference < 0) { 522eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 523eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 524eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 525eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Times used and last time used are the same. Resort to statically defined. 526eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String lhsMimeType = lhs.getMimeType(); 527eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String rhsMimeType = rhs.getMimeType(); 528eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (String mimeType : LEADING_MIMETYPES) { 529eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lhsMimeType.equals(mimeType)) { 530eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 531eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (rhsMimeType.equals(mimeType)) { 532eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 533eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 534eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 535eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 536eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 537eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 538eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 539edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @Override 540f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen public boolean dispatchTouchEvent(MotionEvent ev) { 541f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen if (ev.getAction() == MotionEvent.ACTION_DOWN) { 542f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); 543f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen } 544f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen return super.dispatchTouchEvent(ev); 545f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen } 546f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen 547f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen @Override 5488a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onCreate(Bundle savedInstanceState) { 5498a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onCreate()"); 5508a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onCreate(savedInstanceState); 551edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 5528a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getWindow().setStatusBarColor(Color.TRANSPARENT); 5532426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann 554d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(getIntent()); 555dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 55610d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa // Show QuickContact in front of soft input 55710d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 55810d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 55910d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa 560edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann setContentView(R.layout.quickcontact_activity); 561edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 562a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell mMaterialColorMapUtils = new MaterialColorMapUtils(getResources()); 563a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell 5640cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mScroller = (MultiShrinkScroller) findViewById(R.id.multiscroller); 5650cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos 566eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard = (ExpandingEntryCardView) findViewById(R.id.communication_card); 5676095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard = (ExpandingEntryCardView) findViewById(R.id.no_contact_data_card); 568b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card); 569eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard = (ExpandingEntryCardView) findViewById(R.id.about_card); 570edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 5716095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setOnClickListener(mEntryClickHandler); 572eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setOnClickListener(mEntryClickHandler); 573eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setExpandButtonText( 57423889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos getResources().getString(R.string.expanding_entry_card_view_see_all)); 5752a4207fb39330e840436215c896cde911489e111Paul Soulos mContactCard.setOnCreateContextMenuListener(mEntryContextMenuListener); 576b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 577b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setOnClickListener(mEntryClickHandler); 578b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setTitle(getResources().getString(R.string.recent_card_title)); 579edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 580eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setOnClickListener(mEntryClickHandler); 5812a4207fb39330e840436215c896cde911489e111Paul Soulos mAboutCard.setOnCreateContextMenuListener(mEntryContextMenuListener); 582eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 583d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mPhotoView = (ImageView) findViewById(R.id.photo); 58463176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell final View transparentView = findViewById(R.id.transparent_view); 5850d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell if (mScroller != null) { 58663176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell transparentView.setOnClickListener(new OnClickListener() { 5870d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell @Override 5880d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell public void onClick(View v) { 5890d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell mScroller.scrollOffBottom(); 5900d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 5910d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell }); 5920d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 593edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 594d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell // Allow a shadow to be shown under the toolbar. 595d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell ViewUtil.addRectangularOutlineProvider(findViewById(R.id.toolbar_parent), getResources()); 596d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell 597d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 598d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell setActionBar(toolbar); 5999b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getActionBar().setTitle(null); 6009b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // Put a TextView with a known resource id into the ActionBar. This allows us to easily 6019b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // find the correct TextView location & size later. 6029b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell toolbar.addView(getLayoutInflater().inflate(R.layout.quickcontact_title_placeholder, null)); 6036219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee 6048a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = savedInstanceState != null; 605f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = mHasAlreadyBeenOpened; 6069b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mWindowScrim = new ColorDrawable(SCRIM_COLOR); 607f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mWindowScrim.setAlpha(0); 6089b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getWindow().setBackgroundDrawable(mWindowScrim); 609edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 610c33ae17c9816b770041ee1f9ccde10e7c7eee491Brian Attwell mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED); 611ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // mScroller needs to perform asynchronous measurements after initalize(), therefore 612ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // we can't mark this as GONE. 613ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.INVISIBLE); 6148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 6159b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell setHeaderNameText(R.string.missing_name); 6169b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 617d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener= (SelectAccountDialogFragmentListener) getFragmentManager() 618d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell .findFragmentByTag(FRAGMENT_TAG_SELECT_ACCOUNT); 619d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mSelectAccountFragmentListener == null) { 620d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener = new SelectAccountDialogFragmentListener(); 621d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell getFragmentManager().beginTransaction().add(0, mSelectAccountFragmentListener, 622d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell FRAGMENT_TAG_SELECT_ACCOUNT).commit(); 623d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener.setRetainInstance(true); 624d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 625d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener.setQuickContactActivity(this); 62623889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos 627f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ true, 628f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell new Runnable() { 629f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell @Override 630f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void run() { 631f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell if (!mHasAlreadyBeenOpened) { 632f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell // The initial scrim opacity must match the scrim opacity that would be 633f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell // achieved by scrolling to the starting position. 634f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final float alphaRatio = mExtraMode == MODE_FULLY_EXPANDED ? 635f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 1 : mScroller.getStartingTransparentHeightRatio(); 636f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final int duration = getResources().getInteger( 637f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell android.R.integer.config_shortAnimTime); 638f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final int desiredAlpha = (int) (0xFF * alphaRatio); 639f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell ObjectAnimator o = ObjectAnimator.ofInt(mWindowScrim, "alpha", 0, 640f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell desiredAlpha).setDuration(duration); 641f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 642f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell o.start(); 643f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 644f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 645f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell }); 646f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 6479b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (savedInstanceState != null) { 6489b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell final int color = savedInstanceState.getInt(KEY_THEME_COLOR, 0); 649ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 650ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell new Runnable() { 651ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell @Override 652ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell public void run() { 653ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for the pre draw before setting the initial scroll 654ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // value. Prior to pre draw all scroll values are invalid. 655ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (mHasAlreadyBeenOpened) { 656ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.VISIBLE); 657ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setScroll(mScroller.getScrollNeededToBeFullScreen()); 658ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 659ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for pre draw for setting the theme color. Setting the 660ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // header tint before the MultiShrinkScroller has been measured will 661ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // cause incorrect tinting calculations. 662ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (color != 0) { 663a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell setThemeColor(mMaterialColorMapUtils 664a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell .calculatePrimaryAndSecondaryColor(color)); 6659b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 666ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 667ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell }); 6689b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 6699b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 6708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 6718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 6728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 673405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos @Override 674405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos protected void onActivityResult(int requestCode, int resultCode, Intent data) { 6758a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (requestCode == REQUEST_CODE_CONTACT_EDITOR_ACTIVITY && 6768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell resultCode == ContactDeletionInteraction.RESULT_CODE_DELETED) { 6778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // The contact that we were showing has been deleted. 6788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell finish(); 679b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 6808a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 681dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 6828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 6838a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onNewIntent(Intent intent) { 6848a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onNewIntent(intent); 6858a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 686f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = true; 6878571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = false; 688d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(intent); 689d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 690d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 6919b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell @Override 6929b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell public void onSaveInstanceState(Bundle savedInstanceState) { 6939b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell super.onSaveInstanceState(savedInstanceState); 6949b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mColorFilter != null) { 6959b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell savedInstanceState.putInt(KEY_THEME_COLOR, mColorFilter.getColor()); 6969b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 6979b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 6989b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 699d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void processIntent(Intent intent) { 700d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell Uri lookupUri = intent.getData(); 701d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 702d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Check to see whether it comes from the old version. 703d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) { 704d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final long rawContactId = ContentUris.parseId(lookupUri); 705d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell lookupUri = RawContacts.getContactLookupUri(getContentResolver(), 706d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); 707d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 708d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, 709d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell QuickContact.MODE_LARGE); 710d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Uri oldLookupUri = mLookupUri; 711d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 712d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mLookupUri = Preconditions.checkNotNull(lookupUri, "missing lookupUri"); 713d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES); 714d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (oldLookupUri == null) { 715d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactLoader = (ContactLoader) getLoaderManager().initLoader( 716d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell LOADER_CONTACT_ID, null, mLoaderContactCallbacks); 717d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (oldLookupUri != mLookupUri) { 718d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // After copying a directory contact, the contact URI changes. Therefore, 719d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // we need to restart the loader and reload the new contact. 720899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos for (int interactionLoaderId : mRecentLoaderIds) { 721899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos getLoaderManager().destroyLoader(interactionLoaderId); 722899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos } 723405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos mContactLoader = (ContactLoader) getLoaderManager().restartLoader( 724405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos LOADER_CONTACT_ID, null, mLoaderContactCallbacks); 725d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 7262d150da246632b1649999cfabed776133b097775Brian Attwell 7272d150da246632b1649999cfabed776133b097775Brian Attwell NfcHandler.register(this, mLookupUri); 7282426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann } 729edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 730b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private void runEntranceAnimation() { 7318a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mHasAlreadyBeenOpened) { 7328a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 7338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 7348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 735c33ae17c9816b770041ee1f9ccde10e7c7eee491Brian Attwell mScroller.scrollUpForEntranceAnimation(mExtraMode != MODE_FULLY_EXPANDED); 736b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 737b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 73881281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 739d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void setHeaderNameText(int resId) { 7409b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 741f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell mScroller.setTitle(getText(resId) == null ? null : getText(resId).toString()); 7429b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 74381281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 74481281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 74581281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 746f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell private void setHeaderNameText(String value) { 747d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (!TextUtils.isEmpty(value)) { 7489b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 749f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell mScroller.setTitle(value); 7509b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 75181281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 75281281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 75381281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 75481281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** 755edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Check if the given MIME-type appears in the list of excluded MIME-types 756edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * that the most-recent caller requested. 757edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 758edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private boolean isMimeExcluded(String mimeType) { 759edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (mExcludeMimes == null) return false; 760edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann for (String excludedMime : mExcludeMimes) { 761edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (TextUtils.equals(excludedMime, mimeType)) { 762edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return true; 763edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 764edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 765edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return false; 766edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 767edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 768edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 769cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann * Handle the result from the ContactLoader 770edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 7718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void bindContactData(final Contact data) { 7728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("bindContactData"); 7736cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee mContactData = data; 774d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell invalidateOptionsMenu(); 775edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 7768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 7778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("Set display photo & name"); 778dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 7796219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee mPhotoSetter.setupContactPhoto(data, mPhotoView); 78031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell extractAndApplyTintFromPhotoViewAsynchronously(); 7814936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell analyzeWhitenessOfPhotoAsynchronously(); 782333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos setHeaderNameText(ContactDisplayUtils.getDisplayName(this, data).toString()); 783edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 7848a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 785dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 7866bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mEntriesAndActionsTask = new AsyncTask<Void, Void, Cp2DataCardModel>() { 7878a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 7888a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 7896bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell protected Cp2DataCardModel doInBackground( 790eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Void... params) { 791eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return generateDataModelFromContact(data); 7928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 7938a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 7948a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 7956bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell protected void onPostExecute(Cp2DataCardModel cardDataModel) { 7966bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell super.onPostExecute(cardDataModel); 7978a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Check that original AsyncTask parameters are still valid and the activity 7988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // is still running before binding to UI. A new intent could invalidate 7998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the results, for example. 8008a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (data == mContactData && !isCancelled()) { 8016bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell bindDataToCards(cardDataModel); 8028a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell showActivity(); 8038a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8048a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8058a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }; 8068a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.execute(); 8078a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8088a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 8096bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void bindDataToCards(Cp2DataCardModel cp2DataCardModel) { 8106bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell startInteractionLoaders(cp2DataCardModel); 8116bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell populateContactAndAboutCard(cp2DataCardModel); 812eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 813eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 8146bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void startInteractionLoaders(Cp2DataCardModel cp2DataCardModel) { 8156bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final Map<String, List<DataItem>> dataItemsMap = cp2DataCardModel.dataItemsMap; 8166bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> phoneDataItems = dataItemsMap.get(Phone.CONTENT_ITEM_TYPE); 817eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] phoneNumbers = null; 818eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (phoneDataItems != null) { 819eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers = new String[phoneDataItems.size()]; 820eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < phoneDataItems.size(); ++i) { 821eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers[i] = ((PhoneDataItem) phoneDataItems.get(i)).getNumber(); 822eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 823eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 824ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle phonesExtraBundle = new Bundle(); 825eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_PHONES, phoneNumbers); 826eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 827eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("start sms loader"); 8288a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getLoaderManager().initLoader( 8298a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell LOADER_SMS_ID, 830ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 831ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos mLoaderInteractionsCallbacks); 832ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.endSection(); 833ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 834ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.beginSection("start call log loader"); 835ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos getLoaderManager().initLoader( 836ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID, 837ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 8388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mLoaderInteractionsCallbacks); 839899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.endSection(); 8408a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 841eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 842899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.beginSection("start calendar loader"); 8436bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> emailDataItems = dataItemsMap.get(Email.CONTENT_ITEM_TYPE); 844eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] emailAddresses = null; 845eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (emailDataItems != null) { 846eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses = new String[emailDataItems.size()]; 847eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < emailDataItems.size(); ++i) { 848eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses[i] = ((EmailDataItem) emailDataItems.get(i)).getAddress(); 849eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 850eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 851ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle emailsExtraBundle = new Bundle(); 852eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailsExtraBundle.putStringArray(KEY_LOADER_EXTRA_EMAILS, emailAddresses); 853899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos getLoaderManager().initLoader( 854899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos LOADER_CALENDAR_ID, 855ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos emailsExtraBundle, 856899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos mLoaderInteractionsCallbacks); 8578a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 8588a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8598a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 8608a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void showActivity() { 8618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller != null) { 8628a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mScroller.setVisibility(View.VISIBLE); 8638a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 8648a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell new Runnable() { 8658a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 8668a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void run() { 8678a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell runEntranceAnimation(); 8688a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8698a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }); 8708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 8736bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private List<List<Entry>> buildAboutCardEntries(Map<String, List<DataItem>> dataItemsMap) { 874a153dba33c2152332c5706178a367f52b0550723Paul Soulos final List<List<Entry>> aboutCardEntries = new ArrayList<>(); 875a153dba33c2152332c5706178a367f52b0550723Paul Soulos for (String mimetype : SORTED_ABOUT_CARD_MIMETYPES) { 8766bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> mimeTypeItems = dataItemsMap.get(mimetype); 877a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (mimeTypeItems == null) { 878a153dba33c2152332c5706178a367f52b0550723Paul Soulos continue; 879a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 8806bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // Set aboutCardTitleOut = null, since SORTED_ABOUT_CARD_MIMETYPES doesn't contain 8816bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // the name mimetype. 8826bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<Entry> aboutEntries = dataItemsToEntries(mimeTypeItems, 8836bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /* aboutCardTitleOut = */ null); 884a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (aboutEntries.size() > 0) { 885a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(aboutEntries); 886a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 887a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 888a153dba33c2152332c5706178a367f52b0550723Paul Soulos return aboutCardEntries; 889a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 890a153dba33c2152332c5706178a367f52b0550723Paul Soulos 891a42ef76251778161d27bc07db214b8c81720e476Paul Soulos @Override 892a42ef76251778161d27bc07db214b8c81720e476Paul Soulos protected void onResume() { 893a42ef76251778161d27bc07db214b8c81720e476Paul Soulos super.onResume(); 894a42ef76251778161d27bc07db214b8c81720e476Paul Soulos // If returning from a launched activity, repopulate the contact and about card 895a42ef76251778161d27bc07db214b8c81720e476Paul Soulos if (mHasIntentLaunched) { 896a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = false; 8976bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell populateContactAndAboutCard(mCachedCp2DataCardModel); 898a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 899a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 900a42ef76251778161d27bc07db214b8c81720e476Paul Soulos 9016bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void populateContactAndAboutCard(Cp2DataCardModel cp2DataCardModel) { 9026bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mCachedCp2DataCardModel = cp2DataCardModel; 9036bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (mHasIntentLaunched || cp2DataCardModel == null) { 904a42ef76251778161d27bc07db214b8c81720e476Paul Soulos return; 905a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 906eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind contact card"); 907eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 9086bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> contactCardEntries = cp2DataCardModel.contactCardEntries; 9096bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> aboutCardEntries = cp2DataCardModel.aboutCardEntries; 9106bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final String customAboutCardName = cp2DataCardModel.customAboutCardName; 911eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 912eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (contactCardEntries.size() > 0) { 913eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.initialize(contactCardEntries, 914eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* numInitialVisibleEntries = */ MIN_NUM_CONTACT_ENTRIES_SHOWN, 915c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos /* isExpanded = */ mContactCard.isExpanded(), 91689966b4ed8cc9d385e5ac6b4a7e9e08ada387eb0Paul Soulos /* isAlwaysExpanded = */ false, 9170cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mExpandingEntryCardViewListener, 9180cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mScroller); 919eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.VISIBLE); 920eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 921eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.GONE); 922eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 923eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 9248a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 925eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind about card"); 926c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos // Phonetic name is not a data item, so the entry needs to be created separately 927c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos final String phoneticName = mContactData.getPhoneticName(); 928c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos if (!TextUtils.isEmpty(phoneticName)) { 929c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos Entry phoneticEntry = new Entry(/* viewId = */ -1, 930c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* icon = */ null, 931c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos getResources().getString(R.string.name_phonetic), 932c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos phoneticName, 933c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* text = */ null, 934c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* intent = */ null, 935c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateIcon = */ null, 936c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateIntent = */ null, 937c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateContentDescription = */ null, 938c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* shouldApplyColor = */ false, 9392a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, 9402a4207fb39330e840436215c896cde911489e111Paul Soulos /* EntryContextMenuInfo = */ new EntryContextMenuInfo(phoneticName, 94148fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos getResources().getString(R.string.name_phonetic)), 94248fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, 94348fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIntent = */ null, 94448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdContentDescription = */ null); 945c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos List<Entry> phoneticList = new ArrayList<>(); 946c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos phoneticList.add(phoneticEntry); 947a153dba33c2152332c5706178a367f52b0550723Paul Soulos // Phonetic name comes after nickname. Check to see if the first entry type is nickname 948a0fa4c18dc111ceea9ff47f35ee01fecc1003578Paul Soulos if (aboutCardEntries.size() > 0 && aboutCardEntries.get(0).get(0).getHeader().equals( 949a153dba33c2152332c5706178a367f52b0550723Paul Soulos getResources().getString(R.string.header_nickname_entry))) { 950a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(1, phoneticList); 951a153dba33c2152332c5706178a367f52b0550723Paul Soulos } else { 952a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(0, phoneticList); 953a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 954c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos } 955c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos 9566bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!TextUtils.isEmpty(customAboutCardName)) { 9576bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mAboutCard.setTitle(customAboutCardName); 9586bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 9596bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 960cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos if (aboutCardEntries.size() > 0) { 961cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos mAboutCard.initialize(aboutCardEntries, 962cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos /* numInitialVisibleEntries = */ 1, 963cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos /* isExpanded = */ true, 964cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos /* isAlwaysExpanded = */ true, 965cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos mExpandingEntryCardViewListener, 966cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos mScroller); 967cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos } 9686095369885edcca566a812b551886e29c7ff8039Brian Attwell 9696095369885edcca566a812b551886e29c7ff8039Brian Attwell if (contactCardEntries.size() == 0 && aboutCardEntries.size() == 0) { 9706095369885edcca566a812b551886e29c7ff8039Brian Attwell initializeNoContactDetailCard(); 9716095369885edcca566a812b551886e29c7ff8039Brian Attwell } else { 9726095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setVisibility(View.GONE); 9736095369885edcca566a812b551886e29c7ff8039Brian Attwell } 9746095369885edcca566a812b551886e29c7ff8039Brian Attwell 975a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos // If the Recent card is already initialized (all recent data is loaded), show the About 976a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos // card if it has entries. Otherwise About card visibility will be set in bindRecentData() 977a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos if (isAllRecentDataLoaded() && aboutCardEntries.size() > 0) { 978a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos mAboutCard.setVisibility(View.VISIBLE); 979a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos } 980eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 981eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 982eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 983eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 9846095369885edcca566a812b551886e29c7ff8039Brian Attwell * Create a card that shows "Add email" and "Add phone number" entries in grey. 9856095369885edcca566a812b551886e29c7ff8039Brian Attwell */ 9866095369885edcca566a812b551886e29c7ff8039Brian Attwell private void initializeNoContactDetailCard() { 9876095369885edcca566a812b551886e29c7ff8039Brian Attwell final Drawable phoneIcon = getResources().getDrawable( 9886095369885edcca566a812b551886e29c7ff8039Brian Attwell R.drawable.ic_phone_24dp).mutate(); 9896095369885edcca566a812b551886e29c7ff8039Brian Attwell final Entry phonePromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, 9906095369885edcca566a812b551886e29c7ff8039Brian Attwell phoneIcon, getString(R.string.quickcontact_add_phone_number), 991dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* subHeader = */ null, /* text = */ null, getEditContactIntent(), 992dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIcon = */ null, /* alternateIntent = */ null, 993714455bba22b99d168a2e864dfbc74a6e30dfdb6Paul Soulos /* alternateContentDescription = */ null, /* shouldApplyColor = */ true, 99448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* isEditable = */ false, /* EntryContextMenuInfo = */ null, 99548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, /* thirdIntent = */ null, 99648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdContentDescription = */ null); 9976095369885edcca566a812b551886e29c7ff8039Brian Attwell 9986095369885edcca566a812b551886e29c7ff8039Brian Attwell final Drawable emailIcon = getResources().getDrawable( 9996095369885edcca566a812b551886e29c7ff8039Brian Attwell R.drawable.ic_email_24dp).mutate(); 10006095369885edcca566a812b551886e29c7ff8039Brian Attwell final Entry emailPromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, 10016095369885edcca566a812b551886e29c7ff8039Brian Attwell emailIcon, getString(R.string.quickcontact_add_email), /* subHeader = */ null, 1002dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* text = */ null, getEditContactIntent(), /* alternateIcon = */ null, 1003dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIntent = */ null, /* alternateContentDescription = */ null, 10042a4207fb39330e840436215c896cde911489e111Paul Soulos /* shouldApplyColor = */ true, /* isEditable = */ false, 100548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* EntryContextMenuInfo = */ null, /* thirdIcon = */ null, 100648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIntent = */ null, /* thirdContentDescription = */ null); 10076095369885edcca566a812b551886e29c7ff8039Brian Attwell 10086095369885edcca566a812b551886e29c7ff8039Brian Attwell final List<List<Entry>> promptEntries = new ArrayList<>(); 10096095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.add(new ArrayList<Entry>(1)); 10106095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.add(new ArrayList<Entry>(1)); 10116095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.get(0).add(phonePromptEntry); 10126095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.get(1).add(emailPromptEntry); 10136095369885edcca566a812b551886e29c7ff8039Brian Attwell 10146095369885edcca566a812b551886e29c7ff8039Brian Attwell final int subHeaderTextColor = getResources().getColor( 10156095369885edcca566a812b551886e29c7ff8039Brian Attwell R.color.quickcontact_entry_sub_header_text_color); 10166095369885edcca566a812b551886e29c7ff8039Brian Attwell final PorterDuffColorFilter greyColorFilter = 10176095369885edcca566a812b551886e29c7ff8039Brian Attwell new PorterDuffColorFilter(subHeaderTextColor, PorterDuff.Mode.SRC_ATOP); 1018c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos mNoContactDetailsCard.initialize(promptEntries, 2, /* isExpanded = */ true, 10190cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos /* isAlwaysExpanded = */ true, mExpandingEntryCardViewListener, mScroller); 10206095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setVisibility(View.VISIBLE); 10216095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setEntryHeaderColor(subHeaderTextColor); 10226095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setColorAndFilter(subHeaderTextColor, greyColorFilter); 10236095369885edcca566a812b551886e29c7ff8039Brian Attwell } 10246095369885edcca566a812b551886e29c7ff8039Brian Attwell 10256095369885edcca566a812b551886e29c7ff8039Brian Attwell /** 1026eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Builds the {@link DataItem}s Map out of the Contact. 1027eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param data The contact to build the data from. 1028eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return A pair containing a list of data items sorted within mimetype and sorted 1029eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * amongst mimetype. The map goes from mimetype string to the sorted list of data items within 1030eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * mimetype 1031eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 10326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private Cp2DataCardModel generateDataModelFromContact( 1033eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Contact data) { 1034eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("Build data items map"); 1035eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1036eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Map<String, List<DataItem>> dataItemsMap = new HashMap<>(); 10378bf96e78497ea9c8c893bcb357fc1e3175fb2e9bBrian Attwell 10388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final ResolveCache cache = ResolveCache.getInstance(this); 1039851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (RawContact rawContact : data.getRawContacts()) { 1040851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (DataItem dataItem : rawContact.getDataItems()) { 1041eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setRawContactId(rawContact.getId()); 1042eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1043851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final String mimeType = dataItem.getMimeType(); 1044eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (mimeType == null) continue; 1045eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 104647b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final AccountType accountType = rawContact.getAccountType(this); 104747b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final DataKind dataKind = AccountTypeManager.getInstance(this) 104847b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng .getKindOrFallback(accountType, mimeType); 1049eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataKind == null) continue; 1050cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1051eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setDataKind(dataKind); 1052b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1053eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean hasData = !TextUtils.isEmpty(dataItem.buildDataString(this, 1054eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataKind)); 1055899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 1056eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (isMimeExcluded(mimeType) || !hasData) continue; 1057edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1058eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos List<DataItem> dataItemListByType = dataItemsMap.get(mimeType); 1059eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItemListByType == null) { 1060eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType = new ArrayList<>(); 1061eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsMap.put(mimeType, dataItemListByType); 1062edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1063eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType.add(dataItem); 1064edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1065edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 10668a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 1067edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1068eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort within mimetypes"); 106916339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos /* 107016339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos * Sorting is a multi part step. The end result is to a have a sorted list of the most 1071eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * used data items, one per mimetype. Then, within each mimetype, the list of data items 1072eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * for that type is also sorted, based off of {super primary, primary, times used} in that 1073eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * order. 107416339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos */ 1075eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<List<DataItem>> dataItemsList = new ArrayList<>(); 1076eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (List<DataItem> mimeTypeDataItems : dataItemsMap.values()) { 1077eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Remove duplicate data items 1078eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collapser.collapseList(mimeTypeDataItems, this); 1079eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort within mimetype 1080eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(mimeTypeDataItems, mWithinMimeTypeDataItemComparator); 1081eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Add to the list of data item lists 1082eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsList.add(mimeTypeDataItems); 1083edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1084eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 1085edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1086eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort amongst mimetypes"); 1087eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort amongst mimetypes to bubble up the top data items for the contact card 1088eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(dataItemsList, mAmongstMimeTypeDataItemComparator); 1089eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 109016339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos 10916bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Trace.beginSection("cp2 data items to entries"); 10926bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 10936bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> contactCardEntries = new ArrayList<>(); 10946bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> aboutCardEntries = buildAboutCardEntries(dataItemsMap); 10956bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final MutableString aboutCardName = new MutableString(); 10966bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 10976bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell for (int i = 0; i < dataItemsList.size(); ++i) { 10986bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> dataItemsByMimeType = dataItemsList.get(i); 10996bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final DataItem topDataItem = dataItemsByMimeType.get(0); 11006bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (SORTED_ABOUT_CARD_MIMETYPES.contains(topDataItem.getMimeType())) { 11016bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // About card mimetypes are built in buildAboutCardEntries, skip here 11026bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell continue; 11036bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } else { 11046bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell List<Entry> contactEntries = dataItemsToEntries(dataItemsList.get(i), 11056bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell aboutCardName); 11066bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (contactEntries.size() > 0) { 11076bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell contactCardEntries.add(contactEntries); 11086bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 11096bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 11106bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 11116bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 11126bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Trace.endSection(); 11136bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 11146bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final Cp2DataCardModel dataModel = new Cp2DataCardModel(); 11156bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.customAboutCardName = aboutCardName.value; 11166bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.aboutCardEntries = aboutCardEntries; 11176bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.contactCardEntries = contactCardEntries; 11186bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.dataItemsMap = dataItemsMap; 11196bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell return dataModel; 11206bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 11216bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 11226bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 11236bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * Class used to hold the About card and Contact cards' data model that gets generated 11246bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * on a background thread. All data is from CP2. 11256bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 11266bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static class Cp2DataCardModel { 11276bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 11286bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * A map between a mimetype string and the corresponding list of data items. The data items 11296bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * are in sorted order using mWithinMimeTypeDataItemComparator. 11306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 11316bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public Map<String, List<DataItem>> dataItemsMap; 11326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public List<List<Entry>> aboutCardEntries; 11336bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public List<List<Entry>> contactCardEntries; 11346bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public String customAboutCardName; 11356bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 11366bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 11376bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static class MutableString { 11386bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public String value; 1139eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1140edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1141eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 1142eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Converts a {@link DataItem} into an {@link ExpandingEntryCardView.Entry} for display. 1143eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * If the {@link ExpandingEntryCardView.Entry} has no visual elements, null is returned. 11446bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * 11456bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * This runs on a background thread. This is set as static to avoid accidentally adding 11466bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * additional dependencies on unsafe things (like the Activity). 11476bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * 1148eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param dataItem The {@link DataItem} to convert. 1149eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return The {@link ExpandingEntryCardView.Entry}, or null if no visual elements are present. 1150eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 11516bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static Entry dataItemToEntry(DataItem dataItem, 11526bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Context context, Contact contactData, 11536bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final MutableString aboutCardName) { 1154eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable icon = null; 1155eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String header = null; 1156eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String subHeader = null; 1157eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable subHeaderIcon = null; 1158eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String text = null; 1159eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable textIcon = null; 1160eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Intent intent = null; 116148ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos boolean shouldApplyColor = true; 1162dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Drawable alternateIcon = null; 1163dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Intent alternateIntent = null; 1164dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos String alternateContentDescription = null; 1165eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEditable = false; 11662a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo entryContextMenuInfo = null; 116748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos Drawable thirdIcon = null; 116848fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos Intent thirdIntent = null; 116948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos String thirdContentDescription = null; 1170eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 11716bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell context = context.getApplicationContext(); 1172eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataKind kind = dataItem.getDataKind(); 1173eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1174eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItem instanceof ImDataItem) { 1175eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final ImDataItem im = (ImDataItem) dataItem; 11766bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell intent = ContactsUtils.buildImIntent(context, im).first; 1177eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEmail = im.isCreatedFromEmail(); 11787de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos final int protocol; 11797de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos if (!im.isProtocolValid()) { 11807de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos protocol = Im.PROTOCOL_CUSTOM; 11817de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } else { 11827de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol(); 11837de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } 11847de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos if (protocol == Im.PROTOCOL_CUSTOM) { 11857de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos // If the protocol is custom, display the "IM" entry header as well to distinguish 11867de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos // this entry from other ones 11876bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = context.getResources().getString(R.string.header_im_entry); 11886bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell subHeader = Im.getProtocolLabel(context.getResources(), protocol, 11897de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos im.getCustomProtocol()).toString(); 11907de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos text = im.getData(); 11917de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } else { 11926bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = Im.getProtocolLabel(context.getResources(), protocol, 11937de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos im.getCustomProtocol()).toString(); 11947de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos subHeader = im.getData(); 11957de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } 11962a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(im.getData(), header); 1197eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof OrganizationDataItem) { 1198eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final OrganizationDataItem organization = (OrganizationDataItem) dataItem; 11996bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = context.getResources().getString(R.string.header_organization_entry); 1200eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = organization.getCompany(); 12012a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header); 1202eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = organization.getTitle(); 1203eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NicknameDataItem) { 1204eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NicknameDataItem nickname = (NicknameDataItem) dataItem; 1205eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Build nickname entries 1206eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isNameRawContact = 12076bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell (contactData.getNameRawContactId() == dataItem.getRawContactId()); 1208eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1209eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean duplicatesTitle = 1210eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos isNameRawContact 12116bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell && contactData.getDisplayNameSource() == DisplayNameSources.NICKNAME; 1212eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1213eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!duplicatesTitle) { 12146bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = context.getResources().getString(R.string.header_nickname_entry); 1215eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = nickname.getName(); 12162a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header); 1217eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1218eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NoteDataItem) { 1219eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NoteDataItem note = (NoteDataItem) dataItem; 12206bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = context.getResources().getString(R.string.header_note_entry); 1221eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = note.getNote(); 12222a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header); 1223eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof WebsiteDataItem) { 1224eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final WebsiteDataItem website = (WebsiteDataItem) dataItem; 12256bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = context.getResources().getString(R.string.header_website_entry); 1226eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = website.getUrl(); 12272a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header); 1228eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos try { 12296bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final WebAddress webAddress = new WebAddress(website.buildDataString(context, 12306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell kind)); 1231eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString())); 1232eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ParseException e) { 12336bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Log.e(TAG, "Couldn't parse website: " + website.buildDataString(context, kind)); 1234eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1235eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EventDataItem) { 1236eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EventDataItem event = (EventDataItem) dataItem; 12376bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final String dataString = event.buildDataString(context, kind); 1238eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Calendar cal = DateUtils.parseDate(dataString, false); 1239eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (cal != null) { 1240eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Date nextAnniversary = 1241eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DateUtils.getNextAnnualDate(cal); 1242eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); 1243eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos builder.appendPath("time"); 1244eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos ContentUris.appendId(builder, nextAnniversary.getTime()); 1245eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW).setData(builder.build()); 1246eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 12476bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = context.getResources().getString(R.string.header_event_entry); 1248f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (event.hasKindTypeColumn(kind)) { 12496bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell subHeader = Event.getTypeLabel(context.getResources(), event.getKindTypeColumn(kind), 12507de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos event.getLabel()).toString(); 1251f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 12526bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell text = DateUtils.formatDate(context, dataString); 1253f848c49cac796f99549c8418f8d4e2469ac9f963Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(text, header); 1254eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof RelationDataItem) { 1255eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final RelationDataItem relation = (RelationDataItem) dataItem; 12566bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final String dataString = relation.buildDataString(context, kind); 1257eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(dataString)) { 1258eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SEARCH); 1259eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.putExtra(SearchManager.QUERY, dataString); 1260eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.setType(Contacts.CONTENT_TYPE); 1261eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 12626bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = context.getResources().getString(R.string.header_relation_entry); 1263eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = relation.getName(); 12642a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header); 1265f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (relation.hasKindTypeColumn(kind)) { 12666bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell text = Relation.getTypeLabel(context.getResources(), 12676bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell relation.getKindTypeColumn(kind), 1268f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos relation.getLabel()).toString(); 1269f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1270eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof PhoneDataItem) { 1271eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final PhoneDataItem phone = (PhoneDataItem) dataItem; 1272eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(phone.getNumber())) { 12736bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = phone.buildDataString(context, kind); 12742a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 12756bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell context.getResources().getString(R.string.phoneLabelsGroup)); 1276f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (phone.hasKindTypeColumn(kind)) { 12776bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell text = Phone.getTypeLabel(context.getResources(), phone.getKindTypeColumn(kind), 1278f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos phone.getLabel()).toString(); 1279f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 12806bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell icon = context.getResources().getDrawable(R.drawable.ic_phone_24dp); 12816bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (PhoneCapabilityTester.isPhone(context)) { 1282eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(phone.getNumber()); 128316339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1284dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIntent = new Intent(Intent.ACTION_SENDTO, 1285dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Uri.fromParts(CallUtil.SCHEME_SMSTO, phone.getNumber(), null)); 128648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos 12876bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell alternateIcon = context.getResources().getDrawable(R.drawable.ic_message_24dp); 12886bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell alternateContentDescription = context.getResources().getString(R.string.sms_other); 128948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos 129048fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos // Add video call button if supported 1291f764730a34da560db87206f9a48390d4c8085365Paul Soulos if (CallUtil.isVideoEnabled(context)) { 129248fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos thirdIcon = context.getResources().getDrawable(R.drawable.ic_videocam); 129348fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos thirdIntent = CallUtil.getVideoCallIntent(phone.getNumber(), 129448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY); 129548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos thirdContentDescription = 129648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos context.getResources().getString(R.string.description_video_call); 129748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos } 1298eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1299eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EmailDataItem) { 1300eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EmailDataItem email = (EmailDataItem) dataItem; 1301eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String address = email.getData(); 1302eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(address)) { 1303eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri mailUri = Uri.fromParts(CallUtil.SCHEME_MAILTO, address, null); 1304eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SENDTO, mailUri); 1305eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = email.getAddress(); 13062a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 13076bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell context.getResources().getString(R.string.emailLabelsGroup)); 1308f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (email.hasKindTypeColumn(kind)) { 13096bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell text = Email.getTypeLabel(context.getResources(), email.getKindTypeColumn(kind), 1310f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos email.getLabel()).toString(); 1311f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 13126bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell icon = context.getResources().getDrawable(R.drawable.ic_email_24dp); 1313eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1314eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredPostalDataItem) { 1315eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos StructuredPostalDataItem postal = (StructuredPostalDataItem) dataItem; 1316eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String postalAddress = postal.getFormattedAddress(); 1317eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(postalAddress)) { 1318eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress); 1319eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = postal.getFormattedAddress(); 13202a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 13216bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell context.getResources().getString(R.string.postalLabelsGroup)); 1322f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (postal.hasKindTypeColumn(kind)) { 13236bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell text = StructuredPostal.getTypeLabel(context.getResources(), 1324f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos postal.getKindTypeColumn(kind), postal.getLabel()).toString(); 1325f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 13266a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos alternateIntent = 13276a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos StructuredPostalUtils.getViewPostalAddressDirectionsIntent(postalAddress); 13286bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell alternateIcon = context.getResources().getDrawable(R.drawable.ic_directions_24dp); 13296bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell icon = context.getResources().getDrawable(R.drawable.ic_place_24dp); 1330eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1331eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof SipAddressDataItem) { 13326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (PhoneCapabilityTester.isSipPhone(context)) { 1333eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final SipAddressDataItem sip = (SipAddressDataItem) dataItem; 1334eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String address = sip.getSipAddress(); 1335eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(address)) { 1336eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri callUri = Uri.fromParts(CallUtil.SCHEME_SIP, address, null); 1337eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(callUri); 13381cda01b35a37f79b22e907cc970314b8c0a9e00cPaul Soulos header = address; 13392a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 13406bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell context.getResources().getString(R.string.phoneLabelsGroup)); 13411cda01b35a37f79b22e907cc970314b8c0a9e00cPaul Soulos if (sip.hasKindTypeColumn(kind)) { 13426bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell text = SipAddress.getTypeLabel(context.getResources(), 13436bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell sip.getKindTypeColumn(kind), sip.getLabel()).toString(); 13441cda01b35a37f79b22e907cc970314b8c0a9e00cPaul Soulos } 13456bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell icon = context.getResources().getDrawable(R.drawable.ic_dialer_sip_black_24dp); 134616339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1347edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1348eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredNameDataItem) { 1349eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String givenName = ((StructuredNameDataItem) dataItem).getGivenName(); 1350eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(givenName)) { 13516bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell aboutCardName.value = context.getResources().getString(R.string.about_card_title) + 13526bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell " " + givenName; 1353eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 13546bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell aboutCardName.value = context.getResources().getString(R.string.about_card_title); 1355eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1356eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1357eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Custom DataItem 13586bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = dataItem.buildDataStringForDisplay(context, kind); 1359eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = kind.typeColumn; 1360eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW); 136160e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, dataItem.getId()); 136260e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos intent.setDataAndType(uri, dataItem.getMimeType()); 1363e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 1364e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (intent != null) { 1365e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos final String mimetype = intent.getType(); 1366e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 1367e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos // Attempt to use known icons for known 3p types. Otherwise default to ResolveCache 1368e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos switch (mimetype) { 1369e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos case MIMETYPE_GPLUS_PROFILE: 1370e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (INTENT_DATA_GPLUS_PROFILE_ADD_TO_CIRCLE.equals( 1371e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos intent.getDataString())) { 13726bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell icon = context.getResources().getDrawable( 1373e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos R.drawable.ic_add_to_circles_black_24); 1374e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } else { 13756bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell icon = context.getResources().getDrawable(R.drawable.ic_google_plus_24dp); 1376e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1377e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos break; 1378e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos case MIMETYPE_HANGOUTS: 1379e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (INTENT_DATA_HANGOUTS_VIDEO.equals(intent.getDataString())) { 13806bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell icon = context.getResources().getDrawable(R.drawable.ic_hangout_video_24dp); 1381e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } else { 13826bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell icon = context.getResources().getDrawable(R.drawable.ic_hangout_24dp); 1383e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1384e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos break; 1385e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos default: 13862a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, mimetype); 13876bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell icon = ResolveCache.getInstance(context).getIcon( 1388e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos dataItem.getMimeType(), intent); 1389e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos // Call mutate to create a new Drawable.ConstantState for color filtering 1390e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (icon != null) { 1391e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos icon.mutate(); 1392e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 139348ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos shouldApplyColor = false; 1394e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1395e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1396eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1397b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1398eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (intent != null) { 1399eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Do not set the intent is there are no resolves 14006bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!PhoneCapabilityTester.isIntentRegistered(context, intent)) { 1401eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = null; 1402eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1403eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1404eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1405dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (alternateIntent != null) { 1406dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Do not set the alternate intent is there are no resolves 14076bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!PhoneCapabilityTester.isIntentRegistered(context, alternateIntent)) { 1408dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIntent = null; 1409dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1410dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1411dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Attempt to use package manager to find a suitable content description if needed 1412dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (TextUtils.isEmpty(alternateContentDescription)) { 14136bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell alternateContentDescription = getIntentResolveLabel(alternateIntent, context); 1414dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1415dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1416dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1417eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // If the Entry has no visual elements, return null 1418eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) && 1419eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeaderIcon == null && TextUtils.isEmpty(text) && textIcon == null) { 1420eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return null; 1421eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1422eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1423fa238949855fba3b28a57fad3d585b13e80362bbBrian Attwell // Ignore dataIds from the Me profile. 1424ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final int dataId = dataItem.getId() > Integer.MAX_VALUE ? 1425ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos -1 : (int) dataItem.getId(); 1426ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 1427dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon, intent, 1428dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIcon, alternateIntent, alternateContentDescription, shouldApplyColor, 142948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos isEditable, entryContextMenuInfo, thirdIcon, thirdIntent, thirdContentDescription); 1430eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1431eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 14326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private List<Entry> dataItemsToEntries(List<DataItem> dataItems, 14336bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell MutableString aboutCardTitleOut) { 1434eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> entries = new ArrayList<>(); 1435eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (DataItem dataItem : dataItems) { 14366bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final Entry entry = dataItemToEntry(dataItem, this, mContactData, aboutCardTitleOut); 1437eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (entry != null) { 1438eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos entries.add(entry); 1439eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1440eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1441eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return entries; 1442edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1443edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 14446bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static String getIntentResolveLabel(Intent intent, Context context) { 14456bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, 1446dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos PackageManager.MATCH_DEFAULT_ONLY); 1447dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1448dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Pick first match, otherwise best found 1449dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos ResolveInfo bestResolve = null; 1450dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos final int size = matches.size(); 1451dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (size == 1) { 1452dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos bestResolve = matches.get(0); 1453dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } else if (size > 1) { 14546bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell bestResolve = ResolveCache.getInstance(context).getBestResolve(intent, matches); 1455dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1456dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1457dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (bestResolve == null) { 1458dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos return null; 1459dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1460dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 14616bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell return String.valueOf(bestResolve.loadLabel(context.getPackageManager())); 1462dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1463dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1464edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 146531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * Asynchronously extract the most vibrant color from the PhotoView. Once extracted, 146631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms 146731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * on a Nexus 5. 146831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell */ 146931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell private void extractAndApplyTintFromPhotoViewAsynchronously() { 147031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell if (mScroller == null) { 147131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell return; 147231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 147331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell final Drawable imageViewDrawable = mPhotoView.getDrawable(); 1474faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell new AsyncTask<Void, Void, MaterialPalette>() { 147531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 1476faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell protected MaterialPalette doInBackground(Void... params) { 1477faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell 147831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell if (imageViewDrawable instanceof BitmapDrawable) { 14798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final Bitmap bitmap = ((BitmapDrawable) imageViewDrawable).getBitmap(); 1480faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell final int primaryColor = colorFromBitmap(bitmap); 1481faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell if (primaryColor != 0) { 1482a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor( 1483faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell primaryColor); 1484faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell } 14858a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 14868a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (imageViewDrawable instanceof LetterTileDrawable) { 1487faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell final int primaryColor = ((LetterTileDrawable) imageViewDrawable).getColor(); 1488a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(primaryColor); 148931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 1490a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return MaterialColorMapUtils.getDefaultPrimaryAndSecondaryColors(getResources()); 149131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 149231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 149331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 1494faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell protected void onPostExecute(MaterialPalette palette) { 1495faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell super.onPostExecute(palette); 14968571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (mHasComputedThemeColor) { 14978571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // If we had previously computed a theme color from the contact photo, 14988571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // then do not update the theme color. Changing the theme color several 14998571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // seconds after QC has started, as a result of an updated/upgraded photo, 15008571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // is a jarring experience. On the other hand, changing the theme color after 15018571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // a rotation or onNewIntent() is perfectly fine. 15028571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell return; 15038571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell } 15048571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // Check that the Photo has not changed. If it has changed, the new tint 15058571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // color needs to be extracted 15068571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (imageViewDrawable == mPhotoView.getDrawable()) { 15078571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = true; 1508faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell setThemeColor(palette); 150931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 151031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 151131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell }.execute(); 151231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 151331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 15144936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell /** 15154936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell * Examine how many white pixels are in the bitmap in order to determine whether or not 15164936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell * we need gradient overlays on top of the image. 15174936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell */ 15184936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell private void analyzeWhitenessOfPhotoAsynchronously() { 15194936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell final Drawable imageViewDrawable = mPhotoView.getDrawable(); 15204936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell new AsyncTask<Void, Void, Boolean>() { 15214936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell @Override 15224936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell protected Boolean doInBackground(Void... params) { 15234936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell if (imageViewDrawable instanceof BitmapDrawable) { 15244936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell final Bitmap bitmap = ((BitmapDrawable) imageViewDrawable).getBitmap(); 15254936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell return WhitenessUtils.isBitmapWhiteAtTopOrBottom(bitmap); 15264936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell } 15274936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell return !(imageViewDrawable instanceof LetterTileDrawable); 15284936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell } 15294936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell 15304936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell @Override 15314936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell protected void onPostExecute(Boolean isWhite) { 15324936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell super.onPostExecute(isWhite); 15334936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell mScroller.setUseGradient(isWhite); 15344936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell } 15354936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell }.execute(); 15364936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell } 15374936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell 1538faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell private void setThemeColor(MaterialPalette palette) { 15399b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // If the color is invalid, use the predefined default 1540faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell final int primaryColor = palette.mPrimaryColor; 1541faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mScroller.setHeaderTintColor(primaryColor); 1542faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mStatusBarColor = palette.mSecondaryColor; 15439b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell updateStatusBarColor(); 15448571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell 15459b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mColorFilter = 1546faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell new PorterDuffColorFilter(primaryColor, PorterDuff.Mode.SRC_ATOP); 1547faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mContactCard.setColorAndFilter(primaryColor, mColorFilter); 1548faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mRecentCard.setColorAndFilter(primaryColor, mColorFilter); 1549faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mAboutCard.setColorAndFilter(primaryColor, mColorFilter); 15509b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 15519b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 15528a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void updateStatusBarColor() { 15538a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller == null) { 15548a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 15558a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 15568a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int desiredStatusBarColor; 15578a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Only use a custom status bar color if QuickContacts touches the top of the viewport. 15588a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller.getScrollNeededToBeFullScreen() <= 0) { 15598a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = mStatusBarColor; 15608a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } else { 15618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = Color.TRANSPARENT; 15628a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 15638a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Animate to the new color. 1564847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor", 1565847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell getWindow().getStatusBarColor(), desiredStatusBarColor); 1566847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION); 1567847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.setEvaluator(new ArgbEvaluator()); 1568847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.start(); 15698a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 15708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 15718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int colorFromBitmap(Bitmap bitmap) { 15728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Author of Palette recommends using 24 colors when analyzing profile photos. 15738a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int NUMBER_OF_PALETTE_COLORS = 24; 15748a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final Palette palette = Palette.generate(bitmap, NUMBER_OF_PALETTE_COLORS); 1575a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell if (palette != null && palette.getVibrantSwatch() != null) { 1576a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell return palette.getVibrantSwatch().getRgb(); 15778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 15788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return 0; 15798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 15808a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1581b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) { 1582eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> entries = new ArrayList<>(); 1583b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos for (ContactInteraction interaction : interactions) { 1584ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos entries.add(new Entry(/* id = */ -1, 1585ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos interaction.getIcon(this), 1586b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewHeader(this), 1587b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewBody(this), 1588b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getBodyIcon(this), 1589b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewFooter(this), 1590b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getFooterIcon(this), 1591b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getIntent(), 1592dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIcon = */ null, 1593dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIntent = */ null, 1594dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateContentDescription = */ null, 159548ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos /* shouldApplyColor = */ true, 15962a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, 159748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* EntryContextMenuInfo = */ null, 159848fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, 159948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIntent = */ null, 160048fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdContentDescription = */ null)); 1601b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1602b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return entries; 1603b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1604b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1605eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<Contact> mLoaderContactCallbacks = 1606851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu new LoaderCallbacks<Contact>() { 1607cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 1608851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoaderReset(Loader<Contact> loader) { 1609405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos mContactData = null; 1610cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1611cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1612cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 1613851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoadFinished(Loader<Contact> loader, Contact data) { 16148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onLoadFinished()"); 16158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1616cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (isFinishing()) { 1617cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann return; 1618cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1619cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (data.isError()) { 1620cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann // This shouldn't ever happen, so throw an exception. The {@link ContactLoader} 1621cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann // should log the actual exception. 1622cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann throw new IllegalStateException("Failed to load contact", data.getException()); 1623cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1624cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (data.isNotFound()) { 16258a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mHasAlreadyBeenOpened) { 16268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell finish(); 16278a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } else { 16288a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri()); 16298a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, 16308a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.LENGTH_LONG).show(); 16318a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 1632cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann return; 1633cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1634cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1635b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos bindContactData(data); 1636cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 16378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 1638cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1639cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1640cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 1641851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public Loader<Contact> onCreateLoader(int id, Bundle args) { 1642cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (mLookupUri == null) { 1643cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann Log.wtf(TAG, "Lookup uri wasn't initialized. Loader was started too early"); 1644cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1645d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Load all contact data. We need loadGroupMetaData=true to determine whether the 1646d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // contact is invisible. If it is, we need to display an "Add to Contacts" MenuItem. 1647b2b435a944947fbf1965c3bb7c202a97f0273259Yorke Lee return new ContactLoader(getApplicationContext(), mLookupUri, 1648d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell true /*loadGroupMetaData*/, false /*loadInvitableAccountTypes*/, 16498571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell true /*postViewNotification*/, true /*computeFormattedPhoneNumber*/); 1650cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1651cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann }; 1652b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1653b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 1654b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onBackPressed() { 1655b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell if (mScroller != null) { 16568477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell if (!mIsExitAnimationInProgress) { 16578477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mScroller.scrollOffBottom(); 16588477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 1659b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } else { 1660b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell super.onBackPressed(); 1661b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 1662b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 1663b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 16648a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 16658a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void finish() { 16668a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.finish(); 16678a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 16688a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // override transitions to skip the standard window animations 16698a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell overridePendingTransition(0, 0); 16708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 16718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1672eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<List<ContactInteraction>> mLoaderInteractionsCallbacks = 1673b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos new LoaderCallbacks<List<ContactInteraction>>() { 1674b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1675b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 1676b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public Loader<List<ContactInteraction>> onCreateLoader(int id, Bundle args) { 1677b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Log.v(TAG, "onCreateLoader"); 1678b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Loader<List<ContactInteraction>> loader = null; 1679b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos switch (id) { 1680b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos case LOADER_SMS_ID: 1681b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Log.v(TAG, "LOADER_SMS_ID"); 1682b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos loader = new SmsInteractionsLoader( 1683b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos QuickContactActivity.this, 1684ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 1685b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos MAX_SMS_RETRIEVE); 1686b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos break; 1687899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos case LOADER_CALENDAR_ID: 1688899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Log.v(TAG, "LOADER_CALENDAR_ID"); 1689ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos final String[] emailsArray = args.getStringArray(KEY_LOADER_EXTRA_EMAILS); 1690ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos List<String> emailsList = null; 1691ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos if (emailsArray != null) { 1692ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos emailsList = Arrays.asList(args.getStringArray(KEY_LOADER_EXTRA_EMAILS)); 1693ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos } 1694899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos loader = new CalendarInteractionsLoader( 1695899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos QuickContactActivity.this, 1696ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos emailsList, 1697899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_FUTURE_CALENDAR_RETRIEVE, 1698899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_PAST_CALENDAR_RETRIEVE, 1699899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR, 1700899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR); 1701899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos break; 1702ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos case LOADER_CALL_LOG_ID: 1703ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Log.v(TAG, "LOADER_CALL_LOG_ID"); 1704ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos loader = new CallLogInteractionsLoader( 1705ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.this, 1706ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 1707ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos MAX_CALL_LOG_RETRIEVE); 1708b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1709b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return loader; 1710b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1711b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1712b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 1713b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoadFinished(Loader<List<ContactInteraction>> loader, 1714b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos List<ContactInteraction> data) { 1715b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.put(loader.getId(), data); 1716b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1717b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos if (isAllRecentDataLoaded()) { 1718b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos bindRecentData(); 1719b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1720b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1721b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1722b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 1723b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoaderReset(Loader<List<ContactInteraction>> loader) { 1724b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.remove(loader.getId()); 1725b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1726b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos }; 1727b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1728b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private boolean isAllRecentDataLoaded() { 1729b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return mRecentLoaderResults.size() == mRecentLoaderIds.length; 1730b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1731b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1732b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private void bindRecentData() { 1733eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<ContactInteraction> allInteractions = new ArrayList<>(); 1734b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) { 1735b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos allInteractions.addAll(loaderInteractions); 1736b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1737b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1738b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos // Sort the interactions by most recent 1739b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Collections.sort(allInteractions, new Comparator<ContactInteraction>() { 1740b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 1741b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public int compare(ContactInteraction a, ContactInteraction b) { 1742b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return a.getInteractionDate() >= b.getInteractionDate() ? -1 : 1; 1743b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1744b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos }); 1745b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 174697ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos // Wrap each interaction in its own list so that an icon is displayed for each entry 174760e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos List<List<Entry>> interactionsWrapper = new ArrayList<>(); 174897ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos for (Entry contactInteraction : contactInteractionsToEntries(allInteractions)) { 174997ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos List<Entry> entryListWrapper = new ArrayList<>(1); 175097ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos entryListWrapper.add(contactInteraction); 175197ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos interactionsWrapper.add(entryListWrapper); 175297ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos } 1753b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos if (allInteractions.size() > 0) { 175460e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos mRecentCard.initialize(interactionsWrapper, 1755b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN, 1756c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos /* isExpanded = */ mRecentCard.isExpanded(), /* isAlwaysExpanded = */ false, 17570cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mExpandingEntryCardViewListener, mScroller); 1758b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setVisibility(View.VISIBLE); 1759b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1760eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1761eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // About card is initialized along with the contact card, but since it appears after 1762eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // the recent card in the UI, we hold off until making it visible until the recent card 1763eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // is also ready to avoid stuttering. 1764eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (mAboutCard.shouldShow()) { 1765eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setVisibility(View.VISIBLE); 1766eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1767eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setVisibility(View.GONE); 1768eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1769b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 17708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 17718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 17728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onStop() { 17738a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onStop(); 17748a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 17758a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mEntriesAndActionsTask != null) { 17768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Once the activity is stopped, we will no longer want to bind mEntriesAndActionsTask's 17778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // results on the UI thread. In some circumstances Activities are killed without 17788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // onStop() being called. This is not a problem, because in these circumstances 17798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the entire process will be killed. 17808a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.cancel(/* mayInterruptIfRunning = */ false); 17818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 17828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 178323889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos 178423889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos /** 1785d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Returns true if it is possible to edit the current contact. 1786d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 1787d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private boolean isContactEditable() { 1788d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 1789d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1790d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1791a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell /** 1792a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell * Returns true if it is possible to share the current contact. 1793a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell */ 1794a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell private boolean isContactShareable() { 1795a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 1796a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell } 1797a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 17986095369885edcca566a812b551886e29c7ff8039Brian Attwell private Intent getEditContactIntent() { 179963176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell final Intent intent = new Intent(Intent.ACTION_EDIT, mContactData.getLookupUri()); 1800d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactLoader.cacheResult(); 1801d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 18026095369885edcca566a812b551886e29c7ff8039Brian Attwell return intent; 18036095369885edcca566a812b551886e29c7ff8039Brian Attwell } 18046095369885edcca566a812b551886e29c7ff8039Brian Attwell 18056095369885edcca566a812b551886e29c7ff8039Brian Attwell private void editContact() { 1806a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 18076095369885edcca566a812b551886e29c7ff8039Brian Attwell startActivityForResult(getEditContactIntent(), REQUEST_CODE_CONTACT_EDITOR_ACTIVITY); 1808d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1809d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1810d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void toggleStar(MenuItem starredMenuItem) { 1811d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Make sure there is a contact 181263176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell if (mContactData != null) { 1813d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Read the current starred value from the UI instead of using the last 1814d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // loaded state. This allows rapid tapping without writing the same 1815d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // value several times 1816d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final boolean isStarred = starredMenuItem.isChecked(); 1817d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1818d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // To improve responsiveness, swap out the picture (and tag) in the UI already 1819333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, 1820d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.isDirectoryEntry(), mContactData.isUserProfile(), 1821d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell !isStarred); 1822d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1823d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Now perform the real save 1824eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Intent intent = ContactSaveService.createSetStarredIntent( 182563176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell QuickContactActivity.this, mContactData.getLookupUri(), !isStarred); 1826d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell startService(intent); 182735ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell 182835ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell final CharSequence accessibilityText = !isStarred 182935ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell ? getResources().getText(R.string.description_action_menu_add_star) 183035ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell : getResources().getText(R.string.description_action_menu_remove_star); 183135ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell // Accessibility actions need to have an associated view. We can't access the MenuItem's 183235ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell // underlying view, so put this accessibility action on the root view. 183335ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell mScroller.announceForAccessibility(accessibilityText); 1834d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1835d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1836d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1837752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** 1838752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell * Calls into the contacts provider to get a pre-authorized version of the given URI. 1839752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell */ 1840752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private Uri getPreAuthorizedUri(Uri uri) { 1841752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Bundle uriBundle = new Bundle(); 1842752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell uriBundle.putParcelable(ContactsContract.Authorization.KEY_URI_TO_AUTHORIZE, uri); 1843752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Bundle authResponse = getContentResolver().call( 1844752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell ContactsContract.AUTHORITY_URI, 1845752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell ContactsContract.Authorization.AUTHORIZATION_METHOD, 1846752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell null, 1847752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell uriBundle); 1848752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell if (authResponse != null) { 1849752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return (Uri) authResponse.getParcelable( 1850752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell ContactsContract.Authorization.KEY_AUTHORIZED_URI); 1851752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } else { 1852752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return uri; 1853752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1854752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 18552d150da246632b1649999cfabed776133b097775Brian Attwell 1856752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void shareContact() { 1857752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final String lookupKey = mContactData.getLookupKey(); 1858752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); 1859752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell if (mContactData.isUserProfile()) { 1860752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // User is sharing the profile. We don't want to force the receiver to have 1861752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // the highly-privileged READ_PROFILE permission, so we need to request a 1862752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // pre-authorized URI from the provider. 1863752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell shareUri = getPreAuthorizedUri(shareUri); 1864752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1865752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1866752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent intent = new Intent(Intent.ACTION_SEND); 1867752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell intent.setType(Contacts.CONTENT_VCARD_TYPE); 1868752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell intent.putExtra(Intent.EXTRA_STREAM, shareUri); 1869752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1870752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Launch chooser to share contact via 1871752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final CharSequence chooseTitle = getText(R.string.share_via); 1872752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent chooseIntent = Intent.createChooser(intent, chooseTitle); 1873752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1874752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell try { 1875a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 1876752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell this.startActivity(chooseIntent); 1877eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ActivityNotFoundException ex) { 1878752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show(); 1879752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1880752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1881752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1882752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** 1883752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell * Creates a launcher shortcut with the current contact. 1884752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell */ 1885752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void createLauncherShortcutWithContact() { 1886752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this, 1887752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell new OnShortcutIntentCreatedListener() { 1888752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1889752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell @Override 1890752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) { 1891752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Broadcast the shortcutIntent to the launcher to create a 1892752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // shortcut to this contact 1893752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); 1894752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell QuickContactActivity.this.sendBroadcast(shortcutIntent); 1895752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1896752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Send a toast to give feedback to the user that a shortcut to this 1897752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // contact was added to the launcher. 1898752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.makeText(QuickContactActivity.this, 1899752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell R.string.createContactShortcutSuccessful, 1900752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.LENGTH_SHORT).show(); 1901752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1902752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1903752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell }); 190463176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell builder.createContactShortcutIntent(mContactData.getLookupUri()); 1905752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1906752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1907d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 1908d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onCreateOptionsMenu(Menu menu) { 1909eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final MenuInflater inflater = getMenuInflater(); 1910d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell inflater.inflate(R.menu.quickcontact, menu); 1911d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 1912d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1913d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1914d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 1915d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onPrepareOptionsMenu(Menu menu) { 1916d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mContactData != null) { 1917d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem starredMenuItem = menu.findItem(R.id.menu_star); 1918333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, 1919d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.isDirectoryEntry(), mContactData.isUserProfile(), 1920d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.getStarred()); 1921a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 1922d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Configure edit MenuItem 1923d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem editMenuItem = menu.findItem(R.id.menu_edit); 1924d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(true); 1925d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData) || InvisibleContactUtil 1926d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell .isInvisibleAndAddable(mContactData, this)) { 192730cfd121ad8c8adb83cf417ff1d40a8ba1e3761dBrian Attwell editMenuItem.setIcon(R.drawable.ic_person_add_tinted_24dp); 19282e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell editMenuItem.setTitle(R.string.menu_add_contact); 1929d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 1930d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setIcon(R.drawable.ic_create_24dp); 19312e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell editMenuItem.setTitle(R.string.menu_editContact); 1932d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else { 1933d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(false); 1934d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1935a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 1936a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell final MenuItem shareMenuItem = menu.findItem(R.id.menu_share); 1937a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell shareMenuItem.setVisible(isContactShareable()); 1938a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 19398a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return true; 1940d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 19418a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return false; 1942d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1943d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1944d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 1945d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onOptionsItemSelected(MenuItem item) { 1946d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell switch (item.getItemId()) { 1947d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell case R.id.menu_star: 1948d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell toggleStar(item); 1949d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 1950d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell case R.id.menu_edit: 1951d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData)) { 1952d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell DirectoryContactUtil.addToMyContacts(mContactData, this, getFragmentManager(), 1953d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener); 1954d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { 1955d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell InvisibleContactUtil.addToDefaultGroup(mContactData, this); 1956d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 1957d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editContact(); 1958d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1959d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 1960752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell case R.id.menu_share: 1961752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell shareContact(); 1962752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return true; 1963752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell case R.id.menu_create_contact_shortcut: 1964752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell createLauncherShortcutWithContact(); 1965752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return true; 1966d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell default: 1967d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return super.onOptionsItemSelected(item); 1968d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 196923889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos } 1970edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann} 1971