QuickContactActivity.java revision ac679af994faece43536f1e8b2613f30c50300e1
1edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/* 2edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Copyright (C) 2009 The Android Open Source Project 3edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 4edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Licensed under the Apache License, Version 2.0 (the "License"); 5edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * you may not use this file except in compliance with the License. 6edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * You may obtain a copy of the License at 7edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 8edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * http://www.apache.org/licenses/LICENSE-2.0 9edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 10edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Unless required by applicable law or agreed to in writing, software 11edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * distributed under the License is distributed on an "AS IS" BASIS, 12edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * See the License for the specific language governing permissions and 14edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * limitations under the License. 15edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 16edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 17edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannpackage com.android.contacts.quickcontact; 18edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 19ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulosimport android.accounts.Account; 208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.animation.ArgbEvaluator; 21b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport android.animation.ObjectAnimator; 22edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.app.Activity; 23d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.app.Fragment; 24cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.app.LoaderManager.LoaderCallbacks; 25eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.app.SearchManager; 26752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.content.ActivityNotFoundException; 27edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.ContentUris; 28ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulosimport android.content.ContentValues; 296bb01347eab60f95deafdfe523b0c368707210f3Brian Attwellimport android.content.Context; 30edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.Intent; 31cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.content.Loader; 32dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulosimport android.content.pm.PackageManager; 33dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulosimport android.content.pm.ResolveInfo; 3423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulosimport android.content.res.Resources; 3531b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.Bitmap; 3695c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwellimport android.graphics.BitmapFactory; 378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.Color; 38eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuff; 39eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuffColorFilter; 4031b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.BitmapDrawable; 418a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.drawable.ColorDrawable; 4231b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.Drawable; 43edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.net.Uri; 4431b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.os.AsyncTask; 45edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.os.Bundle; 468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.os.Trace; 47eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.CalendarContract; 48752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.provider.ContactsContract; 49edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Email; 50eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Event; 51eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.GroupMembership; 52eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Identity; 53eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Im; 54eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Nickname; 55eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Note; 56eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Organization; 57edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Phone; 58eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Relation; 59edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.SipAddress; 60edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.StructuredPostal; 61edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Website; 62752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.provider.ContactsContract.Contacts; 6360e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulosimport android.provider.ContactsContract.Data; 64ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulosimport android.provider.ContactsContract.Directory; 65eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.DisplayNameSources; 66ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulosimport android.provider.ContactsContract.DataUsageFeedback; 67ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulosimport android.provider.ContactsContract.Intents; 68edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.QuickContact; 69edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.RawContacts; 7031b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.support.v7.graphics.Palette; 710319222b43927d4d9ce7e2a9070f3543661b5782Tyler Gunnimport android.telecom.PhoneAccount; 720319222b43927d4d9ce7e2a9070f3543661b5782Tyler Gunnimport android.telecom.TelecomManager; 73c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwellimport android.text.BidiFormatter; 747ce5352a70e8aaf120bf4f7bd05d595f46abb080Walter Jangimport android.text.SpannableString; 75c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwellimport android.text.TextDirectionHeuristics; 76edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.text.TextUtils; 77edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.util.Log; 782a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu; 792a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu.ContextMenuInfo; 80d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.Menu; 81d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.MenuInflater; 82eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.view.MenuItem; 83f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chenimport android.view.MotionEvent; 84edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View; 85edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View.OnClickListener; 862a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.View.OnCreateContextMenuListener; 8710d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawaimport android.view.WindowManager; 88edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.widget.Toast; 89d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.widget.Toolbar; 90edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 9172b3ab1d8a62f228a540b05f4ed6373e494c7d72Christine Chenimport com.android.contacts.ContactSaveService; 92d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.ContactsActivity; 932d150da246632b1649999cfabed776133b097775Brian Attwellimport com.android.contacts.NfcHandler; 94e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.R; 95eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.CallUtil; 962a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.common.ClipboardUtils; 97eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.Collapser; 98eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.ContactsUtils; 99bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwellimport com.android.contacts.common.activity.RequestPermissionsActivity; 100d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.common.editor.SelectAccountDialogFragment; 10170e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chenimport com.android.contacts.common.interactions.TouchPointManager; 10231b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport com.android.contacts.common.lettertiles.LetterTileDrawable; 103752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder; 104752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder.OnShortcutIntentCreatedListener; 1050d5588da244d0992c3ff8f25d0875fdf95a8c644Chiao Chengimport com.android.contacts.common.model.AccountTypeManager; 106cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.Contact; 107cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.ContactLoader; 108cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.RawContact; 109428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.account.AccountType; 110d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.common.model.account.AccountWithDataSet; 111cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.DataItem; 112428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.dataitem.DataKind; 113cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.EmailDataItem; 114eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.EventDataItem; 115cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.ImDataItem; 116eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NicknameDataItem; 117eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NoteDataItem; 118eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.OrganizationDataItem; 119b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.common.model.dataitem.PhoneDataItem; 120eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.RelationDataItem; 121eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.SipAddressDataItem; 122eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredNameDataItem; 123eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredPostalDataItem; 124eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.WebsiteDataItem; 125c6100ffd22ae176a3e84a1062d8cb92d955faef2Brian Attwellimport com.android.contacts.common.util.ImplicitIntentsUtil; 126eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.util.DateUtils; 127faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwellimport com.android.contacts.common.util.MaterialColorMapUtils; 128faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwellimport com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette; 129d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwellimport com.android.contacts.common.util.ViewUtil; 130333091ae754ddfc25714c14b9b89534be24379f9Paul Soulosimport com.android.contacts.detail.ContactDisplayUtils; 131f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulosimport com.android.contacts.editor.ContactEditorFragment; 1325a7a23bdb698b8e741a425c9617c5e33e6314cddWalter Jangimport com.android.contacts.editor.EditorIntents; 133899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport com.android.contacts.interactions.CalendarInteractionsLoader; 134ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulosimport com.android.contacts.interactions.CallLogInteractionsLoader; 1358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport com.android.contacts.interactions.ContactDeletionInteraction; 136b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.ContactInteraction; 137b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.SmsInteractionsLoader; 1382d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.Entry; 1392a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryContextMenuInfo; 1402ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryTag; 141e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwellimport com.android.contacts.quickcontact.ExpandingEntryCardView.ExpandingEntryCardViewListener; 142493f8d14b1d974a2939a110ce89fa68e0c915c36Brian Attwellimport com.android.contacts.quickcontact.WebAddress.ParseException; 143e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.util.ImageViewDrawableSetter; 144eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.PhoneCapabilityTester; 145b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.util.SchedulingUtils; 146eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.StructuredPostalUtils; 147b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller; 148b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener; 14902eaf11669d25fd885606b3b0700358323532cddBrian Attwellimport com.android.contacts.widget.QuickContactImageView; 15056bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwellimport com.android.contactsbind.HelpUtils; 15156bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell 152e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.google.common.collect.Lists; 153e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng 15482a5a35c1a2b83b4118bcba56625f6f25e9663d0Jay Shraunerimport java.lang.SecurityException; 1552d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport java.util.ArrayList; 156899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport java.util.Arrays; 157eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Calendar; 158b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Collections; 159b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Comparator; 160eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Date; 161edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.HashMap; 162edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.List; 163b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Map; 16412ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shraunerimport java.util.concurrent.ConcurrentHashMap; 165edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 166edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/** 167edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Mostly translucent {@link Activity} that shows QuickContact dialog. It loads 168edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * data asynchronously, and then shows a popup with details centered around 169edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * {@link Intent#getSourceBounds()}. 170edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 171d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellpublic class QuickContactActivity extends ContactsActivity { 1728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1738a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell /** 1748a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * QuickContacts immediately takes up the full screen. All possible information is shown. 1758a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * This value for {@link android.provider.ContactsContract.QuickContact#EXTRA_MODE} 1768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell * should only be used by the Contacts app. 1778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell */ 1788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public static final int MODE_FULLY_EXPANDED = 4; 1798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 180edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String TAG = "QuickContact"; 181edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1829b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final String KEY_THEME_COLOR = "theme_color"; 1839b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 1849b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private static final int ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION = 150; 1858a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private static final int REQUEST_CODE_CONTACT_EDITOR_ACTIVITY = 1; 1860b267fec5cb5b2d836057b16d0085be349be5243Brian Attwell private static final int SCRIM_COLOR = Color.argb(0xC8, 0, 0, 0); 187ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos private static final int REQUEST_CODE_CONTACT_SELECTION_ACTIVITY = 2; 188ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos private static final String MIMETYPE_SMS = "vnd.android-dir/mms-sms"; 189dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 190752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** This is the Intent action to install a shortcut in the launcher. */ 191752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private static final String ACTION_INSTALL_SHORTCUT = 192752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell "com.android.launcher.action.INSTALL_SHORTCUT"; 193edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 194edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @SuppressWarnings("deprecation") 195edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final String LEGACY_AUTHORITY = android.provider.Contacts.AUTHORITY; 196edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 197e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String MIMETYPE_GPLUS_PROFILE = 198e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos "vnd.android.cursor.item/vnd.googleplus.profile"; 1996a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String GPLUS_PROFILE_DATA_5_ADD_TO_CIRCLE = "addtocircle"; 2006a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String GPLUS_PROFILE_DATA_5_VIEW_PROFILE = "view"; 201e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos private static final String MIMETYPE_HANGOUTS = 202e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos "vnd.android.cursor.item/vnd.googleplus.profile.comm"; 2036a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String HANGOUTS_DATA_5_VIDEO = "hangout"; 2046a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final String HANGOUTS_DATA_5_MESSAGE = "conversation"; 20548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos private static final String CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY = 20648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos "com.android.contacts.quickcontact.QuickContactActivity"; 207e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 20863176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell /** 20963176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell * The URI used to load the the Contact. Once the contact is loaded, use Contact#getLookupUri() 21063176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell * instead of referencing this URI. 21163176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell */ 212edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private Uri mLookupUri; 213edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private String[] mExcludeMimes; 2148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mExtraMode; 21505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell private String mExtraPrioritizedMimeType; 2168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int mStatusBarColor; 2178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private boolean mHasAlreadyBeenOpened; 21897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos private boolean mOnlyOnePhoneNumber; 21997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos private boolean mOnlyOneEmail; 220edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 22102eaf11669d25fd885606b3b0700358323532cddBrian Attwell private QuickContactImageView mPhotoView; 222eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mContactCard; 2236095369885edcca566a812b551886e29c7ff8039Brian Attwell private ExpandingEntryCardView mNoContactDetailsCard; 224b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private ExpandingEntryCardView mRecentCard; 225eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private ExpandingEntryCardView mAboutCard; 226b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private MultiShrinkScroller mScroller; 227d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private SelectAccountDialogFragmentListener mSelectAccountFragmentListener; 2286bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private AsyncTask<Void, Void, Cp2DataCardModel> mEntriesAndActionsTask; 22930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell private AsyncTask<Void, Void, Void> mRecentDataTask; 2306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 2316bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * The last copy of Cp2DataCardModel that was passed to {@link #populateContactAndAboutCard}. 2326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 2336bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private Cp2DataCardModel mCachedCp2DataCardModel; 234f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell /** 235f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * This scrim's opacity is controlled in two different ways. 1) Before the initial entrance 236f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * animation finishes, the opacity is animated by a value animator. This is designed to 237f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * distract the user from the length of the initial loading time. 2) After the initial 238f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell * entrance animation, the opacity is directly related to scroll position. 239f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell */ 2409b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private ColorDrawable mWindowScrim; 241f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell private boolean mIsEntranceAnimationFinished; 242a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell private MaterialColorMapUtils mMaterialColorMapUtils; 2438477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell private boolean mIsExitAnimationInProgress; 2448571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell private boolean mHasComputedThemeColor; 245edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 246a42ef76251778161d27bc07db214b8c81720e476Paul Soulos /** 247a42ef76251778161d27bc07db214b8c81720e476Paul Soulos * Used to stop the ExpandingEntry cards from adjusting between an entry click and the intent 248a42ef76251778161d27bc07db214b8c81720e476Paul Soulos * being launched. 249a42ef76251778161d27bc07db214b8c81720e476Paul Soulos */ 250a42ef76251778161d27bc07db214b8c81720e476Paul Soulos private boolean mHasIntentLaunched; 251a42ef76251778161d27bc07db214b8c81720e476Paul Soulos 2526cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee private Contact mContactData; 2539815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann private ContactLoader mContactLoader; 2549b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell private PorterDuffColorFilter mColorFilter; 2558e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell private int mColorFilterColor; 2569815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann 2579758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter(); 2589758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus 259edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 260cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * {@link #LEADING_MIMETYPES} is used to sort MIME-types. 261edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * 262edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * <p>The MIME-types in {@link #LEADING_MIMETYPES} appear in the front of the dialog, 263edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * in the order specified here.</p> 264edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 265edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private static final List<String> LEADING_MIMETYPES = Lists.newArrayList( 266cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos Phone.CONTENT_ITEM_TYPE, SipAddress.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE, 267405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos StructuredPostal.CONTENT_ITEM_TYPE); 268edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 269a153dba33c2152332c5706178a367f52b0550723Paul Soulos private static final List<String> SORTED_ABOUT_CARD_MIMETYPES = Lists.newArrayList( 270a153dba33c2152332c5706178a367f52b0550723Paul Soulos Nickname.CONTENT_ITEM_TYPE, 271a153dba33c2152332c5706178a367f52b0550723Paul Soulos // Phonetic name is inserted after nickname if it is available. 272a153dba33c2152332c5706178a367f52b0550723Paul Soulos // No mimetype for phonetic name exists. 273a153dba33c2152332c5706178a367f52b0550723Paul Soulos Website.CONTENT_ITEM_TYPE, 274a153dba33c2152332c5706178a367f52b0550723Paul Soulos Organization.CONTENT_ITEM_TYPE, 275a153dba33c2152332c5706178a367f52b0550723Paul Soulos Event.CONTENT_ITEM_TYPE, 276a153dba33c2152332c5706178a367f52b0550723Paul Soulos Relation.CONTENT_ITEM_TYPE, 277a153dba33c2152332c5706178a367f52b0550723Paul Soulos Im.CONTENT_ITEM_TYPE, 278a153dba33c2152332c5706178a367f52b0550723Paul Soulos GroupMembership.CONTENT_ITEM_TYPE, 279a153dba33c2152332c5706178a367f52b0550723Paul Soulos Identity.CONTENT_ITEM_TYPE, 280a153dba33c2152332c5706178a367f52b0550723Paul Soulos Note.CONTENT_ITEM_TYPE); 281eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 282c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwell private static final BidiFormatter sBidiFormatter = BidiFormatter.getInstance(); 283c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwell 284b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background contact loader */ 285b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_CONTACT_ID = 0; 286b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 287ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final String KEY_LOADER_EXTRA_PHONES = 288ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_PHONES"; 289ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 290b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /** Id for the background Sms Loader */ 291b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int LOADER_SMS_ID = 1; 292b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private static final int MAX_SMS_RETRIEVE = 3; 293ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 294ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the back Calendar Loader */ 295899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int LOADER_CALENDAR_ID = 2; 296ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final String KEY_LOADER_EXTRA_EMAILS = 297ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_EMAILS"; 298899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_PAST_CALENDAR_RETRIEVE = 3; 299899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final int MAX_FUTURE_CALENDAR_RETRIEVE = 3; 300899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 30140d7a65c6e68967f3f486715b194c144d93c296fPaul Soulos 1L * 24L * 60L * 60L * 1000L /* 1 day */; 302899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos private static final long FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = 30340d7a65c6e68967f3f486715b194c144d93c296fPaul Soulos 7L * 24L * 60L * 60L * 1000L /* 7 days */; 304899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 305ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos /** Id for the background Call Log Loader */ 306ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int LOADER_CALL_LOG_ID = 3; 307ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int MAX_CALL_LOG_RETRIEVE = 3; 3086095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int MIN_NUM_CONTACT_ENTRIES_SHOWN = 3; 3096095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN = 3; 3106095369885edcca566a812b551886e29c7ff8039Brian Attwell private static final int CARD_ENTRY_ID_EDIT_CONTACT = -2; 311ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 312ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 313ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos private static final int[] mRecentLoaderIds = new int[]{ 314ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_SMS_ID, 315ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALENDAR_ID, 316ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID}; 31712ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner /** 31812ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner * ConcurrentHashMap constructor params: 4 is initial table size, 0.9f is 31912ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner * load factor before resizing, 1 means we only expect a single thread to 32012ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner * write to the map so make only a single shard 32112ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner */ 32212ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner private Map<Integer, List<ContactInteraction>> mRecentLoaderResults = 32312ac1e6f15ae9e4d4e453e7f28467fdd561939a3Jay Shrauner new ConcurrentHashMap<>(4, 0.9f, 1); 324b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 325d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private static final String FRAGMENT_TAG_SELECT_ACCOUNT = "select_account_fragment"; 3266cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee 3272d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos final OnClickListener mEntryClickHandler = new OnClickListener() { 3282d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos @Override 3292d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos public void onClick(View v) { 3302ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final Object entryTagObject = v.getTag(); 3312ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos if (entryTagObject == null || !(entryTagObject instanceof EntryTag)) { 3322ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos Log.w(TAG, "EntryTag was not used correctly"); 3336095369885edcca566a812b551886e29c7ff8039Brian Attwell return; 3346095369885edcca566a812b551886e29c7ff8039Brian Attwell } 3352ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final EntryTag entryTag = (EntryTag) entryTagObject; 3362ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final Intent intent = entryTag.getIntent(); 3372ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos final int dataId = entryTag.getId(); 3382ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos 3392ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos if (dataId == CARD_ENTRY_ID_EDIT_CONTACT) { 3402ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos editContact(); 3412d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos return; 3422d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 343ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 34419c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO // Pass the touch point through the intent for use in the InCallUI 34519c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO if (Intent.ACTION_CALL.equals(intent.getAction())) { 34619c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO if (TouchPointManager.getInstance().hasValidPoint()) { 34719c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Bundle extras = new Bundle(); 34819c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO extras.putParcelable(TouchPointManager.TOUCH_POINT, 34919c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO TouchPointManager.getInstance().getPoint()); 35019c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras); 35119c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } 35219c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } 35319c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO 35419c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 35519c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO 35619c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO mHasIntentLaunched = true; 35719c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO try { 35819c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO startActivity(intent); 35919c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } catch (SecurityException ex) { 36019c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.makeText(QuickContactActivity.this, R.string.missing_app, 36119c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.LENGTH_SHORT).show(); 36219c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Log.e(TAG, "QuickContacts does not have permission to launch " 36319c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO + intent); 36419c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } catch (ActivityNotFoundException ex) { 36519c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.makeText(QuickContactActivity.this, R.string.missing_app, 36619c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO Toast.LENGTH_SHORT).show(); 36719c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO } 36819c83e3f0f88c8598ab174660ae7a844d7d13df1LIANGTAO GAO 369ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Default to USAGE_TYPE_CALL. Usage is summed among all types for sorting each data id 370ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // so the exact usage type is not necessary in all cases 371ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos String usageType = DataUsageFeedback.USAGE_TYPE_CALL; 372ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 37320bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos final Uri intentUri = intent.getData(); 37420bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos if ((intentUri != null && intentUri.getScheme() != null && 3751cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner intentUri.getScheme().equals(ContactsUtils.SCHEME_SMSTO)) || 376ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos (intent.getType() != null && intent.getType().equals(MIMETYPE_SMS))) { 377ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos usageType = DataUsageFeedback.USAGE_TYPE_SHORT_TEXT; 378ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 379ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 380ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos // Data IDs start at 1 so anything less is invalid 381ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (dataId > 0) { 38220bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos final Uri dataUsageUri = DataUsageFeedback.FEEDBACK_URI.buildUpon() 383ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendPath(String.valueOf(dataId)) 384ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, usageType) 385ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos .build(); 386ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final boolean successful = getContentResolver().update( 38720bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos dataUsageUri, new ContentValues(), null, null) > 0; 388ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos if (!successful) { 389ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Log.w(TAG, "DataUsageFeedback increment failed"); 390ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 391ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } else { 392ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos Log.w(TAG, "Invalid Data ID"); 393ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos } 394ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 39570e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen // Pass the touch point through the intent for use in the InCallUI 39670e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen if (Intent.ACTION_CALL.equals(intent.getAction())) { 3971f8a3fda87bf61e579d61e3fdd246548943d070aNancy Chen if (TouchPointManager.getInstance().hasValidPoint()) { 39870e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen Bundle extras = new Bundle(); 3991f8a3fda87bf61e579d61e3fdd246548943d070aNancy Chen extras.putParcelable(TouchPointManager.TOUCH_POINT, 4001f8a3fda87bf61e579d61e3fdd246548943d070aNancy Chen TouchPointManager.getInstance().getPoint()); 4010319222b43927d4d9ce7e2a9070f3543661b5782Tyler Gunn intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras); 40270e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen } 40370e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen } 40470e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen 405793e73c859ed839c28cc37d80d62bde0a361c78aPaul Soulos intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 406793e73c859ed839c28cc37d80d62bde0a361c78aPaul Soulos 407a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 408417309a770568d7b278abc91c46a739020e48157Jay Shrauner try { 409c6100ffd22ae176a3e84a1062d8cb92d955faef2Brian Attwell ImplicitIntentsUtil.startActivityInAppIfPossible(QuickContactActivity.this, intent); 41082a5a35c1a2b83b4118bcba56625f6f25e9663d0Jay Shrauner } catch (SecurityException ex) { 41182a5a35c1a2b83b4118bcba56625f6f25e9663d0Jay Shrauner Toast.makeText(QuickContactActivity.this, R.string.missing_app, 41282a5a35c1a2b83b4118bcba56625f6f25e9663d0Jay Shrauner Toast.LENGTH_SHORT).show(); 41382a5a35c1a2b83b4118bcba56625f6f25e9663d0Jay Shrauner Log.e(TAG, "QuickContacts does not have permission to launch " 41482a5a35c1a2b83b4118bcba56625f6f25e9663d0Jay Shrauner + intent); 415417309a770568d7b278abc91c46a739020e48157Jay Shrauner } catch (ActivityNotFoundException ex) { 416417309a770568d7b278abc91c46a739020e48157Jay Shrauner Toast.makeText(QuickContactActivity.this, R.string.missing_app, 417417309a770568d7b278abc91c46a739020e48157Jay Shrauner Toast.LENGTH_SHORT).show(); 418417309a770568d7b278abc91c46a739020e48157Jay Shrauner } 4192d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos } 4202d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos }; 4212d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos 422e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell final ExpandingEntryCardViewListener mExpandingEntryCardViewListener 423e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell = new ExpandingEntryCardViewListener() { 424e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell @Override 425e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell public void onCollapse(int heightDelta) { 426e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell mScroller.prepareForShrinkingScrollChild(heightDelta); 427e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell } 4280cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos 4290cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos @Override 430245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell public void onExpand() { 431245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell mScroller.setDisableTouchesForSuppressLayout(/* areTouchesDisabled = */ true); 432245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell } 433245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell 434245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell @Override 435245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell public void onExpandDone() { 436245d3d2000150cbb21111370f42addaeeb1b10a0Brian Attwell mScroller.setDisableTouchesForSuppressLayout(/* areTouchesDisabled = */ false); 4370cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos } 438e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell }; 439e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell 44097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos private interface ContextMenuIds { 44197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos static final int COPY_TEXT = 0; 44297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos static final int CLEAR_DEFAULT = 1; 44397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos static final int SET_DEFAULT = 2; 44497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 44597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 4462a4207fb39330e840436215c896cde911489e111Paul Soulos private final OnCreateContextMenuListener mEntryContextMenuListener = 4472a4207fb39330e840436215c896cde911489e111Paul Soulos new OnCreateContextMenuListener() { 4482a4207fb39330e840436215c896cde911489e111Paul Soulos @Override 4492a4207fb39330e840436215c896cde911489e111Paul Soulos public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 4502a4207fb39330e840436215c896cde911489e111Paul Soulos if (menuInfo == null) { 4512a4207fb39330e840436215c896cde911489e111Paul Soulos return; 4522a4207fb39330e840436215c896cde911489e111Paul Soulos } 45397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final EntryContextMenuInfo info = (EntryContextMenuInfo) menuInfo; 4542a4207fb39330e840436215c896cde911489e111Paul Soulos menu.setHeaderTitle(info.getCopyText()); 45597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menu.add(ContextMenu.NONE, ContextMenuIds.COPY_TEXT, 45697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ContextMenu.NONE, getString(R.string.copy_text)); 45797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 45897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Don't allow setting or clearing of defaults for non-editable contacts 45997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (!isContactEditable()) { 46097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return; 46197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 46297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 46397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final String selectedMimeType = info.getMimeType(); 46497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 46597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Defaults to true will only enable the detail to be copied to the clipboard. 46697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos boolean onlyOneOfMimeType = true; 46797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 46897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Only allow primary support for Phone and Email content types 46997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (Phone.CONTENT_ITEM_TYPE.equals(selectedMimeType)) { 47097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos onlyOneOfMimeType = mOnlyOnePhoneNumber; 47197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } else if (Email.CONTENT_ITEM_TYPE.equals(selectedMimeType)) { 47297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos onlyOneOfMimeType = mOnlyOneEmail; 47397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 47497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos 47597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos // Checking for previously set default 47697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (info.isSuperPrimary()) { 47797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menu.add(ContextMenu.NONE, ContextMenuIds.CLEAR_DEFAULT, 47897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ContextMenu.NONE, getString(R.string.clear_default)); 47997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } else if (!onlyOneOfMimeType) { 48097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menu.add(ContextMenu.NONE, ContextMenuIds.SET_DEFAULT, 48197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ContextMenu.NONE, getString(R.string.set_default)); 48297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 4832a4207fb39330e840436215c896cde911489e111Paul Soulos } 4842a4207fb39330e840436215c896cde911489e111Paul Soulos }; 4852a4207fb39330e840436215c896cde911489e111Paul Soulos 4862a4207fb39330e840436215c896cde911489e111Paul Soulos @Override 4872a4207fb39330e840436215c896cde911489e111Paul Soulos public boolean onContextItemSelected(MenuItem item) { 4882a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo menuInfo; 4892a4207fb39330e840436215c896cde911489e111Paul Soulos try { 4902a4207fb39330e840436215c896cde911489e111Paul Soulos menuInfo = (EntryContextMenuInfo) item.getMenuInfo(); 4912a4207fb39330e840436215c896cde911489e111Paul Soulos } catch (ClassCastException e) { 4922a4207fb39330e840436215c896cde911489e111Paul Soulos Log.e(TAG, "bad menuInfo", e); 4932a4207fb39330e840436215c896cde911489e111Paul Soulos return false; 4942a4207fb39330e840436215c896cde911489e111Paul Soulos } 4952a4207fb39330e840436215c896cde911489e111Paul Soulos 49697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos switch (item.getItemId()) { 49797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos case ContextMenuIds.COPY_TEXT: 49897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos ClipboardUtils.copyText(this, menuInfo.getCopyLabel(), menuInfo.getCopyText(), 49997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos true); 50097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return true; 50197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos case ContextMenuIds.SET_DEFAULT: 50297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final Intent setIntent = ContactSaveService.createSetSuperPrimaryIntent(this, 50397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menuInfo.getId()); 50497f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos this.startService(setIntent); 50597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return true; 50697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos case ContextMenuIds.CLEAR_DEFAULT: 50797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos final Intent clearIntent = ContactSaveService.createClearPrimaryIntent(this, 50897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos menuInfo.getId()); 50997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos this.startService(clearIntent); 51097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos return true; 51197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos default: 51297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos throw new IllegalArgumentException("Unknown menu option " + item.getItemId()); 51397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 5142a4207fb39330e840436215c896cde911489e111Paul Soulos } 5152a4207fb39330e840436215c896cde911489e111Paul Soulos 516d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell /** 517d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Headless fragment used to handle account selection callbacks invoked from 518d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * {@link DirectoryContactUtil}. 519d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 520d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public static class SelectAccountDialogFragmentListener extends Fragment 521d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell implements SelectAccountDialogFragment.Listener { 522d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 523d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private QuickContactActivity mQuickContactActivity; 524d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 525d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public SelectAccountDialogFragmentListener() {} 526d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 527d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 528d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void onAccountChosen(AccountWithDataSet account, Bundle extraArgs) { 529d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell DirectoryContactUtil.createCopy(mQuickContactActivity.mContactData.getContentValues(), 530d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell account, mQuickContactActivity); 531d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 532d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 533d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 534d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void onAccountSelectorCancelled() {} 535d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 536d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell /** 537d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Set the parent activity. Since rotation can cause this fragment to be used across 538d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * more than one activity instance, we need to explicitly set this value instead 539d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * of making this class non-static. 540d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 541d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public void setQuickContactActivity(QuickContactActivity quickContactActivity) { 542d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mQuickContactActivity = quickContactActivity; 543d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 544d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 545d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 546b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell final MultiShrinkScrollerListener mMultiShrinkScrollerListener 547b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell = new MultiShrinkScrollerListener() { 548b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 549b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onScrolledOffBottom() { 550f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell finish(); 551b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 5528a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 5538a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 5548a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onEnterFullscreen() { 5558a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 5568a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 5578a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 5588a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 5598a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void onExitFullscreen() { 5608a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell updateStatusBarColor(); 5618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 5628477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 5638477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 5648477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell public void onStartScrollOffBottom() { 5658477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mIsExitAnimationInProgress = true; 5668477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 5678477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell 5688477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell @Override 569f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void onEntranceAnimationDone() { 570f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = true; 571f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 572f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 573f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell @Override 574f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void onTransparentViewHeightChange(float ratio) { 575f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell if (mIsEntranceAnimationFinished) { 576f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mWindowScrim.setAlpha((int) (0xFF * ratio)); 5778477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 5788477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 579b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell }; 580b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 581eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 582eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 583eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Data items are compared to the same mimetype based off of three qualities: 584eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 1. Super primary 585eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 2. Primary 586eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * 3. Times used 587eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 588eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<DataItem> mWithinMimeTypeDataItemComparator = 589eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<DataItem>() { 590eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 591eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(DataItem lhs, DataItem rhs) { 592eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!lhs.getMimeType().equals(rhs.getMimeType())) { 593eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Log.wtf(TAG, "Comparing DataItems with different mimetypes lhs.getMimeType(): " + 594eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getMimeType() + " rhs.getMimeType(): " + rhs.getMimeType()); 595eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 596eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 597eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 598eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lhs.isSuperPrimary()) { 599eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 600eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (rhs.isSuperPrimary()) { 601eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 602eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lhs.isPrimary() && !rhs.isPrimary()) { 603eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 604eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (!lhs.isPrimary() && rhs.isPrimary()) { 605eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 606eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 607eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = 608eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 609eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = 610eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 611eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 612eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return rhsTimesUsed - lhsTimesUsed; 613eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 614eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 615eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 616eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 617cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos /** 618cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos * Sorts among different mimetypes based off: 61905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 1. Whether one of the mimetypes is the prioritized mimetype 62005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 2. Number of times used 62105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 3. Last time used 62205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell * 4. Statically defined 623cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos */ 624eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final Comparator<List<DataItem>> mAmongstMimeTypeDataItemComparator = 625eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos new Comparator<List<DataItem>> () { 626eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos @Override 627eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos public int compare(List<DataItem> lhsList, List<DataItem> rhsList) { 62805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final DataItem lhs = lhsList.get(0); 62905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final DataItem rhs = rhsList.get(0); 63005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final String lhsMimeType = lhs.getMimeType(); 63105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final String rhsMimeType = rhs.getMimeType(); 63205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell 63305287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 1. Whether one of the mimetypes is the prioritized mimetype 63405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (!TextUtils.isEmpty(mExtraPrioritizedMimeType) && !lhsMimeType.equals(rhsMimeType)) { 63505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (rhsMimeType.equals(mExtraPrioritizedMimeType)) { 63605287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return 1; 63705287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 63805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (lhsMimeType.equals(mExtraPrioritizedMimeType)) { 63905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return -1; 64005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 64105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 64205287bf0cea303b93802a629aa883fb6322ca342Brian Attwell 64305287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 2. Number of times used 644eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int lhsTimesUsed = lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); 645eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int rhsTimesUsed = rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); 646eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final int timesUsedDifference = rhsTimesUsed - lhsTimesUsed; 647eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (timesUsedDifference != 0) { 648eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return timesUsedDifference; 649eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 650eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 65105287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 3. Last time used 652eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lhsLastTimeUsed = 653eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos lhs.getLastTimeUsed() == null ? 0 : lhs.getLastTimeUsed(); 654eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long rhsLastTimeUsed = 655eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos rhs.getLastTimeUsed() == null ? 0 : rhs.getLastTimeUsed(); 656eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final long lastTimeUsedDifference = rhsLastTimeUsed - lhsLastTimeUsed; 657eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (lastTimeUsedDifference > 0) { 658eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 1; 659eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (lastTimeUsedDifference < 0) { 660eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return -1; 661eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 662eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 66305287bf0cea303b93802a629aa883fb6322ca342Brian Attwell // 4. Resort to a statically defined mimetype order. 66405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (!lhsMimeType.equals(rhsMimeType)) { 66505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell for (String mimeType : LEADING_MIMETYPES) { 66605287bf0cea303b93802a629aa883fb6322ca342Brian Attwell if (lhsMimeType.equals(mimeType)) { 66705287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return -1; 66805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } else if (rhsMimeType.equals(mimeType)) { 66905287bf0cea303b93802a629aa883fb6322ca342Brian Attwell return 1; 67005287bf0cea303b93802a629aa883fb6322ca342Brian Attwell } 671eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 672eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 673eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return 0; 674eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 675eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos }; 676eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 677edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann @Override 678f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen public boolean dispatchTouchEvent(MotionEvent ev) { 679f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen if (ev.getAction() == MotionEvent.ACTION_DOWN) { 680f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); 681f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen } 682f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen return super.dispatchTouchEvent(ev); 683f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen } 684f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen 685f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen @Override 6868a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onCreate(Bundle savedInstanceState) { 6878a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onCreate()"); 6888a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onCreate(savedInstanceState); 689edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 690bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell if (RequestPermissionsActivity.startPermissionActivity(this)) { 691bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell return; 692bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell } 693bdd32641ae2c2bc6214608cc5712dfb2b96e0305Brian Attwell 6948a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getWindow().setStatusBarColor(Color.TRANSPARENT); 6952426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann 696d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(getIntent()); 697dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 69810d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa // Show QuickContact in front of soft input 69910d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 70010d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 70110d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa 702edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann setContentView(R.layout.quickcontact_activity); 703edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 704a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell mMaterialColorMapUtils = new MaterialColorMapUtils(getResources()); 705a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell 7060cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mScroller = (MultiShrinkScroller) findViewById(R.id.multiscroller); 7070cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos 708eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard = (ExpandingEntryCardView) findViewById(R.id.communication_card); 7096095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard = (ExpandingEntryCardView) findViewById(R.id.no_contact_data_card); 710b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card); 711eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard = (ExpandingEntryCardView) findViewById(R.id.about_card); 712edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 7136095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setOnClickListener(mEntryClickHandler); 714eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setOnClickListener(mEntryClickHandler); 715eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setExpandButtonText( 71623889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos getResources().getString(R.string.expanding_entry_card_view_see_all)); 7172a4207fb39330e840436215c896cde911489e111Paul Soulos mContactCard.setOnCreateContextMenuListener(mEntryContextMenuListener); 718b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 719b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setOnClickListener(mEntryClickHandler); 720b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentCard.setTitle(getResources().getString(R.string.recent_card_title)); 721edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 722eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mAboutCard.setOnClickListener(mEntryClickHandler); 7232a4207fb39330e840436215c896cde911489e111Paul Soulos mAboutCard.setOnCreateContextMenuListener(mEntryContextMenuListener); 724eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 72502eaf11669d25fd885606b3b0700358323532cddBrian Attwell mPhotoView = (QuickContactImageView) findViewById(R.id.photo); 72663176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell final View transparentView = findViewById(R.id.transparent_view); 7270d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell if (mScroller != null) { 72863176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell transparentView.setOnClickListener(new OnClickListener() { 7290d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell @Override 7300d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell public void onClick(View v) { 7310d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell mScroller.scrollOffBottom(); 7320d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 7330d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell }); 7340d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell } 735edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 736d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell // Allow a shadow to be shown under the toolbar. 737d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell ViewUtil.addRectangularOutlineProvider(findViewById(R.id.toolbar_parent), getResources()); 738d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell 739d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 740d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell setActionBar(toolbar); 7419b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getActionBar().setTitle(null); 7429b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // Put a TextView with a known resource id into the ActionBar. This allows us to easily 7439b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // find the correct TextView location & size later. 7449b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell toolbar.addView(getLayoutInflater().inflate(R.layout.quickcontact_title_placeholder, null)); 7456219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee 7468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = savedInstanceState != null; 747f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = mHasAlreadyBeenOpened; 7489b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mWindowScrim = new ColorDrawable(SCRIM_COLOR); 749f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mWindowScrim.setAlpha(0); 7509b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell getWindow().setBackgroundDrawable(mWindowScrim); 751edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 752c33ae17c9816b770041ee1f9ccde10e7c7eee491Brian Attwell mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED); 753ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // mScroller needs to perform asynchronous measurements after initalize(), therefore 754ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // we can't mark this as GONE. 755ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.INVISIBLE); 7568a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 7579b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell setHeaderNameText(R.string.missing_name); 7589b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 759d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener= (SelectAccountDialogFragmentListener) getFragmentManager() 760d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell .findFragmentByTag(FRAGMENT_TAG_SELECT_ACCOUNT); 761d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mSelectAccountFragmentListener == null) { 762d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener = new SelectAccountDialogFragmentListener(); 763d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell getFragmentManager().beginTransaction().add(0, mSelectAccountFragmentListener, 764d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell FRAGMENT_TAG_SELECT_ACCOUNT).commit(); 765d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener.setRetainInstance(true); 766d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 767d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mSelectAccountFragmentListener.setQuickContactActivity(this); 76823889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos 769f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ true, 770f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell new Runnable() { 771f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell @Override 772f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell public void run() { 773f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell if (!mHasAlreadyBeenOpened) { 774f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell // The initial scrim opacity must match the scrim opacity that would be 775f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell // achieved by scrolling to the starting position. 776f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final float alphaRatio = mExtraMode == MODE_FULLY_EXPANDED ? 777f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 1 : mScroller.getStartingTransparentHeightRatio(); 778f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final int duration = getResources().getInteger( 779f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell android.R.integer.config_shortAnimTime); 780f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell final int desiredAlpha = (int) (0xFF * alphaRatio); 781f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell ObjectAnimator o = ObjectAnimator.ofInt(mWindowScrim, "alpha", 0, 782f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell desiredAlpha).setDuration(duration); 783f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 784f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell o.start(); 785f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 786f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell } 787f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell }); 788f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell 7899b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (savedInstanceState != null) { 7909b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell final int color = savedInstanceState.getInt(KEY_THEME_COLOR, 0); 791ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 792ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell new Runnable() { 793ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell @Override 794ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell public void run() { 795ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for the pre draw before setting the initial scroll 796ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // value. Prior to pre draw all scroll values are invalid. 797ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (mHasAlreadyBeenOpened) { 798ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setVisibility(View.VISIBLE); 799ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell mScroller.setScroll(mScroller.getScrollNeededToBeFullScreen()); 800ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 801ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // Need to wait for pre draw for setting the theme color. Setting the 802ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // header tint before the MultiShrinkScroller has been measured will 803ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell // cause incorrect tinting calculations. 804ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell if (color != 0) { 805a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell setThemeColor(mMaterialColorMapUtils 806a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell .calculatePrimaryAndSecondaryColor(color)); 8079b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 808ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell } 809ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell }); 8109b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 8119b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 8128a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 8138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 815405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos @Override 816405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos protected void onActivityResult(int requestCode, int resultCode, Intent data) { 8178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (requestCode == REQUEST_CODE_CONTACT_EDITOR_ACTIVITY && 8188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell resultCode == ContactDeletionInteraction.RESULT_CODE_DELETED) { 8198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // The contact that we were showing has been deleted. 8208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell finish(); 821ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } else if (requestCode == REQUEST_CODE_CONTACT_SELECTION_ACTIVITY && 822ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos resultCode != RESULT_CANCELED) { 823ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos processIntent(data); 824b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 8258a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 826dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 8278a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 8288a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onNewIntent(Intent intent) { 8298a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onNewIntent(intent); 8308a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 831f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell mIsEntranceAnimationFinished = true; 8328571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = false; 833d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell processIntent(intent); 834d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 835d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 8369b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell @Override 8379b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell public void onSaveInstanceState(Bundle savedInstanceState) { 8389b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell super.onSaveInstanceState(savedInstanceState); 8399b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mColorFilter != null) { 8408e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell savedInstanceState.putInt(KEY_THEME_COLOR, mColorFilterColor); 8419b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 8429b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 8439b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 844d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void processIntent(Intent intent) { 845f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos if (intent == null) { 846f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos finish(); 847f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos return; 848f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos } 849d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell Uri lookupUri = intent.getData(); 850d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 851d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Check to see whether it comes from the old version. 852d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) { 853d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final long rawContactId = ContentUris.parseId(lookupUri); 854d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell lookupUri = RawContacts.getContactLookupUri(getContentResolver(), 855d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); 856d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 85705287bf0cea303b93802a629aa883fb6322ca342Brian Attwell mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, QuickContact.MODE_LARGE); 85805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell mExtraPrioritizedMimeType = getIntent().getStringExtra(QuickContact.EXTRA_PRIORITIZED_MIMETYPE); 859d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final Uri oldLookupUri = mLookupUri; 860d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 861fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner if (lookupUri == null) { 862fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner finish(); 863fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner return; 864fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner } 865fcfcae34bd2d74e71ee218cfd7aa3567d7c3fc26Jay Shrauner mLookupUri = lookupUri; 866d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES); 867d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (oldLookupUri == null) { 868d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactLoader = (ContactLoader) getLoaderManager().initLoader( 869d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell LOADER_CONTACT_ID, null, mLoaderContactCallbacks); 870d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (oldLookupUri != mLookupUri) { 871d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // After copying a directory contact, the contact URI changes. Therefore, 872d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // we need to restart the loader and reload the new contact. 87359a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell destroyInteractionLoaders(); 874405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos mContactLoader = (ContactLoader) getLoaderManager().restartLoader( 875405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos LOADER_CONTACT_ID, null, mLoaderContactCallbacks); 87659a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell mCachedCp2DataCardModel = null; 877d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 8782d150da246632b1649999cfabed776133b097775Brian Attwell 8792d150da246632b1649999cfabed776133b097775Brian Attwell NfcHandler.register(this, mLookupUri); 8802426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann } 881edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 88259a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell private void destroyInteractionLoaders() { 88359a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell for (int interactionLoaderId : mRecentLoaderIds) { 88459a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell getLoaderManager().destroyLoader(interactionLoaderId); 88559a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell } 88659a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell } 88759a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell 888b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell private void runEntranceAnimation() { 8898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mHasAlreadyBeenOpened) { 8908a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 8918a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 8928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mHasAlreadyBeenOpened = true; 893c33ae17c9816b770041ee1f9ccde10e7c7eee491Brian Attwell mScroller.scrollUpForEntranceAnimation(mExtraMode != MODE_FULLY_EXPANDED); 894b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 895b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell 89681281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 897d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void setHeaderNameText(int resId) { 8989b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 899f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell mScroller.setTitle(getText(resId) == null ? null : getText(resId).toString()); 9009b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 90181281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 90281281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 90381281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** Assign this string to the view if it is not empty. */ 904f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell private void setHeaderNameText(String value) { 905d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (!TextUtils.isEmpty(value)) { 9069b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell if (mScroller != null) { 907f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell mScroller.setTitle(value); 9089b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 90981281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 91081281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan } 91181281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan 91281281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan /** 913edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Check if the given MIME-type appears in the list of excluded MIME-types 914edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * that the most-recent caller requested. 915edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 916edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann private boolean isMimeExcluded(String mimeType) { 917edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (mExcludeMimes == null) return false; 918edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann for (String excludedMime : mExcludeMimes) { 919edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann if (TextUtils.equals(excludedMime, mimeType)) { 920edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return true; 921edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 922edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 923edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann return false; 924edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 925edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 926edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 927cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann * Handle the result from the ContactLoader 928edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */ 9298a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void bindContactData(final Contact data) { 9308a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("bindContactData"); 9316cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee mContactData = data; 932d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell invalidateOptionsMenu(); 933edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 9348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 9358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("Set display photo & name"); 936dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 93702eaf11669d25fd885606b3b0700358323532cddBrian Attwell mPhotoView.setIsBusiness(mContactData.isDisplayNameFromOrganization()); 9386219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee mPhotoSetter.setupContactPhoto(data, mPhotoView); 93931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell extractAndApplyTintFromPhotoViewAsynchronously(); 940333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos setHeaderNameText(ContactDisplayUtils.getDisplayName(this, data).toString()); 941edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 9428a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 943dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki 9446bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mEntriesAndActionsTask = new AsyncTask<Void, Void, Cp2DataCardModel>() { 9458a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 9468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 9476bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell protected Cp2DataCardModel doInBackground( 948eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Void... params) { 949eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return generateDataModelFromContact(data); 9508a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 9518a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 9528a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 9536bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell protected void onPostExecute(Cp2DataCardModel cardDataModel) { 9546bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell super.onPostExecute(cardDataModel); 9558a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Check that original AsyncTask parameters are still valid and the activity 9568a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // is still running before binding to UI. A new intent could invalidate 9578a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the results, for example. 9588a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (data == mContactData && !isCancelled()) { 9596bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell bindDataToCards(cardDataModel); 9608a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell showActivity(); 9618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 9628a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 9638a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }; 9648a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.execute(); 9658a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 9668a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 9676bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void bindDataToCards(Cp2DataCardModel cp2DataCardModel) { 9686bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell startInteractionLoaders(cp2DataCardModel); 9696bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell populateContactAndAboutCard(cp2DataCardModel); 970eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 971eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 9726bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void startInteractionLoaders(Cp2DataCardModel cp2DataCardModel) { 9736bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final Map<String, List<DataItem>> dataItemsMap = cp2DataCardModel.dataItemsMap; 9746bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> phoneDataItems = dataItemsMap.get(Phone.CONTENT_ITEM_TYPE); 97597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (phoneDataItems != null && phoneDataItems.size() == 1) { 97697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos mOnlyOnePhoneNumber = true; 97797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 978eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] phoneNumbers = null; 979eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (phoneDataItems != null) { 980eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers = new String[phoneDataItems.size()]; 981eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < phoneDataItems.size(); ++i) { 982eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phoneNumbers[i] = ((PhoneDataItem) phoneDataItems.get(i)).getNumber(); 983eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 984eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 985ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle phonesExtraBundle = new Bundle(); 986eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_PHONES, phoneNumbers); 987eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 988eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("start sms loader"); 9898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell getLoaderManager().initLoader( 9908a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell LOADER_SMS_ID, 991ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 992ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos mLoaderInteractionsCallbacks); 993ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.endSection(); 994ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos 995ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos Trace.beginSection("start call log loader"); 996ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos getLoaderManager().initLoader( 997ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos LOADER_CALL_LOG_ID, 998ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos phonesExtraBundle, 9998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mLoaderInteractionsCallbacks); 1000899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.endSection(); 10018a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1002eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1003899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos Trace.beginSection("start calendar loader"); 10046bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> emailDataItems = dataItemsMap.get(Email.CONTENT_ITEM_TYPE); 100597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos if (emailDataItems != null && emailDataItems.size() == 1) { 100697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos mOnlyOneEmail = true; 100797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos } 1008eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String[] emailAddresses = null; 1009eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (emailDataItems != null) { 1010eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses = new String[emailDataItems.size()]; 1011eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (int i = 0; i < emailDataItems.size(); ++i) { 1012eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailAddresses[i] = ((EmailDataItem) emailDataItems.get(i)).getAddress(); 1013eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1014eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1015ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos final Bundle emailsExtraBundle = new Bundle(); 1016eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos emailsExtraBundle.putStringArray(KEY_LOADER_EXTRA_EMAILS, emailAddresses); 1017899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos getLoaderManager().initLoader( 1018899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos LOADER_CALENDAR_ID, 1019ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos emailsExtraBundle, 1020899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos mLoaderInteractionsCallbacks); 10218a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 10228a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 10238a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 10248a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void showActivity() { 10258a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller != null) { 10268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mScroller.setVisibility(View.VISIBLE); 10278a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, 10288a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell new Runnable() { 10298a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 10308a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void run() { 10318a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell runEntranceAnimation(); 10328a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 10338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell }); 10348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 10358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 10368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 10376bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private List<List<Entry>> buildAboutCardEntries(Map<String, List<DataItem>> dataItemsMap) { 1038a153dba33c2152332c5706178a367f52b0550723Paul Soulos final List<List<Entry>> aboutCardEntries = new ArrayList<>(); 1039a153dba33c2152332c5706178a367f52b0550723Paul Soulos for (String mimetype : SORTED_ABOUT_CARD_MIMETYPES) { 10406bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> mimeTypeItems = dataItemsMap.get(mimetype); 1041a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (mimeTypeItems == null) { 1042a153dba33c2152332c5706178a367f52b0550723Paul Soulos continue; 1043a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 10446bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // Set aboutCardTitleOut = null, since SORTED_ABOUT_CARD_MIMETYPES doesn't contain 10456bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // the name mimetype. 10466bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<Entry> aboutEntries = dataItemsToEntries(mimeTypeItems, 10476bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /* aboutCardTitleOut = */ null); 1048a153dba33c2152332c5706178a367f52b0550723Paul Soulos if (aboutEntries.size() > 0) { 1049a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(aboutEntries); 1050a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1051a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1052a153dba33c2152332c5706178a367f52b0550723Paul Soulos return aboutCardEntries; 1053a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1054a153dba33c2152332c5706178a367f52b0550723Paul Soulos 1055a42ef76251778161d27bc07db214b8c81720e476Paul Soulos @Override 1056a42ef76251778161d27bc07db214b8c81720e476Paul Soulos protected void onResume() { 1057a42ef76251778161d27bc07db214b8c81720e476Paul Soulos super.onResume(); 1058a42ef76251778161d27bc07db214b8c81720e476Paul Soulos // If returning from a launched activity, repopulate the contact and about card 1059a42ef76251778161d27bc07db214b8c81720e476Paul Soulos if (mHasIntentLaunched) { 1060a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = false; 10616bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell populateContactAndAboutCard(mCachedCp2DataCardModel); 1062a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 106359a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell 106459a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell // When exiting the activity and resuming, we want to force a full reload of all the 106559a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell // interaction data in case something changed in the background. On screen rotation, 106659a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell // we don't need to do this. And, mCachedCp2DataCardModel will be null, so we won't. 106759a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell if (mCachedCp2DataCardModel != null) { 106859a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell destroyInteractionLoaders(); 106959a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell startInteractionLoaders(mCachedCp2DataCardModel); 107059a585b78d061c84367ec24c71e137fae55d10ceBrian Attwell } 1071a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 1072a42ef76251778161d27bc07db214b8c81720e476Paul Soulos 10736bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private void populateContactAndAboutCard(Cp2DataCardModel cp2DataCardModel) { 10746bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mCachedCp2DataCardModel = cp2DataCardModel; 10756bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (mHasIntentLaunched || cp2DataCardModel == null) { 1076a42ef76251778161d27bc07db214b8c81720e476Paul Soulos return; 1077a42ef76251778161d27bc07db214b8c81720e476Paul Soulos } 1078eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind contact card"); 1079eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 10806bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> contactCardEntries = cp2DataCardModel.contactCardEntries; 10816bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> aboutCardEntries = cp2DataCardModel.aboutCardEntries; 10826bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final String customAboutCardName = cp2DataCardModel.customAboutCardName; 1083eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1084eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (contactCardEntries.size() > 0) { 108505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell final boolean firstEntriesArePrioritizedMimeType = 108605287bf0cea303b93802a629aa883fb6322ca342Brian Attwell !TextUtils.isEmpty(mExtraPrioritizedMimeType) && 108705287bf0cea303b93802a629aa883fb6322ca342Brian Attwell mCachedCp2DataCardModel.dataItemsMap.containsKey(mExtraPrioritizedMimeType) && 108805287bf0cea303b93802a629aa883fb6322ca342Brian Attwell mCachedCp2DataCardModel.dataItemsMap.get(mExtraPrioritizedMimeType).size() != 0; 1089eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.initialize(contactCardEntries, 1090eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /* numInitialVisibleEntries = */ MIN_NUM_CONTACT_ENTRIES_SHOWN, 1091c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos /* isExpanded = */ mContactCard.isExpanded(), 109289966b4ed8cc9d385e5ac6b4a7e9e08ada387eb0Paul Soulos /* isAlwaysExpanded = */ false, 10930cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos mExpandingEntryCardViewListener, 109405287bf0cea303b93802a629aa883fb6322ca342Brian Attwell mScroller, 109505287bf0cea303b93802a629aa883fb6322ca342Brian Attwell firstEntriesArePrioritizedMimeType); 1096eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.VISIBLE); 1097eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1098eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos mContactCard.setVisibility(View.GONE); 1099eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1100eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 11018a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1102eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("bind about card"); 1103c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos // Phonetic name is not a data item, so the entry needs to be created separately 1104c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos final String phoneticName = mContactData.getPhoneticName(); 1105c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos if (!TextUtils.isEmpty(phoneticName)) { 1106c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos Entry phoneticEntry = new Entry(/* viewId = */ -1, 1107c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* icon = */ null, 1108c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos getResources().getString(R.string.name_phonetic), 1109c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos phoneticName, 11108a3fe52802135be2402a5b216325615fb796a509Walter Jang /* subHeaderIcon = */ null, 1111c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* text = */ null, 11128a3fe52802135be2402a5b216325615fb796a509Walter Jang /* textIcon = */ null, 111323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos /* primaryContentDescription = */ null, 1114c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* intent = */ null, 1115c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateIcon = */ null, 1116c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateIntent = */ null, 1117c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* alternateContentDescription = */ null, 1118c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos /* shouldApplyColor = */ false, 11192a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, 11202a4207fb39330e840436215c896cde911489e111Paul Soulos /* EntryContextMenuInfo = */ new EntryContextMenuInfo(phoneticName, 112197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos getResources().getString(R.string.name_phonetic), 112297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos /* mimeType = */ null, /* id = */ -1, /* isPrimary = */ false), 112348fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, 112448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIntent = */ null, 112548290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos /* thirdContentDescription = */ null, 112648290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos /* iconResourceId = */ 0); 1127c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos List<Entry> phoneticList = new ArrayList<>(); 1128c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos phoneticList.add(phoneticEntry); 1129a153dba33c2152332c5706178a367f52b0550723Paul Soulos // Phonetic name comes after nickname. Check to see if the first entry type is nickname 1130a0fa4c18dc111ceea9ff47f35ee01fecc1003578Paul Soulos if (aboutCardEntries.size() > 0 && aboutCardEntries.get(0).get(0).getHeader().equals( 1131a153dba33c2152332c5706178a367f52b0550723Paul Soulos getResources().getString(R.string.header_nickname_entry))) { 1132a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(1, phoneticList); 1133a153dba33c2152332c5706178a367f52b0550723Paul Soulos } else { 1134a153dba33c2152332c5706178a367f52b0550723Paul Soulos aboutCardEntries.add(0, phoneticList); 1135a153dba33c2152332c5706178a367f52b0550723Paul Soulos } 1136c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos } 1137c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos 11386bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!TextUtils.isEmpty(customAboutCardName)) { 11396bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell mAboutCard.setTitle(customAboutCardName); 11406bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 11416bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 11423b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox mAboutCard.initialize(aboutCardEntries, 11433b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox /* numInitialVisibleEntries = */ 1, 11443b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox /* isExpanded = */ true, 11453b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox /* isAlwaysExpanded = */ true, 11463b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox mExpandingEntryCardViewListener, 11473b1a8b2f6349d55ae8ef502d9d2f9451f24eff50kungaox mScroller); 11486095369885edcca566a812b551886e29c7ff8039Brian Attwell 11496095369885edcca566a812b551886e29c7ff8039Brian Attwell if (contactCardEntries.size() == 0 && aboutCardEntries.size() == 0) { 11506095369885edcca566a812b551886e29c7ff8039Brian Attwell initializeNoContactDetailCard(); 11516095369885edcca566a812b551886e29c7ff8039Brian Attwell } else { 11526095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setVisibility(View.GONE); 11536095369885edcca566a812b551886e29c7ff8039Brian Attwell } 11546095369885edcca566a812b551886e29c7ff8039Brian Attwell 1155a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos // If the Recent card is already initialized (all recent data is loaded), show the About 1156a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos // card if it has entries. Otherwise About card visibility will be set in bindRecentData() 1157a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos if (isAllRecentDataLoaded() && aboutCardEntries.size() > 0) { 1158a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos mAboutCard.setVisibility(View.VISIBLE); 1159a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos } 1160eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 1161eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1162eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1163eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 11646095369885edcca566a812b551886e29c7ff8039Brian Attwell * Create a card that shows "Add email" and "Add phone number" entries in grey. 11656095369885edcca566a812b551886e29c7ff8039Brian Attwell */ 11666095369885edcca566a812b551886e29c7ff8039Brian Attwell private void initializeNoContactDetailCard() { 11676095369885edcca566a812b551886e29c7ff8039Brian Attwell final Drawable phoneIcon = getResources().getDrawable( 11686095369885edcca566a812b551886e29c7ff8039Brian Attwell R.drawable.ic_phone_24dp).mutate(); 11696095369885edcca566a812b551886e29c7ff8039Brian Attwell final Entry phonePromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, 11706095369885edcca566a812b551886e29c7ff8039Brian Attwell phoneIcon, getString(R.string.quickcontact_add_phone_number), 11718a3fe52802135be2402a5b216325615fb796a509Walter Jang /* subHeader = */ null, /* subHeaderIcon = */ null, /* text = */ null, 11728a3fe52802135be2402a5b216325615fb796a509Walter Jang /* textIcon = */ null, /* primaryContentDescription = */ null, 117323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos getEditContactIntent(), 1174dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIcon = */ null, /* alternateIntent = */ null, 1175714455bba22b99d168a2e864dfbc74a6e30dfdb6Paul Soulos /* alternateContentDescription = */ null, /* shouldApplyColor = */ true, 117648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* isEditable = */ false, /* EntryContextMenuInfo = */ null, 117748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, /* thirdIntent = */ null, 117848290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos /* thirdContentDescription = */ null, R.drawable.ic_phone_24dp); 11796095369885edcca566a812b551886e29c7ff8039Brian Attwell 11806095369885edcca566a812b551886e29c7ff8039Brian Attwell final Drawable emailIcon = getResources().getDrawable( 11816095369885edcca566a812b551886e29c7ff8039Brian Attwell R.drawable.ic_email_24dp).mutate(); 11826095369885edcca566a812b551886e29c7ff8039Brian Attwell final Entry emailPromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, 11836095369885edcca566a812b551886e29c7ff8039Brian Attwell emailIcon, getString(R.string.quickcontact_add_email), /* subHeader = */ null, 11848a3fe52802135be2402a5b216325615fb796a509Walter Jang /* subHeaderIcon = */ null, 11858a3fe52802135be2402a5b216325615fb796a509Walter Jang /* text = */ null, /* textIcon = */ null, /* primaryContentDescription = */ null, 118623e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos getEditContactIntent(), /* alternateIcon = */ null, 1187dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIntent = */ null, /* alternateContentDescription = */ null, 11882a4207fb39330e840436215c896cde911489e111Paul Soulos /* shouldApplyColor = */ true, /* isEditable = */ false, 118948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* EntryContextMenuInfo = */ null, /* thirdIcon = */ null, 119048290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos /* thirdIntent = */ null, /* thirdContentDescription = */ null, 119148290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos R.drawable.ic_email_24dp); 11926095369885edcca566a812b551886e29c7ff8039Brian Attwell 11936095369885edcca566a812b551886e29c7ff8039Brian Attwell final List<List<Entry>> promptEntries = new ArrayList<>(); 11946095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.add(new ArrayList<Entry>(1)); 11956095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.add(new ArrayList<Entry>(1)); 11966095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.get(0).add(phonePromptEntry); 11976095369885edcca566a812b551886e29c7ff8039Brian Attwell promptEntries.get(1).add(emailPromptEntry); 11986095369885edcca566a812b551886e29c7ff8039Brian Attwell 11996095369885edcca566a812b551886e29c7ff8039Brian Attwell final int subHeaderTextColor = getResources().getColor( 12006095369885edcca566a812b551886e29c7ff8039Brian Attwell R.color.quickcontact_entry_sub_header_text_color); 12016095369885edcca566a812b551886e29c7ff8039Brian Attwell final PorterDuffColorFilter greyColorFilter = 12026095369885edcca566a812b551886e29c7ff8039Brian Attwell new PorterDuffColorFilter(subHeaderTextColor, PorterDuff.Mode.SRC_ATOP); 1203c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos mNoContactDetailsCard.initialize(promptEntries, 2, /* isExpanded = */ true, 12040cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos /* isAlwaysExpanded = */ true, mExpandingEntryCardViewListener, mScroller); 12056095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setVisibility(View.VISIBLE); 12066095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setEntryHeaderColor(subHeaderTextColor); 12076095369885edcca566a812b551886e29c7ff8039Brian Attwell mNoContactDetailsCard.setColorAndFilter(subHeaderTextColor, greyColorFilter); 12086095369885edcca566a812b551886e29c7ff8039Brian Attwell } 12096095369885edcca566a812b551886e29c7ff8039Brian Attwell 12106095369885edcca566a812b551886e29c7ff8039Brian Attwell /** 1211eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Builds the {@link DataItem}s Map out of the Contact. 1212eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param data The contact to build the data from. 1213eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return A pair containing a list of data items sorted within mimetype and sorted 1214eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * amongst mimetype. The map goes from mimetype string to the sorted list of data items within 1215eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * mimetype 1216eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 12176bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private Cp2DataCardModel generateDataModelFromContact( 1218eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Contact data) { 1219eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("Build data items map"); 1220eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1221eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Map<String, List<DataItem>> dataItemsMap = new HashMap<>(); 12228bf96e78497ea9c8c893bcb357fc1e3175fb2e9bBrian Attwell 12238a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final ResolveCache cache = ResolveCache.getInstance(this); 1224851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (RawContact rawContact : data.getRawContacts()) { 1225851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu for (DataItem dataItem : rawContact.getDataItems()) { 1226eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setRawContactId(rawContact.getId()); 1227eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1228851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final String mimeType = dataItem.getMimeType(); 1229eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (mimeType == null) continue; 1230eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 123147b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final AccountType accountType = rawContact.getAccountType(this); 123247b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng final DataKind dataKind = AccountTypeManager.getInstance(this) 123347b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng .getKindOrFallback(accountType, mimeType); 1234eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataKind == null) continue; 1235cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1236eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItem.setDataKind(dataKind); 1237b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1238eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean hasData = !TextUtils.isEmpty(dataItem.buildDataString(this, 1239eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataKind)); 1240899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos 1241eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (isMimeExcluded(mimeType) || !hasData) continue; 1242edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1243eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos List<DataItem> dataItemListByType = dataItemsMap.get(mimeType); 1244eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItemListByType == null) { 1245eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType = new ArrayList<>(); 1246eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsMap.put(mimeType, dataItemListByType); 1247edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1248eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemListByType.add(dataItem); 1249edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1250edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 12518a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.endSection(); 1252edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1253eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort within mimetypes"); 125416339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos /* 125516339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos * Sorting is a multi part step. The end result is to a have a sorted list of the most 1256eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * used data items, one per mimetype. Then, within each mimetype, the list of data items 1257eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * for that type is also sorted, based off of {super primary, primary, times used} in that 1258eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * order. 125916339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos */ 1260eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<List<DataItem>> dataItemsList = new ArrayList<>(); 1261eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (List<DataItem> mimeTypeDataItems : dataItemsMap.values()) { 1262eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Remove duplicate data items 1263eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collapser.collapseList(mimeTypeDataItems, this); 1264eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort within mimetype 1265eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(mimeTypeDataItems, mWithinMimeTypeDataItemComparator); 1266eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Add to the list of data item lists 1267eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos dataItemsList.add(mimeTypeDataItems); 1268edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1269eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 1270edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1271eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.beginSection("sort amongst mimetypes"); 1272eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Sort amongst mimetypes to bubble up the top data items for the contact card 1273eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Collections.sort(dataItemsList, mAmongstMimeTypeDataItemComparator); 1274eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Trace.endSection(); 127516339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos 12766bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Trace.beginSection("cp2 data items to entries"); 12776bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 12786bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> contactCardEntries = new ArrayList<>(); 12796bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<List<Entry>> aboutCardEntries = buildAboutCardEntries(dataItemsMap); 12806bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final MutableString aboutCardName = new MutableString(); 12816bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 12826bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell for (int i = 0; i < dataItemsList.size(); ++i) { 12836bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<DataItem> dataItemsByMimeType = dataItemsList.get(i); 12846bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final DataItem topDataItem = dataItemsByMimeType.get(0); 12856bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (SORTED_ABOUT_CARD_MIMETYPES.contains(topDataItem.getMimeType())) { 12866bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell // About card mimetypes are built in buildAboutCardEntries, skip here 12876bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell continue; 12886bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } else { 12896bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell List<Entry> contactEntries = dataItemsToEntries(dataItemsList.get(i), 12906bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell aboutCardName); 12916bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (contactEntries.size() > 0) { 12926bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell contactCardEntries.add(contactEntries); 12936bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 12946bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 12956bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 12966bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 12976bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Trace.endSection(); 12986bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 12996bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final Cp2DataCardModel dataModel = new Cp2DataCardModel(); 13006bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.customAboutCardName = aboutCardName.value; 13016bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.aboutCardEntries = aboutCardEntries; 13026bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.contactCardEntries = contactCardEntries; 13036bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell dataModel.dataItemsMap = dataItemsMap; 13046bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell return dataModel; 13056bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 13066bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 13076bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 13086bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * Class used to hold the About card and Contact cards' data model that gets generated 13096bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * on a background thread. All data is from CP2. 13106bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 13116bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static class Cp2DataCardModel { 13126bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell /** 13136bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * A map between a mimetype string and the corresponding list of data items. The data items 13146bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * are in sorted order using mWithinMimeTypeDataItemComparator. 13156bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell */ 13166bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public Map<String, List<DataItem>> dataItemsMap; 13176bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public List<List<Entry>> aboutCardEntries; 13186bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public List<List<Entry>> contactCardEntries; 13196bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public String customAboutCardName; 13206bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell } 13216bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell 13226bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static class MutableString { 13236bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell public String value; 1324eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1325edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 1326eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos /** 1327eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * Converts a {@link DataItem} into an {@link ExpandingEntryCardView.Entry} for display. 1328eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * If the {@link ExpandingEntryCardView.Entry} has no visual elements, null is returned. 13296bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * 13306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * This runs on a background thread. This is set as static to avoid accidentally adding 13316bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * additional dependencies on unsafe things (like the Activity). 13326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell * 1333eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @param dataItem The {@link DataItem} to convert. 13346a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * @param secondDataItem A second {@link DataItem} to help build a full entry for some 13356a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * mimetypes 1336eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos * @return The {@link ExpandingEntryCardView.Entry}, or null if no visual elements are present. 1337eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos */ 13386a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static Entry dataItemToEntry(DataItem dataItem, DataItem secondDataItem, 13396bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell Context context, Contact contactData, 13406bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final MutableString aboutCardName) { 1341eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable icon = null; 1342eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String header = null; 1343eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String subHeader = null; 1344eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable subHeaderIcon = null; 1345eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos String text = null; 1346eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Drawable textIcon = null; 134723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos StringBuilder primaryContentDescription = new StringBuilder(); 1348eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos Intent intent = null; 134948ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos boolean shouldApplyColor = true; 1350dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Drawable alternateIcon = null; 1351dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos Intent alternateIntent = null; 135223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos StringBuilder alternateContentDescription = new StringBuilder(); 1353eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEditable = false; 13542a4207fb39330e840436215c896cde911489e111Paul Soulos EntryContextMenuInfo entryContextMenuInfo = null; 135548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos Drawable thirdIcon = null; 135648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos Intent thirdIntent = null; 135748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos String thirdContentDescription = null; 135848290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos int iconResourceId = 0; 1359eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 13606bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell context = context.getApplicationContext(); 136123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos final Resources res = context.getResources(); 1362eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DataKind kind = dataItem.getDataKind(); 1363eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1364eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (dataItem instanceof ImDataItem) { 1365eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final ImDataItem im = (ImDataItem) dataItem; 13666bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell intent = ContactsUtils.buildImIntent(context, im).first; 1367eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isEmail = im.isCreatedFromEmail(); 13687de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos final int protocol; 13697de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos if (!im.isProtocolValid()) { 13707de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos protocol = Im.PROTOCOL_CUSTOM; 13717de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } else { 13727de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol(); 13737de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } 13747de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos if (protocol == Im.PROTOCOL_CUSTOM) { 13757de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos // If the protocol is custom, display the "IM" entry header as well to distinguish 13767de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos // this entry from other ones 137723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_im_entry); 137823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos subHeader = Im.getProtocolLabel(res, protocol, 13797de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos im.getCustomProtocol()).toString(); 13807de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos text = im.getData(); 13817de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } else { 138223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = Im.getProtocolLabel(res, protocol, 13837de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos im.getCustomProtocol()).toString(); 13847de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos subHeader = im.getData(); 13857de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos } 138697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(im.getData(), header, 138797f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1388eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof OrganizationDataItem) { 1389eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final OrganizationDataItem organization = (OrganizationDataItem) dataItem; 139023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_organization_entry); 1391eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = organization.getCompany(); 139297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 139397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1394eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = organization.getTitle(); 1395eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NicknameDataItem) { 1396eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NicknameDataItem nickname = (NicknameDataItem) dataItem; 1397eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Build nickname entries 1398eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean isNameRawContact = 13996bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell (contactData.getNameRawContactId() == dataItem.getRawContactId()); 1400eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1401eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final boolean duplicatesTitle = 1402eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos isNameRawContact 14036bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell && contactData.getDisplayNameSource() == DisplayNameSources.NICKNAME; 1404eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1405eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!duplicatesTitle) { 140623e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_nickname_entry); 1407eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = nickname.getName(); 140897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 140997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1410eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1411eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof NoteDataItem) { 1412eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final NoteDataItem note = (NoteDataItem) dataItem; 141323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_note_entry); 1414eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = note.getNote(); 141597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 141697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1417eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof WebsiteDataItem) { 1418eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final WebsiteDataItem website = (WebsiteDataItem) dataItem; 141923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_website_entry); 1420eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = website.getUrl(); 142197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 142297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1423eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos try { 14243bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell final WebAddress webAddress = new WebAddress(website.buildDataStringForDisplay 14253bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell (context, kind)); 1426eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString())); 1427eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ParseException e) { 14283bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell Log.e(TAG, "Couldn't parse website: " + website.buildDataStringForDisplay( 14293bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell context, kind)); 1430eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1431eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EventDataItem) { 1432eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EventDataItem event = (EventDataItem) dataItem; 14333bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell final String dataString = event.buildDataStringForDisplay(context, kind); 1434eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Calendar cal = DateUtils.parseDate(dataString, false); 1435eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (cal != null) { 1436eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Date nextAnniversary = 1437eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos DateUtils.getNextAnnualDate(cal); 1438eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); 1439eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos builder.appendPath("time"); 1440eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos ContentUris.appendId(builder, nextAnniversary.getTime()); 1441eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW).setData(builder.build()); 1442eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 144323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_event_entry); 1444f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (event.hasKindTypeColumn(kind)) { 144523e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos subHeader = Event.getTypeLabel(res, event.getKindTypeColumn(kind), 14467de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos event.getLabel()).toString(); 1447f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 14486bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell text = DateUtils.formatDate(context, dataString); 144997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(text, header, 145097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1451eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof RelationDataItem) { 1452eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final RelationDataItem relation = (RelationDataItem) dataItem; 14533bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell final String dataString = relation.buildDataStringForDisplay(context, kind); 1454eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(dataString)) { 1455eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SEARCH); 1456eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.putExtra(SearchManager.QUERY, dataString); 1457eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent.setType(Contacts.CONTENT_TYPE); 1458eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 145923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos header = res.getString(R.string.header_relation_entry); 1460eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeader = relation.getName(); 146197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, 146297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); 1463f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (relation.hasKindTypeColumn(kind)) { 146423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = Relation.getTypeLabel(res, 14656bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell relation.getKindTypeColumn(kind), 1466f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos relation.getLabel()).toString(); 1467f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 1468eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof PhoneDataItem) { 1469eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final PhoneDataItem phone = (PhoneDataItem) dataItem; 1470eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(phone.getNumber())) { 147123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(res.getString(R.string.call_other)).append(" "); 14723bcf09eac69251c05cd4e386badfa292ba56b4f0Brian Attwell header = sBidiFormatter.unicodeWrap(phone.buildDataStringForDisplay(context, kind), 1473c62cc7931593b4137f8a507689b653e1e15e1260Brian Attwell TextDirectionHeuristics.LTR); 14742a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 147597f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), 147697f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getId(), dataItem.isSuperPrimary()); 1477f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (phone.hasKindTypeColumn(kind)) { 147823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = Phone.getTypeLabel(res, phone.getKindTypeColumn(kind), 1479f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos phone.getLabel()).toString(); 148023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(text).append(" "); 1481f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 148223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(header); 148323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_phone_24dp); 148448290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos iconResourceId = R.drawable.ic_phone_24dp; 14856bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (PhoneCapabilityTester.isPhone(context)) { 1486eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(phone.getNumber()); 148716339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1488dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIntent = new Intent(Intent.ACTION_SENDTO, 14891cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phone.getNumber(), null)); 149048fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos 149123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateIcon = res.getDrawable(R.drawable.ic_message_24dp); 149223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.append(res.getString(R.string.sms_custom, header)); 149348fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos 149448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos // Add video call button if supported 1495f764730a34da560db87206f9a48390d4c8085365Paul Soulos if (CallUtil.isVideoEnabled(context)) { 149623e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos thirdIcon = res.getDrawable(R.drawable.ic_videocam); 149748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos thirdIntent = CallUtil.getVideoCallIntent(phone.getNumber(), 149848fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY); 149948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos thirdContentDescription = 150023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos res.getString(R.string.description_video_call); 150148fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos } 1502eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1503eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof EmailDataItem) { 1504eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final EmailDataItem email = (EmailDataItem) dataItem; 1505eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String address = email.getData(); 1506eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(address)) { 150723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(res.getString(R.string.email_other)).append(" "); 15081cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner final Uri mailUri = Uri.fromParts(ContactsUtils.SCHEME_MAILTO, address, null); 1509eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_SENDTO, mailUri); 1510eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = email.getAddress(); 15112a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 151297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos res.getString(R.string.emailLabelsGroup), dataItem.getMimeType(), 151397f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getId(), dataItem.isSuperPrimary()); 1514f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (email.hasKindTypeColumn(kind)) { 151523e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = Email.getTypeLabel(res, email.getKindTypeColumn(kind), 1516f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos email.getLabel()).toString(); 151723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(text).append(" "); 1518f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 151923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(header); 152023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_email_24dp); 152148290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos iconResourceId = R.drawable.ic_email_24dp; 1522eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1523eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredPostalDataItem) { 1524eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos StructuredPostalDataItem postal = (StructuredPostalDataItem) dataItem; 1525eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final String postalAddress = postal.getFormattedAddress(); 1526eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (!TextUtils.isEmpty(postalAddress)) { 152723e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(res.getString(R.string.map_other)).append(" "); 1528eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress); 1529eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos header = postal.getFormattedAddress(); 15302a4207fb39330e840436215c896cde911489e111Paul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, 153197f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos res.getString(R.string.postalLabelsGroup), dataItem.getMimeType(), 153297f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getId(), dataItem.isSuperPrimary()); 1533f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos if (postal.hasKindTypeColumn(kind)) { 153423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos text = StructuredPostal.getTypeLabel(res, 1535f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos postal.getKindTypeColumn(kind), postal.getLabel()).toString(); 153623e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(text).append(" "); 1537f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos } 153823e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos primaryContentDescription.append(header); 15396a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos alternateIntent = 15406a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos StructuredPostalUtils.getViewPostalAddressDirectionsIntent(postalAddress); 154123e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateIcon = res.getDrawable(R.drawable.ic_directions_24dp); 154223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.append(res.getString( 154323e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos R.string.content_description_directions)).append(" ").append(header); 154423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_place_24dp); 154548290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos iconResourceId = R.drawable.ic_place_24dp; 1546eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1547eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof SipAddressDataItem) { 1548593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell final SipAddressDataItem sip = (SipAddressDataItem) dataItem; 1549593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell final String address = sip.getSipAddress(); 1550593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell if (!TextUtils.isEmpty(address)) { 1551593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell primaryContentDescription.append(res.getString(R.string.call_other)).append( 1552593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell " "); 1553593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell if (PhoneCapabilityTester.isSipPhone(context)) { 15541cd88e3ecfa72f43c3fe25c912d9f67848f11e60Jay Shrauner final Uri callUri = Uri.fromParts(PhoneAccount.SCHEME_SIP, address, null); 1555eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = CallUtil.getCallIntent(callUri); 155616339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos } 1557593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell header = address; 1558593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell entryContextMenuInfo = new EntryContextMenuInfo(header, 1559593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), 1560593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell dataItem.getId(), dataItem.isSuperPrimary()); 1561593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell if (sip.hasKindTypeColumn(kind)) { 1562593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell text = SipAddress.getTypeLabel(res, 1563593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell sip.getKindTypeColumn(kind), sip.getLabel()).toString(); 1564593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell primaryContentDescription.append(text).append(" "); 1565593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell } 1566593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell primaryContentDescription.append(header); 1567593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell icon = res.getDrawable(R.drawable.ic_dialer_sip_black_24dp); 1568593e5a7f2551b7946ada9913408f649e530202c8Brian Attwell iconResourceId = R.drawable.ic_dialer_sip_black_24dp; 1569edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1570eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else if (dataItem instanceof StructuredNameDataItem) { 15718025f801f5153917781a9496cabdd81ae1b6deafWalter Jang // If the name is already set and this is not the super primary value then leave the 15728025f801f5153917781a9496cabdd81ae1b6deafWalter Jang // current value. This way we show the super primary value when we are able to. 15738025f801f5153917781a9496cabdd81ae1b6deafWalter Jang if (dataItem.isSuperPrimary() || aboutCardName.value == null 15748025f801f5153917781a9496cabdd81ae1b6deafWalter Jang || aboutCardName.value.isEmpty()) { 15758025f801f5153917781a9496cabdd81ae1b6deafWalter Jang final String givenName = ((StructuredNameDataItem) dataItem).getGivenName(); 15768025f801f5153917781a9496cabdd81ae1b6deafWalter Jang if (!TextUtils.isEmpty(givenName)) { 15778025f801f5153917781a9496cabdd81ae1b6deafWalter Jang aboutCardName.value = res.getString(R.string.about_card_title) + 15788025f801f5153917781a9496cabdd81ae1b6deafWalter Jang " " + givenName; 15798025f801f5153917781a9496cabdd81ae1b6deafWalter Jang } else { 15808025f801f5153917781a9496cabdd81ae1b6deafWalter Jang aboutCardName.value = res.getString(R.string.about_card_title); 15818025f801f5153917781a9496cabdd81ae1b6deafWalter Jang } 1582eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1583eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } else { 1584eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Custom DataItem 15856bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell header = dataItem.buildDataStringForDisplay(context, kind); 1586eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos text = kind.typeColumn; 1587eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = new Intent(Intent.ACTION_VIEW); 158860e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, dataItem.getId()); 158960e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos intent.setDataAndType(uri, dataItem.getMimeType()); 1590e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 1591e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (intent != null) { 1592e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos final String mimetype = intent.getType(); 1593e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos 15946a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Build advanced entry for known 3p types. Otherwise default to ResolveCache icon. 1595e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos switch (mimetype) { 1596e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos case MIMETYPE_GPLUS_PROFILE: 15976a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // If a secondDataItem is available, use it to build an entry with 15986a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // alternate actions 15996a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (secondDataItem != null) { 160023e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_google_plus_24dp); 16016a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos alternateIcon = res.getDrawable(R.drawable.ic_add_to_circles_black_24); 16026a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final GPlusOrHangoutsDataItemModel itemModel = 16036a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos new GPlusOrHangoutsDataItemModel(intent, alternateIntent, 16046a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataItem, secondDataItem, alternateContentDescription, 16056a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos header, text, context); 16066a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 160797b1e2d6206ad8f64af6bc935451654204706661Paul Soulos populateGPlusOrHangoutsDataItemModel(itemModel); 160897b1e2d6206ad8f64af6bc935451654204706661Paul Soulos intent = itemModel.intent; 160997b1e2d6206ad8f64af6bc935451654204706661Paul Soulos alternateIntent = itemModel.alternateIntent; 161097b1e2d6206ad8f64af6bc935451654204706661Paul Soulos alternateContentDescription = itemModel.alternateContentDescription; 161197b1e2d6206ad8f64af6bc935451654204706661Paul Soulos header = itemModel.header; 161297b1e2d6206ad8f64af6bc935451654204706661Paul Soulos text = itemModel.text; 16136a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 16146a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (GPLUS_PROFILE_DATA_5_ADD_TO_CIRCLE.equals( 16156a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos intent.getDataString())) { 16166a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos icon = res.getDrawable(R.drawable.ic_add_to_circles_black_24); 16176a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 16186a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos icon = res.getDrawable(R.drawable.ic_google_plus_24dp); 16196a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 1620e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1621e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos break; 1622e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos case MIMETYPE_HANGOUTS: 16236a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // If a secondDataItem is available, use it to build an entry with 16246a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // alternate actions 16256a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (secondDataItem != null) { 162623e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos icon = res.getDrawable(R.drawable.ic_hangout_24dp); 16276a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos alternateIcon = res.getDrawable(R.drawable.ic_hangout_video_24dp); 162897b1e2d6206ad8f64af6bc935451654204706661Paul Soulos final GPlusOrHangoutsDataItemModel itemModel = 16296a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos new GPlusOrHangoutsDataItemModel(intent, alternateIntent, 16306a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataItem, secondDataItem, alternateContentDescription, 16316a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos header, text, context); 16326a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 163397b1e2d6206ad8f64af6bc935451654204706661Paul Soulos populateGPlusOrHangoutsDataItemModel(itemModel); 163497b1e2d6206ad8f64af6bc935451654204706661Paul Soulos intent = itemModel.intent; 163597b1e2d6206ad8f64af6bc935451654204706661Paul Soulos alternateIntent = itemModel.alternateIntent; 163697b1e2d6206ad8f64af6bc935451654204706661Paul Soulos alternateContentDescription = itemModel.alternateContentDescription; 163797b1e2d6206ad8f64af6bc935451654204706661Paul Soulos header = itemModel.header; 163897b1e2d6206ad8f64af6bc935451654204706661Paul Soulos text = itemModel.text; 16396a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 16406a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (HANGOUTS_DATA_5_VIDEO.equals(intent.getDataString())) { 16416a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos icon = res.getDrawable(R.drawable.ic_hangout_video_24dp); 16426a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 16436a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos icon = res.getDrawable(R.drawable.ic_hangout_24dp); 16446a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 1645e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1646e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos break; 1647e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos default: 164897f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos entryContextMenuInfo = new EntryContextMenuInfo(header, mimetype, 164997f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.getMimeType(), dataItem.getId(), 165097f27809c3e6153ce0bc5050bc5ee466a646e8ecPaul Soulos dataItem.isSuperPrimary()); 16516bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell icon = ResolveCache.getInstance(context).getIcon( 1652e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos dataItem.getMimeType(), intent); 1653e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos // Call mutate to create a new Drawable.ConstantState for color filtering 1654e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos if (icon != null) { 1655e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos icon.mutate(); 1656e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 165748ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos shouldApplyColor = false; 1658e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1659e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos } 1660eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1661b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1662eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (intent != null) { 1663eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // Do not set the intent is there are no resolves 16646bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!PhoneCapabilityTester.isIntentRegistered(context, intent)) { 1665eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos intent = null; 1666eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1667eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1668eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1669dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (alternateIntent != null) { 1670dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Do not set the alternate intent is there are no resolves 16716bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell if (!PhoneCapabilityTester.isIntentRegistered(context, alternateIntent)) { 1672dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos alternateIntent = null; 1673f0d04c11b649e953177e79722d05fa048e53273dJay Shrauner } else if (TextUtils.isEmpty(alternateContentDescription)) { 1674f0d04c11b649e953177e79722d05fa048e53273dJay Shrauner // Attempt to use package manager to find a suitable content description if needed 167523e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.append(getIntentResolveLabel(alternateIntent, context)); 1676dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1677dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1678dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1679eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos // If the Entry has no visual elements, return null 1680eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) && 1681eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos subHeaderIcon == null && TextUtils.isEmpty(text) && textIcon == null) { 1682eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return null; 1683eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1684eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 1685fa238949855fba3b28a57fad3d585b13e80362bbBrian Attwell // Ignore dataIds from the Me profile. 1686ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos final int dataId = dataItem.getId() > Integer.MAX_VALUE ? 1687ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos -1 : (int) dataItem.getId(); 1688ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos 168923e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon, 16907ce5352a70e8aaf120bf4f7bd05d595f46abb080Walter Jang new SpannableString(primaryContentDescription.toString()), 16917ce5352a70e8aaf120bf4f7bd05d595f46abb080Walter Jang intent, alternateIcon, alternateIntent, 169223e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos alternateContentDescription.toString(), shouldApplyColor, isEditable, 169348290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos entryContextMenuInfo, thirdIcon, thirdIntent, thirdContentDescription, 169448290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos iconResourceId); 1695eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1696eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 16976bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private List<Entry> dataItemsToEntries(List<DataItem> dataItems, 16986bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell MutableString aboutCardTitleOut) { 16996a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Hangouts and G+ use two data items to create one entry. 17006a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (dataItems.get(0).getMimeType().equals(MIMETYPE_GPLUS_PROFILE) || 17016a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataItems.get(0).getMimeType().equals(MIMETYPE_HANGOUTS)) { 17026a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos return gPlusOrHangoutsDataItemsToEntries(dataItems); 17036a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 17046a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final List<Entry> entries = new ArrayList<>(); 17056a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos for (DataItem dataItem : dataItems) { 17066a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, 17076a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this, mContactData, aboutCardTitleOut); 17086a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (entry != null) { 17096a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos entries.add(entry); 17106a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 17116a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 17126a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos return entries; 17136a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 17146a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 17156a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 17166a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /** 17176a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * G+ and Hangout entries are unique in that a single ExpandingEntryCardView.Entry consists 17186a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * of two data items. This method attempts to build each entry using the two data items if 17196a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * they are available. If there are more or less than two data items, a fall back is used 17206a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * and each data item gets its own entry. 17216a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos */ 17226a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private List<Entry> gPlusOrHangoutsDataItemsToEntries(List<DataItem> dataItems) { 1723eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> entries = new ArrayList<>(); 17246a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Map<Long, List<DataItem>> buckets = new HashMap<>(); 17256a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Put the data items into buckets based on the raw contact id 1726eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos for (DataItem dataItem : dataItems) { 17276a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos List<DataItem> bucket = buckets.get(dataItem.getRawContactId()); 17286a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (bucket == null) { 17296a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos bucket = new ArrayList<>(); 17306a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos buckets.put(dataItem.getRawContactId(), bucket); 17316a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 17326a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos bucket.add(dataItem); 17336a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 17346a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 17356a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Use the buckets to build entries. If a bucket contains two data items, build the special 17366a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // entry, otherwise fall back to the normal entry. 17376a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos for (List<DataItem> bucket : buckets.values()) { 17386a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (bucket.size() == 2) { 17396a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Use the pair to build an entry 17406a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Entry entry = dataItemToEntry(bucket.get(0), 17416a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /* secondDataItem = */ bucket.get(1), this, mContactData, 17426a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /* aboutCardName = */ null); 17436a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (entry != null) { 17446a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos entries.add(entry); 17456a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 17466a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else { 17476a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos for (DataItem dataItem : bucket) { 17486a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, 17496a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this, mContactData, /* aboutCardName = */ null); 17506a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (entry != null) { 17516a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos entries.add(entry); 17526a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 17536a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 1754eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1755eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } 1756eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos return entries; 1757edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann } 1758edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann 17596a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos /** 17606a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * Used for statically passing around G+ or Hangouts data items and entry fields to 17616a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos * populateGPlusOrHangoutsDataItemModel. 17626a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos */ 17636a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static final class GPlusOrHangoutsDataItemModel { 17646a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public Intent intent; 17656a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public Intent alternateIntent; 17666a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public DataItem dataItem; 17676a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public DataItem secondDataItem; 17686a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public StringBuilder alternateContentDescription; 17696a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public String header; 17706a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public String text; 17716a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public Context context; 17726a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 17736a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos public GPlusOrHangoutsDataItemModel(Intent intent, Intent alternateIntent, DataItem dataItem, 17746a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos DataItem secondDataItem, StringBuilder alternateContentDescription, String header, 17756a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos String text, Context context) { 17766a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.intent = intent; 17776a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.alternateIntent = alternateIntent; 17786a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.dataItem = dataItem; 17796a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.secondDataItem = secondDataItem; 17806a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.alternateContentDescription = alternateContentDescription; 17816a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.header = header; 17826a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.text = text; 17836a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos this.context = context; 17846a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 17856a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 17866a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 17876a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos private static void populateGPlusOrHangoutsDataItemModel( 17886a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos GPlusOrHangoutsDataItemModel dataModel) { 17896a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos final Intent secondIntent = new Intent(Intent.ACTION_VIEW); 17906a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos secondIntent.setDataAndType(ContentUris.withAppendedId(Data.CONTENT_URI, 17916a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.getId()), dataModel.secondDataItem.getMimeType()); 17926a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // There is no guarantee the order the data items come in. Second 17936a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // data item does not necessarily mean it's the alternate. 17946a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos // Hangouts video and Add to circles should be alternate. Swap if needed 17956a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos if (HANGOUTS_DATA_5_VIDEO.equals( 17966a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.dataItem.getContentValues().getAsString(Data.DATA5)) || 17976a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos GPLUS_PROFILE_DATA_5_ADD_TO_CIRCLE.equals( 17986a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.dataItem.getContentValues().getAsString(Data.DATA5))) { 17996a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateIntent = dataModel.intent; 18006a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateContentDescription = new StringBuilder(dataModel.header); 18016a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 18026a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.intent = secondIntent; 18036a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.header = dataModel.secondDataItem.buildDataStringForDisplay(dataModel.context, 18046a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.getDataKind()); 18056a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.text = dataModel.secondDataItem.getDataKind().typeColumn; 18066a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } else if (HANGOUTS_DATA_5_MESSAGE.equals( 18076a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.dataItem.getContentValues().getAsString(Data.DATA5)) || 18086a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos GPLUS_PROFILE_DATA_5_VIEW_PROFILE.equals( 18096a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.dataItem.getContentValues().getAsString(Data.DATA5))) { 18106a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateIntent = secondIntent; 18116a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.alternateContentDescription = new StringBuilder( 18126a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.buildDataStringForDisplay(dataModel.context, 18136a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos dataModel.secondDataItem.getDataKind())); 18146a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 18156a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos } 18166a2a1a7d87cd3c59d0e09abce0739ab4175a670ePaul Soulos 18176bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell private static String getIntentResolveLabel(Intent intent, Context context) { 18186bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell final List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, 1819dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos PackageManager.MATCH_DEFAULT_ONLY); 1820dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1821dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos // Pick first match, otherwise best found 1822dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos ResolveInfo bestResolve = null; 1823dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos final int size = matches.size(); 1824dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (size == 1) { 1825dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos bestResolve = matches.get(0); 1826dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } else if (size > 1) { 18276bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell bestResolve = ResolveCache.getInstance(context).getBestResolve(intent, matches); 1828dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1829dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1830dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos if (bestResolve == null) { 1831dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos return null; 1832dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1833dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 18346bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell return String.valueOf(bestResolve.loadLabel(context.getPackageManager())); 1835dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos } 1836dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos 1837edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann /** 183831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * Asynchronously extract the most vibrant color from the PhotoView. Once extracted, 183931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms 184031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell * on a Nexus 5. 184131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell */ 184231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell private void extractAndApplyTintFromPhotoViewAsynchronously() { 184331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell if (mScroller == null) { 184431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell return; 184531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 184631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell final Drawable imageViewDrawable = mPhotoView.getDrawable(); 1847faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell new AsyncTask<Void, Void, MaterialPalette>() { 184831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 1849faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell protected MaterialPalette doInBackground(Void... params) { 1850faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell 1851929a62f5c1bcdc3773270f7d189d88c0464b36adJay Shrauner if (imageViewDrawable instanceof BitmapDrawable && mContactData != null 185295c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell && mContactData.getThumbnailPhotoBinaryData() != null 185395c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell && mContactData.getThumbnailPhotoBinaryData().length > 0) { 185495c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell // Perform the color analysis on the thumbnail instead of the full sized 185595c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell // image, so that our results will be as similar as possible to the Bugle 185695c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell // app. 185795c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell final Bitmap bitmap = BitmapFactory.decodeByteArray( 185895c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell mContactData.getThumbnailPhotoBinaryData(), 0, 185995c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell mContactData.getThumbnailPhotoBinaryData().length); 186095c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell try { 186195c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell final int primaryColor = colorFromBitmap(bitmap); 186295c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell if (primaryColor != 0) { 186395c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor( 186495c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell primaryColor); 186595c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell } 186695c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell } finally { 186795c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell bitmap.recycle(); 1868faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell } 18698a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 18708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (imageViewDrawable instanceof LetterTileDrawable) { 1871faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell final int primaryColor = ((LetterTileDrawable) imageViewDrawable).getColor(); 1872a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(primaryColor); 187331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 1874a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell return MaterialColorMapUtils.getDefaultPrimaryAndSecondaryColors(getResources()); 187531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 187631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 187731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell @Override 1878faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell protected void onPostExecute(MaterialPalette palette) { 1879faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell super.onPostExecute(palette); 18808571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (mHasComputedThemeColor) { 18818571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // If we had previously computed a theme color from the contact photo, 18828571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // then do not update the theme color. Changing the theme color several 18838571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // seconds after QC has started, as a result of an updated/upgraded photo, 18848571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // is a jarring experience. On the other hand, changing the theme color after 18858571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // a rotation or onNewIntent() is perfectly fine. 18868571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell return; 18878571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell } 18888571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // Check that the Photo has not changed. If it has changed, the new tint 18898571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell // color needs to be extracted 18908571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell if (imageViewDrawable == mPhotoView.getDrawable()) { 18918571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell mHasComputedThemeColor = true; 1892faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell setThemeColor(palette); 189331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 189431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 189531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell }.execute(); 189631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell } 189731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell 1898faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell private void setThemeColor(MaterialPalette palette) { 18999b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell // If the color is invalid, use the predefined default 19008e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mColorFilterColor = palette.mPrimaryColor; 19018e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mScroller.setHeaderTintColor(mColorFilterColor); 1902faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell mStatusBarColor = palette.mSecondaryColor; 19039b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell updateStatusBarColor(); 19048571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell 19059b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell mColorFilter = 19068e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell new PorterDuffColorFilter(mColorFilterColor, PorterDuff.Mode.SRC_ATOP); 19078e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mContactCard.setColorAndFilter(mColorFilterColor, mColorFilter); 19088e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mRecentCard.setColorAndFilter(mColorFilterColor, mColorFilter); 19098e29faf7730f744b8f6ff117cae04b5bca1235dbBrian Attwell mAboutCard.setColorAndFilter(mColorFilterColor, mColorFilter); 19109b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell } 19119b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell 19128a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private void updateStatusBarColor() { 19138a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller == null) { 19148a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return; 19158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 19168a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int desiredStatusBarColor; 19178a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Only use a custom status bar color if QuickContacts touches the top of the viewport. 19188a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mScroller.getScrollNeededToBeFullScreen() <= 0) { 19198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = mStatusBarColor; 19208a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } else { 19218a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell desiredStatusBarColor = Color.TRANSPARENT; 19228a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 19238a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Animate to the new color. 1924847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor", 1925847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell getWindow().getStatusBarColor(), desiredStatusBarColor); 1926847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION); 1927847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.setEvaluator(new ArgbEvaluator()); 1928847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell animation.start(); 19298a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 19308a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 19318a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell private int colorFromBitmap(Bitmap bitmap) { 19328a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Author of Palette recommends using 24 colors when analyzing profile photos. 19338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final int NUMBER_OF_PALETTE_COLORS = 24; 19348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell final Palette palette = Palette.generate(bitmap, NUMBER_OF_PALETTE_COLORS); 1935a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell if (palette != null && palette.getVibrantSwatch() != null) { 1936a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell return palette.getVibrantSwatch().getRgb(); 19378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 19388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell return 0; 19398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 19408a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1941b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) { 1942eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<Entry> entries = new ArrayList<>(); 1943b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos for (ContactInteraction interaction : interactions) { 1944ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (interaction == null) { 1945ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell continue; 1946ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 1947ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos entries.add(new Entry(/* id = */ -1, 1948ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos interaction.getIcon(this), 1949b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewHeader(this), 1950b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewBody(this), 1951b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getBodyIcon(this), 1952b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getViewFooter(this), 1953b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getFooterIcon(this), 195423e2836c1e9cbe8996a1344301e69d67bb617891Paul Soulos interaction.getContentDescription(this), 1955b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos interaction.getIntent(), 1956dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIcon = */ null, 1957dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateIntent = */ null, 1958dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos /* alternateContentDescription = */ null, 195948ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos /* shouldApplyColor = */ true, 19602a4207fb39330e840436215c896cde911489e111Paul Soulos /* isEditable = */ false, 196148fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* EntryContextMenuInfo = */ null, 196248fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIcon = */ null, 196348fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos /* thirdIntent = */ null, 196448290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos /* thirdContentDescription = */ null, 196548290bed7c6a8bd5e7be8b206dddacf9047a945fPaul Soulos interaction.getIconResourceId())); 1966b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1967b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return entries; 1968b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 1969b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 1970eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<Contact> mLoaderContactCallbacks = 1971851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu new LoaderCallbacks<Contact>() { 1972cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 1973851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoaderReset(Loader<Contact> loader) { 1974405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos mContactData = null; 1975cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 1976cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 1977cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 1978851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void onLoadFinished(Loader<Contact> loader, Contact data) { 19798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Trace.beginSection("onLoadFinished()"); 1980930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell try { 19818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 1982930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell if (isFinishing()) { 1983930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell return; 1984930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } 1985930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell if (data.isError()) { 198602ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner // This means either the contact is invalid or we had an 198702ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner // internal error such as an acore crash. 198802ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner Log.i(TAG, "Failed to load contact: " + ((ContactLoader)loader).getLookupUri()); 198902ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, 199002ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner Toast.LENGTH_LONG).show(); 199102ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner finish(); 199202ecc3f456a2e9d9fc2713583d387b708ae458d9Jay Shrauner return; 1993930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } 1994930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell if (data.isNotFound()) { 19958a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri()); 19968a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, 19978a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell Toast.LENGTH_LONG).show(); 1998930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell finish(); 1999930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell return; 20008a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 2001cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2002930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell bindContactData(data); 2003cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2004930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } finally { 2005930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell Trace.endSection(); 2006930da3ae6e392777986ed0722c5480caf1bd9e7eBrian Attwell } 2007cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2008cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann 2009cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann @Override 2010851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public Loader<Contact> onCreateLoader(int id, Bundle args) { 2011cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann if (mLookupUri == null) { 2012cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann Log.wtf(TAG, "Lookup uri wasn't initialized. Loader was started too early"); 2013cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2014d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Load all contact data. We need loadGroupMetaData=true to determine whether the 2015d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // contact is invisible. If it is, we need to display an "Add to Contacts" MenuItem. 2016b2b435a944947fbf1965c3bb7c202a97f0273259Yorke Lee return new ContactLoader(getApplicationContext(), mLookupUri, 2017d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell true /*loadGroupMetaData*/, false /*loadInvitableAccountTypes*/, 20188571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell true /*postViewNotification*/, true /*computeFormattedPhoneNumber*/); 2019cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann } 2020cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann }; 2021b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2022b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell @Override 2023b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell public void onBackPressed() { 2024b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell if (mScroller != null) { 20258477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell if (!mIsExitAnimationInProgress) { 20268477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell mScroller.scrollOffBottom(); 20278477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell } 2028b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } else { 2029b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell super.onBackPressed(); 2030b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 2031b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell } 2032b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 20338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 20348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell public void finish() { 20358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.finish(); 20368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 20378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // override transitions to skip the standard window animations 20388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell overridePendingTransition(0, 0); 20398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 20408a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 2041eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos private final LoaderCallbacks<List<ContactInteraction>> mLoaderInteractionsCallbacks = 2042b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos new LoaderCallbacks<List<ContactInteraction>>() { 2043b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2044b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 2045b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public Loader<List<ContactInteraction>> onCreateLoader(int id, Bundle args) { 2046b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos Loader<List<ContactInteraction>> loader = null; 2047b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos switch (id) { 2048b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos case LOADER_SMS_ID: 2049b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos loader = new SmsInteractionsLoader( 2050b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos QuickContactActivity.this, 2051ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 2052b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos MAX_SMS_RETRIEVE); 2053b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos break; 2054899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos case LOADER_CALENDAR_ID: 2055ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos final String[] emailsArray = args.getStringArray(KEY_LOADER_EXTRA_EMAILS); 2056ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos List<String> emailsList = null; 2057ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos if (emailsArray != null) { 2058ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos emailsList = Arrays.asList(args.getStringArray(KEY_LOADER_EXTRA_EMAILS)); 2059ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos } 2060899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos loader = new CalendarInteractionsLoader( 2061899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos QuickContactActivity.this, 2062ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos emailsList, 2063899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_FUTURE_CALENDAR_RETRIEVE, 2064899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos MAX_PAST_CALENDAR_RETRIEVE, 2065899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR, 2066899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR); 2067899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos break; 2068ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos case LOADER_CALL_LOG_ID: 2069ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos loader = new CallLogInteractionsLoader( 2070ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos QuickContactActivity.this, 2071ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos args.getStringArray(KEY_LOADER_EXTRA_PHONES), 2072ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos MAX_CALL_LOG_RETRIEVE); 2073b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2074b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return loader; 2075b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2076b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2077b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 2078b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoadFinished(Loader<List<ContactInteraction>> loader, 2079b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos List<ContactInteraction> data) { 2080b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.put(loader.getId(), data); 2081b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2082b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos if (isAllRecentDataLoaded()) { 2083b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos bindRecentData(); 2084b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2085b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2086b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2087b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 2088b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos public void onLoaderReset(Loader<List<ContactInteraction>> loader) { 2089b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos mRecentLoaderResults.remove(loader.getId()); 2090b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2091b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos }; 2092b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2093b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private boolean isAllRecentDataLoaded() { 2094b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos return mRecentLoaderResults.size() == mRecentLoaderIds.length; 2095b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 2096b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2097b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos private void bindRecentData() { 2098eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final List<ContactInteraction> allInteractions = new ArrayList<>(); 209930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell final List<List<Entry>> interactionsWrapper = new ArrayList<>(); 2100b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos 2101ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell // Serialize mRecentLoaderResults into a single list. This should be done on the main 2102ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell // thread to avoid races against mRecentLoaderResults edits. 2103ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) { 2104ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell allInteractions.addAll(loaderInteractions); 2105ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2106ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell 210730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask = new AsyncTask<Void, Void, Void>() { 2108b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos @Override 210930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell protected Void doInBackground(Void... params) { 211030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.beginSection("sort recent loader results"); 211130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 211230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // Sort the interactions by most recent 211330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Collections.sort(allInteractions, new Comparator<ContactInteraction>() { 211430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell @Override 211530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell public int compare(ContactInteraction a, ContactInteraction b) { 2116ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a == null && b == null) { 2117ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 0; 2118ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2119ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a == null) { 2120ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 1; 2121ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2122ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (b == null) { 2123ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return -1; 2124ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2125ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a.getInteractionDate() > b.getInteractionDate()) { 2126ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return -1; 2127ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2128ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell if (a.getInteractionDate() == b.getInteractionDate()) { 2129ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 0; 2130ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell } 2131ed1882813d7c6b87543d8006a9d02aa55fef8b0dBrian Attwell return 1; 213230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 213330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell }); 213430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 213530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.endSection(); 213630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.beginSection("contactInteractionsToEntries"); 213730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 213830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // Wrap each interaction in its own list so that an icon is displayed for each entry 213930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell for (Entry contactInteraction : contactInteractionsToEntries(allInteractions)) { 214030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell List<Entry> entryListWrapper = new ArrayList<>(1); 214130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell entryListWrapper.add(contactInteraction); 214230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell interactionsWrapper.add(entryListWrapper); 214330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 214430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 214530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.endSection(); 214630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell return null; 2147b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 214830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 214930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell @Override 215030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell protected void onPostExecute(Void aVoid) { 215130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell super.onPostExecute(aVoid); 215230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.beginSection("initialize recents card"); 215330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 215430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell if (allInteractions.size() > 0) { 215530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentCard.initialize(interactionsWrapper, 2156b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN, 2157c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos /* isExpanded = */ mRecentCard.isExpanded(), /* isAlwaysExpanded = */ false, 215830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mExpandingEntryCardViewListener, mScroller); 215930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentCard.setVisibility(View.VISIBLE); 216030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 2161eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos 216230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell Trace.endSection(); 216330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell 216430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // About card is initialized along with the contact card, but since it appears after 216530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // the recent card in the UI, we hold off until making it visible until the recent 216630e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell // card is also ready to avoid stuttering. 216730e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell if (mAboutCard.shouldShow()) { 216830e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mAboutCard.setVisibility(View.VISIBLE); 216930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } else { 217030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mAboutCard.setVisibility(View.GONE); 217130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 217230e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask = null; 217330e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 217430e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell }; 217530e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask.execute(); 2176b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos } 21778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 21788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell @Override 21798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell protected void onStop() { 21808a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell super.onStop(); 21818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell 21828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell if (mEntriesAndActionsTask != null) { 21838a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // Once the activity is stopped, we will no longer want to bind mEntriesAndActionsTask's 21848a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // results on the UI thread. In some circumstances Activities are killed without 21858a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // onStop() being called. This is not a problem, because in these circumstances 21868a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell // the entire process will be killed. 21878a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell mEntriesAndActionsTask.cancel(/* mayInterruptIfRunning = */ false); 21888a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 218930e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell if (mRecentDataTask != null) { 219030e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell mRecentDataTask.cancel(/* mayInterruptIfRunning = */ false); 219130e1ef1927a1a21370b6b5dedd73540152062475Brian Attwell } 21928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell } 219323889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos 219423889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos /** 2195d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell * Returns true if it is possible to edit the current contact. 2196d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell */ 2197d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private boolean isContactEditable() { 2198d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 2199d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2200d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2201a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell /** 2202a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell * Returns true if it is possible to share the current contact. 2203a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell */ 2204a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell private boolean isContactShareable() { 2205a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell return mContactData != null && !mContactData.isDirectoryEntry(); 2206a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell } 2207a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 22086095369885edcca566a812b551886e29c7ff8039Brian Attwell private Intent getEditContactIntent() { 22095a7a23bdb698b8e741a425c9617c5e33e6314cddWalter Jang return EditorIntents.createCompactEditContactIntent( 22101e8801bc9bc60bdd1c95f582c460590272cfad64Walter Jang mContactData.getLookupUri(), 22111e8801bc9bc60bdd1c95f582c460590272cfad64Walter Jang mHasComputedThemeColor 22121e8801bc9bc60bdd1c95f582c460590272cfad64Walter Jang ? new MaterialPalette(mColorFilterColor, mStatusBarColor) : null, 2213ac679af994faece43536f1e8b2613f30c50300e1Walter Jang /* updatedPhotos =*/ null, 2214ac679af994faece43536f1e8b2613f30c50300e1Walter Jang mContactData.getPhotoId()); 22156095369885edcca566a812b551886e29c7ff8039Brian Attwell } 22166095369885edcca566a812b551886e29c7ff8039Brian Attwell 22176095369885edcca566a812b551886e29c7ff8039Brian Attwell private void editContact() { 2218a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 2219c00a0b5370f0714f6af1ea9b3e29b10f25e91af0Zheng Fu mContactLoader.cacheResult(); 22206095369885edcca566a812b551886e29c7ff8039Brian Attwell startActivityForResult(getEditContactIntent(), REQUEST_CODE_CONTACT_EDITOR_ACTIVITY); 2221d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2222d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 22235d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang private void deleteContact() { 22245d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang final Uri contactUri = mContactData.getLookupUri(); 22255d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang ContactDeletionInteraction.start(this, contactUri, /* finishActivityWhenDone =*/ true); 22265d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang } 22275d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang 2228d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell private void toggleStar(MenuItem starredMenuItem) { 2229d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Make sure there is a contact 223063176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell if (mContactData != null) { 2231d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Read the current starred value from the UI instead of using the last 2232d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // loaded state. This allows rapid tapping without writing the same 2233d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // value several times 2234d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final boolean isStarred = starredMenuItem.isChecked(); 2235d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2236d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // To improve responsiveness, swap out the picture (and tag) in the UI already 2237333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, 2238d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.isDirectoryEntry(), mContactData.isUserProfile(), 2239d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell !isStarred); 2240d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2241d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Now perform the real save 2242eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final Intent intent = ContactSaveService.createSetStarredIntent( 224363176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell QuickContactActivity.this, mContactData.getLookupUri(), !isStarred); 2244d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell startService(intent); 224535ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell 224635ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell final CharSequence accessibilityText = !isStarred 224735ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell ? getResources().getText(R.string.description_action_menu_add_star) 224835ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell : getResources().getText(R.string.description_action_menu_remove_star); 224935ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell // Accessibility actions need to have an associated view. We can't access the MenuItem's 225035ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell // underlying view, so put this accessibility action on the root view. 225135ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell mScroller.announceForAccessibility(accessibilityText); 2252d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2253d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2254d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2255752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void shareContact() { 2256752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final String lookupKey = mContactData.getLookupKey(); 2257652936f204b15097d030e870dda5054d8115cbf3Brian Attwell final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); 2258752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent intent = new Intent(Intent.ACTION_SEND); 2259752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell intent.setType(Contacts.CONTENT_VCARD_TYPE); 2260752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell intent.putExtra(Intent.EXTRA_STREAM, shareUri); 2261652936f204b15097d030e870dda5054d8115cbf3Brian Attwell intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 2262652936f204b15097d030e870dda5054d8115cbf3Brian Attwell 2263652936f204b15097d030e870dda5054d8115cbf3Brian Attwell // Even though the data doesn't need to be set for ACTION_SEND, it does need 2264652936f204b15097d030e870dda5054d8115cbf3Brian Attwell // to be set so that FLAG_GRANT_READ_URI_PERMISSION can create a URI permission grant. 2265652936f204b15097d030e870dda5054d8115cbf3Brian Attwell intent.setData(shareUri); 2266752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2267752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Launch chooser to share contact via 2268752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final CharSequence chooseTitle = getText(R.string.share_via); 2269752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final Intent chooseIntent = Intent.createChooser(intent, chooseTitle); 2270752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2271752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell try { 2272a42ef76251778161d27bc07db214b8c81720e476Paul Soulos mHasIntentLaunched = true; 2273652936f204b15097d030e870dda5054d8115cbf3Brian Attwell ImplicitIntentsUtil.startActivityOutsideApp(this, chooseIntent); 2274eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos } catch (final ActivityNotFoundException ex) { 2275752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show(); 2276752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2277752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2278752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2279752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell /** 2280752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell * Creates a launcher shortcut with the current contact. 2281752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell */ 2282752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell private void createLauncherShortcutWithContact() { 2283752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this, 2284752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell new OnShortcutIntentCreatedListener() { 2285752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2286752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell @Override 2287752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) { 2288752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Broadcast the shortcutIntent to the launcher to create a 2289752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // shortcut to this contact 2290752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); 2291752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell QuickContactActivity.this.sendBroadcast(shortcutIntent); 2292752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2293752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // Send a toast to give feedback to the user that a shortcut to this 2294752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell // contact was added to the launcher. 2295752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.makeText(QuickContactActivity.this, 2296752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell R.string.createContactShortcutSuccessful, 2297752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell Toast.LENGTH_SHORT).show(); 2298752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2299752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 2300752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell }); 230163176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell builder.createContactShortcutIntent(mContactData.getLookupUri()); 2302752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell } 2303752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell 230466965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell private boolean isShortcutCreatable() { 23051c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner if (mContactData == null || mContactData.isUserProfile() || 23061c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner mContactData.isDirectoryEntry()) { 23078d0557eb013b2808402e491271fe0f13ffcfabefBrian Attwell return false; 23088d0557eb013b2808402e491271fe0f13ffcfabefBrian Attwell } 230966965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell final Intent createShortcutIntent = new Intent(); 231066965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell createShortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); 231166965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell final List<ResolveInfo> receivers = getPackageManager() 231266965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell .queryBroadcastReceivers(createShortcutIntent, 0); 231366965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell return receivers != null && receivers.size() > 0; 231466965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell } 231566965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell 2316d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 2317d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onCreateOptionsMenu(Menu menu) { 2318eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos final MenuInflater inflater = getMenuInflater(); 2319d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell inflater.inflate(R.menu.quickcontact, menu); 2320d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 2321d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2322d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2323d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 2324d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onPrepareOptionsMenu(Menu menu) { 2325d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (mContactData != null) { 2326d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem starredMenuItem = menu.findItem(R.id.menu_star); 2327333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, 2328d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.isDirectoryEntry(), mContactData.isUserProfile(), 2329d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell mContactData.getStarred()); 2330a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 2331d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell // Configure edit MenuItem 2332d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell final MenuItem editMenuItem = menu.findItem(R.id.menu_edit); 2333d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(true); 2334d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData) || InvisibleContactUtil 2335d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell .isInvisibleAndAddable(mContactData, this)) { 233630cfd121ad8c8adb83cf417ff1d40a8ba1e3761dBrian Attwell editMenuItem.setIcon(R.drawable.ic_person_add_tinted_24dp); 23372e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell editMenuItem.setTitle(R.string.menu_add_contact); 2338d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 2339d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setIcon(R.drawable.ic_create_24dp); 23402e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell editMenuItem.setTitle(R.string.menu_editContact); 2341d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else { 2342d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editMenuItem.setVisible(false); 2343d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2344a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 23455d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang final MenuItem deleteMenuItem = menu.findItem(R.id.menu_delete); 23465d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang deleteMenuItem.setVisible(isContactEditable()); 23475d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang 2348a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell final MenuItem shareMenuItem = menu.findItem(R.id.menu_share); 2349a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell shareMenuItem.setVisible(isContactShareable()); 2350a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell 235166965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell final MenuItem shortcutMenuItem = menu.findItem(R.id.menu_create_contact_shortcut); 235266965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell shortcutMenuItem.setVisible(isShortcutCreatable()); 235366965e14e741be40f3f5ad6aa21a75795f9a1eb1Brian Attwell 235456bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell final MenuItem helpMenu = menu.findItem(R.id.menu_help); 235556bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell helpMenu.setVisible(HelpUtils.isHelpAndFeedbackAvailable()); 235656bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell 23578a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return true; 2358d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 23598a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos return false; 2360d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2361d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell 2362d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell @Override 2363d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell public boolean onOptionsItemSelected(MenuItem item) { 2364d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell switch (item.getItemId()) { 2365d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell case R.id.menu_star: 2366d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell toggleStar(item); 2367d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 2368d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell case R.id.menu_edit: 2369d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell if (DirectoryContactUtil.isDirectoryContact(mContactData)) { 2370ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // This action is used to launch the contact selector, with the option of 2371ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // creating a new contact. Creating a new contact is an INSERT, while selecting 2372ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // an exisiting one is an edit. The fields in the edit screen will be 2373ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // prepopulated with data. 2374ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos 2375ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); 2376ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos intent.setType(Contacts.CONTENT_ITEM_TYPE); 2377ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos 2378fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell ArrayList<ContentValues> values = mContactData.getContentValues(); 2379fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell 2380fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // Only pre-fill the name field if the provided display name is an nickname 2381fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // or better (e.g. structured name, nickname) 2382fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell if (mContactData.getDisplayNameSource() >= DisplayNameSources.NICKNAME) { 2383ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos intent.putExtra(Intents.Insert.NAME, mContactData.getDisplayName()); 2384fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell } else if (mContactData.getDisplayNameSource() 2385fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell == DisplayNameSources.ORGANIZATION) { 2386fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // This is probably an organization. Instead of copying the organization 2387fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // name into a name entry, copy it into the organization entry. This 2388fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell // way we will still consider the contact an organization. 2389fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell final ContentValues organization = new ContentValues(); 2390fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell organization.put(Organization.COMPANY, mContactData.getDisplayName()); 2391fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell organization.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE); 2392fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell values.add(organization); 2393ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } 2394fc423b4040a0ec1728ee32ff40ef430f3e16e9dcBrian Attwell 2395ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // Last time used and times used are aggregated values from the usage stat 2396ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // table. They need to be removed from data values so the SQL table can insert 2397ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // properly 2398ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos for (ContentValues value : values) { 2399ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos value.remove(Data.LAST_TIME_USED); 2400ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos value.remove(Data.TIMES_USED); 2401ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } 2402ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos intent.putExtra(Intents.Insert.DATA, values); 2403ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos 2404ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // If the contact can only export to the same account, add it to the intent. 2405ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // Otherwise the ContactEditorFragment will show a dialog for selecting an 2406ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos // account. 2407ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos if (mContactData.getDirectoryExportSupport() == 2408ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos Directory.EXPORT_SUPPORT_SAME_ACCOUNT_ONLY) { 24094a1c574cd62eb7ca1e0fcc3a61e5378e5e0787feBrian Attwell intent.putExtra(Intents.Insert.EXTRA_ACCOUNT, 2410ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos new Account(mContactData.getDirectoryAccountName(), 2411ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos mContactData.getDirectoryAccountType())); 24124a1c574cd62eb7ca1e0fcc3a61e5378e5e0787feBrian Attwell intent.putExtra(Intents.Insert.EXTRA_DATA_SET, 2413ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos mContactData.getRawContacts().get(0).getDataSet()); 2414ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos } 2415ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos 2416f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos // Add this flag to disable the delete menu option on directory contact joins 2417f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos // with local contacts. The delete option is ambiguous when joining contacts. 2418f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos intent.putExtra(ContactEditorFragment.INTENT_EXTRA_DISABLE_DELETE_MENU_OPTION, 2419f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos true); 2420f19dda97bfdef84e3f39ba069a981004a5c797b1Paul Soulos 2421ab54ea15274dd3975c82a6aac29ba268aaed0799Paul Soulos startActivityForResult(intent, REQUEST_CODE_CONTACT_SELECTION_ACTIVITY); 2422d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { 2423d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell InvisibleContactUtil.addToDefaultGroup(mContactData, this); 2424d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } else if (isContactEditable()) { 2425d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell editContact(); 2426d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 2427d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return true; 24285d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang case R.id.menu_delete: 24291c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner if (isContactEditable()) { 24301c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner deleteContact(); 24311c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner } 24325d2e262ab3658118a12fbf6d0edab76484368c24Walter Jang return true; 2433752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell case R.id.menu_share: 243449de62f06d24653484adebd69123eeff2850a757Jay Shrauner if (isContactShareable()) { 243549de62f06d24653484adebd69123eeff2850a757Jay Shrauner shareContact(); 243649de62f06d24653484adebd69123eeff2850a757Jay Shrauner } 2437752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return true; 2438752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell case R.id.menu_create_contact_shortcut: 24391c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner if (isShortcutCreatable()) { 24401c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner createLauncherShortcutWithContact(); 24411c06ce7ba10cb95183a704d5835e8005c023f726Jay Shrauner } 2442752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell return true; 244356bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell case R.id.menu_help: 244456bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell HelpUtils.launchHelpAndFeedbackForContactScreen(this); 244556bcc2fc455dcb434545fcdeb07c5f916dece847Brian Attwell return true; 2446d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell default: 2447d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell return super.onOptionsItemSelected(item); 2448d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell } 244923889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos } 2450edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann} 2451