Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.widget; |
| 18 | |
Artur Satayev | ed5a6ae | 2019-12-10 17:47:54 +0000 | [diff] [blame] | 19 | import android.compat.annotation.UnsupportedAppUsage; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 20 | import android.content.AsyncQueryHandler; |
| 21 | import android.content.ContentResolver; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.content.res.TypedArray; |
| 25 | import android.database.Cursor; |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 26 | import android.graphics.Canvas; |
Mark Wagner | f5935a9 | 2009-09-22 13:49:26 -0700 | [diff] [blame] | 27 | import android.graphics.drawable.Drawable; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 28 | import android.net.Uri; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 29 | import android.os.Bundle; |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 30 | import android.provider.ContactsContract.CommonDataKinds.Email; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 31 | import android.provider.ContactsContract.Contacts; |
| 32 | import android.provider.ContactsContract.Intents; |
| 33 | import android.provider.ContactsContract.PhoneLookup; |
Tadashi G. Takaoka | 01fd4e1 | 2009-10-01 18:10:46 -0700 | [diff] [blame] | 34 | import android.provider.ContactsContract.QuickContact; |
Dmitri Plotnikov | ea36747 | 2009-09-18 15:04:58 -0700 | [diff] [blame] | 35 | import android.provider.ContactsContract.RawContacts; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 36 | import android.util.AttributeSet; |
| 37 | import android.view.View; |
| 38 | import android.view.View.OnClickListener; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 39 | |
Aurimas Liutikas | 99441c5 | 2016-10-11 16:48:32 -0700 | [diff] [blame] | 40 | import com.android.internal.R; |
| 41 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 42 | /** |
Evan Millar | c1a2a82 | 2009-09-29 18:02:06 -0700 | [diff] [blame] | 43 | * Widget used to show an image with the standard QuickContact badge |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 44 | * and on-click behavior. |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 45 | */ |
Evan Millar | c1a2a82 | 2009-09-29 18:02:06 -0700 | [diff] [blame] | 46 | public class QuickContactBadge extends ImageView implements OnClickListener { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 47 | private Uri mContactUri; |
| 48 | private String mContactEmail; |
| 49 | private String mContactPhone; |
Mathew Inwood | 978c6e2 | 2018-08-21 15:58:55 +0100 | [diff] [blame] | 50 | @UnsupportedAppUsage |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 51 | private Drawable mOverlay; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 52 | private QueryHandler mQueryHandler; |
Evan Millar | 9a20aa7 | 2010-04-13 09:51:21 -0700 | [diff] [blame] | 53 | private Drawable mDefaultAvatar; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 54 | private Bundle mExtras = null; |
Brian Attwell | 7035f2b | 2015-02-25 20:06:08 -0800 | [diff] [blame] | 55 | private String mPrioritizedMimeType; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 56 | |
| 57 | protected String[] mExcludeMimes = null; |
| 58 | |
| 59 | static final private int TOKEN_EMAIL_LOOKUP = 0; |
| 60 | static final private int TOKEN_PHONE_LOOKUP = 1; |
| 61 | static final private int TOKEN_EMAIL_LOOKUP_AND_TRIGGER = 2; |
| 62 | static final private int TOKEN_PHONE_LOOKUP_AND_TRIGGER = 3; |
| 63 | |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 64 | static final private String EXTRA_URI_CONTENT = "uri_content"; |
| 65 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 66 | static final String[] EMAIL_LOOKUP_PROJECTION = new String[] { |
Dmitri Plotnikov | ea36747 | 2009-09-18 15:04:58 -0700 | [diff] [blame] | 67 | RawContacts.CONTACT_ID, |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 68 | Contacts.LOOKUP_KEY, |
| 69 | }; |
Tadashi G. Takaoka | 01fd4e1 | 2009-10-01 18:10:46 -0700 | [diff] [blame] | 70 | static final int EMAIL_ID_COLUMN_INDEX = 0; |
| 71 | static final int EMAIL_LOOKUP_STRING_COLUMN_INDEX = 1; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 72 | |
| 73 | static final String[] PHONE_LOOKUP_PROJECTION = new String[] { |
| 74 | PhoneLookup._ID, |
| 75 | PhoneLookup.LOOKUP_KEY, |
| 76 | }; |
Tadashi G. Takaoka | 01fd4e1 | 2009-10-01 18:10:46 -0700 | [diff] [blame] | 77 | static final int PHONE_ID_COLUMN_INDEX = 0; |
| 78 | static final int PHONE_LOOKUP_STRING_COLUMN_INDEX = 1; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 79 | |
Evan Millar | c1a2a82 | 2009-09-29 18:02:06 -0700 | [diff] [blame] | 80 | public QuickContactBadge(Context context) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 81 | this(context, null); |
| 82 | } |
| 83 | |
Evan Millar | c1a2a82 | 2009-09-29 18:02:06 -0700 | [diff] [blame] | 84 | public QuickContactBadge(Context context, AttributeSet attrs) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 85 | this(context, attrs, 0); |
| 86 | } |
| 87 | |
Alan Viverette | 617feb9 | 2013-09-09 18:09:13 -0700 | [diff] [blame] | 88 | public QuickContactBadge(Context context, AttributeSet attrs, int defStyleAttr) { |
| 89 | this(context, attrs, defStyleAttr, 0); |
| 90 | } |
| 91 | |
| 92 | public QuickContactBadge( |
| 93 | Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 94 | super(context, attrs, defStyleAttr, defStyleRes); |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 95 | |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 96 | TypedArray styledAttributes = mContext.obtainStyledAttributes(R.styleable.Theme); |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 97 | mOverlay = styledAttributes.getDrawable( |
| 98 | com.android.internal.R.styleable.Theme_quickContactBadgeOverlay); |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 99 | styledAttributes.recycle(); |
| 100 | |
John Reck | d0374c6 | 2015-10-20 13:25:01 -0700 | [diff] [blame] | 101 | setOnClickListener(this); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | protected void onAttachedToWindow() { |
| 106 | super.onAttachedToWindow(); |
| 107 | |
Deepanshu Gupta | 34e9c69 | 2013-10-18 11:22:46 -0700 | [diff] [blame] | 108 | if (!isInEditMode()) { |
| 109 | mQueryHandler = new QueryHandler(mContext.getContentResolver()); |
| 110 | } |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Gilles Debunne | 5cba862 | 2011-01-12 19:52:56 -0800 | [diff] [blame] | 113 | @Override |
| 114 | protected void drawableStateChanged() { |
| 115 | super.drawableStateChanged(); |
Alan Viverette | ad0020f | 2015-09-04 10:10:42 -0400 | [diff] [blame] | 116 | |
| 117 | final Drawable overlay = mOverlay; |
| 118 | if (overlay != null && overlay.isStateful() |
| 119 | && overlay.setState(getDrawableState())) { |
| 120 | invalidateDrawable(overlay); |
Gilles Debunne | 5cba862 | 2011-01-12 19:52:56 -0800 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
Alan Viverette | cebc6ba | 2014-06-13 15:52:13 -0700 | [diff] [blame] | 124 | @Override |
Alan Viverette | 8de1494 | 2014-06-18 18:05:15 -0700 | [diff] [blame] | 125 | public void drawableHotspotChanged(float x, float y) { |
| 126 | super.drawableHotspotChanged(x, y); |
Alan Viverette | cebc6ba | 2014-06-13 15:52:13 -0700 | [diff] [blame] | 127 | |
| 128 | if (mOverlay != null) { |
| 129 | mOverlay.setHotspot(x, y); |
| 130 | } |
| 131 | } |
| 132 | |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 133 | /** This call has no effect anymore, as there is only one QuickContact mode */ |
| 134 | @SuppressWarnings("unused") |
Evan Millar | e3ec997 | 2009-09-30 19:37:36 -0700 | [diff] [blame] | 135 | public void setMode(int size) { |
Evan Millar | e3ec997 | 2009-09-30 19:37:36 -0700 | [diff] [blame] | 136 | } |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 137 | |
Brian Attwell | 7035f2b | 2015-02-25 20:06:08 -0800 | [diff] [blame] | 138 | /** |
| 139 | * Set which mimetype should be prioritized in the QuickContacts UI. For example, passing the |
| 140 | * value {@link Email#CONTENT_ITEM_TYPE} can cause emails to be displayed more prominently in |
| 141 | * QuickContacts. |
| 142 | */ |
| 143 | public void setPrioritizedMimeType(String prioritizedMimeType) { |
| 144 | mPrioritizedMimeType = prioritizedMimeType; |
| 145 | } |
| 146 | |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 147 | @Override |
| 148 | protected void onDraw(Canvas canvas) { |
| 149 | super.onDraw(canvas); |
| 150 | |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 151 | if (!isEnabled()) { |
| 152 | // not clickable? don't show triangle |
| 153 | return; |
| 154 | } |
| 155 | |
Gilles Debunne | 5cba862 | 2011-01-12 19:52:56 -0800 | [diff] [blame] | 156 | if (mOverlay == null || mOverlay.getIntrinsicWidth() == 0 || |
| 157 | mOverlay.getIntrinsicHeight() == 0) { |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 158 | // nothing to draw |
| 159 | return; |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | mOverlay.setBounds(0, 0, getWidth(), getHeight()); |
| 163 | |
| 164 | if (mPaddingTop == 0 && mPaddingLeft == 0) { |
| 165 | mOverlay.draw(canvas); |
| 166 | } else { |
| 167 | int saveCount = canvas.getSaveCount(); |
| 168 | canvas.save(); |
| 169 | canvas.translate(mPaddingLeft, mPaddingTop); |
| 170 | mOverlay.draw(canvas); |
| 171 | canvas.restoreToCount(saveCount); |
| 172 | } |
| 173 | } |
| 174 | |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 175 | /** True if a contact, an email address or a phone number has been assigned */ |
| 176 | private boolean isAssigned() { |
| 177 | return mContactUri != null || mContactEmail != null || mContactPhone != null; |
| 178 | } |
| 179 | |
Evan Millar | 9a20aa7 | 2010-04-13 09:51:21 -0700 | [diff] [blame] | 180 | /** |
| 181 | * Resets the contact photo to the default state. |
| 182 | */ |
| 183 | public void setImageToDefault() { |
| 184 | if (mDefaultAvatar == null) { |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 185 | mDefaultAvatar = mContext.getDrawable(R.drawable.ic_contact_picture); |
Evan Millar | 9a20aa7 | 2010-04-13 09:51:21 -0700 | [diff] [blame] | 186 | } |
| 187 | setImageDrawable(mDefaultAvatar); |
| 188 | } |
Evan Millar | e3ec997 | 2009-09-30 19:37:36 -0700 | [diff] [blame] | 189 | |
| 190 | /** |
Evan Millar | c1a2a82 | 2009-09-29 18:02:06 -0700 | [diff] [blame] | 191 | * Assign the contact uri that this QuickContactBadge should be associated |
| 192 | * with. Note that this is only used for displaying the QuickContact window and |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 193 | * won't bind the contact's photo for you. Call {@link #setImageDrawable(Drawable)} to set the |
| 194 | * photo. |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 195 | * |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 196 | * @param contactUri Either a {@link Contacts#CONTENT_URI} or |
| 197 | * {@link Contacts#CONTENT_LOOKUP_URI} style URI. |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 198 | */ |
| 199 | public void assignContactUri(Uri contactUri) { |
| 200 | mContactUri = contactUri; |
Mark Wagner | f5935a9 | 2009-09-22 13:49:26 -0700 | [diff] [blame] | 201 | mContactEmail = null; |
| 202 | mContactPhone = null; |
| 203 | onContactUriChanged(); |
| 204 | } |
| 205 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 206 | /** |
| 207 | * Assign a contact based on an email address. This should only be used when |
| 208 | * the contact's URI is not available, as an extra query will have to be |
| 209 | * performed to lookup the URI based on the email. |
| 210 | * |
| 211 | * @param emailAddress The email address of the contact. |
| 212 | * @param lazyLookup If this is true, the lookup query will not be performed |
| 213 | * until this view is clicked. |
| 214 | */ |
| 215 | public void assignContactFromEmail(String emailAddress, boolean lazyLookup) { |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 216 | assignContactFromEmail(emailAddress, lazyLookup, null); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Assign a contact based on an email address. This should only be used when |
| 221 | * the contact's URI is not available, as an extra query will have to be |
| 222 | * performed to lookup the URI based on the email. |
| 223 | |
| 224 | @param emailAddress The email address of the contact. |
| 225 | @param lazyLookup If this is true, the lookup query will not be performed |
| 226 | until this view is clicked. |
| 227 | @param extras A bundle of extras to populate the contact edit page with if the contact |
| 228 | is not found and the user chooses to add the email address to an existing contact or |
| 229 | create a new contact. Uses the same string constants as those found in |
Yorke Lee | 3e839f4 | 2013-01-15 16:46:00 -0800 | [diff] [blame] | 230 | {@link android.provider.ContactsContract.Intents.Insert} |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 231 | */ |
| 232 | |
| 233 | public void assignContactFromEmail(String emailAddress, boolean lazyLookup, Bundle extras) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 234 | mContactEmail = emailAddress; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 235 | mExtras = extras; |
Deepanshu Gupta | 34e9c69 | 2013-10-18 11:22:46 -0700 | [diff] [blame] | 236 | if (!lazyLookup && mQueryHandler != null) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 237 | mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP, null, |
| 238 | Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)), |
| 239 | EMAIL_LOOKUP_PROJECTION, null, null, null); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 240 | } else { |
| 241 | mContactUri = null; |
Mark Wagner | f5935a9 | 2009-09-22 13:49:26 -0700 | [diff] [blame] | 242 | onContactUriChanged(); |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 246 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 247 | /** |
| 248 | * Assign a contact based on a phone number. This should only be used when |
| 249 | * the contact's URI is not available, as an extra query will have to be |
| 250 | * performed to lookup the URI based on the phone number. |
| 251 | * |
| 252 | * @param phoneNumber The phone number of the contact. |
| 253 | * @param lazyLookup If this is true, the lookup query will not be performed |
| 254 | * until this view is clicked. |
| 255 | */ |
| 256 | public void assignContactFromPhone(String phoneNumber, boolean lazyLookup) { |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 257 | assignContactFromPhone(phoneNumber, lazyLookup, new Bundle()); |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Assign a contact based on a phone number. This should only be used when |
| 262 | * the contact's URI is not available, as an extra query will have to be |
| 263 | * performed to lookup the URI based on the phone number. |
| 264 | * |
| 265 | * @param phoneNumber The phone number of the contact. |
| 266 | * @param lazyLookup If this is true, the lookup query will not be performed |
| 267 | * until this view is clicked. |
| 268 | * @param extras A bundle of extras to populate the contact edit page with if the contact |
| 269 | * is not found and the user chooses to add the phone number to an existing contact or |
| 270 | * create a new contact. Uses the same string constants as those found in |
Yorke Lee | 3e839f4 | 2013-01-15 16:46:00 -0800 | [diff] [blame] | 271 | * {@link android.provider.ContactsContract.Intents.Insert} |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 272 | */ |
| 273 | public void assignContactFromPhone(String phoneNumber, boolean lazyLookup, Bundle extras) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 274 | mContactPhone = phoneNumber; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 275 | mExtras = extras; |
Deepanshu Gupta | 34e9c69 | 2013-10-18 11:22:46 -0700 | [diff] [blame] | 276 | if (!lazyLookup && mQueryHandler != null) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 277 | mQueryHandler.startQuery(TOKEN_PHONE_LOOKUP, null, |
| 278 | Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, mContactPhone), |
| 279 | PHONE_LOOKUP_PROJECTION, null, null, null); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 280 | } else { |
| 281 | mContactUri = null; |
Mark Wagner | f5935a9 | 2009-09-22 13:49:26 -0700 | [diff] [blame] | 282 | onContactUriChanged(); |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
Yorke Lee | a702ccd | 2014-04-28 12:41:44 -0700 | [diff] [blame] | 286 | /** |
| 287 | * Assigns the drawable that is to be drawn on top of the assigned contact photo. |
| 288 | * |
| 289 | * @param overlay Drawable to be drawn over the assigned contact photo. Must have a non-zero |
| 290 | * instrinsic width and height. |
| 291 | */ |
| 292 | public void setOverlay(Drawable overlay) { |
| 293 | mOverlay = overlay; |
| 294 | } |
| 295 | |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 296 | private void onContactUriChanged() { |
| 297 | setEnabled(isAssigned()); |
| 298 | } |
| 299 | |
| 300 | @Override |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 301 | public void onClick(View v) { |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 302 | // If contact has been assigned, mExtras should no longer be null, but do a null check |
| 303 | // anyway just in case assignContactFromPhone or Email was called with a null bundle or |
| 304 | // wasn't assigned previously. |
| 305 | final Bundle extras = (mExtras == null) ? new Bundle() : mExtras; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 306 | if (mContactUri != null) { |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 307 | QuickContact.showQuickContact(getContext(), QuickContactBadge.this, mContactUri, |
Brian Attwell | 7035f2b | 2015-02-25 20:06:08 -0800 | [diff] [blame] | 308 | mExcludeMimes, mPrioritizedMimeType); |
Deepanshu Gupta | 34e9c69 | 2013-10-18 11:22:46 -0700 | [diff] [blame] | 309 | } else if (mContactEmail != null && mQueryHandler != null) { |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 310 | extras.putString(EXTRA_URI_CONTENT, mContactEmail); |
| 311 | mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP_AND_TRIGGER, extras, |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 312 | Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)), |
| 313 | EMAIL_LOOKUP_PROJECTION, null, null, null); |
Deepanshu Gupta | 34e9c69 | 2013-10-18 11:22:46 -0700 | [diff] [blame] | 314 | } else if (mContactPhone != null && mQueryHandler != null) { |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 315 | extras.putString(EXTRA_URI_CONTENT, mContactPhone); |
| 316 | mQueryHandler.startQuery(TOKEN_PHONE_LOOKUP_AND_TRIGGER, extras, |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 317 | Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, mContactPhone), |
| 318 | PHONE_LOOKUP_PROJECTION, null, null, null); |
| 319 | } else { |
| 320 | // If a contact hasn't been assigned, don't react to click. |
| 321 | return; |
| 322 | } |
| 323 | } |
| 324 | |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 325 | @Override |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 326 | public CharSequence getAccessibilityClassName() { |
| 327 | return QuickContactBadge.class.getName(); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 328 | } |
| 329 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 330 | /** |
| 331 | * Set a list of specific MIME-types to exclude and not display. For |
| 332 | * example, this can be used to hide the {@link Contacts#CONTENT_ITEM_TYPE} |
| 333 | * profile icon. |
| 334 | */ |
| 335 | public void setExcludeMimes(String[] excludeMimes) { |
| 336 | mExcludeMimes = excludeMimes; |
| 337 | } |
| 338 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 339 | private class QueryHandler extends AsyncQueryHandler { |
| 340 | |
| 341 | public QueryHandler(ContentResolver cr) { |
| 342 | super(cr); |
| 343 | } |
| 344 | |
| 345 | @Override |
| 346 | protected void onQueryComplete(int token, Object cookie, Cursor cursor) { |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 347 | Uri lookupUri = null; |
| 348 | Uri createUri = null; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 349 | boolean trigger = false; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 350 | Bundle extras = (cookie != null) ? (Bundle) cookie : new Bundle(); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 351 | try { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 352 | switch(token) { |
| 353 | case TOKEN_PHONE_LOOKUP_AND_TRIGGER: |
| 354 | trigger = true; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 355 | createUri = Uri.fromParts("tel", extras.getString(EXTRA_URI_CONTENT), null); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 356 | |
Makoto Onuki | a362e1d | 2010-09-07 10:46:59 -0700 | [diff] [blame] | 357 | //$FALL-THROUGH$ |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 358 | case TOKEN_PHONE_LOOKUP: { |
| 359 | if (cursor != null && cursor.moveToFirst()) { |
| 360 | long contactId = cursor.getLong(PHONE_ID_COLUMN_INDEX); |
| 361 | String lookupKey = cursor.getString(PHONE_LOOKUP_STRING_COLUMN_INDEX); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 362 | lookupUri = Contacts.getLookupUri(contactId, lookupKey); |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 363 | } |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 364 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 365 | break; |
| 366 | } |
| 367 | case TOKEN_EMAIL_LOOKUP_AND_TRIGGER: |
| 368 | trigger = true; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 369 | createUri = Uri.fromParts("mailto", |
| 370 | extras.getString(EXTRA_URI_CONTENT), null); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 371 | |
Makoto Onuki | a362e1d | 2010-09-07 10:46:59 -0700 | [diff] [blame] | 372 | //$FALL-THROUGH$ |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 373 | case TOKEN_EMAIL_LOOKUP: { |
| 374 | if (cursor != null && cursor.moveToFirst()) { |
| 375 | long contactId = cursor.getLong(EMAIL_ID_COLUMN_INDEX); |
| 376 | String lookupKey = cursor.getString(EMAIL_LOOKUP_STRING_COLUMN_INDEX); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 377 | lookupUri = Contacts.getLookupUri(contactId, lookupKey); |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 378 | } |
Makoto Onuki | a362e1d | 2010-09-07 10:46:59 -0700 | [diff] [blame] | 379 | break; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | } finally { |
| 383 | if (cursor != null) { |
| 384 | cursor.close(); |
| 385 | } |
| 386 | } |
| 387 | |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 388 | mContactUri = lookupUri; |
Mark Wagner | f5935a9 | 2009-09-22 13:49:26 -0700 | [diff] [blame] | 389 | onContactUriChanged(); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 390 | |
Brian Attwell | 7035f2b | 2015-02-25 20:06:08 -0800 | [diff] [blame] | 391 | if (trigger && mContactUri != null) { |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 392 | // Found contact, so trigger QuickContact |
Brian Attwell | 7035f2b | 2015-02-25 20:06:08 -0800 | [diff] [blame] | 393 | QuickContact.showQuickContact(getContext(), QuickContactBadge.this, mContactUri, |
| 394 | mExcludeMimes, mPrioritizedMimeType); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 395 | } else if (createUri != null) { |
| 396 | // Prompt user to add this person to contacts |
| 397 | final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, createUri); |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 398 | if (extras != null) { |
| 399 | extras.remove(EXTRA_URI_CONTENT); |
| 400 | intent.putExtras(extras); |
| 401 | } |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 402 | getContext().startActivity(intent); |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | } |
| 406 | } |