Search in sources :

Example 1 with PduPart

use of com.google.android.mms.pdu.PduPart in project android-aosp-mms by slvn.

the class ComposeMessageActivity method copyMedia.

/**
 * Copies media from an Mms to the "download" directory on the SD card. If any of the parts
 * are audio types, drm'd or not, they're copied to the "Ringtones" directory.
 * @param msgId
 */
private boolean copyMedia(long msgId) {
    boolean result = true;
    PduBody body = null;
    try {
        body = SlideshowModel.getPduBody(this, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
    } catch (MmsException e) {
        Log.e(TAG, "copyMedia 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);
        // all parts have to be successful for a valid result.
        result &= copyPart(part, Long.toHexString(msgId));
    }
    return result;
}
Also used : MmsException(com.google.android.mms.MmsException) PduBody(com.google.android.mms.pdu.PduBody) PduPart(com.google.android.mms.pdu.PduPart)

Example 2 with PduPart

use of com.google.android.mms.pdu.PduPart in project android-aosp-mms by slvn.

the class ComposeMessageActivity method saveRingtone.

/**
 * Copies media from an Mms to the DrmProvider
 * @param msgId
 */
private boolean saveRingtone(long msgId) {
    boolean result = true;
    PduBody body = null;
    try {
        body = SlideshowModel.getPduBody(this, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
    } catch (MmsException e) {
        Log.e(TAG, "copyToDrmProvider 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)) {
            // All parts (but there's probably only a single one) have to be successful
            // for a valid result.
            result &= copyPart(part, Long.toHexString(msgId));
        }
    }
    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 3 with PduPart

use of com.google.android.mms.pdu.PduPart in project android-aosp-mms by slvn.

the class ComposeMessageActivity method isDrmRingtoneWithRights.

/**
 * Returns true if any part is drm'd audio with ringtone rights.
 * @param msgId
 * @return true if one of the parts is drm'd audio with rights to save as a ringtone.
 */
private boolean isDrmRingtoneWithRights(long msgId) {
    PduBody body = null;
    try {
        body = SlideshowModel.getPduBody(this, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
    } catch (MmsException e) {
        Log.e(TAG, "isDrmRingtoneWithRights 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)) {
            String mimeType = MmsApp.getApplication().getDrmManagerClient().getOriginalMimeType(part.getDataUri());
            if (ContentType.isAudioType(mimeType) && DrmUtils.haveRightsForAction(part.getDataUri(), DrmStore.Action.RINGTONE)) {
                return true;
            }
        }
    }
    return false;
}
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 4 with PduPart

use of com.google.android.mms.pdu.PduPart in project android-aosp-mms by slvn.

the class UriImage method getResizedImageAsPart.

/**
 * Get a version of this image resized to fit the given dimension and byte-size limits. Note
 * that the content type of the resulting PduPart may not be the same as the content type of
 * this UriImage; always call {@link PduPart#getContentType()} to get the new content type.
 *
 * @param widthLimit The width limit, in pixels
 * @param heightLimit The height limit, in pixels
 * @param byteLimit The binary size limit, in bytes
 * @return A new PduPart containing the resized image data
 */
public PduPart getResizedImageAsPart(int widthLimit, int heightLimit, int byteLimit) {
    PduPart part = new PduPart();
    byte[] data = getResizedImageData(mWidth, mHeight, widthLimit, heightLimit, byteLimit, mUri, mContext);
    if (data == null) {
        if (LOCAL_LOGV) {
            Log.v(TAG, "Resize image failed.");
        }
        return null;
    }
    part.setData(data);
    // getResizedImageData ALWAYS compresses to JPEG, regardless of the original content type
    part.setContentType(ContentType.IMAGE_JPEG.getBytes());
    return part;
}
Also used : PduPart(com.google.android.mms.pdu.PduPart)

Example 5 with PduPart

use of com.google.android.mms.pdu.PduPart in project android-aosp-mms by slvn.

the class SmilHelper method getDocument.

public static SMILDocument getDocument(PduBody pb) {
    // Find SMIL part in the message.
    PduPart smilPart = findSmilPart(pb);
    SMILDocument document = null;
    // Try to load SMIL document from existing part.
    if (smilPart != null) {
        document = getSmilDocument(smilPart);
    }
    if (document == null) {
        // Create a new SMIL document.
        document = createSmilDocument(pb);
    }
    return document;
}
Also used : SMILDocument(org.w3c.dom.smil.SMILDocument) 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