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 
     32 public class MmsThumbnailPresenter extends Presenter {
     33 
     34     public MmsThumbnailPresenter(Context context, ViewInterface view, Model model) {
     35         super(context, view, model);
     36     }
     37 
     38     @Override
     39     public void present() {
     40         SlideModel slide = ((SlideshowModel) mModel).get(0);
     41         if (slide != null) {
     42             presentFirstSlide((SlideViewInterface) mView, slide);
     43         }
     44     }
     45 
     46     private void presentFirstSlide(SlideViewInterface view, SlideModel slide) {
     47         view.reset();
     48 
     49         if (slide.hasImage()) {
     50             presentImageThumbnail(view, slide.getImage());
     51         } else if (slide.hasVideo()) {
     52             presentVideoThumbnail(view, slide.getVideo());
     53         } else if (slide.hasAudio()) {
     54             presentAudioThumbnail(view, slide.getAudio());
     55         }
     56     }
     57 
     58     private void presentVideoThumbnail(SlideViewInterface view, VideoModel video) {
     59         if (video.isDrmProtected()) {
     60             showDrmIcon(view, video.getSrc());
     61         } else {
     62             view.setVideo(video.getSrc(), video.getUri());
     63         }
     64     }
     65 
     66     private void presentImageThumbnail(SlideViewInterface view, ImageModel image) {
     67         if (image.isDrmProtected()) {
     68             showDrmIcon(view, image.getSrc());
     69         } else {
     70             view.setImage(image.getSrc(), image.getBitmap());
     71         }
     72     }
     73 
     74     protected void presentAudioThumbnail(SlideViewInterface view, AudioModel audio) {
     75         if (audio.isDrmProtected()) {
     76             showDrmIcon(view, audio.getSrc());
     77         } else {
     78             view.setAudio(audio.getUri(), audio.getSrc(), audio.getExtras());
     79         }
     80     }
     81 
     82     // Show an icon instead of real content in the thumbnail.
     83     private void showDrmIcon(SlideViewInterface view, String name) {
     84         Bitmap bitmap = BitmapFactory.decodeResource(
     85                 mContext.getResources(), R.drawable.ic_mms_drm_protected);
     86         view.setImage(name, bitmap);
     87     }
     88 
     89     public void onModelChanged(Model model, boolean dataChanged) {
     90         // TODO Auto-generated method stub
     91     }
     92 }
     93