VideoPreviewpublic class VideoPreview extends android.view.SurfaceView
Fields Summary |
---|
private float | mAspectRatio | private int | mHorizontalTileSize | private int | mVerticalTileSize | public static float | DONT_CARESetting the aspect ratio to this value means to not enforce an aspect ratio. |
Methods Summary |
---|
protected void | onMeasure(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 int | roundUpToTile(int dimension, int tileSize, int maxDimension)
return Math.min(((dimension + tileSize - 1) / tileSize) * tileSize, maxDimension);
| public void | setAspectRatio(int width, int height)
setAspectRatio(((float) width) / ((float) height));
| public void | setAspectRatio(float aspectRatio)
if (mAspectRatio != aspectRatio) {
mAspectRatio = aspectRatio;
requestLayout();
invalidate();
}
| public void | setTileSize(int horizontalTileSize, int verticalTileSize)
if ((mHorizontalTileSize != horizontalTileSize)
|| (mVerticalTileSize != verticalTileSize)) {
mHorizontalTileSize = horizontalTileSize;
mVerticalTileSize = verticalTileSize;
requestLayout();
invalidate();
}
|
|