当前位置: 首页>>代码示例>>Java>>正文


Java SensorManager.DATA_Y属性代码示例

本文整理汇总了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();
        }
    }

}
 
开发者ID:wp521,项目名称:MyFire,代码行数:19,代码来源:JCVideoPlayer.java

示例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];
	}
}
 
开发者ID:JackChan1999,项目名称:RandomLayout,代码行数:39,代码来源:ShakeListener.java

示例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();
        }
    }
}
 
开发者ID:monkeywiiu,项目名称:Discover,代码行数:15,代码来源:JZVideoPlayer.java

示例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();
        }
    }
}
 
开发者ID:Longalei,项目名称:Edu,代码行数:15,代码来源:JCVideoPlayer.java

示例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);
            }
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:35,代码来源:RestProtector.java


注:本文中的android.hardware.SensorManager.DATA_Y属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。