當前位置: 首頁>>代碼示例>>Java>>正文


Java SensorManager.DATA_X屬性代碼示例

本文整理匯總了Java中android.hardware.SensorManager.DATA_X屬性的典型用法代碼示例。如果您正苦於以下問題:Java SensorManager.DATA_X屬性的具體用法?Java SensorManager.DATA_X怎麽用?Java SensorManager.DATA_X使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.hardware.SensorManager的用法示例。


在下文中一共展示了SensorManager.DATA_X屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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

@SuppressWarnings(
{ "deprecation" })
@Override
public void onSensorChanged(SensorEvent event)
{
	if (event.sensor.getType() == Sensor.TYPE_ORIENTATION)
	{
		float x = event.values[SensorManager.DATA_X];

		if (Math.abs(x - lastX) > 1.0)
		{
			if (mOnOrientationListener != null)
			{
				mOnOrientationListener.onOrientationChanged(x);
			}
		}

		lastX = x;

	}
}
 
開發者ID:ljlgithup,項目名稱:MapDemo,代碼行數:21,代碼來源:MyOrientationListener.java

示例3: onSensorChanged

@Override
public void onSensorChanged(SensorEvent event) {
    if(event.sensor.getType()== Sensor.TYPE_ORIENTATION)
    {
        float x=event.values[SensorManager.DATA_X];
        if(Math.abs(x-lastX)>1.0)
        {
            if(mOnOrientationListener!=null)
            {
                mOnOrientationListener.onOrientationChanged(x);
            }
        }
        lastX=x;

    }

}
 
開發者ID:yiwent,項目名稱:Mobike,代碼行數:17,代碼來源:MyOrientationListener.java

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: onSensorChanged

@Override
public void onSensorChanged(SensorEvent sensorEvent) {
    double x = sensorEvent.values[SensorManager.DATA_X];
    if (Math.abs(x - lastX) > 1.0) {
        mCurrentDirection = (int) x;
        locData = new MyLocationData.Builder()
                .accuracy(mCurrentAccracy)
                // 此處設置開發者獲取到的方向信息,順時針0-360
                .direction(mCurrentDirection).latitude(mCurrentLat)
                .longitude(mCurrentLon).build();
        mBaiduMap.setMyLocationData(locData);
    }
    lastX = x;

}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:15,代碼來源:LocationDemo.java


注:本文中的android.hardware.SensorManager.DATA_X屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。