FileDocCategorySizeDatePackage
SlideView.javaAPI DocAndroid 1.5 API11152Wed May 06 22:42:46 BST 2009com.android.mms.ui

SlideView

public class SlideView extends android.widget.AbsoluteLayout implements AdaptableSlideViewInterface
A basic view to show the contents of a slide.

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final boolean
LOCAL_LOGV
private static final int
AUDIO_INFO_HEIGHT
private android.view.View
mAudioInfoView
private android.widget.ImageView
mImageView
private android.widget.VideoView
mVideoView
private android.widget.ScrollView
mScrollText
private android.widget.TextView
mTextView
private OnSizeChangedListener
mSizeChangedListener
private android.media.MediaPlayer
mAudioPlayer
private boolean
mIsPrepared
private boolean
mStartWhenPrepared
private int
mSeekWhenPrepared
private boolean
mStopWhenPrepared
MediaPlayer.OnPreparedListener
mPreparedListener
Constructors Summary
public SlideView(android.content.Context context)


       
        super(context);
    
public SlideView(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);
    
Methods Summary
private voiddisplayAudioInfo()

        if (null != mAudioInfoView) {
            mAudioInfoView.setVisibility(View.VISIBLE);
        }
    
private voidhideAudioInfo()

        if (null != mAudioInfoView) {
            mAudioInfoView.setVisibility(View.GONE);
        }
    
private voidinitAudioInfoView(java.lang.String name)

        if (null == mAudioInfoView) {
            LayoutInflater factory = LayoutInflater.from(getContext());
            mAudioInfoView = factory.inflate(R.layout.playing_audio_info, null);
            int height = mAudioInfoView.getHeight();
            TextView audioName = (TextView) mAudioInfoView.findViewById(R.id.name);
            audioName.setText(name);
            addView(mAudioInfoView, new LayoutParams(
                    LayoutParams.FILL_PARENT, AUDIO_INFO_HEIGHT,
                    0, getHeight() - AUDIO_INFO_HEIGHT));
            if (DEBUG) {
                mAudioInfoView.setBackgroundColor(0xFFFF0000);
            }
        }

        mAudioInfoView.setVisibility(View.GONE);
    
protected voidonSizeChanged(int w, int h, int oldw, int oldh)

        super.onSizeChanged(w, h, oldw, oldh);

        if (mSizeChangedListener != null) {
            if (LOCAL_LOGV) {
                Log.v(TAG, "new size=" + w + "x" + h);
            }
            mSizeChangedListener.onSizeChanged(w, h - AUDIO_INFO_HEIGHT);
        }
    
public voidpauseAudio()

        if ((mAudioPlayer != null) && mIsPrepared) {
            if (mAudioPlayer.isPlaying()) {
                mAudioPlayer.pause();
            }
        }
        mStartWhenPrepared = false;
    
public voidpauseVideo()

        if (mVideoView != null) {
            if (LOCAL_LOGV) {
                Log.v(TAG, "Pausing video playback.");
            }
            mVideoView.pause();
        }
    
public voidreset()

        if (null != mScrollText) {
            mScrollText.setVisibility(View.GONE);
        }

        if (null != mImageView) {
            mImageView.setVisibility(View.GONE);
        }

        if (null != mAudioPlayer) {
            stopAudio();
        }

        if (null != mVideoView) {
            stopVideo();
            mVideoView.setVisibility(View.GONE);
        }
    
public voidseekAudio(int seekTo)

        if ((mAudioPlayer != null) && mIsPrepared) {
            mAudioPlayer.seekTo(seekTo);
        } else {
            mSeekWhenPrepared = seekTo;
        }
    
public voidseekVideo(int seekTo)

        if (mVideoView != null) {
            if (seekTo > 0) {
                if (LOCAL_LOGV) {
                    Log.v(TAG, "Seeking video playback to " + seekTo);
                }
                mVideoView.seekTo(seekTo);
            }
        }
    
public voidsetAudio(android.net.Uri audio, java.lang.String name, java.util.Map extras)

        if (audio == null) {
            throw new IllegalArgumentException("Audio URI may not be null.");
        }

        if (LOCAL_LOGV) {
            Log.v(TAG, "Changing audio source to " + audio);
        }

        if (mAudioPlayer != null) {
            mAudioPlayer.reset();
            mAudioPlayer.release();
            mAudioPlayer = null;
        }
        mIsPrepared = false;

        try {
            mAudioPlayer = new MediaPlayer();
            mAudioPlayer.setOnPreparedListener(mPreparedListener);
            mAudioPlayer.setDataSource(mContext, audio);
            mAudioPlayer.prepareAsync();
        } catch (IOException e) {
            Log.e(TAG, "Unexpected IOException.", e);
            mAudioPlayer.release();
            mAudioPlayer = null;
        }
        initAudioInfoView(name);
    
public voidsetImage(java.lang.String name, android.graphics.Bitmap bitmap)

        if (mImageView == null) {
            mImageView = new ImageView(mContext);
            addView(mImageView, new LayoutParams(
                    0, 0, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            if (DEBUG) {
                mImageView.setBackgroundColor(0xFFFF0000);
            }
        }

        if (null == bitmap) {
            bitmap = BitmapFactory.decodeResource(getResources(),
                    R.drawable.ic_missing_thumbnail_picture);
        }
        mImageView.setImageBitmap(bitmap);
    
public voidsetImageRegion(int left, int top, int width, int height)

        if (mImageView != null) {
            mImageView.setLayoutParams(new LayoutParams(width, height, left, top));
        }
    
public voidsetImageRegionFit(java.lang.String fit)

        // TODO Auto-generated method stub
    
public voidsetImageVisibility(boolean visible)

        if (mImageView != null) {
            mImageView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
        }
    
public voidsetOnSizeChangedListener(OnSizeChangedListener l)

        mSizeChangedListener = l;
    
public voidsetText(java.lang.String name, java.lang.String text)

        if (null == mScrollText) {
            mScrollText = new ScrollView(mContext);
            mScrollText.setScrollBarStyle(SCROLLBARS_OUTSIDE_INSET);
            addView(mScrollText, new LayoutParams(
                    0, 0, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            if (DEBUG) {
                mScrollText.setBackgroundColor(0xFF00FF00);
            }
        }

        if (null == mTextView) {
            mTextView = new TextView(mContext);
            mTextView.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
            mScrollText.addView(mTextView);
        }

        mScrollText.requestFocus();
        mTextView.setText(text);
    
public voidsetTextRegion(int left, int top, int width, int height)

        if (mScrollText != null) {
            mScrollText.setLayoutParams(new LayoutParams(width, height, left, top));
        }
    
public voidsetTextVisibility(boolean visible)

        if (mScrollText != null) {
            mScrollText.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
        }
    
public voidsetVideo(java.lang.String name, android.net.Uri video)

        if (mVideoView == null) {
            mVideoView = new VideoView(mContext);
            addView(mVideoView, new LayoutParams(
                    0, 0, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            if (DEBUG) {
                mVideoView.setBackgroundColor(0xFFFF0000);
            }
        }

        if (LOCAL_LOGV) {
            Log.v(TAG, "Changing video source to " + video);
        }
        mVideoView.setVideoURI(video);
    
public voidsetVideoRegion(int left, int top, int width, int height)

        if (mVideoView != null) {
            mVideoView.setLayoutParams(new LayoutParams(width, height, left, top));
        }
    
public voidsetVideoVisibility(boolean visible)

        if (mVideoView != null) {
            mVideoView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
        }
    
public voidsetVisibility(boolean visible)

        // TODO Auto-generated method stub
    
public voidstartAudio()

        if ((mAudioPlayer != null) && mIsPrepared) {
            mAudioPlayer.start();
            mStartWhenPrepared = false;
            displayAudioInfo();
        } else {
            mStartWhenPrepared = true;
        }
    
public voidstartVideo()

        if (mVideoView != null) {
            if (LOCAL_LOGV) {
                Log.v(TAG, "Starting video playback.");
            }
            mVideoView.start();
        }
    
public voidstopAudio()

        if ((mAudioPlayer != null) && mIsPrepared) {
            mAudioPlayer.stop();
            mAudioPlayer.release();
            mAudioPlayer = null;
            hideAudioInfo();
        } else {
            mStopWhenPrepared = true;
        }
    
public voidstopVideo()

        if ((mVideoView != null)) {
            if (LOCAL_LOGV) {
                Log.v(TAG, "Stopping video playback.");
            }
            mVideoView.stopPlayback();
        }