Java Code Examples for android.view.Surface#ROTATION_0
The following examples show how to use
android.view.Surface#ROTATION_0 .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Util.java From FaceDetectCamera with Apache License 2.0 | 6 votes |
/** * Gets the current display rotation in angles. * * @param activity * @return */ public static int getDisplayRotation(Activity activity) { int rotation = activity.getWindowManager().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; }
Example 2
Source File: CaptureActivity.java From barcodescanner-lib-aar with MIT License | 6 votes |
private int getCurrentOrientation() { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } } else { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_270: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } } }
Example 3
Source File: LiveCameraActivity.java From grafika with Apache License 2.0 | 6 votes |
private void startPreview() { mCamera = Camera.open(); if (mCamera == null) { // Seeing this on Nexus 7 2012 -- I guess it wants a rear-facing camera, but // there isn't one. TODO: fix throw new RuntimeException("Default camera not available"); } try { mCamera.setPreviewTexture(mSurfaceTexture); Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); if(display.getRotation() == Surface.ROTATION_0) { mCamera.setDisplayOrientation(90); } if(display.getRotation() == Surface.ROTATION_270) { mCamera.setDisplayOrientation(180); } mCamera.startPreview(); } catch (IOException ioe) { // Something bad happened Log.e(TAG,"Exception starting preview", ioe); } }
Example 4
Source File: Camera2Session.java From VideoCRE with MIT License | 6 votes |
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; }
Example 5
Source File: RCTSensorOrientationChecker.java From react-native-camera-face-detector with MIT License | 6 votes |
@Override public void onSensorChanged(SensorEvent event) { float x = event.values[0]; float y = event.values[1]; if (x<5 && x>-5 && y > 5) mOrientation = Surface.ROTATION_0; // portrait else if (x<-5 && y<5 && y>-5) mOrientation = Surface.ROTATION_270; // right else if (x<5 && x>-5 && y<-5) mOrientation = Surface.ROTATION_180; // upside down else if (x>5 && y<5 && y>-5) mOrientation = Surface.ROTATION_90; // left if (mListener != null) { mListener.orientationEvent(); } }
Example 6
Source File: OrientationData.java From tilt-game-android with MIT License | 6 votes |
private void updateOrientation() { SensorManager.getRotationMatrix(this.mRotationMatrix, null, this.mAccelerationValues, this.mMagneticFieldValues); // TODO Use dont't use identical matrixes in remapCoordinateSystem, due to performance reasons. switch (this.mDisplayRotation) { case Surface.ROTATION_0: /* Nothing. */ break; case Surface.ROTATION_90: SensorManager.remapCoordinateSystem(this.mRotationMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, this.mRotationMatrix); break; // case Surface.ROTATION_180: // SensorManager.remapCoordinateSystem(this.mRotationMatrix, SensorManager.AXIS_?, SensorManager.AXIS_?, this.mRotationMatrix); // break; // case Surface.ROTATION_270: // SensorManager.remapCoordinateSystem(this.mRotationMatrix, SensorManager.AXIS_?, SensorManager.AXIS_?, this.mRotationMatrix); // break; } final float[] values = this.mValues; SensorManager.getOrientation(this.mRotationMatrix, values); for (int i = values.length - 1; i >= 0; i--) { values[i] = values[i] * MathConstants.RAD_TO_DEG; } }
Example 7
Source File: Camera2Wrapper.java From DeviceConnect-Android with MIT License | 6 votes |
/** * カメラの取り付けられた向きと画面の向きから縦横のスワップが必要か確認します. * * @return スワップが必要な場合はtrue、それ以外はfalse */ public boolean isSwappedDimensions() { int sensorOrientation = getSensorOrientation(); switch (getDisplayRotation()) { case Surface.ROTATION_0: case Surface.ROTATION_180: if (sensorOrientation == 90 || sensorOrientation == 270) { return true; } break; case Surface.ROTATION_90: case Surface.ROTATION_270: if (sensorOrientation == 0 || sensorOrientation == 180) { return true; } break; default: if (DEBUG) { Log.w(TAG, "Display rotation is invalid."); } break; } return false; }
Example 8
Source File: DefaultEasyCamera.java From EasyCamera with Apache License 2.0 | 6 votes |
@Override public void alignCameraAndDisplayOrientation(WindowManager windowManager) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(id, info); int rotation = windowManager.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; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); }
Example 9
Source File: VideoCapture.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
private int getDeviceOrientation() { int orientation = 0; if (mContext != null) { WindowManager wm = (WindowManager)mContext.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; }
Example 10
Source File: Utils.java From Paddle-Lite-Demo with Apache License 2.0 | 5 votes |
public static int getCameraDisplayOrientation(Context context, int cameraId) { android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); int rotation = wm.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; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } return result; }
Example 11
Source File: CameraHelper.java From AndroidRecording with Apache License 2.0 | 5 votes |
public static int setCameraDisplayOrientation(int cameraId, android.hardware.Camera camera, int displayRotation) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int degrees = 0; switch (displayRotation) { 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; } int camRotationDegree = 0; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { camRotationDegree = (info.orientation + degrees) % 360; camRotationDegree = (360 - camRotationDegree) % 360; // compensate the mirror } else { camRotationDegree = (info.orientation - degrees + 360) % 360; } if (camera != null) { camera.setDisplayOrientation(camRotationDegree); } return camRotationDegree; }
Example 12
Source File: CameraWrapperTest.java From LandscapeVideoCamera with Apache License 2.0 | 5 votes |
@Test public void getSupportedRecordingSizeTooSmall() { NativeCamera mockCamera = createCameraWithMockParameters(640, 480, 0, 0); final CameraWrapper wrapper = new CameraWrapper(mockCamera, Surface.ROTATION_0); RecordingSize supportedRecordingSize = wrapper.getSupportedRecordingSize(320, 240); assertEquals(supportedRecordingSize.width, 640); assertEquals(supportedRecordingSize.height, 480); }
Example 13
Source File: SurfaceMJPEGEncoder.java From DeviceConnect-Android with MIT License | 5 votes |
/** * 解像度の縦横のサイズをスワップするか判断します. * * @return スワップする場合は true、それ以外は false */ public boolean isSwappedDimensions() { switch (getDisplayRotation()) { case Surface.ROTATION_0: case Surface.ROTATION_180: return false; default: return true; } }
Example 14
Source File: DrawARActivity.java From justaline-android with Apache License 2.0 | 5 votes |
@Override public void onSurfaceChanged(int width, int height) { int rotation = Surface.ROTATION_0; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { rotation = Surface.ROTATION_90; } mSession.setDisplayGeometry(rotation, width, height); }
Example 15
Source File: CameraWrapperTest.java From VideoCamera with Apache License 2.0 | 5 votes |
@Test public void releaseCameraWhenCameraNotNull() { NativeCamera mockCamera = mock(NativeCamera.class); doReturn(mock(Camera.class)).when(mockCamera).getNativeCamera(); final CameraWrapper wrapper = new CameraWrapper(mockCamera, Surface.ROTATION_0); wrapper.releaseCamera(); verify(mockCamera, times(1)).releaseNativeCamera(); }
Example 16
Source File: AndroidSensorJoyInput.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean remapCoordinates(float[] inR, float[] outR) { int xDir = SensorManager.AXIS_X; int yDir = SensorManager.AXIS_Y; int curRotation = getScreenRotation(); if (lastRotation != curRotation) { logger.log(Level.FINE, "Device Rotation changed to: {0}", curRotation); } lastRotation = curRotation; // logger.log(Level.FINE, "Screen Rotation: {0}", getScreenRotation()); switch (getScreenRotation()) { // device natural position case Surface.ROTATION_0: xDir = SensorManager.AXIS_X; yDir = SensorManager.AXIS_Y; break; // device rotated 90 deg counterclockwise case Surface.ROTATION_90: xDir = SensorManager.AXIS_Y; yDir = SensorManager.AXIS_MINUS_X; break; // device rotated 180 deg counterclockwise case Surface.ROTATION_180: xDir = SensorManager.AXIS_MINUS_X; yDir = SensorManager.AXIS_MINUS_Y; break; // device rotated 270 deg counterclockwise case Surface.ROTATION_270: xDir = SensorManager.AXIS_MINUS_Y; yDir = SensorManager.AXIS_X; break; default: break; } return SensorManager.remapCoordinateSystem(inR, xDir, yDir, outR); }
Example 17
Source File: CameraWrapperTest.java From LandscapeVideoCamera with Apache License 2.0 | 5 votes |
@Test public void prepareCameraWhenRuntimeException() { NativeCamera mockCamera = mock(NativeCamera.class); doThrow(new RuntimeException()).when(mockCamera).unlockNativeCamera(); final CameraWrapper wrapper = new CameraWrapper(mockCamera, Surface.ROTATION_0); try { wrapper.prepareCameraForRecording(); fail("Missing exception"); } catch (final PrepareCameraException e) { assertEquals("Unable to use camera for recording", e.getMessage()); } }
Example 18
Source File: CameraView.java From geoar-app with Apache License 2.0 | 4 votes |
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { if (camera == null) return; // �nderung des Surface f�r Kameravorschau ber�cksichtigen // Bilddrehung // Systemdienstinstanz erhalten WindowManager windowManager = (WindowManager) getContext() .getSystemService(Context.WINDOW_SERVICE); // Rotationskonstante Surface.ROTATION_... int rotation = windowManager.getDefaultDisplay().getRotation(); // According to API Documentation // http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation%28int%29 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; } // // Annahme, dass Kamera 90� verdreht zu Standardausrichtung // platziert // // ist. Tats�chlicher Wert erst ab Android 2.3 abrufbar. TODO // int cameraRotation = (90 - degrees + 360) % 360; CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int cameraRotation; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { cameraRotation = (info.orientation + degrees) % 360; cameraRotation = (360 - cameraRotation) % 360; // compensate the // mirror } else { // back-facing cameraRotation = (info.orientation - degrees + 360) % 360; } camera.stopPreview(); // Fix for 2.3.3 Bug? camera.setDisplayOrientation(cameraRotation); // Bildgr��e Camera.Parameters parameters = camera.getParameters(); Size bestSize = getOptimalPreviewSize( parameters.getSupportedPreviewSizes(), cameraSizeHintWidth != 0 ? cameraSizeHintWidth : width, cameraSizeHintHeight != 0 ? cameraSizeHintHeight : height); parameters.setPreviewSize(bestSize.width, bestSize.height); // Update static camera settings fields if (cameraRotation == 0 || cameraRotation == 180) { RealityCamera.setViewportSize(bestSize); RealityCamera.setFovY(parameters.getVerticalViewAngle()); // RealityCamera.setAspect(parameters.getHorizontalViewAngle() // / parameters.getVerticalViewAngle()); // TODO merge updates } else { RealityCamera.setViewportSize(bestSize.height, bestSize.width); RealityCamera.setFovY(parameters.getHorizontalViewAngle()); // RealityCamera.setAspect(parameters.getVerticalViewAngle() // / parameters.getHorizontalViewAngle()); // TODO merge updates } camera.setParameters(parameters); // Neustart der Vorschaudarstellung camera.startPreview(); requestLayout(); }
Example 19
Source File: ControlHelper.java From android_maplibui with GNU Lesser General Public License v3.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.GINGERBREAD) public static void lockScreenOrientation(Activity activity) { WindowManager windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); Configuration configuration = activity.getResources().getConfiguration(); int rotation = windowManager.getDefaultDisplay().getRotation(); // Search for the natural position of the device if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE && ( rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) || configuration.orientation == Configuration.ORIENTATION_PORTRAIT && ( rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270)) { // Natural position is Landscape switch (rotation) { case Surface.ROTATION_0: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; case Surface.ROTATION_90: activity.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); break; case Surface.ROTATION_180: activity.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); break; case Surface.ROTATION_270: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; } } else { // Natural position is Portrait switch (rotation) { case Surface.ROTATION_0: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; case Surface.ROTATION_90: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; case Surface.ROTATION_180: activity.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); break; case Surface.ROTATION_270: activity.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); break; } } }
Example 20
Source File: WhatsappCameraActivity.java From WhatsAppCamera with MIT License | 2 votes |
public void setCameraDisplayOrientation(int cameraId) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (Build.MODEL.equalsIgnoreCase("Nexus 6") && flag == 1) { rotation = Surface.ROTATION_180; } 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; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); }