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
18package com.android.mms.ui;
19
20import java.io.IOException;
21import java.util.Map;
22
23import android.content.Context;
24import android.graphics.Bitmap;
25import android.graphics.BitmapFactory;
26import android.media.MediaPlayer;
27import android.net.Uri;
28import android.text.TextUtils;
29import android.text.method.HideReturnsTransformationMethod;
30import android.util.AttributeSet;
31import android.util.Log;
32import android.view.View;
33import android.widget.ImageView;
34import android.widget.LinearLayout;
35import android.widget.TextView;
36
37import com.android.mms.R;
38
39/**
40 * A simplified view of slide in the slides list.
41 */
42public class SlideListItemView extends LinearLayout implements SlideViewInterface {
43    private static final String TAG = "SlideListItemView";
44
45    private TextView mTextPreview;
46    private ImageView mImagePreview;
47    private TextView mAttachmentName;
48    private ImageView mAttachmentIcon;
49
50    public SlideListItemView(Context context) {
51        super(context);
52    }
53
54    public SlideListItemView(Context context, AttributeSet attrs) {
55        super(context, attrs);
56    }
57
58    @Override
59    protected void onFinishInflate() {
60        mTextPreview = (TextView) findViewById(R.id.text_preview);
61        mTextPreview.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
62        mImagePreview = (ImageView) findViewById(R.id.image_preview);
63        mAttachmentName = (TextView) findViewById(R.id.attachment_name);
64        mAttachmentIcon = (ImageView) findViewById(R.id.attachment_icon);
65    }
66
67    public void startAudio() {
68        // Playing audio is not needed in this view.
69    }
70
71    public void startVideo() {
72        // Playing audio is not needed in this view.
73    }
74
75    public void setAudio(Uri audio, String name, Map<String, ?> extras) {
76        if (name != null) {
77            mAttachmentName.setText(name);
78            mAttachmentIcon.setImageResource(R.drawable.ic_mms_music);
79        } else {
80            mAttachmentName.setText("");
81            mAttachmentIcon.setImageDrawable(null);
82        }
83    }
84
85    public void setImage(String name, Bitmap bitmap) {
86        try {
87            if (null == bitmap) {
88                bitmap = BitmapFactory.decodeResource(getResources(),
89                        R.drawable.ic_missing_thumbnail_picture);
90            }
91            mImagePreview.setImageBitmap(bitmap);
92        } catch (java.lang.OutOfMemoryError e) {
93            Log.e(TAG, "setImage: out of memory: ", e);
94        }
95    }
96
97    public void setImageRegionFit(String fit) {
98        // TODO Auto-generated method stub
99    }
100
101    public void setImageVisibility(boolean visible) {
102        // TODO Auto-generated method stub
103    }
104
105    public void setText(String name, String text) {
106        mTextPreview.setText(text);
107        mTextPreview.setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE);
108    }
109
110    public void setTextVisibility(boolean visible) {
111        // TODO Auto-generated method stub
112    }
113
114    public void setVideo(String name, Uri video) {
115        if (name != null) {
116            mAttachmentName.setText(name);
117            mAttachmentIcon.setImageResource(R.drawable.movie);
118        } else {
119            mAttachmentName.setText("");
120            mAttachmentIcon.setImageDrawable(null);
121        }
122
123        MediaPlayer mp = new MediaPlayer();
124        try {
125            mp.setDataSource(mContext, video);
126            mImagePreview.setImageBitmap(mp.getFrameAt(1000));
127        } catch (IOException e) {
128            Log.e(TAG, "Unexpected IOException.", e);
129        } finally {
130            mp.release();
131        }
132    }
133
134    public void setVideoThumbnail(String name, Bitmap thumbnail) {
135    }
136
137    public void setVideoVisibility(boolean visible) {
138        // TODO Auto-generated method stub
139    }
140
141    public void stopAudio() {
142        // Stopping audio is not needed in this view.
143    }
144
145    public void stopVideo() {
146        // Stopping video is not needed in this view.
147    }
148
149    public void reset() {
150        // TODO Auto-generated method stub
151    }
152
153    public void setVisibility(boolean visible) {
154        // TODO Auto-generated method stub
155    }
156
157    public void pauseAudio() {
158        // TODO Auto-generated method stub
159
160    }
161
162    public void pauseVideo() {
163        // TODO Auto-generated method stub
164
165    }
166
167    public void seekAudio(int seekTo) {
168        // TODO Auto-generated method stub
169
170    }
171
172    public void seekVideo(int seekTo) {
173        // TODO Auto-generated method stub
174
175    }
176}
177