FileDocCategorySizeDatePackage
SlideshowPresenter.javaAPI DocAndroid 1.5 API11111Wed May 06 22:42:46 BST 2009com.android.mms.ui

SlideshowPresenter

public class SlideshowPresenter extends Presenter
A basic presenter of slides.

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final boolean
LOCAL_LOGV
protected int
mLocation
protected final int
mSlideNumber
protected float
mWidthTransformRatio
protected float
mHeightTransformRatio
protected final android.os.Handler
mHandler
private final com.android.mms.ui.AdaptableSlideViewInterface.OnSizeChangedListener
mViewSizeChangedListener
Constructors Summary
public SlideshowPresenter(android.content.Context context, ViewInterface view, com.android.mms.model.Model model)


           
        super(context, view, model);
        mLocation = 0;
        mSlideNumber = ((SlideshowModel) mModel).size();

        if (view instanceof AdaptableSlideViewInterface) {
            ((AdaptableSlideViewInterface) view).setOnSizeChangedListener(
                    mViewSizeChangedListener);
        }
    
Methods Summary
private floatgetHeightTransformRatio(int height, int layoutHeight)

        if (height > 0) {
            return (float) layoutHeight / (float) height;
        }
        return 1.0f;
    
public intgetLocation()

        return mLocation;
    
private floatgetWidthTransformRatio(int width, int layoutWidth)


          
        if (width > 0) {
            return (float) layoutWidth / (float) width;
        }
        return 1.0f;
    
public voidgoBackward()

        if (mLocation > 0) {
            mLocation--;
        }
    
public voidgoForward()

        if (mLocation < (mSlideNumber - 1)) {
            mLocation++;
        }
    
public voidonModelChanged(com.android.mms.model.Model model, boolean dataChanged)

        final SlideViewInterface view = (SlideViewInterface) mView;

        // FIXME: Should be optimized.
        if (model instanceof SlideshowModel) {
            // TODO:
        } else if (model instanceof SlideModel) {
            if (((SlideModel) model).isVisible()) {
                mHandler.post(new Runnable() {
                    public void run() {
                        presentSlide(view, (SlideModel) model);
                    }
                });
            } else {
                mHandler.post(new Runnable() {
                    public void run() {
                        goForward();
                    }
                });
            }
        } else if (model instanceof MediaModel) {
            if (model instanceof RegionMediaModel) {
                mHandler.post(new Runnable() {
                    public void run() {
                        try {
                            presentRegionMedia(view, (RegionMediaModel) model, dataChanged);
                        } catch (DrmException e) {
                            Log.e(TAG, e.getMessage(), e);
                            Toast.makeText(mContext,
                                    mContext.getString(R.string.insufficient_drm_rights),
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            } else if (((MediaModel) model).isAudio()) {
                mHandler.post(new Runnable() {
                    public void run() {
                        try {
                            presentAudio(view, (AudioModel) model, dataChanged);
                        } catch (DrmException e) {
                            Log.e(TAG, e.getMessage(), e);
                            Toast.makeText(mContext,
                                    mContext.getString(R.string.insufficient_drm_rights),
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
        } else if (model instanceof RegionModel) {
            // TODO:
        }
    
public voidpresent()

        presentSlide((SlideViewInterface) mView, ((SlideshowModel) mModel).get(mLocation));
    
protected voidpresentAudio(SlideViewInterface view, com.android.mms.model.AudioModel audio, boolean dataChanged)

        // Set audio only when data changed.
        if (dataChanged) {
            view.setAudio(audio.getUriWithDrmCheck(), audio.getSrc(), audio.getExtras());
        }

        MediaAction action = audio.getCurrentAction();
        if (action == MediaAction.START) {
            view.startAudio();
        } else if (action == MediaAction.PAUSE) {
            view.pauseAudio();
        } else if (action == MediaAction.STOP) {
            view.stopAudio();
        } else if (action == MediaAction.SEEK) {
            view.seekAudio(audio.getSeekTo());
        }
    
protected voidpresentImage(SlideViewInterface view, com.android.mms.model.ImageModel image, com.android.mms.model.RegionModel r, boolean dataChanged)

param
view
param
image
param
r
throws
DrmException

        if (dataChanged) {
            view.setImage(image.getSrc(), image.getBitmapWithDrmCheck());
        }

        if (view instanceof AdaptableSlideViewInterface) {
            ((AdaptableSlideViewInterface) view).setImageRegion(
                    transformWidth(r.getLeft()),
                    transformHeight(r.getTop()),
                    transformWidth(r.getWidth()),
                    transformHeight(r.getHeight()));
        }
        view.setImageRegionFit(r.getFit());
        view.setImageVisibility(image.isVisible());
    
protected voidpresentRegionMedia(SlideViewInterface view, com.android.mms.model.RegionMediaModel rMedia, boolean dataChanged)

param
view
throws
DrmException

        RegionModel r = (rMedia).getRegion();
        if (rMedia.isText()) {
            presentText(view, (TextModel) rMedia, r, dataChanged);
        } else if (rMedia.isImage()) {
            presentImage(view, (ImageModel) rMedia, r, dataChanged);
        } else if (rMedia.isVideo()) {
            presentVideo(view, (VideoModel) rMedia, r, dataChanged);
        }
    
protected voidpresentSlide(SlideViewInterface view, com.android.mms.model.SlideModel model)

param
view
param
model

        view.reset();

        try {
            for (MediaModel media : model) {
                if (media instanceof RegionMediaModel) {
                    presentRegionMedia(view, (RegionMediaModel) media, true);
                } else if (media.isAudio()) {
                    presentAudio(view, (AudioModel) media, true);
                }
            }
        } catch (DrmException e) {
            Log.e(TAG, e.getMessage(), e);
            Toast.makeText(mContext,
                    mContext.getString(R.string.insufficient_drm_rights),
                    Toast.LENGTH_SHORT).show();
        }
    
protected voidpresentText(SlideViewInterface view, com.android.mms.model.TextModel text, com.android.mms.model.RegionModel r, boolean dataChanged)

        if (dataChanged) {
            view.setText(text.getSrc(), text.getText());
        }

        if (view instanceof AdaptableSlideViewInterface) {
            ((AdaptableSlideViewInterface) view).setTextRegion(
                    transformWidth(r.getLeft()),
                    transformHeight(r.getTop()),
                    transformWidth(r.getWidth()),
                    transformHeight(r.getHeight()));
        }
        view.setTextVisibility(text.isVisible());
    
protected voidpresentVideo(SlideViewInterface view, com.android.mms.model.VideoModel video, com.android.mms.model.RegionModel r, boolean dataChanged)

param
view
param
video
param
r
throws
DrmException

        if (dataChanged) {
            view.setVideo(video.getSrc(), video.getUriWithDrmCheck());
        }

        if (view instanceof AdaptableSlideViewInterface) {
            ((AdaptableSlideViewInterface) view).setVideoRegion(
                    transformWidth(r.getLeft()),
                    transformHeight(r.getTop()),
                    transformWidth(r.getWidth()),
                    transformHeight(r.getHeight()));
        }
        view.setVideoVisibility(video.isVisible());

        MediaAction action = video.getCurrentAction();
        if (action == MediaAction.START) {
            view.startVideo();
        } else if (action == MediaAction.PAUSE) {
            view.pauseVideo();
        } else if (action == MediaAction.STOP) {
            view.stopVideo();
        } else if (action == MediaAction.SEEK) {
            view.seekVideo(video.getSeekTo());
        }
    
public voidsetLocation(int location)

        mLocation = location;
    
private inttransformHeight(int height)

        return (int) (height / mHeightTransformRatio);
    
private inttransformWidth(int width)

        return (int) (width / mWidthTransformRatio);