Search in sources :

Example 6 with PduPart

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);
}
Also used : UriImage(com.android.mms.ui.UriImage) PduPersister(com.google.android.mms.pdu.PduPersister) PduPart(com.google.android.mms.pdu.PduPart) ExceedMessageSizeException(com.android.mms.ExceedMessageSizeException) Uri(android.net.Uri)

Example 7 with PduPart

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);
    }
}
Also used : PduPart(com.google.android.mms.pdu.PduPart) SMILRegionMediaElement(org.w3c.dom.smil.SMILRegionMediaElement)

Example 8 with PduPart

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;
}
Also used : MmsException(com.google.android.mms.MmsException) PduBody(com.google.android.mms.pdu.PduBody) PduPart(com.google.android.mms.pdu.PduPart) SpannableString(android.text.SpannableString)

Example 9 with PduPart

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;
}
Also used : MmsException(com.google.android.mms.MmsException) PduBody(com.google.android.mms.pdu.PduBody) PduPart(com.google.android.mms.pdu.PduPart) SpannableString(android.text.SpannableString)

Example 10 with PduPart

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();
}
Also used : PduPart(com.google.android.mms.pdu.PduPart)

Aggregations

PduPart (com.google.android.mms.pdu.PduPart)12 PduBody (com.google.android.mms.pdu.PduBody)6 MmsException (com.google.android.mms.MmsException)5 SpannableString (android.text.SpannableString)4 SMILDocument (org.w3c.dom.smil.SMILDocument)2 DrmManagerClient (android.drm.DrmManagerClient)1 Uri (android.net.Uri)1 ExceedMessageSizeException (com.android.mms.ExceedMessageSizeException)1 SmilDocumentImpl (com.android.mms.dom.smil.SmilDocumentImpl)1 UriImage (com.android.mms.ui.UriImage)1 PduPersister (com.google.android.mms.pdu.PduPersister)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 SMILElement (org.w3c.dom.smil.SMILElement)1 SMILLayoutElement (org.w3c.dom.smil.SMILLayoutElement)1 SMILMediaElement (org.w3c.dom.smil.SMILMediaElement)1 SMILParElement (org.w3c.dom.smil.SMILParElement)1 SMILRegionMediaElement (org.w3c.dom.smil.SMILRegionMediaElement)1