Android Camera SurfaceView方向

Android Camera SurfaceView方向

好的,所以我有一个扩展SurfaceView和重写的类


surfaceChanged-仅调用startPreview

surfaceCreated-打开相机,编辑参数*,设置surfaceHolder

surfaceDestroyed-调用stopPreview,释放相机


这一切都很好,因为当方向是纵向时:


从surfaceCreated *


m_camera = Camera.open();

Camera.Parameters p = m_camera.getParameters();


if (getResources().getConfiguration().orientation != 

    Configuration.ORIENTATION_LANDSCAPE)

{

    p.set("orientation", "portrait");


    // CameraApi is a wrapper to check for backwards compatibility  

    if (CameraApi.isSetRotationSupported())

    {

         CameraApi.setRotation(p, 90);

    }

}

但是,每次方向更改时,它都会调用Camera.open()...,您可能知道这是一项非常昂贵的操作,从而导致过渡不那么平滑。


当我将方向强制为横向时,预览效果很好。仅调用一次Create就可以,因为预览是横向的,相机始终是用户看到的东西,因此可以调用。但是,我需要一种方法来设置肖像拍摄时实际照片的方向。但是,当我强制使用风景时,将相机纵向放置时,永远不会重新创建表面,也永远不会设置参数。


那么,如何执行以下一项(排他性的)?


方向更改时,在onDestroy和onCreate之间保留m_camera,以使过渡平滑


强制横向移动并检测方向变化的另一种方式...如果纵向旋转,则旋转最终拍摄的照片。


另外,如果我不在基地,有人可以指出我的方向吗?谢谢。


catspeake
浏览 1159回答 3
3回答

慕仙森

我的实现方式:private Camera mCamera;private OrientationEventListener mOrientationEventListener;private int mOrientation =&nbsp; -1;private static final int ORIENTATION_PORTRAIT_NORMAL =&nbsp; 1;private static final int ORIENTATION_PORTRAIT_INVERTED =&nbsp; 2;private static final int ORIENTATION_LANDSCAPE_NORMAL =&nbsp; 3;private static final int ORIENTATION_LANDSCAPE_INVERTED =&nbsp; 4;@Overridepublic void onCreate(Bundle savedInstanceState) {&nbsp; &nbsp; super.onCreate(savedInstanceState);&nbsp; &nbsp; // force Landscape layout&nbsp; &nbsp; setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);&nbsp; &nbsp;/*&nbsp; &nbsp;Your other initialization code here&nbsp; &nbsp;*/}@Override&nbsp;protected void onResume() {&nbsp; &nbsp; super.onResume();&nbsp; &nbsp; if (mOrientationEventListener == null) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; mOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void onOrientationChanged(int orientation) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // determine our orientation based on sensor response&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int lastOrientation = mOrientation;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (orientation >= 315 || orientation < 45) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mOrientation != ORIENTATION_PORTRAIT_NORMAL) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mOrientation = ORIENTATION_PORTRAIT_NORMAL;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if (orientation < 315 && orientation >= 225) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mOrientation != ORIENTATION_LANDSCAPE_NORMAL) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mOrientation = ORIENTATION_LANDSCAPE_NORMAL;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if (orientation < 225 && orientation >= 135) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mOrientation != ORIENTATION_PORTRAIT_INVERTED) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mOrientation = ORIENTATION_PORTRAIT_INVERTED;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else { // orientation <135 && orientation > 45&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mOrientation != ORIENTATION_LANDSCAPE_INVERTED) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mOrientation = ORIENTATION_LANDSCAPE_INVERTED;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (lastOrientation != mOrientation) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; changeRotation(mOrientation, lastOrientation);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; }&nbsp; &nbsp; if (mOrientationEventListener.canDetectOrientation()) {&nbsp; &nbsp; &nbsp; &nbsp; mOrientationEventListener.enable();&nbsp; &nbsp; }}@Override protected void onPause() {&nbsp; &nbsp; super.onPause();&nbsp; &nbsp; mOrientationEventListener.disable();}/**&nbsp;* Performs required action to accommodate new orientation&nbsp;* @param orientation&nbsp;* @param lastOrientation&nbsp;*/private void changeRotation(int orientation, int lastOrientation) {&nbsp; &nbsp; switch (orientation) {&nbsp; &nbsp; &nbsp; &nbsp; case ORIENTATION_PORTRAIT_NORMAL:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mSnapButton.setImageDrawable(getRotatedImage(android.R.drawable.ic_menu_camera, 270));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mBackButton.setImageDrawable(getRotatedImage(android.R.drawable.ic_menu_revert, 270));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.v("CameraActivity", "Orientation = 90");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; case ORIENTATION_LANDSCAPE_NORMAL:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mSnapButton.setImageResource(android.R.drawable.ic_menu_camera);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mBackButton.setImageResource(android.R.drawable.ic_menu_revert);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.v("CameraActivity", "Orientation = 0");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; case ORIENTATION_PORTRAIT_INVERTED:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mSnapButton.setImageDrawable(getRotatedImage(android.R.drawable.ic_menu_camera, 90));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mBackButton.setImageDrawable(getRotatedImage(android.R.drawable.ic_menu_revert, 90));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.v("CameraActivity", "Orientation = 270");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; case ORIENTATION_LANDSCAPE_INVERTED:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mSnapButton.setImageDrawable(getRotatedImage(android.R.drawable.ic_menu_camera, 180));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mBackButton.setImageDrawable(getRotatedImage(android.R.drawable.ic_menu_revert, 180));&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.v("CameraActivity", "Orientation = 180");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; }}&nbsp; &nbsp; /**&nbsp;* Rotates given Drawable&nbsp;* @param drawableId&nbsp; &nbsp; Drawable Id to rotate&nbsp;* @param degrees&nbsp; &nbsp; &nbsp; &nbsp;Rotate drawable by Degrees&nbsp;* @return&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Rotated Drawable&nbsp;*/private Drawable getRotatedImage(int drawableId, int degrees) {&nbsp; &nbsp; Bitmap original = BitmapFactory.decodeResource(getResources(), drawableId);&nbsp; &nbsp; Matrix matrix = new Matrix();&nbsp; &nbsp; matrix.postRotate(degrees);&nbsp; &nbsp; Bitmap rotated = Bitmap.createBitmap(original, 0, 0, original.getWidth(), original.getHeight(), matrix, true);&nbsp; &nbsp; return new BitmapDrawable(rotated);}然后在PictureCallback中设置元数据以指示旋转级别:&nbsp; &nbsp; private Camera.PictureCallback mJpegCallback = new Camera.PictureCallback() {&nbsp; &nbsp; @Override&nbsp; &nbsp; public void onPictureTaken(byte[] data, Camera camera) {&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Populate image metadata&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ContentValues image = new ContentValues();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // additional picture metadata&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image.put(Media.DISPLAY_NAME, [picture name]);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image.put(Media.MIME_TYPE, "image/jpg");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image.put(Media.TITLE, [picture title]);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image.put(Media.DESCRIPTION, [picture description]);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image.put(Media.DATE_ADDED, [some time]);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image.put(Media.DATE_TAKEN, [some time]);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image.put(Media.DATE_MODIFIED, [some time]);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // do not rotate image, just put rotation info in&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch (mOrientation) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case ORIENTATION_PORTRAIT_NORMAL:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image.put(Media.ORIENTATION, 90);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case ORIENTATION_LANDSCAPE_NORMAL:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image.put(Media.ORIENTATION, 0);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case ORIENTATION_PORTRAIT_INVERTED:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image.put(Media.ORIENTATION, 270);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case ORIENTATION_LANDSCAPE_INVERTED:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image.put(Media.ORIENTATION, 180);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // store the picture&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Uri uri = getContentResolver().insert(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Media.EXTERNAL_CONTENT_URI, image);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data.length);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputStream out = getContentResolver().openOutputStream(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uri);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; boolean success = bitmap.compress(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bitmap.CompressFormat.JPEG, 75, out);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; out.close();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!success) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; finish(); // image output failed without any error,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // silently finish&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (Exception e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // handle exceptions&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mResultIntent = new Intent();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mResultIntent.setData(uri);&nbsp; &nbsp; &nbsp; &nbsp; } catch (Exception e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; finish();&nbsp; &nbsp; }};希望对您有所帮助。更新现在,当基于景观的设备出现时,在OrientationEventListener中需要对其进行附加检查。Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if (display.getOrientation() == Surface.ROTATION_0) {&nbsp;&nbsp; &nbsp; // landscape oriented devices} else {&nbsp;&nbsp; &nbsp; // portrait oriented device}完整代码(LC有点浪费,但可以轻松演示该方法)@Overridepublic void onOrientationChanged(int orientation) {&nbsp; &nbsp; // determine our orientation based on sensor response&nbsp; &nbsp; int lastOrientation = mOrientation;&nbsp; &nbsp; Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; if (display.getOrientation() == Surface.ROTATION_0) {&nbsp; &nbsp;// landscape oriented devices&nbsp; &nbsp; &nbsp; &nbsp; if (orientation >= 315 || orientation < 45) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mOrientation != ORIENTATION_LANDSCAPE_NORMAL) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mOrientation = ORIENTATION_LANDSCAPE_NORMAL;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; } else if (orientation < 315 && orientation >= 225) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mOrientation != ORIENTATION_PORTRAIT_INVERTED) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mOrientation = ORIENTATION_PORTRAIT_INVERTED;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; } else if (orientation < 225 && orientation >= 135) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mOrientation != ORIENTATION_LANDSCAPE_INVERTED) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mOrientation = ORIENTATION_LANDSCAPE_INVERTED;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; } else if (orientation <135 && orientation > 45) {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mOrientation != ORIENTATION_PORTRAIT_NORMAL) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mOrientation = ORIENTATION_PORTRAIT_NORMAL;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; } else {&nbsp; // portrait oriented devices&nbsp; &nbsp; &nbsp; &nbsp; if (orientation >= 315 || orientation < 45) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mOrientation != ORIENTATION_PORTRAIT_NORMAL) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mOrientation = ORIENTATION_PORTRAIT_NORMAL;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; } else if (orientation < 315 && orientation >= 225) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mOrientation != ORIENTATION_LANDSCAPE_NORMAL) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mOrientation = ORIENTATION_LANDSCAPE_NORMAL;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; } else if (orientation < 225 && orientation >= 135) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mOrientation != ORIENTATION_PORTRAIT_INVERTED) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mOrientation = ORIENTATION_PORTRAIT_INVERTED;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; } else if (orientation <135 && orientation > 45) {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mOrientation != ORIENTATION_LANDSCAPE_INVERTED) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mOrientation = ORIENTATION_LANDSCAPE_INVERTED;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; if (lastOrientation != mOrientation) {&nbsp; &nbsp; &nbsp; &nbsp; changeRotation(mOrientation, lastOrientation);&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android