本文整理汇总了Java中android.hardware.SensorEvent类的典型用法代码示例。如果您正苦于以下问题:Java SensorEvent类的具体用法?Java SensorEvent怎么用?Java SensorEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SensorEvent类属于android.hardware包,在下文中一共展示了SensorEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
final float value = event.values[0];
if (event.sensor.getType() == Sensor.TYPE_AMBIENT_TEMPERATURE) {
updateTemperatureDisplay(value);
} else if (event.sensor.getType() == Sensor.TYPE_PRESSURE) {
updateBarometerDisplay(value);
}
}
示例2: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
// 传感器信息改变时执行该方法
float[] values = event.values;
float x = values[0]; // x轴方向的重力加速度,向右为正
float y = values[1]; // y轴方向的重力加速度,向前为正
float z = values[2]; // z轴方向的重力加速度,向上为正
// Log.i("xlight", "x轴方向的重力加速度" + x + ";y轴方向的重力加速度" + y + ";z轴方向的重力加速度" + z);
// 一般在这三个方向的重力加速度达到40就达到了摇晃手机的状态。
//Logger.i("shake", "x = " + Math.abs(x) + ",y = " + y + ",z = " + z);
int medumValue = 18;// 三星 i9250怎么晃都不会超过20,没办法,只设置19了
if (Math.abs(x) > medumValue || Math.abs(y) > medumValue || Math.abs(z) > medumValue) {
if (!UserUtils.isLogin(SlidingMenuMainActivity.this) || null == mShakeInfo) {
return;
}
vibrator.vibrate(200);
Message msg = new Message();
msg.what = SENSOR_SHAKE;
handler.sendMessage(msg);
}
}
示例3: accelerometerControl
import android.hardware.SensorEvent; //导入依赖的package包/类
private void accelerometerControl(SensorEvent event) {
float xSens;
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER)
return;
xSens = event.values[1];
// if(xSens > mAccelerometerThreshold){
// mMove = true;
// mMoveLeft = false;
// mTouch = true;
// return;
// }
// if(xSens < -mAccelerometerThreshold){
// mMove = true;
// mTouch = true;
// mMoveLeft = true;
// return;
// }
// mMove = false;
// if(mFire == false){
// mTouch = false;
// }
}
示例4: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.timestamp - mLastTimestamp < MIN_TIME_BETWEEN_SAMPLES_MS) {
return;
}
Assertions.assertNotNull(mTimestamps);
Assertions.assertNotNull(mMagnitudes);
float ax = sensorEvent.values[0];
float ay = sensorEvent.values[1];
float az = sensorEvent.values[2];
mLastTimestamp = sensorEvent.timestamp;
mTimestamps[mCurrentIndex] = sensorEvent.timestamp;
mMagnitudes[mCurrentIndex] = Math.sqrt(ax * ax + ay * ay + az * az);
maybeDispatchShake(sensorEvent.timestamp);
mCurrentIndex = (mCurrentIndex + 1) % MAX_SAMPLES;
}
示例5: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
float x = event.values[0];
float y = event.values[1];
if (x<5 && x>-5 && y > 5)
mOrientation = Surface.ROTATION_0; // portrait
else if (x<-5 && y<5 && y>-5)
mOrientation = Surface.ROTATION_270; // right
else if (x<5 && x>-5 && y<-5)
mOrientation = Surface.ROTATION_180; // upside down
else if (x>5 && y<5 && y>-5)
mOrientation = Surface.ROTATION_90; // left
if (mListener != null) {
mListener.orientationEvent();
}
}
示例6: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.timestamp - mLastTimestamp < MIN_TIME_BETWEEN_SAMPLES_MS) {
return;
}
float ax = sensorEvent.values[0];
float ay = sensorEvent.values[1];
float az = sensorEvent.values[2];
mLastTimestamp = sensorEvent.timestamp;
mTimestamps[mCurrentIndex] = sensorEvent.timestamp;
mMagnitudes[mCurrentIndex] = Math.sqrt(ax * ax + ay * ay + az * az);
maybeDispatchShake(sensorEvent.timestamp);
mCurrentIndex = (mCurrentIndex + 1) % MAX_SAMPLES;
}
示例7: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
try {
if (event.sensor == mRotationSensor && getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
if (event.values.length > 4) {
float[] truncatedRotationVector = new float[4];
System.arraycopy(event.values, 0, truncatedRotationVector, 0, 4);
update(truncatedRotationVector);
} else {
update(event.values);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
if(Math.abs(event.values[1]) < Y_DELTA_FOR_DETECT_LANDSCAPE) {
if(orientation != EventSubCodes.SAMSUNG_DEVICE_ORIENTATION_LANDSCAPE) {
Log.d(TAG, "Landscape");
}
orientation = EventSubCodes.SAMSUNG_DEVICE_ORIENTATION_LANDSCAPE;
} else {
if(orientation != EventSubCodes.SAMSUNG_DEVICE_ORIENTATION_PORTRAIT) {
Log.d(TAG, "Portrait");
}
orientation = EventSubCodes.SAMSUNG_DEVICE_ORIENTATION_PORTRAIT;
}
if(previousOrientation != orientation) {
MBApp application = MBApp.getApp();
Intent intent = new Intent(application, IPCService.class);
intent.putExtra(IPCConstants.INTENT_TYPE, EventCategories.IPC_BLE_NOTIFICATION_CHARACTERISTIC_CHANGED);
intent.putExtra(IPCConstants.INTENT_CHARACTERISTIC_MESSAGE, Utils.makeMicroBitValue
(EventCategories.SAMSUNG_DEVICE_INFO_ID, orientation));
application.startService(intent);
previousOrientation = orientation;
}
}
示例9: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
// 传感器信息改变时执行该方法
float[] values = event.values;
float x = values[0]; // x轴方向的重力加速度,向右为正
float y = values[1]; // y轴方向的重力加速度,向前为正
float z = values[2]; // z轴方向的重力加速度,向上为正
// Log.i(TAG, "x轴方向的重力加速度" + x + ";y轴方向的重力加速度" + y + ";z轴方向的重力加速度" + z);
// 一般在这三个方向的重力加速度达到40就达到了摇晃手机的状态。
int medumValue = 30;
if (Math.abs(x) > medumValue || Math.abs(y) > medumValue || Math.abs(z) > medumValue) {
Log.i("Test5555", "x轴方向的重力加速度" + x + ";y轴方向的重力加速度" + y + ";z轴方向的重力加速度" + z);
vibrator.vibrate(200);
Message msg = new Message();
msg.what = SENSOR_SHAKE;
handler.sendMessage(msg);
}
}
示例10: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {//可以得到传感器实时测量出来的变化值
float x = event.values[SensorManager.DATA_X];
float y = event.values[SensorManager.DATA_Y];
float z = event.values[SensorManager.DATA_Z];
if (x < -10) {
//direction right
} else if (x > 10) {
//direction left
if (JCVideoPlayerManager.listener() != null) {
JCVideoPlayerManager.listener().autoFullscreenLeft();
}
} else if (y > 9.5) {
if (JCVideoPlayerManager.listener() != null) {
JCVideoPlayerManager.listener().autoQuitFullscreen();
}
}
}
示例11: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
public void onSensorChanged(SensorEvent sensorEvent) {
switch (sensorEvent.sensor.getType()) {
case 1:
this.g4 = sensorEvent.values;
break;
case 2:
this.g8 = sensorEvent.values;
break;
}
if (this.g4 != null && this.g8 != null) {
float[] fArr = new float[9];
if (SensorManager.getRotationMatrix(fArr, null, this.g4, this.g8)) {
float[] fArr2 = new float[3];
SensorManager.getOrientation(fArr, fArr2);
g5 = (float) Math.toDegrees((double) fArr2[0]);
g5 = (float) Math.floor(g5 >= 0.0f ? (double) g5 : (double) (g5 + 360.0f));
}
}
}
示例12: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@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);
}
}
示例13: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@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);
}
}
示例14: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
Float[] values = new Float[3];
values[0] = event.values[0];
updateValues(values);
//event.accuracy
//event.sensor
//event.timestamp
//Don't block the onSensorChanged() method
/*
Sensor data can change at a high rate, which means the system may call the
onSensorChanged(SensorEvent) method quite often. As a best practice, you
should do as little as possible within the onSensorChanged(SensorEvent) method
so you don't block it. If your application requires you to do any data filtering
or reduction of sensor data, you should perform that work outside of the
onSensorChanged(SensorEvent) method.
*/
}
示例15: onSensorChanged
import android.hardware.SensorEvent; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
boolean accelerating = isAccelerating(event);
long timestamp = event.timestamp;
queue.add(timestamp, accelerating);
if (queue.isShaking()) {
/*
* detect time between two concecutive shakes and limit it to
* MIN_TIME_BETWEEN_TWO_SHAKES
*/
long currentTime = System.currentTimeMillis();
if (currentTime - mDetectedShakeStartTime > MIN_TIME_BETWEEN_TWO_SHAKES) {
queue.clear();
listener.hearShake();
mDetectedShakeStartTime = System.currentTimeMillis();
}
}
}