Пример #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#006666")));
    setContentView(R.layout.contacts_picker_activity);
    mNames = Helpers.getAllContactNames();
    List<String> numbers = Helpers.getAllContactNumbers();
    ArrayList<String> output = getFormattedListEntries(mNames, numbers);
    listAdapter =
        new ArrayAdapter<>(this, android.R.layout.simple_list_item_multiple_choice, output);
    mListView = (ListView) findViewById(R.id.list);
    mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    mListView.setAdapter(listAdapter);

    String noteTitle;
    if (getIntent().getExtras() != null) {
      String checkedContacts = getIntent().getExtras().getString("pre_checked");
      noteTitle = getIntent().getExtras().getString("note");
      boolean revisitingTemporary = getIntent().getExtras().getBoolean("temporary_select");
      if (checkedContacts != null) {
        String[] pre_checked = checkedContacts.split(",");
        for (int i = 0; i < mListView.getCount(); i++) {
          for (String contact : pre_checked) {
            if (PhoneNumberUtils.compare(numbers.get(i), contact)) {
              mListView.setItemChecked(i, true);
            }
          }
        }
      } else if (revisitingTemporary) {
        // Just don't do anything
      } else {
        // checkContacts here
      }
    }
  }
 public boolean shouldCollapseWith(PhoneItem phoneItem) {
   if (PhoneNumberUtils.compare(
       PhoneDisambigDialog.this.mContext, phoneNumber, phoneItem.phoneNumber)) {
     return true;
   }
   return false;
 }
Пример #3
0
 // Remove a contact from the ContactsCache based on the number or email address
 private void remove(Contact contact) {
   synchronized (ContactsCache.this) {
     String number = contact.getNumber();
     final boolean isNotRegularPhoneNumber =
         contact.isMe() || MessageUtils.isEmailAddress(number) || MessageUtils.isAlias(number);
     final String key = isNotRegularPhoneNumber ? number : key(number, sStaticKeyBuffer);
     ArrayList<Contact> candidates = mContactsHash.get(key);
     if (candidates != null) {
       int length = candidates.size();
       for (int i = 0; i < length; i++) {
         Contact c = candidates.get(i);
         if (isNotRegularPhoneNumber) {
           if (number.equals(c.mNumber)) {
             candidates.remove(i);
             break;
           }
         } else {
           if (PhoneNumberUtils.compare(number, c.mNumber)) {
             candidates.remove(i);
             break;
           }
         }
       }
       if (candidates.size() == 0) {
         mContactsHash.remove(key);
       }
     }
   }
 }
    protected boolean equalPhoneNumbers(CharArrayBuffer buffer1, CharArrayBuffer buffer2) {

      // TODO add PhoneNumberUtils.compare(CharSequence, CharSequence) to avoid
      // string allocation
      return PhoneNumberUtils.compare(
          new String(buffer1.data, 0, buffer1.sizeCopied),
          new String(buffer2.data, 0, buffer2.sizeCopied));
    }
  public static boolean isLocalNumber(String number) {
    if (number == null) {
      return false;
    }

    // we don't use Mms.isEmailAddress() because it is too strict for comparing addresses like
    // "[email protected]", which is the 'from' address from a forwarded
    // email
    // message from Gmail. We don't want to treat "[email protected]" and
    // "6505551212" to be the same.
    if (number.indexOf('@') >= 0) {
      return false;
    }

    return PhoneNumberUtils.compare(number, getLocalNumber());
  }
  @SmallTest
  public void testCompareSmsShortcode() {
    Log.i(LogTag.APP, "testCompareSmsShortcode");

    // test the short codes themselves are compared correctly
    assertFalse(PhoneNumberUtils.compare("321", "54321"));
    assertFalse(PhoneNumberUtils.compare("4321", "54321"));
    assertFalse(PhoneNumberUtils.compare("54321", "654321"));

    // test comparing one shortcode to a regular phone number
    assertFalse(PhoneNumberUtils.compare("54321", "6505554321"));
    assertFalse(PhoneNumberUtils.compare("54321", "+16505554321"));
    assertFalse(PhoneNumberUtils.compare("654321", "6505654321"));
    assertFalse(PhoneNumberUtils.compare("654321", "+16505654321"));
  }
Пример #7
0
    private Contact internalGet(String numberOrEmail, boolean isMe) {
      synchronized (ContactsCache.this) {
        // See if we can find "number" in the hashtable.
        // If so, just return the result.
        final boolean isNotRegularPhoneNumber =
            isMe
                || MessageUtils.isEmailAddress(numberOrEmail)
                || MessageUtils.isAlias(numberOrEmail);
        final String key =
            isNotRegularPhoneNumber ? numberOrEmail : key(numberOrEmail, sStaticKeyBuffer);

        ArrayList<Contact> candidates = mContactsHash.get(key);
        if (candidates != null) {
          int length = candidates.size();
          for (int i = 0; i < length; i++) {
            Contact c = candidates.get(i);
            if (isNotRegularPhoneNumber) {
              if (numberOrEmail.equals(c.mNumber)) {
                return c;
              }
            } else {
              if (PhoneNumberUtils.compare(numberOrEmail, c.mNumber)) {
                return c;
              }
            }
          }
        } else {
          candidates = new ArrayList<Contact>();
          // call toString() since it may be the static CharBuffer
          mContactsHash.put(key, candidates);
        }
        Contact c = isMe ? new Contact(true) : new Contact(numberOrEmail);
        candidates.add(c);
        return c;
      }
    }