/** * Test for content equality between two objects. * * @param other The object to compare to this one. * @return true if the argument object is a set of contact details with matching attributes. */ public boolean equals(Object other) { if (other instanceof ContactDetails) { ContactDetails otherDetails = (ContactDetails) other; return name.equals(otherDetails.getName()) && phone.equals(otherDetails.getPhone()) && address.equals(otherDetails.getAddress()); } else { return false; } }
/** * Compare these details against another set, for the purpose of sorting. The fields are sorted by * name, phone, and address. * * @param otherDetails The details to be compared against. * @return a negative integer if this comes before the parameter, zero if they are equal and a * positive integer if this comes after the second. */ public int compareTo(ContactDetails otherDetails) { int comparison = name.compareTo(otherDetails.getName()); if (comparison != 0) { return comparison; } comparison = phone.compareTo(otherDetails.getPhone()); if (comparison != 0) { return comparison; } return address.compareTo(otherDetails.getAddress()); }
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int arrayAdapterPosition = menuInfo.position; ContactDetails selectedContact = contactsAdapter.getItem(arrayAdapterPosition); String number = selectedContact.getPhoneNumber(); Intent callIntent; int id = item.getItemId(); switch (id) { case 1001: Log.d("MainActivity", "Call option is selected"); callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + number)); /*if (checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // public void requestPermissions(@NonNull String[] permissions, int requestCode) // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for Activity#requestPermissions for more details. return false; }*/ try { startActivity(callIntent); } catch (Exception e) { Log.e("Exception", e.getMessage()); } break; case 1002: Log.d("MainActivity", "SMS option is selected"); callIntent = new Intent(Intent.ACTION_SENDTO); callIntent.addCategory(Intent.CATEGORY_DEFAULT); callIntent.setType("vnd.android-dir/mms-sms"); callIntent.setData(Uri.parse("sms:" + number)); try { startActivity(callIntent); } catch (Exception e) { Log.e("Exception", e.getMessage()); } break; } return true; }
/** @return The string to use for displaying this contact */ public String getLabel() { String result = mDetails.getLabel(); if (!TextUtils.isEmpty(result)) { return result; } return ""; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ContactDetails that = (ContactDetails) o; if (mNeedsLazyLoad != that.mNeedsLazyLoad) { lazyLoadData(); that.lazyLoadData(); } if (mLookupKey != null ? !mLookupKey.equals(that.mLookupKey) : that.mLookupKey != null) return false; return true; }
/** * @param context The context * @return The photo Uri. If it isn't set a default contact picture is returned. * @see #setPhotoUri(android.net.Uri) * @see #setPhotoUri(String) * @see #getPhotoUri() */ public Uri getPhotoUriOrDefault(Context context) { Uri result = mDetails.getPhotoUri(); if (result == null) { result = Uri.withAppendedPath( Uri.parse("android.resource://" + context.getPackageName()), String.valueOf(R.drawable.ic_contact_picture)); } return result; }
/** * @return True if the Contact is a valid contact in the Android system. This is determined by if * there is a {@link com.blackberry.widgets.tagview.contact.Contact * .ContactDetails#getLookupKey()} available or not. */ public boolean isContactValid() { return !TextUtils.isEmpty(mDetails.getLookupKey()); }
/** * Set the name of the contact * * @param name The new name of the contact * @see #getName() */ public void setName(String name) { mDetails.setName(name); // notifyOnObjectChangedListener(); }
/** * @return The name of the contact * @see #setName(String) */ public String getName() { return mDetails.getName(); }
/** * Set the lookup key * * @param key The key to set * @see #getLookupKey() */ public void setLookupKey(String key) { mDetails.setLookupKey(key); // notifyOnObjectChangedListener(); }
/** * @return The lookup key for the contact. This is the unique identifier for the contact * @see #setLookupKey(String) */ public String getLookupKey() { return mDetails.getLookupKey(); }
/** * @param contactsHelper The {@link com.blackberry.widgets.tagview.internal.contact * .ContactsHelper} which created this instance * @see #getContactsHelper() */ public void setContactsHelper(ContactsHelper contactsHelper) { mDetails.setContactsHelper(contactsHelper); }
/** * @param photoUri The new photo Uri * @see #getPhotoUri() * @see #setPhotoUri(String) */ public void setPhotoUri(Uri photoUri) { mDetails.setPhotoUri(photoUri); // notifyOnObjectChangedListener(); }
/** * Set the list of phone numbers for this contact * * @param phoneNumbers The new list of phone numbers for this contact * @see #getPhoneNumbers() */ public void setPhoneNumbers(ArrayList<PhoneNumber> phoneNumbers) { mDetails.setPhoneNumbers(phoneNumbers); // notifyOnObjectChangedListener(); }
/** * @return The list of phone numbers for this contact * @see #setPhoneNumbers(java.util.ArrayList) */ public ArrayList<PhoneNumber> getPhoneNumbers() { mDetails.lazyLoadData(); return mDetails.getPhoneNumbers(); }
/** * Set the list of email addresses for this contact * * @param emailAddresses The new list of email addresses for this contact * @see #getEmailAddresses() */ public void setEmailAddresses(ArrayList<EmailAddress> emailAddresses) { mDetails.setEmailAddresses(emailAddresses); // notifyOnObjectChangedListener(); }
/** * @return The list of email addresses for this contact * @see #setEmailAddresses(java.util.ArrayList) */ public ArrayList<EmailAddress> getEmailAddresses() { mDetails.lazyLoadData(); return mDetails.getEmailAddresses(); }
/** * @return The {@link com.blackberry.widgets.tagview.internal.contact.ContactsHelper} which * created this instance * @see #setContactsHelper(com.blackberry.widgets.tagview.internal.contact.ContactsHelper) */ public ContactsHelper getContactsHelper() { return mDetails.getContactsHelper(); }
/** * @return The photo Uri. If it isn't set null is returned * @see #setPhotoUri(android.net.Uri) * @see #setPhotoUri(String) * @see #getPhotoUri(Context context) */ public Uri getPhotoUri() { return mDetails.getPhotoUri(); }