android.view.Surface#ROTATION_0 ( )源码实例Demo

下面列出了android.view.Surface#ROTATION_0 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android-chromium   文件: VideoCapture.java
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;
}
 
源代码2 项目: FaceDetectCamera   文件: Util.java
/**
 * 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;
}
 
源代码3 项目: EasyCamera   文件: DefaultEasyCamera.java
@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);
}
 
源代码4 项目: DeviceConnect-Android   文件: Camera2Wrapper.java
/**
 * カメラの取り付けられた向きと画面の向きから縦横のスワップが必要か確認します.
 *
 * @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;
}
 
源代码5 项目: tilt-game-android   文件: OrientationData.java
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;
		}
	}
 
@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();
    }
}
 
源代码7 项目: VideoCRE   文件: Camera2Session.java
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;
}
 
源代码8 项目: grafika   文件: LiveCameraActivity.java
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);
    }
}
 
源代码9 项目: barcodescanner-lib-aar   文件: 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:
        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;
    }
  }
}
 
源代码10 项目: justaline-android   文件: DrawARActivity.java
@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);
}
 
/**
 * 解像度の縦横のサイズをスワップするか判断します.
 *
 * @return スワップする場合は true、それ以外は false
 */
public boolean isSwappedDimensions() {
    switch (getDisplayRotation()) {
        case Surface.ROTATION_0:
        case Surface.ROTATION_180:
            return false;
        default:
            return true;
    }
}
 
源代码12 项目: AndroidRecording   文件: CameraHelper.java
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;
}
 
源代码13 项目: Paddle-Lite-Demo   文件: Utils.java
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;
}
 
源代码14 项目: LandscapeVideoCamera   文件: CameraWrapperTest.java
@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);
}
 
源代码15 项目: VideoCamera   文件: CameraWrapperTest.java
@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();
}
 
源代码16 项目: jmonkeyengine   文件: AndroidSensorJoyInput.java
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);
    }
 
源代码17 项目: LandscapeVideoCamera   文件: CameraWrapperTest.java
@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());
    }
}
 
源代码18 项目: geoar-app   文件: CameraView.java
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();
}
 
源代码19 项目: android_maplibui   文件: 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;
        }
    } 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;
        }
    }
}
 
源代码20 项目: WhatsAppCamera   文件: WhatsappCameraActivity.java
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);

    }