本文整理匯總了Java中android.hardware.Sensor.TYPE_GRAVITY屬性的典型用法代碼示例。如果您正苦於以下問題:Java Sensor.TYPE_GRAVITY屬性的具體用法?Java Sensor.TYPE_GRAVITY怎麽用?Java Sensor.TYPE_GRAVITY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.hardware.Sensor
的用法示例。
在下文中一共展示了Sensor.TYPE_GRAVITY屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
// we received a sensor event. it is a good practice to check
// that we received the proper event
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
System.arraycopy(event.values, 0, magnitudeValues, 0, magnitudeValues.length);
} else if (event.sensor.getType() == Sensor.TYPE_GRAVITY) {
System.arraycopy(event.values, 0, gravityValues, 0, gravityValues.length);
}
if (magnitudeValues != null && gravityValues != null) {
// Fuse gravity-sensor (virtual sensor) with compass
SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, inclinationValues, gravityValues, magnitudeValues);
// Transform rotation matrix to quaternion
currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix);
}
}
示例2: processSensorsData
protected void processSensorsData(SensorData data) {
switch (data.type) {
case Sensor.TYPE_ACCELEROMETER:
accelerometerNewData = true;
break;
case Sensor.TYPE_GRAVITY:
gravityNewData = true;
break;
case Sensor.TYPE_LINEAR_ACCELERATION:
linearAccelerationNewData = true;
break;
}
boolean isTmp = isNewDataAvailable();
if (dataRecordChangedListeners != null) {
for (DataRecordChangedListener l : dataRecordChangedListeners) {
if (l != null) {
l.onAccelerometerChangedListener(data, sensorGravity.getLastAccelerometerDataEntry());
}
}
}
writeData(isTmp);
}
示例3: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
break;
case Sensor.TYPE_GRAVITY:
vGravity = event.values.clone();
mPhy = (float) Math.atan(Math.abs(vGravity[2]/vGravity[1]));
break;
case Sensor.TYPE_LINEAR_ACCELERATION:
vLinAcceleration = event.values.clone();
detectStep(vLinAcceleration, mPhy);
break;
default:
break;
}
}
示例4: isXYZ
private boolean isXYZ(Sensor s) {
switch (s.getType()) {
case Sensor.TYPE_ACCELEROMETER:
case Sensor.TYPE_GRAVITY:
case Sensor.TYPE_GYROSCOPE:
case Sensor.TYPE_LINEAR_ACCELERATION:
case Sensor.TYPE_MAGNETIC_FIELD:
case Sensor.TYPE_ROTATION_VECTOR:
return true;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
if (s.getType() == Sensor.TYPE_GAME_ROTATION_VECTOR
|| s.getType() == Sensor.TYPE_GYROSCOPE_UNCALIBRATED
|| s.getType() == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
return true;
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (s.getType() == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR) {
return true;
}
}
return false;
}
示例5: isRestricted
@SuppressWarnings("deprecation")
private boolean isRestricted(XParam param, int type) throws Throwable {
if (type == Sensor.TYPE_ALL)
return false;
else if (type == Sensor.TYPE_ACCELEROMETER || type == Sensor.TYPE_LINEAR_ACCELERATION) {
if (isRestricted(param, "acceleration"))
return true;
} else if (type == Sensor.TYPE_GRAVITY) {
if (isRestricted(param, "gravity"))
return true;
} else if (type == Sensor.TYPE_RELATIVE_HUMIDITY) {
if (isRestricted(param, "humidity"))
return true;
} else if (type == Sensor.TYPE_LIGHT) {
if (isRestricted(param, "light"))
return true;
} else if (type == Sensor.TYPE_MAGNETIC_FIELD || type == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
if (isRestricted(param, "magnetic"))
return true;
} else if (type == Sensor.TYPE_SIGNIFICANT_MOTION) {
if (isRestricted(param, "motion"))
return true;
} else if (type == Sensor.TYPE_ORIENTATION || type == Sensor.TYPE_GYROSCOPE
|| type == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) {
if (isRestricted(param, "orientation"))
return true;
} else if (type == Sensor.TYPE_PRESSURE) {
if (isRestricted(param, "pressure"))
return true;
} else if (type == Sensor.TYPE_PROXIMITY) {
if (isRestricted(param, "proximity"))
return true;
} else if (type == Sensor.TYPE_GAME_ROTATION_VECTOR || type == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR
|| type == Sensor.TYPE_ROTATION_VECTOR) {
if (isRestricted(param, "rotation"))
return true;
} else if (type == Sensor.TYPE_TEMPERATURE || type == Sensor.TYPE_AMBIENT_TEMPERATURE) {
if (isRestricted(param, "temperature"))
return true;
} else if (type == Sensor.TYPE_STEP_COUNTER || type == Sensor.TYPE_STEP_DETECTOR) {
if (isRestricted(param, "step"))
return true;
} else if (type == Sensor.TYPE_HEART_RATE) {
if (isRestricted(param, "heartrate"))
return true;
} else if (type == 22) {
// 22 = TYPE_TILT_DETECTOR
// Do nothing
} else if (type == 23 || type == 24 || type == 25) {
// 23 = TYPE_WAKE_GESTURE
// 24 = TYPE_GLANCE_GESTURE
// 25 = TYPE_PICK_UP_GESTURE
// 23/24 This sensor is expected to only be used by the system ui
// 25 Expected to be used internally for always on display
} else
Util.log(this, Log.WARN, "Unknown sensor type=" + type);
return false;
}
示例6: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
testLastAccelerometerDataEntry.setAccelerometerX(event.values[DATA_X]);
testLastAccelerometerDataEntry.setAccelerometerY(event.values[DATA_Y]);
testLastAccelerometerDataEntry.setAccelerometerZ(event.values[DATA_Z]);
if (!gravityAvailable || !linearAccelerationAvailable) {
calcSoftwareGravityVector(event);
calcRotationAngle();
float[] gravityVector = new float[] {
testLastAccelerometerDataEntry.getAccelerometerGravityX(),
testLastAccelerometerDataEntry.getAccelerometerGravityY(),
testLastAccelerometerDataEntry.getAccelerometerGravityZ() };
deviceStateDetector.calcState(gravityVector);
processLinearAcceleration();
}
break;
case Sensor.TYPE_LINEAR_ACCELERATION:
testLastAccelerometerDataEntry.setAccelerometerLinearX(event.values[DATA_X]);
testLastAccelerometerDataEntry.setAccelerometerLinearY(event.values[DATA_Y]);
testLastAccelerometerDataEntry.setAccelerometerLinearZ(event.values[DATA_Z]);
processLinearAcceleration();
break;
case Sensor.TYPE_GRAVITY:
testLastAccelerometerDataEntry.setAccelerometerGravityX(event.values[DATA_X]);
testLastAccelerometerDataEntry.setAccelerometerGravityY(event.values[DATA_Y]);
testLastAccelerometerDataEntry.setAccelerometerGravityZ(event.values[DATA_Z]);
deviceStateDetector.calcState(event.values);
calcRotationAngle();
break;
}
if (sensorListener != null) {
SensorData data = new SensorData(event.sensor.getType(), event.values);
sensorListener.onSensorChanged(data);
}
}
示例7: calcSoftwareGravityVector
private void calcSoftwareGravityVector(SensorEvent event) {
softGravitySensor.setValues(event.values);
float[] gravityValues = softGravitySensor.calculate();
testLastAccelerometerDataEntry.setAccelerometerGravityX(gravityValues[DATA_X]);
testLastAccelerometerDataEntry.setAccelerometerGravityY(gravityValues[DATA_Y]);
testLastAccelerometerDataEntry.setAccelerometerGravityZ(gravityValues[DATA_Z]);
if (sensorListener != null) {
SensorData data = new SensorData(Sensor.TYPE_GRAVITY, gravityValues);
sensorListener.onSensorChanged(data);
}
if (!linearAccelerationAvailable) {
float[] linearAccelerationValues = softGravitySensor.getLinearAcceleration();
calcSoftwareLinearAccelerationVector(linearAccelerationValues);
}
}
示例8: GravityUpdatesProvider
GravityUpdatesProvider(int sensorDelay) {
super(Sensor.TYPE_GRAVITY, sensorDelay);
}