Search in sources :

Example 1 with SMILParElement

use of org.w3c.dom.smil.SMILParElement in project qksms by moezbhatti.

the class SmilHelper method createSmilDocument.

private static SMILDocument createSmilDocument(SlideshowModel slideshow) {
    if (Config.LOGV) {
        Log.v(TAG, "Creating SMIL document from SlideshowModel.");
    }
    SMILDocument document = new SmilDocumentImpl();
    // Create SMIL and append it to document
    SMILElement smilElement = (SMILElement) document.createElement("smil");
    document.appendChild(smilElement);
    // Create HEAD and append it to SMIL
    SMILElement headElement = (SMILElement) document.createElement("head");
    smilElement.appendChild(headElement);
    // Create LAYOUT and append it to HEAD
    SMILLayoutElement layoutElement = (SMILLayoutElement) document.createElement("layout");
    headElement.appendChild(layoutElement);
    // Create ROOT-LAYOUT and append it to LAYOUT
    SMILRootLayoutElement rootLayoutElement = (SMILRootLayoutElement) document.createElement("root-layout");
    LayoutModel layouts = slideshow.getLayout();
    rootLayoutElement.setWidth(layouts.getLayoutWidth());
    rootLayoutElement.setHeight(layouts.getLayoutHeight());
    String bgColor = layouts.getBackgroundColor();
    if (!TextUtils.isEmpty(bgColor)) {
        rootLayoutElement.setBackgroundColor(bgColor);
    }
    layoutElement.appendChild(rootLayoutElement);
    // Create REGIONs and append them to LAYOUT
    ArrayList<RegionModel> regions = layouts.getRegions();
    ArrayList<SMILRegionElement> smilRegions = new ArrayList<>();
    for (RegionModel r : regions) {
        SMILRegionElement smilRegion = (SMILRegionElement) document.createElement("region");
        smilRegion.setId(r.getRegionId());
        smilRegion.setLeft(r.getLeft());
        smilRegion.setTop(r.getTop());
        smilRegion.setWidth(r.getWidth());
        smilRegion.setHeight(r.getHeight());
        smilRegion.setFit(r.getFit());
        smilRegions.add(smilRegion);
    }
    // Create BODY and append it to the document.
    SMILElement bodyElement = (SMILElement) document.createElement("body");
    smilElement.appendChild(bodyElement);
    for (SlideModel slide : slideshow) {
        boolean txtRegionPresentInLayout = false;
        boolean imgRegionPresentInLayout = false;
        // Create PAR element.
        SMILParElement par = addPar(document);
        par.setDur(slide.getDuration() / 1000f);
        addParElementEventListeners((EventTarget) par, slide);
        // Add all media elements.
        for (MediaModel media : slide) {
            SMILMediaElement sme = null;
            String src = media.getSrc();
            if (media instanceof TextModel) {
                TextModel text = (TextModel) media;
                if (TextUtils.isEmpty(text.getText())) {
                    if (LOCAL_LOGV) {
                        Log.v(TAG, "Empty text part ignored: " + text.getSrc());
                    }
                    continue;
                }
                sme = SmilHelper.createMediaElement(SmilHelper.ELEMENT_TAG_TEXT, document, src);
                txtRegionPresentInLayout = setRegion((SMILRegionMediaElement) sme, smilRegions, layoutElement, LayoutModel.TEXT_REGION_ID, txtRegionPresentInLayout);
            } else if (media instanceof ImageModel) {
                sme = SmilHelper.createMediaElement(SmilHelper.ELEMENT_TAG_IMAGE, document, src);
                imgRegionPresentInLayout = setRegion((SMILRegionMediaElement) sme, smilRegions, layoutElement, LayoutModel.IMAGE_REGION_ID, imgRegionPresentInLayout);
            } else if (media instanceof VideoModel) {
                sme = SmilHelper.createMediaElement(SmilHelper.ELEMENT_TAG_VIDEO, document, src);
                imgRegionPresentInLayout = setRegion((SMILRegionMediaElement) sme, smilRegions, layoutElement, LayoutModel.IMAGE_REGION_ID, imgRegionPresentInLayout);
            } else if (media instanceof AudioModel) {
                sme = SmilHelper.createMediaElement(SmilHelper.ELEMENT_TAG_AUDIO, document, src);
            } else {
                Log.w(TAG, "Unsupport media: " + media);
                continue;
            }
            // Set timing information.
            int begin = media.getBegin();
            if (begin != 0) {
                sme.setAttribute("begin", String.valueOf(begin / 1000));
            }
            int duration = media.getDuration();
            if (duration != 0) {
                sme.setDur((float) duration / 1000);
            }
            par.appendChild(sme);
            addMediaElementEventListeners((EventTarget) sme, media);
        }
    }
    if (LOCAL_LOGV) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        SmilXmlSerializer.serialize(document, out);
        Log.v(TAG, out.toString());
    }
    return document;
}
Also used : SMILDocument(org.w3c.dom.smil.SMILDocument) ArrayList(java.util.ArrayList) SMILElement(org.w3c.dom.smil.SMILElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SMILMediaElement(org.w3c.dom.smil.SMILMediaElement) SmilDocumentImpl(com.android.mms.dom.smil.SmilDocumentImpl) SMILRootLayoutElement(org.w3c.dom.smil.SMILRootLayoutElement) SMILLayoutElement(org.w3c.dom.smil.SMILLayoutElement) SMILParElement(org.w3c.dom.smil.SMILParElement) SMILRegionElement(org.w3c.dom.smil.SMILRegionElement) SMILRegionMediaElement(org.w3c.dom.smil.SMILRegionMediaElement)

Example 2 with SMILParElement

use of org.w3c.dom.smil.SMILParElement in project Signal-Android by WhisperSystems.

the class SmilUtil method createSmilDocument.

private static SMILDocument createSmilDocument(PduBody body) {
    Log.w(TAG, "Creating SMIL document from PduBody.");
    SMILDocument document = new SmilDocumentImpl();
    SMILElement smilElement = (SMILElement) document.createElement("smil");
    document.appendChild(smilElement);
    SMILElement headElement = (SMILElement) document.createElement("head");
    smilElement.appendChild(headElement);
    SMILLayoutElement layoutElement = (SMILLayoutElement) document.createElement("layout");
    headElement.appendChild(layoutElement);
    SMILRootLayoutElement rootLayoutElement = (SMILRootLayoutElement) document.createElement("root-layout");
    rootLayoutElement.setWidth(ROOT_WIDTH);
    rootLayoutElement.setHeight(ROOT_HEIGHT);
    layoutElement.appendChild(rootLayoutElement);
    SMILElement bodyElement = (SMILElement) document.createElement("body");
    smilElement.appendChild(bodyElement);
    SMILParElement par = (SMILParElement) document.createElement("par");
    bodyElement.appendChild(par);
    for (int i = 0; i < body.getPartsNum(); i++) {
        PduPart part = body.getPart(i);
        SMILRegionElement regionElement = getRegion(document, part);
        SMILMediaElement mediaElement = getMediaElement(document, part);
        if (regionElement != null) {
            ((SMILRegionMediaElement) mediaElement).setRegion(regionElement);
            layoutElement.appendChild(regionElement);
        }
        par.appendChild(mediaElement);
    }
    return document;
}
Also used : SMILMediaElement(org.w3c.dom.smil.SMILMediaElement) SMILDocument(org.w3c.dom.smil.SMILDocument) SmilDocumentImpl(org.thoughtcrime.securesms.dom.smil.SmilDocumentImpl) SMILRootLayoutElement(org.w3c.dom.smil.SMILRootLayoutElement) SMILLayoutElement(org.w3c.dom.smil.SMILLayoutElement) SMILParElement(org.w3c.dom.smil.SMILParElement) PduPart(ws.com.google.android.mms.pdu.PduPart) SMILElement(org.w3c.dom.smil.SMILElement) SMILRegionElement(org.w3c.dom.smil.SMILRegionElement) SMILRegionMediaElement(org.w3c.dom.smil.SMILRegionMediaElement)

Example 3 with SMILParElement

use of org.w3c.dom.smil.SMILParElement in project qksms by moezbhatti.

the class SmilHelper method createSmilDocument.

public static SMILDocument createSmilDocument(PduBody pb) {
    SMILDocument document = new SmilDocumentImpl();
    // Create root element.
    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;
    }
    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.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 if (contentType.equals(ContentType.TEXT_VCARD)) {
            SMILMediaElement textElement = createMediaElement(ELEMENT_TAG_VCARD, document, part.generateLocation());
            par.appendChild(textElement);
            hasMedia = true;
        } else {
            Log.e("creating_smil_document", "unknown mimetype");
        }
    }
    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_alt.PduPart) SMILElement(org.w3c.dom.smil.SMILElement)

Example 4 with SMILParElement

use of org.w3c.dom.smil.SMILParElement in project qksms by moezbhatti.

the class SmilHelper method addPar.

public static SMILParElement addPar(SMILDocument document) {
    SMILParElement par = (SMILParElement) document.createElement("par");
    // Set duration to eight seconds by default.
    par.setDur(8.0f);
    document.getBody().appendChild(par);
    return par;
}
Also used : SMILParElement(org.w3c.dom.smil.SMILParElement)

Example 5 with SMILParElement

use of org.w3c.dom.smil.SMILParElement in project qksms by moezbhatti.

the class SlideshowModel method createFromPduBody.

public static SlideshowModel createFromPduBody(Context context, PduBody pb) throws MmsException {
    SMILDocument document = SmilHelper.getDocument(pb);
    // Create root-layout model.
    SMILLayoutElement sle = document.getLayout();
    SMILRootLayoutElement srle = sle.getRootLayout();
    int w = srle.getWidth();
    int h = srle.getHeight();
    if ((w == 0) || (h == 0)) {
        w = LayoutManager.getInstance().getLayoutParameters().getWidth();
        h = LayoutManager.getInstance().getLayoutParameters().getHeight();
        srle.setWidth(w);
        srle.setHeight(h);
    }
    RegionModel rootLayout = new RegionModel(null, 0, 0, w, h);
    // Create region models.
    ArrayList<RegionModel> regions = new ArrayList<>();
    NodeList nlRegions = sle.getRegions();
    int regionsNum = nlRegions.getLength();
    for (int i = 0; i < regionsNum; i++) {
        SMILRegionElement sre = (SMILRegionElement) nlRegions.item(i);
        RegionModel r = new RegionModel(sre.getId(), sre.getFit(), sre.getLeft(), sre.getTop(), sre.getWidth(), sre.getHeight(), sre.getBackgroundColor());
        regions.add(r);
    }
    LayoutModel layouts = new LayoutModel(rootLayout, regions);
    // Create slide models.
    SMILElement docBody = document.getBody();
    NodeList slideNodes = docBody.getChildNodes();
    int slidesNum = slideNodes.getLength();
    ArrayList<SlideModel> slides = new ArrayList<>(slidesNum);
    int totalMessageSize = 0;
    for (int i = 0; i < slidesNum; i++) {
        // FIXME: This is NOT compatible with the SMILDocument which is
        // generated by some other mobile phones.
        SMILParElement par = (SMILParElement) slideNodes.item(i);
        // Create media models for each slide.
        NodeList mediaNodes = par.getChildNodes();
        int mediaNum = mediaNodes.getLength();
        ArrayList<MediaModel> mediaSet = new ArrayList<>(mediaNum);
        ArrayList<String> srcs = new ArrayList<>(mediaNum);
        for (int j = 0; j < mediaNum; j++) {
            SMILMediaElement sme = (SMILMediaElement) mediaNodes.item(j);
            srcs.add(sme.getSrc());
        }
        for (int j = 0; j < mediaNum; j++) {
            SMILMediaElement sme = (SMILMediaElement) mediaNodes.item(j);
            try {
                MediaModel media = MediaModelFactory.getMediaModel(context, sme, srcs, layouts, pb);
                /*
                    * This is for slide duration value set.
                    * If mms server does not support slide duration.
                    */
                if (!MmsConfig.getSlideDurationEnabled()) {
                    int mediadur = media.getDuration();
                    float dur = par.getDur();
                    if (dur == 0) {
                        mediadur = MmsConfig.getMinimumSlideElementDuration() * 1000;
                        media.setDuration(mediadur);
                    }
                    if ((int) mediadur / 1000 != dur) {
                        String tag = sme.getTagName();
                        if (ContentType.isVideoType(media.mContentType) || tag.equals(SmilHelper.ELEMENT_TAG_VIDEO) || ContentType.isAudioType(media.mContentType) || tag.equals(SmilHelper.ELEMENT_TAG_AUDIO)) {
                            /*
                                * add 1 sec to release and close audio/video
                                * for guaranteeing the audio/video playing.
                                * because the mmsc does not support the slide duration.
                                */
                            par.setDur((float) mediadur / 1000 + 1);
                        } else {
                            /*
                                * If a slide has an image and an audio/video element
                                * and the audio/video element has longer duration than the image,
                                * The Image disappear before the slide play done. so have to match
                                * an image duration to the slide duration.
                                */
                            if ((int) mediadur / 1000 < dur) {
                                media.setDuration((int) dur * 1000);
                            } else {
                                if ((int) dur != 0) {
                                    media.setDuration((int) dur * 1000);
                                } else {
                                    par.setDur((float) mediadur / 1000);
                                }
                            }
                        }
                    }
                }
                SmilHelper.addMediaElementEventListeners((EventTarget) sme, media);
                mediaSet.add(media);
                totalMessageSize += media.getMediaSize();
            } catch (IOException e) {
                Log.e(TAG, e.getMessage(), e);
            } catch (IllegalArgumentException e) {
                Log.e(TAG, e.getMessage(), e);
            } catch (UnsupportContentTypeException e) {
                Log.e(TAG, e.getMessage(), e);
            }
        }
        SlideModel slide = new SlideModel((int) (par.getDur() * 1000), mediaSet);
        slide.setFill(par.getFill());
        SmilHelper.addParElementEventListeners((EventTarget) par, slide);
        slides.add(slide);
    }
    SlideshowModel slideshow = new SlideshowModel(layouts, slides, document, pb, context);
    slideshow.mTotalMessageSize = totalMessageSize;
    slideshow.registerModelChangedObserver(slideshow);
    return slideshow;
}
Also used : SMILDocument(org.w3c.dom.smil.SMILDocument) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) SMILElement(org.w3c.dom.smil.SMILElement) IOException(java.io.IOException) UnsupportContentTypeException(com.moez.QKSMS.UnsupportContentTypeException) SMILMediaElement(org.w3c.dom.smil.SMILMediaElement) SMILRootLayoutElement(org.w3c.dom.smil.SMILRootLayoutElement) SMILLayoutElement(org.w3c.dom.smil.SMILLayoutElement) SMILParElement(org.w3c.dom.smil.SMILParElement) SMILRegionElement(org.w3c.dom.smil.SMILRegionElement)

Aggregations

SMILParElement (org.w3c.dom.smil.SMILParElement)7 SMILDocument (org.w3c.dom.smil.SMILDocument)5 SMILElement (org.w3c.dom.smil.SMILElement)5 SMILLayoutElement (org.w3c.dom.smil.SMILLayoutElement)5 SMILMediaElement (org.w3c.dom.smil.SMILMediaElement)5 SmilDocumentImpl (com.android.mms.dom.smil.SmilDocumentImpl)3 SMILRegionElement (org.w3c.dom.smil.SMILRegionElement)3 SMILRootLayoutElement (org.w3c.dom.smil.SMILRootLayoutElement)3 PduPart (com.google.android.mms.pdu_alt.PduPart)2 ArrayList (java.util.ArrayList)2 SMILRegionMediaElement (org.w3c.dom.smil.SMILRegionMediaElement)2 DrmManagerClient (android.drm.DrmManagerClient)1 UnsupportContentTypeException (com.moez.QKSMS.UnsupportContentTypeException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 SmilDocumentImpl (org.thoughtcrime.securesms.dom.smil.SmilDocumentImpl)1 NodeList (org.w3c.dom.NodeList)1 PduPart (ws.com.google.android.mms.pdu.PduPart)1