Search in sources :

Example 1 with SMILRegionMediaElement

use of org.w3c.dom.smil.SMILRegionMediaElement 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 SMILRegionMediaElement

use of org.w3c.dom.smil.SMILRegionMediaElement 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 SMILRegionMediaElement

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

the class MediaModelFactory method getMediaModel.

/**
 * Returns the media model for the given SMILMediaElement in the PduBody.
 *
 * @param context Context
 * @param sme     The SMILMediaElement to find
 * @param srcs    String array of sources
 * @param layouts LayoutModel
 * @param pb      PduBuddy
 * @return MediaModel
 * @throws IOException
 * @throws IllegalArgumentException
 * @throws MmsException
 */
public static MediaModel getMediaModel(Context context, SMILMediaElement sme, ArrayList<String> srcs, LayoutModel layouts, PduBody pb) throws IOException, IllegalArgumentException, MmsException {
    String tag = sme.getTagName();
    String src = sme.getSrc();
    PduPart part = findPart(context, pb, src, srcs);
    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_alt.PduPart) SMILRegionMediaElement(org.w3c.dom.smil.SMILRegionMediaElement)

Example 4 with SMILRegionMediaElement

use of org.w3c.dom.smil.SMILRegionMediaElement in project android-aosp-mms by slvn.

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<SMILRegionElement>();
    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 5 with SMILRegionMediaElement

use of org.w3c.dom.smil.SMILRegionMediaElement 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)

Aggregations

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