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