Exemplo n.º 1
0
  /** Bind the contact details provided by the given {@link Cursor}. */
  protected void bindContactInfo(Cursor c) {
    // TODO: Bring back phonetic name
    final String displayName = c.getString(ContactQuery.DISPLAY_NAME);
    final String phoneticName = null;
    this.setDisplayName(displayName, null);

    final boolean starred = c.getInt(ContactQuery.STARRED) != 0;
    mStarredView.setChecked(starred);

    // Set the presence status
    if (!c.isNull(ContactQuery.CONTACT_PRESENCE_STATUS)) {
      int presence = c.getInt(ContactQuery.CONTACT_PRESENCE_STATUS);
      mPresenceView.setImageResource(StatusUpdates.getPresenceIconResourceId(presence));
      mPresenceView.setVisibility(View.VISIBLE);
    } else {
      mPresenceView.setVisibility(View.GONE);
    }

    // Set the status update
    String status = c.getString(ContactQuery.CONTACT_STATUS);
    if (!TextUtils.isEmpty(status)) {
      mStatusView.setText(status);
      mStatusView.setVisibility(View.VISIBLE);

      CharSequence timestamp = null;

      if (!c.isNull(ContactQuery.CONTACT_STATUS_TIMESTAMP)) {
        long date = c.getLong(ContactQuery.CONTACT_STATUS_TIMESTAMP);

        // Set the date/time field by mixing relative and absolute
        // times.
        int flags = DateUtils.FORMAT_ABBREV_RELATIVE;

        timestamp =
            DateUtils.getRelativeTimeSpanString(
                date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags);
      }

      String label = null;

      if (!c.isNull(ContactQuery.CONTACT_STATUS_LABEL)) {
        String resPackage = c.getString(ContactQuery.CONTACT_STATUS_RES_PACKAGE);
        int labelResource = c.getInt(ContactQuery.CONTACT_STATUS_LABEL);
        Resources resources;
        if (TextUtils.isEmpty(resPackage)) {
          resources = getResources();
        } else {
          PackageManager pm = getContext().getPackageManager();
          try {
            resources = pm.getResourcesForApplication(resPackage);
          } catch (NameNotFoundException e) {
            Log.w(TAG, "Contact status update resource package not found: " + resPackage);
            resources = null;
          }
        }

        if (resources != null) {
          try {
            label = resources.getString(labelResource);
          } catch (NotFoundException e) {
            Log.w(
                TAG,
                "Contact status update resource not found: " + resPackage + "@" + labelResource);
          }
        }
      }

      CharSequence attribution;
      if (timestamp != null && label != null) {
        attribution =
            getContext()
                .getString(
                    InternalResource.getString("contact_status_update_attribution_with_date"),
                    timestamp,
                    label);
      } else if (timestamp == null && label != null) {
        attribution =
            getContext()
                .getString(InternalResource.getString("contact_status_update_attribution"), label);
      } else if (timestamp != null) {
        attribution = timestamp;
      } else {
        attribution = null;
      }
      if (attribution != null) {
        mStatusAttributionView.setText(attribution);
        mStatusAttributionView.setVisibility(View.VISIBLE);
      } else {
        mStatusAttributionView.setVisibility(View.GONE);
      }
    } else {
      mStatusView.setVisibility(View.GONE);
      mStatusAttributionView.setVisibility(View.GONE);
    }
  }
Exemplo n.º 2
0
 /** Manually set the presence. */
 public void setPresence(int presence) {
   mPresenceView.setImageResource(StatusUpdates.getPresenceIconResourceId(presence));
 }