Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 1 | /* |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 3 | * Copyright (C) 2009 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | package com.android.contacts.quickcontact; |
| 19 | |
Walter Jang | 0e723d9 | 2016-07-07 19:00:30 -0700 | [diff] [blame] | 20 | import android.Manifest; |
Paul Soulos | ab54ea1 | 2014-08-28 17:22:38 -0700 | [diff] [blame] | 21 | import android.accounts.Account; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 22 | import android.animation.ArgbEvaluator; |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 23 | import android.animation.ObjectAnimator; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 24 | import android.app.Activity; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 25 | import android.app.Fragment; |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 26 | import android.app.LoaderManager.LoaderCallbacks; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 27 | import android.app.SearchManager; |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 28 | import android.content.ActivityNotFoundException; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 29 | import android.content.ContentUris; |
Paul Soulos | ea5e0b7 | 2014-07-08 18:09:44 -0700 | [diff] [blame] | 30 | import android.content.ContentValues; |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 31 | import android.content.Context; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 32 | import android.content.Intent; |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 33 | import android.content.Loader; |
Paul Soulos | dd7419d | 2014-07-15 11:22:13 -0700 | [diff] [blame] | 34 | import android.content.pm.PackageManager; |
| 35 | import android.content.pm.ResolveInfo; |
Wenyi Wang | 8d02b16 | 2016-01-10 12:43:36 -0800 | [diff] [blame] | 36 | import android.content.res.ColorStateList; |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 37 | import android.content.res.Resources; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 38 | import android.graphics.Bitmap; |
Brian Attwell | 95c268e | 2014-08-26 22:04:15 -0700 | [diff] [blame] | 39 | import android.graphics.BitmapFactory; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 40 | import android.graphics.Color; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 41 | import android.graphics.PorterDuff; |
| 42 | import android.graphics.PorterDuffColorFilter; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 43 | import android.graphics.drawable.BitmapDrawable; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 44 | import android.graphics.drawable.ColorDrawable; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 45 | import android.graphics.drawable.Drawable; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 46 | import android.net.Uri; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 47 | import android.os.AsyncTask; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 48 | import android.os.Bundle; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 49 | import android.os.Trace; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 50 | import android.provider.CalendarContract; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 51 | import android.provider.ContactsContract; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 52 | import android.provider.ContactsContract.CommonDataKinds.Email; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 53 | import android.provider.ContactsContract.CommonDataKinds.Event; |
| 54 | import android.provider.ContactsContract.CommonDataKinds.GroupMembership; |
| 55 | import android.provider.ContactsContract.CommonDataKinds.Identity; |
| 56 | import android.provider.ContactsContract.CommonDataKinds.Im; |
| 57 | import android.provider.ContactsContract.CommonDataKinds.Nickname; |
| 58 | import android.provider.ContactsContract.CommonDataKinds.Note; |
| 59 | import android.provider.ContactsContract.CommonDataKinds.Organization; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 60 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 61 | import android.provider.ContactsContract.CommonDataKinds.Relation; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 62 | import android.provider.ContactsContract.CommonDataKinds.SipAddress; |
| 63 | import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; |
| 64 | import android.provider.ContactsContract.CommonDataKinds.Website; |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 65 | import android.provider.ContactsContract.Contacts; |
Paul Soulos | 60e5108 | 2014-07-10 12:33:04 -0700 | [diff] [blame] | 66 | import android.provider.ContactsContract.Data; |
Paul Soulos | ab54ea1 | 2014-08-28 17:22:38 -0700 | [diff] [blame] | 67 | import android.provider.ContactsContract.Directory; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 68 | import android.provider.ContactsContract.DisplayNameSources; |
Paul Soulos | ea5e0b7 | 2014-07-08 18:09:44 -0700 | [diff] [blame] | 69 | import android.provider.ContactsContract.DataUsageFeedback; |
Paul Soulos | ab54ea1 | 2014-08-28 17:22:38 -0700 | [diff] [blame] | 70 | import android.provider.ContactsContract.Intents; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 71 | import android.provider.ContactsContract.QuickContact; |
| 72 | import android.provider.ContactsContract.RawContacts; |
guanxiongliu | 8e56edf | 2016-07-14 13:48:55 -0700 | [diff] [blame] | 73 | import android.support.graphics.drawable.VectorDrawableCompat; |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 74 | import android.support.v4.app.ActivityCompat; |
Wenyi Wang | 23d9b6e | 2015-11-19 15:09:06 -0800 | [diff] [blame] | 75 | import android.support.v4.content.ContextCompat; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 76 | import android.support.v7.graphics.Palette; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 77 | import android.support.v7.widget.CardView; |
Tyler Gunn | 0319222 | 2014-09-10 15:20:09 -0700 | [diff] [blame] | 78 | import android.telecom.PhoneAccount; |
| 79 | import android.telecom.TelecomManager; |
Brian Attwell | c62cc79 | 2014-10-02 12:35:07 -0700 | [diff] [blame] | 80 | import android.text.BidiFormatter; |
Tingting Wang | b6949dc | 2015-11-03 13:17:12 -0800 | [diff] [blame] | 81 | import android.text.Spannable; |
Walter Jang | 7ce5352 | 2014-10-29 13:26:43 -0700 | [diff] [blame] | 82 | import android.text.SpannableString; |
Brian Attwell | c62cc79 | 2014-10-02 12:35:07 -0700 | [diff] [blame] | 83 | import android.text.TextDirectionHeuristics; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 84 | import android.text.TextUtils; |
| 85 | import android.util.Log; |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 86 | import android.view.ContextMenu; |
| 87 | import android.view.ContextMenu.ContextMenuInfo; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 88 | import android.view.LayoutInflater; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 89 | import android.view.Menu; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 90 | import android.view.MenuInflater; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 91 | import android.view.MenuItem; |
Nancy Chen | f619e43 | 2014-08-18 20:15:12 -0700 | [diff] [blame] | 92 | import android.view.MotionEvent; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 93 | import android.view.View; |
| 94 | import android.view.View.OnClickListener; |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 95 | import android.view.View.OnCreateContextMenuListener; |
Daisuke Miyakawa | 10d7df7 | 2011-07-29 16:11:05 -0700 | [diff] [blame] | 96 | import android.view.WindowManager; |
guanxiongliu | bcae18d | 2016-02-26 11:04:19 -0800 | [diff] [blame] | 97 | import android.view.accessibility.AccessibilityEvent; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 98 | import android.widget.Button; |
| 99 | import android.widget.CheckBox; |
| 100 | import android.widget.ImageView; |
| 101 | import android.widget.LinearLayout; |
| 102 | import android.widget.TextView; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 103 | import android.widget.Toast; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 104 | import android.widget.Toolbar; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 105 | |
Christine Chen | 72b3ab1 | 2013-08-13 23:22:34 +0200 | [diff] [blame] | 106 | import com.android.contacts.ContactSaveService; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 107 | import com.android.contacts.ContactsActivity; |
Brian Attwell | 2d150da | 2014-07-09 22:35:56 -0700 | [diff] [blame] | 108 | import com.android.contacts.NfcHandler; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 109 | import com.android.contacts.R; |
Wenyi Wang | d1cb904 | 2015-11-05 17:17:59 -0800 | [diff] [blame] | 110 | import com.android.contacts.activities.ContactEditorBaseActivity; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 111 | import com.android.contacts.common.CallUtil; |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 112 | import com.android.contacts.common.ClipboardUtils; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 113 | import com.android.contacts.common.Collapser; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 114 | import com.android.contacts.common.ContactPhotoManager; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 115 | import com.android.contacts.common.ContactsUtils; |
Walter Jang | f623637 | 2016-02-22 21:24:22 +0000 | [diff] [blame] | 116 | import com.android.contacts.common.activity.RequestDesiredPermissionsActivity; |
Brian Attwell | bdd3264 | 2015-05-08 17:03:15 -0700 | [diff] [blame] | 117 | import com.android.contacts.common.activity.RequestPermissionsActivity; |
Wenyi Wang | 4c3d3e2 | 2015-12-17 14:30:02 -0800 | [diff] [blame] | 118 | import com.android.contacts.common.compat.CompatUtils; |
Wenyi Wang | c85af28 | 2015-12-21 15:55:32 -0800 | [diff] [blame] | 119 | import com.android.contacts.common.compat.EventCompat; |
Wenyi Wang | caf2619 | 2016-05-09 15:00:25 -0700 | [diff] [blame] | 120 | import com.android.contacts.common.compat.MultiWindowCompat; |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 121 | import com.android.contacts.common.dialog.CallSubjectDialog; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 122 | import com.android.contacts.common.editor.SelectAccountDialogFragment; |
Nancy Chen | 70e3f4f | 2014-08-13 16:04:43 -0700 | [diff] [blame] | 123 | import com.android.contacts.common.interactions.TouchPointManager; |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 124 | import com.android.contacts.common.lettertiles.LetterTileDrawable; |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 125 | import com.android.contacts.common.list.ShortcutIntentBuilder; |
| 126 | import com.android.contacts.common.list.ShortcutIntentBuilder.OnShortcutIntentCreatedListener; |
Walter Jang | 62a2074 | 2016-02-24 17:04:12 -0800 | [diff] [blame] | 127 | import com.android.contacts.common.logging.Logger; |
| 128 | import com.android.contacts.common.logging.ScreenEvent.ScreenType; |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 129 | import com.android.contacts.common.logging.QuickContactEvent.ContactType; |
| 130 | import com.android.contacts.common.logging.QuickContactEvent.CardType; |
| 131 | import com.android.contacts.common.logging.QuickContactEvent.ActionType; |
Chiao Cheng | 0d5588d | 2012-11-26 15:34:14 -0800 | [diff] [blame] | 132 | import com.android.contacts.common.model.AccountTypeManager; |
Yorke Lee | cd321f6 | 2013-10-28 15:20:15 -0700 | [diff] [blame] | 133 | import com.android.contacts.common.model.Contact; |
| 134 | import com.android.contacts.common.model.ContactLoader; |
| 135 | import com.android.contacts.common.model.RawContact; |
Chiao Cheng | 428f008 | 2012-11-13 18:38:56 -0800 | [diff] [blame] | 136 | import com.android.contacts.common.model.account.AccountType; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 137 | import com.android.contacts.common.model.account.AccountWithDataSet; |
Yorke Lee | cd321f6 | 2013-10-28 15:20:15 -0700 | [diff] [blame] | 138 | import com.android.contacts.common.model.dataitem.DataItem; |
Chiao Cheng | 428f008 | 2012-11-13 18:38:56 -0800 | [diff] [blame] | 139 | import com.android.contacts.common.model.dataitem.DataKind; |
Yorke Lee | cd321f6 | 2013-10-28 15:20:15 -0700 | [diff] [blame] | 140 | import com.android.contacts.common.model.dataitem.EmailDataItem; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 141 | import com.android.contacts.common.model.dataitem.EventDataItem; |
Yorke Lee | cd321f6 | 2013-10-28 15:20:15 -0700 | [diff] [blame] | 142 | import com.android.contacts.common.model.dataitem.ImDataItem; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 143 | import com.android.contacts.common.model.dataitem.NicknameDataItem; |
| 144 | import com.android.contacts.common.model.dataitem.NoteDataItem; |
| 145 | import com.android.contacts.common.model.dataitem.OrganizationDataItem; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 146 | import com.android.contacts.common.model.dataitem.PhoneDataItem; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 147 | import com.android.contacts.common.model.dataitem.RelationDataItem; |
| 148 | import com.android.contacts.common.model.dataitem.SipAddressDataItem; |
| 149 | import com.android.contacts.common.model.dataitem.StructuredNameDataItem; |
| 150 | import com.android.contacts.common.model.dataitem.StructuredPostalDataItem; |
| 151 | import com.android.contacts.common.model.dataitem.WebsiteDataItem; |
yaolu | 1bd8826 | 2016-08-18 10:29:12 -0700 | [diff] [blame] | 152 | import com.android.contacts.common.model.dataitem.CustomDataItem; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 153 | import com.android.contacts.common.model.ValuesDelta; |
Brian Attwell | c6100ff | 2015-02-19 21:35:36 -0800 | [diff] [blame] | 154 | import com.android.contacts.common.util.ImplicitIntentsUtil; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 155 | import com.android.contacts.common.util.DateUtils; |
Brian Attwell | faf9739 | 2014-07-10 18:32:30 -0700 | [diff] [blame] | 156 | import com.android.contacts.common.util.MaterialColorMapUtils; |
| 157 | import com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette; |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 158 | import com.android.contacts.common.util.PermissionsUtil; |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 159 | import com.android.contacts.common.util.UriUtils; |
Brian Attwell | d41ab8a | 2014-08-07 11:08:55 -0700 | [diff] [blame] | 160 | import com.android.contacts.common.util.ViewUtil; |
Paul Soulos | 333091a | 2014-07-22 13:54:41 -0700 | [diff] [blame] | 161 | import com.android.contacts.detail.ContactDisplayUtils; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 162 | import com.android.contacts.editor.AggregationSuggestionEngine; |
| 163 | import com.android.contacts.editor.AggregationSuggestionEngine.Suggestion; |
Paul Soulos | f19dda9 | 2014-09-15 15:48:02 -0700 | [diff] [blame] | 164 | import com.android.contacts.editor.ContactEditorFragment; |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 165 | import com.android.contacts.editor.EditorIntents; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 166 | import com.android.contacts.interactions.CalendarInteractionsLoader; |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 167 | import com.android.contacts.interactions.CallLogInteractionsLoader; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 168 | import com.android.contacts.interactions.ContactDeletionInteraction; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 169 | import com.android.contacts.interactions.ContactInteraction; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 170 | import com.android.contacts.interactions.SmsInteractionsLoader; |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 171 | import com.android.contacts.quickcontact.ExpandingEntryCardView.Entry; |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 172 | import com.android.contacts.quickcontact.ExpandingEntryCardView.EntryContextMenuInfo; |
Paul Soulos | 2ed2a73 | 2014-08-12 11:58:39 -0700 | [diff] [blame] | 173 | import com.android.contacts.quickcontact.ExpandingEntryCardView.EntryTag; |
Brian Attwell | e8ce6ee | 2014-06-27 18:26:32 -0700 | [diff] [blame] | 174 | import com.android.contacts.quickcontact.ExpandingEntryCardView.ExpandingEntryCardViewListener; |
Brian Attwell | 493f8d1 | 2014-12-18 12:42:03 -0800 | [diff] [blame] | 175 | import com.android.contacts.quickcontact.WebAddress.ParseException; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 176 | import com.android.contacts.util.ImageViewDrawableSetter; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 177 | import com.android.contacts.util.PhoneCapabilityTester; |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 178 | import com.android.contacts.util.SchedulingUtils; |
Tingting Wang | ac9596e | 2016-08-02 22:24:24 -0700 | [diff] [blame] | 179 | import com.android.contacts.util.SharedPreferenceUtil; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 180 | import com.android.contacts.util.StructuredPostalUtils; |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 181 | import com.android.contacts.widget.MultiShrinkScroller; |
| 182 | import com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener; |
Brian Attwell | 02eaf11 | 2014-08-27 21:03:42 -0700 | [diff] [blame] | 183 | import com.android.contacts.widget.QuickContactImageView; |
Brian Attwell | 56bcc2f | 2015-02-12 23:45:27 +0000 | [diff] [blame] | 184 | import com.android.contactsbind.HelpUtils; |
| 185 | |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 186 | import com.google.common.collect.Lists; |
| 187 | |
Jay Shrauner | 82a5a35 | 2014-11-24 11:37:44 -0800 | [diff] [blame] | 188 | import java.lang.SecurityException; |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 189 | import java.util.ArrayList; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 190 | import java.util.Arrays; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 191 | import java.util.Calendar; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 192 | import java.util.Collections; |
| 193 | import java.util.Comparator; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 194 | import java.util.Date; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 195 | import java.util.HashMap; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 196 | import java.util.HashSet; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 197 | import java.util.List; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 198 | import java.util.Map; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 199 | import java.util.Set; |
| 200 | import java.util.TreeSet; |
Jay Shrauner | 12ac1e6 | 2014-12-08 15:57:19 -0800 | [diff] [blame] | 201 | import java.util.concurrent.ConcurrentHashMap; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 202 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 203 | /** |
| 204 | * Mostly translucent {@link Activity} that shows QuickContact dialog. It loads |
| 205 | * data asynchronously, and then shows a popup with details centered around |
| 206 | * {@link Intent#getSourceBounds()}. |
| 207 | */ |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 208 | public class QuickContactActivity extends ContactsActivity |
Cody Thomas | f32dc99 | 2016-05-11 10:56:04 -0700 | [diff] [blame] | 209 | implements AggregationSuggestionEngine.Listener { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * QuickContacts immediately takes up the full screen. All possible information is shown. |
| 213 | * This value for {@link android.provider.ContactsContract.QuickContact#EXTRA_MODE} |
| 214 | * should only be used by the Contacts app. |
| 215 | */ |
| 216 | public static final int MODE_FULLY_EXPANDED = 4; |
| 217 | |
Walter Jang | 62a2074 | 2016-02-24 17:04:12 -0800 | [diff] [blame] | 218 | /** Used to pass the screen where the user came before launching this Activity. */ |
| 219 | public static final String EXTRA_PREVIOUS_SCREEN_TYPE = "previous_screen_type"; |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 220 | /** Used to pass the Contact card action. */ |
| 221 | public static final String EXTRA_ACTION_TYPE = "action_type"; |
| 222 | public static final String EXTRA_THIRD_PARTY_ACTION = "third_party_action"; |
| 223 | |
Gary Mai | 250fc16 | 2016-06-10 16:54:15 -0700 | [diff] [blame] | 224 | /** Used to tell the QuickContact that the previous contact was edited, so it can return an |
| 225 | * activity result back to the original Activity that launched it. */ |
| 226 | public static final String EXTRA_CONTACT_EDITED = "contact_edited"; |
Walter Jang | 62a2074 | 2016-02-24 17:04:12 -0800 | [diff] [blame] | 227 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 228 | private static final String TAG = "QuickContact"; |
| 229 | |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 230 | private static final String KEY_THEME_COLOR = "theme_color"; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 231 | private static final String KEY_IS_SUGGESTION_LIST_COLLAPSED = "is_suggestion_list_collapsed"; |
| 232 | private static final String KEY_SELECTED_SUGGESTION_CONTACTS = "selected_suggestion_contacts"; |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 233 | private static final String KEY_PREVIOUS_CONTACT_ID = "previous_contact_id"; |
| 234 | private static final String KEY_SUGGESTIONS_AUTO_SELECTED = "suggestions_auto_seleted"; |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 235 | |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 236 | private static final int ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION = 150; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 237 | private static final int REQUEST_CODE_CONTACT_EDITOR_ACTIVITY = 1; |
Brian Attwell | 0b267fe | 2014-10-24 19:24:40 +0000 | [diff] [blame] | 238 | private static final int SCRIM_COLOR = Color.argb(0xC8, 0, 0, 0); |
Paul Soulos | ab54ea1 | 2014-08-28 17:22:38 -0700 | [diff] [blame] | 239 | private static final int REQUEST_CODE_CONTACT_SELECTION_ACTIVITY = 2; |
Paul Soulos | ea5e0b7 | 2014-07-08 18:09:44 -0700 | [diff] [blame] | 240 | private static final String MIMETYPE_SMS = "vnd.android-dir/mms-sms"; |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 241 | |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 242 | /** This is the Intent action to install a shortcut in the launcher. */ |
| 243 | private static final String ACTION_INSTALL_SHORTCUT = |
| 244 | "com.android.launcher.action.INSTALL_SHORTCUT"; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 245 | |
| 246 | @SuppressWarnings("deprecation") |
| 247 | private static final String LEGACY_AUTHORITY = android.provider.Contacts.AUTHORITY; |
| 248 | |
Paul Soulos | e005566 | 2014-07-10 16:33:08 -0700 | [diff] [blame] | 249 | private static final String MIMETYPE_GPLUS_PROFILE = |
| 250 | "vnd.android.cursor.item/vnd.googleplus.profile"; |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 251 | private static final String GPLUS_PROFILE_DATA_5_VIEW_PROFILE = "view"; |
Paul Soulos | e005566 | 2014-07-10 16:33:08 -0700 | [diff] [blame] | 252 | private static final String MIMETYPE_HANGOUTS = |
| 253 | "vnd.android.cursor.item/vnd.googleplus.profile.comm"; |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 254 | private static final String HANGOUTS_DATA_5_VIDEO = "hangout"; |
| 255 | private static final String HANGOUTS_DATA_5_MESSAGE = "conversation"; |
Paul Soulos | 48fc912 | 2014-08-26 13:52:36 -0700 | [diff] [blame] | 256 | private static final String CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY = |
| 257 | "com.android.contacts.quickcontact.QuickContactActivity"; |
Paul Soulos | e005566 | 2014-07-10 16:33:08 -0700 | [diff] [blame] | 258 | |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 259 | // Set true in {@link #onCreate} after orientation change for later use in processIntent(). |
| 260 | private boolean mIsRecreatedInstance; |
| 261 | |
| 262 | private boolean mShouldLog; |
| 263 | |
| 264 | // Used to store and log the referrer package name and the contact type. |
| 265 | private String mReferrer; |
| 266 | private int mContactType; |
| 267 | |
Brian Attwell | 63176c9 | 2014-08-18 15:14:18 -0700 | [diff] [blame] | 268 | /** |
| 269 | * The URI used to load the the Contact. Once the contact is loaded, use Contact#getLookupUri() |
| 270 | * instead of referencing this URI. |
| 271 | */ |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 272 | private Uri mLookupUri; |
| 273 | private String[] mExcludeMimes; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 274 | private int mExtraMode; |
Brian Attwell | 05287bf | 2015-02-25 22:24:04 -0800 | [diff] [blame] | 275 | private String mExtraPrioritizedMimeType; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 276 | private int mStatusBarColor; |
| 277 | private boolean mHasAlreadyBeenOpened; |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 278 | private boolean mOnlyOnePhoneNumber; |
| 279 | private boolean mOnlyOneEmail; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 280 | |
Brian Attwell | 02eaf11 | 2014-08-27 21:03:42 -0700 | [diff] [blame] | 281 | private QuickContactImageView mPhotoView; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 282 | private ExpandingEntryCardView mContactCard; |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 283 | private ExpandingEntryCardView mNoContactDetailsCard; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 284 | private ExpandingEntryCardView mRecentCard; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 285 | private ExpandingEntryCardView mAboutCard; |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 286 | private ExpandingEntryCardView mPermissionExplanationCard; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 287 | |
| 288 | // Suggestion card. |
Gary Mai | d1d8a7a | 2016-06-07 14:46:58 -0700 | [diff] [blame] | 289 | private boolean mShouldShowSuggestions = false; |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 290 | private CardView mCollapsedSuggestionCardView; |
| 291 | private CardView mExpandSuggestionCardView; |
Gary Mai | d1d8a7a | 2016-06-07 14:46:58 -0700 | [diff] [blame] | 292 | private View mCollapsedSuggestionHeader; |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 293 | private TextView mCollapsedSuggestionCardTitle; |
| 294 | private TextView mExpandSuggestionCardTitle; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 295 | private ImageView mSuggestionSummaryPhoto; |
| 296 | private TextView mSuggestionForName; |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 297 | private TextView mSuggestionContactsNumber; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 298 | private LinearLayout mSuggestionList; |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 299 | private Button mSuggestionsCancelButton; |
Tingting Wang | 5585c6e | 2015-10-14 11:19:58 -0700 | [diff] [blame] | 300 | private Button mSuggestionsLinkButton; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 301 | private boolean mIsSuggestionListCollapsed; |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 302 | private boolean mSuggestionsShouldAutoSelected = true; |
| 303 | private long mPreviousContactId = 0; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 304 | |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 305 | // Permission explanation card. |
| 306 | private boolean mShouldShowPermissionExplanation = false; |
| 307 | private String mPermissionExplanationCardSubHeader = ""; |
| 308 | |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 309 | private MultiShrinkScroller mScroller; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 310 | private SelectAccountDialogFragmentListener mSelectAccountFragmentListener; |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 311 | private AsyncTask<Void, Void, Cp2DataCardModel> mEntriesAndActionsTask; |
Brian Attwell | 30e1ef1 | 2014-09-02 15:49:20 -0700 | [diff] [blame] | 312 | private AsyncTask<Void, Void, Void> mRecentDataTask; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 313 | |
| 314 | private AggregationSuggestionEngine mAggregationSuggestionEngine; |
| 315 | private List<Suggestion> mSuggestions; |
| 316 | |
| 317 | private TreeSet<Long> mSelectedAggregationIds = new TreeSet<>(); |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 318 | /** |
| 319 | * The last copy of Cp2DataCardModel that was passed to {@link #populateContactAndAboutCard}. |
| 320 | */ |
| 321 | private Cp2DataCardModel mCachedCp2DataCardModel; |
Brian Attwell | f1076dc | 2014-08-12 21:28:21 -0700 | [diff] [blame] | 322 | /** |
| 323 | * This scrim's opacity is controlled in two different ways. 1) Before the initial entrance |
| 324 | * animation finishes, the opacity is animated by a value animator. This is designed to |
| 325 | * distract the user from the length of the initial loading time. 2) After the initial |
| 326 | * entrance animation, the opacity is directly related to scroll position. |
| 327 | */ |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 328 | private ColorDrawable mWindowScrim; |
Brian Attwell | f1076dc | 2014-08-12 21:28:21 -0700 | [diff] [blame] | 329 | private boolean mIsEntranceAnimationFinished; |
Brian Attwell | a3859ed | 2014-07-15 13:51:55 -0700 | [diff] [blame] | 330 | private MaterialColorMapUtils mMaterialColorMapUtils; |
Brian Attwell | 8477eaf | 2014-06-18 15:39:50 -0700 | [diff] [blame] | 331 | private boolean mIsExitAnimationInProgress; |
Brian Attwell | 8571dd3 | 2014-06-23 23:29:10 -0700 | [diff] [blame] | 332 | private boolean mHasComputedThemeColor; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 333 | |
Paul Soulos | a42ef76 | 2014-08-20 10:26:10 -0700 | [diff] [blame] | 334 | /** |
| 335 | * Used to stop the ExpandingEntry cards from adjusting between an entry click and the intent |
| 336 | * being launched. |
| 337 | */ |
| 338 | private boolean mHasIntentLaunched; |
| 339 | |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 340 | private Contact mContactData; |
Daniel Lehmann | 9815d7f | 2012-04-16 18:28:03 -0700 | [diff] [blame] | 341 | private ContactLoader mContactLoader; |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 342 | private PorterDuffColorFilter mColorFilter; |
Brian Attwell | 8e29faf | 2015-01-21 10:22:40 -0800 | [diff] [blame] | 343 | private int mColorFilterColor; |
Daniel Lehmann | 9815d7f | 2012-04-16 18:28:03 -0700 | [diff] [blame] | 344 | |
Josh Gargus | 9758a92 | 2012-03-08 17:12:42 -0800 | [diff] [blame] | 345 | private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter(); |
| 346 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 347 | /** |
Paul Soulos | cb4fcc7 | 2014-07-15 14:08:50 -0700 | [diff] [blame] | 348 | * {@link #LEADING_MIMETYPES} is used to sort MIME-types. |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 349 | * |
| 350 | * <p>The MIME-types in {@link #LEADING_MIMETYPES} appear in the front of the dialog, |
| 351 | * in the order specified here.</p> |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 352 | */ |
| 353 | private static final List<String> LEADING_MIMETYPES = Lists.newArrayList( |
Paul Soulos | cb4fcc7 | 2014-07-15 14:08:50 -0700 | [diff] [blame] | 354 | Phone.CONTENT_ITEM_TYPE, SipAddress.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE, |
Paul Soulos | 405ae40 | 2014-07-14 16:16:36 -0700 | [diff] [blame] | 355 | StructuredPostal.CONTENT_ITEM_TYPE); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 356 | |
Paul Soulos | a153dba | 2014-08-06 13:44:57 -0700 | [diff] [blame] | 357 | private static final List<String> SORTED_ABOUT_CARD_MIMETYPES = Lists.newArrayList( |
| 358 | Nickname.CONTENT_ITEM_TYPE, |
| 359 | // Phonetic name is inserted after nickname if it is available. |
| 360 | // No mimetype for phonetic name exists. |
| 361 | Website.CONTENT_ITEM_TYPE, |
| 362 | Organization.CONTENT_ITEM_TYPE, |
| 363 | Event.CONTENT_ITEM_TYPE, |
| 364 | Relation.CONTENT_ITEM_TYPE, |
| 365 | Im.CONTENT_ITEM_TYPE, |
| 366 | GroupMembership.CONTENT_ITEM_TYPE, |
| 367 | Identity.CONTENT_ITEM_TYPE, |
yaolu | 1bd8826 | 2016-08-18 10:29:12 -0700 | [diff] [blame] | 368 | CustomDataItem.MIMETYPE_CUSTOM_FIELD, |
Paul Soulos | a153dba | 2014-08-06 13:44:57 -0700 | [diff] [blame] | 369 | Note.CONTENT_ITEM_TYPE); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 370 | |
Brian Attwell | c62cc79 | 2014-10-02 12:35:07 -0700 | [diff] [blame] | 371 | private static final BidiFormatter sBidiFormatter = BidiFormatter.getInstance(); |
| 372 | |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 373 | /** Id for the background contact loader */ |
| 374 | private static final int LOADER_CONTACT_ID = 0; |
| 375 | |
| 376 | /** Id for the background Sms Loader */ |
| 377 | private static final int LOADER_SMS_ID = 1; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 378 | private static final int MAX_SMS_RETRIEVE = 3; |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 379 | |
| 380 | /** Id for the back Calendar Loader */ |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 381 | private static final int LOADER_CALENDAR_ID = 2; |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 382 | private static final String KEY_LOADER_EXTRA_EMAILS = |
| 383 | QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_EMAILS"; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 384 | private static final int MAX_PAST_CALENDAR_RETRIEVE = 3; |
| 385 | private static final int MAX_FUTURE_CALENDAR_RETRIEVE = 3; |
| 386 | private static final long PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = |
Paul Soulos | 40d7a65 | 2014-09-03 13:54:11 -0700 | [diff] [blame] | 387 | 1L * 24L * 60L * 60L * 1000L /* 1 day */; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 388 | private static final long FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR = |
Paul Soulos | 40d7a65 | 2014-09-03 13:54:11 -0700 | [diff] [blame] | 389 | 7L * 24L * 60L * 60L * 1000L /* 7 days */; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 390 | |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 391 | /** Id for the background Call Log Loader */ |
| 392 | private static final int LOADER_CALL_LOG_ID = 3; |
| 393 | private static final int MAX_CALL_LOG_RETRIEVE = 3; |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 394 | private static final int MIN_NUM_CONTACT_ENTRIES_SHOWN = 3; |
| 395 | private static final int MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN = 3; |
| 396 | private static final int CARD_ENTRY_ID_EDIT_CONTACT = -2; |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 397 | private static final int CARD_ENTRY_ID_REQUEST_PERMISSION = -3; |
guanxiongliu | c7a4b9c | 2016-04-30 20:19:21 -0700 | [diff] [blame] | 398 | private static final String KEY_LOADER_EXTRA_PHONES = |
| 399 | QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_PHONES"; |
| 400 | private static final String KEY_LOADER_EXTRA_SIP_NUMBERS = |
| 401 | QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_SIP_NUMBERS"; |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 402 | |
| 403 | private static final int[] mRecentLoaderIds = new int[]{ |
| 404 | LOADER_SMS_ID, |
| 405 | LOADER_CALENDAR_ID, |
| 406 | LOADER_CALL_LOG_ID}; |
Jay Shrauner | 12ac1e6 | 2014-12-08 15:57:19 -0800 | [diff] [blame] | 407 | /** |
| 408 | * ConcurrentHashMap constructor params: 4 is initial table size, 0.9f is |
| 409 | * load factor before resizing, 1 means we only expect a single thread to |
| 410 | * write to the map so make only a single shard |
| 411 | */ |
| 412 | private Map<Integer, List<ContactInteraction>> mRecentLoaderResults = |
| 413 | new ConcurrentHashMap<>(4, 0.9f, 1); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 414 | |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 415 | private static final String FRAGMENT_TAG_SELECT_ACCOUNT = "select_account_fragment"; |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 416 | |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 417 | final OnClickListener mEntryClickHandler = new OnClickListener() { |
| 418 | @Override |
| 419 | public void onClick(View v) { |
Paul Soulos | 2ed2a73 | 2014-08-12 11:58:39 -0700 | [diff] [blame] | 420 | final Object entryTagObject = v.getTag(); |
| 421 | if (entryTagObject == null || !(entryTagObject instanceof EntryTag)) { |
| 422 | Log.w(TAG, "EntryTag was not used correctly"); |
| 423 | return; |
| 424 | } |
| 425 | final EntryTag entryTag = (EntryTag) entryTagObject; |
| 426 | final Intent intent = entryTag.getIntent(); |
| 427 | final int dataId = entryTag.getId(); |
| 428 | |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 429 | if (dataId == CARD_ENTRY_ID_EDIT_CONTACT) { |
| 430 | editContact(); |
| 431 | return; |
| 432 | } |
Paul Soulos | ea5e0b7 | 2014-07-08 18:09:44 -0700 | [diff] [blame] | 433 | |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 434 | if (dataId == CARD_ENTRY_ID_REQUEST_PERMISSION) { |
| 435 | finish(); |
| 436 | RequestDesiredPermissionsActivity.startPermissionActivity( |
| 437 | QuickContactActivity.this); |
| 438 | return; |
| 439 | } |
| 440 | |
LIANGTAO GAO | 19c83e3 | 2015-03-12 13:32:04 -0700 | [diff] [blame] | 441 | // Pass the touch point through the intent for use in the InCallUI |
| 442 | if (Intent.ACTION_CALL.equals(intent.getAction())) { |
| 443 | if (TouchPointManager.getInstance().hasValidPoint()) { |
| 444 | Bundle extras = new Bundle(); |
| 445 | extras.putParcelable(TouchPointManager.TOUCH_POINT, |
| 446 | TouchPointManager.getInstance().getPoint()); |
| 447 | intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 452 | |
| 453 | mHasIntentLaunched = true; |
| 454 | try { |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 455 | final int actionType = intent.getIntExtra(EXTRA_ACTION_TYPE, |
| 456 | ActionType.UNKNOWN_ACTION); |
| 457 | final String thirdPartyAction = intent.getStringExtra(EXTRA_THIRD_PARTY_ACTION); |
| 458 | Logger.logQuickContactEvent(mReferrer, mContactType, |
| 459 | CardType.UNKNOWN_CARD, actionType, thirdPartyAction); |
Tingting Wang | 8c434e5 | 2016-01-29 16:45:09 -0800 | [diff] [blame] | 460 | ImplicitIntentsUtil.startActivityInAppIfPossible(QuickContactActivity.this, intent); |
LIANGTAO GAO | 19c83e3 | 2015-03-12 13:32:04 -0700 | [diff] [blame] | 461 | } catch (SecurityException ex) { |
| 462 | Toast.makeText(QuickContactActivity.this, R.string.missing_app, |
| 463 | Toast.LENGTH_SHORT).show(); |
| 464 | Log.e(TAG, "QuickContacts does not have permission to launch " |
| 465 | + intent); |
| 466 | } catch (ActivityNotFoundException ex) { |
| 467 | Toast.makeText(QuickContactActivity.this, R.string.missing_app, |
| 468 | Toast.LENGTH_SHORT).show(); |
| 469 | } |
| 470 | |
Paul Soulos | ea5e0b7 | 2014-07-08 18:09:44 -0700 | [diff] [blame] | 471 | // Default to USAGE_TYPE_CALL. Usage is summed among all types for sorting each data id |
| 472 | // so the exact usage type is not necessary in all cases |
| 473 | String usageType = DataUsageFeedback.USAGE_TYPE_CALL; |
| 474 | |
Paul Soulos | 20bdf9d | 2014-07-28 14:31:54 -0700 | [diff] [blame] | 475 | final Uri intentUri = intent.getData(); |
| 476 | if ((intentUri != null && intentUri.getScheme() != null && |
Jay Shrauner | 1cd88e3 | 2014-09-05 15:37:55 -0700 | [diff] [blame] | 477 | intentUri.getScheme().equals(ContactsUtils.SCHEME_SMSTO)) || |
Paul Soulos | ea5e0b7 | 2014-07-08 18:09:44 -0700 | [diff] [blame] | 478 | (intent.getType() != null && intent.getType().equals(MIMETYPE_SMS))) { |
| 479 | usageType = DataUsageFeedback.USAGE_TYPE_SHORT_TEXT; |
| 480 | } |
| 481 | |
| 482 | // Data IDs start at 1 so anything less is invalid |
| 483 | if (dataId > 0) { |
Paul Soulos | 20bdf9d | 2014-07-28 14:31:54 -0700 | [diff] [blame] | 484 | final Uri dataUsageUri = DataUsageFeedback.FEEDBACK_URI.buildUpon() |
Paul Soulos | ea5e0b7 | 2014-07-08 18:09:44 -0700 | [diff] [blame] | 485 | .appendPath(String.valueOf(dataId)) |
| 486 | .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, usageType) |
| 487 | .build(); |
Jay Shrauner | 9881882 | 2015-07-10 12:54:10 -0700 | [diff] [blame] | 488 | try { |
| 489 | final boolean successful = getContentResolver().update( |
| 490 | dataUsageUri, new ContentValues(), null, null) > 0; |
| 491 | if (!successful) { |
| 492 | Log.w(TAG, "DataUsageFeedback increment failed"); |
| 493 | } |
| 494 | } catch (SecurityException ex) { |
| 495 | Log.w(TAG, "DataUsageFeedback increment failed", ex); |
Paul Soulos | ea5e0b7 | 2014-07-08 18:09:44 -0700 | [diff] [blame] | 496 | } |
| 497 | } else { |
| 498 | Log.w(TAG, "Invalid Data ID"); |
| 499 | } |
Paul Soulos | 2d48b5a | 2014-05-29 13:56:25 -0700 | [diff] [blame] | 500 | } |
| 501 | }; |
| 502 | |
Brian Attwell | e8ce6ee | 2014-06-27 18:26:32 -0700 | [diff] [blame] | 503 | final ExpandingEntryCardViewListener mExpandingEntryCardViewListener |
| 504 | = new ExpandingEntryCardViewListener() { |
| 505 | @Override |
| 506 | public void onCollapse(int heightDelta) { |
| 507 | mScroller.prepareForShrinkingScrollChild(heightDelta); |
| 508 | } |
Paul Soulos | 0cda9ae | 2014-07-23 11:27:28 -0700 | [diff] [blame] | 509 | |
| 510 | @Override |
Brian Attwell | 245d3d2 | 2015-01-21 09:50:08 -0800 | [diff] [blame] | 511 | public void onExpand() { |
| 512 | mScroller.setDisableTouchesForSuppressLayout(/* areTouchesDisabled = */ true); |
| 513 | } |
| 514 | |
| 515 | @Override |
| 516 | public void onExpandDone() { |
| 517 | mScroller.setDisableTouchesForSuppressLayout(/* areTouchesDisabled = */ false); |
Paul Soulos | 0cda9ae | 2014-07-23 11:27:28 -0700 | [diff] [blame] | 518 | } |
Brian Attwell | e8ce6ee | 2014-06-27 18:26:32 -0700 | [diff] [blame] | 519 | }; |
| 520 | |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 521 | @Override |
| 522 | public void onAggregationSuggestionChange() { |
Gary Mai | d1d8a7a | 2016-06-07 14:46:58 -0700 | [diff] [blame] | 523 | if (!mShouldShowSuggestions) { |
| 524 | return; |
| 525 | } |
Wenyi Wang | 1d86a67 | 2016-01-28 17:37:10 -0800 | [diff] [blame] | 526 | if (mAggregationSuggestionEngine == null) { |
| 527 | return; |
| 528 | } |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 529 | mSuggestions = mAggregationSuggestionEngine.getSuggestions(); |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 530 | mCollapsedSuggestionCardView.setVisibility(View.GONE); |
| 531 | mExpandSuggestionCardView.setVisibility(View.GONE); |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 532 | mSuggestionList.removeAllViews(); |
| 533 | |
Wenyi Wang | 96efbb8 | 2015-10-26 11:36:02 -0700 | [diff] [blame] | 534 | if (mContactData == null) { |
| 535 | return; |
| 536 | } |
| 537 | |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 538 | final String suggestionForName = mContactData.getDisplayName(); |
| 539 | final int suggestionNumber = mSuggestions.size(); |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 540 | |
Tingting Wang | e29b694 | 2015-09-30 15:21:33 -0700 | [diff] [blame] | 541 | if (suggestionNumber <= 0) { |
| 542 | mSelectedAggregationIds.clear(); |
| 543 | return; |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 544 | } |
Tingting Wang | e29b694 | 2015-09-30 15:21:33 -0700 | [diff] [blame] | 545 | |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 546 | ContactPhotoManager.DefaultImageRequest |
| 547 | request = new ContactPhotoManager.DefaultImageRequest( |
| 548 | suggestionForName, mContactData.getLookupKey(), ContactPhotoManager.TYPE_DEFAULT, |
| 549 | /* isCircular */ true ); |
| 550 | final long photoId = mContactData.getPhotoId(); |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 551 | final byte[] photoBytes = mContactData.getThumbnailPhotoBinaryData(); |
| 552 | if (photoBytes != null) { |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 553 | ContactPhotoManager.getInstance(this).loadThumbnail(mSuggestionSummaryPhoto, photoId, |
Wenyi Wang | 5cf746f | 2015-10-23 18:27:11 -0700 | [diff] [blame] | 554 | /* darkTheme */ false , /* isCircular */ true , request); |
Tingting Wang | e29b694 | 2015-09-30 15:21:33 -0700 | [diff] [blame] | 555 | } else { |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 556 | ContactPhotoManager.DEFAULT_AVATAR.applyDefaultImage(mSuggestionSummaryPhoto, |
| 557 | -1, false, request); |
Tingting Wang | e29b694 | 2015-09-30 15:21:33 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 560 | final String suggestionTitle = getResources().getQuantityString( |
| 561 | R.plurals.quickcontact_suggestion_card_title, suggestionNumber, suggestionNumber); |
| 562 | mCollapsedSuggestionCardTitle.setText(suggestionTitle); |
| 563 | mExpandSuggestionCardTitle.setText(suggestionTitle); |
| 564 | |
Tingting Wang | e29b694 | 2015-09-30 15:21:33 -0700 | [diff] [blame] | 565 | mSuggestionForName.setText(suggestionForName); |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 566 | final int linkedContactsNumber = mContactData.getRawContacts().size(); |
| 567 | final String contactsInfo; |
Wenyi Wang | 96efbb8 | 2015-10-26 11:36:02 -0700 | [diff] [blame] | 568 | final String accountName = mContactData.getRawContacts().get(0).getAccountName(); |
| 569 | if (linkedContactsNumber == 1 && accountName == null) { |
| 570 | mSuggestionContactsNumber.setVisibility(View.INVISIBLE); |
| 571 | } |
| 572 | if (linkedContactsNumber == 1 && accountName != null) { |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 573 | contactsInfo = getResources().getString(R.string.contact_from_account_name, |
Wenyi Wang | 96efbb8 | 2015-10-26 11:36:02 -0700 | [diff] [blame] | 574 | accountName); |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 575 | } else { |
| 576 | contactsInfo = getResources().getString( |
| 577 | R.string.quickcontact_contacts_number, linkedContactsNumber); |
| 578 | } |
| 579 | mSuggestionContactsNumber.setText(contactsInfo); |
Tingting Wang | e29b694 | 2015-09-30 15:21:33 -0700 | [diff] [blame] | 580 | |
| 581 | final Set<Long> suggestionContactIds = new HashSet<>(); |
| 582 | for (Suggestion suggestion : mSuggestions) { |
| 583 | mSuggestionList.addView(inflateSuggestionListView(suggestion)); |
| 584 | suggestionContactIds.add(suggestion.contactId); |
| 585 | } |
| 586 | |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 587 | if (mIsSuggestionListCollapsed) { |
| 588 | collapseSuggestionList(); |
| 589 | } else { |
| 590 | expandSuggestionList(); |
| 591 | } |
| 592 | |
Tingting Wang | e29b694 | 2015-09-30 15:21:33 -0700 | [diff] [blame] | 593 | // Remove contact Ids that are not suggestions. |
| 594 | final Set<Long> selectedSuggestionIds = com.google.common.collect.Sets.intersection( |
| 595 | mSelectedAggregationIds, suggestionContactIds); |
| 596 | mSelectedAggregationIds = new TreeSet<>(selectedSuggestionIds); |
Wenyi Wang | 96efbb8 | 2015-10-26 11:36:02 -0700 | [diff] [blame] | 597 | if (!mSelectedAggregationIds.isEmpty()) { |
| 598 | enableLinkButton(); |
| 599 | } |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | private void collapseSuggestionList() { |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 603 | mCollapsedSuggestionCardView.setVisibility(View.VISIBLE); |
| 604 | mExpandSuggestionCardView.setVisibility(View.GONE); |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 605 | mIsSuggestionListCollapsed = true; |
| 606 | } |
| 607 | |
| 608 | private void expandSuggestionList() { |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 609 | mCollapsedSuggestionCardView.setVisibility(View.GONE); |
| 610 | mExpandSuggestionCardView.setVisibility(View.VISIBLE); |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 611 | mIsSuggestionListCollapsed = false; |
| 612 | } |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 613 | |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 614 | private View inflateSuggestionListView(final Suggestion suggestion) { |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 615 | final LayoutInflater layoutInflater = LayoutInflater.from(this); |
| 616 | final View suggestionView = layoutInflater.inflate( |
| 617 | R.layout.quickcontact_suggestion_contact_item, null); |
| 618 | |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 619 | ContactPhotoManager.DefaultImageRequest |
| 620 | request = new ContactPhotoManager.DefaultImageRequest( |
| 621 | suggestion.name, suggestion.lookupKey, ContactPhotoManager.TYPE_DEFAULT, /* |
| 622 | isCircular */ true); |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 623 | final ImageView photo = (ImageView) suggestionView.findViewById( |
| 624 | R.id.aggregation_suggestion_photo); |
| 625 | if (suggestion.photo != null) { |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 626 | ContactPhotoManager.getInstance(this).loadThumbnail(photo, suggestion.photoId, |
Wenyi Wang | 5cf746f | 2015-10-23 18:27:11 -0700 | [diff] [blame] | 627 | /* darkTheme */ false, /* isCircular */ true, request); |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 628 | } else { |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 629 | ContactPhotoManager.DEFAULT_AVATAR.applyDefaultImage(photo, -1, false, request); |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | final TextView name = (TextView) suggestionView.findViewById(R.id.aggregation_suggestion_name); |
| 633 | name.setText(suggestion.name); |
| 634 | |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 635 | final TextView accountNameView = (TextView) suggestionView.findViewById( |
| 636 | R.id.aggregation_suggestion_account_name); |
| 637 | final String accountName = suggestion.rawContacts.get(0).accountName; |
| 638 | if (!TextUtils.isEmpty(accountName)) { |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 639 | accountNameView.setText( |
| 640 | getResources().getString(R.string.contact_from_account_name, accountName)); |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 641 | } else { |
Wenyi Wang | 96efbb8 | 2015-10-26 11:36:02 -0700 | [diff] [blame] | 642 | accountNameView.setVisibility(View.INVISIBLE); |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | final CheckBox checkbox = (CheckBox) suggestionView.findViewById(R.id.suggestion_checkbox); |
Wenyi Wang | 8d02b16 | 2016-01-10 12:43:36 -0800 | [diff] [blame] | 646 | final int[][] stateSet = new int[][] { |
| 647 | new int[] { android.R.attr.state_checked }, |
| 648 | new int[] { -android.R.attr.state_checked } |
| 649 | }; |
| 650 | final int[] colors = new int[] { mColorFilterColor, mColorFilterColor }; |
guanxiongliu | 051315f | 2016-02-22 15:51:00 -0800 | [diff] [blame] | 651 | if (suggestion != null && suggestion.name != null) { |
| 652 | checkbox.setContentDescription(suggestion.name + " " + |
| 653 | getResources().getString(R.string.contact_from_account_name, accountName)); |
| 654 | } |
Wenyi Wang | 8d02b16 | 2016-01-10 12:43:36 -0800 | [diff] [blame] | 655 | checkbox.setButtonTintList(new ColorStateList(stateSet, colors)); |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 656 | checkbox.setChecked(mSuggestionsShouldAutoSelected || |
| 657 | mSelectedAggregationIds.contains(suggestion.contactId)); |
| 658 | if (checkbox.isChecked()) { |
| 659 | mSelectedAggregationIds.add(suggestion.contactId); |
| 660 | } |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 661 | checkbox.setTag(suggestion.contactId); |
| 662 | checkbox.setOnClickListener(new OnClickListener() { |
| 663 | @Override |
| 664 | public void onClick(View v) { |
| 665 | final CheckBox checkBox = (CheckBox) v; |
| 666 | final Long contactId = (Long) checkBox.getTag(); |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 667 | if (mSelectedAggregationIds.contains(mContactData.getId())) { |
| 668 | mSelectedAggregationIds.remove(mContactData.getId()); |
| 669 | } |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 670 | if (checkBox.isChecked()) { |
| 671 | mSelectedAggregationIds.add(contactId); |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 672 | if (mSelectedAggregationIds.size() >= 1) { |
| 673 | enableLinkButton(); |
| 674 | } |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 675 | } else { |
| 676 | mSelectedAggregationIds.remove(contactId); |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 677 | mSuggestionsShouldAutoSelected = false; |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 678 | if (mSelectedAggregationIds.isEmpty()) { |
| 679 | disableLinkButton(); |
| 680 | } |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | }); |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 684 | |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 685 | return suggestionView; |
| 686 | } |
| 687 | |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 688 | private void enableLinkButton() { |
| 689 | mSuggestionsLinkButton.setClickable(true); |
Wenyi Wang | 8d02b16 | 2016-01-10 12:43:36 -0800 | [diff] [blame] | 690 | mSuggestionsLinkButton.getBackground().setColorFilter(mColorFilter); |
Wenyi Wang | 56dfa58 | 2015-11-17 17:42:44 -0800 | [diff] [blame] | 691 | mSuggestionsLinkButton.setTextColor( |
Wenyi Wang | 23d9b6e | 2015-11-19 15:09:06 -0800 | [diff] [blame] | 692 | ContextCompat.getColor(this, android.R.color.white)); |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 693 | mSuggestionsLinkButton.setOnClickListener(new OnClickListener() { |
| 694 | @Override |
| 695 | public void onClick(View view) { |
| 696 | // Join selected contacts. |
| 697 | if (!mSelectedAggregationIds.contains(mContactData.getId())) { |
| 698 | mSelectedAggregationIds.add(mContactData.getId()); |
| 699 | } |
Cody Thomas | f32dc99 | 2016-05-11 10:56:04 -0700 | [diff] [blame] | 700 | |
| 701 | final Long[] contactIdsArray = mSelectedAggregationIds.toArray( |
| 702 | new Long[mSelectedAggregationIds.size()]); |
| 703 | final long[] contactIdsArray2 = new long[contactIdsArray.length]; |
| 704 | for (int i = 0; i < contactIdsArray.length; i++) { |
| 705 | contactIdsArray2[i] = contactIdsArray[i]; |
| 706 | } |
| 707 | |
| 708 | final Intent intent = ContactSaveService.createJoinSeveralContactsIntent( |
| 709 | QuickContactActivity.this, contactIdsArray2); |
| 710 | QuickContactActivity.this.startService(intent); |
| 711 | |
| 712 | disableLinkButton(); |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 713 | } |
| 714 | }); |
| 715 | } |
| 716 | |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 717 | private void disableLinkButton() { |
| 718 | mSuggestionsLinkButton.setClickable(false); |
| 719 | mSuggestionsLinkButton.getBackground().setColorFilter( |
Wenyi Wang | 23d9b6e | 2015-11-19 15:09:06 -0800 | [diff] [blame] | 720 | ContextCompat.getColor(this, R.color.disabled_button_background), |
Wenyi Wang | 33f60d3 | 2015-10-24 14:44:06 -0700 | [diff] [blame] | 721 | PorterDuff.Mode.SRC_ATOP); |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 722 | mSuggestionsLinkButton.setTextColor( |
Wenyi Wang | 23d9b6e | 2015-11-19 15:09:06 -0800 | [diff] [blame] | 723 | ContextCompat.getColor(this, R.color.disabled_button_text)); |
Wenyi Wang | 5368489 | 2015-10-23 11:11:16 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 726 | private interface ContextMenuIds { |
| 727 | static final int COPY_TEXT = 0; |
| 728 | static final int CLEAR_DEFAULT = 1; |
| 729 | static final int SET_DEFAULT = 2; |
| 730 | } |
| 731 | |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 732 | private final OnCreateContextMenuListener mEntryContextMenuListener = |
| 733 | new OnCreateContextMenuListener() { |
| 734 | @Override |
| 735 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { |
| 736 | if (menuInfo == null) { |
| 737 | return; |
| 738 | } |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 739 | final EntryContextMenuInfo info = (EntryContextMenuInfo) menuInfo; |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 740 | menu.setHeaderTitle(info.getCopyText()); |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 741 | menu.add(ContextMenu.NONE, ContextMenuIds.COPY_TEXT, |
| 742 | ContextMenu.NONE, getString(R.string.copy_text)); |
| 743 | |
| 744 | // Don't allow setting or clearing of defaults for non-editable contacts |
| 745 | if (!isContactEditable()) { |
| 746 | return; |
| 747 | } |
| 748 | |
| 749 | final String selectedMimeType = info.getMimeType(); |
| 750 | |
| 751 | // Defaults to true will only enable the detail to be copied to the clipboard. |
| 752 | boolean onlyOneOfMimeType = true; |
| 753 | |
| 754 | // Only allow primary support for Phone and Email content types |
| 755 | if (Phone.CONTENT_ITEM_TYPE.equals(selectedMimeType)) { |
| 756 | onlyOneOfMimeType = mOnlyOnePhoneNumber; |
| 757 | } else if (Email.CONTENT_ITEM_TYPE.equals(selectedMimeType)) { |
| 758 | onlyOneOfMimeType = mOnlyOneEmail; |
| 759 | } |
| 760 | |
| 761 | // Checking for previously set default |
| 762 | if (info.isSuperPrimary()) { |
| 763 | menu.add(ContextMenu.NONE, ContextMenuIds.CLEAR_DEFAULT, |
| 764 | ContextMenu.NONE, getString(R.string.clear_default)); |
| 765 | } else if (!onlyOneOfMimeType) { |
| 766 | menu.add(ContextMenu.NONE, ContextMenuIds.SET_DEFAULT, |
| 767 | ContextMenu.NONE, getString(R.string.set_default)); |
| 768 | } |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 769 | } |
| 770 | }; |
| 771 | |
| 772 | @Override |
| 773 | public boolean onContextItemSelected(MenuItem item) { |
| 774 | EntryContextMenuInfo menuInfo; |
| 775 | try { |
| 776 | menuInfo = (EntryContextMenuInfo) item.getMenuInfo(); |
| 777 | } catch (ClassCastException e) { |
| 778 | Log.e(TAG, "bad menuInfo", e); |
| 779 | return false; |
| 780 | } |
| 781 | |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 782 | switch (item.getItemId()) { |
| 783 | case ContextMenuIds.COPY_TEXT: |
| 784 | ClipboardUtils.copyText(this, menuInfo.getCopyLabel(), menuInfo.getCopyText(), |
| 785 | true); |
| 786 | return true; |
| 787 | case ContextMenuIds.SET_DEFAULT: |
| 788 | final Intent setIntent = ContactSaveService.createSetSuperPrimaryIntent(this, |
| 789 | menuInfo.getId()); |
| 790 | this.startService(setIntent); |
| 791 | return true; |
| 792 | case ContextMenuIds.CLEAR_DEFAULT: |
| 793 | final Intent clearIntent = ContactSaveService.createClearPrimaryIntent(this, |
| 794 | menuInfo.getId()); |
| 795 | this.startService(clearIntent); |
| 796 | return true; |
| 797 | default: |
| 798 | throw new IllegalArgumentException("Unknown menu option " + item.getItemId()); |
| 799 | } |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 800 | } |
| 801 | |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 802 | /** |
| 803 | * Headless fragment used to handle account selection callbacks invoked from |
| 804 | * {@link DirectoryContactUtil}. |
| 805 | */ |
| 806 | public static class SelectAccountDialogFragmentListener extends Fragment |
| 807 | implements SelectAccountDialogFragment.Listener { |
| 808 | |
| 809 | private QuickContactActivity mQuickContactActivity; |
| 810 | |
| 811 | public SelectAccountDialogFragmentListener() {} |
| 812 | |
| 813 | @Override |
| 814 | public void onAccountChosen(AccountWithDataSet account, Bundle extraArgs) { |
| 815 | DirectoryContactUtil.createCopy(mQuickContactActivity.mContactData.getContentValues(), |
| 816 | account, mQuickContactActivity); |
| 817 | } |
| 818 | |
| 819 | @Override |
| 820 | public void onAccountSelectorCancelled() {} |
| 821 | |
| 822 | /** |
| 823 | * Set the parent activity. Since rotation can cause this fragment to be used across |
| 824 | * more than one activity instance, we need to explicitly set this value instead |
| 825 | * of making this class non-static. |
| 826 | */ |
| 827 | public void setQuickContactActivity(QuickContactActivity quickContactActivity) { |
| 828 | mQuickContactActivity = quickContactActivity; |
| 829 | } |
| 830 | } |
| 831 | |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 832 | final MultiShrinkScrollerListener mMultiShrinkScrollerListener |
| 833 | = new MultiShrinkScrollerListener() { |
| 834 | @Override |
| 835 | public void onScrolledOffBottom() { |
Brian Attwell | f1076dc | 2014-08-12 21:28:21 -0700 | [diff] [blame] | 836 | finish(); |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 837 | } |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 838 | |
| 839 | @Override |
| 840 | public void onEnterFullscreen() { |
| 841 | updateStatusBarColor(); |
| 842 | } |
| 843 | |
| 844 | @Override |
| 845 | public void onExitFullscreen() { |
| 846 | updateStatusBarColor(); |
| 847 | } |
Brian Attwell | 8477eaf | 2014-06-18 15:39:50 -0700 | [diff] [blame] | 848 | |
| 849 | @Override |
| 850 | public void onStartScrollOffBottom() { |
Brian Attwell | 8477eaf | 2014-06-18 15:39:50 -0700 | [diff] [blame] | 851 | mIsExitAnimationInProgress = true; |
| 852 | } |
Brian Attwell | 8477eaf | 2014-06-18 15:39:50 -0700 | [diff] [blame] | 853 | |
Brian Attwell | 8477eaf | 2014-06-18 15:39:50 -0700 | [diff] [blame] | 854 | @Override |
Brian Attwell | f1076dc | 2014-08-12 21:28:21 -0700 | [diff] [blame] | 855 | public void onEntranceAnimationDone() { |
| 856 | mIsEntranceAnimationFinished = true; |
| 857 | } |
| 858 | |
| 859 | @Override |
| 860 | public void onTransparentViewHeightChange(float ratio) { |
| 861 | if (mIsEntranceAnimationFinished) { |
| 862 | mWindowScrim.setAlpha((int) (0xFF * ratio)); |
Brian Attwell | 8477eaf | 2014-06-18 15:39:50 -0700 | [diff] [blame] | 863 | } |
Brian Attwell | 8477eaf | 2014-06-18 15:39:50 -0700 | [diff] [blame] | 864 | } |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 865 | }; |
| 866 | |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 867 | |
| 868 | /** |
| 869 | * Data items are compared to the same mimetype based off of three qualities: |
| 870 | * 1. Super primary |
| 871 | * 2. Primary |
| 872 | * 3. Times used |
| 873 | */ |
| 874 | private final Comparator<DataItem> mWithinMimeTypeDataItemComparator = |
| 875 | new Comparator<DataItem>() { |
| 876 | @Override |
| 877 | public int compare(DataItem lhs, DataItem rhs) { |
| 878 | if (!lhs.getMimeType().equals(rhs.getMimeType())) { |
| 879 | Log.wtf(TAG, "Comparing DataItems with different mimetypes lhs.getMimeType(): " + |
| 880 | lhs.getMimeType() + " rhs.getMimeType(): " + rhs.getMimeType()); |
| 881 | return 0; |
| 882 | } |
| 883 | |
| 884 | if (lhs.isSuperPrimary()) { |
| 885 | return -1; |
| 886 | } else if (rhs.isSuperPrimary()) { |
| 887 | return 1; |
| 888 | } else if (lhs.isPrimary() && !rhs.isPrimary()) { |
| 889 | return -1; |
| 890 | } else if (!lhs.isPrimary() && rhs.isPrimary()) { |
| 891 | return 1; |
| 892 | } else { |
| 893 | final int lhsTimesUsed = |
| 894 | lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); |
| 895 | final int rhsTimesUsed = |
| 896 | rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); |
| 897 | |
| 898 | return rhsTimesUsed - lhsTimesUsed; |
| 899 | } |
| 900 | } |
| 901 | }; |
| 902 | |
Paul Soulos | cb4fcc7 | 2014-07-15 14:08:50 -0700 | [diff] [blame] | 903 | /** |
| 904 | * Sorts among different mimetypes based off: |
Brian Attwell | 05287bf | 2015-02-25 22:24:04 -0800 | [diff] [blame] | 905 | * 1. Whether one of the mimetypes is the prioritized mimetype |
| 906 | * 2. Number of times used |
| 907 | * 3. Last time used |
| 908 | * 4. Statically defined |
Paul Soulos | cb4fcc7 | 2014-07-15 14:08:50 -0700 | [diff] [blame] | 909 | */ |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 910 | private final Comparator<List<DataItem>> mAmongstMimeTypeDataItemComparator = |
| 911 | new Comparator<List<DataItem>> () { |
| 912 | @Override |
| 913 | public int compare(List<DataItem> lhsList, List<DataItem> rhsList) { |
Brian Attwell | 05287bf | 2015-02-25 22:24:04 -0800 | [diff] [blame] | 914 | final DataItem lhs = lhsList.get(0); |
| 915 | final DataItem rhs = rhsList.get(0); |
| 916 | final String lhsMimeType = lhs.getMimeType(); |
| 917 | final String rhsMimeType = rhs.getMimeType(); |
| 918 | |
| 919 | // 1. Whether one of the mimetypes is the prioritized mimetype |
| 920 | if (!TextUtils.isEmpty(mExtraPrioritizedMimeType) && !lhsMimeType.equals(rhsMimeType)) { |
| 921 | if (rhsMimeType.equals(mExtraPrioritizedMimeType)) { |
| 922 | return 1; |
| 923 | } |
| 924 | if (lhsMimeType.equals(mExtraPrioritizedMimeType)) { |
| 925 | return -1; |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | // 2. Number of times used |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 930 | final int lhsTimesUsed = lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed(); |
| 931 | final int rhsTimesUsed = rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed(); |
| 932 | final int timesUsedDifference = rhsTimesUsed - lhsTimesUsed; |
| 933 | if (timesUsedDifference != 0) { |
| 934 | return timesUsedDifference; |
| 935 | } |
| 936 | |
Brian Attwell | 05287bf | 2015-02-25 22:24:04 -0800 | [diff] [blame] | 937 | // 3. Last time used |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 938 | final long lhsLastTimeUsed = |
| 939 | lhs.getLastTimeUsed() == null ? 0 : lhs.getLastTimeUsed(); |
| 940 | final long rhsLastTimeUsed = |
| 941 | rhs.getLastTimeUsed() == null ? 0 : rhs.getLastTimeUsed(); |
| 942 | final long lastTimeUsedDifference = rhsLastTimeUsed - lhsLastTimeUsed; |
| 943 | if (lastTimeUsedDifference > 0) { |
| 944 | return 1; |
| 945 | } else if (lastTimeUsedDifference < 0) { |
| 946 | return -1; |
| 947 | } |
| 948 | |
Brian Attwell | 05287bf | 2015-02-25 22:24:04 -0800 | [diff] [blame] | 949 | // 4. Resort to a statically defined mimetype order. |
| 950 | if (!lhsMimeType.equals(rhsMimeType)) { |
| 951 | for (String mimeType : LEADING_MIMETYPES) { |
| 952 | if (lhsMimeType.equals(mimeType)) { |
| 953 | return -1; |
| 954 | } else if (rhsMimeType.equals(mimeType)) { |
| 955 | return 1; |
| 956 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 957 | } |
| 958 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 959 | return 0; |
| 960 | } |
| 961 | }; |
| 962 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 963 | @Override |
Nancy Chen | f619e43 | 2014-08-18 20:15:12 -0700 | [diff] [blame] | 964 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 965 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 966 | TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); |
| 967 | } |
| 968 | return super.dispatchTouchEvent(ev); |
| 969 | } |
| 970 | |
| 971 | @Override |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 972 | protected void onCreate(Bundle savedInstanceState) { |
| 973 | Trace.beginSection("onCreate()"); |
| 974 | super.onCreate(savedInstanceState); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 975 | |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 976 | if (RequestPermissionsActivity.startPermissionActivity(this)) { |
Brian Attwell | bdd3264 | 2015-05-08 17:03:15 -0700 | [diff] [blame] | 977 | return; |
| 978 | } |
| 979 | |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 980 | mIsRecreatedInstance = (savedInstanceState != null); |
| 981 | mShouldLog = true; |
| 982 | |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 983 | // There're 3 states for each permission: |
| 984 | // 1. App doesn't have permission, not asked user yet. |
| 985 | // 2. App doesn't have permission, user denied it previously. |
| 986 | // 3. App has permission. |
| 987 | // Permission explanation card is displayed only for case 1. |
Walter Jang | 5a16ef8 | 2016-07-27 09:20:59 -0700 | [diff] [blame] | 988 | final boolean hasTelephonyFeature = |
| 989 | getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY); |
| 990 | |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 991 | final boolean hasCalendarPermission = PermissionsUtil.hasPermission( |
Walter Jang | 0e723d9 | 2016-07-07 19:00:30 -0700 | [diff] [blame] | 992 | this, Manifest.permission.READ_CALENDAR); |
Walter Jang | 5a16ef8 | 2016-07-27 09:20:59 -0700 | [diff] [blame] | 993 | final boolean hasSMSPermission = hasTelephonyFeature |
| 994 | && PermissionsUtil.hasPermission(this, Manifest.permission.READ_SMS); |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 995 | |
| 996 | final boolean wasCalendarPermissionDenied = |
| 997 | ActivityCompat.shouldShowRequestPermissionRationale( |
Walter Jang | 0e723d9 | 2016-07-07 19:00:30 -0700 | [diff] [blame] | 998 | this, Manifest.permission.READ_CALENDAR); |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 999 | final boolean wasSMSPermissionDenied = |
Walter Jang | 5a16ef8 | 2016-07-27 09:20:59 -0700 | [diff] [blame] | 1000 | hasTelephonyFeature && ActivityCompat.shouldShowRequestPermissionRationale( |
Walter Jang | 0e723d9 | 2016-07-07 19:00:30 -0700 | [diff] [blame] | 1001 | this, Manifest.permission.READ_SMS); |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 1002 | |
| 1003 | final boolean shouldDisplayCalendarMessage = |
| 1004 | !hasCalendarPermission && !wasCalendarPermissionDenied; |
Walter Jang | 5a16ef8 | 2016-07-27 09:20:59 -0700 | [diff] [blame] | 1005 | final boolean shouldDisplaySMSMessage = |
| 1006 | hasTelephonyFeature && !hasSMSPermission && !wasSMSPermissionDenied; |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 1007 | mShouldShowPermissionExplanation = shouldDisplayCalendarMessage || shouldDisplaySMSMessage; |
| 1008 | |
| 1009 | if (shouldDisplayCalendarMessage && shouldDisplaySMSMessage) { |
| 1010 | mPermissionExplanationCardSubHeader = |
| 1011 | getString(R.string.permission_explanation_subheader_calendar_and_SMS); |
| 1012 | } else if (shouldDisplayCalendarMessage) { |
| 1013 | mPermissionExplanationCardSubHeader = |
| 1014 | getString(R.string.permission_explanation_subheader_calendar); |
| 1015 | } else if (shouldDisplaySMSMessage) { |
| 1016 | mPermissionExplanationCardSubHeader = |
| 1017 | getString(R.string.permission_explanation_subheader_SMS); |
| 1018 | } |
| 1019 | |
Walter Jang | 1bb6c29 | 2016-02-29 11:46:03 -0800 | [diff] [blame] | 1020 | final int previousScreenType = getIntent().getIntExtra |
| 1021 | (EXTRA_PREVIOUS_SCREEN_TYPE, ScreenType.UNKNOWN); |
Walter Jang | 62a2074 | 2016-02-24 17:04:12 -0800 | [diff] [blame] | 1022 | Logger.logScreenView(this, ScreenType.QUICK_CONTACT, previousScreenType); |
| 1023 | |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 1024 | mReferrer = getCallingPackage(); |
| 1025 | if (mReferrer == null && CompatUtils.isLollipopMr1Compatible() && getReferrer() != null) { |
| 1026 | mReferrer = getReferrer().getAuthority(); |
| 1027 | } |
| 1028 | mContactType = ContactType.UNKNOWN_TYPE; |
| 1029 | |
Wenyi Wang | 4c3d3e2 | 2015-12-17 14:30:02 -0800 | [diff] [blame] | 1030 | if (CompatUtils.isLollipopCompatible()) { |
| 1031 | getWindow().setStatusBarColor(Color.TRANSPARENT); |
| 1032 | } |
Daniel Lehmann | 2426cb0 | 2012-05-10 18:41:21 -0700 | [diff] [blame] | 1033 | |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1034 | processIntent(getIntent()); |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 1035 | |
Daisuke Miyakawa | 10d7df7 | 2011-07-29 16:11:05 -0700 | [diff] [blame] | 1036 | // Show QuickContact in front of soft input |
| 1037 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
| 1038 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
| 1039 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 1040 | setContentView(R.layout.quickcontact_activity); |
| 1041 | |
Brian Attwell | a3859ed | 2014-07-15 13:51:55 -0700 | [diff] [blame] | 1042 | mMaterialColorMapUtils = new MaterialColorMapUtils(getResources()); |
| 1043 | |
Paul Soulos | 0cda9ae | 2014-07-23 11:27:28 -0700 | [diff] [blame] | 1044 | mScroller = (MultiShrinkScroller) findViewById(R.id.multiscroller); |
| 1045 | |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1046 | mContactCard = (ExpandingEntryCardView) findViewById(R.id.communication_card); |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 1047 | mNoContactDetailsCard = (ExpandingEntryCardView) findViewById(R.id.no_contact_data_card); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 1048 | mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1049 | mAboutCard = (ExpandingEntryCardView) findViewById(R.id.about_card); |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 1050 | mPermissionExplanationCard = |
| 1051 | (ExpandingEntryCardView) findViewById(R.id.permission_explanation_card); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 1052 | |
Gary Mai | d1d8a7a | 2016-06-07 14:46:58 -0700 | [diff] [blame] | 1053 | if (mShouldShowSuggestions) { |
| 1054 | mCollapsedSuggestionCardView = (CardView) findViewById(R.id.collapsed_suggestion_card); |
| 1055 | mExpandSuggestionCardView = (CardView) findViewById(R.id.expand_suggestion_card); |
| 1056 | mCollapsedSuggestionHeader = findViewById(R.id.collapsed_suggestion_header); |
| 1057 | mCollapsedSuggestionCardTitle = (TextView) findViewById( |
| 1058 | R.id.collapsed_suggestion_card_title); |
| 1059 | mExpandSuggestionCardTitle = (TextView) findViewById(R.id.expand_suggestion_card_title); |
| 1060 | mSuggestionSummaryPhoto = (ImageView) findViewById(R.id.suggestion_icon); |
| 1061 | mSuggestionForName = (TextView) findViewById(R.id.suggestion_for_name); |
| 1062 | mSuggestionContactsNumber = (TextView) findViewById( |
| 1063 | R.id.suggestion_for_contacts_number); |
| 1064 | mSuggestionList = (LinearLayout) findViewById(R.id.suggestion_list); |
| 1065 | mSuggestionsCancelButton = (Button) findViewById(R.id.cancel_button); |
| 1066 | mSuggestionsLinkButton = (Button) findViewById(R.id.link_button); |
| 1067 | if (savedInstanceState != null) { |
| 1068 | mIsSuggestionListCollapsed = savedInstanceState.getBoolean( |
| 1069 | KEY_IS_SUGGESTION_LIST_COLLAPSED, true); |
| 1070 | mPreviousContactId = savedInstanceState.getLong(KEY_PREVIOUS_CONTACT_ID); |
| 1071 | mSuggestionsShouldAutoSelected = savedInstanceState.getBoolean( |
| 1072 | KEY_SUGGESTIONS_AUTO_SELECTED, true); |
| 1073 | mSelectedAggregationIds = (TreeSet<Long>) |
| 1074 | savedInstanceState.getSerializable(KEY_SELECTED_SUGGESTION_CONTACTS); |
| 1075 | } else { |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 1076 | mIsSuggestionListCollapsed = true; |
Gary Mai | d1d8a7a | 2016-06-07 14:46:58 -0700 | [diff] [blame] | 1077 | mSelectedAggregationIds.clear(); |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 1078 | } |
Gary Mai | d1d8a7a | 2016-06-07 14:46:58 -0700 | [diff] [blame] | 1079 | if (mSelectedAggregationIds.isEmpty()) { |
| 1080 | disableLinkButton(); |
| 1081 | } else { |
| 1082 | enableLinkButton(); |
| 1083 | } |
| 1084 | mCollapsedSuggestionHeader.setOnClickListener(new OnClickListener() { |
| 1085 | @Override |
| 1086 | public void onClick(View view) { |
| 1087 | mCollapsedSuggestionCardView.setVisibility(View.GONE); |
| 1088 | mExpandSuggestionCardView.setVisibility(View.VISIBLE); |
| 1089 | mIsSuggestionListCollapsed = false; |
| 1090 | mExpandSuggestionCardTitle.requestFocus(); |
| 1091 | mExpandSuggestionCardTitle.sendAccessibilityEvent( |
| 1092 | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 1093 | } |
| 1094 | }); |
| 1095 | |
| 1096 | mSuggestionsCancelButton.setOnClickListener(new OnClickListener() { |
| 1097 | @Override |
| 1098 | public void onClick(View view) { |
| 1099 | mCollapsedSuggestionCardView.setVisibility(View.VISIBLE); |
| 1100 | mExpandSuggestionCardView.setVisibility(View.GONE); |
| 1101 | mIsSuggestionListCollapsed = true; |
| 1102 | } |
| 1103 | }); |
| 1104 | } |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 1105 | |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 1106 | mPermissionExplanationCard.setOnClickListener(mEntryClickHandler); |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 1107 | mNoContactDetailsCard.setOnClickListener(mEntryClickHandler); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1108 | mContactCard.setOnClickListener(mEntryClickHandler); |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 1109 | mContactCard.setOnCreateContextMenuListener(mEntryContextMenuListener); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 1110 | |
| 1111 | mRecentCard.setOnClickListener(mEntryClickHandler); |
| 1112 | mRecentCard.setTitle(getResources().getString(R.string.recent_card_title)); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 1113 | |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1114 | mAboutCard.setOnClickListener(mEntryClickHandler); |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 1115 | mAboutCard.setOnCreateContextMenuListener(mEntryContextMenuListener); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1116 | |
Brian Attwell | 02eaf11 | 2014-08-27 21:03:42 -0700 | [diff] [blame] | 1117 | mPhotoView = (QuickContactImageView) findViewById(R.id.photo); |
Brian Attwell | 63176c9 | 2014-08-18 15:14:18 -0700 | [diff] [blame] | 1118 | final View transparentView = findViewById(R.id.transparent_view); |
Brian Attwell | 0d90afe | 2014-06-18 16:45:41 -0700 | [diff] [blame] | 1119 | if (mScroller != null) { |
Brian Attwell | 63176c9 | 2014-08-18 15:14:18 -0700 | [diff] [blame] | 1120 | transparentView.setOnClickListener(new OnClickListener() { |
Brian Attwell | 0d90afe | 2014-06-18 16:45:41 -0700 | [diff] [blame] | 1121 | @Override |
| 1122 | public void onClick(View v) { |
| 1123 | mScroller.scrollOffBottom(); |
| 1124 | } |
| 1125 | }); |
| 1126 | } |
Yorke Lee | 6219668 | 2013-09-06 18:34:17 -0700 | [diff] [blame] | 1127 | |
Brian Attwell | d41ab8a | 2014-08-07 11:08:55 -0700 | [diff] [blame] | 1128 | // Allow a shadow to be shown under the toolbar. |
| 1129 | ViewUtil.addRectangularOutlineProvider(findViewById(R.id.toolbar_parent), getResources()); |
| 1130 | |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1131 | final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
| 1132 | setActionBar(toolbar); |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1133 | getActionBar().setTitle(null); |
| 1134 | // Put a TextView with a known resource id into the ActionBar. This allows us to easily |
| 1135 | // find the correct TextView location & size later. |
| 1136 | toolbar.addView(getLayoutInflater().inflate(R.layout.quickcontact_title_placeholder, null)); |
Yorke Lee | 6219668 | 2013-09-06 18:34:17 -0700 | [diff] [blame] | 1137 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1138 | mHasAlreadyBeenOpened = savedInstanceState != null; |
Brian Attwell | f1076dc | 2014-08-12 21:28:21 -0700 | [diff] [blame] | 1139 | mIsEntranceAnimationFinished = mHasAlreadyBeenOpened; |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1140 | mWindowScrim = new ColorDrawable(SCRIM_COLOR); |
Brian Attwell | f1076dc | 2014-08-12 21:28:21 -0700 | [diff] [blame] | 1141 | mWindowScrim.setAlpha(0); |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1142 | getWindow().setBackgroundDrawable(mWindowScrim); |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 1143 | |
Wenyi Wang | caf2619 | 2016-05-09 15:00:25 -0700 | [diff] [blame] | 1144 | mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED, |
| 1145 | /* maximumHeaderTextSize */ -1, |
| 1146 | /* shouldUpdateNameViewHeight */ true); |
Brian Attwell | ac3ed8e | 2014-06-27 17:24:42 -0700 | [diff] [blame] | 1147 | // mScroller needs to perform asynchronous measurements after initalize(), therefore |
| 1148 | // we can't mark this as GONE. |
| 1149 | mScroller.setVisibility(View.INVISIBLE); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1150 | |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1151 | setHeaderNameText(R.string.missing_name); |
| 1152 | |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1153 | mSelectAccountFragmentListener= (SelectAccountDialogFragmentListener) getFragmentManager() |
| 1154 | .findFragmentByTag(FRAGMENT_TAG_SELECT_ACCOUNT); |
| 1155 | if (mSelectAccountFragmentListener == null) { |
| 1156 | mSelectAccountFragmentListener = new SelectAccountDialogFragmentListener(); |
| 1157 | getFragmentManager().beginTransaction().add(0, mSelectAccountFragmentListener, |
| 1158 | FRAGMENT_TAG_SELECT_ACCOUNT).commit(); |
| 1159 | mSelectAccountFragmentListener.setRetainInstance(true); |
| 1160 | } |
| 1161 | mSelectAccountFragmentListener.setQuickContactActivity(this); |
Paul Soulos | 23889ba | 2014-06-10 14:55:32 -0700 | [diff] [blame] | 1162 | |
Brian Attwell | f1076dc | 2014-08-12 21:28:21 -0700 | [diff] [blame] | 1163 | SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ true, |
| 1164 | new Runnable() { |
| 1165 | @Override |
| 1166 | public void run() { |
| 1167 | if (!mHasAlreadyBeenOpened) { |
| 1168 | // The initial scrim opacity must match the scrim opacity that would be |
| 1169 | // achieved by scrolling to the starting position. |
| 1170 | final float alphaRatio = mExtraMode == MODE_FULLY_EXPANDED ? |
| 1171 | 1 : mScroller.getStartingTransparentHeightRatio(); |
| 1172 | final int duration = getResources().getInteger( |
| 1173 | android.R.integer.config_shortAnimTime); |
| 1174 | final int desiredAlpha = (int) (0xFF * alphaRatio); |
| 1175 | ObjectAnimator o = ObjectAnimator.ofInt(mWindowScrim, "alpha", 0, |
| 1176 | desiredAlpha).setDuration(duration); |
| 1177 | |
| 1178 | o.start(); |
| 1179 | } |
| 1180 | } |
| 1181 | }); |
| 1182 | |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1183 | if (savedInstanceState != null) { |
| 1184 | final int color = savedInstanceState.getInt(KEY_THEME_COLOR, 0); |
Brian Attwell | ac3ed8e | 2014-06-27 17:24:42 -0700 | [diff] [blame] | 1185 | SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, |
| 1186 | new Runnable() { |
| 1187 | @Override |
| 1188 | public void run() { |
| 1189 | // Need to wait for the pre draw before setting the initial scroll |
| 1190 | // value. Prior to pre draw all scroll values are invalid. |
| 1191 | if (mHasAlreadyBeenOpened) { |
| 1192 | mScroller.setVisibility(View.VISIBLE); |
| 1193 | mScroller.setScroll(mScroller.getScrollNeededToBeFullScreen()); |
| 1194 | } |
| 1195 | // Need to wait for pre draw for setting the theme color. Setting the |
| 1196 | // header tint before the MultiShrinkScroller has been measured will |
| 1197 | // cause incorrect tinting calculations. |
| 1198 | if (color != 0) { |
Brian Attwell | a3859ed | 2014-07-15 13:51:55 -0700 | [diff] [blame] | 1199 | setThemeColor(mMaterialColorMapUtils |
| 1200 | .calculatePrimaryAndSecondaryColor(color)); |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1201 | } |
Brian Attwell | ac3ed8e | 2014-06-27 17:24:42 -0700 | [diff] [blame] | 1202 | } |
| 1203 | }); |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1206 | Trace.endSection(); |
| 1207 | } |
| 1208 | |
Paul Soulos | 405ae40 | 2014-07-14 16:16:36 -0700 | [diff] [blame] | 1209 | @Override |
| 1210 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
Wenyi Wang | d1cb904 | 2015-11-05 17:17:59 -0800 | [diff] [blame] | 1211 | final boolean deletedOrSplit = requestCode == REQUEST_CODE_CONTACT_EDITOR_ACTIVITY && |
| 1212 | (resultCode == ContactDeletionInteraction.RESULT_CODE_DELETED || |
| 1213 | resultCode == ContactEditorBaseActivity.RESULT_CODE_SPLIT); |
Gary Mai | 0d76abc | 2016-05-25 16:19:45 -0700 | [diff] [blame] | 1214 | setResult(resultCode, data); |
Wenyi Wang | d1cb904 | 2015-11-05 17:17:59 -0800 | [diff] [blame] | 1215 | if (deletedOrSplit) { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1216 | finish(); |
Paul Soulos | ab54ea1 | 2014-08-28 17:22:38 -0700 | [diff] [blame] | 1217 | } else if (requestCode == REQUEST_CODE_CONTACT_SELECTION_ACTIVITY && |
| 1218 | resultCode != RESULT_CANCELED) { |
| 1219 | processIntent(data); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | @Override |
| 1224 | protected void onNewIntent(Intent intent) { |
| 1225 | super.onNewIntent(intent); |
| 1226 | mHasAlreadyBeenOpened = true; |
Brian Attwell | f1076dc | 2014-08-12 21:28:21 -0700 | [diff] [blame] | 1227 | mIsEntranceAnimationFinished = true; |
Brian Attwell | 8571dd3 | 2014-06-23 23:29:10 -0700 | [diff] [blame] | 1228 | mHasComputedThemeColor = false; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1229 | processIntent(intent); |
| 1230 | } |
| 1231 | |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1232 | @Override |
| 1233 | public void onSaveInstanceState(Bundle savedInstanceState) { |
| 1234 | super.onSaveInstanceState(savedInstanceState); |
| 1235 | if (mColorFilter != null) { |
Brian Attwell | 8e29faf | 2015-01-21 10:22:40 -0800 | [diff] [blame] | 1236 | savedInstanceState.putInt(KEY_THEME_COLOR, mColorFilterColor); |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1237 | } |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 1238 | savedInstanceState.putBoolean(KEY_IS_SUGGESTION_LIST_COLLAPSED, mIsSuggestionListCollapsed); |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 1239 | savedInstanceState.putLong(KEY_PREVIOUS_CONTACT_ID, mPreviousContactId); |
| 1240 | savedInstanceState.putBoolean( |
| 1241 | KEY_SUGGESTIONS_AUTO_SELECTED, mSuggestionsShouldAutoSelected); |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 1242 | savedInstanceState.putSerializable( |
| 1243 | KEY_SELECTED_SUGGESTION_CONTACTS, mSelectedAggregationIds); |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1246 | private void processIntent(Intent intent) { |
Paul Soulos | f19dda9 | 2014-09-15 15:48:02 -0700 | [diff] [blame] | 1247 | if (intent == null) { |
| 1248 | finish(); |
| 1249 | return; |
| 1250 | } |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1251 | Uri lookupUri = intent.getData(); |
Gary Mai | 250fc16 | 2016-06-10 16:54:15 -0700 | [diff] [blame] | 1252 | if (intent.getBooleanExtra(EXTRA_CONTACT_EDITED, false)) { |
| 1253 | setResult(ContactEditorBaseActivity.RESULT_CODE_EDITED); |
| 1254 | } |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1255 | |
| 1256 | // Check to see whether it comes from the old version. |
| 1257 | if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) { |
| 1258 | final long rawContactId = ContentUris.parseId(lookupUri); |
| 1259 | lookupUri = RawContacts.getContactLookupUri(getContentResolver(), |
| 1260 | ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); |
| 1261 | } |
Brian Attwell | 05287bf | 2015-02-25 22:24:04 -0800 | [diff] [blame] | 1262 | mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, QuickContact.MODE_LARGE); |
Wenyi Wang | caf2619 | 2016-05-09 15:00:25 -0700 | [diff] [blame] | 1263 | if (isMultiWindowOnPhone()) { |
| 1264 | mExtraMode = QuickContact.MODE_LARGE; |
| 1265 | } |
| 1266 | mExtraPrioritizedMimeType = |
| 1267 | getIntent().getStringExtra(QuickContact.EXTRA_PRIORITIZED_MIMETYPE); |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1268 | final Uri oldLookupUri = mLookupUri; |
| 1269 | |
Jay Shrauner | fcfcae3 | 2014-11-24 10:23:36 -0800 | [diff] [blame] | 1270 | if (lookupUri == null) { |
| 1271 | finish(); |
| 1272 | return; |
| 1273 | } |
| 1274 | mLookupUri = lookupUri; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1275 | mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES); |
| 1276 | if (oldLookupUri == null) { |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 1277 | // Should not log if only orientation changes. |
| 1278 | mShouldLog = !mIsRecreatedInstance; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1279 | mContactLoader = (ContactLoader) getLoaderManager().initLoader( |
| 1280 | LOADER_CONTACT_ID, null, mLoaderContactCallbacks); |
| 1281 | } else if (oldLookupUri != mLookupUri) { |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 1282 | // Should log when reload happens, regardless of orientation change. |
| 1283 | mShouldLog = true; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1284 | // After copying a directory contact, the contact URI changes. Therefore, |
Wenyi Wang | 144a4d1 | 2016-02-17 11:46:23 -0800 | [diff] [blame] | 1285 | // we need to reload the new contact. |
Brian Attwell | 59a585b | 2014-10-17 18:07:10 -0700 | [diff] [blame] | 1286 | destroyInteractionLoaders(); |
Wenyi Wang | 144a4d1 | 2016-02-17 11:46:23 -0800 | [diff] [blame] | 1287 | mContactLoader = (ContactLoader) (Loader<?>) getLoaderManager().getLoader( |
| 1288 | LOADER_CONTACT_ID); |
Walter Jang | 27a2fac | 2016-03-14 10:44:14 -0700 | [diff] [blame] | 1289 | mContactLoader.setLookupUri(mLookupUri); |
Brian Attwell | 59a585b | 2014-10-17 18:07:10 -0700 | [diff] [blame] | 1290 | mCachedCp2DataCardModel = null; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1291 | } |
Wenyi Wang | 144a4d1 | 2016-02-17 11:46:23 -0800 | [diff] [blame] | 1292 | mContactLoader.forceLoad(); |
Brian Attwell | 2d150da | 2014-07-09 22:35:56 -0700 | [diff] [blame] | 1293 | |
| 1294 | NfcHandler.register(this, mLookupUri); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
Brian Attwell | 59a585b | 2014-10-17 18:07:10 -0700 | [diff] [blame] | 1297 | private void destroyInteractionLoaders() { |
| 1298 | for (int interactionLoaderId : mRecentLoaderIds) { |
| 1299 | getLoaderManager().destroyLoader(interactionLoaderId); |
| 1300 | } |
| 1301 | } |
| 1302 | |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 1303 | private void runEntranceAnimation() { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1304 | if (mHasAlreadyBeenOpened) { |
| 1305 | return; |
| 1306 | } |
| 1307 | mHasAlreadyBeenOpened = true; |
Wenyi Wang | caf2619 | 2016-05-09 15:00:25 -0700 | [diff] [blame] | 1308 | mScroller.scrollUpForEntranceAnimation(/* scrollToCurrentPosition */ !isMultiWindowOnPhone() |
| 1309 | && (mExtraMode != MODE_FULLY_EXPANDED)); |
| 1310 | } |
| 1311 | |
| 1312 | private boolean isMultiWindowOnPhone() { |
| 1313 | return MultiWindowCompat.isInMultiWindowMode(this) && PhoneCapabilityTester.isPhone(this); |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Katherine Kuan | 81281ee | 2011-07-28 16:20:59 -0700 | [diff] [blame] | 1316 | /** Assign this string to the view if it is not empty. */ |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1317 | private void setHeaderNameText(int resId) { |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1318 | if (mScroller != null) { |
Tingting Wang | 9f153a0 | 2015-11-05 18:11:04 -0800 | [diff] [blame] | 1319 | mScroller.setTitle(getText(resId) == null ? null : getText(resId).toString(), |
| 1320 | /* isPhoneNumber= */ false); |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1321 | } |
Katherine Kuan | 81281ee | 2011-07-28 16:20:59 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | /** Assign this string to the view if it is not empty. */ |
Tingting Wang | 9f153a0 | 2015-11-05 18:11:04 -0800 | [diff] [blame] | 1325 | private void setHeaderNameText(String value, boolean isPhoneNumber) { |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1326 | if (!TextUtils.isEmpty(value)) { |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1327 | if (mScroller != null) { |
Tingting Wang | 9f153a0 | 2015-11-05 18:11:04 -0800 | [diff] [blame] | 1328 | mScroller.setTitle(value, isPhoneNumber); |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 1329 | } |
Katherine Kuan | 81281ee | 2011-07-28 16:20:59 -0700 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | /** |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 1334 | * Check if the given MIME-type appears in the list of excluded MIME-types |
| 1335 | * that the most-recent caller requested. |
| 1336 | */ |
| 1337 | private boolean isMimeExcluded(String mimeType) { |
| 1338 | if (mExcludeMimes == null) return false; |
| 1339 | for (String excludedMime : mExcludeMimes) { |
| 1340 | if (TextUtils.equals(excludedMime, mimeType)) { |
| 1341 | return true; |
| 1342 | } |
| 1343 | } |
| 1344 | return false; |
| 1345 | } |
| 1346 | |
| 1347 | /** |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 1348 | * Handle the result from the ContactLoader |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 1349 | */ |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1350 | private void bindContactData(final Contact data) { |
| 1351 | Trace.beginSection("bindContactData"); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 1352 | |
| 1353 | final int actionType = mContactData == null ? ActionType.START : ActionType.UNKNOWN_ACTION; |
Yorke Lee | 6cb6f6f | 2013-09-26 16:26:03 -0700 | [diff] [blame] | 1354 | mContactData = data; |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 1355 | |
| 1356 | final int newContactType; |
| 1357 | if (DirectoryContactUtil.isDirectoryContact(mContactData)) { |
| 1358 | newContactType = ContactType.DIRECTORY; |
| 1359 | } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { |
| 1360 | newContactType = ContactType.INVISIBLE_AND_ADDABLE; |
| 1361 | } else if (isContactEditable()) { |
| 1362 | newContactType = ContactType.EDITABLE; |
| 1363 | } else { |
| 1364 | newContactType = ContactType.UNKNOWN_TYPE; |
| 1365 | } |
| 1366 | if (mShouldLog && mContactType != newContactType) { |
| 1367 | Logger.logQuickContactEvent( mReferrer, newContactType, CardType.UNKNOWN_CARD, |
| 1368 | actionType, /* thirdPartyAction */ null); |
| 1369 | } |
| 1370 | mContactType = newContactType; |
| 1371 | |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 1372 | invalidateOptionsMenu(); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 1373 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1374 | Trace.endSection(); |
| 1375 | Trace.beginSection("Set display photo & name"); |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 1376 | |
Brian Attwell | 02eaf11 | 2014-08-27 21:03:42 -0700 | [diff] [blame] | 1377 | mPhotoView.setIsBusiness(mContactData.isDisplayNameFromOrganization()); |
Yorke Lee | 6219668 | 2013-09-06 18:34:17 -0700 | [diff] [blame] | 1378 | mPhotoSetter.setupContactPhoto(data, mPhotoView); |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 1379 | extractAndApplyTintFromPhotoViewAsynchronously(); |
Tingting Wang | df65d16 | 2015-07-24 17:04:35 -0700 | [diff] [blame] | 1380 | final String displayName = ContactDisplayUtils.getDisplayName(this, data).toString(); |
Tingting Wang | 9f153a0 | 2015-11-05 18:11:04 -0800 | [diff] [blame] | 1381 | setHeaderNameText( |
| 1382 | displayName, mContactData.getDisplayNameSource() == DisplayNameSources.PHONE); |
Tingting Wang | df65d16 | 2015-07-24 17:04:35 -0700 | [diff] [blame] | 1383 | final String phoneticName = ContactDisplayUtils.getPhoneticName(this, data); |
| 1384 | if (mScroller != null) { |
Tingting Wang | 469a70f | 2016-03-08 14:50:29 -0800 | [diff] [blame] | 1385 | // Show phonetic name only when it doesn't equal the display name. |
| 1386 | if (!TextUtils.isEmpty(phoneticName) && !phoneticName.equals(displayName)) { |
Tingting Wang | df65d16 | 2015-07-24 17:04:35 -0700 | [diff] [blame] | 1387 | mScroller.setPhoneticName(phoneticName); |
| 1388 | } else { |
| 1389 | mScroller.setPhoneticNameGone(); |
| 1390 | } |
Tingting Wang | d5b686e | 2015-07-13 12:52:40 -0700 | [diff] [blame] | 1391 | } |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 1392 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1393 | Trace.endSection(); |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 1394 | |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1395 | mEntriesAndActionsTask = new AsyncTask<Void, Void, Cp2DataCardModel>() { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1396 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1397 | @Override |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1398 | protected Cp2DataCardModel doInBackground( |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1399 | Void... params) { |
| 1400 | return generateDataModelFromContact(data); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | @Override |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1404 | protected void onPostExecute(Cp2DataCardModel cardDataModel) { |
| 1405 | super.onPostExecute(cardDataModel); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1406 | // Check that original AsyncTask parameters are still valid and the activity |
| 1407 | // is still running before binding to UI. A new intent could invalidate |
| 1408 | // the results, for example. |
| 1409 | if (data == mContactData && !isCancelled()) { |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1410 | bindDataToCards(cardDataModel); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1411 | showActivity(); |
| 1412 | } |
| 1413 | } |
| 1414 | }; |
| 1415 | mEntriesAndActionsTask.execute(); |
| 1416 | } |
| 1417 | |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1418 | private void bindDataToCards(Cp2DataCardModel cp2DataCardModel) { |
| 1419 | startInteractionLoaders(cp2DataCardModel); |
Wenyi Wang | a26a57a | 2016-03-02 17:53:23 -0800 | [diff] [blame] | 1420 | populateContactAndAboutCard(cp2DataCardModel, /* shouldAddPhoneticName */ true); |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 1421 | populateSuggestionCard(); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1424 | private void startInteractionLoaders(Cp2DataCardModel cp2DataCardModel) { |
| 1425 | final Map<String, List<DataItem>> dataItemsMap = cp2DataCardModel.dataItemsMap; |
| 1426 | final List<DataItem> phoneDataItems = dataItemsMap.get(Phone.CONTENT_ITEM_TYPE); |
guanxiongliu | c7a4b9c | 2016-04-30 20:19:21 -0700 | [diff] [blame] | 1427 | final List<DataItem> sipCallDataItems = dataItemsMap.get(SipAddress.CONTENT_ITEM_TYPE); |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 1428 | if (phoneDataItems != null && phoneDataItems.size() == 1) { |
| 1429 | mOnlyOnePhoneNumber = true; |
| 1430 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1431 | String[] phoneNumbers = null; |
| 1432 | if (phoneDataItems != null) { |
| 1433 | phoneNumbers = new String[phoneDataItems.size()]; |
| 1434 | for (int i = 0; i < phoneDataItems.size(); ++i) { |
| 1435 | phoneNumbers[i] = ((PhoneDataItem) phoneDataItems.get(i)).getNumber(); |
| 1436 | } |
| 1437 | } |
guanxiongliu | c7a4b9c | 2016-04-30 20:19:21 -0700 | [diff] [blame] | 1438 | String[] sipNumbers = null; |
| 1439 | if (sipCallDataItems != null) { |
| 1440 | sipNumbers = new String[sipCallDataItems.size()]; |
| 1441 | for (int i = 0; i < sipCallDataItems.size(); ++i) { |
| 1442 | sipNumbers[i] = ((SipAddressDataItem) sipCallDataItems.get(i)).getSipAddress(); |
| 1443 | } |
| 1444 | } |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 1445 | final Bundle phonesExtraBundle = new Bundle(); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1446 | phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_PHONES, phoneNumbers); |
guanxiongliu | c7a4b9c | 2016-04-30 20:19:21 -0700 | [diff] [blame] | 1447 | phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_SIP_NUMBERS, sipNumbers); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1448 | |
| 1449 | Trace.beginSection("start sms loader"); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1450 | getLoaderManager().initLoader( |
| 1451 | LOADER_SMS_ID, |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 1452 | phonesExtraBundle, |
| 1453 | mLoaderInteractionsCallbacks); |
| 1454 | Trace.endSection(); |
| 1455 | |
| 1456 | Trace.beginSection("start call log loader"); |
| 1457 | getLoaderManager().initLoader( |
| 1458 | LOADER_CALL_LOG_ID, |
| 1459 | phonesExtraBundle, |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1460 | mLoaderInteractionsCallbacks); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1461 | Trace.endSection(); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1462 | |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1463 | |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 1464 | Trace.beginSection("start calendar loader"); |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1465 | final List<DataItem> emailDataItems = dataItemsMap.get(Email.CONTENT_ITEM_TYPE); |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 1466 | if (emailDataItems != null && emailDataItems.size() == 1) { |
| 1467 | mOnlyOneEmail = true; |
| 1468 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1469 | String[] emailAddresses = null; |
| 1470 | if (emailDataItems != null) { |
| 1471 | emailAddresses = new String[emailDataItems.size()]; |
| 1472 | for (int i = 0; i < emailDataItems.size(); ++i) { |
| 1473 | emailAddresses[i] = ((EmailDataItem) emailDataItems.get(i)).getAddress(); |
| 1474 | } |
| 1475 | } |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 1476 | final Bundle emailsExtraBundle = new Bundle(); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1477 | emailsExtraBundle.putStringArray(KEY_LOADER_EXTRA_EMAILS, emailAddresses); |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 1478 | getLoaderManager().initLoader( |
| 1479 | LOADER_CALENDAR_ID, |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 1480 | emailsExtraBundle, |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 1481 | mLoaderInteractionsCallbacks); |
| 1482 | Trace.endSection(); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | private void showActivity() { |
| 1486 | if (mScroller != null) { |
| 1487 | mScroller.setVisibility(View.VISIBLE); |
| 1488 | SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false, |
| 1489 | new Runnable() { |
| 1490 | @Override |
| 1491 | public void run() { |
| 1492 | runEntranceAnimation(); |
| 1493 | } |
| 1494 | }); |
| 1495 | } |
| 1496 | } |
| 1497 | |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1498 | private List<List<Entry>> buildAboutCardEntries(Map<String, List<DataItem>> dataItemsMap) { |
Paul Soulos | a153dba | 2014-08-06 13:44:57 -0700 | [diff] [blame] | 1499 | final List<List<Entry>> aboutCardEntries = new ArrayList<>(); |
| 1500 | for (String mimetype : SORTED_ABOUT_CARD_MIMETYPES) { |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1501 | final List<DataItem> mimeTypeItems = dataItemsMap.get(mimetype); |
Paul Soulos | a153dba | 2014-08-06 13:44:57 -0700 | [diff] [blame] | 1502 | if (mimeTypeItems == null) { |
| 1503 | continue; |
| 1504 | } |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1505 | // Set aboutCardTitleOut = null, since SORTED_ABOUT_CARD_MIMETYPES doesn't contain |
| 1506 | // the name mimetype. |
| 1507 | final List<Entry> aboutEntries = dataItemsToEntries(mimeTypeItems, |
| 1508 | /* aboutCardTitleOut = */ null); |
Paul Soulos | a153dba | 2014-08-06 13:44:57 -0700 | [diff] [blame] | 1509 | if (aboutEntries.size() > 0) { |
| 1510 | aboutCardEntries.add(aboutEntries); |
| 1511 | } |
| 1512 | } |
| 1513 | return aboutCardEntries; |
| 1514 | } |
| 1515 | |
Paul Soulos | a42ef76 | 2014-08-20 10:26:10 -0700 | [diff] [blame] | 1516 | @Override |
| 1517 | protected void onResume() { |
| 1518 | super.onResume(); |
| 1519 | // If returning from a launched activity, repopulate the contact and about card |
| 1520 | if (mHasIntentLaunched) { |
| 1521 | mHasIntentLaunched = false; |
Wenyi Wang | a26a57a | 2016-03-02 17:53:23 -0800 | [diff] [blame] | 1522 | populateContactAndAboutCard(mCachedCp2DataCardModel, /* shouldAddPhoneticName */ false); |
Paul Soulos | a42ef76 | 2014-08-20 10:26:10 -0700 | [diff] [blame] | 1523 | } |
Brian Attwell | 59a585b | 2014-10-17 18:07:10 -0700 | [diff] [blame] | 1524 | |
| 1525 | // When exiting the activity and resuming, we want to force a full reload of all the |
| 1526 | // interaction data in case something changed in the background. On screen rotation, |
| 1527 | // we don't need to do this. And, mCachedCp2DataCardModel will be null, so we won't. |
| 1528 | if (mCachedCp2DataCardModel != null) { |
| 1529 | destroyInteractionLoaders(); |
| 1530 | startInteractionLoaders(mCachedCp2DataCardModel); |
| 1531 | } |
Paul Soulos | a42ef76 | 2014-08-20 10:26:10 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 1534 | private void populateSuggestionCard() { |
Gary Mai | d1d8a7a | 2016-06-07 14:46:58 -0700 | [diff] [blame] | 1535 | if (!mShouldShowSuggestions) { |
| 1536 | return; |
| 1537 | } |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 1538 | // Initialize suggestion related view and data. |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 1539 | if (mPreviousContactId != mContactData.getId()) { |
| 1540 | mCollapsedSuggestionCardView.setVisibility(View.GONE); |
| 1541 | mExpandSuggestionCardView.setVisibility(View.GONE); |
| 1542 | mIsSuggestionListCollapsed = true; |
Tingting Wang | 42a08d9 | 2015-11-20 11:26:21 -0800 | [diff] [blame] | 1543 | mSuggestionsShouldAutoSelected = true; |
Tingting Wang | 0fafb0e | 2015-10-14 12:18:45 -0700 | [diff] [blame] | 1544 | mSuggestionList.removeAllViews(); |
| 1545 | } |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 1546 | |
Tingting Wang | 3d65ea5 | 2015-11-13 09:36:02 -0800 | [diff] [blame] | 1547 | // Do not show the card when it's directory contact or invisible. |
| 1548 | if (DirectoryContactUtil.isDirectoryContact(mContactData) |
| 1549 | || InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { |
| 1550 | return; |
| 1551 | } |
| 1552 | |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 1553 | if (mAggregationSuggestionEngine == null) { |
| 1554 | mAggregationSuggestionEngine = new AggregationSuggestionEngine(this); |
| 1555 | mAggregationSuggestionEngine.setListener(this); |
Tingting Wang | e29b694 | 2015-09-30 15:21:33 -0700 | [diff] [blame] | 1556 | mAggregationSuggestionEngine.setSuggestionsLimit(getResources().getInteger( |
| 1557 | R.integer.quickcontact_suggestions_limit)); |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 1558 | mAggregationSuggestionEngine.start(); |
| 1559 | } |
| 1560 | |
| 1561 | mAggregationSuggestionEngine.setContactId(mContactData.getId()); |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 1562 | if (mPreviousContactId != 0 |
| 1563 | && mPreviousContactId != mContactData.getId()) { |
Tingting Wang | e29b694 | 2015-09-30 15:21:33 -0700 | [diff] [blame] | 1564 | // Clear selected Ids when listing suggestions for new contact Id. |
| 1565 | mSelectedAggregationIds.clear(); |
| 1566 | } |
Tingting Wang | 18906c0 | 2015-10-16 14:53:10 -0700 | [diff] [blame] | 1567 | mPreviousContactId = mContactData.getId(); |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 1568 | |
| 1569 | // Trigger suggestion engine to compute suggestions. |
Tingting Wang | a1af0c8 | 2015-10-23 10:53:58 -0700 | [diff] [blame] | 1570 | if (mContactData.getId() <= 0) { |
| 1571 | return; |
| 1572 | } |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 1573 | final ContentValues values = new ContentValues(); |
| 1574 | values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, |
| 1575 | mContactData.getDisplayName()); |
| 1576 | values.put(ContactsContract.CommonDataKinds.StructuredName.PHONETIC_FAMILY_NAME, |
| 1577 | mContactData.getPhoneticName()); |
| 1578 | mAggregationSuggestionEngine.onNameChange(ValuesDelta.fromBefore(values)); |
| 1579 | } |
| 1580 | |
Wenyi Wang | a26a57a | 2016-03-02 17:53:23 -0800 | [diff] [blame] | 1581 | private void populateContactAndAboutCard(Cp2DataCardModel cp2DataCardModel, |
| 1582 | boolean shouldAddPhoneticName) { |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1583 | mCachedCp2DataCardModel = cp2DataCardModel; |
| 1584 | if (mHasIntentLaunched || cp2DataCardModel == null) { |
Paul Soulos | a42ef76 | 2014-08-20 10:26:10 -0700 | [diff] [blame] | 1585 | return; |
| 1586 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1587 | Trace.beginSection("bind contact card"); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1588 | |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1589 | final List<List<Entry>> contactCardEntries = cp2DataCardModel.contactCardEntries; |
| 1590 | final List<List<Entry>> aboutCardEntries = cp2DataCardModel.aboutCardEntries; |
| 1591 | final String customAboutCardName = cp2DataCardModel.customAboutCardName; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1592 | |
| 1593 | if (contactCardEntries.size() > 0) { |
| 1594 | mContactCard.initialize(contactCardEntries, |
| 1595 | /* numInitialVisibleEntries = */ MIN_NUM_CONTACT_ENTRIES_SHOWN, |
Paul Soulos | c8e2a91 | 2014-07-21 14:52:20 -0700 | [diff] [blame] | 1596 | /* isExpanded = */ mContactCard.isExpanded(), |
yaolu | 139a03b | 2016-09-02 17:44:10 -0700 | [diff] [blame^] | 1597 | /* isAlwaysExpanded = */ true, |
Paul Soulos | 0cda9ae | 2014-07-23 11:27:28 -0700 | [diff] [blame] | 1598 | mExpandingEntryCardViewListener, |
yaolu | 139a03b | 2016-09-02 17:44:10 -0700 | [diff] [blame^] | 1599 | mScroller); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 1600 | if (mContactCard.getVisibility() == View.GONE && mShouldLog) { |
| 1601 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.CONTACT, |
| 1602 | ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); |
| 1603 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1604 | mContactCard.setVisibility(View.VISIBLE); |
| 1605 | } else { |
| 1606 | mContactCard.setVisibility(View.GONE); |
| 1607 | } |
| 1608 | Trace.endSection(); |
| 1609 | |
| 1610 | Trace.beginSection("bind about card"); |
Paul Soulos | c6e1109 | 2014-07-22 09:22:27 -0700 | [diff] [blame] | 1611 | // Phonetic name is not a data item, so the entry needs to be created separately |
Wenyi Wang | a26a57a | 2016-03-02 17:53:23 -0800 | [diff] [blame] | 1612 | // But if mCachedCp2DataCardModel is passed to this method (e.g. returning from editor |
| 1613 | // without saving any changes), then it should include phoneticName and the phoneticName |
| 1614 | // shouldn't be changed. If this is the case, we shouldn't add it again. b/27459294 |
Paul Soulos | c6e1109 | 2014-07-22 09:22:27 -0700 | [diff] [blame] | 1615 | final String phoneticName = mContactData.getPhoneticName(); |
Wenyi Wang | a26a57a | 2016-03-02 17:53:23 -0800 | [diff] [blame] | 1616 | if (shouldAddPhoneticName && !TextUtils.isEmpty(phoneticName)) { |
Paul Soulos | c6e1109 | 2014-07-22 09:22:27 -0700 | [diff] [blame] | 1617 | Entry phoneticEntry = new Entry(/* viewId = */ -1, |
| 1618 | /* icon = */ null, |
| 1619 | getResources().getString(R.string.name_phonetic), |
| 1620 | phoneticName, |
Walter Jang | 8a3fe52 | 2014-10-16 11:12:13 -0700 | [diff] [blame] | 1621 | /* subHeaderIcon = */ null, |
Paul Soulos | c6e1109 | 2014-07-22 09:22:27 -0700 | [diff] [blame] | 1622 | /* text = */ null, |
Walter Jang | 8a3fe52 | 2014-10-16 11:12:13 -0700 | [diff] [blame] | 1623 | /* textIcon = */ null, |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1624 | /* primaryContentDescription = */ null, |
Paul Soulos | c6e1109 | 2014-07-22 09:22:27 -0700 | [diff] [blame] | 1625 | /* intent = */ null, |
| 1626 | /* alternateIcon = */ null, |
| 1627 | /* alternateIntent = */ null, |
| 1628 | /* alternateContentDescription = */ null, |
| 1629 | /* shouldApplyColor = */ false, |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 1630 | /* isEditable = */ false, |
| 1631 | /* EntryContextMenuInfo = */ new EntryContextMenuInfo(phoneticName, |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 1632 | getResources().getString(R.string.name_phonetic), |
| 1633 | /* mimeType = */ null, /* id = */ -1, /* isPrimary = */ false), |
Paul Soulos | 48fc912 | 2014-08-26 13:52:36 -0700 | [diff] [blame] | 1634 | /* thirdIcon = */ null, |
| 1635 | /* thirdIntent = */ null, |
Paul Soulos | 48290be | 2014-09-08 13:44:51 -0700 | [diff] [blame] | 1636 | /* thirdContentDescription = */ null, |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 1637 | /* thirdAction = */ Entry.ACTION_NONE, |
| 1638 | /* thirdExtras = */ null, |
| 1639 | /* iconResourceId = */ 0); |
Paul Soulos | c6e1109 | 2014-07-22 09:22:27 -0700 | [diff] [blame] | 1640 | List<Entry> phoneticList = new ArrayList<>(); |
| 1641 | phoneticList.add(phoneticEntry); |
Paul Soulos | a153dba | 2014-08-06 13:44:57 -0700 | [diff] [blame] | 1642 | // Phonetic name comes after nickname. Check to see if the first entry type is nickname |
Paul Soulos | a0fa4c1 | 2014-08-07 12:01:32 -0700 | [diff] [blame] | 1643 | if (aboutCardEntries.size() > 0 && aboutCardEntries.get(0).get(0).getHeader().equals( |
Paul Soulos | a153dba | 2014-08-06 13:44:57 -0700 | [diff] [blame] | 1644 | getResources().getString(R.string.header_nickname_entry))) { |
| 1645 | aboutCardEntries.add(1, phoneticList); |
| 1646 | } else { |
| 1647 | aboutCardEntries.add(0, phoneticList); |
| 1648 | } |
Paul Soulos | c6e1109 | 2014-07-22 09:22:27 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1651 | if (!TextUtils.isEmpty(customAboutCardName)) { |
| 1652 | mAboutCard.setTitle(customAboutCardName); |
| 1653 | } |
| 1654 | |
kungaox | 3b1a8b2 | 2015-02-05 15:29:19 +0800 | [diff] [blame] | 1655 | mAboutCard.initialize(aboutCardEntries, |
| 1656 | /* numInitialVisibleEntries = */ 1, |
| 1657 | /* isExpanded = */ true, |
| 1658 | /* isAlwaysExpanded = */ true, |
| 1659 | mExpandingEntryCardViewListener, |
| 1660 | mScroller); |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 1661 | |
| 1662 | if (contactCardEntries.size() == 0 && aboutCardEntries.size() == 0) { |
| 1663 | initializeNoContactDetailCard(); |
| 1664 | } else { |
| 1665 | mNoContactDetailsCard.setVisibility(View.GONE); |
| 1666 | } |
| 1667 | |
Paul Soulos | a8fce96 | 2014-07-15 13:37:24 -0700 | [diff] [blame] | 1668 | // If the Recent card is already initialized (all recent data is loaded), show the About |
| 1669 | // card if it has entries. Otherwise About card visibility will be set in bindRecentData() |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 1670 | if (aboutCardEntries.size() > 0) { |
| 1671 | if (mAboutCard.getVisibility() == View.GONE && mShouldLog) { |
| 1672 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.ABOUT, |
| 1673 | ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); |
| 1674 | } |
| 1675 | if (isAllRecentDataLoaded()) { |
| 1676 | mAboutCard.setVisibility(View.VISIBLE); |
| 1677 | } |
Paul Soulos | a8fce96 | 2014-07-15 13:37:24 -0700 | [diff] [blame] | 1678 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1679 | Trace.endSection(); |
| 1680 | } |
| 1681 | |
| 1682 | /** |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 1683 | * Create a card that shows "Add email" and "Add phone number" entries in grey. |
| 1684 | */ |
| 1685 | private void initializeNoContactDetailCard() { |
| 1686 | final Drawable phoneIcon = getResources().getDrawable( |
| 1687 | R.drawable.ic_phone_24dp).mutate(); |
| 1688 | final Entry phonePromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, |
| 1689 | phoneIcon, getString(R.string.quickcontact_add_phone_number), |
Walter Jang | 8a3fe52 | 2014-10-16 11:12:13 -0700 | [diff] [blame] | 1690 | /* subHeader = */ null, /* subHeaderIcon = */ null, /* text = */ null, |
| 1691 | /* textIcon = */ null, /* primaryContentDescription = */ null, |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1692 | getEditContactIntent(), |
Paul Soulos | dd7419d | 2014-07-15 11:22:13 -0700 | [diff] [blame] | 1693 | /* alternateIcon = */ null, /* alternateIntent = */ null, |
Paul Soulos | 714455b | 2014-07-15 14:32:01 -0700 | [diff] [blame] | 1694 | /* alternateContentDescription = */ null, /* shouldApplyColor = */ true, |
Paul Soulos | 48fc912 | 2014-08-26 13:52:36 -0700 | [diff] [blame] | 1695 | /* isEditable = */ false, /* EntryContextMenuInfo = */ null, |
| 1696 | /* thirdIcon = */ null, /* thirdIntent = */ null, |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 1697 | /* thirdContentDescription = */ null, |
| 1698 | /* thirdAction = */ Entry.ACTION_NONE, |
| 1699 | /* thirdExtras = */ null, |
| 1700 | R.drawable.ic_phone_24dp); |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 1701 | |
| 1702 | final Drawable emailIcon = getResources().getDrawable( |
| 1703 | R.drawable.ic_email_24dp).mutate(); |
| 1704 | final Entry emailPromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT, |
| 1705 | emailIcon, getString(R.string.quickcontact_add_email), /* subHeader = */ null, |
Walter Jang | 8a3fe52 | 2014-10-16 11:12:13 -0700 | [diff] [blame] | 1706 | /* subHeaderIcon = */ null, |
| 1707 | /* text = */ null, /* textIcon = */ null, /* primaryContentDescription = */ null, |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1708 | getEditContactIntent(), /* alternateIcon = */ null, |
Paul Soulos | dd7419d | 2014-07-15 11:22:13 -0700 | [diff] [blame] | 1709 | /* alternateIntent = */ null, /* alternateContentDescription = */ null, |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 1710 | /* shouldApplyColor = */ true, /* isEditable = */ false, |
Paul Soulos | 48fc912 | 2014-08-26 13:52:36 -0700 | [diff] [blame] | 1711 | /* EntryContextMenuInfo = */ null, /* thirdIcon = */ null, |
Paul Soulos | 48290be | 2014-09-08 13:44:51 -0700 | [diff] [blame] | 1712 | /* thirdIntent = */ null, /* thirdContentDescription = */ null, |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 1713 | /* thirdAction = */ Entry.ACTION_NONE, /* thirdExtras = */ null, |
Paul Soulos | 48290be | 2014-09-08 13:44:51 -0700 | [diff] [blame] | 1714 | R.drawable.ic_email_24dp); |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 1715 | |
| 1716 | final List<List<Entry>> promptEntries = new ArrayList<>(); |
| 1717 | promptEntries.add(new ArrayList<Entry>(1)); |
| 1718 | promptEntries.add(new ArrayList<Entry>(1)); |
| 1719 | promptEntries.get(0).add(phonePromptEntry); |
| 1720 | promptEntries.get(1).add(emailPromptEntry); |
| 1721 | |
| 1722 | final int subHeaderTextColor = getResources().getColor( |
| 1723 | R.color.quickcontact_entry_sub_header_text_color); |
| 1724 | final PorterDuffColorFilter greyColorFilter = |
| 1725 | new PorterDuffColorFilter(subHeaderTextColor, PorterDuff.Mode.SRC_ATOP); |
Paul Soulos | c8e2a91 | 2014-07-21 14:52:20 -0700 | [diff] [blame] | 1726 | mNoContactDetailsCard.initialize(promptEntries, 2, /* isExpanded = */ true, |
Paul Soulos | 0cda9ae | 2014-07-23 11:27:28 -0700 | [diff] [blame] | 1727 | /* isAlwaysExpanded = */ true, mExpandingEntryCardViewListener, mScroller); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 1728 | if (mNoContactDetailsCard.getVisibility() == View.GONE && mShouldLog) { |
| 1729 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.NO_CONTACT, |
| 1730 | ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); |
| 1731 | } |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 1732 | mNoContactDetailsCard.setVisibility(View.VISIBLE); |
| 1733 | mNoContactDetailsCard.setEntryHeaderColor(subHeaderTextColor); |
| 1734 | mNoContactDetailsCard.setColorAndFilter(subHeaderTextColor, greyColorFilter); |
| 1735 | } |
| 1736 | |
| 1737 | /** |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1738 | * Builds the {@link DataItem}s Map out of the Contact. |
| 1739 | * @param data The contact to build the data from. |
| 1740 | * @return A pair containing a list of data items sorted within mimetype and sorted |
| 1741 | * amongst mimetype. The map goes from mimetype string to the sorted list of data items within |
| 1742 | * mimetype |
| 1743 | */ |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1744 | private Cp2DataCardModel generateDataModelFromContact( |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1745 | Contact data) { |
| 1746 | Trace.beginSection("Build data items map"); |
| 1747 | |
| 1748 | final Map<String, List<DataItem>> dataItemsMap = new HashMap<>(); |
Brian Attwell | 8bf96e7 | 2014-06-25 15:46:47 -0700 | [diff] [blame] | 1749 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1750 | final ResolveCache cache = ResolveCache.getInstance(this); |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 1751 | for (RawContact rawContact : data.getRawContacts()) { |
| 1752 | for (DataItem dataItem : rawContact.getDataItems()) { |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1753 | dataItem.setRawContactId(rawContact.getId()); |
| 1754 | |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 1755 | final String mimeType = dataItem.getMimeType(); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1756 | if (mimeType == null) continue; |
| 1757 | |
Chiao Cheng | 47b6f70 | 2012-09-07 17:28:17 -0700 | [diff] [blame] | 1758 | final AccountType accountType = rawContact.getAccountType(this); |
| 1759 | final DataKind dataKind = AccountTypeManager.getInstance(this) |
| 1760 | .getKindOrFallback(accountType, mimeType); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1761 | if (dataKind == null) continue; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 1762 | |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1763 | dataItem.setDataKind(dataKind); |
| 1764 | |
| 1765 | final boolean hasData = !TextUtils.isEmpty(dataItem.buildDataString(this, |
| 1766 | dataKind)); |
| 1767 | |
| 1768 | if (isMimeExcluded(mimeType) || !hasData) continue; |
| 1769 | |
| 1770 | List<DataItem> dataItemListByType = dataItemsMap.get(mimeType); |
| 1771 | if (dataItemListByType == null) { |
| 1772 | dataItemListByType = new ArrayList<>(); |
| 1773 | dataItemsMap.put(mimeType, dataItemListByType); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 1774 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1775 | dataItemListByType.add(dataItem); |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 1776 | } |
| 1777 | } |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 1778 | Trace.endSection(); |
Makoto Onuki | dfe8cc8 | 2012-05-17 18:03:44 -0700 | [diff] [blame] | 1779 | |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1780 | Trace.beginSection("sort within mimetypes"); |
Paul Soulos | 1633933 | 2014-06-24 13:59:56 -0700 | [diff] [blame] | 1781 | /* |
| 1782 | * Sorting is a multi part step. The end result is to a have a sorted list of the most |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1783 | * used data items, one per mimetype. Then, within each mimetype, the list of data items |
| 1784 | * for that type is also sorted, based off of {super primary, primary, times used} in that |
| 1785 | * order. |
Paul Soulos | 1633933 | 2014-06-24 13:59:56 -0700 | [diff] [blame] | 1786 | */ |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1787 | final List<List<DataItem>> dataItemsList = new ArrayList<>(); |
| 1788 | for (List<DataItem> mimeTypeDataItems : dataItemsMap.values()) { |
| 1789 | // Remove duplicate data items |
| 1790 | Collapser.collapseList(mimeTypeDataItems, this); |
| 1791 | // Sort within mimetype |
| 1792 | Collections.sort(mimeTypeDataItems, mWithinMimeTypeDataItemComparator); |
| 1793 | // Add to the list of data item lists |
| 1794 | dataItemsList.add(mimeTypeDataItems); |
| 1795 | } |
| 1796 | Trace.endSection(); |
Paul Soulos | 1633933 | 2014-06-24 13:59:56 -0700 | [diff] [blame] | 1797 | |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1798 | Trace.beginSection("sort amongst mimetypes"); |
| 1799 | // Sort amongst mimetypes to bubble up the top data items for the contact card |
| 1800 | Collections.sort(dataItemsList, mAmongstMimeTypeDataItemComparator); |
| 1801 | Trace.endSection(); |
| 1802 | |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1803 | Trace.beginSection("cp2 data items to entries"); |
| 1804 | |
| 1805 | final List<List<Entry>> contactCardEntries = new ArrayList<>(); |
| 1806 | final List<List<Entry>> aboutCardEntries = buildAboutCardEntries(dataItemsMap); |
| 1807 | final MutableString aboutCardName = new MutableString(); |
| 1808 | |
| 1809 | for (int i = 0; i < dataItemsList.size(); ++i) { |
| 1810 | final List<DataItem> dataItemsByMimeType = dataItemsList.get(i); |
| 1811 | final DataItem topDataItem = dataItemsByMimeType.get(0); |
| 1812 | if (SORTED_ABOUT_CARD_MIMETYPES.contains(topDataItem.getMimeType())) { |
| 1813 | // About card mimetypes are built in buildAboutCardEntries, skip here |
| 1814 | continue; |
| 1815 | } else { |
| 1816 | List<Entry> contactEntries = dataItemsToEntries(dataItemsList.get(i), |
| 1817 | aboutCardName); |
| 1818 | if (contactEntries.size() > 0) { |
| 1819 | contactCardEntries.add(contactEntries); |
| 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | Trace.endSection(); |
| 1825 | |
| 1826 | final Cp2DataCardModel dataModel = new Cp2DataCardModel(); |
| 1827 | dataModel.customAboutCardName = aboutCardName.value; |
| 1828 | dataModel.aboutCardEntries = aboutCardEntries; |
| 1829 | dataModel.contactCardEntries = contactCardEntries; |
| 1830 | dataModel.dataItemsMap = dataItemsMap; |
| 1831 | return dataModel; |
| 1832 | } |
| 1833 | |
| 1834 | /** |
| 1835 | * Class used to hold the About card and Contact cards' data model that gets generated |
| 1836 | * on a background thread. All data is from CP2. |
| 1837 | */ |
| 1838 | private static class Cp2DataCardModel { |
| 1839 | /** |
| 1840 | * A map between a mimetype string and the corresponding list of data items. The data items |
| 1841 | * are in sorted order using mWithinMimeTypeDataItemComparator. |
| 1842 | */ |
| 1843 | public Map<String, List<DataItem>> dataItemsMap; |
| 1844 | public List<List<Entry>> aboutCardEntries; |
| 1845 | public List<List<Entry>> contactCardEntries; |
| 1846 | public String customAboutCardName; |
| 1847 | } |
| 1848 | |
| 1849 | private static class MutableString { |
| 1850 | public String value; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | /** |
| 1854 | * Converts a {@link DataItem} into an {@link ExpandingEntryCardView.Entry} for display. |
| 1855 | * If the {@link ExpandingEntryCardView.Entry} has no visual elements, null is returned. |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1856 | * |
| 1857 | * This runs on a background thread. This is set as static to avoid accidentally adding |
| 1858 | * additional dependencies on unsafe things (like the Activity). |
| 1859 | * |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1860 | * @param dataItem The {@link DataItem} to convert. |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 1861 | * @param secondDataItem A second {@link DataItem} to help build a full entry for some |
| 1862 | * mimetypes |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1863 | * @return The {@link ExpandingEntryCardView.Entry}, or null if no visual elements are present. |
| 1864 | */ |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 1865 | private static Entry dataItemToEntry(DataItem dataItem, DataItem secondDataItem, |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1866 | Context context, Contact contactData, |
| 1867 | final MutableString aboutCardName) { |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1868 | Drawable icon = null; |
| 1869 | String header = null; |
| 1870 | String subHeader = null; |
| 1871 | Drawable subHeaderIcon = null; |
| 1872 | String text = null; |
| 1873 | Drawable textIcon = null; |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1874 | StringBuilder primaryContentDescription = new StringBuilder(); |
Tingting Wang | b6949dc | 2015-11-03 13:17:12 -0800 | [diff] [blame] | 1875 | Spannable phoneContentDescription = null; |
Wenyi Wang | 5da55ff | 2015-11-19 13:22:40 -0800 | [diff] [blame] | 1876 | Spannable smsContentDescription = null; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1877 | Intent intent = null; |
Paul Soulos | 48ebbaa | 2014-07-15 13:11:23 -0700 | [diff] [blame] | 1878 | boolean shouldApplyColor = true; |
Paul Soulos | dd7419d | 2014-07-15 11:22:13 -0700 | [diff] [blame] | 1879 | Drawable alternateIcon = null; |
| 1880 | Intent alternateIntent = null; |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1881 | StringBuilder alternateContentDescription = new StringBuilder(); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1882 | final boolean isEditable = false; |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 1883 | EntryContextMenuInfo entryContextMenuInfo = null; |
Paul Soulos | 48fc912 | 2014-08-26 13:52:36 -0700 | [diff] [blame] | 1884 | Drawable thirdIcon = null; |
| 1885 | Intent thirdIntent = null; |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 1886 | int thirdAction = Entry.ACTION_NONE; |
Paul Soulos | 48fc912 | 2014-08-26 13:52:36 -0700 | [diff] [blame] | 1887 | String thirdContentDescription = null; |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 1888 | Bundle thirdExtras = null; |
Paul Soulos | 48290be | 2014-09-08 13:44:51 -0700 | [diff] [blame] | 1889 | int iconResourceId = 0; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1890 | |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1891 | context = context.getApplicationContext(); |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1892 | final Resources res = context.getResources(); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1893 | DataKind kind = dataItem.getDataKind(); |
| 1894 | |
| 1895 | if (dataItem instanceof ImDataItem) { |
| 1896 | final ImDataItem im = (ImDataItem) dataItem; |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1897 | intent = ContactsUtils.buildImIntent(context, im).first; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1898 | final boolean isEmail = im.isCreatedFromEmail(); |
Paul Soulos | 7de6f85 | 2014-07-28 14:07:28 -0700 | [diff] [blame] | 1899 | final int protocol; |
| 1900 | if (!im.isProtocolValid()) { |
| 1901 | protocol = Im.PROTOCOL_CUSTOM; |
| 1902 | } else { |
| 1903 | protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol(); |
| 1904 | } |
| 1905 | if (protocol == Im.PROTOCOL_CUSTOM) { |
| 1906 | // If the protocol is custom, display the "IM" entry header as well to distinguish |
| 1907 | // this entry from other ones |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1908 | header = res.getString(R.string.header_im_entry); |
| 1909 | subHeader = Im.getProtocolLabel(res, protocol, |
Paul Soulos | 7de6f85 | 2014-07-28 14:07:28 -0700 | [diff] [blame] | 1910 | im.getCustomProtocol()).toString(); |
| 1911 | text = im.getData(); |
| 1912 | } else { |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1913 | header = Im.getProtocolLabel(res, protocol, |
Paul Soulos | 7de6f85 | 2014-07-28 14:07:28 -0700 | [diff] [blame] | 1914 | im.getCustomProtocol()).toString(); |
| 1915 | subHeader = im.getData(); |
| 1916 | } |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 1917 | entryContextMenuInfo = new EntryContextMenuInfo(im.getData(), header, |
| 1918 | dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1919 | } else if (dataItem instanceof OrganizationDataItem) { |
| 1920 | final OrganizationDataItem organization = (OrganizationDataItem) dataItem; |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1921 | header = res.getString(R.string.header_organization_entry); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1922 | subHeader = organization.getCompany(); |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 1923 | entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, |
| 1924 | dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1925 | text = organization.getTitle(); |
| 1926 | } else if (dataItem instanceof NicknameDataItem) { |
| 1927 | final NicknameDataItem nickname = (NicknameDataItem) dataItem; |
| 1928 | // Build nickname entries |
| 1929 | final boolean isNameRawContact = |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1930 | (contactData.getNameRawContactId() == dataItem.getRawContactId()); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1931 | |
| 1932 | final boolean duplicatesTitle = |
| 1933 | isNameRawContact |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1934 | && contactData.getDisplayNameSource() == DisplayNameSources.NICKNAME; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1935 | |
| 1936 | if (!duplicatesTitle) { |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1937 | header = res.getString(R.string.header_nickname_entry); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1938 | subHeader = nickname.getName(); |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 1939 | entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, |
| 1940 | dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1941 | } |
yaolu | 1bd8826 | 2016-08-18 10:29:12 -0700 | [diff] [blame] | 1942 | } else if (dataItem instanceof CustomDataItem) { |
| 1943 | final CustomDataItem customDataItem = (CustomDataItem) dataItem; |
| 1944 | final String summary = customDataItem.getSummary(); |
| 1945 | header = TextUtils.isEmpty(summary) |
| 1946 | ? res.getString(R.string.label_custom_field) : summary; |
| 1947 | subHeader = customDataItem.getContent(); |
| 1948 | entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, |
| 1949 | dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1950 | } else if (dataItem instanceof NoteDataItem) { |
| 1951 | final NoteDataItem note = (NoteDataItem) dataItem; |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1952 | header = res.getString(R.string.header_note_entry); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1953 | subHeader = note.getNote(); |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 1954 | entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, |
| 1955 | dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1956 | } else if (dataItem instanceof WebsiteDataItem) { |
| 1957 | final WebsiteDataItem website = (WebsiteDataItem) dataItem; |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1958 | header = res.getString(R.string.header_website_entry); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1959 | subHeader = website.getUrl(); |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 1960 | entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, |
| 1961 | dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1962 | try { |
Brian Attwell | 3bcf09e | 2014-12-08 16:16:05 -0800 | [diff] [blame] | 1963 | final WebAddress webAddress = new WebAddress(website.buildDataStringForDisplay |
| 1964 | (context, kind)); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1965 | intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString())); |
| 1966 | } catch (final ParseException e) { |
Brian Attwell | 3bcf09e | 2014-12-08 16:16:05 -0800 | [diff] [blame] | 1967 | Log.e(TAG, "Couldn't parse website: " + website.buildDataStringForDisplay( |
| 1968 | context, kind)); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1969 | } |
| 1970 | } else if (dataItem instanceof EventDataItem) { |
| 1971 | final EventDataItem event = (EventDataItem) dataItem; |
Brian Attwell | 3bcf09e | 2014-12-08 16:16:05 -0800 | [diff] [blame] | 1972 | final String dataString = event.buildDataStringForDisplay(context, kind); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1973 | final Calendar cal = DateUtils.parseDate(dataString, false); |
| 1974 | if (cal != null) { |
| 1975 | final Date nextAnniversary = |
| 1976 | DateUtils.getNextAnnualDate(cal); |
| 1977 | final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); |
| 1978 | builder.appendPath("time"); |
| 1979 | ContentUris.appendId(builder, nextAnniversary.getTime()); |
| 1980 | intent = new Intent(Intent.ACTION_VIEW).setData(builder.build()); |
| 1981 | } |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1982 | header = res.getString(R.string.header_event_entry); |
Paul Soulos | f9d5c0e | 2014-07-09 11:25:59 -0700 | [diff] [blame] | 1983 | if (event.hasKindTypeColumn(kind)) { |
Wenyi Wang | c85af28 | 2015-12-21 15:55:32 -0800 | [diff] [blame] | 1984 | subHeader = EventCompat.getTypeLabel(res, event.getKindTypeColumn(kind), |
Paul Soulos | 7de6f85 | 2014-07-28 14:07:28 -0700 | [diff] [blame] | 1985 | event.getLabel()).toString(); |
Paul Soulos | f9d5c0e | 2014-07-09 11:25:59 -0700 | [diff] [blame] | 1986 | } |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 1987 | text = DateUtils.formatDate(context, dataString); |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 1988 | entryContextMenuInfo = new EntryContextMenuInfo(text, header, |
| 1989 | dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1990 | } else if (dataItem instanceof RelationDataItem) { |
| 1991 | final RelationDataItem relation = (RelationDataItem) dataItem; |
Brian Attwell | 3bcf09e | 2014-12-08 16:16:05 -0800 | [diff] [blame] | 1992 | final String dataString = relation.buildDataStringForDisplay(context, kind); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1993 | if (!TextUtils.isEmpty(dataString)) { |
| 1994 | intent = new Intent(Intent.ACTION_SEARCH); |
| 1995 | intent.putExtra(SearchManager.QUERY, dataString); |
| 1996 | intent.setType(Contacts.CONTENT_TYPE); |
| 1997 | } |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 1998 | header = res.getString(R.string.header_relation_entry); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 1999 | subHeader = relation.getName(); |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 2000 | entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, |
| 2001 | dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary()); |
Paul Soulos | f9d5c0e | 2014-07-09 11:25:59 -0700 | [diff] [blame] | 2002 | if (relation.hasKindTypeColumn(kind)) { |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2003 | text = Relation.getTypeLabel(res, |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 2004 | relation.getKindTypeColumn(kind), |
Paul Soulos | f9d5c0e | 2014-07-09 11:25:59 -0700 | [diff] [blame] | 2005 | relation.getLabel()).toString(); |
| 2006 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2007 | } else if (dataItem instanceof PhoneDataItem) { |
| 2008 | final PhoneDataItem phone = (PhoneDataItem) dataItem; |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 2009 | String phoneLabel = null; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2010 | if (!TextUtils.isEmpty(phone.getNumber())) { |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2011 | primaryContentDescription.append(res.getString(R.string.call_other)).append(" "); |
Brian Attwell | 3bcf09e | 2014-12-08 16:16:05 -0800 | [diff] [blame] | 2012 | header = sBidiFormatter.unicodeWrap(phone.buildDataStringForDisplay(context, kind), |
Brian Attwell | c62cc79 | 2014-10-02 12:35:07 -0700 | [diff] [blame] | 2013 | TextDirectionHeuristics.LTR); |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 2014 | entryContextMenuInfo = new EntryContextMenuInfo(header, |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 2015 | res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), |
| 2016 | dataItem.getId(), dataItem.isSuperPrimary()); |
Paul Soulos | f9d5c0e | 2014-07-09 11:25:59 -0700 | [diff] [blame] | 2017 | if (phone.hasKindTypeColumn(kind)) { |
Tingting Wang | 01b3768 | 2015-07-17 14:09:19 -0700 | [diff] [blame] | 2018 | final int kindTypeColumn = phone.getKindTypeColumn(kind); |
| 2019 | final String label = phone.getLabel(); |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 2020 | phoneLabel = label; |
Tingting Wang | 01b3768 | 2015-07-17 14:09:19 -0700 | [diff] [blame] | 2021 | if (kindTypeColumn == Phone.TYPE_CUSTOM && TextUtils.isEmpty(label)) { |
| 2022 | text = ""; |
| 2023 | } else { |
| 2024 | text = Phone.getTypeLabel(res, kindTypeColumn, label).toString(); |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 2025 | phoneLabel= text; |
Tingting Wang | 3df785b | 2015-07-07 16:53:14 -0700 | [diff] [blame] | 2026 | primaryContentDescription.append(text).append(" "); |
| 2027 | } |
Paul Soulos | f9d5c0e | 2014-07-09 11:25:59 -0700 | [diff] [blame] | 2028 | } |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2029 | primaryContentDescription.append(header); |
Tingting Wang | b6949dc | 2015-11-03 13:17:12 -0800 | [diff] [blame] | 2030 | phoneContentDescription = com.android.contacts.common.util.ContactDisplayUtils |
| 2031 | .getTelephoneTtsSpannable(primaryContentDescription.toString(), header); |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2032 | icon = res.getDrawable(R.drawable.ic_phone_24dp); |
Paul Soulos | 48290be | 2014-09-08 13:44:51 -0700 | [diff] [blame] | 2033 | iconResourceId = R.drawable.ic_phone_24dp; |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 2034 | if (PhoneCapabilityTester.isPhone(context)) { |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2035 | intent = CallUtil.getCallIntent(phone.getNumber()); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2036 | intent.putExtra(EXTRA_ACTION_TYPE, ActionType.CALL); |
Paul Soulos | 1633933 | 2014-06-24 13:59:56 -0700 | [diff] [blame] | 2037 | } |
Paul Soulos | dd7419d | 2014-07-15 11:22:13 -0700 | [diff] [blame] | 2038 | alternateIntent = new Intent(Intent.ACTION_SENDTO, |
Jay Shrauner | 1cd88e3 | 2014-09-05 15:37:55 -0700 | [diff] [blame] | 2039 | Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phone.getNumber(), null)); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2040 | alternateIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.SMS); |
Paul Soulos | 48fc912 | 2014-08-26 13:52:36 -0700 | [diff] [blame] | 2041 | |
Walter Jang | 3133a53 | 2016-05-04 17:51:19 -0700 | [diff] [blame] | 2042 | alternateIcon = res.getDrawable(R.drawable.ic_message_24dp_mirrored); |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2043 | alternateContentDescription.append(res.getString(R.string.sms_custom, header)); |
Wenyi Wang | 5da55ff | 2015-11-19 13:22:40 -0800 | [diff] [blame] | 2044 | smsContentDescription = com.android.contacts.common.util.ContactDisplayUtils |
| 2045 | .getTelephoneTtsSpannable(alternateContentDescription.toString(), header); |
Paul Soulos | 48fc912 | 2014-08-26 13:52:36 -0700 | [diff] [blame] | 2046 | |
Tyler Gunn | 0a8f973 | 2015-12-15 15:38:54 -0800 | [diff] [blame] | 2047 | int videoCapability = CallUtil.getVideoCallingAvailability(context); |
| 2048 | boolean isPresenceEnabled = |
| 2049 | (videoCapability & CallUtil.VIDEO_CALLING_PRESENCE) != 0; |
| 2050 | boolean isVideoEnabled = (videoCapability & CallUtil.VIDEO_CALLING_ENABLED) != 0; |
| 2051 | |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 2052 | if (CallUtil.isCallWithSubjectSupported(context)) { |
| 2053 | thirdIcon = res.getDrawable(R.drawable.ic_call_note_white_24dp); |
| 2054 | thirdAction = Entry.ACTION_CALL_WITH_SUBJECT; |
| 2055 | thirdContentDescription = |
| 2056 | res.getString(R.string.call_with_a_note); |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 2057 | // Create a bundle containing the data the call subject dialog requires. |
| 2058 | thirdExtras = new Bundle(); |
| 2059 | thirdExtras.putLong(CallSubjectDialog.ARG_PHOTO_ID, |
| 2060 | contactData.getPhotoId()); |
| 2061 | thirdExtras.putParcelable(CallSubjectDialog.ARG_PHOTO_URI, |
| 2062 | UriUtils.parseUriOrNull(contactData.getPhotoUri())); |
| 2063 | thirdExtras.putParcelable(CallSubjectDialog.ARG_CONTACT_URI, |
| 2064 | contactData.getLookupUri()); |
| 2065 | thirdExtras.putString(CallSubjectDialog.ARG_NAME_OR_NUMBER, |
| 2066 | contactData.getDisplayName()); |
| 2067 | thirdExtras.putBoolean(CallSubjectDialog.ARG_IS_BUSINESS, false); |
| 2068 | thirdExtras.putString(CallSubjectDialog.ARG_NUMBER, |
| 2069 | phone.getNumber()); |
| 2070 | thirdExtras.putString(CallSubjectDialog.ARG_DISPLAY_NUMBER, |
| 2071 | phone.getFormattedPhoneNumber()); |
| 2072 | thirdExtras.putString(CallSubjectDialog.ARG_NUMBER_LABEL, |
| 2073 | phoneLabel); |
Tyler Gunn | 0a8f973 | 2015-12-15 15:38:54 -0800 | [diff] [blame] | 2074 | } else if (isVideoEnabled) { |
| 2075 | // Check to ensure carrier presence indicates the number supports video calling. |
| 2076 | int carrierPresence = dataItem.getCarrierPresence(); |
| 2077 | boolean isPresent = (carrierPresence & Phone.CARRIER_PRESENCE_VT_CAPABLE) != 0; |
| 2078 | |
| 2079 | if ((isPresenceEnabled && isPresent) || !isPresenceEnabled) { |
| 2080 | thirdIcon = res.getDrawable(R.drawable.ic_videocam); |
| 2081 | thirdAction = Entry.ACTION_INTENT; |
| 2082 | thirdIntent = CallUtil.getVideoCallIntent(phone.getNumber(), |
| 2083 | CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2084 | thirdIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.VIDEOCALL); |
Tyler Gunn | 0a8f973 | 2015-12-15 15:38:54 -0800 | [diff] [blame] | 2085 | thirdContentDescription = |
| 2086 | res.getString(R.string.description_video_call); |
| 2087 | } |
Paul Soulos | 48fc912 | 2014-08-26 13:52:36 -0700 | [diff] [blame] | 2088 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2089 | } |
| 2090 | } else if (dataItem instanceof EmailDataItem) { |
| 2091 | final EmailDataItem email = (EmailDataItem) dataItem; |
| 2092 | final String address = email.getData(); |
| 2093 | if (!TextUtils.isEmpty(address)) { |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2094 | primaryContentDescription.append(res.getString(R.string.email_other)).append(" "); |
Jay Shrauner | 1cd88e3 | 2014-09-05 15:37:55 -0700 | [diff] [blame] | 2095 | final Uri mailUri = Uri.fromParts(ContactsUtils.SCHEME_MAILTO, address, null); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2096 | intent = new Intent(Intent.ACTION_SENDTO, mailUri); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2097 | intent.putExtra(EXTRA_ACTION_TYPE, ActionType.EMAIL); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2098 | header = email.getAddress(); |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 2099 | entryContextMenuInfo = new EntryContextMenuInfo(header, |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 2100 | res.getString(R.string.emailLabelsGroup), dataItem.getMimeType(), |
| 2101 | dataItem.getId(), dataItem.isSuperPrimary()); |
Paul Soulos | f9d5c0e | 2014-07-09 11:25:59 -0700 | [diff] [blame] | 2102 | if (email.hasKindTypeColumn(kind)) { |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2103 | text = Email.getTypeLabel(res, email.getKindTypeColumn(kind), |
Paul Soulos | f9d5c0e | 2014-07-09 11:25:59 -0700 | [diff] [blame] | 2104 | email.getLabel()).toString(); |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2105 | primaryContentDescription.append(text).append(" "); |
Paul Soulos | f9d5c0e | 2014-07-09 11:25:59 -0700 | [diff] [blame] | 2106 | } |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2107 | primaryContentDescription.append(header); |
| 2108 | icon = res.getDrawable(R.drawable.ic_email_24dp); |
Paul Soulos | 48290be | 2014-09-08 13:44:51 -0700 | [diff] [blame] | 2109 | iconResourceId = R.drawable.ic_email_24dp; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2110 | } |
| 2111 | } else if (dataItem instanceof StructuredPostalDataItem) { |
| 2112 | StructuredPostalDataItem postal = (StructuredPostalDataItem) dataItem; |
| 2113 | final String postalAddress = postal.getFormattedAddress(); |
| 2114 | if (!TextUtils.isEmpty(postalAddress)) { |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2115 | primaryContentDescription.append(res.getString(R.string.map_other)).append(" "); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2116 | intent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2117 | intent.putExtra(EXTRA_ACTION_TYPE, ActionType.MAP); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2118 | header = postal.getFormattedAddress(); |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 2119 | entryContextMenuInfo = new EntryContextMenuInfo(header, |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 2120 | res.getString(R.string.postalLabelsGroup), dataItem.getMimeType(), |
| 2121 | dataItem.getId(), dataItem.isSuperPrimary()); |
Paul Soulos | f9d5c0e | 2014-07-09 11:25:59 -0700 | [diff] [blame] | 2122 | if (postal.hasKindTypeColumn(kind)) { |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2123 | text = StructuredPostal.getTypeLabel(res, |
Paul Soulos | f9d5c0e | 2014-07-09 11:25:59 -0700 | [diff] [blame] | 2124 | postal.getKindTypeColumn(kind), postal.getLabel()).toString(); |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2125 | primaryContentDescription.append(text).append(" "); |
Paul Soulos | f9d5c0e | 2014-07-09 11:25:59 -0700 | [diff] [blame] | 2126 | } |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2127 | primaryContentDescription.append(header); |
Paul Soulos | 6a4d273 | 2014-07-22 14:22:12 -0700 | [diff] [blame] | 2128 | alternateIntent = |
| 2129 | StructuredPostalUtils.getViewPostalAddressDirectionsIntent(postalAddress); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2130 | alternateIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.DIRECTIONS); |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2131 | alternateIcon = res.getDrawable(R.drawable.ic_directions_24dp); |
| 2132 | alternateContentDescription.append(res.getString( |
| 2133 | R.string.content_description_directions)).append(" ").append(header); |
| 2134 | icon = res.getDrawable(R.drawable.ic_place_24dp); |
Paul Soulos | 48290be | 2014-09-08 13:44:51 -0700 | [diff] [blame] | 2135 | iconResourceId = R.drawable.ic_place_24dp; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2136 | } |
| 2137 | } else if (dataItem instanceof SipAddressDataItem) { |
Brian Attwell | 593e5a7 | 2014-10-22 19:45:28 -0700 | [diff] [blame] | 2138 | final SipAddressDataItem sip = (SipAddressDataItem) dataItem; |
| 2139 | final String address = sip.getSipAddress(); |
| 2140 | if (!TextUtils.isEmpty(address)) { |
| 2141 | primaryContentDescription.append(res.getString(R.string.call_other)).append( |
| 2142 | " "); |
| 2143 | if (PhoneCapabilityTester.isSipPhone(context)) { |
Jay Shrauner | 1cd88e3 | 2014-09-05 15:37:55 -0700 | [diff] [blame] | 2144 | final Uri callUri = Uri.fromParts(PhoneAccount.SCHEME_SIP, address, null); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2145 | intent = CallUtil.getCallIntent(callUri); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2146 | intent.putExtra(EXTRA_ACTION_TYPE, ActionType.SIPCALL); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2147 | } |
Brian Attwell | 593e5a7 | 2014-10-22 19:45:28 -0700 | [diff] [blame] | 2148 | header = address; |
| 2149 | entryContextMenuInfo = new EntryContextMenuInfo(header, |
| 2150 | res.getString(R.string.phoneLabelsGroup), dataItem.getMimeType(), |
| 2151 | dataItem.getId(), dataItem.isSuperPrimary()); |
| 2152 | if (sip.hasKindTypeColumn(kind)) { |
| 2153 | text = SipAddress.getTypeLabel(res, |
| 2154 | sip.getKindTypeColumn(kind), sip.getLabel()).toString(); |
| 2155 | primaryContentDescription.append(text).append(" "); |
| 2156 | } |
| 2157 | primaryContentDescription.append(header); |
| 2158 | icon = res.getDrawable(R.drawable.ic_dialer_sip_black_24dp); |
| 2159 | iconResourceId = R.drawable.ic_dialer_sip_black_24dp; |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2160 | } |
| 2161 | } else if (dataItem instanceof StructuredNameDataItem) { |
Walter Jang | 8025f80 | 2015-02-27 14:18:14 -0800 | [diff] [blame] | 2162 | // If the name is already set and this is not the super primary value then leave the |
| 2163 | // current value. This way we show the super primary value when we are able to. |
| 2164 | if (dataItem.isSuperPrimary() || aboutCardName.value == null |
| 2165 | || aboutCardName.value.isEmpty()) { |
| 2166 | final String givenName = ((StructuredNameDataItem) dataItem).getGivenName(); |
| 2167 | if (!TextUtils.isEmpty(givenName)) { |
| 2168 | aboutCardName.value = res.getString(R.string.about_card_title) + |
| 2169 | " " + givenName; |
| 2170 | } else { |
| 2171 | aboutCardName.value = res.getString(R.string.about_card_title); |
| 2172 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2173 | } |
| 2174 | } else { |
| 2175 | // Custom DataItem |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 2176 | header = dataItem.buildDataStringForDisplay(context, kind); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2177 | text = kind.typeColumn; |
| 2178 | intent = new Intent(Intent.ACTION_VIEW); |
Paul Soulos | 60e5108 | 2014-07-10 12:33:04 -0700 | [diff] [blame] | 2179 | final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, dataItem.getId()); |
| 2180 | intent.setDataAndType(uri, dataItem.getMimeType()); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2181 | intent.putExtra(EXTRA_ACTION_TYPE, ActionType.THIRD_PARTY); |
| 2182 | intent.putExtra(EXTRA_THIRD_PARTY_ACTION, header); |
Paul Soulos | e005566 | 2014-07-10 16:33:08 -0700 | [diff] [blame] | 2183 | |
| 2184 | if (intent != null) { |
| 2185 | final String mimetype = intent.getType(); |
| 2186 | |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2187 | // Build advanced entry for known 3p types. Otherwise default to ResolveCache icon. |
yaolu | 8c3ff2c | 2016-08-18 20:13:40 -0700 | [diff] [blame] | 2188 | if (MIMETYPE_HANGOUTS.equals(mimetype)) { |
| 2189 | // If a secondDataItem is available, use it to build an entry with |
| 2190 | // alternate actions |
| 2191 | if (secondDataItem != null) { |
| 2192 | icon = res.getDrawable(R.drawable.ic_hangout_24dp); |
| 2193 | alternateIcon = res.getDrawable(R.drawable.ic_hangout_video_24dp); |
| 2194 | final HangoutsDataItemModel itemModel = |
| 2195 | new HangoutsDataItemModel(intent, alternateIntent, |
| 2196 | dataItem, secondDataItem, alternateContentDescription, |
| 2197 | header, text, context); |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2198 | |
yaolu | 8c3ff2c | 2016-08-18 20:13:40 -0700 | [diff] [blame] | 2199 | populateHangoutsDataItemModel(itemModel); |
| 2200 | intent = itemModel.intent; |
| 2201 | alternateIntent = itemModel.alternateIntent; |
| 2202 | alternateContentDescription = itemModel.alternateContentDescription; |
| 2203 | header = itemModel.header; |
| 2204 | text = itemModel.text; |
| 2205 | } else { |
| 2206 | if (HANGOUTS_DATA_5_VIDEO.equals(intent.getDataString())) { |
| 2207 | icon = res.getDrawable(R.drawable.ic_hangout_video_24dp); |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2208 | } else { |
yaolu | 8c3ff2c | 2016-08-18 20:13:40 -0700 | [diff] [blame] | 2209 | icon = res.getDrawable(R.drawable.ic_hangout_24dp); |
Paul Soulos | e005566 | 2014-07-10 16:33:08 -0700 | [diff] [blame] | 2210 | } |
yaolu | 8c3ff2c | 2016-08-18 20:13:40 -0700 | [diff] [blame] | 2211 | } |
| 2212 | } else { |
| 2213 | icon = ResolveCache.getInstance(context).getIcon( |
| 2214 | dataItem.getMimeType(), intent); |
| 2215 | // Call mutate to create a new Drawable.ConstantState for color filtering |
| 2216 | if (icon != null) { |
| 2217 | icon.mutate(); |
| 2218 | } |
| 2219 | shouldApplyColor = false; |
| 2220 | |
| 2221 | if (!MIMETYPE_GPLUS_PROFILE.equals(mimetype)) { |
Paul Soulos | 97f2780 | 2014-09-08 13:55:45 -0700 | [diff] [blame] | 2222 | entryContextMenuInfo = new EntryContextMenuInfo(header, mimetype, |
| 2223 | dataItem.getMimeType(), dataItem.getId(), |
| 2224 | dataItem.isSuperPrimary()); |
yaolu | 8c3ff2c | 2016-08-18 20:13:40 -0700 | [diff] [blame] | 2225 | } |
Paul Soulos | e005566 | 2014-07-10 16:33:08 -0700 | [diff] [blame] | 2226 | } |
| 2227 | } |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2230 | if (intent != null) { |
| 2231 | // Do not set the intent is there are no resolves |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 2232 | if (!PhoneCapabilityTester.isIntentRegistered(context, intent)) { |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2233 | intent = null; |
Paul Soulos | 1633933 | 2014-06-24 13:59:56 -0700 | [diff] [blame] | 2234 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2235 | } |
Paul Soulos | 1633933 | 2014-06-24 13:59:56 -0700 | [diff] [blame] | 2236 | |
Paul Soulos | dd7419d | 2014-07-15 11:22:13 -0700 | [diff] [blame] | 2237 | if (alternateIntent != null) { |
| 2238 | // Do not set the alternate intent is there are no resolves |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 2239 | if (!PhoneCapabilityTester.isIntentRegistered(context, alternateIntent)) { |
Paul Soulos | dd7419d | 2014-07-15 11:22:13 -0700 | [diff] [blame] | 2240 | alternateIntent = null; |
Jay Shrauner | f0d04c1 | 2014-09-02 13:44:48 -0700 | [diff] [blame] | 2241 | } else if (TextUtils.isEmpty(alternateContentDescription)) { |
| 2242 | // Attempt to use package manager to find a suitable content description if needed |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2243 | alternateContentDescription.append(getIntentResolveLabel(alternateIntent, context)); |
Paul Soulos | dd7419d | 2014-07-15 11:22:13 -0700 | [diff] [blame] | 2244 | } |
| 2245 | } |
| 2246 | |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2247 | // If the Entry has no visual elements, return null |
| 2248 | if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) && |
| 2249 | subHeaderIcon == null && TextUtils.isEmpty(text) && textIcon == null) { |
| 2250 | return null; |
| 2251 | } |
| 2252 | |
Brian Attwell | fa23894 | 2014-08-12 10:21:28 -0700 | [diff] [blame] | 2253 | // Ignore dataIds from the Me profile. |
Paul Soulos | ea5e0b7 | 2014-07-08 18:09:44 -0700 | [diff] [blame] | 2254 | final int dataId = dataItem.getId() > Integer.MAX_VALUE ? |
| 2255 | -1 : (int) dataItem.getId(); |
| 2256 | |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2257 | return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon, |
Tingting Wang | b6949dc | 2015-11-03 13:17:12 -0800 | [diff] [blame] | 2258 | phoneContentDescription == null |
| 2259 | ? new SpannableString(primaryContentDescription.toString()) |
| 2260 | : phoneContentDescription, |
Walter Jang | 7ce5352 | 2014-10-29 13:26:43 -0700 | [diff] [blame] | 2261 | intent, alternateIcon, alternateIntent, |
Wenyi Wang | 5da55ff | 2015-11-19 13:22:40 -0800 | [diff] [blame] | 2262 | smsContentDescription == null |
| 2263 | ? new SpannableString(alternateContentDescription.toString()) |
| 2264 | : smsContentDescription, |
| 2265 | shouldApplyColor, isEditable, |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 2266 | entryContextMenuInfo, thirdIcon, thirdIntent, thirdContentDescription, thirdAction, |
| 2267 | thirdExtras, iconResourceId); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2268 | } |
| 2269 | |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 2270 | private List<Entry> dataItemsToEntries(List<DataItem> dataItems, |
| 2271 | MutableString aboutCardTitleOut) { |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2272 | // Hangouts and G+ use two data items to create one entry. |
yaolu | 3904fb5 | 2016-08-05 13:32:56 -0700 | [diff] [blame] | 2273 | if (dataItems.get(0).getMimeType().equals(MIMETYPE_GPLUS_PROFILE)) { |
| 2274 | return gPlusDataItemsToEntries(dataItems); |
| 2275 | } else if (dataItems.get(0).getMimeType().equals(MIMETYPE_HANGOUTS)) { |
| 2276 | return hangoutsDataItemsToEntries(dataItems); |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2277 | } else { |
| 2278 | final List<Entry> entries = new ArrayList<>(); |
| 2279 | for (DataItem dataItem : dataItems) { |
| 2280 | final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, |
| 2281 | this, mContactData, aboutCardTitleOut); |
| 2282 | if (entry != null) { |
| 2283 | entries.add(entry); |
| 2284 | } |
| 2285 | } |
| 2286 | return entries; |
| 2287 | } |
| 2288 | } |
| 2289 | |
| 2290 | /** |
yaolu | 3904fb5 | 2016-08-05 13:32:56 -0700 | [diff] [blame] | 2291 | * Put the data items into buckets based on the raw contact id |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2292 | */ |
yaolu | 3904fb5 | 2016-08-05 13:32:56 -0700 | [diff] [blame] | 2293 | private Map<Long, List<DataItem>> dataItemsToBucket(List<DataItem> dataItems) { |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2294 | final Map<Long, List<DataItem>> buckets = new HashMap<>(); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2295 | for (DataItem dataItem : dataItems) { |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2296 | List<DataItem> bucket = buckets.get(dataItem.getRawContactId()); |
| 2297 | if (bucket == null) { |
| 2298 | bucket = new ArrayList<>(); |
| 2299 | buckets.put(dataItem.getRawContactId(), bucket); |
| 2300 | } |
| 2301 | bucket.add(dataItem); |
| 2302 | } |
yaolu | 3904fb5 | 2016-08-05 13:32:56 -0700 | [diff] [blame] | 2303 | return buckets; |
| 2304 | } |
| 2305 | |
| 2306 | /** |
| 2307 | * For G+ entries, a single ExpandingEntryCardView.Entry consists of two data items. This |
| 2308 | * method use only the View profile to build entry. |
| 2309 | */ |
| 2310 | private List<Entry> gPlusDataItemsToEntries(List<DataItem> dataItems) { |
| 2311 | final List<Entry> entries = new ArrayList<>(); |
| 2312 | |
| 2313 | for (List<DataItem> bucket : dataItemsToBucket(dataItems).values()) { |
| 2314 | for (DataItem dataItem : bucket) { |
| 2315 | if (GPLUS_PROFILE_DATA_5_VIEW_PROFILE.equals( |
| 2316 | dataItem.getContentValues().getAsString(Data.DATA5))) { |
| 2317 | final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, |
| 2318 | this, mContactData, /* aboutCardName = */ null); |
| 2319 | if (entry != null) { |
| 2320 | entries.add(entry); |
| 2321 | } |
| 2322 | } |
| 2323 | } |
| 2324 | } |
| 2325 | return entries; |
| 2326 | } |
| 2327 | |
| 2328 | /** |
| 2329 | * For Hangouts entries, a single ExpandingEntryCardView.Entry consists of two data items. This |
| 2330 | * method attempts to build each entry using the two data items if they are available. If there |
| 2331 | * are more or less than two data items, a fall back is used and each data item gets its own |
| 2332 | * entry. |
| 2333 | */ |
| 2334 | private List<Entry> hangoutsDataItemsToEntries(List<DataItem> dataItems) { |
| 2335 | final List<Entry> entries = new ArrayList<>(); |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2336 | |
| 2337 | // Use the buckets to build entries. If a bucket contains two data items, build the special |
| 2338 | // entry, otherwise fall back to the normal entry. |
yaolu | 3904fb5 | 2016-08-05 13:32:56 -0700 | [diff] [blame] | 2339 | for (List<DataItem> bucket : dataItemsToBucket(dataItems).values()) { |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2340 | if (bucket.size() == 2) { |
| 2341 | // Use the pair to build an entry |
| 2342 | final Entry entry = dataItemToEntry(bucket.get(0), |
| 2343 | /* secondDataItem = */ bucket.get(1), this, mContactData, |
| 2344 | /* aboutCardName = */ null); |
| 2345 | if (entry != null) { |
| 2346 | entries.add(entry); |
| 2347 | } |
| 2348 | } else { |
| 2349 | for (DataItem dataItem : bucket) { |
| 2350 | final Entry entry = dataItemToEntry(dataItem, /* secondDataItem = */ null, |
| 2351 | this, mContactData, /* aboutCardName = */ null); |
| 2352 | if (entry != null) { |
| 2353 | entries.add(entry); |
| 2354 | } |
| 2355 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2356 | } |
| 2357 | } |
| 2358 | return entries; |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2361 | /** |
yaolu | 3904fb5 | 2016-08-05 13:32:56 -0700 | [diff] [blame] | 2362 | * Used for statically passing around Hangouts data items and entry fields to |
| 2363 | * populateHangoutsDataItemModel. |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2364 | */ |
yaolu | 3904fb5 | 2016-08-05 13:32:56 -0700 | [diff] [blame] | 2365 | private static final class HangoutsDataItemModel { |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2366 | public Intent intent; |
| 2367 | public Intent alternateIntent; |
| 2368 | public DataItem dataItem; |
| 2369 | public DataItem secondDataItem; |
| 2370 | public StringBuilder alternateContentDescription; |
| 2371 | public String header; |
| 2372 | public String text; |
| 2373 | public Context context; |
| 2374 | |
yaolu | 3904fb5 | 2016-08-05 13:32:56 -0700 | [diff] [blame] | 2375 | public HangoutsDataItemModel(Intent intent, Intent alternateIntent, DataItem dataItem, |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2376 | DataItem secondDataItem, StringBuilder alternateContentDescription, String header, |
| 2377 | String text, Context context) { |
| 2378 | this.intent = intent; |
| 2379 | this.alternateIntent = alternateIntent; |
| 2380 | this.dataItem = dataItem; |
| 2381 | this.secondDataItem = secondDataItem; |
| 2382 | this.alternateContentDescription = alternateContentDescription; |
| 2383 | this.header = header; |
| 2384 | this.text = text; |
| 2385 | this.context = context; |
| 2386 | } |
| 2387 | } |
| 2388 | |
yaolu | 3904fb5 | 2016-08-05 13:32:56 -0700 | [diff] [blame] | 2389 | private static void populateHangoutsDataItemModel( |
| 2390 | HangoutsDataItemModel dataModel) { |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2391 | final Intent secondIntent = new Intent(Intent.ACTION_VIEW); |
| 2392 | secondIntent.setDataAndType(ContentUris.withAppendedId(Data.CONTENT_URI, |
| 2393 | dataModel.secondDataItem.getId()), dataModel.secondDataItem.getMimeType()); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2394 | final String secondHeader= dataModel.secondDataItem.buildDataStringForDisplay( |
| 2395 | dataModel.context, dataModel.secondDataItem.getDataKind()); |
| 2396 | secondIntent.putExtra(EXTRA_ACTION_TYPE, ActionType.THIRD_PARTY); |
| 2397 | secondIntent.putExtra(EXTRA_THIRD_PARTY_ACTION, secondHeader); |
| 2398 | |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2399 | // There is no guarantee the order the data items come in. Second |
| 2400 | // data item does not necessarily mean it's the alternate. |
yaolu | 3904fb5 | 2016-08-05 13:32:56 -0700 | [diff] [blame] | 2401 | // Hangouts video should be alternate. Swap if needed |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2402 | if (HANGOUTS_DATA_5_VIDEO.equals( |
yaolu | 3904fb5 | 2016-08-05 13:32:56 -0700 | [diff] [blame] | 2403 | dataModel.dataItem.getContentValues().getAsString(Data.DATA5))) { |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2404 | dataModel.alternateIntent = dataModel.intent; |
| 2405 | dataModel.alternateContentDescription = new StringBuilder(dataModel.header); |
| 2406 | |
| 2407 | dataModel.intent = secondIntent; |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2408 | dataModel.header = secondHeader; |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2409 | dataModel.text = dataModel.secondDataItem.getDataKind().typeColumn; |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2410 | |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2411 | } else if (HANGOUTS_DATA_5_MESSAGE.equals( |
yaolu | 3904fb5 | 2016-08-05 13:32:56 -0700 | [diff] [blame] | 2412 | dataModel.dataItem.getContentValues().getAsString(Data.DATA5))) { |
Paul Soulos | 6a2a1a7 | 2014-10-10 15:52:56 -0700 | [diff] [blame] | 2413 | dataModel.alternateIntent = secondIntent; |
| 2414 | dataModel.alternateContentDescription = new StringBuilder( |
| 2415 | dataModel.secondDataItem.buildDataStringForDisplay(dataModel.context, |
| 2416 | dataModel.secondDataItem.getDataKind())); |
| 2417 | } |
| 2418 | } |
| 2419 | |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 2420 | private static String getIntentResolveLabel(Intent intent, Context context) { |
| 2421 | final List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, |
Paul Soulos | dd7419d | 2014-07-15 11:22:13 -0700 | [diff] [blame] | 2422 | PackageManager.MATCH_DEFAULT_ONLY); |
| 2423 | |
| 2424 | // Pick first match, otherwise best found |
| 2425 | ResolveInfo bestResolve = null; |
| 2426 | final int size = matches.size(); |
| 2427 | if (size == 1) { |
| 2428 | bestResolve = matches.get(0); |
| 2429 | } else if (size > 1) { |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 2430 | bestResolve = ResolveCache.getInstance(context).getBestResolve(intent, matches); |
Paul Soulos | dd7419d | 2014-07-15 11:22:13 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | if (bestResolve == null) { |
| 2434 | return null; |
| 2435 | } |
| 2436 | |
Brian Attwell | 6bb0134 | 2014-08-20 23:16:00 -0700 | [diff] [blame] | 2437 | return String.valueOf(bestResolve.loadLabel(context.getPackageManager())); |
Paul Soulos | dd7419d | 2014-07-15 11:22:13 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 2440 | /** |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 2441 | * Asynchronously extract the most vibrant color from the PhotoView. Once extracted, |
| 2442 | * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms |
| 2443 | * on a Nexus 5. |
| 2444 | */ |
| 2445 | private void extractAndApplyTintFromPhotoViewAsynchronously() { |
| 2446 | if (mScroller == null) { |
| 2447 | return; |
| 2448 | } |
| 2449 | final Drawable imageViewDrawable = mPhotoView.getDrawable(); |
Brian Attwell | faf9739 | 2014-07-10 18:32:30 -0700 | [diff] [blame] | 2450 | new AsyncTask<Void, Void, MaterialPalette>() { |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 2451 | @Override |
Brian Attwell | faf9739 | 2014-07-10 18:32:30 -0700 | [diff] [blame] | 2452 | protected MaterialPalette doInBackground(Void... params) { |
| 2453 | |
Jay Shrauner | 929a62f | 2014-11-13 12:03:50 -0800 | [diff] [blame] | 2454 | if (imageViewDrawable instanceof BitmapDrawable && mContactData != null |
Brian Attwell | 95c268e | 2014-08-26 22:04:15 -0700 | [diff] [blame] | 2455 | && mContactData.getThumbnailPhotoBinaryData() != null |
| 2456 | && mContactData.getThumbnailPhotoBinaryData().length > 0) { |
| 2457 | // Perform the color analysis on the thumbnail instead of the full sized |
| 2458 | // image, so that our results will be as similar as possible to the Bugle |
| 2459 | // app. |
| 2460 | final Bitmap bitmap = BitmapFactory.decodeByteArray( |
| 2461 | mContactData.getThumbnailPhotoBinaryData(), 0, |
| 2462 | mContactData.getThumbnailPhotoBinaryData().length); |
| 2463 | try { |
| 2464 | final int primaryColor = colorFromBitmap(bitmap); |
| 2465 | if (primaryColor != 0) { |
| 2466 | return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor( |
| 2467 | primaryColor); |
| 2468 | } |
| 2469 | } finally { |
| 2470 | bitmap.recycle(); |
Brian Attwell | faf9739 | 2014-07-10 18:32:30 -0700 | [diff] [blame] | 2471 | } |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 2472 | } |
| 2473 | if (imageViewDrawable instanceof LetterTileDrawable) { |
Brian Attwell | faf9739 | 2014-07-10 18:32:30 -0700 | [diff] [blame] | 2474 | final int primaryColor = ((LetterTileDrawable) imageViewDrawable).getColor(); |
Brian Attwell | a3859ed | 2014-07-15 13:51:55 -0700 | [diff] [blame] | 2475 | return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(primaryColor); |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 2476 | } |
Brian Attwell | a3859ed | 2014-07-15 13:51:55 -0700 | [diff] [blame] | 2477 | return MaterialColorMapUtils.getDefaultPrimaryAndSecondaryColors(getResources()); |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
| 2480 | @Override |
Brian Attwell | faf9739 | 2014-07-10 18:32:30 -0700 | [diff] [blame] | 2481 | protected void onPostExecute(MaterialPalette palette) { |
| 2482 | super.onPostExecute(palette); |
Brian Attwell | 8571dd3 | 2014-06-23 23:29:10 -0700 | [diff] [blame] | 2483 | if (mHasComputedThemeColor) { |
| 2484 | // If we had previously computed a theme color from the contact photo, |
| 2485 | // then do not update the theme color. Changing the theme color several |
| 2486 | // seconds after QC has started, as a result of an updated/upgraded photo, |
| 2487 | // is a jarring experience. On the other hand, changing the theme color after |
| 2488 | // a rotation or onNewIntent() is perfectly fine. |
| 2489 | return; |
| 2490 | } |
| 2491 | // Check that the Photo has not changed. If it has changed, the new tint |
| 2492 | // color needs to be extracted |
| 2493 | if (imageViewDrawable == mPhotoView.getDrawable()) { |
| 2494 | mHasComputedThemeColor = true; |
Brian Attwell | faf9739 | 2014-07-10 18:32:30 -0700 | [diff] [blame] | 2495 | setThemeColor(palette); |
Wenyi Wang | 1d86a67 | 2016-01-28 17:37:10 -0800 | [diff] [blame] | 2496 | // update color and photo in suggestion card |
| 2497 | onAggregationSuggestionChange(); |
Brian Attwell | 31b2d42 | 2014-06-05 00:14:58 -0700 | [diff] [blame] | 2498 | } |
| 2499 | } |
| 2500 | }.execute(); |
| 2501 | } |
| 2502 | |
Brian Attwell | faf9739 | 2014-07-10 18:32:30 -0700 | [diff] [blame] | 2503 | private void setThemeColor(MaterialPalette palette) { |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 2504 | // If the color is invalid, use the predefined default |
Brian Attwell | 8e29faf | 2015-01-21 10:22:40 -0800 | [diff] [blame] | 2505 | mColorFilterColor = palette.mPrimaryColor; |
| 2506 | mScroller.setHeaderTintColor(mColorFilterColor); |
Brian Attwell | faf9739 | 2014-07-10 18:32:30 -0700 | [diff] [blame] | 2507 | mStatusBarColor = palette.mSecondaryColor; |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 2508 | updateStatusBarColor(); |
Brian Attwell | 8571dd3 | 2014-06-23 23:29:10 -0700 | [diff] [blame] | 2509 | |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 2510 | mColorFilter = |
Brian Attwell | 8e29faf | 2015-01-21 10:22:40 -0800 | [diff] [blame] | 2511 | new PorterDuffColorFilter(mColorFilterColor, PorterDuff.Mode.SRC_ATOP); |
| 2512 | mContactCard.setColorAndFilter(mColorFilterColor, mColorFilter); |
| 2513 | mRecentCard.setColorAndFilter(mColorFilterColor, mColorFilter); |
| 2514 | mAboutCard.setColorAndFilter(mColorFilterColor, mColorFilter); |
Gary Mai | d1d8a7a | 2016-06-07 14:46:58 -0700 | [diff] [blame] | 2515 | if (mShouldShowSuggestions) { |
| 2516 | mSuggestionsCancelButton.setTextColor(mColorFilterColor); |
| 2517 | } |
Brian Attwell | 9b889e6 | 2014-06-23 18:25:32 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 2520 | private void updateStatusBarColor() { |
Wenyi Wang | 4c3d3e2 | 2015-12-17 14:30:02 -0800 | [diff] [blame] | 2521 | if (mScroller == null || !CompatUtils.isLollipopCompatible()) { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 2522 | return; |
| 2523 | } |
| 2524 | final int desiredStatusBarColor; |
| 2525 | // Only use a custom status bar color if QuickContacts touches the top of the viewport. |
| 2526 | if (mScroller.getScrollNeededToBeFullScreen() <= 0) { |
| 2527 | desiredStatusBarColor = mStatusBarColor; |
| 2528 | } else { |
| 2529 | desiredStatusBarColor = Color.TRANSPARENT; |
| 2530 | } |
| 2531 | // Animate to the new color. |
Brian Attwell | 847bf2c | 2014-07-24 13:59:27 -0700 | [diff] [blame] | 2532 | final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor", |
| 2533 | getWindow().getStatusBarColor(), desiredStatusBarColor); |
| 2534 | animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION); |
| 2535 | animation.setEvaluator(new ArgbEvaluator()); |
| 2536 | animation.start(); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | private int colorFromBitmap(Bitmap bitmap) { |
| 2540 | // Author of Palette recommends using 24 colors when analyzing profile photos. |
| 2541 | final int NUMBER_OF_PALETTE_COLORS = 24; |
| 2542 | final Palette palette = Palette.generate(bitmap, NUMBER_OF_PALETTE_COLORS); |
Brian Attwell | a0f20f7 | 2014-07-07 11:51:52 -0700 | [diff] [blame] | 2543 | if (palette != null && palette.getVibrantSwatch() != null) { |
| 2544 | return palette.getVibrantSwatch().getRgb(); |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 2545 | } |
| 2546 | return 0; |
| 2547 | } |
| 2548 | |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2549 | private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) { |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2550 | final List<Entry> entries = new ArrayList<>(); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2551 | for (ContactInteraction interaction : interactions) { |
Brian Attwell | ed18828 | 2015-02-11 14:12:41 -0800 | [diff] [blame] | 2552 | if (interaction == null) { |
| 2553 | continue; |
| 2554 | } |
Paul Soulos | ea5e0b7 | 2014-07-08 18:09:44 -0700 | [diff] [blame] | 2555 | entries.add(new Entry(/* id = */ -1, |
| 2556 | interaction.getIcon(this), |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2557 | interaction.getViewHeader(this), |
| 2558 | interaction.getViewBody(this), |
| 2559 | interaction.getBodyIcon(this), |
| 2560 | interaction.getViewFooter(this), |
| 2561 | interaction.getFooterIcon(this), |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 2562 | interaction.getContentDescription(this), |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2563 | interaction.getIntent(), |
Paul Soulos | dd7419d | 2014-07-15 11:22:13 -0700 | [diff] [blame] | 2564 | /* alternateIcon = */ null, |
| 2565 | /* alternateIntent = */ null, |
| 2566 | /* alternateContentDescription = */ null, |
Paul Soulos | 48ebbaa | 2014-07-15 13:11:23 -0700 | [diff] [blame] | 2567 | /* shouldApplyColor = */ true, |
Paul Soulos | 2a4207f | 2014-07-31 17:09:05 -0700 | [diff] [blame] | 2568 | /* isEditable = */ false, |
Paul Soulos | 48fc912 | 2014-08-26 13:52:36 -0700 | [diff] [blame] | 2569 | /* EntryContextMenuInfo = */ null, |
| 2570 | /* thirdIcon = */ null, |
| 2571 | /* thirdIntent = */ null, |
Paul Soulos | 48290be | 2014-09-08 13:44:51 -0700 | [diff] [blame] | 2572 | /* thirdContentDescription = */ null, |
Tyler Gunn | 5f87e92 | 2015-08-05 14:24:52 -0700 | [diff] [blame] | 2573 | /* thirdAction = */ Entry.ACTION_NONE, |
| 2574 | /* thirdActionExtras = */ null, |
Paul Soulos | 48290be | 2014-09-08 13:44:51 -0700 | [diff] [blame] | 2575 | interaction.getIconResourceId())); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2576 | } |
| 2577 | return entries; |
| 2578 | } |
| 2579 | |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2580 | private final LoaderCallbacks<Contact> mLoaderContactCallbacks = |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 2581 | new LoaderCallbacks<Contact>() { |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 2582 | @Override |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 2583 | public void onLoaderReset(Loader<Contact> loader) { |
Paul Soulos | 405ae40 | 2014-07-14 16:16:36 -0700 | [diff] [blame] | 2584 | mContactData = null; |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | @Override |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 2588 | public void onLoadFinished(Loader<Contact> loader, Contact data) { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 2589 | Trace.beginSection("onLoadFinished()"); |
Brian Attwell | 930da3a | 2014-10-16 21:01:21 -0700 | [diff] [blame] | 2590 | try { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 2591 | |
Brian Attwell | 930da3a | 2014-10-16 21:01:21 -0700 | [diff] [blame] | 2592 | if (isFinishing()) { |
| 2593 | return; |
| 2594 | } |
| 2595 | if (data.isError()) { |
Jay Shrauner | 02ecc3f | 2014-12-12 11:29:16 -0800 | [diff] [blame] | 2596 | // This means either the contact is invalid or we had an |
| 2597 | // internal error such as an acore crash. |
| 2598 | Log.i(TAG, "Failed to load contact: " + ((ContactLoader)loader).getLookupUri()); |
| 2599 | Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, |
| 2600 | Toast.LENGTH_LONG).show(); |
| 2601 | finish(); |
| 2602 | return; |
Brian Attwell | 930da3a | 2014-10-16 21:01:21 -0700 | [diff] [blame] | 2603 | } |
| 2604 | if (data.isNotFound()) { |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 2605 | Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri()); |
| 2606 | Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage, |
| 2607 | Toast.LENGTH_LONG).show(); |
Brian Attwell | 930da3a | 2014-10-16 21:01:21 -0700 | [diff] [blame] | 2608 | finish(); |
| 2609 | return; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 2610 | } |
Brian Attwell | 930da3a | 2014-10-16 21:01:21 -0700 | [diff] [blame] | 2611 | |
| 2612 | bindContactData(data); |
| 2613 | |
| 2614 | } finally { |
| 2615 | Trace.endSection(); |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 2616 | } |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | @Override |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 2620 | public Loader<Contact> onCreateLoader(int id, Bundle args) { |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 2621 | if (mLookupUri == null) { |
| 2622 | Log.wtf(TAG, "Lookup uri wasn't initialized. Loader was started too early"); |
| 2623 | } |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 2624 | // Load all contact data. We need loadGroupMetaData=true to determine whether the |
| 2625 | // contact is invisible. If it is, we need to display an "Add to Contacts" MenuItem. |
Yorke Lee | b2b435a | 2012-11-12 16:47:06 -0800 | [diff] [blame] | 2626 | return new ContactLoader(getApplicationContext(), mLookupUri, |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 2627 | true /*loadGroupMetaData*/, false /*loadInvitableAccountTypes*/, |
Brian Attwell | 8571dd3 | 2014-06-23 23:29:10 -0700 | [diff] [blame] | 2628 | true /*postViewNotification*/, true /*computeFormattedPhoneNumber*/); |
Daniel Lehmann | cb8d73f | 2011-12-16 17:39:50 +0200 | [diff] [blame] | 2629 | } |
| 2630 | }; |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2631 | |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 2632 | @Override |
| 2633 | public void onBackPressed() { |
Tingting Wang | ac9596e | 2016-08-02 22:24:24 -0700 | [diff] [blame] | 2634 | final int previousScreenType = getIntent().getIntExtra |
| 2635 | (EXTRA_PREVIOUS_SCREEN_TYPE, ScreenType.UNKNOWN); |
| 2636 | if ((previousScreenType == ScreenType.ALL_CONTACTS |
| 2637 | || previousScreenType == ScreenType.FAVORITES) |
| 2638 | && !SharedPreferenceUtil.getHamburgerPromoTriggerActionHappenedBefore(this)) { |
| 2639 | SharedPreferenceUtil.setHamburgerPromoTriggerActionHappenedBefore(this); |
| 2640 | } |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 2641 | if (mScroller != null) { |
Brian Attwell | 8477eaf | 2014-06-18 15:39:50 -0700 | [diff] [blame] | 2642 | if (!mIsExitAnimationInProgress) { |
| 2643 | mScroller.scrollOffBottom(); |
| 2644 | } |
Brian Attwell | b7e4364 | 2014-06-02 14:33:04 -0700 | [diff] [blame] | 2645 | } else { |
| 2646 | super.onBackPressed(); |
| 2647 | } |
| 2648 | } |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2649 | |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 2650 | @Override |
| 2651 | public void finish() { |
| 2652 | super.finish(); |
| 2653 | |
| 2654 | // override transitions to skip the standard window animations |
| 2655 | overridePendingTransition(0, 0); |
| 2656 | } |
| 2657 | |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2658 | private final LoaderCallbacks<List<ContactInteraction>> mLoaderInteractionsCallbacks = |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2659 | new LoaderCallbacks<List<ContactInteraction>>() { |
| 2660 | |
| 2661 | @Override |
| 2662 | public Loader<List<ContactInteraction>> onCreateLoader(int id, Bundle args) { |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2663 | Loader<List<ContactInteraction>> loader = null; |
| 2664 | switch (id) { |
| 2665 | case LOADER_SMS_ID: |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2666 | loader = new SmsInteractionsLoader( |
| 2667 | QuickContactActivity.this, |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 2668 | args.getStringArray(KEY_LOADER_EXTRA_PHONES), |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2669 | MAX_SMS_RETRIEVE); |
| 2670 | break; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 2671 | case LOADER_CALENDAR_ID: |
Paul Soulos | ae4cafe | 2014-07-09 14:11:03 -0700 | [diff] [blame] | 2672 | final String[] emailsArray = args.getStringArray(KEY_LOADER_EXTRA_EMAILS); |
| 2673 | List<String> emailsList = null; |
| 2674 | if (emailsArray != null) { |
| 2675 | emailsList = Arrays.asList(args.getStringArray(KEY_LOADER_EXTRA_EMAILS)); |
| 2676 | } |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 2677 | loader = new CalendarInteractionsLoader( |
| 2678 | QuickContactActivity.this, |
Paul Soulos | ae4cafe | 2014-07-09 14:11:03 -0700 | [diff] [blame] | 2679 | emailsList, |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 2680 | MAX_FUTURE_CALENDAR_RETRIEVE, |
| 2681 | MAX_PAST_CALENDAR_RETRIEVE, |
| 2682 | FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR, |
| 2683 | PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR); |
| 2684 | break; |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 2685 | case LOADER_CALL_LOG_ID: |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 2686 | loader = new CallLogInteractionsLoader( |
| 2687 | QuickContactActivity.this, |
| 2688 | args.getStringArray(KEY_LOADER_EXTRA_PHONES), |
guanxiongliu | c7a4b9c | 2016-04-30 20:19:21 -0700 | [diff] [blame] | 2689 | args.getStringArray(KEY_LOADER_EXTRA_SIP_NUMBERS), |
Paul Soulos | ab84044 | 2014-06-17 14:08:40 -0700 | [diff] [blame] | 2690 | MAX_CALL_LOG_RETRIEVE); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2691 | } |
| 2692 | return loader; |
| 2693 | } |
| 2694 | |
| 2695 | @Override |
| 2696 | public void onLoadFinished(Loader<List<ContactInteraction>> loader, |
| 2697 | List<ContactInteraction> data) { |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2698 | mRecentLoaderResults.put(loader.getId(), data); |
| 2699 | |
| 2700 | if (isAllRecentDataLoaded()) { |
| 2701 | bindRecentData(); |
| 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | @Override |
| 2706 | public void onLoaderReset(Loader<List<ContactInteraction>> loader) { |
| 2707 | mRecentLoaderResults.remove(loader.getId()); |
| 2708 | } |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2709 | }; |
| 2710 | |
| 2711 | private boolean isAllRecentDataLoaded() { |
| 2712 | return mRecentLoaderResults.size() == mRecentLoaderIds.length; |
| 2713 | } |
| 2714 | |
| 2715 | private void bindRecentData() { |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2716 | final List<ContactInteraction> allInteractions = new ArrayList<>(); |
Brian Attwell | 30e1ef1 | 2014-09-02 15:49:20 -0700 | [diff] [blame] | 2717 | final List<List<Entry>> interactionsWrapper = new ArrayList<>(); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2718 | |
Brian Attwell | ed18828 | 2015-02-11 14:12:41 -0800 | [diff] [blame] | 2719 | // Serialize mRecentLoaderResults into a single list. This should be done on the main |
| 2720 | // thread to avoid races against mRecentLoaderResults edits. |
| 2721 | for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) { |
| 2722 | allInteractions.addAll(loaderInteractions); |
| 2723 | } |
| 2724 | |
Brian Attwell | 30e1ef1 | 2014-09-02 15:49:20 -0700 | [diff] [blame] | 2725 | mRecentDataTask = new AsyncTask<Void, Void, Void>() { |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2726 | @Override |
Brian Attwell | 30e1ef1 | 2014-09-02 15:49:20 -0700 | [diff] [blame] | 2727 | protected Void doInBackground(Void... params) { |
| 2728 | Trace.beginSection("sort recent loader results"); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2729 | |
Brian Attwell | 30e1ef1 | 2014-09-02 15:49:20 -0700 | [diff] [blame] | 2730 | // Sort the interactions by most recent |
| 2731 | Collections.sort(allInteractions, new Comparator<ContactInteraction>() { |
| 2732 | @Override |
| 2733 | public int compare(ContactInteraction a, ContactInteraction b) { |
Brian Attwell | ed18828 | 2015-02-11 14:12:41 -0800 | [diff] [blame] | 2734 | if (a == null && b == null) { |
| 2735 | return 0; |
| 2736 | } |
| 2737 | if (a == null) { |
| 2738 | return 1; |
| 2739 | } |
| 2740 | if (b == null) { |
| 2741 | return -1; |
| 2742 | } |
| 2743 | if (a.getInteractionDate() > b.getInteractionDate()) { |
| 2744 | return -1; |
| 2745 | } |
| 2746 | if (a.getInteractionDate() == b.getInteractionDate()) { |
| 2747 | return 0; |
| 2748 | } |
| 2749 | return 1; |
Brian Attwell | 30e1ef1 | 2014-09-02 15:49:20 -0700 | [diff] [blame] | 2750 | } |
| 2751 | }); |
| 2752 | |
| 2753 | Trace.endSection(); |
| 2754 | Trace.beginSection("contactInteractionsToEntries"); |
| 2755 | |
| 2756 | // Wrap each interaction in its own list so that an icon is displayed for each entry |
| 2757 | for (Entry contactInteraction : contactInteractionsToEntries(allInteractions)) { |
| 2758 | List<Entry> entryListWrapper = new ArrayList<>(1); |
| 2759 | entryListWrapper.add(contactInteraction); |
| 2760 | interactionsWrapper.add(entryListWrapper); |
| 2761 | } |
| 2762 | |
| 2763 | Trace.endSection(); |
| 2764 | return null; |
| 2765 | } |
| 2766 | |
| 2767 | @Override |
| 2768 | protected void onPostExecute(Void aVoid) { |
| 2769 | super.onPostExecute(aVoid); |
| 2770 | Trace.beginSection("initialize recents card"); |
| 2771 | |
| 2772 | if (allInteractions.size() > 0) { |
| 2773 | mRecentCard.initialize(interactionsWrapper, |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2774 | /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN, |
Paul Soulos | c8e2a91 | 2014-07-21 14:52:20 -0700 | [diff] [blame] | 2775 | /* isExpanded = */ mRecentCard.isExpanded(), /* isAlwaysExpanded = */ false, |
Brian Attwell | 30e1ef1 | 2014-09-02 15:49:20 -0700 | [diff] [blame] | 2776 | mExpandingEntryCardViewListener, mScroller); |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2777 | if (mRecentCard.getVisibility() == View.GONE && mShouldLog) { |
| 2778 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.RECENT, |
| 2779 | ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); |
| 2780 | } |
Brian Attwell | 30e1ef1 | 2014-09-02 15:49:20 -0700 | [diff] [blame] | 2781 | mRecentCard.setVisibility(View.VISIBLE); |
| 2782 | } |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2783 | |
Brian Attwell | 30e1ef1 | 2014-09-02 15:49:20 -0700 | [diff] [blame] | 2784 | Trace.endSection(); |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 2785 | Trace.beginSection("initialize permission explanation card"); |
| 2786 | |
guanxiongliu | 8e56edf | 2016-07-14 13:48:55 -0700 | [diff] [blame] | 2787 | final Drawable historyIcon = VectorDrawableCompat.create( |
| 2788 | getResources(), R.drawable.ic_history_24dp, null); |
| 2789 | |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 2790 | final Entry permissionExplanationEntry = new Entry(CARD_ENTRY_ID_REQUEST_PERMISSION, |
| 2791 | historyIcon, getString(R.string.permission_explanation_header), |
| 2792 | mPermissionExplanationCardSubHeader, /* subHeaderIcon = */ null, |
| 2793 | /* text = */ null, /* textIcon = */ null, |
| 2794 | /* primaryContentDescription = */ null, getIntent(), |
| 2795 | /* alternateIcon = */ null, /* alternateIntent = */ null, |
| 2796 | /* alternateContentDescription = */ null, /* shouldApplyColor = */ true, |
| 2797 | /* isEditable = */ false, /* EntryContextMenuInfo = */ null, |
| 2798 | /* thirdIcon = */ null, /* thirdIntent = */ null, |
| 2799 | /* thirdContentDescription = */ null, /* thirdAction = */ Entry.ACTION_NONE, |
| 2800 | /* thirdExtras = */ null, R.drawable.ic_history_24dp); |
| 2801 | |
| 2802 | final List<List<Entry>> permissionExplanationEntries = new ArrayList<>(); |
| 2803 | permissionExplanationEntries.add(new ArrayList<Entry>()); |
| 2804 | permissionExplanationEntries.get(0).add(permissionExplanationEntry); |
| 2805 | |
| 2806 | final int subHeaderTextColor = getResources().getColor(android.R.color.white); |
| 2807 | final PorterDuffColorFilter whiteColorFilter = |
| 2808 | new PorterDuffColorFilter(subHeaderTextColor, PorterDuff.Mode.SRC_ATOP); |
| 2809 | |
| 2810 | mPermissionExplanationCard.initialize(permissionExplanationEntries, |
| 2811 | /* numInitialVisibleEntries = */ 1, |
| 2812 | /* isExpanded = */ true, |
| 2813 | /* isAlwaysExpanded = */ true, |
| 2814 | /* listener = */ null, |
| 2815 | mScroller); |
| 2816 | |
| 2817 | mPermissionExplanationCard.setColorAndFilter(subHeaderTextColor, whiteColorFilter); |
| 2818 | mPermissionExplanationCard.setBackgroundColor(mColorFilterColor); |
| 2819 | mPermissionExplanationCard.setEntryHeaderColor(subHeaderTextColor); |
| 2820 | mPermissionExplanationCard.setEntrySubHeaderColor(subHeaderTextColor); |
| 2821 | |
| 2822 | if (mShouldShowPermissionExplanation) { |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2823 | if (mPermissionExplanationCard.getVisibility() == View.GONE |
| 2824 | && mShouldLog) { |
| 2825 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.PERMISSION, |
| 2826 | ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); |
| 2827 | } |
guanxiongliu | 04a1936 | 2016-05-18 14:38:51 -0700 | [diff] [blame] | 2828 | mPermissionExplanationCard.setVisibility(View.VISIBLE); |
| 2829 | } else { |
| 2830 | mPermissionExplanationCard.setVisibility(View.GONE); |
| 2831 | } |
| 2832 | |
| 2833 | Trace.endSection(); |
Brian Attwell | 30e1ef1 | 2014-09-02 15:49:20 -0700 | [diff] [blame] | 2834 | |
| 2835 | // About card is initialized along with the contact card, but since it appears after |
| 2836 | // the recent card in the UI, we hold off until making it visible until the recent |
| 2837 | // card is also ready to avoid stuttering. |
| 2838 | if (mAboutCard.shouldShow()) { |
| 2839 | mAboutCard.setVisibility(View.VISIBLE); |
| 2840 | } else { |
| 2841 | mAboutCard.setVisibility(View.GONE); |
| 2842 | } |
| 2843 | mRecentDataTask = null; |
| 2844 | } |
| 2845 | }; |
| 2846 | mRecentDataTask.execute(); |
Paul Soulos | b3054e5 | 2014-06-05 16:46:02 -0700 | [diff] [blame] | 2847 | } |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 2848 | |
| 2849 | @Override |
| 2850 | protected void onStop() { |
| 2851 | super.onStop(); |
| 2852 | |
| 2853 | if (mEntriesAndActionsTask != null) { |
| 2854 | // Once the activity is stopped, we will no longer want to bind mEntriesAndActionsTask's |
| 2855 | // results on the UI thread. In some circumstances Activities are killed without |
| 2856 | // onStop() being called. This is not a problem, because in these circumstances |
| 2857 | // the entire process will be killed. |
| 2858 | mEntriesAndActionsTask.cancel(/* mayInterruptIfRunning = */ false); |
| 2859 | } |
Brian Attwell | 30e1ef1 | 2014-09-02 15:49:20 -0700 | [diff] [blame] | 2860 | if (mRecentDataTask != null) { |
| 2861 | mRecentDataTask.cancel(/* mayInterruptIfRunning = */ false); |
| 2862 | } |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 2863 | } |
Paul Soulos | 23889ba | 2014-06-10 14:55:32 -0700 | [diff] [blame] | 2864 | |
Tingting Wang | e3a7c4f | 2015-09-24 18:23:18 -0700 | [diff] [blame] | 2865 | @Override |
| 2866 | public void onDestroy() { |
| 2867 | super.onDestroy(); |
| 2868 | if (mAggregationSuggestionEngine != null) { |
| 2869 | mAggregationSuggestionEngine.quit(); |
| 2870 | } |
| 2871 | } |
| 2872 | |
Paul Soulos | 23889ba | 2014-06-10 14:55:32 -0700 | [diff] [blame] | 2873 | /** |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 2874 | * Returns true if it is possible to edit the current contact. |
| 2875 | */ |
| 2876 | private boolean isContactEditable() { |
| 2877 | return mContactData != null && !mContactData.isDirectoryEntry(); |
| 2878 | } |
| 2879 | |
Brian Attwell | a41d6d1 | 2014-07-31 15:23:13 -0700 | [diff] [blame] | 2880 | /** |
| 2881 | * Returns true if it is possible to share the current contact. |
| 2882 | */ |
| 2883 | private boolean isContactShareable() { |
| 2884 | return mContactData != null && !mContactData.isDirectoryEntry(); |
| 2885 | } |
| 2886 | |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 2887 | private Intent getEditContactIntent() { |
John Shao | 41c6886 | 2016-08-17 21:02:41 -0700 | [diff] [blame] | 2888 | return EditorIntents.createCompactEditContactIntent(QuickContactActivity.this, |
Walter Jang | 1e8801b | 2015-03-10 15:57:05 -0700 | [diff] [blame] | 2889 | mContactData.getLookupUri(), |
| 2890 | mHasComputedThemeColor |
| 2891 | ? new MaterialPalette(mColorFilterColor, mStatusBarColor) : null, |
Wenyi Wang | c41a1e5 | 2016-01-29 17:01:35 +0000 | [diff] [blame] | 2892 | mContactData.getPhotoId()); |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | private void editContact() { |
Paul Soulos | a42ef76 | 2014-08-20 10:26:10 -0700 | [diff] [blame] | 2896 | mHasIntentLaunched = true; |
Zheng Fu | c00a0b5 | 2014-09-02 16:44:44 -0700 | [diff] [blame] | 2897 | mContactLoader.cacheResult(); |
Brian Attwell | 6095369 | 2014-07-11 17:18:46 -0700 | [diff] [blame] | 2898 | startActivityForResult(getEditContactIntent(), REQUEST_CODE_CONTACT_EDITOR_ACTIVITY); |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 2899 | } |
| 2900 | |
Walter Jang | 5d2e262 | 2014-11-03 13:20:48 -0800 | [diff] [blame] | 2901 | private void deleteContact() { |
| 2902 | final Uri contactUri = mContactData.getLookupUri(); |
| 2903 | ContactDeletionInteraction.start(this, contactUri, /* finishActivityWhenDone =*/ true); |
| 2904 | } |
| 2905 | |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2906 | private void toggleStar(MenuItem starredMenuItem, boolean isStarred) { |
| 2907 | // To improve responsiveness, swap out the picture (and tag) in the UI already |
| 2908 | ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, |
| 2909 | mContactData.isDirectoryEntry(), mContactData.isUserProfile(), !isStarred); |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 2910 | |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2911 | // Now perform the real save |
| 2912 | final Intent intent = ContactSaveService.createSetStarredIntent( |
| 2913 | QuickContactActivity.this, mContactData.getLookupUri(), !isStarred); |
| 2914 | startService(intent); |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 2915 | |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 2916 | final CharSequence accessibilityText = !isStarred |
| 2917 | ? getResources().getText(R.string.description_action_menu_add_star) |
| 2918 | : getResources().getText(R.string.description_action_menu_remove_star); |
| 2919 | // Accessibility actions need to have an associated view. We can't access the MenuItem's |
| 2920 | // underlying view, so put this accessibility action on the root view. |
| 2921 | mScroller.announceForAccessibility(accessibilityText); |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 2922 | } |
| 2923 | |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 2924 | private void shareContact() { |
| 2925 | final String lookupKey = mContactData.getLookupKey(); |
Brian Attwell | 652936f | 2015-05-27 19:40:36 -0700 | [diff] [blame] | 2926 | final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 2927 | final Intent intent = new Intent(Intent.ACTION_SEND); |
Yorke Lee | 552ee56 | 2015-07-28 15:58:56 -0700 | [diff] [blame] | 2928 | intent.setType(Contacts.CONTENT_VCARD_TYPE); |
Brian Attwell | 8dcb4ed | 2015-06-15 15:45:03 -0700 | [diff] [blame] | 2929 | intent.putExtra(Intent.EXTRA_STREAM, shareUri); |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 2930 | |
| 2931 | // Launch chooser to share contact via |
Wenyi Wang | 281689f | 2016-05-30 10:32:30 -0700 | [diff] [blame] | 2932 | final CharSequence chooseTitle = getResources().getQuantityString( |
| 2933 | R.plurals.title_share_via, /* quantity */ 1); |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 2934 | final Intent chooseIntent = Intent.createChooser(intent, chooseTitle); |
| 2935 | |
| 2936 | try { |
Paul Soulos | a42ef76 | 2014-08-20 10:26:10 -0700 | [diff] [blame] | 2937 | mHasIntentLaunched = true; |
Brian Attwell | 652936f | 2015-05-27 19:40:36 -0700 | [diff] [blame] | 2938 | ImplicitIntentsUtil.startActivityOutsideApp(this, chooseIntent); |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2939 | } catch (final ActivityNotFoundException ex) { |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 2940 | Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show(); |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | /** |
| 2945 | * Creates a launcher shortcut with the current contact. |
| 2946 | */ |
| 2947 | private void createLauncherShortcutWithContact() { |
| 2948 | final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this, |
| 2949 | new OnShortcutIntentCreatedListener() { |
| 2950 | |
| 2951 | @Override |
| 2952 | public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) { |
| 2953 | // Broadcast the shortcutIntent to the launcher to create a |
| 2954 | // shortcut to this contact |
| 2955 | shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); |
| 2956 | QuickContactActivity.this.sendBroadcast(shortcutIntent); |
| 2957 | |
| 2958 | // Send a toast to give feedback to the user that a shortcut to this |
| 2959 | // contact was added to the launcher. |
guanxiongliu | ce8fc7b | 2016-03-28 11:32:32 -0700 | [diff] [blame] | 2960 | final String displayName = shortcutIntent |
| 2961 | .getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Tingting Wang | 168331d | 2015-10-30 12:00:57 -0700 | [diff] [blame] | 2962 | final String toastMessage = TextUtils.isEmpty(displayName) |
| 2963 | ? getString(R.string.createContactShortcutSuccessful_NoName) |
| 2964 | : getString(R.string.createContactShortcutSuccessful, displayName); |
| 2965 | Toast.makeText(QuickContactActivity.this, toastMessage, |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 2966 | Toast.LENGTH_SHORT).show(); |
| 2967 | } |
| 2968 | |
| 2969 | }); |
Brian Attwell | 63176c9 | 2014-08-18 15:14:18 -0700 | [diff] [blame] | 2970 | builder.createContactShortcutIntent(mContactData.getLookupUri()); |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 2971 | } |
| 2972 | |
Brian Attwell | 66965e1 | 2014-09-08 16:15:20 -0700 | [diff] [blame] | 2973 | private boolean isShortcutCreatable() { |
Jay Shrauner | 1c06ce7 | 2015-05-01 11:56:08 -0700 | [diff] [blame] | 2974 | if (mContactData == null || mContactData.isUserProfile() || |
| 2975 | mContactData.isDirectoryEntry()) { |
Brian Attwell | 8d0557e | 2014-12-02 11:18:16 -0800 | [diff] [blame] | 2976 | return false; |
| 2977 | } |
Brian Attwell | 66965e1 | 2014-09-08 16:15:20 -0700 | [diff] [blame] | 2978 | final Intent createShortcutIntent = new Intent(); |
| 2979 | createShortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); |
| 2980 | final List<ResolveInfo> receivers = getPackageManager() |
| 2981 | .queryBroadcastReceivers(createShortcutIntent, 0); |
| 2982 | return receivers != null && receivers.size() > 0; |
| 2983 | } |
| 2984 | |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 2985 | @Override |
| 2986 | public boolean onCreateOptionsMenu(Menu menu) { |
Paul Soulos | eb64a4b | 2014-07-07 17:03:27 -0700 | [diff] [blame] | 2987 | final MenuInflater inflater = getMenuInflater(); |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 2988 | inflater.inflate(R.menu.quickcontact, menu); |
| 2989 | return true; |
| 2990 | } |
| 2991 | |
| 2992 | @Override |
| 2993 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 2994 | if (mContactData != null) { |
| 2995 | final MenuItem starredMenuItem = menu.findItem(R.id.menu_star); |
Paul Soulos | 333091a | 2014-07-22 13:54:41 -0700 | [diff] [blame] | 2996 | ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 2997 | mContactData.isDirectoryEntry(), mContactData.isUserProfile(), |
| 2998 | mContactData.getStarred()); |
Brian Attwell | a41d6d1 | 2014-07-31 15:23:13 -0700 | [diff] [blame] | 2999 | |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 3000 | // Configure edit MenuItem |
| 3001 | final MenuItem editMenuItem = menu.findItem(R.id.menu_edit); |
| 3002 | editMenuItem.setVisible(true); |
| 3003 | if (DirectoryContactUtil.isDirectoryContact(mContactData) || InvisibleContactUtil |
| 3004 | .isInvisibleAndAddable(mContactData, this)) { |
Brian Attwell | 30cfd12 | 2014-06-13 16:42:11 -0700 | [diff] [blame] | 3005 | editMenuItem.setIcon(R.drawable.ic_person_add_tinted_24dp); |
Brian Attwell | 2e4214c | 2014-07-10 22:03:16 -0700 | [diff] [blame] | 3006 | editMenuItem.setTitle(R.string.menu_add_contact); |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 3007 | } else if (isContactEditable()) { |
| 3008 | editMenuItem.setIcon(R.drawable.ic_create_24dp); |
Brian Attwell | 2e4214c | 2014-07-10 22:03:16 -0700 | [diff] [blame] | 3009 | editMenuItem.setTitle(R.string.menu_editContact); |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 3010 | } else { |
| 3011 | editMenuItem.setVisible(false); |
| 3012 | } |
Brian Attwell | a41d6d1 | 2014-07-31 15:23:13 -0700 | [diff] [blame] | 3013 | |
Walter Jang | 5d2e262 | 2014-11-03 13:20:48 -0800 | [diff] [blame] | 3014 | final MenuItem deleteMenuItem = menu.findItem(R.id.menu_delete); |
Walter Jang | 82ed2b5 | 2015-09-09 12:01:04 -0700 | [diff] [blame] | 3015 | deleteMenuItem.setVisible(isContactEditable() && !mContactData.isUserProfile()); |
Walter Jang | 5d2e262 | 2014-11-03 13:20:48 -0800 | [diff] [blame] | 3016 | |
Brian Attwell | a41d6d1 | 2014-07-31 15:23:13 -0700 | [diff] [blame] | 3017 | final MenuItem shareMenuItem = menu.findItem(R.id.menu_share); |
| 3018 | shareMenuItem.setVisible(isContactShareable()); |
| 3019 | |
Brian Attwell | 66965e1 | 2014-09-08 16:15:20 -0700 | [diff] [blame] | 3020 | final MenuItem shortcutMenuItem = menu.findItem(R.id.menu_create_contact_shortcut); |
| 3021 | shortcutMenuItem.setVisible(isShortcutCreatable()); |
| 3022 | |
Brian Attwell | 56bcc2f | 2015-02-12 23:45:27 +0000 | [diff] [blame] | 3023 | final MenuItem helpMenu = menu.findItem(R.id.menu_help); |
| 3024 | helpMenu.setVisible(HelpUtils.isHelpAndFeedbackAvailable()); |
| 3025 | |
Paul Soulos | 8a6d002 | 2014-06-16 15:11:03 -0700 | [diff] [blame] | 3026 | return true; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 3027 | } |
Paul Soulos | 8a6d002 | 2014-06-16 15:11:03 -0700 | [diff] [blame] | 3028 | return false; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 3029 | } |
| 3030 | |
| 3031 | @Override |
| 3032 | public boolean onOptionsItemSelected(MenuItem item) { |
| 3033 | switch (item.getItemId()) { |
| 3034 | case R.id.menu_star: |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 3035 | // Make sure there is a contact |
| 3036 | if (mContactData != null) { |
| 3037 | // Read the current starred value from the UI instead of using the last |
| 3038 | // loaded state. This allows rapid tapping without writing the same |
| 3039 | // value several times |
| 3040 | final boolean isStarred = item.isChecked(); |
| 3041 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, |
| 3042 | isStarred ? ActionType.UNSTAR : ActionType.STAR, |
| 3043 | /* thirdPartyAction */ null); |
| 3044 | toggleStar(item, isStarred); |
| 3045 | } |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 3046 | return true; |
| 3047 | case R.id.menu_edit: |
| 3048 | if (DirectoryContactUtil.isDirectoryContact(mContactData)) { |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 3049 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, |
| 3050 | ActionType.ADD, /* thirdPartyAction */ null); |
| 3051 | |
Paul Soulos | ab54ea1 | 2014-08-28 17:22:38 -0700 | [diff] [blame] | 3052 | // This action is used to launch the contact selector, with the option of |
| 3053 | // creating a new contact. Creating a new contact is an INSERT, while selecting |
| 3054 | // an exisiting one is an edit. The fields in the edit screen will be |
| 3055 | // prepopulated with data. |
| 3056 | |
| 3057 | final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 3058 | intent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 3059 | |
Paul Soulos | ab54ea1 | 2014-08-28 17:22:38 -0700 | [diff] [blame] | 3060 | ArrayList<ContentValues> values = mContactData.getContentValues(); |
Brian Attwell | fc423b4 | 2014-10-17 12:58:15 -0700 | [diff] [blame] | 3061 | |
| 3062 | // Only pre-fill the name field if the provided display name is an nickname |
| 3063 | // or better (e.g. structured name, nickname) |
| 3064 | if (mContactData.getDisplayNameSource() >= DisplayNameSources.NICKNAME) { |
| 3065 | intent.putExtra(Intents.Insert.NAME, mContactData.getDisplayName()); |
| 3066 | } else if (mContactData.getDisplayNameSource() |
| 3067 | == DisplayNameSources.ORGANIZATION) { |
| 3068 | // This is probably an organization. Instead of copying the organization |
| 3069 | // name into a name entry, copy it into the organization entry. This |
| 3070 | // way we will still consider the contact an organization. |
| 3071 | final ContentValues organization = new ContentValues(); |
| 3072 | organization.put(Organization.COMPANY, mContactData.getDisplayName()); |
| 3073 | organization.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE); |
| 3074 | values.add(organization); |
| 3075 | } |
| 3076 | |
Paul Soulos | ab54ea1 | 2014-08-28 17:22:38 -0700 | [diff] [blame] | 3077 | // Last time used and times used are aggregated values from the usage stat |
| 3078 | // table. They need to be removed from data values so the SQL table can insert |
| 3079 | // properly |
| 3080 | for (ContentValues value : values) { |
| 3081 | value.remove(Data.LAST_TIME_USED); |
| 3082 | value.remove(Data.TIMES_USED); |
| 3083 | } |
| 3084 | intent.putExtra(Intents.Insert.DATA, values); |
| 3085 | |
| 3086 | // If the contact can only export to the same account, add it to the intent. |
| 3087 | // Otherwise the ContactEditorFragment will show a dialog for selecting an |
| 3088 | // account. |
| 3089 | if (mContactData.getDirectoryExportSupport() == |
| 3090 | Directory.EXPORT_SUPPORT_SAME_ACCOUNT_ONLY) { |
Brian Attwell | 4a1c574 | 2015-01-26 15:59:58 -0800 | [diff] [blame] | 3091 | intent.putExtra(Intents.Insert.EXTRA_ACCOUNT, |
Paul Soulos | ab54ea1 | 2014-08-28 17:22:38 -0700 | [diff] [blame] | 3092 | new Account(mContactData.getDirectoryAccountName(), |
| 3093 | mContactData.getDirectoryAccountType())); |
Brian Attwell | 4a1c574 | 2015-01-26 15:59:58 -0800 | [diff] [blame] | 3094 | intent.putExtra(Intents.Insert.EXTRA_DATA_SET, |
Paul Soulos | ab54ea1 | 2014-08-28 17:22:38 -0700 | [diff] [blame] | 3095 | mContactData.getRawContacts().get(0).getDataSet()); |
| 3096 | } |
| 3097 | |
Paul Soulos | f19dda9 | 2014-09-15 15:48:02 -0700 | [diff] [blame] | 3098 | // Add this flag to disable the delete menu option on directory contact joins |
| 3099 | // with local contacts. The delete option is ambiguous when joining contacts. |
| 3100 | intent.putExtra(ContactEditorFragment.INTENT_EXTRA_DISABLE_DELETE_MENU_OPTION, |
| 3101 | true); |
| 3102 | |
John Shao | 41c6886 | 2016-08-17 21:02:41 -0700 | [diff] [blame] | 3103 | intent.setPackage(getPackageName()); |
Paul Soulos | ab54ea1 | 2014-08-28 17:22:38 -0700 | [diff] [blame] | 3104 | startActivityForResult(intent, REQUEST_CODE_CONTACT_SELECTION_ACTIVITY); |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 3105 | } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 3106 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, |
| 3107 | ActionType.ADD, /* thirdPartyAction */ null); |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 3108 | InvisibleContactUtil.addToDefaultGroup(mContactData, this); |
| 3109 | } else if (isContactEditable()) { |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 3110 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, |
| 3111 | ActionType.EDIT, /* thirdPartyAction */ null); |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 3112 | editContact(); |
| 3113 | } |
| 3114 | return true; |
Walter Jang | 5d2e262 | 2014-11-03 13:20:48 -0800 | [diff] [blame] | 3115 | case R.id.menu_delete: |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 3116 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, |
| 3117 | ActionType.DELETE, /* thirdPartyAction */ null); |
Jay Shrauner | 1c06ce7 | 2015-05-01 11:56:08 -0700 | [diff] [blame] | 3118 | if (isContactEditable()) { |
| 3119 | deleteContact(); |
| 3120 | } |
Walter Jang | 5d2e262 | 2014-11-03 13:20:48 -0800 | [diff] [blame] | 3121 | return true; |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 3122 | case R.id.menu_share: |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 3123 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, |
| 3124 | ActionType.SHARE, /* thirdPartyAction */ null); |
Jay Shrauner | 49de62f | 2014-11-26 10:44:28 -0800 | [diff] [blame] | 3125 | if (isContactShareable()) { |
| 3126 | shareContact(); |
| 3127 | } |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 3128 | return true; |
| 3129 | case R.id.menu_create_contact_shortcut: |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 3130 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, |
| 3131 | ActionType.SHORTCUT, /* thirdPartyAction */ null); |
Jay Shrauner | 1c06ce7 | 2015-05-01 11:56:08 -0700 | [diff] [blame] | 3132 | if (isShortcutCreatable()) { |
| 3133 | createLauncherShortcutWithContact(); |
| 3134 | } |
Brian Attwell | 752cccf | 2014-06-10 16:24:04 -0700 | [diff] [blame] | 3135 | return true; |
Brian Attwell | 56bcc2f | 2015-02-12 23:45:27 +0000 | [diff] [blame] | 3136 | case R.id.menu_help: |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 3137 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, |
| 3138 | ActionType.HELP, /* thirdPartyAction */ null); |
Brian Attwell | 56bcc2f | 2015-02-12 23:45:27 +0000 | [diff] [blame] | 3139 | HelpUtils.launchHelpAndFeedbackForContactScreen(this); |
| 3140 | return true; |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 3141 | default: |
yaolu | 79525d0 | 2016-08-24 12:08:39 -0700 | [diff] [blame] | 3142 | Logger.logQuickContactEvent(mReferrer, mContactType, CardType.UNKNOWN_CARD, |
| 3143 | ActionType.UNKNOWN_ACTION, /* thirdPartyAction */ null); |
Brian Attwell | d28851f | 2014-06-10 13:25:07 -0700 | [diff] [blame] | 3144 | return super.onOptionsItemSelected(item); |
| 3145 | } |
Paul Soulos | 23889ba | 2014-06-10 14:55:32 -0700 | [diff] [blame] | 3146 | } |
Daniel Lehmann | edb576a | 2011-07-27 16:45:13 -0700 | [diff] [blame] | 3147 | } |