QuickContactBadgepublic class QuickContactBadge extends ImageView implements android.view.View.OnClickListenerWidget used to show an image with the standard QuickContact badge
and on-click behavior. |
Fields Summary |
---|
private android.net.Uri | mContactUri | private String | mContactEmail | private String | mContactPhone | private android.graphics.drawable.Drawable | mOverlay | private QueryHandler | mQueryHandler | private android.graphics.drawable.Drawable | mDefaultAvatar | private android.os.Bundle | mExtras | protected String[] | mExcludeMimes | private static final int | TOKEN_EMAIL_LOOKUP | private static final int | TOKEN_PHONE_LOOKUP | private static final int | TOKEN_EMAIL_LOOKUP_AND_TRIGGER | private static final int | TOKEN_PHONE_LOOKUP_AND_TRIGGER | private static final String | EXTRA_URI_CONTENT | static final String[] | EMAIL_LOOKUP_PROJECTION | static final int | EMAIL_ID_COLUMN_INDEX | static final int | EMAIL_LOOKUP_STRING_COLUMN_INDEX | static final String[] | PHONE_LOOKUP_PROJECTION | static final int | PHONE_ID_COLUMN_INDEX | static final int | PHONE_LOOKUP_STRING_COLUMN_INDEX |
Constructors Summary |
---|
public QuickContactBadge(android.content.Context context)
this(context, null);
| public QuickContactBadge(android.content.Context context, android.util.AttributeSet attrs)
this(context, attrs, 0);
| public QuickContactBadge(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)
this(context, attrs, defStyleAttr, 0);
| public QuickContactBadge(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)
super(context, attrs, defStyleAttr, defStyleRes);
TypedArray styledAttributes = mContext.obtainStyledAttributes(R.styleable.Theme);
mOverlay = styledAttributes.getDrawable(
com.android.internal.R.styleable.Theme_quickContactBadgeOverlay);
styledAttributes.recycle();
if (!isInEditMode()) {
mQueryHandler = new QueryHandler(mContext.getContentResolver());
}
setOnClickListener(this);
|
Methods Summary |
---|
public void | assignContactFromEmail(java.lang.String emailAddress, boolean lazyLookup)Assign a contact based on an email address. This should only be used when
the contact's URI is not available, as an extra query will have to be
performed to lookup the URI based on the email.
assignContactFromEmail(emailAddress, lazyLookup, null);
| public void | assignContactFromEmail(java.lang.String emailAddress, boolean lazyLookup, android.os.Bundle extras)Assign a contact based on an email address. This should only be used when
the contact's URI is not available, as an extra query will have to be
performed to lookup the URI based on the email.
mContactEmail = emailAddress;
mExtras = extras;
if (!lazyLookup && mQueryHandler != null) {
mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP, null,
Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)),
EMAIL_LOOKUP_PROJECTION, null, null, null);
} else {
mContactUri = null;
onContactUriChanged();
}
| public void | assignContactFromPhone(java.lang.String phoneNumber, boolean lazyLookup)Assign a contact based on a phone number. This should only be used when
the contact's URI is not available, as an extra query will have to be
performed to lookup the URI based on the phone number.
assignContactFromPhone(phoneNumber, lazyLookup, new Bundle());
| public void | assignContactFromPhone(java.lang.String phoneNumber, boolean lazyLookup, android.os.Bundle extras)Assign a contact based on a phone number. This should only be used when
the contact's URI is not available, as an extra query will have to be
performed to lookup the URI based on the phone number.
mContactPhone = phoneNumber;
mExtras = extras;
if (!lazyLookup && mQueryHandler != null) {
mQueryHandler.startQuery(TOKEN_PHONE_LOOKUP, null,
Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, mContactPhone),
PHONE_LOOKUP_PROJECTION, null, null, null);
} else {
mContactUri = null;
onContactUriChanged();
}
| public void | assignContactUri(android.net.Uri contactUri)Assign the contact uri that this QuickContactBadge should be associated
with. Note that this is only used for displaying the QuickContact window and
won't bind the contact's photo for you. Call {@link #setImageDrawable(Drawable)} to set the
photo.
mContactUri = contactUri;
mContactEmail = null;
mContactPhone = null;
onContactUriChanged();
| public void | drawableHotspotChanged(float x, float y)
super.drawableHotspotChanged(x, y);
if (mOverlay != null) {
mOverlay.setHotspot(x, y);
}
| protected void | drawableStateChanged()
super.drawableStateChanged();
if (mOverlay != null && mOverlay.isStateful()) {
mOverlay.setState(getDrawableState());
invalidate();
}
| private boolean | isAssigned()True if a contact, an email address or a phone number has been assigned
return mContactUri != null || mContactEmail != null || mContactPhone != null;
| public void | onClick(android.view.View v)
// If contact has been assigned, mExtras should no longer be null, but do a null check
// anyway just in case assignContactFromPhone or Email was called with a null bundle or
// wasn't assigned previously.
final Bundle extras = (mExtras == null) ? new Bundle() : mExtras;
if (mContactUri != null) {
QuickContact.showQuickContact(getContext(), QuickContactBadge.this, mContactUri,
QuickContact.MODE_LARGE, mExcludeMimes);
} else if (mContactEmail != null && mQueryHandler != null) {
extras.putString(EXTRA_URI_CONTENT, mContactEmail);
mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP_AND_TRIGGER, extras,
Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)),
EMAIL_LOOKUP_PROJECTION, null, null, null);
} else if (mContactPhone != null && mQueryHandler != null) {
extras.putString(EXTRA_URI_CONTENT, mContactPhone);
mQueryHandler.startQuery(TOKEN_PHONE_LOOKUP_AND_TRIGGER, extras,
Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, mContactPhone),
PHONE_LOOKUP_PROJECTION, null, null, null);
} else {
// If a contact hasn't been assigned, don't react to click.
return;
}
| private void | onContactUriChanged()
setEnabled(isAssigned());
| protected void | onDraw(android.graphics.Canvas canvas)
super.onDraw(canvas);
if (!isEnabled()) {
// not clickable? don't show triangle
return;
}
if (mOverlay == null || mOverlay.getIntrinsicWidth() == 0 ||
mOverlay.getIntrinsicHeight() == 0) {
// nothing to draw
return;
}
mOverlay.setBounds(0, 0, getWidth(), getHeight());
if (mPaddingTop == 0 && mPaddingLeft == 0) {
mOverlay.draw(canvas);
} else {
int saveCount = canvas.getSaveCount();
canvas.save();
canvas.translate(mPaddingLeft, mPaddingTop);
mOverlay.draw(canvas);
canvas.restoreToCount(saveCount);
}
| public void | onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)
super.onInitializeAccessibilityEvent(event);
event.setClassName(QuickContactBadge.class.getName());
| public void | onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(QuickContactBadge.class.getName());
| public void | setExcludeMimes(java.lang.String[] excludeMimes)Set a list of specific MIME-types to exclude and not display. For
example, this can be used to hide the {@link Contacts#CONTENT_ITEM_TYPE}
profile icon.
mExcludeMimes = excludeMimes;
| public void | setImageToDefault()Resets the contact photo to the default state.
if (mDefaultAvatar == null) {
mDefaultAvatar = mContext.getDrawable(R.drawable.ic_contact_picture);
}
setImageDrawable(mDefaultAvatar);
| public void | setMode(int size)This call has no effect anymore, as there is only one QuickContact mode
| public void | setOverlay(android.graphics.drawable.Drawable overlay)Assigns the drawable that is to be drawn on top of the assigned contact photo.
mOverlay = overlay;
|
|