Search in sources :

Example 11 with PduPart

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

the class SlideshowModel method makePduBody.

private PduBody makePduBody(SMILDocument document) {
    PduBody pb = new PduBody();
    boolean hasForwardLock = false;
    for (SlideModel slide : mSlides) {
        for (MediaModel media : slide) {
            PduPart part = new PduPart();
            if (media.isText()) {
                TextModel text = (TextModel) media;
                // Don't create empty text part.
                if (TextUtils.isEmpty(text.getText())) {
                    continue;
                }
                // Set Charset if it's a text media.
                part.setCharset(text.getCharset());
            }
            // Set Content-Type.
            part.setContentType(media.getContentType().getBytes());
            String src = media.getSrc();
            String location;
            boolean startWithContentId = src.startsWith("cid:");
            if (startWithContentId) {
                location = src.substring("cid:".length());
            } else {
                location = src;
            }
            // Set Content-Location.
            part.setContentLocation(location.getBytes());
            // Set Content-Id.
            if (startWithContentId) {
                // Keep the original Content-Id.
                part.setContentId(location.getBytes());
            } else {
                int index = location.lastIndexOf(".");
                String contentId = (index == -1) ? location : location.substring(0, index);
                part.setContentId(contentId.getBytes());
            }
            if (media.isText()) {
                part.setData(((TextModel) media).getText().getBytes());
            } else if (media.isImage() || media.isVideo() || media.isAudio()) {
                part.setDataUri(media.getUri());
            } else {
                Log.w(TAG, "Unsupport media: " + media);
            }
            pb.addPart(part);
        }
    }
    // Create and insert SMIL part(as the first part) into the PduBody.
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SmilXmlSerializer.serialize(document, out);
    PduPart smilPart = new PduPart();
    smilPart.setContentId("smil".getBytes());
    smilPart.setContentLocation("smil.xml".getBytes());
    smilPart.setContentType(ContentType.APP_SMIL.getBytes());
    smilPart.setData(out.toByteArray());
    pb.addPart(0, smilPart);
    return pb;
}
Also used : PduBody(com.google.android.mms.pdu.PduBody) PduPart(com.google.android.mms.pdu.PduPart) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 12 with PduPart

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

the class SmilHelper method createSmilDocument.

private static SMILDocument createSmilDocument(PduBody pb) {
    if (Config.LOGV) {
        Log.v(TAG, "Creating default SMIL document.");
    }
    SMILDocument document = new SmilDocumentImpl();
    // Create root element.
    // FIXME: Should we create root element in the constructor of document?
    SMILElement smil = (SMILElement) document.createElement("smil");
    smil.setAttribute("xmlns", "http://www.w3.org/2001/SMIL20/Language");
    document.appendChild(smil);
    // Create <head> and <layout> element.
    SMILElement head = (SMILElement) document.createElement("head");
    smil.appendChild(head);
    SMILLayoutElement layout = (SMILLayoutElement) document.createElement("layout");
    head.appendChild(layout);
    // Create <body> element and add a empty <par>.
    SMILElement body = (SMILElement) document.createElement("body");
    smil.appendChild(body);
    SMILParElement par = addPar(document);
    // Create media objects for the parts in PDU.
    int partsNum = pb.getPartsNum();
    if (partsNum == 0) {
        return document;
    }
    DrmManagerClient drmManagerClient = MmsApp.getApplication().getDrmManagerClient();
    boolean hasText = false;
    boolean hasMedia = false;
    for (int i = 0; i < partsNum; i++) {
        // Create new <par> element.
        if ((par == null) || (hasMedia && hasText)) {
            par = addPar(document);
            hasText = false;
            hasMedia = false;
        }
        PduPart part = pb.getPart(i);
        String contentType = new String(part.getContentType());
        if (ContentType.isDrmType(contentType)) {
            contentType = drmManagerClient.getOriginalMimeType(part.getDataUri());
        }
        if (contentType.equals(ContentType.TEXT_PLAIN) || contentType.equalsIgnoreCase(ContentType.APP_WAP_XHTML) || contentType.equals(ContentType.TEXT_HTML)) {
            SMILMediaElement textElement = createMediaElement(ELEMENT_TAG_TEXT, document, part.generateLocation());
            par.appendChild(textElement);
            hasText = true;
        } else if (ContentType.isImageType(contentType)) {
            SMILMediaElement imageElement = createMediaElement(ELEMENT_TAG_IMAGE, document, part.generateLocation());
            par.appendChild(imageElement);
            hasMedia = true;
        } else if (ContentType.isVideoType(contentType)) {
            SMILMediaElement videoElement = createMediaElement(ELEMENT_TAG_VIDEO, document, part.generateLocation());
            par.appendChild(videoElement);
            hasMedia = true;
        } else if (ContentType.isAudioType(contentType)) {
            SMILMediaElement audioElement = createMediaElement(ELEMENT_TAG_AUDIO, document, part.generateLocation());
            par.appendChild(audioElement);
            hasMedia = true;
        } else {
            // TODO: handle other media types.
            Log.w(TAG, "unsupport media type");
        }
    }
    return document;
}
Also used : SMILMediaElement(org.w3c.dom.smil.SMILMediaElement) SMILDocument(org.w3c.dom.smil.SMILDocument) SmilDocumentImpl(com.android.mms.dom.smil.SmilDocumentImpl) SMILLayoutElement(org.w3c.dom.smil.SMILLayoutElement) SMILParElement(org.w3c.dom.smil.SMILParElement) PduPart(com.google.android.mms.pdu.PduPart) SMILElement(org.w3c.dom.smil.SMILElement) DrmManagerClient(android.drm.DrmManagerClient)

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