Home | History | Annotate | Download | only in ui
      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 com.android.mms.R;
     21 import com.android.mms.model.AudioModel;
     22 import com.android.mms.model.ImageModel;
     23 import com.android.mms.model.Model;
     24 import com.android.mms.model.SlideModel;
     25 import com.android.mms.model.SlideshowModel;
     26 import com.android.mms.model.VideoModel;
     27 
     28 import android.content.Context;
     29 import android.graphics.Bitmap;
     30 import android.graphics.BitmapFactory;
     31 import android.util.Log;
     32 
     33 public class MmsThumbnailPresenter extends Presenter {
     34     private static final String TAG = "MmsThumbnailPresenter";
     35 
     36     public MmsThumbnailPresenter(Context context, ViewInterface view, Model model) {
     37         super(context, view, model);
     38     }
     39 
     40     @Override
     41     public void present() {
     42         SlideModel slide = ((SlideshowModel) mModel).get(0);
     43         if (slide != null) {
     44             presentFirstSlide((SlideViewInterface) mView, slide);
     45         }
     46     }
     47 
     48     private void presentFirstSlide(SlideViewInterface view, SlideModel slide) {
     49         view.reset();
     50 
     51         if (slide.hasImage()) {
     52             presentImageThumbnail(view, slide.getImage());
     53         } else if (slide.hasVideo()) {
     54             presentVideoThumbnail(view, slide.getVideo());
     55         } else if (slide.hasAudio()) {
     56             presentAudioThumbnail(view, slide.getAudio());
     57         }
     58     }
     59 
     60     private void presentVideoThumbnail(SlideViewInterface view, VideoModel video) {
     61         if (video.isDrmProtected()) {
     62             showDrmIcon(view, video.getSrc());
     63         } else {
     64             view.setVideo(video.getSrc(), video.getUri());
     65         }
     66     }
     67 
     68     private void presentImageThumbnail(SlideViewInterface view, ImageModel image) {
     69         if (image.isDrmProtected()) {
     70             showDrmIcon(view, image.getSrc());
     71         } else {
     72             view.setImage(image.getSrc(), image.getBitmap());
     73         }
     74     }
     75 
     76     protected void presentAudioThumbnail(SlideViewInterface view, AudioModel audio) {
     77         if (audio.isDrmProtected()) {
     78             showDrmIcon(view, audio.getSrc());
     79         } else {
     80             view.setAudio(audio.getUri(), audio.getSrc(), audio.getExtras());
     81         }
     82     }
     83 
     84     // Show an icon instead of real content in the thumbnail.
     85     private void showDrmIcon(SlideViewInterface view, String name) {
     86         try {
     87             Bitmap bitmap = BitmapFactory.decodeResource(
     88                     mContext.getResources(), R.drawable.ic_mms_drm_protected);
     89             view.setImage(name, bitmap);
     90         } catch (java.lang.OutOfMemoryError e) {
     91             Log.e(TAG, "showDrmIcon: out of memory: ", e);
     92         }
     93     }
     94 
     95     public void onModelChanged(Model model, boolean dataChanged) {
     96         // TODO Auto-generated method stub
     97     }
     98 }
     99