本文整理汇总了Java中android.hardware.Sensor.TYPE_ACCELEROMETER属性的典型用法代码示例。如果您正苦于以下问题:Java Sensor.TYPE_ACCELEROMETER属性的具体用法?Java Sensor.TYPE_ACCELEROMETER怎么用?Java Sensor.TYPE_ACCELEROMETER使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.hardware.Sensor
的用法示例。
在下文中一共展示了Sensor.TYPE_ACCELEROMETER属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
switch (event.sensor.getType()) {
case Sensor.TYPE_ROTATION_VECTOR:
System.arraycopy(event.values, 0, mRotation, 0, 3);
calculateOrientation();
break;
case Sensor.TYPE_ACCELEROMETER:
mAccel = LowPassFilter.lowPass(event.values.clone(), mAccel);
calculateOrientation();
break;
case Sensor.TYPE_MAGNETIC_FIELD:
mMagnet = LowPassFilter.lowPass(event.values.clone(), mMagnet);
break;
case Sensor.TYPE_STEP_DETECTOR:
mStep = event.values[0] == 1.0;
announceChange(STEP_UPDATE);
break;
}
}
示例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) {
synchronized (this) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
lowPass(event.values, mGravity);
}
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
lowPass(event.values, mGeomagnetic);
}
float R[] = new float[9];
float I[] = new float[9];
if (SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic)) {
float orientation[] = new float[3];
SensorManager.getOrientation(R, orientation);
mOrientation[0] = (float)Math.toDegrees(orientation[0]);
adjustArrow();
}
}
}
示例4: 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_ACCELEROMETER) {
System.arraycopy(event.values, 0, accelerometerValues, 0, accelerometerValues.length);
}
if (magnitudeValues != null && accelerometerValues != null) {
// Fuse accelerometer with compass
SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, inclinationValues, accelerometerValues,
magnitudeValues);
// Transform rotation matrix to quaternion
currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix);
}
}
示例5: parse
@Override
public double[] parse(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
accValues = new float[3];
fixOrientation(event.values, accValues);
accFilt.add(accValues);
}
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
magValues = new float[3];
fixOrientation(event.values, magValues);
magFilt.add(magValues);
}
if (magValues != null && accValues != null) {
float[] rotationMatrix = new float[9];
if (SensorManager.getRotationMatrix(rotationMatrix, null, accFilt.getAverage(), magFilt.getAverage())) {
degHolder = parseRoatationMatrix(rotationMatrix);
}
}
return degHolder;
}
示例6: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
// do something about values of accelerometer
// 深度复制,可避免部分设备下 SensorManager.getRotationMatrix 返回false的问题
for (int i = 0; i < 3; i++) {
accValues[i] = event.values[i];
}
break;
case Sensor.TYPE_MAGNETIC_FIELD:
// do something about values of magnetic field
for (int i = 0; i < 3; i++) {
magValues[i] = event.values[i];
}
break;
default:
break;
}
calculateOrientation(accValues, magValues);
// 摇一摇功能
float x = accValues[0];
float y = accValues[1];
float z = accValues[2];
int medumValue = 18;
if (Math.abs(x) > medumValue || Math.abs(y) > medumValue || Math.abs(z) > medumValue) {
// 检测摇动的频率,防止摇动过快
// 检测是否快速点击间隔<3000
if ((System.currentTimeMillis() - exitTime) < 2000) {
return;
} else {
exitTime = System.currentTimeMillis();
Toast.makeText(CalendarActivity.this, "正常模式",
Toast.LENGTH_SHORT).show();
finish();
}
}
}
示例7: onSensorChanged
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
stepDetector.updateModel(isActivity);
stepDetector.updateStep(sensorEvent.values[0], sensorEvent.values[1], sensorEvent.values[2]);
}
}
示例8: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
simpleStepDetector.updateAccel(
event.timestamp, event.values[0], event.values[1], event.values[2]);
}
}
示例9: onSensorChanged
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
synchronized (this) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
if (sensorEvent.values[0] < 4 && sensorEvent.values[0] > -4) {
if (sensorEvent.values[1] > 0) {
// UP
configurationProvider.setSensorPosition(Configuration.SENSOR_POSITION_UP);
configurationProvider.setDegrees(configurationProvider.getDeviceDefaultOrientation() == Configuration.ORIENTATION_PORTRAIT ? 0 : 90);
} else if (sensorEvent.values[1] < 0) {
// UP SIDE DOWN
configurationProvider.setSensorPosition(Configuration.SENSOR_POSITION_UP_SIDE_DOWN);
configurationProvider.setDegrees(configurationProvider.getDeviceDefaultOrientation() == Configuration.ORIENTATION_PORTRAIT ? 180 : 270);
}
} else if (sensorEvent.values[1] < 4 && sensorEvent.values[1] > -4) {
if (sensorEvent.values[0] > 0) {
// LEFT
configurationProvider.setSensorPosition(Configuration.SENSOR_POSITION_LEFT);
configurationProvider.setDegrees(configurationProvider.getDeviceDefaultOrientation() == Configuration.ORIENTATION_PORTRAIT ? 90 : 180);
} else if (sensorEvent.values[0] < 0) {
// RIGHT
configurationProvider.setSensorPosition(Configuration.SENSOR_POSITION_RIGHT);
configurationProvider.setDegrees(configurationProvider.getDeviceDefaultOrientation() == Configuration.ORIENTATION_PORTRAIT ? 270 : 0);
}
}
onScreenRotation(configurationProvider.getDegrees());
}
}
}
示例10: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
System.arraycopy(event.values, 0, mAccelerometerReading,
0, mAccelerometerReading.length);
} else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
System.arraycopy(event.values, 0, mMagnetometerReading,
0, mMagnetometerReading.length);
}
updateOrientationAngles();
directionView.updateAngle(mOrientationAngles[0]);
}
示例11: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
Sensor evtSensor = event.sensor;
if(evtSensor.getType()==Sensor.TYPE_ACCELEROMETER)
{
double x = event.values[0];
double y = event.values[1];
double maxValue = Math.sqrt(x*x+y*y);
double xDiv = x/maxValue;
double yDiv = y/maxValue;
// Calculates new falling angle
double angle = Math.atan(yDiv/xDiv) + (x < 0 ? Math.PI : 0);
float accY = accG*(float)Math.sin(angle);
float accX = -accG*(float)Math.cos(angle);
// Push new angle data to RS
if(scriptMain != null) {
scriptMain.set_accY((float) accY);
scriptMain.set_accX((float) accX);
}
}
}
示例12: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
{
mGravity = event.values;
}
if(event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
{
mGeomagnetic = event.values;
}
if(mGravity != null && mGeomagnetic != null)
{
float R[] = new float[9];
float I[] = new float[9];
boolean success = SensorManager.getRotationMatrix(R,I,mGravity,mGeomagnetic);
if(success)
{
float orientation[] = new float[3];
SensorManager.getOrientation(R, orientation);
Log.e("NEW ORIENTATION---","---------------");
Log.e("orientation azimut", String.valueOf(orientation[0]*60));
Log.e("orientation pitch", String.valueOf(orientation[1]*60));
Log.e("orientation roll", String.valueOf(orientation[2]*60));
txt.setText("orientation azimut " + String.valueOf(orientation[0]*60) + "\n" + "orientation pitch" + String.valueOf(orientation[1]*60) + "\n" + "orientation roll"+ String.valueOf(orientation[2]*60));
}
}
}
示例13: onSensorChanged
public void onSensorChanged(SensorEvent event) {
Sensor sensor = event.sensor;
synchronized (this) {
if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
calc_step(event);
}
}
}
示例14: 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;
}
示例15: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
int sensorType = event.sensor.getType();
float[] values = event.values;
if (sensorType == Sensor.TYPE_ACCELEROMETER) {
int value = 12;
if ((Math.abs(values[0]) >= value || Math.abs(values[1]) >= value || Math.abs(values[2]) >= value)) {
showFragmentStackHierarchyView();
}
}
}