List of usage examples for android.view Surface ROTATION_270
int ROTATION_270
To view the source code for android.view Surface ROTATION_270.
Click Source Link
From source file:nz.ac.auckland.lablet.ExperimentRunViewManager.java
/** * Lock the screen to the current orientation. * @return the previous orientation settings *//*from w w w . j a va 2 s. co m*/ private int lockScreenOrientation() { int initialRequestedOrientation = getRequestedOrientation(); // Note: a surface rotation of 90 degrees means a physical device rotation of -90 degrees. int orientation = getResources().getConfiguration().orientation; int rotation = getWindowManager().getDefaultDisplay().getRotation(); switch (rotation) { case Surface.ROTATION_0: if (orientation == Configuration.ORIENTATION_PORTRAIT) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); else if (orientation == Configuration.ORIENTATION_LANDSCAPE) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; case Surface.ROTATION_90: if (orientation == Configuration.ORIENTATION_PORTRAIT) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); else if (orientation == Configuration.ORIENTATION_LANDSCAPE) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; case Surface.ROTATION_180: if (orientation == Configuration.ORIENTATION_PORTRAIT) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); else if (orientation == Configuration.ORIENTATION_LANDSCAPE) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); break; case Surface.ROTATION_270: if (orientation == Configuration.ORIENTATION_PORTRAIT) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); else if (orientation == Configuration.ORIENTATION_LANDSCAPE) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); break; } return initialRequestedOrientation; }
From source file:com.example.camera2apidemo.Camera2BasicFragment.java
/** , ? * ??:/*from www . j a va2 s. com*/ * 1. ???, ? * 2. ????, ??? * 3. ??, ? * Sets up member variables related to camera. * * @param width The width of available size for camera preview * @param height The height of available size for camera preview */ private void setUpCameraOutputs(int width, int height) { Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { // ???? for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); checkCamera2Support(characteristics); // ???, ?(???) // We don't use a front facing camera in this sample. Integer facing = characteristics.get(LENS_FACING); if (facing != null && facing == LENS_FACING_FRONT) { continue; } // ?? StreamConfigurationMap map = characteristics.get(SCALER_STREAM_CONFIGURATION_MAP); if (map == null) { continue; } // For still image captures, we use the largest available size. // // maxImagesImageReader?? Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // Find out if we need to swap dimension to get the preview size relative to sensor // coordinate. // ???(??, ""???ROTATION_90 // ROTATION_270,?ROTATION_0ROTATION_180) int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); //noinspection ConstantConditions // ??(""?0, , ?90) // ?, ??, , 90, switch?? mSensorOrientation = characteristics.get(SENSOR_ORIENTATION); boolean swappedDimensions = false; switch (displayRotation) { // ROTATION_0ROTATION_180?????? // ?, ?90270, ??(?true) case Surface.ROTATION_0: case Surface.ROTATION_180: if (mSensorOrientation == 90 || mSensorOrientation == 270) { swappedDimensions = true; } break; case Surface.ROTATION_90: case Surface.ROTATION_270: if (mSensorOrientation == 0 || mSensorOrientation == 180) { swappedDimensions = true; } break; default: Log.e(TAG, "Display rotation is invalid: " + displayRotation); } // ???, Point displaySize = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(displaySize); // ?(), ?? int rotatedPreviewWidth = width; int rotatedPreviewHeight = height; // ?(, ?(texture????)) int maxPreviewWidth = displaySize.x; int maxPreviewHeight = displaySize.y; // ??, if (swappedDimensions) { rotatedPreviewWidth = height; rotatedPreviewHeight = width; maxPreviewWidth = displaySize.y; maxPreviewHeight = displaySize.x; } // ?? if (maxPreviewWidth > MAX_PREVIEW_WIDTH) { maxPreviewWidth = MAX_PREVIEW_WIDTH; } if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) { maxPreviewHeight = MAX_PREVIEW_HEIGHT; } // Danger, W.R.! Attempting to use too large a preview size could exceed the camera // bus' bandwidth limitation, resulting in gorgeous previews but the storage of // garbage capture data. // ? // ?:map.getOutputSizes(SurfaceTexture.class)SurfaceTexture?List mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest); // We fit the aspect ratio of TextureView to the size of preview we picked. // ???? int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { // ??(landscape) mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); } else { mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); } // Check if the flash is supported. Boolean available = characteristics.get(FLASH_INFO_AVAILABLE); mFlashSupported = available == null ? false : available; mCameraId = cameraId; return; } } catch (CameraAccessException e) { e.printStackTrace(); } catch (NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(), FRAGMENT_DIALOG); } }
From source file:com.almalence.util.Util.java
public static boolean shouldRemapOrientation(final int orientationProc, final int rotation) { return (orientationProc == Configuration.ORIENTATION_LANDSCAPE && rotation == Surface.ROTATION_0) || (orientationProc == Configuration.ORIENTATION_LANDSCAPE && rotation == Surface.ROTATION_180) || (orientationProc == Configuration.ORIENTATION_PORTRAIT && rotation == Surface.ROTATION_90) || (orientationProc == Configuration.ORIENTATION_PORTRAIT && rotation == Surface.ROTATION_270); }
From source file:nautilus.writingpane.CameraActivity.java
/** * 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` *///from w w w .j ava2 s. c o m private void configureTransform(int viewWidth, int viewHeight) { if (null == mTextureView || null == mPreviewSize) { return; } int rotation = 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); }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopDetailsFragment.java
/** * Update the direction needle so that it is pointing towards the bus stop, * based on the device location and the direction it is facing. *///from w w w . ja va 2 s .c o m private void updateDirectionNeedle() { // We need values for location, the accelerometer and magnetometer to // continue. if (lastLocation == null || accelerometerValues == null || magnetometerValues == null) { // Make sure the needle isn't showing. txtDistance.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); recycleNeedleBitmapIfNotNull(null); return; } // Calculating the rotation matrix may fail, for example, if the device // is in freefall. In that case we cannot continue as the values will // be unreliable. if (!SensorManager.getRotationMatrix(rotationMatrix, null, accelerometerValues, magnetometerValues)) { return; } // The screen rotation was obtained earlier. switch (screenRotation) { // There's lots of information about this elsewhere, but briefly; // The values from the sensors are in the device's coordinate system // which may be correct if the device is in its natural orientation, // but it needs to be remapped if the device is rotated. case Surface.ROTATION_0: SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, rotationMatrix); break; case Surface.ROTATION_90: SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_Z, SensorManager.AXIS_MINUS_X, rotationMatrix); break; case Surface.ROTATION_180: SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_MINUS_X, SensorManager.AXIS_MINUS_Z, rotationMatrix); break; case Surface.ROTATION_270: SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_MINUS_Z, SensorManager.AXIS_X, rotationMatrix); break; } // Get the X, Y and Z orientations, which are in radians. Covert this // in to degrees East of North. SensorManager.getOrientation(rotationMatrix, headings); double heading = Math.toDegrees(headings[0]); // If there's a GeomagneticField value, then adjust the heading to take // this in to account. if (geoField != null) { heading -= geoField.getDeclination(); } // The orientation is in the range of -180 to +180. Convert this in to // a range of 0 to 360. final float bearingTo = distance[1] < 0 ? distance[1] + 360 : distance[1]; // This is the heading to the bus stop. heading = bearingTo - heading; // The above calculation may come out as a negative number again. Put // this back in to the range of 0 to 360. if (heading < 0) { heading += 360; } // This 'if' statement is required to prevent a crash during device // rotation. It ensured that the Fragment is still part of the Activity. if (isAdded()) { // Get the arrow bitmap from the resources. final Bitmap needleIn = BitmapFactory.decodeResource(getResources(), R.drawable.heading_arrow); // Get an identity matrix and rotate it by the required amount. final Matrix m = new Matrix(); m.setRotate((float) heading % 360, (float) needleIn.getWidth() / 2, (float) needleIn.getHeight() / 2); // Apply the rotation matrix to the Bitmap, to create a new Bitmap. final Bitmap needleOut = Bitmap.createBitmap(needleIn, 0, 0, needleIn.getWidth(), needleIn.getHeight(), m, true); // Recycle the needle read in if it's not the same as the rotated // needle. if (needleIn != needleOut) { needleIn.recycle(); } // This Bitmap needs to be converted to a Drawable type. final BitmapDrawable drawable = new BitmapDrawable(getResources(), needleOut); // Set the new needle to be on the right hand side of the TextView. txtDistance.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null); recycleNeedleBitmapIfNotNull(needleOut); } else { // If the Fragment is not added to the Activity, then make sure // there's no needle. txtDistance.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); recycleNeedleBitmapIfNotNull(null); } }
From source file:io.digibyte.presenter.activities.camera.CameraActivity.java
/** * 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` *///w ww .j a v a 2s. c o m private void configureTransform(int viewWidth, int viewHeight) { Activity activity = CameraActivity.this; if (null == mTextureView || null == mPreviewSize) { 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); }
From source file:camera2basic.Camera2BasicFragment.java
/** * 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` *//*from w w w . j a va 2 s . c om*/ 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); }
From source file:com.example.joshf.conc.CameraFragment.java
/** * 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` *//*from w w w .ja v a 2s . c om*/ 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) { Log.e("rotate", "90"); 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), centerX, centerY); } else if (Surface.ROTATION_180 == rotation) { Log.e("rotate", "180"); matrix.postRotate(180, centerX, centerY); } mTextureView.setTransform(matrix); }
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
public void onRotate() { Display display = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int rotation = display.getRotation(); if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) { orient = "portrait"; } else if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) { orient = "landscape"; }// w w w. j a v a 2 s . c o m if (orient.equals("portrait")) { if (lang.equals("prilang")) { keyboard = prilang; } else if (lang.equals("seclang")) { keyboard = seclang; } slideAnimation(); kv.setKeyboard(keyboard); doubleUp = 1; screen = 1; caps = true; if (allCaps) { capsLock = false; } kv.invalidateAllKeys(); keyboard.setShifted(caps); kv.invalidateAllKeys(); } else if (orient.equals("landscape")) { switch (screen) { case 1: if (lang.equals("prilang")) { keyboard = prilang_landscape; } else if (lang.equals("seclang")) { keyboard = seclang_landscape; } break; case 2: if (number == 1) { keyboard = new Keyboard(this, R.xml.numeric_landscape); } else if (number == 2) { keyboard = new Keyboard(this, R.xml.symbols_landscape); } break; } slideAnimation(); kv.setKeyboard(keyboard); doubleUp = 1; screen = 1; caps = true; if (allCaps) { capsLock = false; } kv.invalidateAllKeys(); keyboard.setShifted(caps); kv.invalidateAllKeys(); } }
From source file:net.ddns.mlsoftlaberge.trycorder.TryviscamFragment.java
/** * Sets up member variables related to camera. * * @param width The width of available size for camera preview * @param height The height of available size for camera preview *//*from w w w. j a v a 2 s . c o m*/ private void setUpCameraOutputs(int width, int height) { Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING); if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) { continue; } StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (map == null) { continue; } // For still image captures, we use the largest available size. Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // Find out if we need to swap dimension to get the preview size relative to sensor // coordinate. int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); //noinspection ConstantConditions mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); boolean swappedDimensions = false; switch (displayRotation) { case Surface.ROTATION_0: case Surface.ROTATION_180: if (mSensorOrientation == 90 || mSensorOrientation == 270) { swappedDimensions = true; } break; case Surface.ROTATION_90: case Surface.ROTATION_270: if (mSensorOrientation == 0 || mSensorOrientation == 180) { swappedDimensions = true; } break; default: Log.e(TAG, "Display rotation is invalid: " + displayRotation); } Point displaySize = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(displaySize); int rotatedPreviewWidth = width; int rotatedPreviewHeight = height; int maxPreviewWidth = displaySize.x; int maxPreviewHeight = displaySize.y; if (swappedDimensions) { rotatedPreviewWidth = height; rotatedPreviewHeight = width; maxPreviewWidth = displaySize.y; maxPreviewHeight = displaySize.x; } if (maxPreviewWidth > MAX_PREVIEW_WIDTH) { maxPreviewWidth = MAX_PREVIEW_WIDTH; } if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) { maxPreviewHeight = MAX_PREVIEW_HEIGHT; } // Danger, W.R.! Attempting to use too large a preview size could exceed the camera // bus' bandwidth limitation, resulting in gorgeous previews but the storage of // garbage capture data. mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest); // We fit the aspect ratio of TextureView to the size of preview we picked. int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); } else { mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); } // Check if the flash is supported. Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); mFlashSupported = available == null ? false : available; mCameraId = cameraId; return; } } catch (CameraAccessException e) { e.printStackTrace(); } catch (NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. //ErrorDialog.newInstance(getString(R.string.camera_error)) // .show(getChildFragmentManager(), FRAGMENT_DIALOG); e.printStackTrace(); } }