Example usage for android.view Surface ROTATION_90

List of usage examples for android.view Surface ROTATION_90

Introduction

In this page you can find the example usage for android.view Surface ROTATION_90.

Prototype

int ROTATION_90

To view the source code for android.view Surface ROTATION_90.

Click Source Link

Document

Rotation constant: 90 degree rotation.

Usage

From source file:com.example.android.tflitecamerademo.Camera2BasicFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `textureView`. This
 * method should be called after the camera preview size is determined in setUpCameraOutputs and
 * also the size of `textureView` is fixed.
 *
 * @param viewWidth The width of `textureView`
 * @param viewHeight The height of `textureView`
 *///from  w  ww  .j  ava 2s  .  c o  m
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == textureView || null == previewSize || 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, previewSize.getHeight(), previewSize.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 / 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);
}

From source file:com.askjeffreyliu.camera2barcode.camera.CameraSource.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
 *//*  w  ww  .ja  va 2s  .c o m*/
private void setUpCameraOutputs(int width, int height) {
    try {
        if (ContextCompat.checkSelfPermission(mContext,
                Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
            throw new RuntimeException("Time out waiting to lock camera opening.");
        }
        if (manager == null)
            manager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
        mCameraId = manager.getCameraIdList()[mFacing];
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);
        StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        if (map == null) {
            return;
        }

        // For still image captures, we use the largest available size.
        Size largest = getBestAspectPictureSize(map.getOutputSizes(ImageFormat.JPEG));

        // Find out if we need to swap dimension to get the preview size relative to sensor
        // coordinate.
        int displayRotation = mDisplayOrientation;
        //noinspection ConstantConditions
        int 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(Utils.getScreenWidth(mContext), Utils.getScreenHeight(mContext));
        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.
        Size[] outputSizes = Utils.sizeToSize(map.getOutputSizes(SurfaceTexture.class));
        mPreviewSize = chooseOptimalSize(outputSizes, rotatedPreviewWidth, rotatedPreviewHeight,
                maxPreviewWidth, maxPreviewHeight, largest);

        // We fit the aspect ratio of TextureView to the size of preview we picked.
        int orientation = mDisplayOrientation;
        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;

        // control.aeTargetFpsRange
        Range<Integer>[] availableFpsRange = characteristics
                .get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);

        configureTransform(width, height);

        manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
    } catch (NullPointerException e) {
        // Currently an NPE is thrown when the Camera2API is used but not supported on the
        // device this code runs.
        Log.d(TAG, "Camera Error: " + e.getMessage());
    }
}

From source file:org.tensorflow.demo.Camera2BasicFragment.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 .  co 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.YUV_420_888)),
                    new CompareSizesByArea());
            mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(),
                    ImageFormat.YUV_420_888, 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());
            }

            previewWidth = mPreviewSize.getWidth();
            previewHeight = mPreviewSize.getHeight();
            rgbBytes = new int[previewWidth * previewHeight];
            rgbFrameBitmap = Bitmap.createBitmap(previewWidth, previewHeight, Bitmap.Config.ARGB_8888);
            croppedBitmap = Bitmap.createBitmap(INPUT_SIZE, INPUT_SIZE, Bitmap.Config.ARGB_8888);

            // Check if the flash is supported.
            Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
            mFlashSupported = false; //= 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.yahala.ui.LaunchActivity.java

private void fixLayout() {
    if (containerView != null) {
        ViewTreeObserver obs = containerView.getViewTreeObserver();
        obs.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override/*from  ww  w.  j a  va 2  s  .c om*/
            public void onGlobalLayout() {
                WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
                int rotation = manager.getDefaultDisplay().getRotation();

                int height;
                int currentActionBarHeight = getSupportActionBar().getHeight();
                if (currentActionBarHeight != OSUtilities.dp(48)
                        && currentActionBarHeight != OSUtilities.dp(40)) {
                    height = currentActionBarHeight;
                } else {
                    height = OSUtilities.dp(48);
                    if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
                        height = OSUtilities.dp(40);
                    }
                }

                if (notificationView != null) {
                    notificationView.applyOrientationPaddings(
                            rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90, height);
                }

                if (Build.VERSION.SDK_INT < 16) {
                    containerView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    containerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
            }
        });
    }
}

From source file:nz.ac.auckland.lablet.ExperimentRunViewManager.java

/**
 * Lock the screen to the current orientation.
 * @return the previous orientation settings
 */// ww  w  . j  a  v  a 2 s. com
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

/**   , ?
 * ??://  w  ww  .  j  a  v a  2s .c  om
 * 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: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  www.  jav  a  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: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  www  . ja  v a  2s.  com
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: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  w w. ja  va2 s.  c  om*/
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);
}