MessageItempublic class MessageItem extends Object Mostly immutable model for an SMS/MMS message.
The only mutable field is the cached formatted message member,
the formatting of which is done outside this model in MessageListItem. |
Fields Summary |
---|
private static String | TAG | final android.content.Context | mContext | final String | mType | final long | mMsgId | final int | mBoxId | boolean | mDeliveryReport | boolean | mReadReport | String | mTimestamp | String | mAddress | String | mContact | String | mBody | CharSequence | mCachedFormattedMessage | android.net.Uri | mMessageUri | int | mMessageType | int | mAttachmentType | String | mSubject | com.android.mms.model.SlideshowModel | mSlideshow | int | mMessageSize | int | mErrorType | int | mThreadType |
Constructors Summary |
---|
MessageItem(android.content.Context context, String type, android.database.Cursor cursor, com.android.mms.ui.MessageListAdapter.ColumnsMap columnsMap, int threadType)
mContext = context;
mThreadType = threadType;
mMsgId = cursor.getLong(columnsMap.mColumnMsgId);
if ("sms".equals(type)) {
ContactInfoCache infoCache = ContactInfoCache.getInstance();
mReadReport = false; // No read reports in sms
mDeliveryReport = (cursor.getLong(columnsMap.mColumnSmsStatus)
!= Sms.STATUS_NONE);
mMessageUri = ContentUris.withAppendedId(Sms.CONTENT_URI, mMsgId);
// Set contact and message body
mBoxId = cursor.getInt(columnsMap.mColumnSmsType);
mAddress = cursor.getString(columnsMap.mColumnSmsAddress);
if (Sms.isOutgoingFolder(mBoxId)) {
String meString = context.getString(
R.string.messagelist_sender_self);
if (mThreadType == Threads.COMMON_THREAD) {
mContact = meString;
} else {
mContact = String.format(
context.getString(R.string.broadcast_from_to),
meString,
infoCache.getContactName(context, mAddress));
}
} else {
// For incoming messages, the ADDRESS field contains the sender.
mContact = infoCache.getContactName(context, mAddress);
}
mBody = cursor.getString(columnsMap.mColumnSmsBody);
// Set time stamp
long date = cursor.getLong(columnsMap.mColumnSmsDate);
mTimestamp = String.format(context.getString(R.string.sent_on),
MessageUtils.formatTimeStampString(context, date));
} else if ("mms".equals(type)) {
mMessageUri = ContentUris.withAppendedId(Mms.CONTENT_URI, mMsgId);
mBoxId = cursor.getInt(columnsMap.mColumnMmsMessageBox);
mMessageType = cursor.getInt(columnsMap.mColumnMmsMessageType);
mErrorType = cursor.getInt(columnsMap.mColumnMmsErrorType);
String subject = cursor.getString(columnsMap.mColumnMmsSubject);
if (!TextUtils.isEmpty(subject)) {
EncodedStringValue v = new EncodedStringValue(
cursor.getInt(columnsMap.mColumnMmsSubjectCharset),
PduPersister.getBytes(subject));
mSubject = v.getString();
}
long timestamp = 0L;
PduPersister p = PduPersister.getPduPersister(mContext);
if (PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND == mMessageType) {
mDeliveryReport = false;
NotificationInd notifInd = (NotificationInd) p.load(mMessageUri);
interpretFrom(notifInd.getFrom());
// Borrow the mBody to hold the URL of the message.
mBody = new String(notifInd.getContentLocation());
mMessageSize = (int) notifInd.getMessageSize();
timestamp = notifInd.getExpiry() * 1000L;
} else {
MultimediaMessagePdu msg = (MultimediaMessagePdu) p.load(mMessageUri);
mSlideshow = SlideshowModel.createFromPduBody(context, msg.getBody());
mAttachmentType = MessageUtils.getAttachmentType(mSlideshow);
if (mMessageType == PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF) {
RetrieveConf retrieveConf = (RetrieveConf) msg;
interpretFrom(retrieveConf.getFrom());
timestamp = retrieveConf.getDate() * 1000L;
} else {
// Use constant string for outgoing messages
mContact = mAddress = context.getString(
R.string.messagelist_sender_self);
timestamp = ((SendReq) msg).getDate() * 1000L;
}
String report = cursor.getString(columnsMap.mColumnMmsDeliveryReport);
if ((report == null) || !mAddress.equals(context.getString(
R.string.messagelist_sender_self))) {
mDeliveryReport = false;
} else {
int reportInt;
try {
reportInt = Integer.parseInt(report);
mDeliveryReport =
(reportInt == PduHeaders.VALUE_YES);
} catch (NumberFormatException nfe) {
Log.e(TAG, "Value for delivery report was invalid.");
mDeliveryReport = false;
}
}
report = cursor.getString(columnsMap.mColumnMmsReadReport);
if ((report == null) || !mAddress.equals(context.getString(
R.string.messagelist_sender_self))) {
mReadReport = false;
} else {
int reportInt;
try {
reportInt = Integer.parseInt(report);
mReadReport = (reportInt == PduHeaders.VALUE_YES);
} catch (NumberFormatException nfe) {
Log.e(TAG, "Value for read report was invalid.");
mReadReport = false;
}
}
SlideModel slide = mSlideshow.get(0);
if ((slide != null) && slide.hasText()) {
TextModel tm = slide.getText();
if (tm.isDrmProtected()) {
mBody = mContext.getString(R.string.drm_protected_text);
} else {
mBody = slide.getText().getText();
}
}
mMessageSize = mSlideshow.getCurrentMessageSize();
}
mTimestamp = context.getString(getTimestampStrId(),
MessageUtils.formatTimeStampString(context, timestamp));
} else {
throw new MmsException("Unknown type of the message: " + type);
}
mType = type;
|
Methods Summary |
---|
public java.lang.CharSequence | getCachedFormattedMessage()
return mCachedFormattedMessage;
| private int | getTimestampStrId()
if (PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND == mMessageType) {
return R.string.expire_on;
} else {
return R.string.sent_on;
}
| private void | interpretFrom(com.google.android.mms.pdu.EncodedStringValue from)
if (from != null) {
mAddress = from.getString();
mContact = ContactInfoCache.getInstance().getContactName(mContext, mAddress);
} else {
mContact = mAddress = mContext.getString(
R.string.anonymous_recipient);
}
| public boolean | isDownloaded()
return (mMessageType != PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND);
| public boolean | isMms()
return mType.equals("mms");
| public boolean | isOutgoingMessage()
boolean isOutgoingMms = isMms() && (mBoxId == Mms.MESSAGE_BOX_OUTBOX);
boolean isOutgoingSms = isSms()
&& ((mBoxId == Sms.MESSAGE_TYPE_FAILED)
|| (mBoxId == Sms.MESSAGE_TYPE_OUTBOX)
|| (mBoxId == Sms.MESSAGE_TYPE_QUEUED));
return isOutgoingMms || isOutgoingSms;
| public boolean | isSms()
return mType.equals("sms");
| public void | setCachedFormattedMessage(java.lang.CharSequence formattedMessage)
mCachedFormattedMessage = formattedMessage;
|
|