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