Search in sources :

Example 16 with SMILElement

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

Example 17 with SMILElement

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

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 = QKSMSApp.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_alt.PduPart) SMILElement(org.w3c.dom.smil.SMILElement) DrmManagerClient(android.drm.DrmManagerClient)

Example 18 with SMILElement

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

the class SlideshowActivity method isMMSConformance.

/**
 * @return whether the Smil has MMS conformance layout.
 * Refer to MMS Conformance Document OMA-MMS-CONF-v1_2-20050301-A
 */
private static final boolean isMMSConformance(SMILDocument smilDoc) {
    SMILElement head = smilDoc.getHead();
    if (head == null) {
        // No 'head' element
        return false;
    }
    NodeList children = head.getChildNodes();
    if (children == null || children.getLength() != 1) {
        // The 'head' element should have only one child.
        return false;
    }
    Node layout = children.item(0);
    if (layout == null || !"layout".equals(layout.getNodeName())) {
        // The child is not layout element
        return false;
    }
    NodeList layoutChildren = layout.getChildNodes();
    if (layoutChildren == null) {
        // The 'layout' element has no child.
        return false;
    }
    int num = layoutChildren.getLength();
    if (num <= 0) {
        // The 'layout' element has no child.
        return false;
    }
    for (int i = 0; i < num; i++) {
        Node layoutChild = layoutChildren.item(i);
        if (layoutChild == null) {
            // The 'layout' child is null.
            return false;
        }
        String name = layoutChild.getNodeName();
        if ("root-layout".equals(name)) {
            continue;
        } else if ("region".equals(name)) {
            NamedNodeMap map = layoutChild.getAttributes();
            for (int j = 0; j < map.getLength(); j++) {
                Node node = map.item(j);
                if (node == null) {
                    return false;
                }
                String attrName = node.getNodeName();
                // The attr should be one of left, top, height, width, fit and id
                if ("left".equals(attrName) || "top".equals(attrName) || "height".equals(attrName) || "width".equals(attrName) || "fit".equals(attrName)) {
                    continue;
                } else if ("id".equals(attrName)) {
                    String value;
                    if (node instanceof AttrImpl) {
                        value = ((AttrImpl) node).getValue();
                    } else {
                        return false;
                    }
                    if ("Text".equals(value) || "Image".equals(value)) {
                        continue;
                    } else {
                        // The id attr is not 'Text' or 'Image'
                        return false;
                    }
                } else {
                    return false;
                }
            }
        } else {
            // The 'layout' element has the child other than 'root-layout' or 'region'
            return false;
        }
    }
    return true;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) SMILElement(org.w3c.dom.smil.SMILElement) AttrImpl(com.android.mms.dom.AttrImpl)

Example 19 with SMILElement

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

the class SmilXmlSerializer method writeElement.

private static void writeElement(Writer writer, Element element) throws IOException {
    writer.write('<');
    writer.write(element.getTagName());
    if (element.hasAttributes()) {
        NamedNodeMap attributes = element.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            Attr attribute = (Attr) attributes.item(i);
            writer.write(" " + attribute.getName());
            writer.write("=\"" + attribute.getValue() + "\"");
        }
    }
    // FIXME: Might throw ClassCastException
    SMILElement childElement = (SMILElement) element.getFirstChild();
    if (childElement != null) {
        writer.write('>');
        do {
            writeElement(writer, childElement);
            childElement = (SMILElement) childElement.getNextSibling();
        } while (childElement != null);
        writer.write("</");
        writer.write(element.getTagName());
        writer.write('>');
    } else {
        writer.write("/>");
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) SMILElement(org.w3c.dom.smil.SMILElement) Attr(org.w3c.dom.Attr)

Example 20 with SMILElement

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

the class SmilDocumentImpl method getHead.

/*
     * SMILElement Interface
     */
public SMILElement getHead() {
    Node rootElement = getDocumentElement();
    Node headElement = rootElement.getFirstChild();
    if (headElement == null || !(headElement instanceof SMILElement)) {
        // The head doesn't exist. Create a new one.
        headElement = createElement("head");
        rootElement.appendChild(headElement);
    }
    return (SMILElement) headElement;
}
Also used : Node(org.w3c.dom.Node) SMILElement(org.w3c.dom.smil.SMILElement)

Aggregations

SMILElement (org.w3c.dom.smil.SMILElement)23 Node (org.w3c.dom.Node)11 SMILDocument (org.w3c.dom.smil.SMILDocument)9 SMILParElement (org.w3c.dom.smil.SMILParElement)9 NodeList (org.w3c.dom.NodeList)8 SMILLayoutElement (org.w3c.dom.smil.SMILLayoutElement)8 SMILMediaElement (org.w3c.dom.smil.SMILMediaElement)8 SmilDocumentImpl (com.android.mms.dom.smil.SmilDocumentImpl)5 ArrayList (java.util.ArrayList)5 NamedNodeMap (org.w3c.dom.NamedNodeMap)5 SMILRegionElement (org.w3c.dom.smil.SMILRegionElement)5 SMILRootLayoutElement (org.w3c.dom.smil.SMILRootLayoutElement)5 Attr (org.w3c.dom.Attr)3 DocumentEvent (org.w3c.dom.events.DocumentEvent)3 Event (org.w3c.dom.events.Event)3 ElementTime (org.w3c.dom.smil.ElementTime)3 SMILRegionMediaElement (org.w3c.dom.smil.SMILRegionMediaElement)3 DrmManagerClient (android.drm.DrmManagerClient)2 AttrImpl (com.android.mms.dom.AttrImpl)2 PduPart (com.google.android.mms.pdu_alt.PduPart)2