|
|
|
@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.util;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.dom.smil.SmilDocumentImpl;
|
|
|
|
|
import org.thoughtcrime.securesms.dom.smil.parser.SmilXmlSerializer;
|
|
|
|
|
import org.thoughtcrime.securesms.mms.PartParser;
|
|
|
|
|
import org.thoughtcrime.securesms.mms.Slide;
|
|
|
|
|
import org.thoughtcrime.securesms.mms.SlideDeck;
|
|
|
|
|
import org.w3c.dom.smil.SMILDocument;
|
|
|
|
@ -14,14 +16,34 @@ import org.w3c.dom.smil.SMILRegionElement;
|
|
|
|
|
import org.w3c.dom.smil.SMILRegionMediaElement;
|
|
|
|
|
import org.w3c.dom.smil.SMILRootLayoutElement;
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
|
|
|
|
|
import ws.com.google.android.mms.ContentType;
|
|
|
|
|
import ws.com.google.android.mms.pdu.PduBody;
|
|
|
|
|
import ws.com.google.android.mms.pdu.PduParser;
|
|
|
|
|
import ws.com.google.android.mms.pdu.PduPart;
|
|
|
|
|
|
|
|
|
|
public class SmilUtil {
|
|
|
|
|
private static final String TAG = SmilUtil.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
public static final int ROOT_HEIGHT = 1024;
|
|
|
|
|
public static final int ROOT_WIDTH = 1024;
|
|
|
|
|
|
|
|
|
|
public static SMILDocument createSmilDocument(SlideDeck deck) {
|
|
|
|
|
Log.w(TAG, "Creating SMIL document from SlideDeck.");
|
|
|
|
|
public static PduBody getSmilBody(PduBody body) {
|
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
|
|
SmilXmlSerializer.serialize(SmilUtil.createSmilDocument(body), out);
|
|
|
|
|
PduPart smilPart = new PduPart();
|
|
|
|
|
smilPart.setContentId("smil".getBytes());
|
|
|
|
|
smilPart.setContentLocation("smil.xml".getBytes());
|
|
|
|
|
smilPart.setContentType(ContentType.APP_SMIL.getBytes());
|
|
|
|
|
smilPart.setData(out.toByteArray());
|
|
|
|
|
body.addPart(0, smilPart);
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static SMILDocument createSmilDocument(PduBody body) {
|
|
|
|
|
Log.w(TAG, "Creating SMIL document from PduBody.");
|
|
|
|
|
|
|
|
|
|
SMILDocument document = new SmilDocumentImpl();
|
|
|
|
|
|
|
|
|
@ -45,9 +67,10 @@ public class SmilUtil {
|
|
|
|
|
SMILParElement par = (SMILParElement) document.createElement("par");
|
|
|
|
|
bodyElement.appendChild(par);
|
|
|
|
|
|
|
|
|
|
for (Slide slide : deck.getSlides()) {
|
|
|
|
|
SMILRegionElement regionElement = slide.getSmilRegion(document);
|
|
|
|
|
SMILMediaElement mediaElement = slide.getMediaElement(document);
|
|
|
|
|
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);
|
|
|
|
@ -59,7 +82,42 @@ public class SmilUtil {
|
|
|
|
|
return document;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static SMILMediaElement createMediaElement(String tag, SMILDocument document, String src) {
|
|
|
|
|
private static SMILRegionElement getRegion(SMILDocument document, PduPart part) {
|
|
|
|
|
if (PartParser.isAudio(part)) return null;
|
|
|
|
|
|
|
|
|
|
SMILRegionElement region = (SMILRegionElement) document.createElement("region");
|
|
|
|
|
if (PartParser.isText(part)) {
|
|
|
|
|
region.setId("Text");
|
|
|
|
|
region.setTop(SmilUtil.ROOT_HEIGHT);
|
|
|
|
|
region.setHeight(50);
|
|
|
|
|
} else {
|
|
|
|
|
region.setId("Image");
|
|
|
|
|
region.setTop(0);
|
|
|
|
|
region.setHeight(SmilUtil.ROOT_HEIGHT);
|
|
|
|
|
}
|
|
|
|
|
region.setLeft(0);
|
|
|
|
|
region.setWidth(SmilUtil.ROOT_WIDTH);
|
|
|
|
|
region.setFit("meet");
|
|
|
|
|
return region;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static SMILMediaElement getMediaElement(SMILDocument document, PduPart part) {
|
|
|
|
|
final String tag;
|
|
|
|
|
if (PartParser.isImage(part)) {
|
|
|
|
|
tag = "img";
|
|
|
|
|
} else if (PartParser.isAudio(part)) {
|
|
|
|
|
tag = "audio";
|
|
|
|
|
} else if (PartParser.isVideo(part)) {
|
|
|
|
|
tag = "video";
|
|
|
|
|
} else if (PartParser.isText(part)) {
|
|
|
|
|
tag = "text";
|
|
|
|
|
} else {
|
|
|
|
|
tag = "ref";
|
|
|
|
|
}
|
|
|
|
|
return createMediaElement(tag, document, new String(part.getName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static SMILMediaElement createMediaElement(String tag, SMILDocument document, String src) {
|
|
|
|
|
SMILMediaElement mediaElement = (SMILMediaElement) document.createElement(tag);
|
|
|
|
|
mediaElement.setSrc(escapeXML(src));
|
|
|
|
|
return mediaElement;
|
|
|
|
|