Beispiel #1
0
  public void onEventMainThread(Events.LocationMessageReceived e) {
    // Updates a contact or allocates a new one

    Contact c = App.getContacts().get(e.getTopic());

    if (c == null) {
      Log.v(this.toString(), "Allocating new contact for " + e.getTopic());
      c = new st.alr.mqttitude.model.Contact(e.getTopic());
      updateContact(c);
    }

    c.setLocation(e.getGeocodableLocation());

    App.getContacts().put(e.getTopic(), c);

    //		if (e.getLocationMessage().hasTransition()) {
    //			Notification noti = new Notification.InboxStyle(
    //					new Notification.Builder(this.context)
    //							.setContentTitle("title").setContentText("subject")
    //							.setSmallIcon(R.drawable.ic_notification)).addLine(
    //					"line1").build();
    //
    //		}

    // Fires a new event with the now updated or created contact to which
    // fragments can react
    EventBus.getDefault().post(new Events.ContactUpdated(c));
  }
Beispiel #2
0
  public void linkContact(Contact c, long contactId) {
    if (Preferences.isContactLinkCloudStorageEnabled()) {
      Log.e(this.toString(), "Saving a ContactLink to the cloud is not yet supported");
      return;
    }
    Log.v(
        this.toString(),
        "Creating ContactLink from " + c.getTopic() + " to contactId " + contactId);

    ContactLink cl = new ContactLink(c.getTopic(), contactId);
    App.getContactLinkDao().insertOrReplace(cl);

    updateContact(c);
    EventBus.getDefault().postSticky(new Events.ContactUpdated(c));
  }
Beispiel #3
0
  public long getContactIdFromCloud(Contact c) {
    Long cId = (long) 0;
    String imWhere =
        "("
            + ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL
            + " = ? COLLATE NOCASE) AND ("
            + ContactsContract.CommonDataKinds.Im.DATA
            + " = ? COLLATE NOCASE)";
    String[] imWhereParams = new String[] {"OwnTracks", c.getTopic()};

    Cursor cursor =
        this.context
            .getContentResolver()
            .query(ContactsContract.Data.CONTENT_URI, null, imWhere, imWhereParams, null);

    cursor.move(-1);
    while (cursor.moveToNext()) {
      cId = cursor.getLong(cursor.getColumnIndex(ContactsContract.Data.CONTACT_ID));
      Log.v(
          this.toString(),
          "found matching raw contact id "
              + cursor.getString(cursor.getColumnIndex(BaseColumns._ID))
              + " with contact id "
              + cId
              + " to be associated with topic "
              + cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
      break;
    }
    cursor.close();
    return cId;
  }
Beispiel #4
0
  /*
   * Resolves username and image either from a locally saved mapping or from
   * synced cloud contacts. If no mapping is found, no mame is set and the
   * default image is assumed
   */
  void updateContact(Contact c) {

    long contactId = getContactId(c);
    boolean found = false;

    if (contactId <= 0) {
      Log.v(this.toString(), "contactId could not be resolved for " + c.getTopic());
      setContactImageAndName(c, null, null);
      return;
    } else {
      Log.v(this.toString(), "contactId for " + c.getTopic() + " was resolved to " + contactId);
    }

    Cursor cursor =
        this.context
            .getContentResolver()
            .query(
                RawContacts.CONTENT_URI,
                null,
                ContactsContract.Data.CONTACT_ID + " = ?",
                new String[] {contactId + ""},
                null);
    if (!cursor.isAfterLast()) {

      while (cursor.moveToNext()) {
        Bitmap image = Contact.resolveImage(this.context.getContentResolver(), contactId);
        String displayName =
            cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

        Log.v(
            this.toString(),
            "Resolved display Name: "
                + displayName
                + ", image: "
                + image
                + " for topic "
                + c.getTopic());
        c.setName(displayName);
        c.setUserImage(image);
        found = true;
        break;
      }
    }

    if (!found) setContactImageAndName(c, null, null);

    cursor.close();
  }
Beispiel #5
0
  public long getContactIdFromLocalStorage(Contact c) {
    ContactLink cl = App.getContactLinkDao().load(c.getTopic());

    return cl != null ? cl.getContactId() : 0;
  }
Beispiel #6
0
 void setContactImageAndName(Contact c, Bitmap image, String name) {
   c.setName(name);
   c.setUserImage(image);
 }