FileDocCategorySizeDatePackage
SlideModel.javaAPI DocAndroid 1.5 API14215Wed May 06 22:42:46 BST 2009com.android.mms.model

SlideModel

public class SlideModel extends Model implements List, EventListener

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final boolean
LOCAL_LOGV
private static final int
DEFAULT_SLIDE_DURATION
private final ArrayList
mMedia
private MediaModel
mText
private MediaModel
mImage
private MediaModel
mAudio
private MediaModel
mVideo
private boolean
mCanAddImage
private boolean
mCanAddAudio
private boolean
mCanAddVideo
private int
mDuration
private boolean
mVisible
private short
mFill
private int
mSlideSize
private SlideshowModel
mParent
Constructors Summary
public SlideModel(SlideshowModel slideshow)


       
        this(DEFAULT_SLIDE_DURATION, slideshow);
    
public SlideModel(int duration, SlideshowModel slideshow)

        mDuration = duration;
        mParent = slideshow;
    
public SlideModel(int duration, ArrayList mediaList)
Create a SlideModel with exist media collection.

param
duration The duration of the slide.
param
mediaList The exist media collection.
throws
IllegalStateException One or more media in the mediaList cannot be added into the slide due to a slide cannot contain image and video or audio and video at the same time.

        mDuration = duration;

        int maxDur = 0;
        for (MediaModel media : mediaList) {
            internalAdd(media);

            int mediaDur = media.getDuration();
            if (mediaDur > maxDur) {
                maxDur = mediaDur;
            }
        }

        updateDuration(maxDur);
    
Methods Summary
public booleanadd(MediaModel object)
Add a MediaModel to the slide. If the slide has already contained a media object in the same type, the media object will be replaced by the new one.

param
object A media object to be added into the slide.
return
true
throws
IllegalStateException One or more media in the mediaList cannot be added into the slide due to a slide cannot contain image and video or audio and video at the same time.
throws
ContentRestrictionException when can not add this object.

        internalAdd(object);
        notifyModelChanged(true);
        return true;
    
public voidadd(int location, MediaModel object)

        throw new UnsupportedOperationException("Operation not supported.");
    
public booleanaddAll(java.util.Collection collection)

        throw new UnsupportedOperationException("Operation not supported.");
    
public booleanaddAll(int location, java.util.Collection collection)

        throw new UnsupportedOperationException("Operation not supported.");
    
public voidclear()

        if (mMedia.size() > 0) {
            for (MediaModel media : mMedia) {
                media.unregisterAllModelChangedObservers();
                int decreaseSize = media.getMediaSize();
                decreaseSlideSize(decreaseSize);
                decreaseMessageSize(decreaseSize);
            }
            mMedia.clear();

            mText = null;
            mImage = null;
            mAudio = null;
            mVideo = null;

            mCanAddImage = true;
            mCanAddAudio = true;
            mCanAddVideo = true;

            notifyModelChanged(true);
        }
    
public booleancontains(java.lang.Object object)

        return mMedia.contains(object);
    
public booleancontainsAll(java.util.Collection collection)

        return mMedia.containsAll(collection);
    
public voiddecreaseMessageSize(int decreaseSize)

        if ((decreaseSize > 0) && (null != mParent)) {
            int size = mParent.getCurrentMessageSize();
            size -= decreaseSize;
            mParent.setCurrentMessageSize(size);
        }
    
public voiddecreaseSlideSize(int decreaseSize)

        if (decreaseSize > 0) {
            mSlideSize -= decreaseSize;
        }
    
public MediaModelget(int location)

        return mMedia.get(location);
    
public AudioModelgetAudio()

        return (AudioModel) mAudio;
    
public intgetDuration()

return
the mDuration

        return mDuration;
    
public shortgetFill()

return
the mFill

        return mFill;
    
public ImageModelgetImage()

        return (ImageModel) mImage;
    
public intgetSlideSize()

        return mSlideSize;
    
public TextModelgetText()

        return (TextModel) mText;
    
public VideoModelgetVideo()

        return (VideoModel) mVideo;
    
public voidhandleEvent(org.w3c.dom.events.Event evt)

        if (evt.getType().equals(SmilParElementImpl.SMIL_SLIDE_START_EVENT)) {
            if (LOCAL_LOGV) {
                Log.v(TAG, "Start to play slide: " + this);
            }
            mVisible = true;
        } else if (mFill != ElementTime.FILL_FREEZE) {
            if (LOCAL_LOGV) {
                Log.v(TAG, "Stop playing slide: " + this);
            }
            mVisible = false;
        }

        notifyModelChanged(false);
    
public booleanhasAudio()

        return mAudio != null;
    
public booleanhasImage()

        return mImage != null;
    
public booleanhasText()

        return mText != null;
    
public booleanhasVideo()

        return mVideo != null;
    
public voidincreaseMessageSize(int increaseSize)

        if ((increaseSize > 0) && (null != mParent)) {
            int size = mParent.getCurrentMessageSize();
            size += increaseSize;
            mParent.setCurrentMessageSize(size);
        }
    
public voidincreaseSlideSize(int increaseSize)

        if (increaseSize > 0) {
            mSlideSize += increaseSize;
        }
    
public intindexOf(java.lang.Object object)

        return mMedia.indexOf(object);
    
private voidinternalAdd(MediaModel media)

        if (media == null) {
            // Don't add null value into the list.
            return;
        }

        if (media.isText()) {
            internalAddOrReplace(mText, media);
            mText = media;
        } else if (media.isImage()) {
            if (mCanAddImage) {
                internalAddOrReplace(mImage, media);
                mImage = media;
                mCanAddVideo = false;
            } else {
                throw new IllegalStateException();
            }
        } else if (media.isAudio()) {
            if (mCanAddAudio) {
                internalAddOrReplace(mAudio, media);
                mAudio = media;
                mCanAddVideo = false;
            } else {
                throw new IllegalStateException();
            }
        } else if (media.isVideo()) {
            if (mCanAddVideo) {
                internalAddOrReplace(mVideo, media);
                mVideo = media;
                mCanAddImage = false;
                mCanAddAudio = false;
            } else {
                throw new IllegalStateException();
            }
        }
    
private voidinternalAddOrReplace(MediaModel old, MediaModel media)

        int addSize = media.getMediaSize();
        int removeSize;
        if (old == null) {
            if (null != mParent) {
                mParent.checkMessageSize(addSize);
            }
            mMedia.add(media);
            increaseSlideSize(addSize);
            increaseMessageSize(addSize);
        } else {
            removeSize = old.getMediaSize();
            if (addSize > removeSize) {
                if (null != mParent) {
                    mParent.checkMessageSize(addSize - removeSize);
                }
                increaseSlideSize(addSize - removeSize);
                increaseMessageSize(addSize - removeSize);
            } else {
                decreaseSlideSize(removeSize - addSize);
                decreaseMessageSize(removeSize - addSize);
            }
            mMedia.set(mMedia.indexOf(old), media);
            old.unregisterAllModelChangedObservers();
        }

        for (IModelChangedObserver observer : mModelChangedObservers) {
            media.registerModelChangedObserver(observer);
        }
    
private booleaninternalRemove(java.lang.Object object)

        if (mMedia.remove(object)) {
            if (object instanceof TextModel) {
                mText = null;
            } else if (object instanceof ImageModel) {
                mImage = null;
                mCanAddVideo = true;
            } else if (object instanceof AudioModel) {
                mAudio = null;
                mCanAddVideo = true;
            } else if (object instanceof VideoModel) {
                mVideo = null;
                mCanAddImage = true;
                mCanAddAudio = true;
            }
            int decreaseSize = ((MediaModel) object).getMediaSize();
            decreaseSlideSize(decreaseSize);
            decreaseMessageSize(decreaseSize);

            ((Model) object).unregisterAllModelChangedObservers();

            return true;
        }

        return false;
    
public booleanisEmpty()

        return mMedia.isEmpty();
    
public booleanisVisible()

return
the mVisible

        return mVisible;
    
public java.util.Iteratoriterator()

        return mMedia.iterator();
    
public intlastIndexOf(java.lang.Object object)

        return mMedia.lastIndexOf(object);
    
public java.util.ListIteratorlistIterator()

        return mMedia.listIterator();
    
public java.util.ListIteratorlistIterator(int location)

        return mMedia.listIterator(location);
    
protected voidregisterModelChangedObserverInDescendants(IModelChangedObserver observer)

        for (MediaModel media : mMedia) {
            media.registerModelChangedObserver(observer);
        }
    
public booleanremove(java.lang.Object object)

        if ((object != null) && (object instanceof MediaModel)
                && internalRemove(object)) {
            notifyModelChanged(true);
            return true;
        }
        return false;
    
public MediaModelremove(int location)

        MediaModel media = mMedia.get(location);
        if ((media != null) && internalRemove(media)) {
            notifyModelChanged(true);
        }
        return media;
    
public booleanremoveAll(java.util.Collection collection)

        throw new UnsupportedOperationException("Operation not supported.");
    
public booleanremoveAudio()

        return remove(mAudio);
    
public booleanremoveImage()

        return remove(mImage);
    
public booleanremoveText()

        return remove(mText);
    
public booleanremoveVideo()

        return remove(mVideo);
    
public booleanretainAll(java.util.Collection collection)

        throw new UnsupportedOperationException("Operation not supported.");
    
public MediaModelset(int location, MediaModel object)

        throw new UnsupportedOperationException("Operation not supported.");
    
public voidsetDuration(int duration)

param
duration the mDuration to set

        mDuration = duration;
        notifyModelChanged(true);
    
public voidsetFill(short fill)

param
fill the mFill to set

        mFill = fill;
        notifyModelChanged(true);
    
public voidsetParent(SlideshowModel parent)

        mParent = parent;
    
public voidsetVisible(boolean visible)

param
visible the mVisible to set

        mVisible = visible;
        notifyModelChanged(true);
    
public intsize()

        return mMedia.size();
    
public java.util.ListsubList(int start, int end)

        return mMedia.subList(start, end);
    
public java.lang.Object[]toArray()

        return mMedia.toArray();
    
public T[]toArray(T[] array)

        return mMedia.toArray(array);
    
protected voidunregisterAllModelChangedObserversInDescendants()

        for (MediaModel media : mMedia) {
            media.unregisterAllModelChangedObservers();
        }
    
protected voidunregisterModelChangedObserverInDescendants(IModelChangedObserver observer)

        for (MediaModel media : mMedia) {
            media.unregisterModelChangedObserver(observer);
        }
    
public voidupdateDuration(int duration)

        if (duration <= 0) {
            return;
        }

        if ((duration > mDuration)
                || (mDuration == DEFAULT_SLIDE_DURATION)) {
            mDuration = duration;
        }