当前位置: 首页>>代码示例>>Java>>正文


Java SensorManager.AXIS_X属性代码示例

本文整理汇总了Java中android.hardware.SensorManager.AXIS_X属性的典型用法代码示例。如果您正苦于以下问题:Java SensorManager.AXIS_X属性的具体用法?Java SensorManager.AXIS_X怎么用?Java SensorManager.AXIS_X使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.hardware.SensorManager的用法示例。


在下文中一共展示了SensorManager.AXIS_X属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: update

protected void update(float[] vectors) {
	int worldAxisX = SensorManager.AXIS_X;
	int worldAxisZ = SensorManager.AXIS_Z;

	float[] rotationMatrix = new float[9];
	float[] adjustedRotationMatrix = new float[9];
	float[] orientation = new float[3];

	SensorManager.getRotationMatrixFromVector(rotationMatrix, vectors);
	SensorManager.remapCoordinateSystem(rotationMatrix, worldAxisX, worldAxisZ, adjustedRotationMatrix);
	SensorManager.getOrientation(adjustedRotationMatrix, orientation);

	float roll = orientation[2] * FROM_RADS_TO_DEGS;

	if (roll > -45 && roll < 45) {
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
		Log.d(LOG_TAG, "Requesting undefined");
	}
	Log.d(LOG_TAG, "Roll: " + roll);
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:20,代码来源:StreamActivity.java

示例2: updateOrientation

@SuppressWarnings("SuspiciousNameCombination")
private void updateOrientation(float[] rotationVector) {
  float[] rotationMatrix = new float[9];
  SensorManager.getRotationMatrixFromVector(rotationMatrix, rotationVector);

  final int worldAxisForDeviceAxisX;
  final int worldAxisForDeviceAxisY;

  // Remap the axes as if the device screen was the instrument panel,
  // and adjust the rotation matrix for the device orientation.
  switch (windowManager.getDefaultDisplay().getRotation()) {
    case Surface.ROTATION_90:
      worldAxisForDeviceAxisX = SensorManager.AXIS_Z;
      worldAxisForDeviceAxisY = SensorManager.AXIS_MINUS_X;
      break;
    case Surface.ROTATION_180:
      worldAxisForDeviceAxisX = SensorManager.AXIS_MINUS_X;
      worldAxisForDeviceAxisY = SensorManager.AXIS_MINUS_Z;
      break;
    case Surface.ROTATION_270:
      worldAxisForDeviceAxisX = SensorManager.AXIS_MINUS_Z;
      worldAxisForDeviceAxisY = SensorManager.AXIS_X;
      break;
    case Surface.ROTATION_0:
    default:
      worldAxisForDeviceAxisX = SensorManager.AXIS_X;
      worldAxisForDeviceAxisY = SensorManager.AXIS_Z;
      break;
  }

  float[] adjustedRotationMatrix = new float[9];
  SensorManager.remapCoordinateSystem(rotationMatrix, worldAxisForDeviceAxisX,
    worldAxisForDeviceAxisY, adjustedRotationMatrix);

  // Transform rotation matrix into azimuth/pitch/roll
  float[] orientation = new float[3];
  SensorManager.getOrientation(adjustedRotationMatrix, orientation);

  // The x-axis is all we care about here.
  internalCompassListener.onCompassChanged((float) Math.toDegrees(orientation[0]));
  for (CompassListener compassListener : compassListeners) {
    compassListener.onCompassChanged((float) Math.toDegrees(orientation[0]));
  }
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:44,代码来源:CompassManager.java


注:本文中的android.hardware.SensorManager.AXIS_X属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。