本文整理汇总了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);
}
示例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]));
}
}