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