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