1 /* 2 * Copyright (C) 2007 Esmertec AG. 3 * Copyright (C) 2007 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.mms.dom.smil; 19 20 import java.util.ArrayList; 21 22 import org.w3c.dom.Node; 23 import org.w3c.dom.NodeList; 24 import org.w3c.dom.smil.ElementSequentialTimeContainer; 25 import org.w3c.dom.smil.ElementTime; 26 import org.w3c.dom.smil.SMILElement; 27 28 import com.android.mms.dom.NodeListImpl; 29 30 public abstract class ElementSequentialTimeContainerImpl extends 31 ElementTimeContainerImpl implements ElementSequentialTimeContainer { 32 33 /* 34 * Internal Interface 35 */ 36 ElementSequentialTimeContainerImpl(SMILElement element)37 ElementSequentialTimeContainerImpl(SMILElement element) { 38 super(element); 39 } 40 41 /* 42 * ElementSequentialTimeContainer Interface 43 */ 44 getActiveChildrenAt(float instant)45 public NodeList getActiveChildrenAt(float instant) { 46 NodeList allChildren = this.getTimeChildren(); 47 ArrayList<Node> nodes = new ArrayList<Node>(); 48 for (int i = 0; i < allChildren.getLength(); i++) { 49 instant -= ((ElementTime) allChildren.item(i)).getDur(); 50 if (instant < 0) { 51 nodes.add(allChildren.item(i)); 52 return new NodeListImpl(nodes); 53 } 54 } 55 return new NodeListImpl(nodes); 56 } 57 getDur()58 public float getDur() { 59 float dur = super.getDur(); 60 if (dur == 0) { 61 NodeList children = getTimeChildren(); 62 for (int i = 0; i < children.getLength(); ++i) { 63 ElementTime child = (ElementTime) children.item(i); 64 if (child.getDur() < 0) { 65 // Return "indefinite" since containing a child whose duration is indefinite. 66 return -1.0F; 67 } 68 dur += child.getDur(); 69 } 70 } 71 return dur; 72 } 73 } 74