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