diff options
author | Daniel Lehmann <lehmannd@google.com> | 2011-08-08 13:06:01 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-08-08 13:06:01 -0700 |
commit | f6d3079f98ce0f0854249433ab85a4fff1225e9a (patch) | |
tree | 6e5c6dbde1d2106ae17577f01158970b10d88881 /core | |
parent | f95761826590a953c927fd93b1e8ef627dbc3e5b (diff) | |
parent | e13e55b9bb477493f65c9fb33ff25e00e2a98260 (diff) | |
download | frameworks_base-f6d3079f98ce0f0854249433ab85a4fff1225e9a.zip frameworks_base-f6d3079f98ce0f0854249433ab85a4fff1225e9a.tar.gz frameworks_base-f6d3079f98ce0f0854249433ab85a4fff1225e9a.tar.bz2 |
Merge "Don't perform query if QuickContactBadge has been initialized via assignContactUri"
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/widget/QuickContactBadge.java | 105 |
1 files changed, 30 insertions, 75 deletions
diff --git a/core/java/android/widget/QuickContactBadge.java b/core/java/android/widget/QuickContactBadge.java index 5f3d21f..adc0fb0 100644 --- a/core/java/android/widget/QuickContactBadge.java +++ b/core/java/android/widget/QuickContactBadge.java @@ -42,15 +42,11 @@ import android.view.View.OnClickListener; * and on-click behavior. */ public class QuickContactBadge extends ImageView implements OnClickListener { - private Uri mContactUri; private String mContactEmail; private String mContactPhone; - private int mMode; private Drawable mOverlay; private QueryHandler mQueryHandler; - private Drawable mBadgeBackground; - private Drawable mNoBadgeBackground; private Drawable mDefaultAvatar; protected String[] mExcludeMimes = null; @@ -59,7 +55,6 @@ public class QuickContactBadge extends ImageView implements OnClickListener { static final private int TOKEN_PHONE_LOOKUP = 1; static final private int TOKEN_EMAIL_LOOKUP_AND_TRIGGER = 2; static final private int TOKEN_PHONE_LOOKUP_AND_TRIGGER = 3; - static final private int TOKEN_CONTACT_LOOKUP_AND_TRIGGER = 4; static final String[] EMAIL_LOOKUP_PROJECTION = new String[] { RawContacts.CONTACT_ID, @@ -75,14 +70,6 @@ public class QuickContactBadge extends ImageView implements OnClickListener { static final int PHONE_ID_COLUMN_INDEX = 0; static final int PHONE_LOOKUP_STRING_COLUMN_INDEX = 1; - static final String[] CONTACT_LOOKUP_PROJECTION = new String[] { - Contacts._ID, - Contacts.LOOKUP_KEY, - }; - static final int CONTACT_ID_COLUMN_INDEX = 0; - static final int CONTACT_LOOKUPKEY_COLUMN_INDEX = 1; - - public QuickContactBadge(Context context) { this(context, null); } @@ -94,55 +81,42 @@ public class QuickContactBadge extends ImageView implements OnClickListener { public QuickContactBadge(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - TypedArray a = - context.obtainStyledAttributes(attrs, - com.android.internal.R.styleable.QuickContactBadge, defStyle, 0); - - mMode = a.getInt(com.android.internal.R.styleable.QuickContactBadge_quickContactWindowSize, - QuickContact.MODE_MEDIUM); - - a.recycle(); - TypedArray styledAttributes = mContext.obtainStyledAttributes(R.styleable.Theme); - mOverlay = styledAttributes.getDrawable(com.android.internal.R.styleable.Theme_quickContactBadgeOverlay); + mOverlay = styledAttributes.getDrawable( + com.android.internal.R.styleable.Theme_quickContactBadgeOverlay); styledAttributes.recycle(); - init(); - - mBadgeBackground = getBackground(); + mQueryHandler = new QueryHandler(mContext.getContentResolver()); + setOnClickListener(this); } @Override protected void drawableStateChanged() { super.drawableStateChanged(); - Drawable d = mOverlay; - if (d != null && d.isStateful()) { - d.setState(getDrawableState()); + if (mOverlay != null && mOverlay.isStateful()) { + mOverlay.setState(getDrawableState()); invalidate(); } } - private void init() { - mQueryHandler = new QueryHandler(mContext.getContentResolver()); - setOnClickListener(this); - } - - /** - * Set the QuickContact window mode. Options are {@link QuickContact#MODE_SMALL}, - * {@link QuickContact#MODE_MEDIUM}, {@link QuickContact#MODE_LARGE}. - * @param size - */ + /** This call has no effect anymore, as there is only one QuickContact mode */ + @SuppressWarnings("unused") public void setMode(int size) { - mMode = size; } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); + if (!isEnabled()) { + // not clickable? don't show triangle + return; + } + if (mOverlay == null || mOverlay.getIntrinsicWidth() == 0 || mOverlay.getIntrinsicHeight() == 0) { - return; // nothing to draw + // nothing to draw + return; } mOverlay.setBounds(0, 0, getWidth(), getHeight()); @@ -158,6 +132,11 @@ public class QuickContactBadge extends ImageView implements OnClickListener { } } + /** True if a contact, an email address or a phone number has been assigned */ + private boolean isAssigned() { + return mContactUri != null || mContactEmail != null || mContactPhone != null; + } + /** * Resets the contact photo to the default state. */ @@ -184,20 +163,6 @@ public class QuickContactBadge extends ImageView implements OnClickListener { onContactUriChanged(); } - private void onContactUriChanged() { - if (mContactUri == null && mContactEmail == null && mContactPhone == null) { - // Holo theme has no background on badges. Use a null background. - /* - if (mNoBadgeBackground == null) { - mNoBadgeBackground = getResources().getDrawable(R.drawable.quickcontact_nobadge); - } - */ - setBackgroundDrawable(mNoBadgeBackground); - } else { - setBackgroundDrawable(mBadgeBackground); - } - } - /** * 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 @@ -240,11 +205,15 @@ public class QuickContactBadge extends ImageView implements OnClickListener { } } + private void onContactUriChanged() { + setEnabled(isAssigned()); + } + + @Override public void onClick(View v) { if (mContactUri != null) { - mQueryHandler.startQuery(TOKEN_CONTACT_LOOKUP_AND_TRIGGER, null, - mContactUri, - CONTACT_LOOKUP_PROJECTION, null, null, null); + QuickContact.showQuickContact(getContext(), QuickContactBadge.this, mContactUri, + QuickContact.MODE_LARGE, mExcludeMimes); } else if (mContactEmail != null) { mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP_AND_TRIGGER, mContactEmail, Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)), @@ -268,10 +237,6 @@ public class QuickContactBadge extends ImageView implements OnClickListener { mExcludeMimes = excludeMimes; } - private void trigger(Uri lookupUri) { - QuickContact.showQuickContact(getContext(), this, lookupUri, mMode, mExcludeMimes); - } - private class QueryHandler extends AsyncQueryHandler { public QueryHandler(ContentResolver cr) { @@ -313,17 +278,6 @@ public class QuickContactBadge extends ImageView implements OnClickListener { } break; } - - case TOKEN_CONTACT_LOOKUP_AND_TRIGGER: { - if (cursor != null && cursor.moveToFirst()) { - long contactId = cursor.getLong(CONTACT_ID_COLUMN_INDEX); - String lookupKey = cursor.getString(CONTACT_LOOKUPKEY_COLUMN_INDEX); - lookupUri = Contacts.getLookupUri(contactId, lookupKey); - trigger = true; - } - - break; - } } } finally { if (cursor != null) { @@ -335,8 +289,9 @@ public class QuickContactBadge extends ImageView implements OnClickListener { onContactUriChanged(); if (trigger && lookupUri != null) { - // Found contact, so trigger track - trigger(lookupUri); + // Found contact, so trigger QuickContact + QuickContact.showQuickContact(getContext(), QuickContactBadge.this, lookupUri, + QuickContact.MODE_LARGE, mExcludeMimes); } else if (createUri != null) { // Prompt user to add this person to contacts final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, createUri); |