use of com.android.mms.dom.smil.SmilDocumentImpl 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;
}
use of com.android.mms.dom.smil.SmilDocumentImpl 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;
}
use of com.android.mms.dom.smil.SmilDocumentImpl in project android-aosp-mms by slvn.
the class SmilContentHandler method reset.
/**
* Resets this handler.
*/
public void reset() {
mSmilDocument = new SmilDocumentImpl();
mCurrentNode = mSmilDocument;
}
use of com.android.mms.dom.smil.SmilDocumentImpl 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;
}
use of com.android.mms.dom.smil.SmilDocumentImpl in project qksms by moezbhatti.
the class SmilContentHandler method reset.
/**
* Resets this handler.
*/
public void reset() {
mSmilDocument = new SmilDocumentImpl();
mCurrentNode = mSmilDocument;
}
Aggregations