本文整理汇总了Java中android.hardware.SensorManager.DATA_Y属性的典型用法代码示例。如果您正苦于以下问题:Java SensorManager.DATA_Y属性的具体用法?Java SensorManager.DATA_Y怎么用?Java SensorManager.DATA_Y使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.hardware.SensorManager
的用法示例。
在下文中一共展示了SensorManager.DATA_Y属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSensorChanged
@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();
}
}
}
示例2: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
System.out.println("x:" + event.values[SensorManager.DATA_X] + " y:" + event.values[SensorManager.DATA_Y]
+ " z:" + event.values[SensorManager.DATA_Z]);
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
return;
}
long now = System.currentTimeMillis();
if ((now - mLastForce) > SHAKE_TIMEOUT) {
mShakeCount = 0;
}
if ((now - mLastTime) > TIME_THRESHOLD) {
long diff = now - mLastTime;
// 把X,Y,Z方向的距离除以时间,得出速度
float speed = Math.abs(event.values[SensorManager.DATA_X] + event.values[SensorManager.DATA_Y]
+ event.values[SensorManager.DATA_Z] - mLastX - mLastY - mLastZ)
/ diff * 10000;
if (speed > FORCE_THRESHOLD) {// 如果速度大于某个值
// 先把摇晃的次数+1,再判断是否超过了要换的次数,并且间隙大于特定的值
if ((++mShakeCount >= SHAKE_COUNT) && (now - mLastShake > SHAKE_DURATION)) {
mLastShake = now;
mShakeCount = 0;
if (mShakeListener != null) {// 回调我们的listener
mShakeListener.onShake();
}
}
mLastForce = now;
}
mLastTime = now;
mLastX = event.values[SensorManager.DATA_X];
mLastY = event.values[SensorManager.DATA_Y];
mLastZ = event.values[SensorManager.DATA_Z];
}
}
示例3: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {//可以得到传感器实时测量出来的变化值
final float x = event.values[SensorManager.DATA_X];
float y = event.values[SensorManager.DATA_Y];
float z = event.values[SensorManager.DATA_Z];
//过滤掉用力过猛会有一个反向的大数值
if (((x > -15 && x < -10) || (x < 15 && x > 10)) && Math.abs(y) < 1.5) {
if ((System.currentTimeMillis() - lastAutoFullscreenTime) > 2000) {
if (JZVideoPlayerManager.getCurrentJzvd() != null) {
JZVideoPlayerManager.getCurrentJzvd().autoFullscreen(x);
}
lastAutoFullscreenTime = System.currentTimeMillis();
}
}
}
示例4: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {//可以得到传感器实时测量出来的变化值
final float x = event.values[SensorManager.DATA_X];
float y = event.values[SensorManager.DATA_Y];
float z = event.values[SensorManager.DATA_Z];
//过滤掉用力过猛会有一个反向的大数值
if (((x > -15 && x < -10) || (x < 15 && x > 10)) && Math.abs(y) < 1.5) {
if ((System.currentTimeMillis() - lastAutoFullscreenTime) > 2000) {
if (JCVideoPlayerManager.getCurrentJcvd() != null) {
JCVideoPlayerManager.getCurrentJcvd().autoFullscreen(x);
}
lastAutoFullscreenTime = System.currentTimeMillis();
}
}
}
示例5: onSensorChanged
@SuppressWarnings("deprecation")
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER){
return;
}
//现在检测时间
long currentUpdateTime = System.currentTimeMillis();
//两次检测的时间间隔
long timeInterval = currentUpdateTime - lastUpdateTime;
//判断是否达到了检测时间间隔
if(timeInterval < UPTATE_INTERVAL_TIME)
return;
//现在的时间变成last时间
lastUpdateTime = currentUpdateTime;
//获取加速度数值,以下三个值为重力分量在设备坐标的分量大小
float x = event.values[SensorManager.DATA_X];
float y = event.values[SensorManager.DATA_Y];
float z = event.values[SensorManager.DATA_Z];
//获得x,y,z的变化值
float deltaX = x - lastX;
float deltaY = y - lastY;
float deltaZ = z - lastZ;
//备份本次坐标
lastX = x;
lastY = y;
lastZ = z;
//计算移动速度
double speed = Math.sqrt(deltaX*deltaX + deltaY*deltaY + deltaZ*deltaZ)/timeInterval * 10000;
L.i("speed:" + speed);
L.i("mSpeedThreshold:" + mSpeedThreshold);
if(speed >= mSpeedThreshold){
request(AntiTheftService.REQUEST_START_ALARM, null);
}
}