當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。