remove more unused code

This commit is contained in:
Vincent Breitmoser 2017-02-23 13:25:10 +01:00
parent e18466c290
commit 110179deb5

View file

@ -13,7 +13,6 @@ import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Intents; import android.provider.ContactsContract.Intents;
import android.provider.ContactsContract.PhoneLookup;
import android.provider.ContactsContract.QuickContact; import android.provider.ContactsContract.QuickContact;
import android.provider.ContactsContract.RawContacts; import android.provider.ContactsContract.RawContacts;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -31,19 +30,8 @@ import android.widget.ImageView;
* https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/QuickContactBadge.java * https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/QuickContactBadge.java
*/ */
public class ContactBadge extends ImageView implements OnClickListener { public class ContactBadge extends ImageView implements OnClickListener {
private Uri mContactUri;
private String mContactEmail;
private String mContactPhone;
private QueryHandler mQueryHandler;
private Bundle mExtras = null;
protected String[] mExcludeMimes = null;
static final private int TOKEN_EMAIL_LOOKUP = 0; static final private int TOKEN_EMAIL_LOOKUP = 0;
static final private int TOKEN_PHONE_LOOKUP = 1; static final private int TOKEN_EMAIL_LOOKUP_AND_TRIGGER = 1;
static final private int TOKEN_EMAIL_LOOKUP_AND_TRIGGER = 2;
static final private int TOKEN_PHONE_LOOKUP_AND_TRIGGER = 3;
static final private String EXTRA_URI_CONTENT = "uri_content"; static final private String EXTRA_URI_CONTENT = "uri_content";
@ -54,12 +42,11 @@ public class ContactBadge extends ImageView implements OnClickListener {
static final int EMAIL_ID_COLUMN_INDEX = 0; static final int EMAIL_ID_COLUMN_INDEX = 0;
static final int EMAIL_LOOKUP_STRING_COLUMN_INDEX = 1; static final int EMAIL_LOOKUP_STRING_COLUMN_INDEX = 1;
static final String[] PHONE_LOOKUP_PROJECTION = new String[] {
PhoneLookup._ID, private Uri contactUri;
PhoneLookup.LOOKUP_KEY, private String contactEmail;
}; private QueryHandler queryHandler;
static final int PHONE_ID_COLUMN_INDEX = 0; private Bundle extras = null;
static final int PHONE_LOOKUP_STRING_COLUMN_INDEX = 1;
public ContactBadge(Context context) { public ContactBadge(Context context) {
@ -72,7 +59,7 @@ public class ContactBadge extends ImageView implements OnClickListener {
public ContactBadge(Context context, AttributeSet attrs, int defStyle) { public ContactBadge(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
mQueryHandler = new QueryHandler(context.getContentResolver()); queryHandler = new QueryHandler(context.getContentResolver());
setOnClickListener(this); setOnClickListener(this);
} }
@ -97,7 +84,7 @@ public class ContactBadge extends ImageView implements OnClickListener {
* True if a contact, an email address or a phone number has been assigned * True if a contact, an email address or a phone number has been assigned
*/ */
private boolean isAssigned() { private boolean isAssigned() {
return mContactUri != null || mContactEmail != null || mContactPhone != null; return contactUri != null || contactEmail != null;
} }
/** /**
@ -111,9 +98,8 @@ public class ContactBadge extends ImageView implements OnClickListener {
* {@link Contacts#CONTENT_LOOKUP_URI} style URI. * {@link Contacts#CONTENT_LOOKUP_URI} style URI.
*/ */
public void assignContactUri(Uri contactUri) { public void assignContactUri(Uri contactUri) {
mContactUri = contactUri; this.contactUri = contactUri;
mContactEmail = null; contactEmail = null;
mContactPhone = null;
onContactUriChanged(); onContactUriChanged();
} }
@ -150,14 +136,14 @@ public class ContactBadge extends ImageView implements OnClickListener {
*/ */
public void assignContactFromEmail(String emailAddress, boolean lazyLookup, Bundle extras) { public void assignContactFromEmail(String emailAddress, boolean lazyLookup, Bundle extras) {
mContactEmail = emailAddress; contactEmail = emailAddress;
mExtras = extras; this.extras = extras;
if (!lazyLookup) { if (!lazyLookup) {
mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP, null, queryHandler.startQuery(TOKEN_EMAIL_LOOKUP, null,
Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)), Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(contactEmail)),
EMAIL_LOOKUP_PROJECTION, null, null, null); EMAIL_LOOKUP_PROJECTION, null, null, null);
} else { } else {
mContactUri = null; contactUri = null;
onContactUriChanged(); onContactUriChanged();
} }
} }
@ -171,20 +157,15 @@ public class ContactBadge extends ImageView implements OnClickListener {
// If contact has been assigned, mExtras should no longer be null, but do a null check // 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 // anyway just in case assignContactFromPhone or Email was called with a null bundle or
// wasn't assigned previously. // wasn't assigned previously.
final Bundle extras = (mExtras == null) ? new Bundle() : mExtras; final Bundle extras = (this.extras == null) ? new Bundle() : this.extras;
if (mContactUri != null) { if (contactUri != null) {
QuickContact.showQuickContact(getContext(), ContactBadge.this, mContactUri, QuickContact.showQuickContact(getContext(), ContactBadge.this, contactUri,
QuickContact.MODE_LARGE, mExcludeMimes); QuickContact.MODE_LARGE, null);
} else if (mContactEmail != null) { } else if (contactEmail != null) {
extras.putString(EXTRA_URI_CONTENT, mContactEmail); extras.putString(EXTRA_URI_CONTENT, contactEmail);
mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP_AND_TRIGGER, extras, queryHandler.startQuery(TOKEN_EMAIL_LOOKUP_AND_TRIGGER, extras,
Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)), Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(contactEmail)),
EMAIL_LOOKUP_PROJECTION, null, null, null); EMAIL_LOOKUP_PROJECTION, null, null, null);
} else if (mContactPhone != 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);
} }
} }
@ -211,23 +192,9 @@ public class ContactBadge extends ImageView implements OnClickListener {
Uri lookupUri = null; Uri lookupUri = null;
Uri createUri = null; Uri createUri = null;
boolean trigger = false; boolean trigger = false;
final Bundle extras = (cookie != null) ? (Bundle) cookie : new Bundle(); Bundle extras = (cookie != null) ? (Bundle) cookie : new Bundle();
try { try {
switch (token) { switch (token) {
case TOKEN_PHONE_LOOKUP_AND_TRIGGER:
trigger = true;
createUri = Uri.fromParts("tel", extras.getString(EXTRA_URI_CONTENT), null);
//$FALL-THROUGH$
case TOKEN_PHONE_LOOKUP: {
if (cursor != null && cursor.moveToFirst()) {
long contactId = cursor.getLong(PHONE_ID_COLUMN_INDEX);
String lookupKey = cursor.getString(PHONE_LOOKUP_STRING_COLUMN_INDEX);
lookupUri = Contacts.getLookupUri(contactId, lookupKey);
}
break;
}
case TOKEN_EMAIL_LOOKUP_AND_TRIGGER: case TOKEN_EMAIL_LOOKUP_AND_TRIGGER:
trigger = true; trigger = true;
createUri = Uri.fromParts("mailto", createUri = Uri.fromParts("mailto",
@ -249,13 +216,13 @@ public class ContactBadge extends ImageView implements OnClickListener {
} }
} }
mContactUri = lookupUri; contactUri = lookupUri;
onContactUriChanged(); onContactUriChanged();
if (trigger && lookupUri != null) { if (trigger && lookupUri != null) {
// Found contact, so trigger QuickContact // Found contact, so trigger QuickContact
QuickContact.showQuickContact(getContext(), ContactBadge.this, lookupUri, QuickContact.showQuickContact(
QuickContact.MODE_LARGE, ContactBadge.this.mExcludeMimes); getContext(), ContactBadge.this, lookupUri, QuickContact.MODE_LARGE, null);
} else if (createUri != null) { } else if (createUri != null) {
// Prompt user to add this person to contacts // Prompt user to add this person to contacts
final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, createUri); final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, createUri);