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