private static String getTextMessageDetails(Context context, Cursor cursor) {
    Log.d(TAG, "getTextMessageDetails");

    StringBuilder details = new StringBuilder();
    Resources res = context.getResources();

    // Message Type: Text message.
    details.append(res.getString(R.string.message_type_label));
    details.append(res.getString(R.string.text_message));

    // Address: ***
    details.append('\n');
    int smsType = cursor.getInt(MessageListAdapter.COLUMN_SMS_TYPE);
    if (Sms.isOutgoingFolder(smsType)) {
      details.append(res.getString(R.string.to_address_label));
    } else {
      details.append(res.getString(R.string.from_label));
    }
    details.append(cursor.getString(MessageListAdapter.COLUMN_SMS_ADDRESS));

    // Sent: ***
    if (smsType == Sms.MESSAGE_TYPE_INBOX) {
      long date_sent = cursor.getLong(MessageListAdapter.COLUMN_SMS_DATE_SENT);
      if (date_sent > 0) {
        details.append('\n');
        details.append(res.getString(R.string.sent_label));
        details.append(MessageUtils.formatTimeStampString(context, date_sent, true));
      }
    }

    // Received: ***
    details.append('\n');
    if (smsType == Sms.MESSAGE_TYPE_DRAFT) {
      details.append(res.getString(R.string.saved_label));
    } else if (smsType == Sms.MESSAGE_TYPE_INBOX) {
      details.append(res.getString(R.string.received_label));
    } else {
      details.append(res.getString(R.string.sent_label));
    }

    long date = cursor.getLong(MessageListAdapter.COLUMN_SMS_DATE);
    details.append(MessageUtils.formatTimeStampString(context, date, true));

    // Error code: ***
    int errorCode = cursor.getInt(MessageListAdapter.COLUMN_SMS_ERROR_CODE);
    if (errorCode != 0) {
      details.append('\n').append(res.getString(R.string.error_code_label)).append(errorCode);
    }

    return details.toString();
  }
  private static String getNotificationIndDetails(Context context, Cursor cursor) {
    StringBuilder details = new StringBuilder();
    Resources res = context.getResources();

    long id = cursor.getLong(MessageListAdapter.COLUMN_ID);
    Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, id);
    NotificationInd nInd;

    try {
      nInd = (NotificationInd) PduPersister.getPduPersister(context).load(uri);
    } catch (MmsException e) {
      Log.e(TAG, "Failed to load the message: " + uri, e);
      return context.getResources().getString(R.string.cannot_get_details);
    }

    // Message Type: Mms Notification.
    details.append(res.getString(R.string.message_type_label));
    details.append(res.getString(R.string.multimedia_notification));

    // From: ***
    String from = extractEncStr(context, nInd.getFrom());
    details.append('\n');
    details.append(res.getString(R.string.from_label));
    details.append(!TextUtils.isEmpty(from) ? from : res.getString(R.string.hidden_sender_address));

    // Date: ***
    details.append('\n');
    details.append(
        res.getString(
            R.string.expire_on,
            MessageUtils.formatTimeStampString(context, nInd.getExpiry() * 1000L, true)));

    // Subject: ***
    details.append('\n');
    details.append(res.getString(R.string.subject_label));

    EncodedStringValue subject = nInd.getSubject();
    if (subject != null) {
      details.append(subject.getString());
    }

    // Message class: Personal/Advertisement/Infomational/Auto
    details.append('\n');
    details.append(res.getString(R.string.message_class_label));
    details.append(new String(nInd.getMessageClass()));

    // Message size: *** KB
    details.append('\n');
    details.append(res.getString(R.string.message_size_label));
    details.append(String.valueOf((nInd.getMessageSize() + 1023) / 1024));
    details.append(context.getString(R.string.kilobyte));

    return details.toString();
  }
Exemplo n.º 3
0
 public CBMessageItem(Context context, CBMessage message) {
   mMessage = message;
   mId = message.getMessageId();
   mPresenceResId = 0;
   mSubject = message.getBody();
   mFrom = message.getDisplayName();
   mDate =
       String.format(
           context.getString(R.string.received_on),
           MessageUtils.formatTimeStampString(context, message.getDate()));
   mChannelId = message.getChannelId();
   mSimId = message.getSimId();
 }
  private static String getMultimediaMessageDetails(Context context, Cursor cursor, int size) {
    int type = cursor.getInt(MessageListAdapter.COLUMN_MMS_MESSAGE_TYPE);
    if (type == PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND) {
      return getNotificationIndDetails(context, cursor);
    }

    StringBuilder details = new StringBuilder();
    Resources res = context.getResources();

    long id = cursor.getLong(MessageListAdapter.COLUMN_ID);
    Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, id);
    MultimediaMessagePdu msg;

    try {
      msg = (MultimediaMessagePdu) PduPersister.getPduPersister(context).load(uri);
    } catch (MmsException e) {
      Log.e(TAG, "Failed to load the message: " + uri, e);
      return context.getResources().getString(R.string.cannot_get_details);
    }

    // Message Type: Text message.
    details.append(res.getString(R.string.message_type_label));
    details.append(res.getString(R.string.multimedia_message));

    if (msg instanceof RetrieveConf) {
      // From: ***
      String from = extractEncStr(context, ((RetrieveConf) msg).getFrom());
      details.append('\n');
      details.append(res.getString(R.string.from_label));
      details.append(
          !TextUtils.isEmpty(from) ? from : res.getString(R.string.hidden_sender_address));
    }

    // To: ***
    details.append('\n');
    details.append(res.getString(R.string.to_address_label));
    EncodedStringValue[] to = msg.getTo();
    if (to != null) {
      details.append(EncodedStringValue.concat(to));
    } else {
      Log.w(TAG, "recipient list is empty!");
    }

    // Bcc: ***
    if (msg instanceof SendReq) {
      EncodedStringValue[] values = ((SendReq) msg).getBcc();
      if ((values != null) && (values.length > 0)) {
        details.append('\n');
        details.append(res.getString(R.string.bcc_label));
        details.append(EncodedStringValue.concat(values));
      }
    }

    // Date: ***
    details.append('\n');
    int msgBox = cursor.getInt(MessageListAdapter.COLUMN_MMS_MESSAGE_BOX);
    if (msgBox == Mms.MESSAGE_BOX_DRAFTS) {
      details.append(res.getString(R.string.saved_label));
    } else if (msgBox == Mms.MESSAGE_BOX_INBOX) {
      details.append(res.getString(R.string.received_label));
    } else {
      details.append(res.getString(R.string.sent_label));
    }

    details.append(MessageUtils.formatTimeStampString(context, msg.getDate() * 1000L, true));

    // Subject: ***
    details.append('\n');
    details.append(res.getString(R.string.subject_label));

    EncodedStringValue subject = msg.getSubject();
    if (subject != null) {
      String subStr = subject.getString();
      // Message size should include size of subject.
      size += subStr.length();
      details.append(subStr);
    }

    // Priority: High/Normal/Low
    details.append('\n');
    details.append(res.getString(R.string.priority_label));
    details.append(getPriorityDescription(context, msg.getPriority()));

    // Message size: *** KB
    details.append('\n');
    details.append(res.getString(R.string.message_size_label));
    details.append((size - 1) / 1000 + 1);
    details.append(" KB");

    return details.toString();
  }