FileDocCategorySizeDatePackage
VideoPreview.javaAPI DocAndroid 1.5 API3492Wed May 06 22:42:42 BST 2009com.android.camera

VideoPreview

public class VideoPreview extends android.view.SurfaceView

Fields Summary
private float
mAspectRatio
private int
mHorizontalTileSize
private int
mVerticalTileSize
public static float
DONT_CARE
Setting the aspect ratio to this value means to not enforce an aspect ratio.
Constructors Summary
public VideoPreview(android.content.Context context)


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

        super(context, attrs);
    
public VideoPreview(android.content.Context context, android.util.AttributeSet attrs, int defStyle)

        super(context, attrs, defStyle);
    
Methods Summary
protected voidonMeasure(int widthMeasureSpec, int heightMeasureSpec)

        if (mAspectRatio != DONT_CARE) {
            int widthSpecSize =  MeasureSpec.getSize(widthMeasureSpec);
            int heightSpecSize =  MeasureSpec.getSize(heightMeasureSpec);

            int width = widthSpecSize;
            int height = heightSpecSize;

            if (width > 0 && height > 0) {
                float defaultRatio = ((float) width) / ((float) height);
                if (defaultRatio < mAspectRatio) {
                    // Need to reduce height
                    height = (int) (width / mAspectRatio);
                } else if (defaultRatio > mAspectRatio) {
                    width = (int) (height * mAspectRatio);
                }
                width = roundUpToTile(width, mHorizontalTileSize, widthSpecSize);
                height = roundUpToTile(height, mVerticalTileSize, heightSpecSize);
                Log.i("VideoPreview", "ar " + mAspectRatio + " setting size: " + width + 'x" + height);
                setMeasuredDimension(width, height);
                return;
            }
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    
private introundUpToTile(int dimension, int tileSize, int maxDimension)

        return Math.min(((dimension + tileSize - 1) / tileSize) * tileSize, maxDimension);
    
public voidsetAspectRatio(int width, int height)

        setAspectRatio(((float) width) / ((float) height));
    
public voidsetAspectRatio(float aspectRatio)

        if (mAspectRatio != aspectRatio) {
            mAspectRatio = aspectRatio;
            requestLayout();
            invalidate();
        }
    
public voidsetTileSize(int horizontalTileSize, int verticalTileSize)

        if ((mHorizontalTileSize != horizontalTileSize)
                || (mVerticalTileSize != verticalTileSize)) {
            mHorizontalTileSize = horizontalTileSize;
            mVerticalTileSize = verticalTileSize;
            requestLayout();
            invalidate();
        }