示例#1
0
 @Override
 public SMILRegionElement getSmilRegion(SMILDocument document) {
   SMILRegionElement region = (SMILRegionElement) document.createElement("region");
   region.setId("Image");
   region.setLeft(0);
   region.setTop(0);
   region.setWidth(SmilUtil.ROOT_WIDTH);
   region.setHeight(SmilUtil.ROOT_HEIGHT);
   region.setFit("meet");
   return region;
 }
 /**
  * @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;
 }
  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<RegionModel>();
    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<SlideModel>(slidesNum);

    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<MediaModel>(mediaNum);

      for (int j = 0; j < mediaNum; j++) {
        SMILMediaElement sme = (SMILMediaElement) mediaNodes.item(j);
        try {
          MediaModel media = MediaModelFactory.getMediaModel(context, sme, layouts, pb);
          SmilHelper.addMediaElementEventListeners((EventTarget) sme, media);
          mediaSet.add(media);
        } catch (DrmException e) {
          Log.e(TAG, e.getMessage(), e);
        } catch (IOException e) {
          Log.e(TAG, e.getMessage(), e);
        } catch (IllegalArgumentException 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.getContentResolver());
    slideshow.registerModelChangedObserver(slideshow);
    return slideshow;
  }