use of com.google.android.mms.MmsException in project android-aosp-mms by slvn.
the class MessageUtils method getMultimediaMessageDetails.
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();
}
use of com.google.android.mms.MmsException in project android-aosp-mms by slvn.
the class MessageUtils method getNotificationIndDetails.
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();
}
use of com.google.android.mms.MmsException in project android-aosp-mms by slvn.
the class SlideshowEditActivity method onPause.
@Override
protected void onPause() {
super.onPause();
synchronized (this) {
if (mDirty) {
try {
PduBody pb = mSlideshowModel.toPduBody();
PduPersister.getPduPersister(this).updateParts(mUri, pb, null);
mSlideshowModel.sync(pb);
} catch (MmsException e) {
Log.e(TAG, "Cannot update the message: " + mUri, e);
}
}
}
}
use of com.google.android.mms.MmsException in project android-aosp-mms by slvn.
the class SlideshowEditActivity method onCreate.
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
mList = getListView();
mAddSlideItem = createAddSlideItem();
mList.addFooterView(mAddSlideItem);
mAddSlideItem.setVisibility(View.GONE);
if (icicle != null) {
// Retrieve previously saved state of this activity.
mState = icicle.getBundle(STATE);
}
if (mState != null) {
mUri = Uri.parse(mState.getString(MESSAGE_URI));
} else {
mUri = getIntent().getData();
}
if (mUri == null) {
Log.e(TAG, "Cannot startup activity, null Uri.");
finish();
return;
}
// Return the Uri of the message to whoever invoked us.
mResultIntent = new Intent();
mResultIntent.setData(mUri);
try {
initSlideList();
adjustAddSlideVisibility();
} catch (MmsException e) {
Log.e(TAG, "Failed to initialize the slide-list.", e);
finish();
}
registerForContextMenu(mList);
}
use of com.google.android.mms.MmsException in project android-aosp-mms by slvn.
the class SlideEditorActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
switch(requestCode) {
case REQUEST_CODE_EDIT_TEXT:
// XXX where does this come from? Action is probably not the
// right place to have the text...
mSlideshowEditor.changeText(mPosition, data.getAction());
break;
case REQUEST_CODE_TAKE_PICTURE:
Uri pictureUri = null;
boolean showError = false;
try {
pictureUri = TempFileProvider.renameScrapFile(".jpg", Integer.toString(mPosition), this);
if (pictureUri == null) {
showError = true;
} else {
// Remove the old captured picture's thumbnail from the cache
MmsApp.getApplication().getThumbnailManager().removeThumbnail(pictureUri);
mSlideshowEditor.changeImage(mPosition, pictureUri);
setReplaceButtonText(R.string.replace_image);
}
} catch (MmsException e) {
Log.e(TAG, "add image failed", e);
showError = true;
} catch (UnsupportContentTypeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getPictureString()), getResourcesString(R.string.select_different_media, getPictureString()));
} catch (ResolutionException e) {
MessageUtils.resizeImageAsync(this, pictureUri, new Handler(), mResizeImageCallback, false);
} catch (ExceedMessageSizeException e) {
MessageUtils.resizeImageAsync(this, pictureUri, new Handler(), mResizeImageCallback, false);
}
if (showError) {
notifyUser("add picture failed");
Toast.makeText(SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getPictureString()), Toast.LENGTH_SHORT).show();
}
break;
case REQUEST_CODE_CHANGE_PICTURE:
try {
mSlideshowEditor.changeImage(mPosition, data.getData());
setReplaceButtonText(R.string.replace_image);
} catch (MmsException e) {
Log.e(TAG, "add image failed", e);
notifyUser("add picture failed");
Toast.makeText(SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getPictureString()), Toast.LENGTH_SHORT).show();
} catch (UnsupportContentTypeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getPictureString()), getResourcesString(R.string.select_different_media, getPictureString()));
} catch (ResolutionException e) {
MessageUtils.resizeImageAsync(this, data.getData(), new Handler(), mResizeImageCallback, false);
} catch (ExceedMessageSizeException e) {
MessageUtils.resizeImageAsync(this, data.getData(), new Handler(), mResizeImageCallback, false);
}
break;
case REQUEST_CODE_CHANGE_MUSIC:
case REQUEST_CODE_RECORD_SOUND:
Uri uri;
if (requestCode == REQUEST_CODE_CHANGE_MUSIC) {
uri = (Uri) data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (Settings.System.DEFAULT_RINGTONE_URI.equals(uri)) {
return;
}
} else {
uri = data.getData();
}
try {
mSlideshowEditor.changeAudio(mPosition, uri);
} catch (MmsException e) {
Log.e(TAG, "add audio failed", e);
notifyUser("add music failed");
Toast.makeText(SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getAudioString()), Toast.LENGTH_SHORT).show();
} catch (UnsupportContentTypeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getAudioString()), getResourcesString(R.string.select_different_media, getAudioString()));
} catch (ExceedMessageSizeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.exceed_message_size_limitation), getResourcesString(R.string.failed_to_add_media, getAudioString()));
}
break;
case REQUEST_CODE_TAKE_VIDEO:
try {
Uri videoUri = TempFileProvider.renameScrapFile(".3gp", Integer.toString(mPosition), this);
mSlideshowEditor.changeVideo(mPosition, videoUri);
} catch (MmsException e) {
notifyUser("add video failed");
Toast.makeText(SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getVideoString()), Toast.LENGTH_SHORT).show();
} catch (UnsupportContentTypeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getVideoString()), getResourcesString(R.string.select_different_media, getVideoString()));
} catch (ExceedMessageSizeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.exceed_message_size_limitation), getResourcesString(R.string.failed_to_add_media, getVideoString()));
}
break;
case REQUEST_CODE_CHANGE_VIDEO:
try {
mSlideshowEditor.changeVideo(mPosition, data.getData());
} catch (MmsException e) {
Log.e(TAG, "add video failed", e);
notifyUser("add video failed");
Toast.makeText(SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getVideoString()), Toast.LENGTH_SHORT).show();
} catch (UnsupportContentTypeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getVideoString()), getResourcesString(R.string.select_different_media, getVideoString()));
} catch (ExceedMessageSizeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.exceed_message_size_limitation), getResourcesString(R.string.failed_to_add_media, getVideoString()));
}
break;
case REQUEST_CODE_CHANGE_DURATION:
mSlideshowEditor.changeDuration(mPosition, Integer.valueOf(data.getAction()) * 1000);
break;
}
}
Aggregations