SlideshowPresenterpublic 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 float | getHeightTransformRatio(int height, int layoutHeight)
if (height > 0) {
return (float) layoutHeight / (float) height;
}
return 1.0f;
| public int | getLocation()
return mLocation;
| private float | getWidthTransformRatio(int width, int layoutWidth)
if (width > 0) {
return (float) layoutWidth / (float) width;
}
return 1.0f;
| public void | goBackward()
if (mLocation > 0) {
mLocation--;
}
| public void | goForward()
if (mLocation < (mSlideNumber - 1)) {
mLocation++;
}
| public void | onModelChanged(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 void | present()
presentSlide((SlideViewInterface) mView, ((SlideshowModel) mModel).get(mLocation));
| protected void | presentAudio(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 void | presentImage(SlideViewInterface view, com.android.mms.model.ImageModel image, com.android.mms.model.RegionModel r, boolean dataChanged)
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 void | presentRegionMedia(SlideViewInterface view, com.android.mms.model.RegionMediaModel rMedia, boolean dataChanged)
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 void | presentSlide(SlideViewInterface view, com.android.mms.model.SlideModel 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 void | presentText(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 void | presentVideo(SlideViewInterface view, com.android.mms.model.VideoModel video, com.android.mms.model.RegionModel r, boolean dataChanged)
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 void | setLocation(int location)
mLocation = location;
| private int | transformHeight(int height)
return (int) (height / mHeightTransformRatio);
| private int | transformWidth(int width)
return (int) (width / mWidthTransformRatio);
|
|