Esempio n. 1
0
  /**
   * Create a <tt>SourceContact</tt> from a <tt>GoogleContactsEntry</tt>.
   *
   * @param entry <tt>GoogleContactsEntry</tt>
   */
  private void onGoogleContactsEntry(GoogleContactsEntry entry) {
    String displayName = entry.getFullName();
    if (displayName == null || displayName.length() == 0) {
      if ((entry.getGivenName() == null || entry.getGivenName().length() == 0)
          && (entry.getFamilyName() == null || entry.getFamilyName().length() == 0)) {
        return;
      }

      displayName = entry.getGivenName() + " " + entry.getFamilyName();
    }

    List<ContactDetail> contactDetails = getContactDetails(entry);

    if (!contactDetails.isEmpty()) {
      GenericSourceContact sourceContact =
          new GenericSourceContact(getContactSource(), displayName, contactDetails);

      try {
        byte img[] =
            GoogleContactsServiceImpl.downloadPhoto(
                ((GoogleContactsEntryImpl) entry).getPhotoLink(),
                getContactSource().getConnection().getGoogleService());
        sourceContact.setImage(img);
      } catch (OutOfMemoryError oome) {
        // Ignore it, the image is not vital.
      }

      addQueryResult(sourceContact);
    }
  }
Esempio n. 2
0
  /**
   * Performs this <tt>AsyncContactQuery</tt> in a background <tt>Thread</tt>.
   *
   * @see AsyncContactQuery#run()
   */
  @Override
  protected void run() {
    GoogleContactsServiceImpl service = GoogleContactsActivator.getGoogleContactsService();
    gQuery = new GoogleQuery(query);

    GoogleContactsConnection cnx = getContactSource().getConnection();

    if (cnx == null) {
      return;
    }

    service.searchContact(
        cnx,
        gQuery,
        count,
        new GoogleEntryCallback() {
          public void callback(GoogleContactsEntry entry) {
            onGoogleContactsEntry(entry);
          }
        });
  }