• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Esmertec AG.
3  * Copyright (C) 2008 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.ui;
19 
20 import android.content.Context;
21 import android.graphics.Bitmap;
22 import android.graphics.BitmapFactory;
23 import android.util.Log;
24 
25 import com.android.mms.R;
26 import com.android.mms.model.AudioModel;
27 import com.android.mms.model.ImageModel;
28 import com.android.mms.model.Model;
29 import com.android.mms.model.SlideModel;
30 import com.android.mms.model.SlideshowModel;
31 import com.android.mms.model.VideoModel;
32 import com.android.mms.util.ItemLoadedCallback;
33 import com.android.mms.util.ItemLoadedFuture;
34 import com.android.mms.util.ThumbnailManager.ImageLoaded;
35 
36 public class MmsThumbnailPresenter extends Presenter {
37     private static final String TAG = "MmsThumbnailPresenter";
38     private ItemLoadedCallback mOnLoadedCallback;
39 
MmsThumbnailPresenter(Context context, ViewInterface view, Model model)40     public MmsThumbnailPresenter(Context context, ViewInterface view, Model model) {
41         super(context, view, model);
42     }
43 
44     @Override
present(ItemLoadedCallback callback)45     public void present(ItemLoadedCallback callback) {
46         mOnLoadedCallback = callback;
47         SlideModel slide = ((SlideshowModel) mModel).get(0);
48         if (slide != null) {
49             presentFirstSlide((SlideViewInterface) mView, slide);
50         }
51     }
52 
presentFirstSlide(SlideViewInterface view, SlideModel slide)53     private void presentFirstSlide(SlideViewInterface view, SlideModel slide) {
54         view.reset();
55 
56         if (slide.hasImage()) {
57             presentImageThumbnail(view, slide.getImage());
58         } else if (slide.hasVideo()) {
59             presentVideoThumbnail(view, slide.getVideo());
60         } else if (slide.hasAudio()) {
61             presentAudioThumbnail(view, slide.getAudio());
62         }
63     }
64 
65     private ItemLoadedCallback<ImageLoaded> mImageLoadedCallback =
66             new ItemLoadedCallback<ImageLoaded>() {
67         public void onItemLoaded(ImageLoaded imageLoaded, Throwable exception) {
68             if (exception == null) {
69                 if (mOnLoadedCallback != null) {
70                     mOnLoadedCallback.onItemLoaded(imageLoaded, exception);
71                 } else {
72                     // Right now we're only handling image and video loaded callbacks.
73                     SlideModel slide = ((SlideshowModel) mModel).get(0);
74                     if (slide != null) {
75                         if (slide.hasVideo() && imageLoaded.mIsVideo) {
76                             ((SlideViewInterface)mView).setVideoThumbnail(null,
77                                     imageLoaded.mBitmap);
78                         } else if (slide.hasImage() && !imageLoaded.mIsVideo) {
79                             ((SlideViewInterface)mView).setImage(null, imageLoaded.mBitmap);
80                         }
81                     }
82                 }
83             }
84         }
85     };
86 
presentVideoThumbnail(SlideViewInterface view, VideoModel video)87     private void presentVideoThumbnail(SlideViewInterface view, VideoModel video) {
88         video.loadThumbnailBitmap(mImageLoadedCallback);
89     }
90 
presentImageThumbnail(SlideViewInterface view, ImageModel image)91     private void presentImageThumbnail(SlideViewInterface view, ImageModel image) {
92         image.loadThumbnailBitmap(mImageLoadedCallback);
93     }
94 
presentAudioThumbnail(SlideViewInterface view, AudioModel audio)95     protected void presentAudioThumbnail(SlideViewInterface view, AudioModel audio) {
96         view.setAudio(audio.getUri(), audio.getSrc(), audio.getExtras());
97     }
98 
onModelChanged(Model model, boolean dataChanged)99     public void onModelChanged(Model model, boolean dataChanged) {
100         // TODO Auto-generated method stub
101     }
102 
cancelBackgroundLoading()103     public void cancelBackgroundLoading() {
104         // Currently we only support background loading of thumbnails. If we extend background
105         // loading to other media types, we should add a cancelLoading API to Model.
106         SlideModel slide = ((SlideshowModel) mModel).get(0);
107         if (slide != null && slide.hasImage()) {
108             slide.getImage().cancelThumbnailLoading();
109         }
110     }
111 
112 }
113