use of com.google.android.mms.pdu.PduPart in project android-aosp-mms by slvn.
the class ImageModel method resizeMedia.
@Override
protected void resizeMedia(int byteLimit, long messageId) throws MmsException {
UriImage image = new UriImage(mContext, getUri());
int widthLimit = MmsConfig.getMaxImageWidth();
int heightLimit = MmsConfig.getMaxImageHeight();
int size = getMediaSize();
// possible.
if (image.getHeight() > image.getWidth()) {
int temp = widthLimit;
widthLimit = heightLimit;
heightLimit = temp;
}
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "resizeMedia size: " + size + " image.getWidth(): " + image.getWidth() + " widthLimit: " + widthLimit + " image.getHeight(): " + image.getHeight() + " heightLimit: " + heightLimit + " image.getContentType(): " + image.getContentType());
}
// set the size.
if (size != 0 && size <= byteLimit && image.getWidth() <= widthLimit && image.getHeight() <= heightLimit && SUPPORTED_MMS_IMAGE_CONTENT_TYPES.contains(image.getContentType())) {
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "resizeMedia - already sized");
}
return;
}
PduPart part = image.getResizedImageAsPart(widthLimit, heightLimit, byteLimit);
if (part == null) {
throw new ExceedMessageSizeException("Not enough memory to turn image into part: " + getUri());
}
// Update the content type because it may have changed due to resizing/recompressing
mContentType = new String(part.getContentType());
String src = getSrc();
byte[] srcBytes = src.getBytes();
part.setContentLocation(srcBytes);
int period = src.lastIndexOf(".");
byte[] contentId = period != -1 ? src.substring(0, period).getBytes() : srcBytes;
part.setContentId(contentId);
PduPersister persister = PduPersister.getPduPersister(mContext);
this.mSize = part.getData().length;
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "resizeMedia mSize: " + mSize);
}
Uri newUri = persister.persistPart(part, messageId, null);
setUri(newUri);
}
use of com.google.android.mms.pdu.PduPart in project android-aosp-mms by slvn.
the class MediaModelFactory method getMediaModel.
public static MediaModel getMediaModel(Context context, SMILMediaElement sme, LayoutModel layouts, PduBody pb) throws IOException, IllegalArgumentException, MmsException {
String tag = sme.getTagName();
String src = sme.getSrc();
PduPart part = findPart(pb, src);
if (sme instanceof SMILRegionMediaElement) {
return getRegionMediaModel(context, tag, src, (SMILRegionMediaElement) sme, layouts, part);
} else {
return getGenericMediaModel(context, tag, src, sme, part, null);
}
}
use of com.google.android.mms.pdu.PduPart in project android-aosp-mms by slvn.
the class ComposeMessageActivity method haveSomethingToCopyToSDCard.
/**
* Looks to see if there are any valid parts of the attachment that can be copied to a SD card.
* @param msgId
*/
private boolean haveSomethingToCopyToSDCard(long msgId) {
PduBody body = null;
try {
body = SlideshowModel.getPduBody(this, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
} catch (MmsException e) {
Log.e(TAG, "haveSomethingToCopyToSDCard can't load pdu body: " + msgId);
}
if (body == null) {
return false;
}
boolean result = false;
int partNum = body.getPartsNum();
for (int i = 0; i < partNum; i++) {
PduPart part = body.getPart(i);
String type = new String(part.getContentType());
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
log("[CMA] haveSomethingToCopyToSDCard: part[" + i + "] contentType=" + type);
}
if (ContentType.isImageType(type) || ContentType.isVideoType(type) || ContentType.isAudioType(type) || DrmUtils.isDrmType(type)) {
result = true;
break;
}
}
return result;
}
use of com.google.android.mms.pdu.PduPart in project android-aosp-mms by slvn.
the class ComposeMessageActivity method isForwardable.
/**
* Returns true if all drm'd parts are forwardable.
* @param msgId
* @return true if all drm'd parts are forwardable.
*/
private boolean isForwardable(long msgId) {
PduBody body = null;
try {
body = SlideshowModel.getPduBody(this, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
} catch (MmsException e) {
Log.e(TAG, "getDrmMimeType can't load pdu body: " + msgId);
}
if (body == null) {
return false;
}
int partNum = body.getPartsNum();
for (int i = 0; i < partNum; i++) {
PduPart part = body.getPart(i);
String type = new String(part.getContentType());
if (DrmUtils.isDrmType(type) && !DrmUtils.haveRightsForAction(part.getDataUri(), DrmStore.Action.TRANSFER)) {
return false;
}
}
return true;
}
use of com.google.android.mms.pdu.PduPart in project android-aosp-mms by slvn.
the class MessageUtils method resizeImageAsync.
public static void resizeImageAsync(final Context context, final Uri imageUri, final Handler handler, final ResizeImageResultCallback cb, final boolean append) {
// Show a progress toast if the resize hasn't finished
// within one second.
// Stash the runnable for showing it away so we can cancel
// it later if the resize completes ahead of the deadline.
final Runnable showProgress = new Runnable() {
@Override
public void run() {
Toast.makeText(context, R.string.compressing, Toast.LENGTH_SHORT).show();
}
};
// Schedule it for one second from now.
handler.postDelayed(showProgress, 1000);
new Thread(new Runnable() {
@Override
public void run() {
final PduPart part;
try {
UriImage image = new UriImage(context, imageUri);
int widthLimit = MmsConfig.getMaxImageWidth();
int heightLimit = MmsConfig.getMaxImageHeight();
// as little as possible.
if (image.getHeight() > image.getWidth()) {
int temp = widthLimit;
widthLimit = heightLimit;
heightLimit = temp;
}
part = image.getResizedImageAsPart(widthLimit, heightLimit, MmsConfig.getMaxMessageSize() - MESSAGE_OVERHEAD);
} finally {
// Cancel pending show of the progress toast if necessary.
handler.removeCallbacks(showProgress);
}
handler.post(new Runnable() {
@Override
public void run() {
cb.onResizeResult(part, append);
}
});
}
}, "MessageUtils.resizeImageAsync").start();
}
Aggregations