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 | |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 19 | import com.android.internal.R; |
| 20 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 21 | import android.content.AsyncQueryHandler; |
| 22 | import android.content.ContentResolver; |
| 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.res.TypedArray; |
| 26 | import android.database.Cursor; |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 27 | import android.graphics.Canvas; |
Mark Wagner | f5935a9 | 2009-09-22 13:49:26 -0700 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 29 | import android.net.Uri; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 30 | import android.os.Bundle; |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 31 | import android.provider.ContactsContract.CommonDataKinds.Email; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 32 | import android.provider.ContactsContract.Contacts; |
| 33 | import android.provider.ContactsContract.Intents; |
| 34 | import android.provider.ContactsContract.PhoneLookup; |
Tadashi G. Takaoka | 01fd4e1 | 2009-10-01 18:10:46 -0700 | [diff] [blame] | 35 | import android.provider.ContactsContract.QuickContact; |
Dmitri Plotnikov | ea36747 | 2009-09-18 15:04:58 -0700 | [diff] [blame] | 36 | import android.provider.ContactsContract.RawContacts; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 37 | import android.util.AttributeSet; |
| 38 | import android.view.View; |
| 39 | import android.view.View.OnClickListener; |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 40 | import android.view.accessibility.AccessibilityEvent; |
| 41 | import android.view.accessibility.AccessibilityNodeInfo; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
Evan Millar | c1a2a82 | 2009-09-29 18:02:06 -0700 | [diff] [blame] | 44 | * Widget used to show an image with the standard QuickContact badge |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 45 | * and on-click behavior. |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 46 | */ |
Evan Millar | c1a2a82 | 2009-09-29 18:02:06 -0700 | [diff] [blame] | 47 | public class QuickContactBadge extends ImageView implements OnClickListener { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 48 | private Uri mContactUri; |
| 49 | private String mContactEmail; |
| 50 | private String mContactPhone; |
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; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 55 | |
| 56 | protected String[] mExcludeMimes = null; |
| 57 | |
| 58 | static final private int TOKEN_EMAIL_LOOKUP = 0; |
| 59 | static final private int TOKEN_PHONE_LOOKUP = 1; |
| 60 | static final private int TOKEN_EMAIL_LOOKUP_AND_TRIGGER = 2; |
| 61 | static final private int TOKEN_PHONE_LOOKUP_AND_TRIGGER = 3; |
| 62 | |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 63 | static final private String EXTRA_URI_CONTENT = "uri_content"; |
| 64 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 65 | static final String[] EMAIL_LOOKUP_PROJECTION = new String[] { |
Dmitri Plotnikov | ea36747 | 2009-09-18 15:04:58 -0700 | [diff] [blame] | 66 | RawContacts.CONTACT_ID, |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 67 | Contacts.LOOKUP_KEY, |
| 68 | }; |
Tadashi G. Takaoka | 01fd4e1 | 2009-10-01 18:10:46 -0700 | [diff] [blame] | 69 | static final int EMAIL_ID_COLUMN_INDEX = 0; |
| 70 | static final int EMAIL_LOOKUP_STRING_COLUMN_INDEX = 1; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 71 | |
| 72 | static final String[] PHONE_LOOKUP_PROJECTION = new String[] { |
| 73 | PhoneLookup._ID, |
| 74 | PhoneLookup.LOOKUP_KEY, |
| 75 | }; |
Tadashi G. Takaoka | 01fd4e1 | 2009-10-01 18:10:46 -0700 | [diff] [blame] | 76 | static final int PHONE_ID_COLUMN_INDEX = 0; |
| 77 | static final int PHONE_LOOKUP_STRING_COLUMN_INDEX = 1; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 78 | |
Evan Millar | c1a2a82 | 2009-09-29 18:02:06 -0700 | [diff] [blame] | 79 | public QuickContactBadge(Context context) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 80 | this(context, null); |
| 81 | } |
| 82 | |
Evan Millar | c1a2a82 | 2009-09-29 18:02:06 -0700 | [diff] [blame] | 83 | public QuickContactBadge(Context context, AttributeSet attrs) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 84 | this(context, attrs, 0); |
| 85 | } |
| 86 | |
Evan Millar | c1a2a82 | 2009-09-29 18:02:06 -0700 | [diff] [blame] | 87 | public QuickContactBadge(Context context, AttributeSet attrs, int defStyle) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 88 | super(context, attrs, defStyle); |
| 89 | |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 90 | TypedArray styledAttributes = mContext.obtainStyledAttributes(R.styleable.Theme); |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 91 | mOverlay = styledAttributes.getDrawable( |
| 92 | com.android.internal.R.styleable.Theme_quickContactBadgeOverlay); |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 93 | styledAttributes.recycle(); |
| 94 | |
Deepanshu Gupta | 34e9c69 | 2013-10-18 11:22:46 -0700 | [diff] [blame] | 95 | if (!isInEditMode()) { |
| 96 | mQueryHandler = new QueryHandler(mContext.getContentResolver()); |
| 97 | } |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 98 | setOnClickListener(this); |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Gilles Debunne | 5cba862 | 2011-01-12 19:52:56 -0800 | [diff] [blame] | 101 | @Override |
| 102 | protected void drawableStateChanged() { |
| 103 | super.drawableStateChanged(); |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 104 | if (mOverlay != null && mOverlay.isStateful()) { |
| 105 | mOverlay.setState(getDrawableState()); |
Gilles Debunne | 5cba862 | 2011-01-12 19:52:56 -0800 | [diff] [blame] | 106 | invalidate(); |
| 107 | } |
| 108 | } |
| 109 | |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 110 | /** This call has no effect anymore, as there is only one QuickContact mode */ |
| 111 | @SuppressWarnings("unused") |
Evan Millar | e3ec997 | 2009-09-30 19:37:36 -0700 | [diff] [blame] | 112 | public void setMode(int size) { |
Evan Millar | e3ec997 | 2009-09-30 19:37:36 -0700 | [diff] [blame] | 113 | } |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 114 | |
| 115 | @Override |
| 116 | protected void onDraw(Canvas canvas) { |
| 117 | super.onDraw(canvas); |
| 118 | |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 119 | if (!isEnabled()) { |
| 120 | // not clickable? don't show triangle |
| 121 | return; |
| 122 | } |
| 123 | |
Gilles Debunne | 5cba862 | 2011-01-12 19:52:56 -0800 | [diff] [blame] | 124 | if (mOverlay == null || mOverlay.getIntrinsicWidth() == 0 || |
| 125 | mOverlay.getIntrinsicHeight() == 0) { |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 126 | // nothing to draw |
| 127 | return; |
Gilles Debunne | 9235058 | 2011-01-07 19:39:26 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | mOverlay.setBounds(0, 0, getWidth(), getHeight()); |
| 131 | |
| 132 | if (mPaddingTop == 0 && mPaddingLeft == 0) { |
| 133 | mOverlay.draw(canvas); |
| 134 | } else { |
| 135 | int saveCount = canvas.getSaveCount(); |
| 136 | canvas.save(); |
| 137 | canvas.translate(mPaddingLeft, mPaddingTop); |
| 138 | mOverlay.draw(canvas); |
| 139 | canvas.restoreToCount(saveCount); |
| 140 | } |
| 141 | } |
| 142 | |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 143 | /** True if a contact, an email address or a phone number has been assigned */ |
| 144 | private boolean isAssigned() { |
| 145 | return mContactUri != null || mContactEmail != null || mContactPhone != null; |
| 146 | } |
| 147 | |
Evan Millar | 9a20aa7 | 2010-04-13 09:51:21 -0700 | [diff] [blame] | 148 | /** |
| 149 | * Resets the contact photo to the default state. |
| 150 | */ |
| 151 | public void setImageToDefault() { |
| 152 | if (mDefaultAvatar == null) { |
| 153 | mDefaultAvatar = getResources().getDrawable(R.drawable.ic_contact_picture); |
| 154 | } |
| 155 | setImageDrawable(mDefaultAvatar); |
| 156 | } |
Evan Millar | e3ec997 | 2009-09-30 19:37:36 -0700 | [diff] [blame] | 157 | |
| 158 | /** |
Evan Millar | c1a2a82 | 2009-09-29 18:02:06 -0700 | [diff] [blame] | 159 | * Assign the contact uri that this QuickContactBadge should be associated |
| 160 | * 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] | 161 | * won't bind the contact's photo for you. Call {@link #setImageDrawable(Drawable)} to set the |
| 162 | * photo. |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 163 | * |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 164 | * @param contactUri Either a {@link Contacts#CONTENT_URI} or |
| 165 | * {@link Contacts#CONTENT_LOOKUP_URI} style URI. |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 166 | */ |
| 167 | public void assignContactUri(Uri contactUri) { |
| 168 | mContactUri = contactUri; |
Mark Wagner | f5935a9 | 2009-09-22 13:49:26 -0700 | [diff] [blame] | 169 | mContactEmail = null; |
| 170 | mContactPhone = null; |
| 171 | onContactUriChanged(); |
| 172 | } |
| 173 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 174 | /** |
| 175 | * Assign a contact based on an email address. This should only be used when |
| 176 | * the contact's URI is not available, as an extra query will have to be |
| 177 | * performed to lookup the URI based on the email. |
| 178 | * |
| 179 | * @param emailAddress The email address of the contact. |
| 180 | * @param lazyLookup If this is true, the lookup query will not be performed |
| 181 | * until this view is clicked. |
| 182 | */ |
| 183 | public void assignContactFromEmail(String emailAddress, boolean lazyLookup) { |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 184 | assignContactFromEmail(emailAddress, lazyLookup, null); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Assign a contact based on an email address. This should only be used when |
| 189 | * the contact's URI is not available, as an extra query will have to be |
| 190 | * performed to lookup the URI based on the email. |
| 191 | |
| 192 | @param emailAddress The email address of the contact. |
| 193 | @param lazyLookup If this is true, the lookup query will not be performed |
| 194 | until this view is clicked. |
| 195 | @param extras A bundle of extras to populate the contact edit page with if the contact |
| 196 | is not found and the user chooses to add the email address to an existing contact or |
| 197 | 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] | 198 | {@link android.provider.ContactsContract.Intents.Insert} |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 199 | */ |
| 200 | |
| 201 | public void assignContactFromEmail(String emailAddress, boolean lazyLookup, Bundle extras) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 202 | mContactEmail = emailAddress; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 203 | mExtras = extras; |
Deepanshu Gupta | 34e9c69 | 2013-10-18 11:22:46 -0700 | [diff] [blame] | 204 | if (!lazyLookup && mQueryHandler != null) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 205 | mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP, null, |
| 206 | Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)), |
| 207 | EMAIL_LOOKUP_PROJECTION, null, null, null); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 208 | } else { |
| 209 | mContactUri = null; |
Mark Wagner | f5935a9 | 2009-09-22 13:49:26 -0700 | [diff] [blame] | 210 | onContactUriChanged(); |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 214 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 215 | /** |
| 216 | * Assign a contact based on a phone number. This should only be used when |
| 217 | * the contact's URI is not available, as an extra query will have to be |
| 218 | * performed to lookup the URI based on the phone number. |
| 219 | * |
| 220 | * @param phoneNumber The phone number of the contact. |
| 221 | * @param lazyLookup If this is true, the lookup query will not be performed |
| 222 | * until this view is clicked. |
| 223 | */ |
| 224 | public void assignContactFromPhone(String phoneNumber, boolean lazyLookup) { |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 225 | assignContactFromPhone(phoneNumber, lazyLookup, new Bundle()); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Assign a contact based on a phone number. This should only be used when |
| 230 | * the contact's URI is not available, as an extra query will have to be |
| 231 | * performed to lookup the URI based on the phone number. |
| 232 | * |
| 233 | * @param phoneNumber The phone number of the contact. |
| 234 | * @param lazyLookup If this is true, the lookup query will not be performed |
| 235 | * until this view is clicked. |
| 236 | * @param extras A bundle of extras to populate the contact edit page with if the contact |
| 237 | * is not found and the user chooses to add the phone number to an existing contact or |
| 238 | * 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] | 239 | * {@link android.provider.ContactsContract.Intents.Insert} |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 240 | */ |
| 241 | public void assignContactFromPhone(String phoneNumber, boolean lazyLookup, Bundle extras) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 242 | mContactPhone = phoneNumber; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 243 | mExtras = extras; |
Deepanshu Gupta | 34e9c69 | 2013-10-18 11:22:46 -0700 | [diff] [blame] | 244 | if (!lazyLookup && mQueryHandler != null) { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 245 | mQueryHandler.startQuery(TOKEN_PHONE_LOOKUP, null, |
| 246 | Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, mContactPhone), |
| 247 | PHONE_LOOKUP_PROJECTION, null, null, null); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 248 | } else { |
| 249 | mContactUri = null; |
Mark Wagner | f5935a9 | 2009-09-22 13:49:26 -0700 | [diff] [blame] | 250 | onContactUriChanged(); |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 254 | private void onContactUriChanged() { |
| 255 | setEnabled(isAssigned()); |
| 256 | } |
| 257 | |
| 258 | @Override |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 259 | public void onClick(View v) { |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 260 | // If contact has been assigned, mExtras should no longer be null, but do a null check |
| 261 | // anyway just in case assignContactFromPhone or Email was called with a null bundle or |
| 262 | // wasn't assigned previously. |
| 263 | final Bundle extras = (mExtras == null) ? new Bundle() : mExtras; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 264 | if (mContactUri != null) { |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 265 | QuickContact.showQuickContact(getContext(), QuickContactBadge.this, mContactUri, |
| 266 | QuickContact.MODE_LARGE, mExcludeMimes); |
Deepanshu Gupta | 34e9c69 | 2013-10-18 11:22:46 -0700 | [diff] [blame] | 267 | } else if (mContactEmail != null && mQueryHandler != null) { |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 268 | extras.putString(EXTRA_URI_CONTENT, mContactEmail); |
| 269 | mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP_AND_TRIGGER, extras, |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 270 | Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)), |
| 271 | EMAIL_LOOKUP_PROJECTION, null, null, null); |
Deepanshu Gupta | 34e9c69 | 2013-10-18 11:22:46 -0700 | [diff] [blame] | 272 | } else if (mContactPhone != null && mQueryHandler != null) { |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 273 | extras.putString(EXTRA_URI_CONTENT, mContactPhone); |
| 274 | mQueryHandler.startQuery(TOKEN_PHONE_LOOKUP_AND_TRIGGER, extras, |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 275 | Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, mContactPhone), |
| 276 | PHONE_LOOKUP_PROJECTION, null, null, null); |
| 277 | } else { |
| 278 | // If a contact hasn't been assigned, don't react to click. |
| 279 | return; |
| 280 | } |
| 281 | } |
| 282 | |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 283 | @Override |
| 284 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 285 | super.onInitializeAccessibilityEvent(event); |
| 286 | event.setClassName(QuickContactBadge.class.getName()); |
| 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 291 | super.onInitializeAccessibilityNodeInfo(info); |
| 292 | info.setClassName(QuickContactBadge.class.getName()); |
| 293 | } |
| 294 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 295 | /** |
| 296 | * Set a list of specific MIME-types to exclude and not display. For |
| 297 | * example, this can be used to hide the {@link Contacts#CONTENT_ITEM_TYPE} |
| 298 | * profile icon. |
| 299 | */ |
| 300 | public void setExcludeMimes(String[] excludeMimes) { |
| 301 | mExcludeMimes = excludeMimes; |
| 302 | } |
| 303 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 304 | private class QueryHandler extends AsyncQueryHandler { |
| 305 | |
| 306 | public QueryHandler(ContentResolver cr) { |
| 307 | super(cr); |
| 308 | } |
| 309 | |
| 310 | @Override |
| 311 | protected void onQueryComplete(int token, Object cookie, Cursor cursor) { |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 312 | Uri lookupUri = null; |
| 313 | Uri createUri = null; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 314 | boolean trigger = false; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 315 | Bundle extras = (cookie != null) ? (Bundle) cookie : new Bundle(); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 316 | try { |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 317 | switch(token) { |
| 318 | case TOKEN_PHONE_LOOKUP_AND_TRIGGER: |
| 319 | trigger = true; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 320 | createUri = Uri.fromParts("tel", extras.getString(EXTRA_URI_CONTENT), null); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 321 | |
Makoto Onuki | a362e1d | 2010-09-07 10:46:59 -0700 | [diff] [blame] | 322 | //$FALL-THROUGH$ |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 323 | case TOKEN_PHONE_LOOKUP: { |
| 324 | if (cursor != null && cursor.moveToFirst()) { |
| 325 | long contactId = cursor.getLong(PHONE_ID_COLUMN_INDEX); |
| 326 | String lookupKey = cursor.getString(PHONE_LOOKUP_STRING_COLUMN_INDEX); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 327 | lookupUri = Contacts.getLookupUri(contactId, lookupKey); |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 328 | } |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 329 | |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 330 | break; |
| 331 | } |
| 332 | case TOKEN_EMAIL_LOOKUP_AND_TRIGGER: |
| 333 | trigger = true; |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 334 | createUri = Uri.fromParts("mailto", |
| 335 | extras.getString(EXTRA_URI_CONTENT), null); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 336 | |
Makoto Onuki | a362e1d | 2010-09-07 10:46:59 -0700 | [diff] [blame] | 337 | //$FALL-THROUGH$ |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 338 | case TOKEN_EMAIL_LOOKUP: { |
| 339 | if (cursor != null && cursor.moveToFirst()) { |
| 340 | long contactId = cursor.getLong(EMAIL_ID_COLUMN_INDEX); |
| 341 | String lookupKey = cursor.getString(EMAIL_LOOKUP_STRING_COLUMN_INDEX); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 342 | lookupUri = Contacts.getLookupUri(contactId, lookupKey); |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 343 | } |
Makoto Onuki | a362e1d | 2010-09-07 10:46:59 -0700 | [diff] [blame] | 344 | break; |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | } finally { |
| 348 | if (cursor != null) { |
| 349 | cursor.close(); |
| 350 | } |
| 351 | } |
| 352 | |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 353 | mContactUri = lookupUri; |
Mark Wagner | f5935a9 | 2009-09-22 13:49:26 -0700 | [diff] [blame] | 354 | onContactUriChanged(); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 355 | |
| 356 | if (trigger && lookupUri != null) { |
Daniel Lehmann | e13e55b | 2011-08-07 19:51:28 -0700 | [diff] [blame] | 357 | // Found contact, so trigger QuickContact |
| 358 | QuickContact.showQuickContact(getContext(), QuickContactBadge.this, lookupUri, |
| 359 | QuickContact.MODE_LARGE, mExcludeMimes); |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 360 | } else if (createUri != null) { |
| 361 | // Prompt user to add this person to contacts |
| 362 | final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, createUri); |
Yorke Lee | 02f304f | 2013-01-14 08:57:43 -0800 | [diff] [blame] | 363 | if (extras != null) { |
| 364 | extras.remove(EXTRA_URI_CONTENT); |
| 365 | intent.putExtras(extras); |
| 366 | } |
Jeff Sharkey | 0050ee3 | 2009-09-17 16:11:32 -0700 | [diff] [blame] | 367 | getContext().startActivity(intent); |
Evan Millar | e727f18 | 2009-08-27 11:15:55 -0700 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | } |
| 371 | } |