本文整理汇总了Java中android.view.Surface类的典型用法代码示例。如果您正苦于以下问题:Java Surface类的具体用法?Java Surface怎么用?Java Surface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Surface类属于android.view包,在下文中一共展示了Surface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureTransform
import android.view.Surface; //导入依赖的package包/类
/**
* Configures the necessary {@link Matrix} transformation to `mTextureView`.
* This method should be called after the camera preview size is determined in
* setUpCameraOutputs and also the size of `mTextureView` is fixed.
*
* @param viewWidth The width of `mTextureView`
* @param viewHeight The height of `mTextureView`
*/
private void configureTransform(int viewWidth, int viewHeight) {
Activity activity = getActivity();
if (null == mTextureView || null == mPreviewSize || null == activity) {
return;
}
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
Matrix matrix = new Matrix();
RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
float centerX = viewRect.centerX();
float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
float scale = Math.max(
(float) viewHeight / mPreviewSize.getHeight(),
(float) viewWidth / mPreviewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
} else if (Surface.ROTATION_180 == rotation) {
matrix.postRotate(180, centerX, centerY);
}
mTextureView.setTransform(matrix);
}
示例2: getOrientationInDegree
import android.view.Surface; //导入依赖的package包/类
public static int getOrientationInDegree(Activity activity) {
int rotation = activity.getWindowManager().getDefaultDisplay()
.getRotation();
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0:
degrees = 0;
break;
case Surface.ROTATION_90:
degrees = 90;
break;
case Surface.ROTATION_180:
degrees = 180;
break;
case Surface.ROTATION_270:
degrees = 270;
break;
}
return degrees;
}
示例3: getDeviceDefaultOrientation
import android.view.Surface; //导入依赖的package包/类
/**
* Get the natural orientation of the device. For larger phones it is often LANDSCAPE - for smaller, PORTRAIT.
*
* @return LANDSCAPE or PORTRAIT, based on the screen information
*/
public ScreenOrientation getDeviceDefaultOrientation() {
WindowManager windowManager = (WindowManager) Util.getContext().getSystemService(Context.WINDOW_SERVICE);
Configuration config = Util.getContext().getResources().getConfiguration();
int rotation = windowManager.getDefaultDisplay().getRotation();
if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) &&
config.orientation == Configuration.ORIENTATION_LANDSCAPE)
|| ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) &&
config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
return ScreenOrientation.LANDSCAPE;
} else {
return ScreenOrientation.PORTRAIT;
}
}
示例4: initGLComponents
import android.view.Surface; //导入依赖的package包/类
@Override
protected synchronized void initGLComponents()
{
if (mEffect != null) {
mEffect.initGLComponents();
int videoTexture = mEffect.getVideoTexture();
mVideoSurfaceTexture = new SurfaceTexture(videoTexture);
mVideoSurfaceTexture.setOnFrameAvailableListener(this);
int uiTexture = mEffect.getUIOverlayTexture();
mUISurfaceTexture = new SurfaceTexture(uiTexture);
mUISurfaceTexture.setDefaultBufferSize(mViewWidth, mViewHeight);
mUISurface = new Surface(mUISurfaceTexture);
try {
Canvas c = mUISurface.lockCanvas(null);
c.drawColor(0x0);
mUISurface.unlockCanvasAndPost(c);
} catch (Exception e) { }
}
notifyInit();
}
示例5: configureTransform
import android.view.Surface; //导入依赖的package包/类
/**
* Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
* This method should be called after the camera preview size is determined in
* setUpCameraOutputs and also the size of `mTextureView` is fixed.
*
* @param viewWidth The width of `mTextureView`
* @param viewHeight The height of `mTextureView`
*/
private void configureTransform(final int viewWidth, final int viewHeight) {
final Activity activity = getActivity();
if (null == textureView || null == previewSize || null == activity) {
return;
}
final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
final Matrix matrix = new Matrix();
final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
final float centerX = viewRect.centerX();
final float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
final float scale =
Math.max(
(float) viewHeight / previewSize.getHeight(),
(float) viewWidth / previewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
} else if (Surface.ROTATION_180 == rotation) {
matrix.postRotate(180, centerX, centerY);
}
textureView.setTransform(matrix);
}
示例6: open
import android.view.Surface; //导入依赖的package包/类
@Override
public Point open(SurfaceTexture surface) {
try {
if(!extractMedia()){
return new Point(0,0);
}
mFrameSem=new Semaphore(0);
mDecodeSem=new Semaphore(1);
videoProvideEndFlag=false;
isUserWantToStop=false;
mAudioEncodeTrack=mStore.addTrack(mExtractor.getTrackFormat(mAudioDecodeTrack));
MediaFormat format=mExtractor.getTrackFormat(mVideoDecodeTrack);
mVideoDecoder = MediaCodec.createDecoderByType(format.getString(MediaFormat.KEY_MIME));
mVideoDecoder.configure(format,new Surface(surface),null,0);
mVideoDecoder.start();
startDecodeThread();
} catch (IOException e) {
e.printStackTrace();
}
return mVideoSize;
}
示例7: lockOrientation
import android.view.Surface; //导入依赖的package包/类
/**
* Locks the device window in actual screen mode
*/
public static void lockOrientation(Activity activity) {
Display display = ((WindowManager) activity.
getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
int orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
switch (activity.getResources().getConfiguration().orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90)
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
else
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
break;
case Configuration.ORIENTATION_PORTRAIT:
if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270)
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
else
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
}
//noinspection ResourceType
activity.setRequestedOrientation(orientation);
}
示例8: configureTransform
import android.view.Surface; //导入依赖的package包/类
/**
* Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
* This method should be called after the camera preview size is determined in
* setUpCameraOutputs and also the size of `mTextureView` is fixed.
*
* @param viewWidth The width of `mTextureView`
* @param viewHeight The height of `mTextureView`
*/
private void configureTransform(final int viewWidth, final int viewHeight) {
final Activity activity = getActivity();
if (null == textureView || null == previewSize || null == activity) {
return;
}
final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
final Matrix matrix = new Matrix();
final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
final float centerX = viewRect.centerX();
final float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
final float scale = Math.max((float) viewHeight / previewSize.getHeight(),
(float) viewWidth / previewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
} else if (Surface.ROTATION_180 == rotation) {
matrix.postRotate(180, centerX, centerY);
}
textureView.setTransform(matrix);
}
示例9: getRotationAngle
import android.view.Surface; //导入依赖的package包/类
public static int getRotationAngle(int rotation)
{
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0:
degrees = 0;
break;
case Surface.ROTATION_90:
degrees = 90;
break;
case Surface.ROTATION_180:
degrees = 180;
break;
case Surface.ROTATION_270:
degrees = 270;
break;
default:
break;
}
return degrees;
}
示例10: adjustHeadingForDeviceOrientation
import android.view.Surface; //导入依赖的package包/类
private float adjustHeadingForDeviceOrientation(float heading)
{
switch (m_deviceRotation) {
case Surface.ROTATION_0:
heading += 0.f;
break;
case Surface.ROTATION_90:
heading += 90.f;
break;
case Surface.ROTATION_180:
heading += 180.f;
break;
default:
heading += 90.f;
break;
}
heading = (heading + 360.f)%360.f;
return heading;
}
示例11: MoviePlayer
import android.view.Surface; //导入依赖的package包/类
public MoviePlayer(File sourceFile, Surface outputSurface)
throws IOException {
// Pop the file open and pull out the video characteristics.
// TODO: consider leaving the extractor open. Should be able to just seek back to
// the start after each iteration of play. Need to rearrange the API a bit --
// currently play() is taking an all-in-one open+work+release approach.
try {
Log.d(TAG, sourceFile.toString());
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(sourceFile.toString());
mVideoDuration = Long.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
Log.d(TAG, "Duration: " + mVideoDuration);
retriever.release();
mVideoDecoder = new VideoDecoder(this, sourceFile);
mVideoDecoder.setOutputSurface(outputSurface);
mAudioDecoder = new AudioDecoder(this, sourceFile);
mVideoDecoder.prepare();
mAudioDecoder.prepare();
} catch (Exception ex) {
release();
throw new IOException(ex.getMessage());
}
}
示例12: configureTransform
import android.view.Surface; //导入依赖的package包/类
private void configureTransform(TextureView textureView) {
if (null == textureView || null == mPreviewSize || null == mActivity) {
return;
}
int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
Matrix matrix = new Matrix();
RectF viewRect = new RectF(0, 0, textureView.getWidth(), textureView.getHeight());
RectF bufferRect = new RectF(0, 0, mPreviewSize.y, mPreviewSize.x);
float centerX = viewRect.centerX();
float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
float scale = Math.max(
(float) textureView.getHeight() / mPreviewSize.y,
(float) textureView.getWidth() / mPreviewSize.x);
matrix.postScale(scale, scale, centerX, centerY);
}
matrix.postRotate(-90 * rotation, centerX, centerY);
textureView.setTransform(matrix);
}
示例13: configureTransform
import android.view.Surface; //导入依赖的package包/类
/**
* Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
* This method should be called after the camera preview size is determined in
* setUpCameraOutputs and also the size of `mTextureView` is fixed.
*
* @param viewWidth The width of `mTextureView`
* @param viewHeight The height of `mTextureView`
*/
private void configureTransform(final int viewWidth, final int viewHeight) {
if (mPreviewSize == null) return;
final int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
final Matrix matrix = new Matrix();
final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
final RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
final float centerX = viewRect.centerX();
final float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
final float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(),
(float) viewWidth / mPreviewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
} else if (Surface.ROTATION_180 == rotation) {
matrix.postRotate(180, centerX, centerY);
}
mAutoFitTextureView.setTransform(matrix);
}
示例14: getDisplayRotation
import android.view.Surface; //导入依赖的package包/类
private int getDisplayRotation(Context context) {
WindowManager windowManager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
int rotation = windowManager.getDefaultDisplay().getRotation();
switch (rotation) {
case Surface.ROTATION_0:
return 0;
case Surface.ROTATION_90:
return 90;
case Surface.ROTATION_180:
return 180;
case Surface.ROTATION_270:
return 270;
}
return 0;
}
示例15: getDeviceOrientation
import android.view.Surface; //导入依赖的package包/类
private int getDeviceOrientation() {
int orientation = 0;
WindowManager wm = (WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE);
switch (wm.getDefaultDisplay().getRotation()) {
case Surface.ROTATION_90:
orientation = 90;
break;
case Surface.ROTATION_180:
orientation = 180;
break;
case Surface.ROTATION_270:
orientation = 270;
break;
case Surface.ROTATION_0:
default:
orientation = 0;
break;
}
return orientation;
}