本文整理匯總了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]));
}
}