Example usage for android.view Surface ROTATION_0

List of usage examples for android.view Surface ROTATION_0

Introduction

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

Prototype

int ROTATION_0

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

Click Source Link

Document

Rotation constant: 0 degree rotation (natural orientation)

Usage

From source file:com.jasompeter.openalpr.CameraActivity.java

public void setCorrectOrientation(Camera camera) {
    int displayRotation = getWindowManager().getDefaultDisplay().getRotation();

    int degrees = 0;
    switch (displayRotation) {
    case Surface.ROTATION_0:
        degrees = 0;//from  w w  w . j  ava2 s.  co m
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break;
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    Camera.CameraInfo cameraInfo = getCurrentCameraInfo();
    int resultDegrees;
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        resultDegrees = (cameraInfo.orientation + degrees) % 360;
        resultDegrees = (360 - resultDegrees) % 360;
    } else {
        resultDegrees = (cameraInfo.orientation - degrees + 360) % 360;
    }

    camera.setDisplayOrientation(resultDegrees);

    Camera.Parameters parameters = camera.getParameters();
    parameters.setRotation(resultDegrees);
    camera.setParameters(parameters);
}

From source file:com.almalence.util.Util.java

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;
    default:/*from w ww .  j  a v a  2  s  . c o m*/
        break;
    }
    return 0;
}

From source file:com.nextgis.maplibui.util.ControlHelper.java

@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;
        }//from  w ww. ja va2 s  .  c o m
    } 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;
        }
    }
}

From source file:com.example.android.animationsdemo.CameraActivity.java

/**
 * Convert touch position x:y to {@link android.hardware.Camera.Area} position -1000:-1000 to 1000:1000.
 *//*from w  w  w. jav a 2s  .  c om*/
private Rect calculateTapArea(float x, float y) {

    // define focus area (36dp)
    Display display = ((WindowManager) getSystemService(Activity.WINDOW_SERVICE)).getDefaultDisplay();
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    int areaSize = Float.valueOf(36 * metrics.density).intValue();
    DKLog.d(TAG, String.format("x=%f, y=%f, areaSize=%d", x, y, areaSize));

    int width = mPreview.getWidth();
    int height = mPreview.getHeight();

    // Convert touch area to new area -1000:-1000 to 1000:1000.
    float left = ((x - areaSize) / width) * 2000 - 1000;
    float top = ((y - areaSize) / height) * 2000 - 1000;
    float right = ((x + areaSize) / width) * 2000 - 1000;
    float bottom = ((y + areaSize) / height) * 2000 - 1000;

    // adjust boundary
    if (left < -1000) {
        right += ((-1000) - left);
        left = (-1000);
    }
    if (top < -1000) {
        bottom += ((-1000) - top);
        top = (-1000);
    }
    if (right > 1000) {
        left -= (right - 1000);
        right = 1000;
    }
    if (bottom > 1000) {
        top -= (bottom - 1000);
        bottom = 1000;
    }

    // rotate matrix if portrait
    RectF rectF = new RectF(left, top, right, bottom);
    Matrix matrix = new Matrix();
    int degree = (display.getRotation() == Surface.ROTATION_0) ? (-90) : (0);
    matrix.setRotate(degree);
    matrix.mapRect(rectF);
    return new Rect(Math.round(rectF.left), Math.round(rectF.top), Math.round(rectF.right),
            Math.round(rectF.bottom));
}

From source file:com.coact.kochzap.CaptureActivity.java

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://from  ww  w . j  a va 2s. com
            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;
        }
    }
}

From source file:com.metinkale.prayerapp.compass.Main.java

@Override
public void onRotationUpdate(float[] newMatrix) {
    if (mMode == Mode.Map) {
        return;//w w w.j ava2  s . com
    }
    // remap matrix values according to display rotation, as in
    // SensorManager documentation.
    switch (mDisplayRotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180:
        break;
    case Surface.ROTATION_90:
        SensorManager.remapCoordinateSystem(newMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X,
                newMatrix);
        break;
    case Surface.ROTATION_270:
        SensorManager.remapCoordinateSystem(newMatrix, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X,
                newMatrix);
        break;
    default:
        break;
    }
    mRotationMatrix.set(newMatrix);
    mOrientationCalculator.getOrientation(mRotationMatrix, mDisplayRotation, mDerivedDeviceOrientation);

    updateFrag((mDerivedDeviceOrientation[1] > -55f) ? Mode.ThreeDim : Mode.TwoDim);

    mList.onUpdateSensors(mDerivedDeviceOrientation);
}

From source file:com.tritop.androsense2.fragments.GpsFragment.java

@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        mAccel = event.values;/*  w  ww  . jav a  2  s  . c om*/
    }
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        mMag = event.values;
    }
    if ((mAccel != null) && (mMag != null)) {
        float R[] = new float[9];
        float I[] = new float[9];
        float Rot[] = new float[9];
        if (SensorManager.getRotationMatrix(R, I, mAccel, mMag)) {
            float orientation[] = new float[3];
            int axisX = 0, axisY = 0;
            switch (display.getRotation()) {
            case Surface.ROTATION_0:
                axisX = SensorManager.AXIS_X;
                axisY = SensorManager.AXIS_Y;
                break;
            case Surface.ROTATION_90:
                axisX = SensorManager.AXIS_Y;
                axisY = SensorManager.AXIS_MINUS_X;
                break;
            case Surface.ROTATION_180:
                axisX = SensorManager.AXIS_MINUS_X;
                axisY = SensorManager.AXIS_MINUS_Y;
                break;
            case Surface.ROTATION_270:
                axisX = SensorManager.AXIS_MINUS_Y;
                axisY = SensorManager.AXIS_X;
                break;
            default:
                break;
            }

            SensorManager.remapCoordinateSystem(R, axisX, axisY, Rot);
            SensorManager.getOrientation(Rot, orientation);
            aRotation = orientation[0];
            aRotation = (int) Math.toDegrees(aRotation);
            satView.setAzimutRotation(-aRotation);
            satView.invalidate();
        }
    }
}

From source file:com.cleverzone.zhizhi.capture.CaptureActivity.java

private int getCurrentOrientation() {
    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_90:
        return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    default://w  w w.  j  ava2  s  . c  o m
        return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
    }
}

From source file:com.google.android.testing.nativedriver.server.AndroidNativeDriver.java

@Override
public ScreenOrientation getOrientation() {
    int orientation = context.getOnMainSyncRunner().run(doGetOrientation());

    if ((orientation == Surface.ROTATION_0) || (orientation == Surface.ROTATION_180)) {
        return ScreenOrientation.PORTRAIT;
    } else { // Surface.ROTATION_90 or Surface.ROTATION_270
        return ScreenOrientation.LANDSCAPE;
    }/*  ww w  .ja  v a  2 s.c  o m*/
}

From source file:net.oschina.app.v2.activity.zxing.CaptureActivity.java

@Deprecated
private int getCurrentOrientation() {
    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_90:
        return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    default://from w w  w  . j  av  a  2  s. c o  m
        return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
    }
}