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 
     22 import android.content.Context;
     23 import android.graphics.Bitmap;
     24 import android.graphics.BitmapFactory;
     25 import android.media.MediaPlayer;
     26 import android.net.Uri;
     27 import android.text.Editable;
     28 import android.text.TextWatcher;
     29 import android.util.AttributeSet;
     30 import android.util.Log;
     31 import android.view.View;
     32 import android.widget.EditText;
     33 import android.widget.ImageView;
     34 import android.widget.LinearLayout;
     35 import android.widget.TextView;
     36 
     37 import java.io.IOException;
     38 import java.util.Map;
     39 
     40 /**
     41  * This is a basic view to show and edit a slide.
     42  */
     43 public 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 setVideoThumbnail(String name, Bitmap bitmap) {
    147         mImageView.setImageBitmap(bitmap);
    148     }
    149 
    150     public void setVideoVisibility(boolean visible) {
    151         // TODO Auto-generated method stub
    152     }
    153 
    154     public void stopAudio() {
    155         // TODO Auto-generated method stub
    156     }
    157 
    158     public void stopVideo() {
    159         // TODO Auto-generated method stub
    160     }
    161 
    162     public void reset() {
    163         mImageView.setImageDrawable(null);
    164         mAudioView.setVisibility(View.GONE);
    165         mOnTextChangedListenerEnabled = false;
    166         mEditText.setText("");
    167         mOnTextChangedListenerEnabled = true;
    168     }
    169 
    170     public void setVisibility(boolean visible) {
    171         // TODO Auto-generated method stub
    172     }
    173 
    174     public void setOnTextChangedListener(OnTextChangedListener l) {
    175         mOnTextChangedListener = l;
    176     }
    177 
    178     public interface OnTextChangedListener {
    179         void onTextChanged(String s);
    180     }
    181 
    182     public void pauseAudio() {
    183         // TODO Auto-generated method stub
    184 
    185     }
    186 
    187     public void pauseVideo() {
    188         // TODO Auto-generated method stub
    189 
    190     }
    191 
    192     public void seekAudio(int seekTo) {
    193         // TODO Auto-generated method stub
    194 
    195     }
    196 
    197     public void seekVideo(int seekTo) {
    198         // TODO Auto-generated method stub
    199 
    200     }
    201 }
    202