QuickContactActivity.java revision 95c268e8dae6ed6b3bf6a205b02eadd995dec2c0
1edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/*
2edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Copyright (C) 2009 The Android Open Source Project
3edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann *
4edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Licensed under the Apache License, Version 2.0 (the "License");
5edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * you may not use this file except in compliance with the License.
6edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * You may obtain a copy of the License at
7edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann *
8edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann *      http://www.apache.org/licenses/LICENSE-2.0
9edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann *
10edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Unless required by applicable law or agreed to in writing, software
11edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * distributed under the License is distributed on an "AS IS" BASIS,
12edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * See the License for the specific language governing permissions and
14edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * limitations under the License.
15edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */
16edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
17edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannpackage com.android.contacts.quickcontact;
18edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
198a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.animation.ArgbEvaluator;
20b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport android.animation.ObjectAnimator;
21edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.app.Activity;
22d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.app.Fragment;
23cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.app.LoaderManager.LoaderCallbacks;
24eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.app.SearchManager;
25752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.content.ActivityNotFoundException;
26edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.ContentUris;
27ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulosimport android.content.ContentValues;
286bb01347eab60f95deafdfe523b0c368707210f3Brian Attwellimport android.content.Context;
29edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.content.Intent;
30cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmannimport android.content.Loader;
31dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulosimport android.content.pm.PackageManager;
32dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulosimport android.content.pm.ResolveInfo;
3331b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.Bitmap;
3495c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwellimport android.graphics.BitmapFactory;
358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.Color;
36eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuff;
37eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.graphics.PorterDuffColorFilter;
3831b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.BitmapDrawable;
398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.graphics.drawable.ColorDrawable;
4031b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.graphics.drawable.Drawable;
41eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.net.ParseException;
42edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.net.Uri;
43eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.net.WebAddress;
4431b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.os.AsyncTask;
45edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.os.Bundle;
468a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport android.os.Trace;
47eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.CalendarContract;
48752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.provider.ContactsContract;
49edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Email;
50eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Event;
51eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.GroupMembership;
52eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Identity;
53eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Im;
54eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Nickname;
55eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Note;
56eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Organization;
57edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Phone;
58eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.CommonDataKinds.Relation;
59edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.SipAddress;
60edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
61edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Website;
62752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport android.provider.ContactsContract.Contacts;
6360e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulosimport android.provider.ContactsContract.Data;
64eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.provider.ContactsContract.DisplayNameSources;
65ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulosimport android.provider.ContactsContract.DataUsageFeedback;
66edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.QuickContact;
67edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.provider.ContactsContract.RawContacts;
6831b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport android.support.v7.graphics.Palette;
6970e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chenimport android.telecomm.TelecommManager;
70edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.text.TextUtils;
71edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.util.Log;
722a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu;
732a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.ContextMenu.ContextMenuInfo;
74d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.Menu;
75d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.view.MenuInflater;
76eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport android.view.MenuItem;
77f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chenimport android.view.MotionEvent;
78edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View;
79edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.view.View.OnClickListener;
802a4207fb39330e840436215c896cde911489e111Paul Soulosimport android.view.View.OnCreateContextMenuListener;
8110d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawaimport android.view.WindowManager;
82edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.widget.ImageView;
83edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport android.widget.Toast;
84d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport android.widget.Toolbar;
85edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
8672b3ab1d8a62f228a540b05f4ed6373e494c7d72Christine Chenimport com.android.contacts.ContactSaveService;
87d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.ContactsActivity;
882d150da246632b1649999cfabed776133b097775Brian Attwellimport com.android.contacts.NfcHandler;
89e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.R;
90eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.CallUtil;
912a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.common.ClipboardUtils;
92eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.Collapser;
93eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.ContactsUtils;
94d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.common.editor.SelectAccountDialogFragment;
9570e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chenimport com.android.contacts.common.interactions.TouchPointManager;
9631b2d42fb0889e61515d27314aa5a245147100daBrian Attwellimport com.android.contacts.common.lettertiles.LetterTileDrawable;
97752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder;
98752cccf954bd6070c5fb623875314951c8e9849dBrian Attwellimport com.android.contacts.common.list.ShortcutIntentBuilder.OnShortcutIntentCreatedListener;
990d5588da244d0992c3ff8f25d0875fdf95a8c644Chiao Chengimport com.android.contacts.common.model.AccountTypeManager;
100cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.Contact;
101cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.ContactLoader;
102cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.RawContact;
103428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.account.AccountType;
104d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellimport com.android.contacts.common.model.account.AccountWithDataSet;
105cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.DataItem;
106428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.dataitem.DataKind;
107cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.EmailDataItem;
108eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.EventDataItem;
109cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.dataitem.ImDataItem;
110eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NicknameDataItem;
111eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.NoteDataItem;
112eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.OrganizationDataItem;
113b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.common.model.dataitem.PhoneDataItem;
114eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.RelationDataItem;
115eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.SipAddressDataItem;
116eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredNameDataItem;
117eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.StructuredPostalDataItem;
118eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.model.dataitem.WebsiteDataItem;
119eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.common.util.DateUtils;
120faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwellimport com.android.contacts.common.util.MaterialColorMapUtils;
121faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwellimport com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette;
122d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwellimport com.android.contacts.common.util.ViewUtil;
123333091ae754ddfc25714c14b9b89534be24379f9Paul Soulosimport com.android.contacts.detail.ContactDisplayUtils;
124899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport com.android.contacts.interactions.CalendarInteractionsLoader;
125ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulosimport com.android.contacts.interactions.CallLogInteractionsLoader;
1268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwellimport com.android.contacts.interactions.ContactDeletionInteraction;
127b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.ContactInteraction;
128b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport com.android.contacts.interactions.SmsInteractionsLoader;
1292d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.Entry;
1302a4207fb39330e840436215c896cde911489e111Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryContextMenuInfo;
1312ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulosimport com.android.contacts.quickcontact.ExpandingEntryCardView.EntryTag;
132e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwellimport com.android.contacts.quickcontact.ExpandingEntryCardView.ExpandingEntryCardViewListener;
133e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.util.ImageViewDrawableSetter;
134eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.PhoneCapabilityTester;
135b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.util.SchedulingUtils;
136eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport com.android.contacts.util.StructuredPostalUtils;
137b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller;
138b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwellimport com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener;
139e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.google.common.base.Preconditions;
140e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.google.common.collect.Lists;
141e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng
1422d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulosimport java.util.ArrayList;
143899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulosimport java.util.Arrays;
144eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Calendar;
145b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Collections;
146b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Comparator;
147eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulosimport java.util.Date;
148edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.HashMap;
149edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmannimport java.util.List;
150b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulosimport java.util.Map;
151edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
152edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann/**
153edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * Mostly translucent {@link Activity} that shows QuickContact dialog. It loads
154edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * data asynchronously, and then shows a popup with details centered around
155edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann * {@link Intent#getSourceBounds()}.
156edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann */
157d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwellpublic class QuickContactActivity extends ContactsActivity {
1588a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
1598a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    /**
1608a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell     * QuickContacts immediately takes up the full screen. All possible information is shown.
1618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell     * This value for {@link android.provider.ContactsContract.QuickContact#EXTRA_MODE}
1628a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell     * should only be used by the Contacts app.
1638a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell     */
1648a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    public static final int MODE_FULLY_EXPANDED = 4;
1658a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
166edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    private static final String TAG = "QuickContact";
167edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
1689b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell    private static final String KEY_THEME_COLOR = "theme_color";
1699b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell
1709b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell    private static final int ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION = 150;
1718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    private static final int REQUEST_CODE_CONTACT_EDITOR_ACTIVITY = 1;
172bfa9442453c1d86e11e56702f9b8ef0e8e0da0b1Brian Attwell    private static final int SCRIM_COLOR = Color.argb(0xC8, 0, 0, 0);
173ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos    private static final String MIMETYPE_SMS = "vnd.android-dir/mms-sms";
174dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki
175752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell    /** This is the Intent action to install a shortcut in the launcher. */
176752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell    private static final String ACTION_INSTALL_SHORTCUT =
177752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell            "com.android.launcher.action.INSTALL_SHORTCUT";
178edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
179edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    @SuppressWarnings("deprecation")
180edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    private static final String LEGACY_AUTHORITY = android.provider.Contacts.AUTHORITY;
181edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
182e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos    private static final String MIMETYPE_GPLUS_PROFILE =
183e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos            "vnd.android.cursor.item/vnd.googleplus.profile";
184e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos    private static final String INTENT_DATA_GPLUS_PROFILE_ADD_TO_CIRCLE = "Add to circle";
185e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos    private static final String MIMETYPE_HANGOUTS =
186e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos            "vnd.android.cursor.item/vnd.googleplus.profile.comm";
187e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos    private static final String INTENT_DATA_HANGOUTS_VIDEO = "Start video call";
18848fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos    private static final String CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY =
18948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos            "com.android.contacts.quickcontact.QuickContactActivity";
190e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos
19163176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell    /**
19263176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell     * The URI used to load the the Contact. Once the contact is loaded, use Contact#getLookupUri()
19363176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell     * instead of referencing this URI.
19463176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell     */
195edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    private Uri mLookupUri;
196edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    private String[] mExcludeMimes;
1978a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    private int mExtraMode;
1988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    private int mStatusBarColor;
1998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    private boolean mHasAlreadyBeenOpened;
200edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
2016219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee    private ImageView mPhotoView;
202eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    private ExpandingEntryCardView mContactCard;
2036095369885edcca566a812b551886e29c7ff8039Brian Attwell    private ExpandingEntryCardView mNoContactDetailsCard;
204b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    private ExpandingEntryCardView mRecentCard;
205eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    private ExpandingEntryCardView mAboutCard;
206b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell    private MultiShrinkScroller mScroller;
207d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    private SelectAccountDialogFragmentListener mSelectAccountFragmentListener;
2086bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    private AsyncTask<Void, Void, Cp2DataCardModel> mEntriesAndActionsTask;
2096bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    /**
2106bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell     * The last copy of Cp2DataCardModel that was passed to {@link #populateContactAndAboutCard}.
2116bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell     */
2126bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    private Cp2DataCardModel mCachedCp2DataCardModel;
213f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell    /**
214f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell     *  This scrim's opacity is controlled in two different ways. 1) Before the initial entrance
215f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell     *  animation finishes, the opacity is animated by a value animator. This is designed to
216f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell     *  distract the user from the length of the initial loading time. 2) After the initial
217f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell     *  entrance animation, the opacity is directly related to scroll position.
218f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell     */
2199b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell    private ColorDrawable mWindowScrim;
220f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell    private boolean mIsEntranceAnimationFinished;
221a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell    private MaterialColorMapUtils mMaterialColorMapUtils;
2228477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell    private boolean mIsExitAnimationInProgress;
2238571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell    private boolean mHasComputedThemeColor;
224edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
225a42ef76251778161d27bc07db214b8c81720e476Paul Soulos    /**
226a42ef76251778161d27bc07db214b8c81720e476Paul Soulos     * Used to stop the ExpandingEntry cards from adjusting between an entry click and the intent
227a42ef76251778161d27bc07db214b8c81720e476Paul Soulos     * being launched.
228a42ef76251778161d27bc07db214b8c81720e476Paul Soulos     */
229a42ef76251778161d27bc07db214b8c81720e476Paul Soulos    private boolean mHasIntentLaunched;
230a42ef76251778161d27bc07db214b8c81720e476Paul Soulos
2316cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee    private Contact mContactData;
2329815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann    private ContactLoader mContactLoader;
2339b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell    private PorterDuffColorFilter mColorFilter;
2349815d7f98baf80ce51b0cf1f01f48a3dbb9a9db9Daniel Lehmann
2359758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus    private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter();
2369758a92fac3e9f64892d893c992f6020d7fe3bfdJosh Gargus
237edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    /**
238cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos     * {@link #LEADING_MIMETYPES} is used to sort MIME-types.
239edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann     *
240edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann     * <p>The MIME-types in {@link #LEADING_MIMETYPES} appear in the front of the dialog,
241edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann     * in the order specified here.</p>
242edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann     */
243edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    private static final List<String> LEADING_MIMETYPES = Lists.newArrayList(
244cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos            Phone.CONTENT_ITEM_TYPE, SipAddress.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE,
245405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos            StructuredPostal.CONTENT_ITEM_TYPE);
246edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
247a153dba33c2152332c5706178a367f52b0550723Paul Soulos    private static final List<String> SORTED_ABOUT_CARD_MIMETYPES = Lists.newArrayList(
248a153dba33c2152332c5706178a367f52b0550723Paul Soulos            Nickname.CONTENT_ITEM_TYPE,
249a153dba33c2152332c5706178a367f52b0550723Paul Soulos            // Phonetic name is inserted after nickname if it is available.
250a153dba33c2152332c5706178a367f52b0550723Paul Soulos            // No mimetype for phonetic name exists.
251a153dba33c2152332c5706178a367f52b0550723Paul Soulos            Website.CONTENT_ITEM_TYPE,
252a153dba33c2152332c5706178a367f52b0550723Paul Soulos            Organization.CONTENT_ITEM_TYPE,
253a153dba33c2152332c5706178a367f52b0550723Paul Soulos            Event.CONTENT_ITEM_TYPE,
254a153dba33c2152332c5706178a367f52b0550723Paul Soulos            Relation.CONTENT_ITEM_TYPE,
255a153dba33c2152332c5706178a367f52b0550723Paul Soulos            Im.CONTENT_ITEM_TYPE,
256a153dba33c2152332c5706178a367f52b0550723Paul Soulos            GroupMembership.CONTENT_ITEM_TYPE,
257a153dba33c2152332c5706178a367f52b0550723Paul Soulos            Identity.CONTENT_ITEM_TYPE,
258a153dba33c2152332c5706178a367f52b0550723Paul Soulos            Note.CONTENT_ITEM_TYPE);
259eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
260b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    /** Id for the background contact loader */
261b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    private static final int LOADER_CONTACT_ID = 0;
262b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
263ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos    private static final String KEY_LOADER_EXTRA_PHONES =
264ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos            QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_PHONES";
265ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos
266b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    /** Id for the background Sms Loader */
267b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    private static final int LOADER_SMS_ID = 1;
268b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    private static final int MAX_SMS_RETRIEVE = 3;
269ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos
270ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos    /** Id for the back Calendar Loader */
271899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos    private static final int LOADER_CALENDAR_ID = 2;
272ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos    private static final String KEY_LOADER_EXTRA_EMAILS =
273ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos            QuickContactActivity.class.getCanonicalName() + ".KEY_LOADER_EXTRA_EMAILS";
274899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos    private static final int MAX_PAST_CALENDAR_RETRIEVE = 3;
275899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos    private static final int MAX_FUTURE_CALENDAR_RETRIEVE = 3;
276899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos    private static final long PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR =
277899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos            180L * 24L * 60L * 60L * 1000L /* 180 days */;
278899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos    private static final long FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR =
279899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos            36L * 60L * 60L * 1000L /* 36 hours */;
280899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos
281ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos    /** Id for the background Call Log Loader */
282ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos    private static final int LOADER_CALL_LOG_ID = 3;
283ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos    private static final int MAX_CALL_LOG_RETRIEVE = 3;
2846095369885edcca566a812b551886e29c7ff8039Brian Attwell    private static final int MIN_NUM_CONTACT_ENTRIES_SHOWN = 3;
2856095369885edcca566a812b551886e29c7ff8039Brian Attwell    private static final int MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN = 3;
2866095369885edcca566a812b551886e29c7ff8039Brian Attwell    private static final int CARD_ENTRY_ID_EDIT_CONTACT = -2;
287ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos
288ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos
289ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos    private static final int[] mRecentLoaderIds = new int[]{
290ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos        LOADER_SMS_ID,
291ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos        LOADER_CALENDAR_ID,
292ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos        LOADER_CALL_LOG_ID};
293a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos    private Map<Integer, List<ContactInteraction>> mRecentLoaderResults = new HashMap<>();
294b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
295d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    private static final String FRAGMENT_TAG_SELECT_ACCOUNT = "select_account_fragment";
2966cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee
2972d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos    final OnClickListener mEntryClickHandler = new OnClickListener() {
2982d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos        @Override
2992d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos        public void onClick(View v) {
3002ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos            final Object entryTagObject = v.getTag();
3012ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos            if (entryTagObject == null || !(entryTagObject instanceof EntryTag)) {
3022ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos                Log.w(TAG, "EntryTag was not used correctly");
3036095369885edcca566a812b551886e29c7ff8039Brian Attwell                return;
3046095369885edcca566a812b551886e29c7ff8039Brian Attwell            }
3052ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos            final EntryTag entryTag = (EntryTag) entryTagObject;
3062ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos            final Intent intent = entryTag.getIntent();
3072ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos            final int dataId = entryTag.getId();
3082ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos
3092ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos            if (dataId == CARD_ENTRY_ID_EDIT_CONTACT) {
3102ed2a73d15bd80bced18e5924d3f84c8a9e5e5a5Paul Soulos                editContact();
3112d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos                return;
3122d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos            }
313ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos
314ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos            // Default to USAGE_TYPE_CALL. Usage is summed among all types for sorting each data id
315ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos            // so the exact usage type is not necessary in all cases
316ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos            String usageType = DataUsageFeedback.USAGE_TYPE_CALL;
317ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos
31820bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos            final Uri intentUri = intent.getData();
31920bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos            if ((intentUri != null && intentUri.getScheme() != null &&
32020bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos                    intentUri.getScheme().equals(CallUtil.SCHEME_SMSTO)) ||
321ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos                    (intent.getType() != null && intent.getType().equals(MIMETYPE_SMS))) {
322ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos                usageType = DataUsageFeedback.USAGE_TYPE_SHORT_TEXT;
323ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos            }
324ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos
325ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos            // Data IDs start at 1 so anything less is invalid
326ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos            if (dataId > 0) {
32720bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos                final Uri dataUsageUri = DataUsageFeedback.FEEDBACK_URI.buildUpon()
328ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos                        .appendPath(String.valueOf(dataId))
329ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos                        .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, usageType)
330ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos                        .build();
331ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos                final boolean successful = getContentResolver().update(
33220bdf9d2d21e1c82513f798ef4205b9d1713996dPaul Soulos                        dataUsageUri, new ContentValues(), null, null) > 0;
333ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos                if (!successful) {
334ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos                    Log.w(TAG, "DataUsageFeedback increment failed");
335ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos                }
336ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos            } else {
337ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos                Log.w(TAG, "Invalid Data ID");
338ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos            }
339ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos
34070e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen            // Pass the touch point through the intent for use in the InCallUI
34170e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen            if (Intent.ACTION_CALL.equals(intent.getAction())) {
3421f8a3fda87bf61e579d61e3fdd246548943d070aNancy Chen                if (TouchPointManager.getInstance().hasValidPoint()) {
34370e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen                    Bundle extras = new Bundle();
3441f8a3fda87bf61e579d61e3fdd246548943d070aNancy Chen                    extras.putParcelable(TouchPointManager.TOUCH_POINT,
3451f8a3fda87bf61e579d61e3fdd246548943d070aNancy Chen                            TouchPointManager.getInstance().getPoint());
34670e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen                    intent.putExtra(TelecommManager.EXTRA_OUTGOING_CALL_EXTRAS, extras);
34770e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen                }
34870e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen            }
34970e3f4f45c040a2d09bfb46462242b450cf20b29Nancy Chen
350a42ef76251778161d27bc07db214b8c81720e476Paul Soulos            mHasIntentLaunched = true;
351ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos            startActivity(intent);
3522d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos        }
3532d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos    };
3542d48b5ae6664a7ae0ed9941f55fae9dc327bd640Paul Soulos
355e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell    final ExpandingEntryCardViewListener mExpandingEntryCardViewListener
356e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell            = new ExpandingEntryCardViewListener() {
357e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell        @Override
358e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell        public void onCollapse(int heightDelta) {
359e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell            mScroller.prepareForShrinkingScrollChild(heightDelta);
360e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell        }
3610cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos
3620cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos        @Override
3630cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos        public void onExpand(int heightDelta) {
3640cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos            mScroller.prepareForExpandingScrollChild();
3650cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos        }
366e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell    };
367e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9Brian Attwell
3682a4207fb39330e840436215c896cde911489e111Paul Soulos    private final OnCreateContextMenuListener mEntryContextMenuListener =
3692a4207fb39330e840436215c896cde911489e111Paul Soulos            new OnCreateContextMenuListener() {
3702a4207fb39330e840436215c896cde911489e111Paul Soulos        @Override
3712a4207fb39330e840436215c896cde911489e111Paul Soulos        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
3722a4207fb39330e840436215c896cde911489e111Paul Soulos            if (menuInfo == null) {
3732a4207fb39330e840436215c896cde911489e111Paul Soulos                return;
3742a4207fb39330e840436215c896cde911489e111Paul Soulos            }
3752a4207fb39330e840436215c896cde911489e111Paul Soulos            EntryContextMenuInfo info = (EntryContextMenuInfo) menuInfo;
3762a4207fb39330e840436215c896cde911489e111Paul Soulos            menu.setHeaderTitle(info.getCopyText());
3772a4207fb39330e840436215c896cde911489e111Paul Soulos            menu.add(R.string.copy_text);
3782a4207fb39330e840436215c896cde911489e111Paul Soulos        }
3792a4207fb39330e840436215c896cde911489e111Paul Soulos    };
3802a4207fb39330e840436215c896cde911489e111Paul Soulos
3812a4207fb39330e840436215c896cde911489e111Paul Soulos    @Override
3822a4207fb39330e840436215c896cde911489e111Paul Soulos    public boolean onContextItemSelected(MenuItem item) {
3832a4207fb39330e840436215c896cde911489e111Paul Soulos        EntryContextMenuInfo menuInfo;
3842a4207fb39330e840436215c896cde911489e111Paul Soulos        try {
3852a4207fb39330e840436215c896cde911489e111Paul Soulos            menuInfo = (EntryContextMenuInfo) item.getMenuInfo();
3862a4207fb39330e840436215c896cde911489e111Paul Soulos        } catch (ClassCastException e) {
3872a4207fb39330e840436215c896cde911489e111Paul Soulos            Log.e(TAG, "bad menuInfo", e);
3882a4207fb39330e840436215c896cde911489e111Paul Soulos            return false;
3892a4207fb39330e840436215c896cde911489e111Paul Soulos        }
3902a4207fb39330e840436215c896cde911489e111Paul Soulos
3912a4207fb39330e840436215c896cde911489e111Paul Soulos        ClipboardUtils.copyText(this, menuInfo.getCopyLabel(), menuInfo.getCopyText(), true);
3922a4207fb39330e840436215c896cde911489e111Paul Soulos        return true;
3932a4207fb39330e840436215c896cde911489e111Paul Soulos    }
3942a4207fb39330e840436215c896cde911489e111Paul Soulos
395d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    /**
396d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell     * Headless fragment used to handle account selection callbacks invoked from
397d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell     * {@link DirectoryContactUtil}.
398d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell     */
399d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    public static class SelectAccountDialogFragmentListener extends Fragment
400d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            implements SelectAccountDialogFragment.Listener {
401d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
402d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        private QuickContactActivity mQuickContactActivity;
403d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
404d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        public SelectAccountDialogFragmentListener() {}
405d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
406d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        @Override
407d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        public void onAccountChosen(AccountWithDataSet account, Bundle extraArgs) {
408d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            DirectoryContactUtil.createCopy(mQuickContactActivity.mContactData.getContentValues(),
409d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    account, mQuickContactActivity);
410d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        }
411d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
412d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        @Override
413d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        public void onAccountSelectorCancelled() {}
414d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
415d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        /**
416d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell         * Set the parent activity. Since rotation can cause this fragment to be used across
417d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell         * more than one activity instance, we need to explicitly set this value instead
418d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell         * of making this class non-static.
419d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell         */
420d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        public void setQuickContactActivity(QuickContactActivity quickContactActivity) {
421d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            mQuickContactActivity = quickContactActivity;
422d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        }
423d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    }
424d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
425b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell    final MultiShrinkScrollerListener mMultiShrinkScrollerListener
426b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell            = new MultiShrinkScrollerListener() {
427b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell        @Override
428b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell        public void onScrolledOffBottom() {
429f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell            finish();
430b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell        }
4318a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
4328a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        @Override
4338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        public void onEnterFullscreen() {
4348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            updateStatusBarColor();
4358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        }
4368a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
4378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        @Override
4388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        public void onExitFullscreen() {
4398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            updateStatusBarColor();
4408a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        }
4418477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell
4428477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell        @Override
4438477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell        public void onStartScrollOffBottom() {
4448477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell            mIsExitAnimationInProgress = true;
4458477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell        }
4468477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell
4478477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell        @Override
448f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell        public void onEntranceAnimationDone() {
449f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell            mIsEntranceAnimationFinished = true;
450f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell        }
451f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell
452f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell        @Override
453f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell        public void onTransparentViewHeightChange(float ratio) {
454f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell            if (mIsEntranceAnimationFinished) {
455f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                mWindowScrim.setAlpha((int) (0xFF * ratio));
4568477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell            }
4578477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell        }
458b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell    };
459b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell
460eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
461eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    /**
462eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     * Data items are compared to the same mimetype based off of three qualities:
463eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     * 1. Super primary
464eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     * 2. Primary
465eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     * 3. Times used
466eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     */
467eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    private final Comparator<DataItem> mWithinMimeTypeDataItemComparator =
468eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            new Comparator<DataItem>() {
469eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        @Override
470eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        public int compare(DataItem lhs, DataItem rhs) {
471eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            if (!lhs.getMimeType().equals(rhs.getMimeType())) {
472eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                Log.wtf(TAG, "Comparing DataItems with different mimetypes lhs.getMimeType(): " +
473eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                        lhs.getMimeType() + " rhs.getMimeType(): " + rhs.getMimeType());
474eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                return 0;
475eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
476eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
477eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            if (lhs.isSuperPrimary()) {
478eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                return -1;
479eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            } else if (rhs.isSuperPrimary()) {
480eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                return 1;
481eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            } else if (lhs.isPrimary() && !rhs.isPrimary()) {
482eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                return -1;
483eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            } else if (!lhs.isPrimary() && rhs.isPrimary()) {
484eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                return 1;
485eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            } else {
486eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                final int lhsTimesUsed =
487eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                        lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed();
488eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                final int rhsTimesUsed =
489eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                        rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed();
490eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
491eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                return rhsTimesUsed - lhsTimesUsed;
492eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
493eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        }
494eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    };
495eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
496cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos    /**
497cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos     * Sorts among different mimetypes based off:
498cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos     * 1. Times used
499cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos     * 2. Last time used
500cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos     * 3. Statically defined
501cb4fcc7ef75c33411d2b900db7933c5bc4336527Paul Soulos     */
502eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    private final Comparator<List<DataItem>> mAmongstMimeTypeDataItemComparator =
503eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            new Comparator<List<DataItem>> () {
504eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        @Override
505eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        public int compare(List<DataItem> lhsList, List<DataItem> rhsList) {
506eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            DataItem lhs = lhsList.get(0);
507eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            DataItem rhs = rhsList.get(0);
508eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final int lhsTimesUsed = lhs.getTimesUsed() == null ? 0 : lhs.getTimesUsed();
509eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final int rhsTimesUsed = rhs.getTimesUsed() == null ? 0 : rhs.getTimesUsed();
510eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final int timesUsedDifference = rhsTimesUsed - lhsTimesUsed;
511eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            if (timesUsedDifference != 0) {
512eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                return timesUsedDifference;
513eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
514eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
515eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final long lhsLastTimeUsed =
516eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                    lhs.getLastTimeUsed() == null ? 0 : lhs.getLastTimeUsed();
517eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final long rhsLastTimeUsed =
518eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                    rhs.getLastTimeUsed() == null ? 0 : rhs.getLastTimeUsed();
519eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final long lastTimeUsedDifference = rhsLastTimeUsed - lhsLastTimeUsed;
520eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            if (lastTimeUsedDifference > 0) {
521eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                return 1;
522eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            } else if (lastTimeUsedDifference < 0) {
523eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                return -1;
524eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
525eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
526eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            // Times used and last time used are the same. Resort to statically defined.
527eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final String lhsMimeType = lhs.getMimeType();
528eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final String rhsMimeType = rhs.getMimeType();
529eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            for (String mimeType : LEADING_MIMETYPES) {
530eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                if (lhsMimeType.equals(mimeType)) {
531eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                    return -1;
532eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                } else if (rhsMimeType.equals(mimeType)) {
533eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                    return 1;
534eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                }
535eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
536eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            return 0;
537eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        }
538eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    };
539eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
540edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    @Override
541f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen    public boolean dispatchTouchEvent(MotionEvent ev) {
542f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
543f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen            TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
544f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen        }
545f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen        return super.dispatchTouchEvent(ev);
546f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen    }
547f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen
548f619e432bcebb7f91c9ed88fc384abab16a9cd6aNancy Chen    @Override
5498a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    protected void onCreate(Bundle savedInstanceState) {
5508a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        Trace.beginSection("onCreate()");
5518a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        super.onCreate(savedInstanceState);
552edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
5538a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        getWindow().setStatusBarColor(Color.TRANSPARENT);
5542426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann
555d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        processIntent(getIntent());
556dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki
55710d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa        // Show QuickContact in front of soft input
55810d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa        getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
55910d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa                WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
56010d7df7bab8c332744fad64b9167c2ef061070e4Daisuke Miyakawa
561edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann        setContentView(R.layout.quickcontact_activity);
562edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
563a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell        mMaterialColorMapUtils = new MaterialColorMapUtils(getResources());
564a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell
5650cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos        mScroller = (MultiShrinkScroller) findViewById(R.id.multiscroller);
5660cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos
567eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        mContactCard = (ExpandingEntryCardView) findViewById(R.id.communication_card);
5686095369885edcca566a812b551886e29c7ff8039Brian Attwell        mNoContactDetailsCard = (ExpandingEntryCardView) findViewById(R.id.no_contact_data_card);
569b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card);
570eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        mAboutCard = (ExpandingEntryCardView) findViewById(R.id.about_card);
571edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
5726095369885edcca566a812b551886e29c7ff8039Brian Attwell        mNoContactDetailsCard.setOnClickListener(mEntryClickHandler);
573eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        mContactCard.setOnClickListener(mEntryClickHandler);
574eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        mContactCard.setExpandButtonText(
57523889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos        getResources().getString(R.string.expanding_entry_card_view_see_all));
5762a4207fb39330e840436215c896cde911489e111Paul Soulos        mContactCard.setOnCreateContextMenuListener(mEntryContextMenuListener);
577b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
578b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        mRecentCard.setOnClickListener(mEntryClickHandler);
579b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        mRecentCard.setTitle(getResources().getString(R.string.recent_card_title));
580edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
581eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        mAboutCard.setOnClickListener(mEntryClickHandler);
5822a4207fb39330e840436215c896cde911489e111Paul Soulos        mAboutCard.setOnCreateContextMenuListener(mEntryContextMenuListener);
583eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
584d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        mPhotoView = (ImageView) findViewById(R.id.photo);
58563176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell        final View transparentView = findViewById(R.id.transparent_view);
5860d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell        if (mScroller != null) {
58763176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell            transparentView.setOnClickListener(new OnClickListener() {
5880d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell                @Override
5890d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell                public void onClick(View v) {
5900d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell                    mScroller.scrollOffBottom();
5910d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell                }
5920d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell            });
5930d90afea92dc37245d5c2cad4d6b8040f2faed5cBrian Attwell        }
594edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
595d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell        // Allow a shadow to be shown under the toolbar.
596d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell        ViewUtil.addRectangularOutlineProvider(findViewById(R.id.toolbar_parent), getResources());
597d41ab8ace81a2e44f8b28aa8782679b9e9cca1b9Brian Attwell
598d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
599d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        setActionBar(toolbar);
6009b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        getActionBar().setTitle(null);
6019b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        // Put a TextView with a known resource id into the ActionBar. This allows us to easily
6029b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        // find the correct TextView location & size later.
6039b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        toolbar.addView(getLayoutInflater().inflate(R.layout.quickcontact_title_placeholder, null));
6046219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee
6058a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        mHasAlreadyBeenOpened = savedInstanceState != null;
606f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell        mIsEntranceAnimationFinished = mHasAlreadyBeenOpened;
6079b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        mWindowScrim = new ColorDrawable(SCRIM_COLOR);
608f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell        mWindowScrim.setAlpha(0);
6099b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        getWindow().setBackgroundDrawable(mWindowScrim);
610edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
611c33ae17c9816b770041ee1f9ccde10e7c7eee491Brian Attwell        mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED);
612ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell        // mScroller needs to perform asynchronous measurements after initalize(), therefore
613ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell        // we can't mark this as GONE.
614ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell        mScroller.setVisibility(View.INVISIBLE);
6158a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
6169b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        setHeaderNameText(R.string.missing_name);
6179b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell
618d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        mSelectAccountFragmentListener= (SelectAccountDialogFragmentListener) getFragmentManager()
619d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                .findFragmentByTag(FRAGMENT_TAG_SELECT_ACCOUNT);
620d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        if (mSelectAccountFragmentListener == null) {
621d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            mSelectAccountFragmentListener = new SelectAccountDialogFragmentListener();
622d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            getFragmentManager().beginTransaction().add(0, mSelectAccountFragmentListener,
623d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    FRAGMENT_TAG_SELECT_ACCOUNT).commit();
624d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            mSelectAccountFragmentListener.setRetainInstance(true);
625d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        }
626d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        mSelectAccountFragmentListener.setQuickContactActivity(this);
62723889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos
628f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell        SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ true,
629f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                new Runnable() {
630f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                    @Override
631f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                    public void run() {
632f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                        if (!mHasAlreadyBeenOpened) {
633f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                            // The initial scrim opacity must match the scrim opacity that would be
634f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                            // achieved by scrolling to the starting position.
635f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                            final float alphaRatio = mExtraMode == MODE_FULLY_EXPANDED ?
636f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                                    1 : mScroller.getStartingTransparentHeightRatio();
637f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                            final int duration = getResources().getInteger(
638f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                                    android.R.integer.config_shortAnimTime);
639f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                            final int desiredAlpha = (int) (0xFF * alphaRatio);
640f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                            ObjectAnimator o = ObjectAnimator.ofInt(mWindowScrim, "alpha", 0,
641f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                                    desiredAlpha).setDuration(duration);
642f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell
643f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                            o.start();
644f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                        }
645f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                    }
646f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell                });
647f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell
6489b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        if (savedInstanceState != null) {
6499b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell            final int color = savedInstanceState.getInt(KEY_THEME_COLOR, 0);
650ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell            SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false,
651ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                    new Runnable() {
652ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                        @Override
653ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                        public void run() {
654ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                            // Need to wait for the pre draw before setting the initial scroll
655ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                            // value. Prior to pre draw all scroll values are invalid.
656ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                            if (mHasAlreadyBeenOpened) {
657ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                                mScroller.setVisibility(View.VISIBLE);
658ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                                mScroller.setScroll(mScroller.getScrollNeededToBeFullScreen());
659ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                            }
660ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                            // Need to wait for pre draw for setting the theme color. Setting the
661ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                            // header tint before the MultiShrinkScroller has been measured will
662ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                            // cause incorrect tinting calculations.
663ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                            if (color != 0) {
664a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell                                setThemeColor(mMaterialColorMapUtils
665a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell                                        .calculatePrimaryAndSecondaryColor(color));
6669b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell                            }
667ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                        }
668ac3ed8e48cc474448aa5a7cfed5d6b95073b84f9Brian Attwell                    });
6699b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        }
6709b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell
6718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        Trace.endSection();
6728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    }
6738a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
674405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos    @Override
675405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
6768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        if (requestCode == REQUEST_CODE_CONTACT_EDITOR_ACTIVITY &&
6778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                resultCode == ContactDeletionInteraction.RESULT_CODE_DELETED) {
6788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            // The contact that we were showing has been deleted.
6798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            finish();
680b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell        }
6818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    }
682dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki
6838a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    @Override
6848a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    protected void onNewIntent(Intent intent) {
6858a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        super.onNewIntent(intent);
6868a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        mHasAlreadyBeenOpened = true;
687f1076dc20feb3ee0c687c818d70ffc1d25bef909Brian Attwell        mIsEntranceAnimationFinished = true;
6888571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell        mHasComputedThemeColor = false;
689d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        processIntent(intent);
690d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    }
691d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
6929b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell    @Override
6939b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell    public void onSaveInstanceState(Bundle savedInstanceState) {
6949b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        super.onSaveInstanceState(savedInstanceState);
6959b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        if (mColorFilter != null) {
6969b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell            savedInstanceState.putInt(KEY_THEME_COLOR, mColorFilter.getColor());
6979b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        }
6989b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell    }
6999b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell
700d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    private void processIntent(Intent intent) {
701d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        Uri lookupUri = intent.getData();
702d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
703d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        // Check to see whether it comes from the old version.
704d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) {
705d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            final long rawContactId = ContentUris.parseId(lookupUri);
706d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            lookupUri = RawContacts.getContactLookupUri(getContentResolver(),
707d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
708d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        }
709d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE,
710d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                QuickContact.MODE_LARGE);
711d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        final Uri oldLookupUri = mLookupUri;
712d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
713d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        mLookupUri = Preconditions.checkNotNull(lookupUri, "missing lookupUri");
714d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES);
715d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        if (oldLookupUri == null) {
716d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            mContactLoader = (ContactLoader) getLoaderManager().initLoader(
717d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    LOADER_CONTACT_ID, null, mLoaderContactCallbacks);
718d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        } else if (oldLookupUri != mLookupUri) {
719d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            // After copying a directory contact, the contact URI changes. Therefore,
720d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            // we need to restart the loader and reload the new contact.
721899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos            for (int interactionLoaderId : mRecentLoaderIds) {
722899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos                getLoaderManager().destroyLoader(interactionLoaderId);
723899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos            }
724405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos            mContactLoader = (ContactLoader) getLoaderManager().restartLoader(
725405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos                    LOADER_CONTACT_ID, null, mLoaderContactCallbacks);
726d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        }
7272d150da246632b1649999cfabed776133b097775Brian Attwell
7282d150da246632b1649999cfabed776133b097775Brian Attwell        NfcHandler.register(this, mLookupUri);
7292426cb015ba4cb679a525bd1ffe223527375468cDaniel Lehmann    }
730edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
731b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell    private void runEntranceAnimation() {
7328a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        if (mHasAlreadyBeenOpened) {
7338a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            return;
7348a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        }
7358a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        mHasAlreadyBeenOpened = true;
736c33ae17c9816b770041ee1f9ccde10e7c7eee491Brian Attwell        mScroller.scrollUpForEntranceAnimation(mExtraMode != MODE_FULLY_EXPANDED);
737b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell    }
738b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell
73981281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan    /** Assign this string to the view if it is not empty. */
740d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    private void setHeaderNameText(int resId) {
7419b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        if (mScroller != null) {
742f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell            mScroller.setTitle(getText(resId) == null ? null : getText(resId).toString());
7439b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        }
74481281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan    }
74581281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan
74681281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan    /** Assign this string to the view if it is not empty. */
747f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell    private void setHeaderNameText(String value) {
748d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        if (!TextUtils.isEmpty(value)) {
7499b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell            if (mScroller != null) {
750f43f573340fd9de5d30b43d7c96cac1ec9021e58Brian Attwell                mScroller.setTitle(value);
7519b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell            }
75281281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan        }
75381281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan    }
75481281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan
75581281eefd5aaf339cbfa080ddfa6c6f63caca71aKatherine Kuan    /**
756edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann     * Check if the given MIME-type appears in the list of excluded MIME-types
757edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann     * that the most-recent caller requested.
758edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann     */
759edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    private boolean isMimeExcluded(String mimeType) {
760edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann        if (mExcludeMimes == null) return false;
761edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann        for (String excludedMime : mExcludeMimes) {
762edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann            if (TextUtils.equals(excludedMime, mimeType)) {
763edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann                return true;
764edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann            }
765edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann        }
766edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann        return false;
767edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    }
768edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
769edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    /**
770cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann     * Handle the result from the ContactLoader
771edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann     */
7728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    private void bindContactData(final Contact data) {
7738a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        Trace.beginSection("bindContactData");
7746cb6f6f8304d4b42fc9db4bbb0cc4058ab53afe3Yorke Lee        mContactData = data;
775d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        invalidateOptionsMenu();
776edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
7778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        Trace.endSection();
7788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        Trace.beginSection("Set display photo & name");
779dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki
7806219668d0612f7522bd15a9d34c6232cb15b9a6cYorke Lee        mPhotoSetter.setupContactPhoto(data, mPhotoView);
78131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell        extractAndApplyTintFromPhotoViewAsynchronously();
7824936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell        analyzeWhitenessOfPhotoAsynchronously();
783333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos        setHeaderNameText(ContactDisplayUtils.getDisplayName(this, data).toString());
784edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
7858a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        Trace.endSection();
786dfe8cc82e8aa31929bb85eb68b7de3492b875d57Makoto Onuki
7876bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        mEntriesAndActionsTask = new AsyncTask<Void, Void, Cp2DataCardModel>() {
7888a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
7898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            @Override
7906bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            protected Cp2DataCardModel doInBackground(
791eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                    Void... params) {
792eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                return generateDataModelFromContact(data);
7938a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            }
7948a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
7958a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            @Override
7966bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            protected void onPostExecute(Cp2DataCardModel cardDataModel) {
7976bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                super.onPostExecute(cardDataModel);
7988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                // Check that original AsyncTask parameters are still valid and the activity
7998a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                // is still running before binding to UI. A new intent could invalidate
8008a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                // the results, for example.
8018a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                if (data == mContactData && !isCancelled()) {
8026bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                    bindDataToCards(cardDataModel);
8038a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                    showActivity();
8048a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                }
8058a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            }
8068a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        };
8078a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        mEntriesAndActionsTask.execute();
8088a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    }
8098a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
8106bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    private void bindDataToCards(Cp2DataCardModel cp2DataCardModel) {
8116bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        startInteractionLoaders(cp2DataCardModel);
8126bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        populateContactAndAboutCard(cp2DataCardModel);
813eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    }
814eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
8156bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    private void startInteractionLoaders(Cp2DataCardModel cp2DataCardModel) {
8166bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        final Map<String, List<DataItem>> dataItemsMap = cp2DataCardModel.dataItemsMap;
8176bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        final List<DataItem> phoneDataItems = dataItemsMap.get(Phone.CONTENT_ITEM_TYPE);
818eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        String[] phoneNumbers = null;
819eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        if (phoneDataItems != null) {
820eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            phoneNumbers = new String[phoneDataItems.size()];
821eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            for (int i = 0; i < phoneDataItems.size(); ++i) {
822eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                phoneNumbers[i] = ((PhoneDataItem) phoneDataItems.get(i)).getNumber();
823eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
824eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        }
825ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos        final Bundle phonesExtraBundle = new Bundle();
826eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_PHONES, phoneNumbers);
827eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
828eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Trace.beginSection("start sms loader");
8298a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        getLoaderManager().initLoader(
8308a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                LOADER_SMS_ID,
831ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos                phonesExtraBundle,
832ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos                mLoaderInteractionsCallbacks);
833ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos        Trace.endSection();
834ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos
835ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos        Trace.beginSection("start call log loader");
836ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos        getLoaderManager().initLoader(
837ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos                LOADER_CALL_LOG_ID,
838ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos                phonesExtraBundle,
8398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                mLoaderInteractionsCallbacks);
840899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos        Trace.endSection();
8418a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
842eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
843899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos        Trace.beginSection("start calendar loader");
8446bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        final List<DataItem> emailDataItems = dataItemsMap.get(Email.CONTENT_ITEM_TYPE);
845eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        String[] emailAddresses = null;
846eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        if (emailDataItems != null) {
847eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            emailAddresses = new String[emailDataItems.size()];
848eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            for (int i = 0; i < emailDataItems.size(); ++i) {
849eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                emailAddresses[i] = ((EmailDataItem) emailDataItems.get(i)).getAddress();
850eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
851eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        }
852ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos        final Bundle emailsExtraBundle = new Bundle();
853eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        emailsExtraBundle.putStringArray(KEY_LOADER_EXTRA_EMAILS, emailAddresses);
854899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos        getLoaderManager().initLoader(
855899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos                LOADER_CALENDAR_ID,
856ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos                emailsExtraBundle,
857899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos                mLoaderInteractionsCallbacks);
8588a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        Trace.endSection();
8598a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    }
8608a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
8618a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    private void showActivity() {
8628a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        if (mScroller != null) {
8638a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            mScroller.setVisibility(View.VISIBLE);
8648a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            SchedulingUtils.doOnPreDraw(mScroller, /* drawNextFrame = */ false,
8658a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                    new Runnable() {
8668a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                        @Override
8678a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                        public void run() {
8688a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                            runEntranceAnimation();
8698a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                        }
8708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                    });
8718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        }
8728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    }
8738a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
8746bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    private List<List<Entry>> buildAboutCardEntries(Map<String, List<DataItem>> dataItemsMap) {
875a153dba33c2152332c5706178a367f52b0550723Paul Soulos        final List<List<Entry>> aboutCardEntries = new ArrayList<>();
876a153dba33c2152332c5706178a367f52b0550723Paul Soulos        for (String mimetype : SORTED_ABOUT_CARD_MIMETYPES) {
8776bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            final List<DataItem> mimeTypeItems = dataItemsMap.get(mimetype);
878a153dba33c2152332c5706178a367f52b0550723Paul Soulos            if (mimeTypeItems == null) {
879a153dba33c2152332c5706178a367f52b0550723Paul Soulos                continue;
880a153dba33c2152332c5706178a367f52b0550723Paul Soulos            }
8816bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            // Set aboutCardTitleOut = null, since SORTED_ABOUT_CARD_MIMETYPES doesn't contain
8826bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            // the name mimetype.
8836bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            final List<Entry> aboutEntries = dataItemsToEntries(mimeTypeItems,
8846bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                    /* aboutCardTitleOut = */ null);
885a153dba33c2152332c5706178a367f52b0550723Paul Soulos            if (aboutEntries.size() > 0) {
886a153dba33c2152332c5706178a367f52b0550723Paul Soulos                aboutCardEntries.add(aboutEntries);
887a153dba33c2152332c5706178a367f52b0550723Paul Soulos            }
888a153dba33c2152332c5706178a367f52b0550723Paul Soulos        }
889a153dba33c2152332c5706178a367f52b0550723Paul Soulos        return aboutCardEntries;
890a153dba33c2152332c5706178a367f52b0550723Paul Soulos    }
891a153dba33c2152332c5706178a367f52b0550723Paul Soulos
892a42ef76251778161d27bc07db214b8c81720e476Paul Soulos    @Override
893a42ef76251778161d27bc07db214b8c81720e476Paul Soulos    protected void onResume() {
894a42ef76251778161d27bc07db214b8c81720e476Paul Soulos        super.onResume();
895a42ef76251778161d27bc07db214b8c81720e476Paul Soulos        // If returning from a launched activity, repopulate the contact and about card
896a42ef76251778161d27bc07db214b8c81720e476Paul Soulos        if (mHasIntentLaunched) {
897a42ef76251778161d27bc07db214b8c81720e476Paul Soulos            mHasIntentLaunched = false;
8986bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            populateContactAndAboutCard(mCachedCp2DataCardModel);
899a42ef76251778161d27bc07db214b8c81720e476Paul Soulos        }
900a42ef76251778161d27bc07db214b8c81720e476Paul Soulos    }
901a42ef76251778161d27bc07db214b8c81720e476Paul Soulos
9026bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    private void populateContactAndAboutCard(Cp2DataCardModel cp2DataCardModel) {
9036bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        mCachedCp2DataCardModel = cp2DataCardModel;
9046bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        if (mHasIntentLaunched || cp2DataCardModel == null) {
905a42ef76251778161d27bc07db214b8c81720e476Paul Soulos            return;
906a42ef76251778161d27bc07db214b8c81720e476Paul Soulos        }
907eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Trace.beginSection("bind contact card");
908eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
9096bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        final List<List<Entry>> contactCardEntries = cp2DataCardModel.contactCardEntries;
9106bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        final List<List<Entry>> aboutCardEntries = cp2DataCardModel.aboutCardEntries;
9116bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        final String customAboutCardName = cp2DataCardModel.customAboutCardName;
912eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
913eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        if (contactCardEntries.size() > 0) {
914eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            mContactCard.initialize(contactCardEntries,
915eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                    /* numInitialVisibleEntries = */ MIN_NUM_CONTACT_ENTRIES_SHOWN,
916c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos                    /* isExpanded = */ mContactCard.isExpanded(),
91789966b4ed8cc9d385e5ac6b4a7e9e08ada387eb0Paul Soulos                    /* isAlwaysExpanded = */ false,
9180cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos                    mExpandingEntryCardViewListener,
9190cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos                    mScroller);
920eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            mContactCard.setVisibility(View.VISIBLE);
921eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else {
922eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            mContactCard.setVisibility(View.GONE);
923eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        }
924eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Trace.endSection();
9258a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
926eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Trace.beginSection("bind about card");
927c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos        // Phonetic name is not a data item, so the entry needs to be created separately
928c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos        final String phoneticName = mContactData.getPhoneticName();
929c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos        if (!TextUtils.isEmpty(phoneticName)) {
930c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos            Entry phoneticEntry = new Entry(/* viewId = */ -1,
931c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos                    /* icon = */ null,
932c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos                    getResources().getString(R.string.name_phonetic),
933c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos                    phoneticName,
934c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos                    /* text = */ null,
935c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos                    /* intent = */ null,
936c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos                    /* alternateIcon = */ null,
937c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos                    /* alternateIntent = */ null,
938c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos                    /* alternateContentDescription = */ null,
939c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos                    /* shouldApplyColor = */ false,
9402a4207fb39330e840436215c896cde911489e111Paul Soulos                    /* isEditable = */ false,
9412a4207fb39330e840436215c896cde911489e111Paul Soulos                    /* EntryContextMenuInfo = */ new EntryContextMenuInfo(phoneticName,
94248fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                            getResources().getString(R.string.name_phonetic)),
94348fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                    /* thirdIcon = */ null,
94448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                    /* thirdIntent = */ null,
94548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                    /* thirdContentDescription = */ null);
946c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos            List<Entry> phoneticList = new ArrayList<>();
947c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos            phoneticList.add(phoneticEntry);
948a153dba33c2152332c5706178a367f52b0550723Paul Soulos            // Phonetic name comes after nickname. Check to see if the first entry type is nickname
949a0fa4c18dc111ceea9ff47f35ee01fecc1003578Paul Soulos            if (aboutCardEntries.size() > 0 && aboutCardEntries.get(0).get(0).getHeader().equals(
950a153dba33c2152332c5706178a367f52b0550723Paul Soulos                    getResources().getString(R.string.header_nickname_entry))) {
951a153dba33c2152332c5706178a367f52b0550723Paul Soulos                aboutCardEntries.add(1, phoneticList);
952a153dba33c2152332c5706178a367f52b0550723Paul Soulos            } else {
953a153dba33c2152332c5706178a367f52b0550723Paul Soulos                aboutCardEntries.add(0, phoneticList);
954a153dba33c2152332c5706178a367f52b0550723Paul Soulos            }
955c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos        }
956c6e110946e2c51be6276591b85ac8abe169534a0Paul Soulos
9576bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        if (!TextUtils.isEmpty(customAboutCardName)) {
9586bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            mAboutCard.setTitle(customAboutCardName);
9596bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        }
9606bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell
961cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos        if (aboutCardEntries.size() > 0) {
962cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos            mAboutCard.initialize(aboutCardEntries,
963cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos                    /* numInitialVisibleEntries = */ 1,
964cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos                    /* isExpanded = */ true,
965cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos                    /* isAlwaysExpanded = */ true,
966cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos                    mExpandingEntryCardViewListener,
967cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos                    mScroller);
968cc5ec22992ee61d130cb2ee99a038fb1761b8d35Paul Soulos        }
9696095369885edcca566a812b551886e29c7ff8039Brian Attwell
9706095369885edcca566a812b551886e29c7ff8039Brian Attwell        if (contactCardEntries.size() == 0 && aboutCardEntries.size() == 0) {
9716095369885edcca566a812b551886e29c7ff8039Brian Attwell            initializeNoContactDetailCard();
9726095369885edcca566a812b551886e29c7ff8039Brian Attwell        } else {
9736095369885edcca566a812b551886e29c7ff8039Brian Attwell            mNoContactDetailsCard.setVisibility(View.GONE);
9746095369885edcca566a812b551886e29c7ff8039Brian Attwell        }
9756095369885edcca566a812b551886e29c7ff8039Brian Attwell
976a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos        // If the Recent card is already initialized (all recent data is loaded), show the About
977a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos        // card if it has entries. Otherwise About card visibility will be set in bindRecentData()
978a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos        if (isAllRecentDataLoaded() && aboutCardEntries.size() > 0) {
979a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos            mAboutCard.setVisibility(View.VISIBLE);
980a8fce966f48d84af82f5ad767aa7986740ca7b26Paul Soulos        }
981eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Trace.endSection();
982eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    }
983eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
984eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    /**
9856095369885edcca566a812b551886e29c7ff8039Brian Attwell     * Create a card that shows "Add email" and "Add phone number" entries in grey.
9866095369885edcca566a812b551886e29c7ff8039Brian Attwell     */
9876095369885edcca566a812b551886e29c7ff8039Brian Attwell    private void initializeNoContactDetailCard() {
9886095369885edcca566a812b551886e29c7ff8039Brian Attwell        final Drawable phoneIcon = getResources().getDrawable(
9896095369885edcca566a812b551886e29c7ff8039Brian Attwell                R.drawable.ic_phone_24dp).mutate();
9906095369885edcca566a812b551886e29c7ff8039Brian Attwell        final Entry phonePromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT,
9916095369885edcca566a812b551886e29c7ff8039Brian Attwell                phoneIcon, getString(R.string.quickcontact_add_phone_number),
992dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos                /* subHeader = */ null, /* text = */ null, getEditContactIntent(),
993dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos                /* alternateIcon = */ null, /* alternateIntent = */ null,
994714455bba22b99d168a2e864dfbc74a6e30dfdb6Paul Soulos                /* alternateContentDescription = */ null, /* shouldApplyColor = */ true,
99548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                /* isEditable = */ false, /* EntryContextMenuInfo = */ null,
99648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                /* thirdIcon = */ null, /* thirdIntent = */ null,
99748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                /* thirdContentDescription = */ null);
9986095369885edcca566a812b551886e29c7ff8039Brian Attwell
9996095369885edcca566a812b551886e29c7ff8039Brian Attwell        final Drawable emailIcon = getResources().getDrawable(
10006095369885edcca566a812b551886e29c7ff8039Brian Attwell                R.drawable.ic_email_24dp).mutate();
10016095369885edcca566a812b551886e29c7ff8039Brian Attwell        final Entry emailPromptEntry = new Entry(CARD_ENTRY_ID_EDIT_CONTACT,
10026095369885edcca566a812b551886e29c7ff8039Brian Attwell                emailIcon, getString(R.string.quickcontact_add_email), /* subHeader = */ null,
1003dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos                /* text = */ null, getEditContactIntent(), /* alternateIcon = */ null,
1004dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos                /* alternateIntent = */ null, /* alternateContentDescription = */ null,
10052a4207fb39330e840436215c896cde911489e111Paul Soulos                /* shouldApplyColor = */ true, /* isEditable = */ false,
100648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                /* EntryContextMenuInfo = */ null, /* thirdIcon = */ null,
100748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                /* thirdIntent = */ null, /* thirdContentDescription = */ null);
10086095369885edcca566a812b551886e29c7ff8039Brian Attwell
10096095369885edcca566a812b551886e29c7ff8039Brian Attwell        final List<List<Entry>> promptEntries = new ArrayList<>();
10106095369885edcca566a812b551886e29c7ff8039Brian Attwell        promptEntries.add(new ArrayList<Entry>(1));
10116095369885edcca566a812b551886e29c7ff8039Brian Attwell        promptEntries.add(new ArrayList<Entry>(1));
10126095369885edcca566a812b551886e29c7ff8039Brian Attwell        promptEntries.get(0).add(phonePromptEntry);
10136095369885edcca566a812b551886e29c7ff8039Brian Attwell        promptEntries.get(1).add(emailPromptEntry);
10146095369885edcca566a812b551886e29c7ff8039Brian Attwell
10156095369885edcca566a812b551886e29c7ff8039Brian Attwell        final int subHeaderTextColor = getResources().getColor(
10166095369885edcca566a812b551886e29c7ff8039Brian Attwell                R.color.quickcontact_entry_sub_header_text_color);
10176095369885edcca566a812b551886e29c7ff8039Brian Attwell        final PorterDuffColorFilter greyColorFilter =
10186095369885edcca566a812b551886e29c7ff8039Brian Attwell                new PorterDuffColorFilter(subHeaderTextColor, PorterDuff.Mode.SRC_ATOP);
1019c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos        mNoContactDetailsCard.initialize(promptEntries, 2, /* isExpanded = */ true,
10200cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos                /* isAlwaysExpanded = */ true, mExpandingEntryCardViewListener, mScroller);
10216095369885edcca566a812b551886e29c7ff8039Brian Attwell        mNoContactDetailsCard.setVisibility(View.VISIBLE);
10226095369885edcca566a812b551886e29c7ff8039Brian Attwell        mNoContactDetailsCard.setEntryHeaderColor(subHeaderTextColor);
10236095369885edcca566a812b551886e29c7ff8039Brian Attwell        mNoContactDetailsCard.setColorAndFilter(subHeaderTextColor, greyColorFilter);
10246095369885edcca566a812b551886e29c7ff8039Brian Attwell    }
10256095369885edcca566a812b551886e29c7ff8039Brian Attwell
10266095369885edcca566a812b551886e29c7ff8039Brian Attwell    /**
1027eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     * Builds the {@link DataItem}s Map out of the Contact.
1028eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     * @param data The contact to build the data from.
1029eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     * @return A pair containing a list of data items sorted within mimetype and sorted
1030eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     *  amongst mimetype. The map goes from mimetype string to the sorted list of data items within
1031eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     *  mimetype
1032eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     */
10336bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    private Cp2DataCardModel generateDataModelFromContact(
1034eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            Contact data) {
1035eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Trace.beginSection("Build data items map");
1036eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
1037eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        final Map<String, List<DataItem>> dataItemsMap = new HashMap<>();
10388bf96e78497ea9c8c893bcb357fc1e3175fb2e9bBrian Attwell
10398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        final ResolveCache cache = ResolveCache.getInstance(this);
1040851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu        for (RawContact rawContact : data.getRawContacts()) {
1041851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu            for (DataItem dataItem : rawContact.getDataItems()) {
1042eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                dataItem.setRawContactId(rawContact.getId());
1043eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
1044851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu                final String mimeType = dataItem.getMimeType();
1045eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                if (mimeType == null) continue;
1046eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
104747b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng                final AccountType accountType = rawContact.getAccountType(this);
104847b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng                final DataKind dataKind = AccountTypeManager.getInstance(this)
104947b6f70eadb118d815b4aaf5426c070bd75a38fbChiao Cheng                        .getKindOrFallback(accountType, mimeType);
1050eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                if (dataKind == null) continue;
1051cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann
1052eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                dataItem.setDataKind(dataKind);
1053b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
1054eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                final boolean hasData = !TextUtils.isEmpty(dataItem.buildDataString(this,
1055eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                        dataKind));
1056899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos
1057eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                if (isMimeExcluded(mimeType) || !hasData) continue;
1058edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
1059eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                List<DataItem> dataItemListByType = dataItemsMap.get(mimeType);
1060eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                if (dataItemListByType == null) {
1061eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                    dataItemListByType = new ArrayList<>();
1062eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                    dataItemsMap.put(mimeType, dataItemListByType);
1063edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann                }
1064eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                dataItemListByType.add(dataItem);
1065edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann            }
1066edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann        }
10678a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        Trace.endSection();
1068edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
1069eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Trace.beginSection("sort within mimetypes");
107016339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos        /*
107116339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos         * Sorting is a multi part step. The end result is to a have a sorted list of the most
1072eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos         * used data items, one per mimetype. Then, within each mimetype, the list of data items
1073eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos         * for that type is also sorted, based off of {super primary, primary, times used} in that
1074eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos         * order.
107516339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos         */
1076eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        final List<List<DataItem>> dataItemsList = new ArrayList<>();
1077eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        for (List<DataItem> mimeTypeDataItems : dataItemsMap.values()) {
1078eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            // Remove duplicate data items
1079eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            Collapser.collapseList(mimeTypeDataItems, this);
1080eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            // Sort within mimetype
1081eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            Collections.sort(mimeTypeDataItems, mWithinMimeTypeDataItemComparator);
1082eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            // Add to the list of data item lists
1083eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            dataItemsList.add(mimeTypeDataItems);
1084edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann        }
1085eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Trace.endSection();
1086edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
1087eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Trace.beginSection("sort amongst mimetypes");
1088eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        // Sort amongst mimetypes to bubble up the top data items for the contact card
1089eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Collections.sort(dataItemsList, mAmongstMimeTypeDataItemComparator);
1090eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Trace.endSection();
109116339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos
10926bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        Trace.beginSection("cp2 data items to entries");
10936bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell
10946bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        final List<List<Entry>> contactCardEntries = new ArrayList<>();
10956bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        final List<List<Entry>> aboutCardEntries = buildAboutCardEntries(dataItemsMap);
10966bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        final MutableString aboutCardName = new MutableString();
10976bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell
10986bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        for (int i = 0; i < dataItemsList.size(); ++i) {
10996bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            final List<DataItem> dataItemsByMimeType = dataItemsList.get(i);
11006bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            final DataItem topDataItem = dataItemsByMimeType.get(0);
11016bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            if (SORTED_ABOUT_CARD_MIMETYPES.contains(topDataItem.getMimeType())) {
11026bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                // About card mimetypes are built in buildAboutCardEntries, skip here
11036bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                continue;
11046bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            } else {
11056bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                List<Entry> contactEntries = dataItemsToEntries(dataItemsList.get(i),
11066bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                        aboutCardName);
11076bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                if (contactEntries.size() > 0) {
11086bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                    contactCardEntries.add(contactEntries);
11096bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                }
11106bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            }
11116bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        }
11126bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell
11136bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        Trace.endSection();
11146bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell
11156bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        final Cp2DataCardModel dataModel = new Cp2DataCardModel();
11166bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        dataModel.customAboutCardName = aboutCardName.value;
11176bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        dataModel.aboutCardEntries = aboutCardEntries;
11186bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        dataModel.contactCardEntries = contactCardEntries;
11196bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        dataModel.dataItemsMap = dataItemsMap;
11206bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        return dataModel;
11216bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    }
11226bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell
11236bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    /**
11246bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell     * Class used to hold the About card and Contact cards' data model that gets generated
11256bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell     * on a background thread. All data is from CP2.
11266bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell     */
11276bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    private static class Cp2DataCardModel {
11286bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        /**
11296bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell         * A map between a mimetype string and the corresponding list of data items. The data items
11306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell         * are in sorted order using mWithinMimeTypeDataItemComparator.
11316bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell         */
11326bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        public Map<String, List<DataItem>> dataItemsMap;
11336bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        public List<List<Entry>> aboutCardEntries;
11346bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        public List<List<Entry>> contactCardEntries;
11356bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        public String customAboutCardName;
11366bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    }
11376bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell
11386bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    private static class MutableString {
11396bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        public String value;
1140eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    }
1141edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
1142eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    /**
1143eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     * Converts a {@link DataItem} into an {@link ExpandingEntryCardView.Entry} for display.
1144eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     * If the {@link ExpandingEntryCardView.Entry} has no visual elements, null is returned.
11456bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell     *
11466bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell     * This runs on a background thread. This is set as static to avoid accidentally adding
11476bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell     * additional dependencies on unsafe things (like the Activity).
11486bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell     *
1149eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     * @param dataItem The {@link DataItem} to convert.
1150eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     * @return The {@link ExpandingEntryCardView.Entry}, or null if no visual elements are present.
1151eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos     */
11526bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    private static Entry dataItemToEntry(DataItem dataItem,
11536bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            Context context, Contact contactData,
11546bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            final MutableString aboutCardName) {
1155eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Drawable icon = null;
1156eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        String header = null;
1157eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        String subHeader = null;
1158eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Drawable subHeaderIcon = null;
1159eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        String text = null;
1160eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Drawable textIcon = null;
1161eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        Intent intent = null;
116248ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos        boolean shouldApplyColor = true;
1163dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        Drawable alternateIcon = null;
1164dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        Intent alternateIntent = null;
1165dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        String alternateContentDescription = null;
1166eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        final boolean isEditable = false;
11672a4207fb39330e840436215c896cde911489e111Paul Soulos        EntryContextMenuInfo entryContextMenuInfo = null;
116848fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos        Drawable thirdIcon = null;
116948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos        Intent thirdIntent = null;
117048fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos        String thirdContentDescription = null;
1171eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
11726bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        context = context.getApplicationContext();
1173eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        DataKind kind = dataItem.getDataKind();
1174eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
1175eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        if (dataItem instanceof ImDataItem) {
1176eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final ImDataItem im = (ImDataItem) dataItem;
11776bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            intent = ContactsUtils.buildImIntent(context, im).first;
1178eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final boolean isEmail = im.isCreatedFromEmail();
11797de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos            final int protocol;
11807de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos            if (!im.isProtocolValid()) {
11817de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos                protocol = Im.PROTOCOL_CUSTOM;
11827de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos            } else {
11837de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos                protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol();
11847de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos            }
11857de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos            if (protocol == Im.PROTOCOL_CUSTOM) {
11867de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos                // If the protocol is custom, display the "IM" entry header as well to distinguish
11877de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos                // this entry from other ones
11886bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                header = context.getResources().getString(R.string.header_im_entry);
11896bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                subHeader = Im.getProtocolLabel(context.getResources(), protocol,
11907de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos                        im.getCustomProtocol()).toString();
11917de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos                text = im.getData();
11927de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos            } else {
11936bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                header = Im.getProtocolLabel(context.getResources(), protocol,
11947de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos                        im.getCustomProtocol()).toString();
11957de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos                subHeader = im.getData();
11967de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos            }
11972a4207fb39330e840436215c896cde911489e111Paul Soulos            entryContextMenuInfo = new EntryContextMenuInfo(im.getData(), header);
1198eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else if (dataItem instanceof OrganizationDataItem) {
1199eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final OrganizationDataItem organization = (OrganizationDataItem) dataItem;
12006bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            header = context.getResources().getString(R.string.header_organization_entry);
1201eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            subHeader = organization.getCompany();
12022a4207fb39330e840436215c896cde911489e111Paul Soulos            entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header);
1203eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            text = organization.getTitle();
1204eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else if (dataItem instanceof NicknameDataItem) {
1205eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final NicknameDataItem nickname = (NicknameDataItem) dataItem;
1206eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            // Build nickname entries
1207eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final boolean isNameRawContact =
12086bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                (contactData.getNameRawContactId() == dataItem.getRawContactId());
1209eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
1210eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final boolean duplicatesTitle =
1211eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                isNameRawContact
12126bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                && contactData.getDisplayNameSource() == DisplayNameSources.NICKNAME;
1213eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
1214eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            if (!duplicatesTitle) {
12156bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                header = context.getResources().getString(R.string.header_nickname_entry);
1216eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                subHeader = nickname.getName();
12172a4207fb39330e840436215c896cde911489e111Paul Soulos                entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header);
1218eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
1219eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else if (dataItem instanceof NoteDataItem) {
1220eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final NoteDataItem note = (NoteDataItem) dataItem;
12216bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            header = context.getResources().getString(R.string.header_note_entry);
1222eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            subHeader = note.getNote();
12232a4207fb39330e840436215c896cde911489e111Paul Soulos            entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header);
1224eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else if (dataItem instanceof WebsiteDataItem) {
1225eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final WebsiteDataItem website = (WebsiteDataItem) dataItem;
12266bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            header = context.getResources().getString(R.string.header_website_entry);
1227eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            subHeader = website.getUrl();
12282a4207fb39330e840436215c896cde911489e111Paul Soulos            entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header);
1229eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            try {
12306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                final WebAddress webAddress = new WebAddress(website.buildDataString(context,
12316bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                        kind));
1232eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString()));
1233eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            } catch (final ParseException e) {
12346bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                Log.e(TAG, "Couldn't parse website: " + website.buildDataString(context, kind));
1235eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
1236eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else if (dataItem instanceof EventDataItem) {
1237eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final EventDataItem event = (EventDataItem) dataItem;
12386bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            final String dataString = event.buildDataString(context, kind);
1239eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final Calendar cal = DateUtils.parseDate(dataString, false);
1240eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            if (cal != null) {
1241eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                final Date nextAnniversary =
1242eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                        DateUtils.getNextAnnualDate(cal);
1243eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
1244eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                builder.appendPath("time");
1245eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                ContentUris.appendId(builder, nextAnniversary.getTime());
1246eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
1247eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
12486bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            header = context.getResources().getString(R.string.header_event_entry);
1249f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos            if (event.hasKindTypeColumn(kind)) {
12506bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                subHeader = Event.getTypeLabel(context.getResources(), event.getKindTypeColumn(kind),
12517de6f85b0ee66deda13505f545c6b7125b2ac462Paul Soulos                        event.getLabel()).toString();
1252f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos            }
12536bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            text = DateUtils.formatDate(context, dataString);
1254f848c49cac796f99549c8418f8d4e2469ac9f963Paul Soulos            entryContextMenuInfo = new EntryContextMenuInfo(text, header);
1255eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else if (dataItem instanceof RelationDataItem) {
1256eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final RelationDataItem relation = (RelationDataItem) dataItem;
12576bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            final String dataString = relation.buildDataString(context, kind);
1258eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            if (!TextUtils.isEmpty(dataString)) {
1259eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                intent = new Intent(Intent.ACTION_SEARCH);
1260eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                intent.putExtra(SearchManager.QUERY, dataString);
1261eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                intent.setType(Contacts.CONTENT_TYPE);
1262eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
12636bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            header = context.getResources().getString(R.string.header_relation_entry);
1264eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            subHeader = relation.getName();
12652a4207fb39330e840436215c896cde911489e111Paul Soulos            entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header);
1266f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos            if (relation.hasKindTypeColumn(kind)) {
12676bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                text = Relation.getTypeLabel(context.getResources(),
12686bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                        relation.getKindTypeColumn(kind),
1269f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos                        relation.getLabel()).toString();
1270f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos            }
1271eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else if (dataItem instanceof PhoneDataItem) {
1272eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final PhoneDataItem phone = (PhoneDataItem) dataItem;
1273eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            if (!TextUtils.isEmpty(phone.getNumber())) {
12746bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                header = phone.buildDataString(context, kind);
12752a4207fb39330e840436215c896cde911489e111Paul Soulos                entryContextMenuInfo = new EntryContextMenuInfo(header,
12766bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                        context.getResources().getString(R.string.phoneLabelsGroup));
1277f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos                if (phone.hasKindTypeColumn(kind)) {
12786bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                    text = Phone.getTypeLabel(context.getResources(), phone.getKindTypeColumn(kind),
1279f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos                            phone.getLabel()).toString();
1280f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos                }
12816bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                icon = context.getResources().getDrawable(R.drawable.ic_phone_24dp);
12826bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                if (PhoneCapabilityTester.isPhone(context)) {
1283eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                    intent = CallUtil.getCallIntent(phone.getNumber());
128416339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos                }
1285dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos                alternateIntent = new Intent(Intent.ACTION_SENDTO,
1286dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos                        Uri.fromParts(CallUtil.SCHEME_SMSTO, phone.getNumber(), null));
128748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos
12886bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                alternateIcon = context.getResources().getDrawable(R.drawable.ic_message_24dp);
12896bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                alternateContentDescription = context.getResources().getString(R.string.sms_other);
129048fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos
129148fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                // Add video call button if supported
1292f764730a34da560db87206f9a48390d4c8085365Paul Soulos                if (CallUtil.isVideoEnabled(context)) {
129348fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                    thirdIcon = context.getResources().getDrawable(R.drawable.ic_videocam);
129448fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                    thirdIntent = CallUtil.getVideoCallIntent(phone.getNumber(),
129548fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                            CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY);
129648fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                    thirdContentDescription =
129748fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                            context.getResources().getString(R.string.description_video_call);
129848fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                }
1299eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
1300eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else if (dataItem instanceof EmailDataItem) {
1301eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final EmailDataItem email = (EmailDataItem) dataItem;
1302eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final String address = email.getData();
1303eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            if (!TextUtils.isEmpty(address)) {
1304eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                final Uri mailUri = Uri.fromParts(CallUtil.SCHEME_MAILTO, address, null);
1305eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                intent = new Intent(Intent.ACTION_SENDTO, mailUri);
1306eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                header = email.getAddress();
13072a4207fb39330e840436215c896cde911489e111Paul Soulos                entryContextMenuInfo = new EntryContextMenuInfo(header,
13086bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                        context.getResources().getString(R.string.emailLabelsGroup));
1309f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos                if (email.hasKindTypeColumn(kind)) {
13106bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                    text = Email.getTypeLabel(context.getResources(), email.getKindTypeColumn(kind),
1311f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos                            email.getLabel()).toString();
1312f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos                }
13136bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                icon = context.getResources().getDrawable(R.drawable.ic_email_24dp);
1314eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
1315eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else if (dataItem instanceof StructuredPostalDataItem) {
1316eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            StructuredPostalDataItem postal = (StructuredPostalDataItem) dataItem;
1317eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final String postalAddress = postal.getFormattedAddress();
1318eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            if (!TextUtils.isEmpty(postalAddress)) {
1319eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                intent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress);
1320eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                header = postal.getFormattedAddress();
13212a4207fb39330e840436215c896cde911489e111Paul Soulos                entryContextMenuInfo = new EntryContextMenuInfo(header,
13226bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                        context.getResources().getString(R.string.postalLabelsGroup));
1323f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos                if (postal.hasKindTypeColumn(kind)) {
13246bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                    text = StructuredPostal.getTypeLabel(context.getResources(),
1325f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos                            postal.getKindTypeColumn(kind), postal.getLabel()).toString();
1326f9d5c0e24d1b11527475227549f9530127e9dc07Paul Soulos                }
13276a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos                alternateIntent =
13286a4d2736d772cc5cbb79d04e115f2d6117826860Paul Soulos                        StructuredPostalUtils.getViewPostalAddressDirectionsIntent(postalAddress);
13296bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                alternateIcon = context.getResources().getDrawable(R.drawable.ic_directions_24dp);
13306bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                icon = context.getResources().getDrawable(R.drawable.ic_place_24dp);
1331eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
1332eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else if (dataItem instanceof SipAddressDataItem) {
13336bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            if (PhoneCapabilityTester.isSipPhone(context)) {
1334eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                final SipAddressDataItem sip = (SipAddressDataItem) dataItem;
1335eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                final String address = sip.getSipAddress();
1336eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                if (!TextUtils.isEmpty(address)) {
1337eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                    final Uri callUri = Uri.fromParts(CallUtil.SCHEME_SIP, address, null);
1338eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                    intent = CallUtil.getCallIntent(callUri);
13391cda01b35a37f79b22e907cc970314b8c0a9e00cPaul Soulos                    header = address;
13402a4207fb39330e840436215c896cde911489e111Paul Soulos                    entryContextMenuInfo = new EntryContextMenuInfo(header,
13416bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                            context.getResources().getString(R.string.phoneLabelsGroup));
13421cda01b35a37f79b22e907cc970314b8c0a9e00cPaul Soulos                    if (sip.hasKindTypeColumn(kind)) {
13436bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                        text = SipAddress.getTypeLabel(context.getResources(),
13446bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                                sip.getKindTypeColumn(kind), sip.getLabel()).toString();
13451cda01b35a37f79b22e907cc970314b8c0a9e00cPaul Soulos                    }
13466bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                    icon = context.getResources().getDrawable(R.drawable.ic_dialer_sip_black_24dp);
134716339336653fa028a2e02e1eee92851fe5084d1cPaul Soulos                }
1348edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann            }
1349eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else if (dataItem instanceof StructuredNameDataItem) {
1350eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final String givenName = ((StructuredNameDataItem) dataItem).getGivenName();
1351eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            if (!TextUtils.isEmpty(givenName)) {
13526bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                aboutCardName.value = context.getResources().getString(R.string.about_card_title) +
13536bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                        " " + givenName;
1354eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            } else {
13556bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                aboutCardName.value = context.getResources().getString(R.string.about_card_title);
1356eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
1357eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else {
1358eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            // Custom DataItem
13596bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            header = dataItem.buildDataStringForDisplay(context, kind);
1360eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            text = kind.typeColumn;
1361eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            intent = new Intent(Intent.ACTION_VIEW);
136260e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos            final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, dataItem.getId());
136360e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos            intent.setDataAndType(uri, dataItem.getMimeType());
1364e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos
1365e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos            if (intent != null) {
1366e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                final String mimetype = intent.getType();
1367e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos
1368e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                // Attempt to use known icons for known 3p types. Otherwise default to ResolveCache
1369e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                switch (mimetype) {
1370e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                    case MIMETYPE_GPLUS_PROFILE:
1371e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                        if (INTENT_DATA_GPLUS_PROFILE_ADD_TO_CIRCLE.equals(
1372e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                                intent.getDataString())) {
13736bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                            icon = context.getResources().getDrawable(
1374e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                                    R.drawable.ic_add_to_circles_black_24);
1375e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                        } else {
13766bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                            icon = context.getResources().getDrawable(R.drawable.ic_google_plus_24dp);
1377e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                        }
1378e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                        break;
1379e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                    case MIMETYPE_HANGOUTS:
1380e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                        if (INTENT_DATA_HANGOUTS_VIDEO.equals(intent.getDataString())) {
13816bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                            icon = context.getResources().getDrawable(R.drawable.ic_hangout_video_24dp);
1382e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                        } else {
13836bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                            icon = context.getResources().getDrawable(R.drawable.ic_hangout_24dp);
1384e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                        }
1385e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                        break;
1386e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                    default:
13872a4207fb39330e840436215c896cde911489e111Paul Soulos                        entryContextMenuInfo = new EntryContextMenuInfo(header, mimetype);
13886bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                        icon = ResolveCache.getInstance(context).getIcon(
1389e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                                dataItem.getMimeType(), intent);
1390e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                        // Call mutate to create a new Drawable.ConstantState for color filtering
1391e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                        if (icon != null) {
1392e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                            icon.mutate();
1393e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                        }
139448ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos                        shouldApplyColor = false;
1395e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos                }
1396e005566a1616d6797fb7e204d0d41bd341b37543Paul Soulos            }
1397eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        }
1398b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
1399eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        if (intent != null) {
1400eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            // Do not set the intent is there are no resolves
14016bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            if (!PhoneCapabilityTester.isIntentRegistered(context, intent)) {
1402eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                intent = null;
1403eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
1404eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        }
1405eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
1406dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        if (alternateIntent != null) {
1407dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos            // Do not set the alternate intent is there are no resolves
14086bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            if (!PhoneCapabilityTester.isIntentRegistered(context, alternateIntent)) {
1409dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos                alternateIntent = null;
1410dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos            }
1411dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos
1412dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos            // Attempt to use package manager to find a suitable content description if needed
1413dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos            if (TextUtils.isEmpty(alternateContentDescription)) {
14146bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell                alternateContentDescription = getIntentResolveLabel(alternateIntent, context);
1415dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos            }
1416dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        }
1417dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos
1418eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        // If the Entry has no visual elements, return null
1419eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) &&
1420eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                subHeaderIcon == null && TextUtils.isEmpty(text) && textIcon == null) {
1421eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            return null;
1422eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        }
1423eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
1424fa238949855fba3b28a57fad3d585b13e80362bbBrian Attwell        // Ignore dataIds from the Me profile.
1425ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos        final int dataId = dataItem.getId() > Integer.MAX_VALUE ?
1426ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos                -1 : (int) dataItem.getId();
1427ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos
1428dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon, intent,
1429dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos                alternateIcon, alternateIntent, alternateContentDescription, shouldApplyColor,
143048fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                isEditable, entryContextMenuInfo, thirdIcon, thirdIntent, thirdContentDescription);
1431eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    }
1432eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
14336bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    private List<Entry> dataItemsToEntries(List<DataItem> dataItems,
14346bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            MutableString aboutCardTitleOut) {
1435eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        final List<Entry> entries = new ArrayList<>();
1436eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        for (DataItem dataItem : dataItems) {
14376bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            final Entry entry = dataItemToEntry(dataItem, this, mContactData, aboutCardTitleOut);
1438eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            if (entry != null) {
1439eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos                entries.add(entry);
1440eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            }
1441eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        }
1442eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        return entries;
1443edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    }
1444edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann
14456bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell    private static String getIntentResolveLabel(Intent intent, Context context) {
14466bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        final List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent,
1447dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos                PackageManager.MATCH_DEFAULT_ONLY);
1448dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos
1449dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        // Pick first match, otherwise best found
1450dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        ResolveInfo bestResolve = null;
1451dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        final int size = matches.size();
1452dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        if (size == 1) {
1453dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos            bestResolve = matches.get(0);
1454dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        } else if (size > 1) {
14556bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell            bestResolve = ResolveCache.getInstance(context).getBestResolve(intent, matches);
1456dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        }
1457dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos
1458dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        if (bestResolve == null) {
1459dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos            return null;
1460dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos        }
1461dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos
14626bb01347eab60f95deafdfe523b0c368707210f3Brian Attwell        return String.valueOf(bestResolve.loadLabel(context.getPackageManager()));
1463dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos    }
1464dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos
1465edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann    /**
146631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell     * Asynchronously extract the most vibrant color from the PhotoView. Once extracted,
146731b2d42fb0889e61515d27314aa5a245147100daBrian Attwell     * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms
146831b2d42fb0889e61515d27314aa5a245147100daBrian Attwell     * on a Nexus 5.
146931b2d42fb0889e61515d27314aa5a245147100daBrian Attwell     */
147031b2d42fb0889e61515d27314aa5a245147100daBrian Attwell    private void extractAndApplyTintFromPhotoViewAsynchronously() {
147131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell        if (mScroller == null) {
147231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell            return;
147331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell        }
147431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell        final Drawable imageViewDrawable = mPhotoView.getDrawable();
1475faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell        new AsyncTask<Void, Void, MaterialPalette>() {
147631b2d42fb0889e61515d27314aa5a245147100daBrian Attwell            @Override
1477faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell            protected MaterialPalette doInBackground(Void... params) {
1478faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell
147995c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                if (imageViewDrawable instanceof BitmapDrawable
148095c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                        && mContactData.getThumbnailPhotoBinaryData() != null
148195c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                        && mContactData.getThumbnailPhotoBinaryData().length > 0) {
148295c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                    // Perform the color analysis on the thumbnail instead of the full sized
148395c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                    // image, so that our results will be as similar as possible to the Bugle
148495c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                    // app.
148595c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                    final Bitmap bitmap = BitmapFactory.decodeByteArray(
148695c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                            mContactData.getThumbnailPhotoBinaryData(), 0,
148795c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                            mContactData.getThumbnailPhotoBinaryData().length);
148895c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                    try {
148995c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                        final int primaryColor = colorFromBitmap(bitmap);
149095c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                        if (primaryColor != 0) {
149195c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                            return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(
149295c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                                    primaryColor);
149395c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                        }
149495c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                    } finally {
149595c268e8dae6ed6b3bf6a205b02eadd995dec2c0Brian Attwell                        bitmap.recycle();
1496faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell                    }
14978a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                }
14988a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                if (imageViewDrawable instanceof LetterTileDrawable) {
1499faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell                    final int primaryColor = ((LetterTileDrawable) imageViewDrawable).getColor();
1500a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell                    return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(primaryColor);
150131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell                }
1502a3859ed9ff9f315d492e199620a08ae35ab8569fBrian Attwell                return MaterialColorMapUtils.getDefaultPrimaryAndSecondaryColors(getResources());
150331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell            }
150431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell
150531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell            @Override
1506faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell            protected void onPostExecute(MaterialPalette palette) {
1507faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell                super.onPostExecute(palette);
15088571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                if (mHasComputedThemeColor) {
15098571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                    // If we had previously computed a theme color from the contact photo,
15108571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                    // then do not update the theme color. Changing the theme color several
15118571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                    // seconds after QC has started, as a result of an updated/upgraded photo,
15128571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                    // is a jarring experience. On the other hand, changing the theme color after
15138571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                    // a rotation or onNewIntent() is perfectly fine.
15148571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                    return;
15158571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                }
15168571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                // Check that the Photo has not changed. If it has changed, the new tint
15178571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                // color needs to be extracted
15188571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                if (imageViewDrawable == mPhotoView.getDrawable()) {
15198571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                    mHasComputedThemeColor = true;
1520faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell                    setThemeColor(palette);
152131b2d42fb0889e61515d27314aa5a245147100daBrian Attwell                }
152231b2d42fb0889e61515d27314aa5a245147100daBrian Attwell            }
152331b2d42fb0889e61515d27314aa5a245147100daBrian Attwell        }.execute();
152431b2d42fb0889e61515d27314aa5a245147100daBrian Attwell    }
152531b2d42fb0889e61515d27314aa5a245147100daBrian Attwell
15264936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell    /**
15274936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell     * Examine how many white pixels are in the bitmap in order to determine whether or not
15284936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell     * we need gradient overlays on top of the image.
15294936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell     */
15304936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell    private void analyzeWhitenessOfPhotoAsynchronously() {
15314936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell        final Drawable imageViewDrawable = mPhotoView.getDrawable();
15324936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell        new AsyncTask<Void, Void, Boolean>() {
15334936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell            @Override
15344936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell            protected Boolean doInBackground(Void... params) {
15354936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell                if (imageViewDrawable instanceof BitmapDrawable) {
15364936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell                    final Bitmap bitmap = ((BitmapDrawable) imageViewDrawable).getBitmap();
15374936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell                    return WhitenessUtils.isBitmapWhiteAtTopOrBottom(bitmap);
15384936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell                }
15394936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell                return !(imageViewDrawable instanceof LetterTileDrawable);
15404936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell            }
15414936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell
15424936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell            @Override
15434936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell            protected void onPostExecute(Boolean isWhite) {
15444936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell                super.onPostExecute(isWhite);
15454936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell                mScroller.setUseGradient(isWhite);
15464936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell            }
15474936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell        }.execute();
15484936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell    }
15494936a92aeef739ae6b57dad00f385307d1b1c5b8Brian Attwell
1550faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell    private void setThemeColor(MaterialPalette palette) {
15519b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        // If the color is invalid, use the predefined default
1552faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell        final int primaryColor = palette.mPrimaryColor;
1553faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell        mScroller.setHeaderTintColor(primaryColor);
1554faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell        mStatusBarColor = palette.mSecondaryColor;
15559b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        updateStatusBarColor();
15568571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell
15579b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell        mColorFilter =
1558faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell                new PorterDuffColorFilter(primaryColor, PorterDuff.Mode.SRC_ATOP);
1559faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell        mContactCard.setColorAndFilter(primaryColor, mColorFilter);
1560faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell        mRecentCard.setColorAndFilter(primaryColor, mColorFilter);
1561faf973989af7ac3b735c2aee1bec22ef6608b123Brian Attwell        mAboutCard.setColorAndFilter(primaryColor, mColorFilter);
15629b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell    }
15639b889e6ef4534db6925e3f915bed281733ea8bc3Brian Attwell
15648a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    private void updateStatusBarColor() {
15658a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        if (mScroller == null) {
15668a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            return;
15678a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        }
15688a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        final int desiredStatusBarColor;
15698a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        // Only use a custom status bar color if QuickContacts touches the top of the viewport.
15708a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        if (mScroller.getScrollNeededToBeFullScreen() <= 0) {
15718a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            desiredStatusBarColor = mStatusBarColor;
15728a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        } else {
15738a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            desiredStatusBarColor = Color.TRANSPARENT;
15748a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        }
15758a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        // Animate to the new color.
1576847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell        final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor",
1577847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell                getWindow().getStatusBarColor(), desiredStatusBarColor);
1578847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell        animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION);
1579847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell        animation.setEvaluator(new ArgbEvaluator());
1580847bf2cd3946b1801c83c745d7183aed5143b44cBrian Attwell        animation.start();
15818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    }
15828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
15838a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    private int colorFromBitmap(Bitmap bitmap) {
15848a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        // Author of Palette recommends using 24 colors when analyzing profile photos.
15858a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        final int NUMBER_OF_PALETTE_COLORS = 24;
15868a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        final Palette palette = Palette.generate(bitmap, NUMBER_OF_PALETTE_COLORS);
1587a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell        if (palette != null && palette.getVibrantSwatch() != null) {
1588a0f20f77e1b4f6cde5934d8b3348d93b58fd6362Brian Attwell            return palette.getVibrantSwatch().getRgb();
15898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        }
15908a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        return 0;
15918a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    }
15928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
1593b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) {
1594eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        final List<Entry> entries = new ArrayList<>();
1595b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        for (ContactInteraction interaction : interactions) {
1596ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos            entries.add(new Entry(/* id = */ -1,
1597ea5e0b715030f1b0e8015defd10842127a8a4121Paul Soulos                    interaction.getIcon(this),
1598b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                    interaction.getViewHeader(this),
1599b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                    interaction.getViewBody(this),
1600b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                    interaction.getBodyIcon(this),
1601b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                    interaction.getViewFooter(this),
1602b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                    interaction.getFooterIcon(this),
1603b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                    interaction.getIntent(),
1604dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos                    /* alternateIcon = */ null,
1605dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos                    /* alternateIntent = */ null,
1606dd7419d90cda5c52e81491bea3cf3c3f4e0535c7Paul Soulos                    /* alternateContentDescription = */ null,
160748ebbaafcf467c072e4477c98ef2faba1c65af7ePaul Soulos                    /* shouldApplyColor = */ true,
16082a4207fb39330e840436215c896cde911489e111Paul Soulos                    /* isEditable = */ false,
160948fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                    /* EntryContextMenuInfo = */ null,
161048fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                    /* thirdIcon = */ null,
161148fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                    /* thirdIntent = */ null,
161248fc91217042fd854f0e96c2028c188e50a5e21dPaul Soulos                    /* thirdContentDescription = */ null));
1613b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        }
1614b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        return entries;
1615b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    }
1616b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
1617eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    private final LoaderCallbacks<Contact> mLoaderContactCallbacks =
1618851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu            new LoaderCallbacks<Contact>() {
1619cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann        @Override
1620851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu        public void onLoaderReset(Loader<Contact> loader) {
1621405ae406379ad9c47770783afc76a660f6c55fcaPaul Soulos            mContactData = null;
1622cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann        }
1623cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann
1624cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann        @Override
1625851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu        public void onLoadFinished(Loader<Contact> loader, Contact data) {
16268a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            Trace.beginSection("onLoadFinished()");
16278a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
1628cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann            if (isFinishing()) {
1629cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann                return;
1630cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann            }
1631cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann            if (data.isError()) {
1632cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann                // This shouldn't ever happen, so throw an exception. The {@link ContactLoader}
1633cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann                // should log the actual exception.
1634cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann                throw new IllegalStateException("Failed to load contact", data.getException());
1635cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann            }
1636cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann            if (data.isNotFound()) {
16378a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                if (mHasAlreadyBeenOpened) {
16388a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                    finish();
16398a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                } else {
16408a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                    Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri());
16418a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                    Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage,
16428a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                            Toast.LENGTH_LONG).show();
16438a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell                }
1644cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann                return;
1645cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann            }
1646cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann
1647b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            bindContactData(data);
1648cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann
16498a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            Trace.endSection();
1650cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann        }
1651cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann
1652cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann        @Override
1653851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu        public Loader<Contact> onCreateLoader(int id, Bundle args) {
1654cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann            if (mLookupUri == null) {
1655cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann                Log.wtf(TAG, "Lookup uri wasn't initialized. Loader was started too early");
1656cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann            }
1657d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            // Load all contact data. We need loadGroupMetaData=true to determine whether the
1658d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            // contact is invisible. If it is, we need to display an "Add to Contacts" MenuItem.
1659b2b435a944947fbf1965c3bb7c202a97f0273259Yorke Lee            return new ContactLoader(getApplicationContext(), mLookupUri,
1660d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    true /*loadGroupMetaData*/, false /*loadInvitableAccountTypes*/,
16618571dd3953ddf2cf8442335657a1945487d665a1Brian Attwell                    true /*postViewNotification*/, true /*computeFormattedPhoneNumber*/);
1662cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann        }
1663cb8d73fc8ea538d0b63dd77210c05c5b8de32f03Daniel Lehmann    };
1664b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
1665b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell    @Override
1666b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell    public void onBackPressed() {
1667b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell        if (mScroller != null) {
16688477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell            if (!mIsExitAnimationInProgress) {
16698477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell                mScroller.scrollOffBottom();
16708477eafe57bca7b6b72da6e2e419ebeaf4de9674Brian Attwell            }
1671b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell        } else {
1672b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell            super.onBackPressed();
1673b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell        }
1674b7e4364d6536449271ac4534dbeb7430134c096bBrian Attwell    }
1675b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
16768a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    @Override
16778a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    public void finish() {
16788a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        super.finish();
16798a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
16808a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        // override transitions to skip the standard window animations
16818a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        overridePendingTransition(0, 0);
16828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    }
16838a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
1684eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos    private final LoaderCallbacks<List<ContactInteraction>> mLoaderInteractionsCallbacks =
1685b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            new LoaderCallbacks<List<ContactInteraction>>() {
1686b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
1687b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        @Override
1688b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        public Loader<List<ContactInteraction>> onCreateLoader(int id, Bundle args) {
1689b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            Log.v(TAG, "onCreateLoader");
1690b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            Loader<List<ContactInteraction>> loader = null;
1691b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            switch (id) {
1692b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                case LOADER_SMS_ID:
1693b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                    Log.v(TAG, "LOADER_SMS_ID");
1694b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                    loader = new SmsInteractionsLoader(
1695b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                            QuickContactActivity.this,
1696ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos                            args.getStringArray(KEY_LOADER_EXTRA_PHONES),
1697b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                            MAX_SMS_RETRIEVE);
1698b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                    break;
1699899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos                case LOADER_CALENDAR_ID:
1700899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos                    Log.v(TAG, "LOADER_CALENDAR_ID");
1701ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos                    final String[] emailsArray = args.getStringArray(KEY_LOADER_EXTRA_EMAILS);
1702ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos                    List<String> emailsList = null;
1703ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos                    if (emailsArray != null) {
1704ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos                        emailsList = Arrays.asList(args.getStringArray(KEY_LOADER_EXTRA_EMAILS));
1705ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos                    }
1706899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos                    loader = new CalendarInteractionsLoader(
1707899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos                            QuickContactActivity.this,
1708ae4cafed699b7cd6c5d4dad855bc0d4948452983Paul Soulos                            emailsList,
1709899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos                            MAX_FUTURE_CALENDAR_RETRIEVE,
1710899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos                            MAX_PAST_CALENDAR_RETRIEVE,
1711899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos                            FUTURE_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR,
1712899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos                            PAST_MILLISECOND_TO_SEARCH_LOCAL_CALENDAR);
1713899aa21e911ee7170beab228d44d7fed68c414e4Paul Soulos                    break;
1714ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos                case LOADER_CALL_LOG_ID:
1715ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos                    Log.v(TAG, "LOADER_CALL_LOG_ID");
1716ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos                    loader = new CallLogInteractionsLoader(
1717ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos                            QuickContactActivity.this,
1718ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos                            args.getStringArray(KEY_LOADER_EXTRA_PHONES),
1719ab840448dd00ce3f02ec7317df69b24613ade8a9Paul Soulos                            MAX_CALL_LOG_RETRIEVE);
1720b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            }
1721b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            return loader;
1722b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        }
1723b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
1724b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        @Override
1725b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        public void onLoadFinished(Loader<List<ContactInteraction>> loader,
1726b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                List<ContactInteraction> data) {
1727b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            mRecentLoaderResults.put(loader.getId(), data);
1728b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
1729b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            if (isAllRecentDataLoaded()) {
1730b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                bindRecentData();
1731b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            }
1732b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        }
1733b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
1734b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        @Override
1735b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        public void onLoaderReset(Loader<List<ContactInteraction>> loader) {
1736b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            mRecentLoaderResults.remove(loader.getId());
1737b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        }
1738b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    };
1739b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
1740b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    private boolean isAllRecentDataLoaded() {
1741b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        return mRecentLoaderResults.size() == mRecentLoaderIds.length;
1742b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    }
1743b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
1744b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    private void bindRecentData() {
1745eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        final List<ContactInteraction> allInteractions = new ArrayList<>();
1746b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) {
1747b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            allInteractions.addAll(loaderInteractions);
1748b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        }
1749b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
1750b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        // Sort the interactions by most recent
1751b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        Collections.sort(allInteractions, new Comparator<ContactInteraction>() {
1752b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            @Override
1753b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            public int compare(ContactInteraction a, ContactInteraction b) {
1754b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                return a.getInteractionDate() >= b.getInteractionDate() ? -1 : 1;
1755b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            }
1756b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        });
1757b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos
175897ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos        // Wrap each interaction in its own list so that an icon is displayed for each entry
175960e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos        List<List<Entry>> interactionsWrapper = new ArrayList<>();
176097ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos        for (Entry contactInteraction : contactInteractionsToEntries(allInteractions)) {
176197ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos            List<Entry> entryListWrapper = new ArrayList<>(1);
176297ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos            entryListWrapper.add(contactInteraction);
176397ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos            interactionsWrapper.add(entryListWrapper);
176497ed5019d75bd6afdfd5f3a8150161d9d9441275Paul Soulos        }
1765b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        if (allInteractions.size() > 0) {
176660e5108e39e54d0a7e4c6924b33597d338be3fb9Paul Soulos            mRecentCard.initialize(interactionsWrapper,
1767b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos                    /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN,
1768c8e2a91807b581194566eb45019fa16e2268b462Paul Soulos                    /* isExpanded = */ mRecentCard.isExpanded(), /* isAlwaysExpanded = */ false,
17690cda9aeb01f1922fce2a9e87ae4c0146c177b4f0Paul Soulos                    mExpandingEntryCardViewListener, mScroller);
1770b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos            mRecentCard.setVisibility(View.VISIBLE);
1771b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos        }
1772eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos
1773eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        // About card is initialized along with the contact card, but since it appears after
1774eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        // the recent card in the UI, we hold off until making it visible until the recent card
1775eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        // is also ready to avoid stuttering.
1776eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        if (mAboutCard.shouldShow()) {
1777eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            mAboutCard.setVisibility(View.VISIBLE);
1778eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } else {
1779eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            mAboutCard.setVisibility(View.GONE);
1780eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        }
1781b3054e551173887029c55cb10b83f1afb7f8a6fePaul Soulos    }
17828a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
17838a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    @Override
17848a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    protected void onStop() {
17858a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        super.onStop();
17868a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell
17878a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        if (mEntriesAndActionsTask != null) {
17888a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            // Once the activity is stopped, we will no longer want to bind mEntriesAndActionsTask's
17898a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            // results on the UI thread. In some circumstances Activities are killed without
17908a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            // onStop() being called. This is not a problem, because in these circumstances
17918a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            // the entire process will be killed.
17928a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell            mEntriesAndActionsTask.cancel(/* mayInterruptIfRunning = */ false);
17938a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell        }
17948a6f4ade05e5a8a89d91078ef9c22944450ac8baBrian Attwell    }
179523889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos
179623889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos    /**
1797d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell     * Returns true if it is possible to edit the current contact.
1798d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell     */
1799d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    private boolean isContactEditable() {
1800d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        return mContactData != null && !mContactData.isDirectoryEntry();
1801d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    }
1802d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
1803a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell    /**
1804a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell     * Returns true if it is possible to share the current contact.
1805a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell     */
1806a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell    private boolean isContactShareable() {
1807a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell        return mContactData != null && !mContactData.isDirectoryEntry();
1808a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell    }
1809a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell
18106095369885edcca566a812b551886e29c7ff8039Brian Attwell    private Intent getEditContactIntent() {
181163176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell        final Intent intent = new Intent(Intent.ACTION_EDIT, mContactData.getLookupUri());
1812d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        mContactLoader.cacheResult();
1813d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
18146095369885edcca566a812b551886e29c7ff8039Brian Attwell        return intent;
18156095369885edcca566a812b551886e29c7ff8039Brian Attwell    }
18166095369885edcca566a812b551886e29c7ff8039Brian Attwell
18176095369885edcca566a812b551886e29c7ff8039Brian Attwell    private void editContact() {
1818a42ef76251778161d27bc07db214b8c81720e476Paul Soulos        mHasIntentLaunched = true;
18196095369885edcca566a812b551886e29c7ff8039Brian Attwell        startActivityForResult(getEditContactIntent(), REQUEST_CODE_CONTACT_EDITOR_ACTIVITY);
1820d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    }
1821d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
1822d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    private void toggleStar(MenuItem starredMenuItem) {
1823d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        // Make sure there is a contact
182463176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell        if (mContactData != null) {
1825d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            // Read the current starred value from the UI instead of using the last
1826d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            // loaded state. This allows rapid tapping without writing the same
1827d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            // value several times
1828d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            final boolean isStarred = starredMenuItem.isChecked();
1829d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
1830d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            // To improve responsiveness, swap out the picture (and tag) in the UI already
1831333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos            ContactDisplayUtils.configureStarredMenuItem(starredMenuItem,
1832d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    mContactData.isDirectoryEntry(), mContactData.isUserProfile(),
1833d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    !isStarred);
1834d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
1835d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            // Now perform the real save
1836eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos            final Intent intent = ContactSaveService.createSetStarredIntent(
183763176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell                    QuickContactActivity.this, mContactData.getLookupUri(), !isStarred);
1838d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            startService(intent);
183935ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell
184035ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell            final CharSequence accessibilityText = !isStarred
184135ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell                    ? getResources().getText(R.string.description_action_menu_add_star)
184235ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell                    : getResources().getText(R.string.description_action_menu_remove_star);
184335ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell            // Accessibility actions need to have an associated view. We can't access the MenuItem's
184435ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell            // underlying view, so put this accessibility action on the root view.
184535ccdba7b8b2270204f7f96d824d258e408fe6efBrian Attwell            mScroller.announceForAccessibility(accessibilityText);
1846d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        }
1847d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    }
1848d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
1849752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell    /**
1850752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell     * Calls into the contacts provider to get a pre-authorized version of the given URI.
1851752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell     */
1852752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell    private Uri getPreAuthorizedUri(Uri uri) {
1853752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        final Bundle uriBundle = new Bundle();
1854752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        uriBundle.putParcelable(ContactsContract.Authorization.KEY_URI_TO_AUTHORIZE, uri);
1855752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        final Bundle authResponse = getContentResolver().call(
1856752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                ContactsContract.AUTHORITY_URI,
1857752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                ContactsContract.Authorization.AUTHORIZATION_METHOD,
1858752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                null,
1859752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                uriBundle);
1860752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        if (authResponse != null) {
1861752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell            return (Uri) authResponse.getParcelable(
1862752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                    ContactsContract.Authorization.KEY_AUTHORIZED_URI);
1863752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        } else {
1864752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell            return uri;
1865752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        }
1866752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell    }
18672d150da246632b1649999cfabed776133b097775Brian Attwell
1868752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell    private void shareContact() {
1869752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        final String lookupKey = mContactData.getLookupKey();
1870752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey);
1871752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        if (mContactData.isUserProfile()) {
1872752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell            // User is sharing the profile.  We don't want to force the receiver to have
1873752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell            // the highly-privileged READ_PROFILE permission, so we need to request a
1874752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell            // pre-authorized URI from the provider.
1875752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell            shareUri = getPreAuthorizedUri(shareUri);
1876752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        }
1877752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell
1878752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        final Intent intent = new Intent(Intent.ACTION_SEND);
1879752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        intent.setType(Contacts.CONTENT_VCARD_TYPE);
1880752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        intent.putExtra(Intent.EXTRA_STREAM, shareUri);
1881752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell
1882752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        // Launch chooser to share contact via
1883752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        final CharSequence chooseTitle = getText(R.string.share_via);
1884752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        final Intent chooseIntent = Intent.createChooser(intent, chooseTitle);
1885752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell
1886752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        try {
1887a42ef76251778161d27bc07db214b8c81720e476Paul Soulos            mHasIntentLaunched = true;
1888752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell            this.startActivity(chooseIntent);
1889eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        } catch (final ActivityNotFoundException ex) {
1890752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell            Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show();
1891752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        }
1892752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell    }
1893752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell
1894752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell    /**
1895752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell     * Creates a launcher shortcut with the current contact.
1896752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell     */
1897752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell    private void createLauncherShortcutWithContact() {
1898752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell        final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this,
1899752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                new OnShortcutIntentCreatedListener() {
1900752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell
1901752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                    @Override
1902752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                    public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) {
1903752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                        // Broadcast the shortcutIntent to the launcher to create a
1904752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                        // shortcut to this contact
1905752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                        shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT);
1906752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                        QuickContactActivity.this.sendBroadcast(shortcutIntent);
1907752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell
1908752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                        // Send a toast to give feedback to the user that a shortcut to this
1909752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                        // contact was added to the launcher.
1910752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                        Toast.makeText(QuickContactActivity.this,
1911752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                                R.string.createContactShortcutSuccessful,
1912752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                                Toast.LENGTH_SHORT).show();
1913752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                    }
1914752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell
1915752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                });
191663176c96f33b5a0bcb25816c80889bb11e5c7152Brian Attwell        builder.createContactShortcutIntent(mContactData.getLookupUri());
1917752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell    }
1918752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell
1919d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    @Override
1920d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    public boolean onCreateOptionsMenu(Menu menu) {
1921eb64a4b5c51b39fe56ba4ef97dfff73fdcdf8c75Paul Soulos        final MenuInflater inflater = getMenuInflater();
1922d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        inflater.inflate(R.menu.quickcontact, menu);
1923d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        return true;
1924d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    }
1925d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
1926d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    @Override
1927d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    public boolean onPrepareOptionsMenu(Menu menu) {
1928d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        if (mContactData != null) {
1929d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            final MenuItem starredMenuItem = menu.findItem(R.id.menu_star);
1930333091ae754ddfc25714c14b9b89534be24379f9Paul Soulos            ContactDisplayUtils.configureStarredMenuItem(starredMenuItem,
1931d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    mContactData.isDirectoryEntry(), mContactData.isUserProfile(),
1932d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    mContactData.getStarred());
1933a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell
1934d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            // Configure edit MenuItem
1935d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            final MenuItem editMenuItem = menu.findItem(R.id.menu_edit);
1936d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            editMenuItem.setVisible(true);
1937d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            if (DirectoryContactUtil.isDirectoryContact(mContactData) || InvisibleContactUtil
1938d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    .isInvisibleAndAddable(mContactData, this)) {
193930cfd121ad8c8adb83cf417ff1d40a8ba1e3761dBrian Attwell                editMenuItem.setIcon(R.drawable.ic_person_add_tinted_24dp);
19402e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell                editMenuItem.setTitle(R.string.menu_add_contact);
1941d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            } else if (isContactEditable()) {
1942d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                editMenuItem.setIcon(R.drawable.ic_create_24dp);
19432e4214c79170cdb6c1b8b6ff0408925d3f512becBrian Attwell                editMenuItem.setTitle(R.string.menu_editContact);
1944d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            } else {
1945d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                editMenuItem.setVisible(false);
1946d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            }
1947a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell
1948a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell            final MenuItem shareMenuItem = menu.findItem(R.id.menu_share);
1949a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell            shareMenuItem.setVisible(isContactShareable());
1950a41d6d1c9d87fe81630426f537bdb864c1ee6db4Brian Attwell
19518a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos            return true;
1952d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        }
19538a6d0022b07640d4a1fb8b264c8822bbab2981adPaul Soulos        return false;
1954d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    }
1955d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell
1956d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    @Override
1957d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell    public boolean onOptionsItemSelected(MenuItem item) {
1958d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        switch (item.getItemId()) {
1959d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            case R.id.menu_star:
1960d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                toggleStar(item);
1961d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                return true;
1962d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            case R.id.menu_edit:
1963d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                if (DirectoryContactUtil.isDirectoryContact(mContactData)) {
1964d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    DirectoryContactUtil.addToMyContacts(mContactData, this, getFragmentManager(),
1965d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                            mSelectAccountFragmentListener);
1966d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) {
1967d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    InvisibleContactUtil.addToDefaultGroup(mContactData, this);
1968d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                } else if (isContactEditable()) {
1969d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                    editContact();
1970d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                }
1971d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                return true;
1972752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell            case R.id.menu_share:
1973752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                shareContact();
1974752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                return true;
1975752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell            case R.id.menu_create_contact_shortcut:
1976752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                createLauncherShortcutWithContact();
1977752cccf954bd6070c5fb623875314951c8e9849dBrian Attwell                return true;
1978d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell            default:
1979d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell                return super.onOptionsItemSelected(item);
1980d28851f436c39a83f02d3b405fd91f0fb4833b2aBrian Attwell        }
198123889ba7ca18ed4ea56248355438a734511bc0b7Paul Soulos    }
1982edb576aab33efff623691a89ace3c76cb2ff12d1Daniel Lehmann}
1983