重力感应-翻转手机

//////////////add by lee 2011.08.01
float x;
float y;
float z;
SensorManager sensorMgr;  
Sensor sensor;
SensorEventListener lsn;
boolean mIsTurnOver = false;
////////////////////////////////////

///////////add by lee 2011.08.01
try {
sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);  
Sensor sensor = sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);    
sensorMgr = (SensorManager)getSystemService(SENSOR_SERVICE);  
lsn = new SensorEventListener() {  
public void onSensorChanged(SensorEvent e) {  
x = e.values[SensorManager.DATA_X];  
y = e.values[SensorManager.DATA_Y];  
z = e.values[SensorManager.DATA_Z];  
//setTitle("x="+(int)x+","+"y="+(int)y+","+"z="+(int)z);
//Log.d(TAG, "***x="+(int)x+","+"y="+(int)y+","+"z="+(int)z+"***");
if(z<-5 && !mIsTurnOver){
Log.d(TAG, "***if(z<-5)***");
mIsTurnOver = true;
        mAnotherCurrentPosition = mVideoPlayerActivity.mVideoView.getCurrentPosition();
        Log.d(TAG, "mAnotherCurrentPosition="+mAnotherCurrentPosition);
        mVideoPlayerActivity.mHandler.removeMessages(VideoPlayerActivity.VIDEO_REFRESH);
        if(isChannel){
        mVideoPlayerActivity.mVideoView.stopPlayback();
        }
        else{
        mVideoPlayerActivity.mVideoView.pause();
        }
        mVideoControl.setInPauseStatus();
        lee_show_Adview();
            lee_isPlayBeforeHome=false;
            lee_isHOMEpressed = true;
}
else if(z>=-5){
mIsTurnOver = false;
}
else{

}
}  
public void onAccuracyChanged(Sensor s, int accuracy) {  
}  
};  
sensorMgr.registerListener(lsn, sensor, SensorManager.SENSOR_DELAY_GAME);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();

///////////////////////////////////////

你可能感兴趣的:(手机)