QuickContactActivity.java revision a42ef76251778161d27bc07db214b8c81720e476
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; 28edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.Intent; 29cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.content.Loader; 30dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulosimport android.content.pm.PackageManager; 31dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulosimport android.content.pm.ResolveInfo; 3231b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.Bitmap; 338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.Color; 3470e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chenimport android.graphics.Point; 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; 71eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.util.Pair; 722a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu; 732a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu.ContextMenuInfo; 74d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.Menu; 75d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.MenuInflater; 76eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.view.MenuItem; 77f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chenimport android.view.MotionEvent; 78edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View; 79edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View.OnClickListener; 802a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.View.OnCreateContextMenuListener; 8110d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawaimport android.view.WindowManager; 82edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.widget.ImageView; 83edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.widget.Toast; 84d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.widget.Toolbar; 85edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 8672b3ab1d8a62f228a540b05f4ed6373e494c7d72Christine Chenimport com.android.contacts.ContactSaveService; 87d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.ContactsActivity; 882d150da246632b1649999cfabed776133b097775Brian Attwellimport com.android.contacts.NfcHandler; 89e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.R; 90eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.CallUtil; 912a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.common.ClipboardUtils; 92eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.Collapser; 93eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.ContactsUtils; 94d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.common.editor.SelectAccountDialogFragment; 9570e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chenimport com.android.contacts.common.interactions.TouchPointManager; 9631b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport com.android.contacts.common.lettertiles.LetterTileDrawable; 97752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder; 98752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder.OnShortcutIntentCreatedListener; 990d5588da244d0992c3ff8f25d0875fdf95a8c644Chiao Chengimport com.android.contacts.common.model.AccountTypeManager; 100cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.Contact; 101cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.ContactLoader; 102cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.RawContact; 103428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.account.AccountType; 104d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.common.model.account.AccountWithDataSet; 105cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.DataItem; 106428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.dataitem.DataKind; 107cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.EmailDataItem; 108eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.EventDataItem; 109cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.ImDataItem; 110eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NicknameDataItem; 111eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NoteDataItem; 112eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.OrganizationDataItem; 113b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.common.model.dataitem.PhoneDataItem; 114eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.RelationDataItem; 115eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.SipAddressDataItem; 116eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredNameDataItem; 117eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredPostalDataItem; 118eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.WebsiteDataItem; 119eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.util.DateUtils; 120faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwellimport com.android.contacts.common.util.MaterialColorMapUtils; 121faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwellimport com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette; 122d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwellimport com.android.contacts.common.util.ViewUtil; 123333091ae754ddfc25714c14b9b89534be24379f9Paul Soulosimport com.android.contacts.detail.ContactDisplayUtils; 124899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport com.android.contacts.interactions.CalendarInteractionsLoader; 125ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulosimport com.android.contacts.interactions.CallLogInteractionsLoader; 1268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport com.android.contacts.interactions.ContactDeletionInteraction; 127b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.ContactInteraction; 128b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.SmsInteractionsLoader; 1292d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.Entry; 1302a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryContextMenuInfo; 1312ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryTag; 132e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwellimport com.android.contacts.quickcontact.ExpandingEntryCardView.ExpandingEntryCardViewListener; 133e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.util.ImageViewDrawableSetter; 134eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.PhoneCapabilityTester; 135b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.util.SchedulingUtils; 136eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.StructuredPostalUtils; 137b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller; 138b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener; 13970e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen 140e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.google.common.base.Preconditions; 141e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.google.common.collect.Lists; 142e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng 1432d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport java.util.ArrayList; 144899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport java.util.Arrays; 145eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Calendar; 146b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Collections; 147b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Comparator; 148eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Date; 149edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.HashMap; 150edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.List; 151b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Map; 152edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 153edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/** 154edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Mostly translucent {@link Activity} that shows QuickContact dialog. It loads 155edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * data asynchronously, and then shows a popup with details centered around 156edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * {@link Intent#getSourceBounds()}. 157edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 158d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellpublic class QuickContactActivity extends ContactsActivity { 1598a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1608a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell /** 1618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * QuickContacts immediately takes up the full screen. All possible information is shown. 1628a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * This value for {@link android.provider.ContactsContract.QuickContact#EXTRA_MODE} 1638a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * should only be used by the Contacts app. 1648a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell */ 1658a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public static final int MODE_FULLY_EXPANDED = 4; 1668a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 167edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String TAG = "QuickContact"; 168edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1699b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final String KEY_THEME_COLOR = "theme_color"; 1709b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 1719b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final int ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION = 150; 1728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private static final int REQUEST_CODE_CONTACT_EDITOR_ACTIVITY = 1; 173bfa9442453c1d86e11e56702f9b8ef0e8e0da0b1Brian Attwell private static final int SCRIM_COLOR = Color.argb(0xC8, 0, 0, 0); 174ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos private static final String MIMETYPE_SMS = "vnd.android-dir/mms-sms"; 175dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 176752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** This is the Intent action to install a shortcut in the launcher. */ 177752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private static final String ACTION_INSTALL_SHORTCUT = 178752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell "com.android.launcher.action.INSTALL_SHORTCUT"; 179edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 180edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @SuppressWarnings("deprecation") 181edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String LEGACY_AUTHORITY = android.provider.Contacts.AUTHORITY; 182edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 183e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String MIMETYPE_GPLUS_PROFILE = 184e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos "vnd.android.cursor.item/vnd.googleplus.profile"; 185e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String INTENT_DATA_GPLUS_PROFILE_ADD_TO_CIRCLE = "Add to circle"; 186e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String MIMETYPE_HANGOUTS = 187e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos "vnd.android.cursor.item/vnd.googleplus.profile.comm"; 188e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String INTENT_DATA_HANGOUTS_VIDEO = "Start video call"; 189e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 190edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private Uri mLookupUri; 191edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private String[] mExcludeMimes; 1928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mExtraMode; 1938a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mStatusBarColor; 1948a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private boolean mHasAlreadyBeenOpened; 195edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1966219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee private ImageView mPhotoView; 1970d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell private View mTransparentView; 198eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mContactCard; 1996095369885edcca566a812b551886e29c7ff8039Brian Attwell private ExpandingEntryCardView mNoContactDetailsCard; 200b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private ExpandingEntryCardView mRecentCard; 201eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mAboutCard; 202eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 203eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * This list contains all the {@link DataItem}s. Each nested list contains all data items of a 204eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * specific mimetype in sorted order, using mWithinMimeTypeDataItemComparator. The mimetype 205eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * lists are sorted using mAmongstMimeTypeDataItemComparator. 206eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 207eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private List<List<DataItem>> mDataItemsList; 208eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 209eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * A map between a mimetype string and the corresponding list of data items. The data items 210eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * are in sorted order using mWithinMimeTypeDataItemComparator. 211eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 212eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private Map<String, List<DataItem>> mDataItemsMap; 213b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private MultiShrinkScroller mScroller; 214d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private SelectAccountDialogFragmentListener mSelectAccountFragmentListener; 215eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private AsyncTask<Void, Void, Pair<List<List<DataItem>>, Map<String, List<DataItem>>>> 216eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mEntriesAndActionsTask; 217f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell /** 218f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * This scrim's opacity is controlled in two different ways. 1) Before the initial entrance 219f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * animation finishes, the opacity is animated by a value animator. This is designed to 220f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * distract the user from the length of the initial loading time. 2) After the initial 221f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * entrance animation, the opacity is directly related to scroll position. 222f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell */ 2239b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private ColorDrawable mWindowScrim; 224f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell private boolean mIsEntranceAnimationFinished; 225a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell private MaterialColorMapUtils mMaterialColorMapUtils; 2268477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell private boolean mIsExitAnimationInProgress; 2278571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell private boolean mHasComputedThemeColor; 228edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 229a42ef76251778161d27bc07db214b8c81720e476Paul Soulos /** 230a42ef76251778161d27bc07db214b8c81720e476Paul Soulos * Used to stop the ExpandingEntry cards from adjusting between an entry click and the intent 231a42ef76251778161d27bc07db214b8c81720e476Paul Soulos * being launched. 232a42ef76251778161d27bc07db214b8c81720e476Paul Soulos */ 233a42ef76251778161d27bc07db214b8c81720e476Paul Soulos private boolean mHasIntentLaunched; 234a42ef76251778161d27bc07db214b8c81720e476Paul Soulos 2356cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee private Contact mContactData; 2369815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann private ContactLoader mContactLoader; 2379b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private PorterDuffColorFilter mColorFilter; 2389815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann 2399758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter(); 2409758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus 241edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 242cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * {@link #LEADING_MIMETYPES} is used to sort MIME-types. 243edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 244edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * <p>The MIME-types in {@link #LEADING_MIMETYPES} appear in the front of the dialog, 245edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * in the order specified here.</p> 246edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 247edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final List<String> LEADING_MIMETYPES = Lists.newArrayList( 248cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos Phone.CONTENT_ITEM_TYPE, SipAddress.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE, 249405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos StructuredPostal.CONTENT_ITEM_TYPE); 250edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 251a153dba33c2152332c5706178a367f52b0550723Paul Soulos private static final List<String> SORTED_ABOUT_CARD_MIMETYPES = Lists.newArrayList( 252a153dba33c2152332c5706178a367f52b0550723Paul Soulos Nickname.CONTENT_ITEM_TYPE, 253a153dba33c2152332c5706178a367f52b0550723Paul Soulos // Phonetic name is inserted after nickname if it is available. 254a153dba33c2152332c5706178a367f52b0550723Paul Soulos // No mimetype for phonetic name exists. 255a153dba33c2152332c5706178a367f52b0550723Paul Soulos Website.CONTENT_ITEM_TYPE, 256a153dba33c2152332c5706178a367f52b0550723Paul Soulos Organization.CONTENT_ITEM_TYPE, 257a153dba33c2152332c5706178a367f52b0550723Paul Soulos Event.CONTENT_ITEM_TYPE, 258a153dba33c2152332c5706178a367f52b0550723Paul Soulos Relation.CONTENT_ITEM_TYPE, 259a153dba33c2152332c5706178a367f52b0550723Paul Soulos Im.CONTENT_ITEM_TYPE, 260a153dba33c2152332c5706178a367f52b0550723Paul Soulos GroupMembership.CONTENT_ITEM_TYPE, 261a153dba33c2152332c5706178a367f52b0550723Paul Soulos Identity.CONTENT_ITEM_TYPE, 262a153dba33c2152332c5706178a367f52b0550723Paul Soulos Note.CONTENT_ITEM_TYPE); 263eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 264b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background contact loader */ 265b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_CONTACT_ID = 0; 266b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 267ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final String KEY_LOADER_EXTRA_PHONES = 268ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_PHONES"; 269ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 270b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background Sms Loader */ 271b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_SMS_ID = 1; 272b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int MAX_SMS_RETRIEVE = 3; 273ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 274ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the back Calendar Loader */ 275899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int LOADER_CALENDAR_ID = 2; 276ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final String KEY_LOADER_EXTRA_EMAILS = 277ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_EMAILS"; 278899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_PAST_CALENDAR_RETRIEVE = 3; 279899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_FUTURE_CALENDAR_RETRIEVE = 3; 280899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 281899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 180L * 24L * 60L * 60L * 1000L /* 180 days */; 282899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 283899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 36L * 60L * 60L * 1000L /* 36 hours */; 284899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 285ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the background Call Log Loader */ 286ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int LOADER_CALL_LOG_ID = 3; 287ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int MAX_CALL_LOG_RETRIEVE = 3; 2886095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int MIN_NUM_CONTACT_ENTRIES_SHOWN = 3; 2896095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN = 3; 2906095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int CARD_ENTRY_ID_EDIT_CONTACT = -2; 291ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 292ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 293ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int[] mRecentLoaderIds = new int[]{ 294ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_SMS_ID, 295ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALENDAR_ID, 296ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID}; 297a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos private Map<Integer, List<ContactInteraction>> mRecentLoaderResults = new HashMap<>(); 298b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 299d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private static final String FRAGMENT_TAG_SELECT_ACCOUNT = "select_account_fragment"; 3006cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee 3012d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos final OnClickListener mEntryClickHandler = new OnClickListener() { 3022d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos @Override 3032d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos public void onClick(View v) { 3042ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final Object entryTagObject = v.getTag(); 3052ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos if (entryTagObject == null || !(entryTagObject instanceof EntryTag)) { 3062ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos Log.w(TAG, "EntryTag was not used correctly"); 3076095369885edcca566a812b551886e29c7ff8039Brian Attwell return; 3086095369885edcca566a812b551886e29c7ff8039Brian Attwell } 3092ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final EntryTag entryTag = (EntryTag) entryTagObject; 3102ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final Intent intent = entryTag.getIntent(); 3112ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final int dataId = entryTag.getId(); 3122ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos 3132ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos if (dataId == CARD_ENTRY_ID_EDIT_CONTACT) { 3142ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos editContact(); 3152d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos return; 3162d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 317ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 318ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Default to USAGE_TYPE_CALL. Usage is summed among all types for sorting each data id 319ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // so the exact usage type is not necessary in all cases 320ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos String usageType = DataUsageFeedback.USAGE_TYPE_CALL; 321ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 32220bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos final Uri intentUri = intent.getData(); 32320bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos if ((intentUri != null && intentUri.getScheme() != null && 32420bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos intentUri.getScheme().equals(CallUtil.SCHEME_SMSTO)) || 325ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos (intent.getType() != null && intent.getType().equals(MIMETYPE_SMS))) { 326ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos usageType = DataUsageFeedback.USAGE_TYPE_SHORT_TEXT; 327ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 328ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 329ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Data IDs start at 1 so anything less is invalid 330ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (dataId > 0) { 33120bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos final Uri dataUsageUri = DataUsageFeedback.FEEDBACK_URI.buildUpon() 332ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendPath(String.valueOf(dataId)) 333ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, usageType) 334ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .build(); 335ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final boolean successful = getContentResolver().update( 33620bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos dataUsageUri, new ContentValues(), null, null) > 0; 337ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (!successful) { 338ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Log.w(TAG, "DataUsageFeedback increment failed"); 339ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 340ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } else { 341ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Log.w(TAG, "Invalid Data ID"); 342ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 343ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 34470e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen // Pass the touch point through the intent for use in the InCallUI 34570e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen if (Intent.ACTION_CALL.equals(intent.getAction())) { 34670e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen final Point touchPoint = TouchPointManager.getInstance().getPoint(); 34770e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen 34870e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen if (touchPoint.x != 0 || touchPoint.y != 0) { 34970e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen Bundle extras = new Bundle(); 35070e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen extras.putParcelable(TouchPointManager.TOUCH_POINT, touchPoint); 35170e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen intent.putExtra(TelecommManager.EXTRA_OUTGOING_CALL_EXTRAS, extras); 35270e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen } 35370e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen } 35470e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen 355a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 356ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos startActivity(intent); 3572d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 3582d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos }; 3592d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos 360e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell final ExpandingEntryCardViewListener mExpandingEntryCardViewListener 361e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell = new ExpandingEntryCardViewListener() { 362e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell @Override 363e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell public void onCollapse(int heightDelta) { 364e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell mScroller.prepareForShrinkingScrollChild(heightDelta); 365e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell } 3660cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos 3670cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos @Override 3680cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos public void onExpand(int heightDelta) { 3690cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mScroller.prepareForExpandingScrollChild(); 3700cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos } 371e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell }; 372e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell 3732a4207fb39330e840436215c896cde911489e111Paul Soulos private final OnCreateContextMenuListener mEntryContextMenuListener = 3742a4207fb39330e840436215c896cde911489e111Paul Soulos new OnCreateContextMenuListener() { 3752a4207fb39330e840436215c896cde911489e111Paul Soulos @Override 3762a4207fb39330e840436215c896cde911489e111Paul Soulos public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 3772a4207fb39330e840436215c896cde911489e111Paul Soulos if (menuInfo == null) { 3782a4207fb39330e840436215c896cde911489e111Paul Soulos return; 3792a4207fb39330e840436215c896cde911489e111Paul Soulos } 3802a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo info = (EntryContextMenuInfo) menuInfo; 3812a4207fb39330e840436215c896cde911489e111Paul Soulos menu.setHeaderTitle(info.getCopyText()); 3822a4207fb39330e840436215c896cde911489e111Paul Soulos menu.add(R.string.copy_text); 3832a4207fb39330e840436215c896cde911489e111Paul Soulos } 3842a4207fb39330e840436215c896cde911489e111Paul Soulos }; 3852a4207fb39330e840436215c896cde911489e111Paul Soulos 3862a4207fb39330e840436215c896cde911489e111Paul Soulos @Override 3872a4207fb39330e840436215c896cde911489e111Paul Soulos public boolean onContextItemSelected(MenuItem item) { 3882a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo menuInfo; 3892a4207fb39330e840436215c896cde911489e111Paul Soulos try { 3902a4207fb39330e840436215c896cde911489e111Paul Soulos menuInfo = (EntryContextMenuInfo) item.getMenuInfo(); 3912a4207fb39330e840436215c896cde911489e111Paul Soulos } catch (ClassCastException e) { 3922a4207fb39330e840436215c896cde911489e111Paul Soulos Log.e(TAG, "bad menuInfo", e); 3932a4207fb39330e840436215c896cde911489e111Paul Soulos return false; 3942a4207fb39330e840436215c896cde911489e111Paul Soulos } 3952a4207fb39330e840436215c896cde911489e111Paul Soulos 3962a4207fb39330e840436215c896cde911489e111Paul Soulos ClipboardUtils.copyText(this, menuInfo.getCopyLabel(), menuInfo.getCopyText(), true); 3972a4207fb39330e840436215c896cde911489e111Paul Soulos return true; 3982a4207fb39330e840436215c896cde911489e111Paul Soulos } 3992a4207fb39330e840436215c896cde911489e111Paul Soulos 400d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell /** 401d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Headless fragment used to handle account selection callbacks invoked from 402d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * {@link DirectoryContactUtil}. 403d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 404d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public static class SelectAccountDialogFragmentListener extends Fragment 405d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell implements SelectAccountDialogFragment.Listener { 406d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 407d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private QuickContactActivity mQuickContactActivity; 408d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 409d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public SelectAccountDialogFragmentListener() {} 410d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 411d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 412d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void onAccountChosen(AccountWithDataSet account, Bundle extraArgs) { 413d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell DirectoryContactUtil.createCopy(mQuickContactActivity.mContactData.getContentValues(), 414d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell account, mQuickContactActivity); 415d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 416d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 417d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 418d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void onAccountSelectorCancelled() {} 419d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 420d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell /** 421d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Set the parent activity. Since rotation can cause this fragment to be used across 422d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * more than one activity instance, we need to explicitly set this value instead 423d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * of making this class non-static. 424d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 425d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void setQuickContactActivity(QuickContactActivity quickContactActivity) { 426d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mQuickContactActivity = quickContactActivity; 427d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 428d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 429d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 430b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell final MultiShrinkScrollerListener mMultiShrinkScrollerListener 431b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell = new MultiShrinkScrollerListener() { 432b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 433b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onScrolledOffBottom() { 434f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell finish(); 435b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 4368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 4378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 4388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onEnterFullscreen() { 4398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 4408a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 4418a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 4428a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 4438a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onExitFullscreen() { 4448a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 4458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 4468477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 4478477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 4488477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell public void onStartScrollOffBottom() { 4498477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mIsExitAnimationInProgress = true; 4508477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 4518477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 4528477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 453f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void onEntranceAnimationDone() { 454f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = true; 455f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 456f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 457f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell @Override 458f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void onTransparentViewHeightChange(float ratio) { 459f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell if (mIsEntranceAnimationFinished) { 460f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mWindowScrim.setAlpha((int) (0xFF * ratio)); 4618477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 4628477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 463b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell }; 464b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 465eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 466eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 467eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Data items are compared to the same mimetype based off of three qualities: 468eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 1. Super primary 469eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 2. Primary 470eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 3. Times used 471eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 472eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<DataItem> mWithinMimeTypeDataItemComparator = 473eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<DataItem>() { 474eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 475eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(DataItem lhs, DataItem rhs) { 476eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!lhs.getMimeType().equals(rhs.getMimeType())) { 477eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Log.wtf(TAG, "Comparing DataItems with different mimetypes lhs.getMimeType(): " + 478eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getMimeType() + " rhs.getMimeType(): " + rhs.getMimeType()); 479eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 480eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 481eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 482eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lhs.isSuperPrimary()) { 483eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 484eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (rhs.isSuperPrimary()) { 485eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 486eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lhs.isPrimary() && !rhs.isPrimary()) { 487eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 488eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (!lhs.isPrimary() && rhs.isPrimary()) { 489eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 490eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 491eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = 492eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 493eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = 494eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 495eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 496eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return rhsTimesUsed - lhsTimesUsed; 497eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 498eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 499eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 500eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 501cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos /** 502cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * Sorts among different mimetypes based off: 503cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * 1. Times used 504cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * 2. Last time used 505cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * 3. Statically defined 506cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos */ 507eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<List<DataItem>> mAmongstMimeTypeDataItemComparator = 508eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<List<DataItem>> () { 509eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 510eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(List<DataItem> lhsList, List<DataItem> rhsList) { 511eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataItem lhs = lhsList.get(0); 512eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataItem rhs = rhsList.get(0); 513eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 514eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 515eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int timesUsedDifference = rhsTimesUsed - lhsTimesUsed; 516eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (timesUsedDifference != 0) { 517eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return timesUsedDifference; 518eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 519eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 520eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lhsLastTimeUsed = 521eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getLastTimeUsed() == null ? 0 : lhs.getLastTimeUsed(); 522eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long rhsLastTimeUsed = 523eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getLastTimeUsed() == null ? 0 : rhs.getLastTimeUsed(); 524eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lastTimeUsedDifference = rhsLastTimeUsed - lhsLastTimeUsed; 525eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lastTimeUsedDifference > 0) { 526eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 527eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lastTimeUsedDifference < 0) { 528eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 529eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 530eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 531eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Times used and last time used are the same. Resort to statically defined. 532eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String lhsMimeType = lhs.getMimeType(); 533eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String rhsMimeType = rhs.getMimeType(); 534eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (String mimeType : LEADING_MIMETYPES) { 535eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lhsMimeType.equals(mimeType)) { 536eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 537eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (rhsMimeType.equals(mimeType)) { 538eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 539eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 540eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 541eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 542eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 543eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 544eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 545edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @Override 546f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen public boolean dispatchTouchEvent(MotionEvent ev) { 547f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen if (ev.getAction() == MotionEvent.ACTION_DOWN) { 548f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); 549f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen } 550f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen return super.dispatchTouchEvent(ev); 551f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen } 552f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen 553f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen @Override 5548a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onCreate(Bundle savedInstanceState) { 5558a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onCreate()"); 5568a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onCreate(savedInstanceState); 557edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 5588a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getWindow().setStatusBarColor(Color.TRANSPARENT); 5592426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann 560d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(getIntent()); 561dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 56210d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa // Show QuickContact in front of soft input 56310d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 56410d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 56510d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa 566edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann setContentView(R.layout.quickcontact_activity); 567edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 568a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell mMaterialColorMapUtils = new MaterialColorMapUtils(getResources()); 569a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell 5700cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mScroller = (MultiShrinkScroller) findViewById(R.id.multiscroller); 5710cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos 572eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard = (ExpandingEntryCardView) findViewById(R.id.communication_card); 5736095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard = (ExpandingEntryCardView) findViewById(R.id.no_contact_data_card); 574b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card); 575eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard = (ExpandingEntryCardView) findViewById(R.id.about_card); 576edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 5776095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setOnClickListener(mEntryClickHandler); 578eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setOnClickListener(mEntryClickHandler); 579eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setExpandButtonText( 58023889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos getResources().getString(R.string.expanding_entry_card_view_see_all)); 5812a4207fb39330e840436215c896cde911489e111Paul Soulos mContactCard.setOnCreateContextMenuListener(mEntryContextMenuListener); 582b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 583b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setOnClickListener(mEntryClickHandler); 584b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setTitle(getResources().getString(R.string.recent_card_title)); 585edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 586eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setOnClickListener(mEntryClickHandler); 5872a4207fb39330e840436215c896cde911489e111Paul Soulos mAboutCard.setOnCreateContextMenuListener(mEntryContextMenuListener); 588eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 589d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mPhotoView = (ImageView) findViewById(R.id.photo); 5900d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell mTransparentView = findViewById(R.id.transparent_view); 5910d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell if (mScroller != null) { 5920d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell mTransparentView.setOnClickListener(new OnClickListener() { 5930d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell @Override 5940d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell public void onClick(View v) { 5950d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell mScroller.scrollOffBottom(); 5960d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 5970d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell }); 5980d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 599edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 600d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell // Allow a shadow to be shown under the toolbar. 601d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell ViewUtil.addRectangularOutlineProvider(findViewById(R.id.toolbar_parent), getResources()); 602d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell 603d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 604d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell setActionBar(toolbar); 6059b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getActionBar().setTitle(null); 6069b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // Put a TextView with a known resource id into the ActionBar. This allows us to easily 6079b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // find the correct TextView location & size later. 6089b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell toolbar.addView(getLayoutInflater().inflate(R.layout.quickcontact_title_placeholder, null)); 6096219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee 6108a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = savedInstanceState != null; 611f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = mHasAlreadyBeenOpened; 6129b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mWindowScrim = new ColorDrawable(SCRIM_COLOR); 613f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mWindowScrim.setAlpha(0); 6149b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getWindow().setBackgroundDrawable(mWindowScrim); 615edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 616c33ae17c9816b770041ee1f9ccde10e7c7eee491Brian Attwell mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED); 617ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // mScroller needs to perform asynchronous measurements after initalize(), therefore 618ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // we can't mark this as GONE. 619ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.INVISIBLE); 6208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 6219b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell setHeaderNameText(R.string.missing_name); 6229b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 623d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener= (SelectAccountDialogFragmentListener) getFragmentManager() 624d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell .findFragmentByTag(FRAGMENT_TAG_SELECT_ACCOUNT); 625d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mSelectAccountFragmentListener == null) { 626d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener = new SelectAccountDialogFragmentListener(); 627d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell getFragmentManager().beginTransaction().add(0, mSelectAccountFragmentListener, 628d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell FRAGMENT_TAG_SELECT_ACCOUNT).commit(); 629d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener.setRetainInstance(true); 630d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 631d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener.setQuickContactActivity(this); 63223889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos 633f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ true, 634f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell new Runnable() { 635f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell @Override 636f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void run() { 637f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell if (!mHasAlreadyBeenOpened) { 638f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell // The initial scrim opacity must match the scrim opacity that would be 639f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell // achieved by scrolling to the starting position. 640f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final float alphaRatio = mExtraMode == MODE_FULLY_EXPANDED ? 641f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 1 : mScroller.getStartingTransparentHeightRatio(); 642f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final int duration = getResources().getInteger( 643f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell android.R.integer.config_shortAnimTime); 644f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final int desiredAlpha = (int) (0xFF * alphaRatio); 645f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell ObjectAnimator o = ObjectAnimator.ofInt(mWindowScrim, "alpha", 0, 646f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell desiredAlpha).setDuration(duration); 647f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 648f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell o.start(); 649f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 650f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 651f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell }); 652f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 6539b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (savedInstanceState != null) { 6549b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell final int color = savedInstanceState.getInt(KEY_THEME_COLOR, 0); 655ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 656ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell new Runnable() { 657ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell @Override 658ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell public void run() { 659ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for the pre draw before setting the initial scroll 660ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // value. Prior to pre draw all scroll values are invalid. 661ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (mHasAlreadyBeenOpened) { 662ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.VISIBLE); 663ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setScroll(mScroller.getScrollNeededToBeFullScreen()); 664ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 665ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for pre draw for setting the theme color. Setting the 666ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // header tint before the MultiShrinkScroller has been measured will 667ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // cause incorrect tinting calculations. 668ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (color != 0) { 669a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell setThemeColor(mMaterialColorMapUtils 670a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell .calculatePrimaryAndSecondaryColor(color)); 6719b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 672ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 673ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell }); 6749b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 6759b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 6768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 6778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 6788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 679405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos @Override 680405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos protected void onActivityResult(int requestCode, int resultCode, Intent data) { 6818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (requestCode == REQUEST_CODE_CONTACT_EDITOR_ACTIVITY && 6828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell resultCode == ContactDeletionInteraction.RESULT_CODE_DELETED) { 6838a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // The contact that we were showing has been deleted. 6848a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell finish(); 685b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 6868a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 687dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 6888a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 6898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onNewIntent(Intent intent) { 6908a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onNewIntent(intent); 6918a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 692f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = true; 6938571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = false; 694d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(intent); 695d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 696d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 6979b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell @Override 6989b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell public void onSaveInstanceState(Bundle savedInstanceState) { 6999b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell super.onSaveInstanceState(savedInstanceState); 7009b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mColorFilter != null) { 7019b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell savedInstanceState.putInt(KEY_THEME_COLOR, mColorFilter.getColor()); 7029b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 7039b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 7049b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 705d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void processIntent(Intent intent) { 706d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell Uri lookupUri = intent.getData(); 707d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 708d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Check to see whether it comes from the old version. 709d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) { 710d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final long rawContactId = ContentUris.parseId(lookupUri); 711d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell lookupUri = RawContacts.getContactLookupUri(getContentResolver(), 712d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); 713d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 714d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, 715d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell QuickContact.MODE_LARGE); 716d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Uri oldLookupUri = mLookupUri; 717d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 718d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mLookupUri = Preconditions.checkNotNull(lookupUri, "missing lookupUri"); 719d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES); 720d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (oldLookupUri == null) { 721d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactLoader = (ContactLoader) getLoaderManager().initLoader( 722d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell LOADER_CONTACT_ID, null, mLoaderContactCallbacks); 723d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (oldLookupUri != mLookupUri) { 724d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // After copying a directory contact, the contact URI changes. Therefore, 725d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // we need to restart the loader and reload the new contact. 726899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos for (int interactionLoaderId : mRecentLoaderIds) { 727899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos getLoaderManager().destroyLoader(interactionLoaderId); 728899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos } 729405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos mContactLoader = (ContactLoader) getLoaderManager().restartLoader( 730405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos LOADER_CONTACT_ID, null, mLoaderContactCallbacks); 731d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 7322d150da246632b1649999cfabed776133b097775Brian Attwell 7332d150da246632b1649999cfabed776133b097775Brian Attwell NfcHandler.register(this, mLookupUri); 7342426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann } 735edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 736b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private void runEntranceAnimation() { 7378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mHasAlreadyBeenOpened) { 7388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 7398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 7408a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 741c33ae17c9816b770041ee1f9ccde10e7c7eee491Brian Attwell mScroller.scrollUpForEntranceAnimation(mExtraMode != MODE_FULLY_EXPANDED); 742b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 743b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 74481281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 745d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void setHeaderNameText(int resId) { 7469b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 747f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell mScroller.setTitle(getText(resId) == null ? null : getText(resId).toString()); 7489b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 74981281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 75081281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 75181281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 752f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell private void setHeaderNameText(String value) { 753d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (!TextUtils.isEmpty(value)) { 7549b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 755f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell mScroller.setTitle(value); 7569b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 75781281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 75881281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 75981281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 76081281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** 761edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Check if the given MIME-type appears in the list of excluded MIME-types 762edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * that the most-recent caller requested. 763edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 764edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private boolean isMimeExcluded(String mimeType) { 765edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (mExcludeMimes == null) return false; 766edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann for (String excludedMime : mExcludeMimes) { 767edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (TextUtils.equals(excludedMime, mimeType)) { 768edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return true; 769edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 770edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 771edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return false; 772edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 773edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 774edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 775cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann * Handle the result from the ContactLoader 776edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 7778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void bindContactData(final Contact data) { 7788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("bindContactData"); 7796cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee mContactData = data; 780d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell invalidateOptionsMenu(); 781edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 7828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 7838a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("Set display photo & name"); 784dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 7856219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee mPhotoSetter.setupContactPhoto(data, mPhotoView); 78631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell extractAndApplyTintFromPhotoViewAsynchronously(); 7874936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell analyzeWhitenessOfPhotoAsynchronously(); 788333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos setHeaderNameText(ContactDisplayUtils.getDisplayName(this, data).toString()); 789edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 7908a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 791dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 792eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mEntriesAndActionsTask = new AsyncTask<Void, Void, 793eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Pair<List<List<DataItem>>, Map<String, List<DataItem>>>>() { 7948a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 7958a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 796eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos protected Pair<List<List<DataItem>>, Map<String, List<DataItem>>> doInBackground( 797eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Void... params) { 798eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return generateDataModelFromContact(data); 7998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8008a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 8018a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 802eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos protected void onPostExecute(Pair<List<List<DataItem>>, 803eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Map<String, List<DataItem>>> dataItemsPair) { 804eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos super.onPostExecute(dataItemsPair); 805eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mDataItemsList = dataItemsPair.first; 806eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mDataItemsMap = dataItemsPair.second; 8078a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Check that original AsyncTask parameters are still valid and the activity 8088a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // is still running before binding to UI. A new intent could invalidate 8098a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the results, for example. 8108a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (data == mContactData && !isCancelled()) { 811eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos bindDataToCards(); 8128a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell showActivity(); 8138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }; 8168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.execute(); 8178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 819eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private void bindDataToCards() { 820eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos startInteractionLoaders(); 821eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos populateContactAndAboutCard(); 822eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 823eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 824eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private void startInteractionLoaders() { 825eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<DataItem> phoneDataItems = mDataItemsMap.get(Phone.CONTENT_ITEM_TYPE); 826eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] phoneNumbers = null; 827eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (phoneDataItems != null) { 828eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers = new String[phoneDataItems.size()]; 829eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < phoneDataItems.size(); ++i) { 830eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers[i] = ((PhoneDataItem) phoneDataItems.get(i)).getNumber(); 831eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 832eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 833ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle phonesExtraBundle = new Bundle(); 834eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_PHONES, phoneNumbers); 835eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 836eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("start sms loader"); 8378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getLoaderManager().initLoader( 8388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell LOADER_SMS_ID, 839ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 840ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos mLoaderInteractionsCallbacks); 841ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.endSection(); 842ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 843ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.beginSection("start call log loader"); 844ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos getLoaderManager().initLoader( 845ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID, 846ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 8478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mLoaderInteractionsCallbacks); 848899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.endSection(); 8498a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 850eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 851899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.beginSection("start calendar loader"); 852eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<DataItem> emailDataItems = mDataItemsMap.get(Email.CONTENT_ITEM_TYPE); 853eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] emailAddresses = null; 854eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (emailDataItems != null) { 855eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses = new String[emailDataItems.size()]; 856eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < emailDataItems.size(); ++i) { 857eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses[i] = ((EmailDataItem) emailDataItems.get(i)).getAddress(); 858eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 859eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 860ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle emailsExtraBundle = new Bundle(); 861eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailsExtraBundle.putStringArray(KEY_LOADER_EXTRA_EMAILS, emailAddresses); 862899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos getLoaderManager().initLoader( 863899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos LOADER_CALENDAR_ID, 864ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos emailsExtraBundle, 865899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos mLoaderInteractionsCallbacks); 8668a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 8678a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8688a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 8698a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void showActivity() { 8708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller != null) { 8718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mScroller.setVisibility(View.VISIBLE); 8728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 8738a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell new Runnable() { 8748a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 8758a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void run() { 8768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell runEntranceAnimation(); 8778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }); 8798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8808a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 882a153dba33c2152332c5706178a367f52b0550723Paul Soulos private List<List<Entry>> buildAboutCardEntries() { 883a153dba33c2152332c5706178a367f52b0550723Paul Soulos final List<List<Entry>> aboutCardEntries = new ArrayList<>(); 884a153dba33c2152332c5706178a367f52b0550723Paul Soulos for (String mimetype : SORTED_ABOUT_CARD_MIMETYPES) { 885a153dba33c2152332c5706178a367f52b0550723Paul Soulos final List<DataItem> mimeTypeItems = mDataItemsMap.get(mimetype); 886a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (mimeTypeItems == null) { 887a153dba33c2152332c5706178a367f52b0550723Paul Soulos continue; 888a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 889a153dba33c2152332c5706178a367f52b0550723Paul Soulos final List<Entry> aboutEntries = dataItemsToEntries(mimeTypeItems); 890a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (aboutEntries.size() > 0) { 891a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(aboutEntries); 892a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 893a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 894a153dba33c2152332c5706178a367f52b0550723Paul Soulos return aboutCardEntries; 895a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 896a153dba33c2152332c5706178a367f52b0550723Paul Soulos 897a42ef76251778161d27bc07db214b8c81720e476Paul Soulos @Override 898a42ef76251778161d27bc07db214b8c81720e476Paul Soulos protected void onResume() { 899a42ef76251778161d27bc07db214b8c81720e476Paul Soulos super.onResume(); 900a42ef76251778161d27bc07db214b8c81720e476Paul Soulos // If returning from a launched activity, repopulate the contact and about card 901a42ef76251778161d27bc07db214b8c81720e476Paul Soulos if (mHasIntentLaunched) { 902a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = false; 903a42ef76251778161d27bc07db214b8c81720e476Paul Soulos populateContactAndAboutCard(); 904a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 905a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 906a42ef76251778161d27bc07db214b8c81720e476Paul Soulos 907eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private void populateContactAndAboutCard() { 908a42ef76251778161d27bc07db214b8c81720e476Paul Soulos if (mHasIntentLaunched) { 909a42ef76251778161d27bc07db214b8c81720e476Paul Soulos return; 910a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 911eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind contact card"); 912eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 91360e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos final List<List<Entry>> contactCardEntries = new ArrayList<>(); 914a153dba33c2152332c5706178a367f52b0550723Paul Soulos final List<List<Entry>> aboutCardEntries = buildAboutCardEntries(); 915eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 916eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < mDataItemsList.size(); ++i) { 917eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<DataItem> dataItemsByMimeType = mDataItemsList.get(i); 918eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final DataItem topDataItem = dataItemsByMimeType.get(0); 919a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (SORTED_ABOUT_CARD_MIMETYPES.contains(topDataItem.getMimeType())) { 920a153dba33c2152332c5706178a367f52b0550723Paul Soulos // About card mimetypes are built in buildAboutCardEntries, skip here 921a153dba33c2152332c5706178a367f52b0550723Paul Soulos continue; 92260e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos } else { 92360e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos List<Entry> contactEntries = dataItemsToEntries(mDataItemsList.get(i)); 92460e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos if (contactEntries.size() > 0) { 92560e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos contactCardEntries.add(contactEntries); 926eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 927eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 928eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 929eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 930eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (contactCardEntries.size() > 0) { 931eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.initialize(contactCardEntries, 932eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* numInitialVisibleEntries = */ MIN_NUM_CONTACT_ENTRIES_SHOWN, 933c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos /* isExpanded = */ mContactCard.isExpanded(), 93489966b4ed8cc9d385e5ac6b4a7e9e08ada387eb0Paul Soulos /* isAlwaysExpanded = */ false, 9350cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mExpandingEntryCardViewListener, 9360cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mScroller); 937eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.VISIBLE); 938eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 939eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.GONE); 940eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 941eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 9428a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 943eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind about card"); 944c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos // Phonetic name is not a data item, so the entry needs to be created separately 945c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos final String phoneticName = mContactData.getPhoneticName(); 946c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos if (!TextUtils.isEmpty(phoneticName)) { 947c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos Entry phoneticEntry = new Entry(/* viewId = */ -1, 948c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* icon = */ null, 949c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos getResources().getString(R.string.name_phonetic), 950c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos phoneticName, 951c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* text = */ null, 952c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* intent = */ null, 953c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateIcon = */ null, 954c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateIntent = */ null, 955c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateContentDescription = */ null, 956c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* shouldApplyColor = */ false, 9572a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, 9582a4207fb39330e840436215c896cde911489e111Paul Soulos /* EntryContextMenuInfo = */ new EntryContextMenuInfo(phoneticName, 9592a4207fb39330e840436215c896cde911489e111Paul Soulos getResources().getString(R.string.name_phonetic))); 960c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos List<Entry> phoneticList = new ArrayList<>(); 961c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos phoneticList.add(phoneticEntry); 962a153dba33c2152332c5706178a367f52b0550723Paul Soulos // Phonetic name comes after nickname. Check to see if the first entry type is nickname 963a0fa4c18dc111ceea9ff47f35ee01fecc1003578Paul Soulos if (aboutCardEntries.size() > 0 && aboutCardEntries.get(0).get(0).getHeader().equals( 964a153dba33c2152332c5706178a367f52b0550723Paul Soulos getResources().getString(R.string.header_nickname_entry))) { 965a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(1, phoneticList); 966a153dba33c2152332c5706178a367f52b0550723Paul Soulos } else { 967a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(0, phoneticList); 968a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 969c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos } 970c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos 971eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.initialize(aboutCardEntries, 972eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* numInitialVisibleEntries = */ 1, 973eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* isExpanded = */ true, 97489966b4ed8cc9d385e5ac6b4a7e9e08ada387eb0Paul Soulos /* isAlwaysExpanded = */ true, 9750cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mExpandingEntryCardViewListener, 9760cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mScroller); 9776095369885edcca566a812b551886e29c7ff8039Brian Attwell 9786095369885edcca566a812b551886e29c7ff8039Brian Attwell if (contactCardEntries.size() == 0 && aboutCardEntries.size() == 0) { 9796095369885edcca566a812b551886e29c7ff8039Brian Attwell initializeNoContactDetailCard(); 9806095369885edcca566a812b551886e29c7ff8039Brian Attwell } else { 9816095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setVisibility(View.GONE); 9826095369885edcca566a812b551886e29c7ff8039Brian Attwell } 9836095369885edcca566a812b551886e29c7ff8039Brian Attwell 984a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos // If the Recent card is already initialized (all recent data is loaded), show the About 985a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos // card if it has entries. Otherwise About card visibility will be set in bindRecentData() 986a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos if (isAllRecentDataLoaded() && aboutCardEntries.size() > 0) { 987a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos mAboutCard.setVisibility(View.VISIBLE); 988a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos } 989eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 990eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 991eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 992eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 9936095369885edcca566a812b551886e29c7ff8039Brian Attwell * Create a card that shows "Add email" and "Add phone number" entries in grey. 9946095369885edcca566a812b551886e29c7ff8039Brian Attwell */ 9956095369885edcca566a812b551886e29c7ff8039Brian Attwell private void initializeNoContactDetailCard() { 9966095369885edcca566a812b551886e29c7ff8039Brian Attwell final Drawable phoneIcon = getResources().getDrawable( 9976095369885edcca566a812b551886e29c7ff8039Brian Attwell R.drawable.ic_phone_24dp).mutate(); 9986095369885edcca566a812b551886e29c7ff8039Brian Attwell final Entry phonePromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, 9996095369885edcca566a812b551886e29c7ff8039Brian Attwell phoneIcon, getString(R.string.quickcontact_add_phone_number), 1000dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* subHeader = */ null, /* text = */ null, getEditContactIntent(), 1001dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIcon = */ null, /* alternateIntent = */ null, 1002714455bba22b99d168a2e864dfbc74a6e30dfdb6Paul Soulos /* alternateContentDescription = */ null, /* shouldApplyColor = */ true, 10032a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, /* EntryContextMenuInfo = */ null); 10046095369885edcca566a812b551886e29c7ff8039Brian Attwell 10056095369885edcca566a812b551886e29c7ff8039Brian Attwell final Drawable emailIcon = getResources().getDrawable( 10066095369885edcca566a812b551886e29c7ff8039Brian Attwell R.drawable.ic_email_24dp).mutate(); 10076095369885edcca566a812b551886e29c7ff8039Brian Attwell final Entry emailPromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, 10086095369885edcca566a812b551886e29c7ff8039Brian Attwell emailIcon, getString(R.string.quickcontact_add_email), /* subHeader = */ null, 1009dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* text = */ null, getEditContactIntent(), /* alternateIcon = */ null, 1010dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIntent = */ null, /* alternateContentDescription = */ null, 10112a4207fb39330e840436215c896cde911489e111Paul Soulos /* shouldApplyColor = */ true, /* isEditable = */ false, 10122a4207fb39330e840436215c896cde911489e111Paul Soulos /* EntryContextMenuInfo = */ null); 10136095369885edcca566a812b551886e29c7ff8039Brian Attwell 10146095369885edcca566a812b551886e29c7ff8039Brian Attwell final List<List<Entry>> promptEntries = new ArrayList<>(); 10156095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.add(new ArrayList<Entry>(1)); 10166095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.add(new ArrayList<Entry>(1)); 10176095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.get(0).add(phonePromptEntry); 10186095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.get(1).add(emailPromptEntry); 10196095369885edcca566a812b551886e29c7ff8039Brian Attwell 10206095369885edcca566a812b551886e29c7ff8039Brian Attwell final int subHeaderTextColor = getResources().getColor( 10216095369885edcca566a812b551886e29c7ff8039Brian Attwell R.color.quickcontact_entry_sub_header_text_color); 10226095369885edcca566a812b551886e29c7ff8039Brian Attwell final PorterDuffColorFilter greyColorFilter = 10236095369885edcca566a812b551886e29c7ff8039Brian Attwell new PorterDuffColorFilter(subHeaderTextColor, PorterDuff.Mode.SRC_ATOP); 1024c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos mNoContactDetailsCard.initialize(promptEntries, 2, /* isExpanded = */ true, 10250cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos /* isAlwaysExpanded = */ true, mExpandingEntryCardViewListener, mScroller); 10266095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setVisibility(View.VISIBLE); 10276095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setEntryHeaderColor(subHeaderTextColor); 10286095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setColorAndFilter(subHeaderTextColor, greyColorFilter); 10296095369885edcca566a812b551886e29c7ff8039Brian Attwell } 10306095369885edcca566a812b551886e29c7ff8039Brian Attwell 10316095369885edcca566a812b551886e29c7ff8039Brian Attwell /** 1032eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Builds the {@link DataItem}s Map out of the Contact. 1033eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param data The contact to build the data from. 1034eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return A pair containing a list of data items sorted within mimetype and sorted 1035eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * amongst mimetype. The map goes from mimetype string to the sorted list of data items within 1036eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * mimetype 1037eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 1038eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private Pair<List<List<DataItem>>, Map<String, List<DataItem>>> generateDataModelFromContact( 1039eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Contact data) { 1040eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("Build data items map"); 1041eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1042eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Map<String, List<DataItem>> dataItemsMap = new HashMap<>(); 10438bf96e78497ea9c8c893bcb357fc1e3175fb2e9bBrian Attwell 10448a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final ResolveCache cache = ResolveCache.getInstance(this); 1045851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (RawContact rawContact : data.getRawContacts()) { 1046851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (DataItem dataItem : rawContact.getDataItems()) { 1047eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setRawContactId(rawContact.getId()); 1048eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1049851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final String mimeType = dataItem.getMimeType(); 1050eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (mimeType == null) continue; 1051eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 105247b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final AccountType accountType = rawContact.getAccountType(this); 105347b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final DataKind dataKind = AccountTypeManager.getInstance(this) 105447b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng .getKindOrFallback(accountType, mimeType); 1055eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataKind == null) continue; 1056cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1057eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setDataKind(dataKind); 1058b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1059eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean hasData = !TextUtils.isEmpty(dataItem.buildDataString(this, 1060eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataKind)); 1061899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 1062eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (isMimeExcluded(mimeType) || !hasData) continue; 1063edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1064eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos List<DataItem> dataItemListByType = dataItemsMap.get(mimeType); 1065eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItemListByType == null) { 1066eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType = new ArrayList<>(); 1067eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsMap.put(mimeType, dataItemListByType); 1068edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1069eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType.add(dataItem); 1070edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1071edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 10728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 1073edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1074eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort within mimetypes"); 107516339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos /* 107616339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos * Sorting is a multi part step. The end result is to a have a sorted list of the most 1077eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * used data items, one per mimetype. Then, within each mimetype, the list of data items 1078eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * for that type is also sorted, based off of {super primary, primary, times used} in that 1079eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * order. 108016339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos */ 1081eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<List<DataItem>> dataItemsList = new ArrayList<>(); 1082eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (List<DataItem> mimeTypeDataItems : dataItemsMap.values()) { 1083eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Remove duplicate data items 1084eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collapser.collapseList(mimeTypeDataItems, this); 1085eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort within mimetype 1086eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(mimeTypeDataItems, mWithinMimeTypeDataItemComparator); 1087eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Add to the list of data item lists 1088eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsList.add(mimeTypeDataItems); 1089edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1090eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 1091edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1092eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort amongst mimetypes"); 1093eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort amongst mimetypes to bubble up the top data items for the contact card 1094eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(dataItemsList, mAmongstMimeTypeDataItemComparator); 1095eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 109616339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos 1097eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return new Pair<>(dataItemsList, dataItemsMap); 1098eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1099edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1100eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 1101eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Converts a {@link DataItem} into an {@link ExpandingEntryCardView.Entry} for display. 1102eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * If the {@link ExpandingEntryCardView.Entry} has no visual elements, null is returned. 1103eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param dataItem The {@link DataItem} to convert. 1104eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return The {@link ExpandingEntryCardView.Entry}, or null if no visual elements are present. 1105eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 1106eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private Entry dataItemToEntry(DataItem dataItem) { 1107eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable icon = null; 1108eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String header = null; 1109eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String subHeader = null; 1110eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable subHeaderIcon = null; 1111eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String text = null; 1112eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable textIcon = null; 1113eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Intent intent = null; 111448ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos boolean shouldApplyColor = true; 1115dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Drawable alternateIcon = null; 1116dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Intent alternateIntent = null; 1117dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos String alternateContentDescription = null; 1118eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEditable = false; 11192a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo entryContextMenuInfo = null; 1120eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1121eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataKind kind = dataItem.getDataKind(); 1122eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1123eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItem instanceof ImDataItem) { 1124eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final ImDataItem im = (ImDataItem) dataItem; 1125eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = ContactsUtils.buildImIntent(this, im).first; 1126eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEmail = im.isCreatedFromEmail(); 11277de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos final int protocol; 11287de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos if (!im.isProtocolValid()) { 11297de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos protocol = Im.PROTOCOL_CUSTOM; 11307de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } else { 11317de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol(); 11327de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } 11337de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos if (protocol == Im.PROTOCOL_CUSTOM) { 11347de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos // If the protocol is custom, display the "IM" entry header as well to distinguish 11357de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos // this entry from other ones 11367de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos header = getResources().getString(R.string.header_im_entry); 11377de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos subHeader = Im.getProtocolLabel(getResources(), protocol, 11387de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos im.getCustomProtocol()).toString(); 11397de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos text = im.getData(); 11407de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } else { 11417de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos header = Im.getProtocolLabel(getResources(), protocol, 11427de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos im.getCustomProtocol()).toString(); 11437de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos subHeader = im.getData(); 11447de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } 11452a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(im.getData(), header); 1146eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof OrganizationDataItem) { 1147eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final OrganizationDataItem organization = (OrganizationDataItem) dataItem; 1148eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_organization_entry); 1149eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = organization.getCompany(); 11502a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header); 1151eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = organization.getTitle(); 1152eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NicknameDataItem) { 1153eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NicknameDataItem nickname = (NicknameDataItem) dataItem; 1154eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Build nickname entries 1155eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isNameRawContact = 1156eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos (mContactData.getNameRawContactId() == dataItem.getRawContactId()); 1157eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1158eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean duplicatesTitle = 1159eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos isNameRawContact 1160eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos && mContactData.getDisplayNameSource() == DisplayNameSources.NICKNAME; 1161eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1162eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!duplicatesTitle) { 1163eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_nickname_entry); 1164eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = nickname.getName(); 11652a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header); 1166eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1167eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NoteDataItem) { 1168eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NoteDataItem note = (NoteDataItem) dataItem; 1169eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_note_entry); 1170eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = note.getNote(); 11712a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header); 1172eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof WebsiteDataItem) { 1173eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final WebsiteDataItem website = (WebsiteDataItem) dataItem; 1174eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_website_entry); 1175eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = website.getUrl(); 11762a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header); 1177eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos try { 1178eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final WebAddress webAddress = new WebAddress(website.buildDataString(this, kind)); 1179eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString())); 1180eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ParseException e) { 1181eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Log.e(TAG, "Couldn't parse website: " + website.buildDataString(this, kind)); 1182eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1183eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EventDataItem) { 1184eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EventDataItem event = (EventDataItem) dataItem; 1185eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String dataString = event.buildDataString(this, kind); 1186eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Calendar cal = DateUtils.parseDate(dataString, false); 1187eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (cal != null) { 1188eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Date nextAnniversary = 1189eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DateUtils.getNextAnnualDate(cal); 1190eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); 1191eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos builder.appendPath("time"); 1192eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos ContentUris.appendId(builder, nextAnniversary.getTime()); 1193eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW).setData(builder.build()); 1194eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1195eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_event_entry); 1196f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (event.hasKindTypeColumn(kind)) { 11977de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos subHeader = Event.getTypeLabel(getResources(), event.getKindTypeColumn(kind), 11987de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos event.getLabel()).toString(); 1199f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1200eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = DateUtils.formatDate(this, dataString); 1201f848c49cac796f99549c8418f8d4e2469ac9f963Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(text, header); 1202eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof RelationDataItem) { 1203eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final RelationDataItem relation = (RelationDataItem) dataItem; 1204eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String dataString = relation.buildDataString(this, kind); 1205eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(dataString)) { 1206eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SEARCH); 1207eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.putExtra(SearchManager.QUERY, dataString); 1208eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.setType(Contacts.CONTENT_TYPE); 1209eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1210eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = getResources().getString(R.string.header_relation_entry); 1211eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = relation.getName(); 12122a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header); 1213f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (relation.hasKindTypeColumn(kind)) { 1214f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos text = Relation.getTypeLabel(getResources(), relation.getKindTypeColumn(kind), 1215f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos relation.getLabel()).toString(); 1216f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1217eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof PhoneDataItem) { 1218eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final PhoneDataItem phone = (PhoneDataItem) dataItem; 1219eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(phone.getNumber())) { 1220eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = phone.buildDataString(this, kind); 12212a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 12222a4207fb39330e840436215c896cde911489e111Paul Soulos getResources().getString(R.string.phoneLabelsGroup)); 1223f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (phone.hasKindTypeColumn(kind)) { 1224f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos text = Phone.getTypeLabel(getResources(), phone.getKindTypeColumn(kind), 1225f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos phone.getLabel()).toString(); 1226f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1227eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos icon = getResources().getDrawable(R.drawable.ic_phone_24dp); 1228eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (PhoneCapabilityTester.isPhone(this)) { 1229eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(phone.getNumber()); 123016339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1231dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIntent = new Intent(Intent.ACTION_SENDTO, 1232dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Uri.fromParts(CallUtil.SCHEME_SMSTO, phone.getNumber(), null)); 1233dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIcon = getResources().getDrawable(R.drawable.ic_message_24dp); 1234dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateContentDescription = getResources().getString(R.string.sms_other); 1235eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1236eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EmailDataItem) { 1237eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EmailDataItem email = (EmailDataItem) dataItem; 1238eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String address = email.getData(); 1239eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(address)) { 1240eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri mailUri = Uri.fromParts(CallUtil.SCHEME_MAILTO, address, null); 1241eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SENDTO, mailUri); 1242eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = email.getAddress(); 12432a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 12442a4207fb39330e840436215c896cde911489e111Paul Soulos getResources().getString(R.string.emailLabelsGroup)); 1245f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (email.hasKindTypeColumn(kind)) { 1246f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos text = Email.getTypeLabel(getResources(), email.getKindTypeColumn(kind), 1247f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos email.getLabel()).toString(); 1248f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1249eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos icon = getResources().getDrawable(R.drawable.ic_email_24dp); 1250eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1251eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredPostalDataItem) { 1252eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos StructuredPostalDataItem postal = (StructuredPostalDataItem) dataItem; 1253eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String postalAddress = postal.getFormattedAddress(); 1254eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(postalAddress)) { 1255eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress); 1256eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = postal.getFormattedAddress(); 12572a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 12582a4207fb39330e840436215c896cde911489e111Paul Soulos getResources().getString(R.string.postalLabelsGroup)); 1259f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (postal.hasKindTypeColumn(kind)) { 1260f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos text = StructuredPostal.getTypeLabel(getResources(), 1261f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos postal.getKindTypeColumn(kind), postal.getLabel()).toString(); 1262f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 12636a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos alternateIntent = 12646a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos StructuredPostalUtils.getViewPostalAddressDirectionsIntent(postalAddress); 12656a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos alternateIcon = getResources().getDrawable(R.drawable.ic_directions_24dp); 1266eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos icon = getResources().getDrawable(R.drawable.ic_place_24dp); 1267eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1268eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof SipAddressDataItem) { 1269eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (PhoneCapabilityTester.isSipPhone(this)) { 1270eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final SipAddressDataItem sip = (SipAddressDataItem) dataItem; 1271eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String address = sip.getSipAddress(); 1272eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(address)) { 1273eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri callUri = Uri.fromParts(CallUtil.SCHEME_SIP, address, null); 1274eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(callUri); 12751cda01b35a37f79b22e907cc970314b8c0a9e00cPaul Soulos header = address; 12762a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 12772a4207fb39330e840436215c896cde911489e111Paul Soulos getResources().getString(R.string.phoneLabelsGroup)); 12781cda01b35a37f79b22e907cc970314b8c0a9e00cPaul Soulos if (sip.hasKindTypeColumn(kind)) { 12791cda01b35a37f79b22e907cc970314b8c0a9e00cPaul Soulos text = SipAddress.getTypeLabel(getResources(), sip.getKindTypeColumn(kind), 12801cda01b35a37f79b22e907cc970314b8c0a9e00cPaul Soulos sip.getLabel()).toString(); 12811cda01b35a37f79b22e907cc970314b8c0a9e00cPaul Soulos } 1282307b49420ce66b0aee5563bf2624dba7e20e28e2Paul Soulos icon = getResources().getDrawable(R.drawable.ic_dialer_sip_black_24dp); 128316339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1284edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1285eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredNameDataItem) { 1286eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String givenName = ((StructuredNameDataItem) dataItem).getGivenName(); 1287eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(givenName)) { 1288eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setTitle(getResources().getString(R.string.about_card_title) + 1289eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos " " + givenName); 1290eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1291eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setTitle(getResources().getString(R.string.about_card_title)); 1292eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1293eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1294eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Custom DataItem 1295eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = dataItem.buildDataStringForDisplay(this, kind); 1296eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = kind.typeColumn; 1297eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW); 129860e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, dataItem.getId()); 129960e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos intent.setDataAndType(uri, dataItem.getMimeType()); 1300e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 1301e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (intent != null) { 1302e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos final String mimetype = intent.getType(); 1303e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 1304e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos // Attempt to use known icons for known 3p types. Otherwise default to ResolveCache 1305e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos switch (mimetype) { 1306e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos case MIMETYPE_GPLUS_PROFILE: 1307e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (INTENT_DATA_GPLUS_PROFILE_ADD_TO_CIRCLE.equals( 1308e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos intent.getDataString())) { 1309e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos icon = getResources().getDrawable( 1310e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos R.drawable.ic_add_to_circles_black_24); 1311e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } else { 1312e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos icon = getResources().getDrawable(R.drawable.ic_google_plus_24dp); 1313e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1314e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos break; 1315e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos case MIMETYPE_HANGOUTS: 1316e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (INTENT_DATA_HANGOUTS_VIDEO.equals(intent.getDataString())) { 1317e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos icon = getResources().getDrawable(R.drawable.ic_hangout_video_24dp); 1318e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } else { 1319e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos icon = getResources().getDrawable(R.drawable.ic_hangout_24dp); 1320e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1321e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos break; 1322e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos default: 13232a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, mimetype); 1324e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos icon = ResolveCache.getInstance(this).getIcon( 1325e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos dataItem.getMimeType(), intent); 1326e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos // Call mutate to create a new Drawable.ConstantState for color filtering 1327e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (icon != null) { 1328e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos icon.mutate(); 1329e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 133048ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos shouldApplyColor = false; 1331e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1332e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1333eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1334b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1335eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (intent != null) { 1336eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Do not set the intent is there are no resolves 1337eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!PhoneCapabilityTester.isIntentRegistered(this, intent)) { 1338eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = null; 1339eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1340eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1341eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1342dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (alternateIntent != null) { 1343dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Do not set the alternate intent is there are no resolves 1344dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (!PhoneCapabilityTester.isIntentRegistered(this, alternateIntent)) { 1345dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIntent = null; 1346dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1347dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1348dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Attempt to use package manager to find a suitable content description if needed 1349dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (TextUtils.isEmpty(alternateContentDescription)) { 1350dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateContentDescription = getIntentResolveLabel(alternateIntent); 1351dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1352dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1353dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1354eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // If the Entry has no visual elements, return null 1355eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) && 1356eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeaderIcon == null && TextUtils.isEmpty(text) && textIcon == null) { 1357eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return null; 1358eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1359eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1360fa238949855fba3b28a57fad3d585b13e80362bbBrian Attwell // Ignore dataIds from the Me profile. 1361ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final int dataId = dataItem.getId() > Integer.MAX_VALUE ? 1362ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos -1 : (int) dataItem.getId(); 1363ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 1364dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon, intent, 1365dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIcon, alternateIntent, alternateContentDescription, shouldApplyColor, 13662a4207fb39330e840436215c896cde911489e111Paul Soulos isEditable, entryContextMenuInfo); 1367eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1368eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1369eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private List<Entry> dataItemsToEntries(List<DataItem> dataItems) { 1370eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> entries = new ArrayList<>(); 1371eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (DataItem dataItem : dataItems) { 1372eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Entry entry = dataItemToEntry(dataItem); 1373eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (entry != null) { 1374eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos entries.add(entry); 1375eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1376eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1377eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return entries; 1378edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1379edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1380dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos private String getIntentResolveLabel(Intent intent) { 1381dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos final List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 1382dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos PackageManager.MATCH_DEFAULT_ONLY); 1383dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1384dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Pick first match, otherwise best found 1385dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos ResolveInfo bestResolve = null; 1386dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos final int size = matches.size(); 1387dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (size == 1) { 1388dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos bestResolve = matches.get(0); 1389dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } else if (size > 1) { 1390dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos bestResolve = ResolveCache.getInstance(this).getBestResolve(intent, matches); 1391dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1392dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1393dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (bestResolve == null) { 1394dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos return null; 1395dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1396dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1397dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos return String.valueOf(bestResolve.loadLabel(getPackageManager())); 1398dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1399dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1400edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 140131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * Asynchronously extract the most vibrant color from the PhotoView. Once extracted, 140231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms 140331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * on a Nexus 5. 140431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell */ 140531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell private void extractAndApplyTintFromPhotoViewAsynchronously() { 140631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell if (mScroller == null) { 140731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell return; 140831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 140931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell final Drawable imageViewDrawable = mPhotoView.getDrawable(); 1410faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell new AsyncTask<Void, Void, MaterialPalette>() { 141131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 1412faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell protected MaterialPalette doInBackground(Void... params) { 1413faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell 141431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell if (imageViewDrawable instanceof BitmapDrawable) { 14158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final Bitmap bitmap = ((BitmapDrawable) imageViewDrawable).getBitmap(); 1416faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell final int primaryColor = colorFromBitmap(bitmap); 1417faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell if (primaryColor != 0) { 1418a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor( 1419faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell primaryColor); 1420faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell } 14218a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 14228a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (imageViewDrawable instanceof LetterTileDrawable) { 1423faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell final int primaryColor = ((LetterTileDrawable) imageViewDrawable).getColor(); 1424a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(primaryColor); 142531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 1426a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return MaterialColorMapUtils.getDefaultPrimaryAndSecondaryColors(getResources()); 142731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 142831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 142931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 1430faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell protected void onPostExecute(MaterialPalette palette) { 1431faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell super.onPostExecute(palette); 14328571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (mHasComputedThemeColor) { 14338571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // If we had previously computed a theme color from the contact photo, 14348571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // then do not update the theme color. Changing the theme color several 14358571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // seconds after QC has started, as a result of an updated/upgraded photo, 14368571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // is a jarring experience. On the other hand, changing the theme color after 14378571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // a rotation or onNewIntent() is perfectly fine. 14388571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell return; 14398571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell } 14408571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // Check that the Photo has not changed. If it has changed, the new tint 14418571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // color needs to be extracted 14428571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (imageViewDrawable == mPhotoView.getDrawable()) { 14438571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = true; 1444faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell setThemeColor(palette); 144531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 144631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 144731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell }.execute(); 144831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 144931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 14504936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell /** 14514936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell * Examine how many white pixels are in the bitmap in order to determine whether or not 14524936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell * we need gradient overlays on top of the image. 14534936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell */ 14544936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell private void analyzeWhitenessOfPhotoAsynchronously() { 14554936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell final Drawable imageViewDrawable = mPhotoView.getDrawable(); 14564936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell new AsyncTask<Void, Void, Boolean>() { 14574936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell @Override 14584936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell protected Boolean doInBackground(Void... params) { 14594936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell if (imageViewDrawable instanceof BitmapDrawable) { 14604936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell final Bitmap bitmap = ((BitmapDrawable) imageViewDrawable).getBitmap(); 14614936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell return WhitenessUtils.isBitmapWhiteAtTopOrBottom(bitmap); 14624936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell } 14634936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell return !(imageViewDrawable instanceof LetterTileDrawable); 14644936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell } 14654936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell 14664936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell @Override 14674936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell protected void onPostExecute(Boolean isWhite) { 14684936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell super.onPostExecute(isWhite); 14694936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell mScroller.setUseGradient(isWhite); 14704936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell } 14714936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell }.execute(); 14724936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell } 14734936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell 1474faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell private void setThemeColor(MaterialPalette palette) { 14759b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // If the color is invalid, use the predefined default 1476faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell final int primaryColor = palette.mPrimaryColor; 1477faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mScroller.setHeaderTintColor(primaryColor); 1478faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mStatusBarColor = palette.mSecondaryColor; 14799b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell updateStatusBarColor(); 14808571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell 14819b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mColorFilter = 1482faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell new PorterDuffColorFilter(primaryColor, PorterDuff.Mode.SRC_ATOP); 1483faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mContactCard.setColorAndFilter(primaryColor, mColorFilter); 1484faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mRecentCard.setColorAndFilter(primaryColor, mColorFilter); 1485faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mAboutCard.setColorAndFilter(primaryColor, mColorFilter); 14869b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 14879b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 14888a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void updateStatusBarColor() { 14898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller == null) { 14908a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 14918a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 14928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int desiredStatusBarColor; 14938a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Only use a custom status bar color if QuickContacts touches the top of the viewport. 14948a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller.getScrollNeededToBeFullScreen() <= 0) { 14958a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = mStatusBarColor; 14968a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } else { 14978a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = Color.TRANSPARENT; 14988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 14998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Animate to the new color. 1500847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor", 1501847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell getWindow().getStatusBarColor(), desiredStatusBarColor); 1502847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION); 1503847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.setEvaluator(new ArgbEvaluator()); 1504847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.start(); 15058a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 15068a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 15078a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int colorFromBitmap(Bitmap bitmap) { 15088a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Author of Palette recommends using 24 colors when analyzing profile photos. 15098a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int NUMBER_OF_PALETTE_COLORS = 24; 15108a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final Palette palette = Palette.generate(bitmap, NUMBER_OF_PALETTE_COLORS); 1511a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell if (palette != null && palette.getVibrantSwatch() != null) { 1512a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell return palette.getVibrantSwatch().getRgb(); 15138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 15148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return 0; 15158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 15168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1517b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) { 1518eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> entries = new ArrayList<>(); 1519b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos for (ContactInteraction interaction : interactions) { 1520ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos entries.add(new Entry(/* id = */ -1, 1521ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos interaction.getIcon(this), 1522b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewHeader(this), 1523b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewBody(this), 1524b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getBodyIcon(this), 1525b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewFooter(this), 1526b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getFooterIcon(this), 1527b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getIntent(), 1528dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIcon = */ null, 1529dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIntent = */ null, 1530dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateContentDescription = */ null, 153148ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos /* shouldApplyColor = */ true, 15322a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, 15332a4207fb39330e840436215c896cde911489e111Paul Soulos /* EntryContextMenuInfo = */ null)); 1534b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1535b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return entries; 1536b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1537b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1538eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<Contact> mLoaderContactCallbacks = 1539851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu new LoaderCallbacks<Contact>() { 1540cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 1541851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoaderReset(Loader<Contact> loader) { 1542405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos mContactData = null; 1543cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1544cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1545cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 1546851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoadFinished(Loader<Contact> loader, Contact data) { 15478a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onLoadFinished()"); 15488a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1549cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (isFinishing()) { 1550cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann return; 1551cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1552cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (data.isError()) { 1553cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann // This shouldn't ever happen, so throw an exception. The {@link ContactLoader} 1554cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann // should log the actual exception. 1555cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann throw new IllegalStateException("Failed to load contact", data.getException()); 1556cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1557cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (data.isNotFound()) { 15588a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mHasAlreadyBeenOpened) { 15598a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell finish(); 15608a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } else { 15618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri()); 15628a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, 15638a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.LENGTH_LONG).show(); 15648a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 1565cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann return; 1566cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1567cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1568b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos bindContactData(data); 1569cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 15708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 1571cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1572cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1573cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 1574851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public Loader<Contact> onCreateLoader(int id, Bundle args) { 1575cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (mLookupUri == null) { 1576cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann Log.wtf(TAG, "Lookup uri wasn't initialized. Loader was started too early"); 1577cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1578d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Load all contact data. We need loadGroupMetaData=true to determine whether the 1579d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // contact is invisible. If it is, we need to display an "Add to Contacts" MenuItem. 1580b2b435a944947fbf1965c3bb7c202a97f0273259Yorke Lee return new ContactLoader(getApplicationContext(), mLookupUri, 1581d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell true /*loadGroupMetaData*/, false /*loadInvitableAccountTypes*/, 15828571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell true /*postViewNotification*/, true /*computeFormattedPhoneNumber*/); 1583cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1584cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann }; 1585b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1586b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 1587b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onBackPressed() { 1588b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell if (mScroller != null) { 15898477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell if (!mIsExitAnimationInProgress) { 15908477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mScroller.scrollOffBottom(); 15918477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 1592b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } else { 1593b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell super.onBackPressed(); 1594b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 1595b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 1596b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 15978a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 15988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void finish() { 15998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.finish(); 16008a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 16018a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // override transitions to skip the standard window animations 16028a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell overridePendingTransition(0, 0); 16038a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 16048a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1605eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<List<ContactInteraction>> mLoaderInteractionsCallbacks = 1606b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos new LoaderCallbacks<List<ContactInteraction>>() { 1607b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1608b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 1609b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public Loader<List<ContactInteraction>> onCreateLoader(int id, Bundle args) { 1610b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Log.v(TAG, "onCreateLoader"); 1611b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Loader<List<ContactInteraction>> loader = null; 1612b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos switch (id) { 1613b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos case LOADER_SMS_ID: 1614b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Log.v(TAG, "LOADER_SMS_ID"); 1615b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos loader = new SmsInteractionsLoader( 1616b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos QuickContactActivity.this, 1617ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 1618b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos MAX_SMS_RETRIEVE); 1619b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos break; 1620899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos case LOADER_CALENDAR_ID: 1621899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Log.v(TAG, "LOADER_CALENDAR_ID"); 1622ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos final String[] emailsArray = args.getStringArray(KEY_LOADER_EXTRA_EMAILS); 1623ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos List<String> emailsList = null; 1624ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos if (emailsArray != null) { 1625ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos emailsList = Arrays.asList(args.getStringArray(KEY_LOADER_EXTRA_EMAILS)); 1626ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos } 1627899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos loader = new CalendarInteractionsLoader( 1628899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos QuickContactActivity.this, 1629ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos emailsList, 1630899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_FUTURE_CALENDAR_RETRIEVE, 1631899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_PAST_CALENDAR_RETRIEVE, 1632899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR, 1633899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR); 1634899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos break; 1635ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos case LOADER_CALL_LOG_ID: 1636ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Log.v(TAG, "LOADER_CALL_LOG_ID"); 1637ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos loader = new CallLogInteractionsLoader( 1638ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.this, 1639ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 1640ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos MAX_CALL_LOG_RETRIEVE); 1641b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1642b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return loader; 1643b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1644b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1645b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 1646b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoadFinished(Loader<List<ContactInteraction>> loader, 1647b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos List<ContactInteraction> data) { 1648b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.put(loader.getId(), data); 1649b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1650b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos if (isAllRecentDataLoaded()) { 1651b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos bindRecentData(); 1652b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1653b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1654b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1655b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 1656b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoaderReset(Loader<List<ContactInteraction>> loader) { 1657b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.remove(loader.getId()); 1658b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1659b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos }; 1660b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1661b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private boolean isAllRecentDataLoaded() { 1662b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return mRecentLoaderResults.size() == mRecentLoaderIds.length; 1663b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1664b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1665b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private void bindRecentData() { 1666eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<ContactInteraction> allInteractions = new ArrayList<>(); 1667b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) { 1668b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos allInteractions.addAll(loaderInteractions); 1669b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1670b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1671b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos // Sort the interactions by most recent 1672b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Collections.sort(allInteractions, new Comparator<ContactInteraction>() { 1673b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 1674b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public int compare(ContactInteraction a, ContactInteraction b) { 1675b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return a.getInteractionDate() >= b.getInteractionDate() ? -1 : 1; 1676b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1677b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos }); 1678b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 167997ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos // Wrap each interaction in its own list so that an icon is displayed for each entry 168060e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos List<List<Entry>> interactionsWrapper = new ArrayList<>(); 168197ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos for (Entry contactInteraction : contactInteractionsToEntries(allInteractions)) { 168297ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos List<Entry> entryListWrapper = new ArrayList<>(1); 168397ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos entryListWrapper.add(contactInteraction); 168497ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos interactionsWrapper.add(entryListWrapper); 168597ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos } 1686b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos if (allInteractions.size() > 0) { 168760e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos mRecentCard.initialize(interactionsWrapper, 1688b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN, 1689c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos /* isExpanded = */ mRecentCard.isExpanded(), /* isAlwaysExpanded = */ false, 16900cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mExpandingEntryCardViewListener, mScroller); 1691b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setVisibility(View.VISIBLE); 1692b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1693eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1694eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // About card is initialized along with the contact card, but since it appears after 1695eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // the recent card in the UI, we hold off until making it visible until the recent card 1696eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // is also ready to avoid stuttering. 1697eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (mAboutCard.shouldShow()) { 1698eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setVisibility(View.VISIBLE); 1699eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1700eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setVisibility(View.GONE); 1701eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1702b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 17038a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 17048a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 17058a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onStop() { 17068a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onStop(); 17078a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 17088a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mEntriesAndActionsTask != null) { 17098a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Once the activity is stopped, we will no longer want to bind mEntriesAndActionsTask's 17108a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // results on the UI thread. In some circumstances Activities are killed without 17118a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // onStop() being called. This is not a problem, because in these circumstances 17128a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the entire process will be killed. 17138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.cancel(/* mayInterruptIfRunning = */ false); 17148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 17158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 171623889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos 171723889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos /** 1718d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Returns true if it is possible to edit the current contact. 1719d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 1720d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private boolean isContactEditable() { 1721d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 1722d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1723d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1724a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell /** 1725a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell * Returns true if it is possible to share the current contact. 1726a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell */ 1727a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell private boolean isContactShareable() { 1728a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 1729a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell } 1730a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 17316095369885edcca566a812b551886e29c7ff8039Brian Attwell private Intent getEditContactIntent() { 1732d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Intent intent = new Intent(Intent.ACTION_EDIT, mLookupUri); 1733d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactLoader.cacheResult(); 1734d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 17356095369885edcca566a812b551886e29c7ff8039Brian Attwell return intent; 17366095369885edcca566a812b551886e29c7ff8039Brian Attwell } 17376095369885edcca566a812b551886e29c7ff8039Brian Attwell 17386095369885edcca566a812b551886e29c7ff8039Brian Attwell private void editContact() { 1739a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 17406095369885edcca566a812b551886e29c7ff8039Brian Attwell startActivityForResult(getEditContactIntent(), REQUEST_CODE_CONTACT_EDITOR_ACTIVITY); 1741d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1742d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1743d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void toggleStar(MenuItem starredMenuItem) { 1744d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Make sure there is a contact 1745d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mLookupUri != null) { 1746d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Read the current starred value from the UI instead of using the last 1747d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // loaded state. This allows rapid tapping without writing the same 1748d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // value several times 1749d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final boolean isStarred = starredMenuItem.isChecked(); 1750d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1751d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // To improve responsiveness, swap out the picture (and tag) in the UI already 1752333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, 1753d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.isDirectoryEntry(), mContactData.isUserProfile(), 1754d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell !isStarred); 1755d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1756d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Now perform the real save 1757eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Intent intent = ContactSaveService.createSetStarredIntent( 1758d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell QuickContactActivity.this, mLookupUri, !isStarred); 1759d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell startService(intent); 176035ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell 176135ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell final CharSequence accessibilityText = !isStarred 176235ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell ? getResources().getText(R.string.description_action_menu_add_star) 176335ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell : getResources().getText(R.string.description_action_menu_remove_star); 176435ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell // Accessibility actions need to have an associated view. We can't access the MenuItem's 176535ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell // underlying view, so put this accessibility action on the root view. 176635ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell mScroller.announceForAccessibility(accessibilityText); 1767d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1768d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1769d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1770752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** 1771752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell * Calls into the contacts provider to get a pre-authorized version of the given URI. 1772752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell */ 1773752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private Uri getPreAuthorizedUri(Uri uri) { 1774752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Bundle uriBundle = new Bundle(); 1775752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell uriBundle.putParcelable(ContactsContract.Authorization.KEY_URI_TO_AUTHORIZE, uri); 1776752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Bundle authResponse = getContentResolver().call( 1777752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell ContactsContract.AUTHORITY_URI, 1778752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell ContactsContract.Authorization.AUTHORIZATION_METHOD, 1779752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell null, 1780752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell uriBundle); 1781752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell if (authResponse != null) { 1782752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return (Uri) authResponse.getParcelable( 1783752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell ContactsContract.Authorization.KEY_AUTHORIZED_URI); 1784752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } else { 1785752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return uri; 1786752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1787752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 17882d150da246632b1649999cfabed776133b097775Brian Attwell 1789752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void shareContact() { 1790752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final String lookupKey = mContactData.getLookupKey(); 1791752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); 1792752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell if (mContactData.isUserProfile()) { 1793752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // User is sharing the profile. We don't want to force the receiver to have 1794752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // the highly-privileged READ_PROFILE permission, so we need to request a 1795752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // pre-authorized URI from the provider. 1796752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell shareUri = getPreAuthorizedUri(shareUri); 1797752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1798752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1799752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent intent = new Intent(Intent.ACTION_SEND); 1800752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell intent.setType(Contacts.CONTENT_VCARD_TYPE); 1801752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell intent.putExtra(Intent.EXTRA_STREAM, shareUri); 1802752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1803752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Launch chooser to share contact via 1804752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final CharSequence chooseTitle = getText(R.string.share_via); 1805752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent chooseIntent = Intent.createChooser(intent, chooseTitle); 1806752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1807752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell try { 1808a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 1809752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell this.startActivity(chooseIntent); 1810eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ActivityNotFoundException ex) { 1811752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show(); 1812752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1813752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1814752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1815752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** 1816752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell * Creates a launcher shortcut with the current contact. 1817752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell */ 1818752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void createLauncherShortcutWithContact() { 1819752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this, 1820752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell new OnShortcutIntentCreatedListener() { 1821752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1822752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell @Override 1823752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) { 1824752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Broadcast the shortcutIntent to the launcher to create a 1825752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // shortcut to this contact 1826752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); 1827752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell QuickContactActivity.this.sendBroadcast(shortcutIntent); 1828752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1829752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Send a toast to give feedback to the user that a shortcut to this 1830752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // contact was added to the launcher. 1831752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.makeText(QuickContactActivity.this, 1832752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell R.string.createContactShortcutSuccessful, 1833752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.LENGTH_SHORT).show(); 1834752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1835752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1836752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell }); 1837752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell builder.createContactShortcutIntent(mLookupUri); 1838752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 1839752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 1840d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 1841d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onCreateOptionsMenu(Menu menu) { 1842eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final MenuInflater inflater = getMenuInflater(); 1843d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell inflater.inflate(R.menu.quickcontact, menu); 1844d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 1845d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1846d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1847d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 1848d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onPrepareOptionsMenu(Menu menu) { 1849d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mContactData != null) { 1850d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem starredMenuItem = menu.findItem(R.id.menu_star); 1851333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, 1852d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.isDirectoryEntry(), mContactData.isUserProfile(), 1853d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.getStarred()); 1854a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 1855d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Configure edit MenuItem 1856d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem editMenuItem = menu.findItem(R.id.menu_edit); 1857d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(true); 1858d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData) || InvisibleContactUtil 1859d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell .isInvisibleAndAddable(mContactData, this)) { 186030cfd121ad8c8adb83cf417ff1d40a8ba1e3761dBrian Attwell editMenuItem.setIcon(R.drawable.ic_person_add_tinted_24dp); 18612e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell editMenuItem.setTitle(R.string.menu_add_contact); 1862d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 1863d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setIcon(R.drawable.ic_create_24dp); 18642e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell editMenuItem.setTitle(R.string.menu_editContact); 1865d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else { 1866d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(false); 1867d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1868a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 1869a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell final MenuItem shareMenuItem = menu.findItem(R.id.menu_share); 1870a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell shareMenuItem.setVisible(isContactShareable()); 1871a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 18728a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return true; 1873d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 18748a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return false; 1875d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1876d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 1877d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 1878d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onOptionsItemSelected(MenuItem item) { 1879d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell switch (item.getItemId()) { 1880d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell case R.id.menu_star: 1881d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell toggleStar(item); 1882d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 1883d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell case R.id.menu_edit: 1884d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData)) { 1885d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell DirectoryContactUtil.addToMyContacts(mContactData, this, getFragmentManager(), 1886d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener); 1887d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { 1888d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell InvisibleContactUtil.addToDefaultGroup(mContactData, this); 1889d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 1890d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editContact(); 1891d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 1892d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 1893752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell case R.id.menu_share: 1894752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell shareContact(); 1895752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return true; 1896752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell case R.id.menu_create_contact_shortcut: 1897752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell createLauncherShortcutWithContact(); 1898752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return true; 1899d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell default: 1900d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return super.onOptionsItemSelected(item); 1901d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 190223889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos } 1903edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann} 1904