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 com.android.mms.R;
21
22import android.content.Context;
23import android.graphics.Bitmap;
24import android.graphics.BitmapFactory;
25import android.media.MediaPlayer;
26import android.net.Uri;
27import android.text.Editable;
28import android.text.TextWatcher;
29import android.util.AttributeSet;
30import android.util.Log;
31import android.view.View;
32import android.widget.EditText;
33import android.widget.ImageView;
34import android.widget.LinearLayout;
35import android.widget.TextView;
36
37import java.io.IOException;
38import java.util.Map;
39
40/**
41 * This is a basic view to show and edit a slide.
42 */
43public class BasicSlideEditorView extends LinearLayout implements
44        SlideViewInterface {
45    private static final String TAG = "BasicSlideEditorView";
46
47    private ImageView mImageView;
48    private View mAudioView;
49    private TextView mAudioNameView;
50    private EditText mEditText;
51    private boolean mOnTextChangedListenerEnabled = true;
52    private OnTextChangedListener mOnTextChangedListener;
53
54    public BasicSlideEditorView(Context context) {
55        super(context);
56    }
57
58    public BasicSlideEditorView(Context context, AttributeSet attrs) {
59        super(context, attrs);
60    }
61
62    @Override
63    public void onFinishInflate() {
64        mImageView = (ImageView) findViewById(R.id.image);
65        mAudioView = findViewById(R.id.audio);
66        mAudioNameView = (TextView) findViewById(R.id.audio_name);
67        mEditText = (EditText) findViewById(R.id.text_message);
68        mEditText.addTextChangedListener(new TextWatcher() {
69            public void beforeTextChanged(CharSequence s, int start, int count,
70                    int after) {
71                // TODO Auto-generated method stub
72            }
73
74            public void onTextChanged(CharSequence s, int start, int before,
75                    int count) {
76                if (mOnTextChangedListenerEnabled && (mOnTextChangedListener != null)) {
77                    mOnTextChangedListener.onTextChanged(s.toString());
78                }
79            }
80
81            public void afterTextChanged(Editable s) {
82                // TODO Auto-generated method stub
83            }
84        });
85    }
86
87    public void startAudio() {
88        // TODO Auto-generated method stub
89    }
90
91    public void startVideo() {
92        // TODO Auto-generated method stub
93    }
94
95    public void setAudio(Uri audio, String name, Map<String, ?> extras) {
96        mAudioView.setVisibility(View.VISIBLE);
97        mAudioNameView.setText(name);
98    }
99
100    public void setImage(String name, Bitmap bitmap) {
101        try {
102            if (null == bitmap) {
103                bitmap = BitmapFactory.decodeResource(getResources(),
104                        R.drawable.ic_missing_thumbnail_picture);
105            }
106            mImageView.setImageBitmap(bitmap);
107        } catch (java.lang.OutOfMemoryError e) {
108            Log.e(TAG, "setImage: out of memory: ", e);
109        }
110    }
111
112    public void setImageRegionFit(String fit) {
113        // TODO Auto-generated method stub
114    }
115
116    public void setImageVisibility(boolean visible) {
117        // TODO Auto-generated method stub
118    }
119
120    public void setText(String name, String text) {
121        mOnTextChangedListenerEnabled = false;
122        if ((text != null) && !text.equals(mEditText.getText().toString())) {
123            mEditText.setText(text);
124            mEditText.setSelection(text.length());
125        }
126        mOnTextChangedListenerEnabled = true;
127    }
128
129    public void setTextVisibility(boolean visible) {
130        // TODO Auto-generated method stub
131    }
132
133    public void setVideo(String name, Uri video) {
134        try {
135            Bitmap bitmap = VideoAttachmentView.createVideoThumbnail(mContext, video);
136            if (null == bitmap) {
137                bitmap = BitmapFactory.decodeResource(getResources(),
138                        R.drawable.ic_missing_thumbnail_video);
139            }
140            mImageView.setImageBitmap(bitmap);
141        } catch (java.lang.OutOfMemoryError e) {
142            Log.e(TAG, "setVideo: out of memory: ", e);
143        }
144    }
145
146    public void setVideoVisibility(boolean visible) {
147        // TODO Auto-generated method stub
148    }
149
150    public void stopAudio() {
151        // TODO Auto-generated method stub
152    }
153
154    public void stopVideo() {
155        // TODO Auto-generated method stub
156    }
157
158    public void reset() {
159        mImageView.setImageDrawable(null);
160        mAudioView.setVisibility(View.GONE);
161        mOnTextChangedListenerEnabled = false;
162        mEditText.setText("");
163        mOnTextChangedListenerEnabled = true;
164    }
165
166    public void setVisibility(boolean visible) {
167        // TODO Auto-generated method stub
168    }
169
170    public void setOnTextChangedListener(OnTextChangedListener l) {
171        mOnTextChangedListener = l;
172    }
173
174    public interface OnTextChangedListener {
175        void onTextChanged(String s);
176    }
177
178    public void pauseAudio() {
179        // TODO Auto-generated method stub
180
181    }
182
183    public void pauseVideo() {
184        // TODO Auto-generated method stub
185
186    }
187
188    public void seekAudio(int seekTo) {
189        // TODO Auto-generated method stub
190
191    }
192
193    public void seekVideo(int seekTo) {
194        // TODO Auto-generated method stub
195
196    }
197}
198