Java Code Examples for android.hardware.SensorManager#DATA_X
The following examples show how to use
android.hardware.SensorManager#DATA_X .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShakeDetectEventListener.java From android-wear-gopro-remote with Apache License 2.0 | 6 votes |
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { long curTime = System.currentTimeMillis(); // if a shake in last X seconds ignore. if (lastShake != 0 && (curTime - lastShake) < IGNORE_EVENTS_AFTER_SHAKE) return; float x = event.values[SensorManager.DATA_X]; float y = event.values[SensorManager.DATA_Y]; float z = event.values[SensorManager.DATA_Z]; if (last_x != 0 && last_y != 0 && last_z != 0 && (last_x != x || last_y != y || last_z != z)) { DataPoint dp = new DataPoint(last_x-x, last_y-y, last_z-z, curTime); //Log.i("XYZ",Float.toString(dp.x)+" "+Float.toString(dp.y)+" "+Float.toString(dp.z)+" "); dataPoints.add(dp); if ((curTime - lastUpdate) > SHAKE_CHECK_THRESHOLD) { lastUpdate = curTime; checkForShake(); } } last_x = x; last_y = y; last_z = z; } }
Example 2
Source File: MyOrientationListener.java From Mobike with Apache License 2.0 | 6 votes |
@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; } }
Example 3
Source File: QiblaCompassFragment.java From al-muazzin with GNU Lesser General Public License v2.1 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.tab_qibla, container, false); final QiblaCompassView qiblaCompassView = (QiblaCompassView) rootView .findViewById(R.id.qibla_compass); qiblaCompassView.setConstants(((TextView) rootView.findViewById(R.id.bearing_north)), getText(R.string.bearing_north), ((TextView) rootView.findViewById(R.id.bearing_qibla)), getText(R.string.bearing_qibla)); sOrientationListener = new android.hardware.SensorListener() { @Override public void onSensorChanged(int s, float v[]) { float northDirection = v[SensorManager.DATA_X]; qiblaCompassView.setDirections(northDirection, sQiblaDirection); } @Override public void onAccuracyChanged(int s, int a) { } }; return rootView; }
Example 4
Source File: MyOrientationListener.java From BaiduMap-TrafficAssistant with MIT License | 6 votes |
@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; } }
Example 5
Source File: MxVideoPlayer.java From MxVideoPlayer with Apache License 2.0 | 5 votes |
@Override public void onSensorChanged(SensorEvent event) { // 可以得到传感器实时测量出来的变化值 final float x = event.values[SensorManager.DATA_X]; float y = event.values[SensorManager.DATA_Y]; // 过滤掉用力过猛会有一个反向的大数值 if (((x > -15 && x < -10) || (x < 15 && x > 10)) && Math.abs(y) < 1.5) { if ((System.currentTimeMillis() - mLastAutoFullscreenTime) > 1200) { MxMediaPlayerListener currentListener = MxVideoPlayerManager.getCurrentListener(); if (currentListener != null) { currentListener.autoFullscreen(x); } mLastAutoFullscreenTime = System.currentTimeMillis(); } } }
Example 6
Source File: AccelerationData.java From 30-android-libraries-in-30-days with Apache License 2.0 | 5 votes |
@Override public void swapAxis(final float[] pValues) { final float x = -pValues[SensorManager.DATA_X]; final float y = pValues[SensorManager.DATA_Y]; pValues[SensorManager.DATA_X] = x; pValues[SensorManager.DATA_Y] = y; }
Example 7
Source File: AccelerationData.java From tilt-game-android with MIT License | 5 votes |
@Override public void swapAxis(final float[] pValues) { final float x = -pValues[SensorManager.DATA_Y]; final float y = pValues[SensorManager.DATA_X]; pValues[SensorManager.DATA_X] = x; pValues[SensorManager.DATA_Y] = y; }
Example 8
Source File: DragableView.java From appcan-android with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onSensorChanged(SensorEvent event) { long curTime = System.currentTimeMillis(); // 每100毫秒检测一次 if ((curTime - lastUpdate) > 100) { long diffTime = (curTime - lastUpdate); lastUpdate = curTime; x = event.values[SensorManager.DATA_X]; y = event.values[SensorManager.DATA_Y]; z = event.values[SensorManager.DATA_Z]; float speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000; if (speed > SHAKE_THRESHOLD) { // 检测到摇晃后执行的代码 setVisibility(View.GONE); setClickable(false); sensorManager.unregisterListener(this, sensor); if (!isAddedSenseView) { windowManager.addView(gSenseView, gSenseView.getLayoutParams()); isAddedSenseView = true; gSenseView.startSense(); gSenseView.addBallFallIntoCallback(new OnBallFallIntoCallback() { @Override public void onFallInto() { windowManager.removeViewImmediate(gSenseView); isAddedSenseView = false; if (listener != null) { listener.onGSBallFalled(); } } }); } } last_x = x; last_y = y; last_z = z; } }
Example 9
Source File: AccelerationData.java From tilt-game-android with MIT License | 5 votes |
@Override public void swapAxis(final float[] pValues) { final float x = pValues[SensorManager.DATA_Y]; final float y = -pValues[SensorManager.DATA_X]; pValues[SensorManager.DATA_X] = x; pValues[SensorManager.DATA_Y] = y; }
Example 10
Source File: AccelerationData.java From tilt-game-android with MIT License | 5 votes |
@Override public void swapAxis(final float[] pValues) { final float x = -pValues[SensorManager.DATA_X]; final float y = -pValues[SensorManager.DATA_Y]; pValues[SensorManager.DATA_X] = x; pValues[SensorManager.DATA_Y] = y; }
Example 11
Source File: ShakeMonitor.java From RoMote with Apache License 2.0 | 5 votes |
public final void onSensorChanged(SensorEvent event) { // The light sensor returns a single value. // Many sensors return 3 values, one for each axis. float [] values = event.values; // Do something with this sensor value. long now = System.currentTimeMillis(); if ((now - mLastForce) > SHAKE_TIMEOUT) { mShakeCount = 0; } if ((now - mLastTime) > TIME_THRESHOLD) { long diff = now - mLastTime; float speed = Math.abs(values[SensorManager.DATA_X] + values[SensorManager.DATA_Y] + values[SensorManager.DATA_Z] - mLastX - mLastY - mLastZ) / diff * 10000; if (speed > FORCE_THRESHOLD) { if ((++mShakeCount >= SHAKE_COUNT) && (now - mLastShake > SHAKE_DURATION)) { mLastShake = now; mShakeCount = 0; if (mShakeListener != null) { mShakeListener.onShake(); } } mLastForce = now; } mLastTime = now; mLastX = values[SensorManager.DATA_X]; mLastY = values[SensorManager.DATA_Y]; mLastZ = values[SensorManager.DATA_Z]; } }
Example 12
Source File: AccelerationData.java From 30-android-libraries-in-30-days with Apache License 2.0 | 5 votes |
@Override public void swapAxis(final float[] pValues) { final float x = pValues[SensorManager.DATA_X]; final float y = -pValues[SensorManager.DATA_Y]; pValues[SensorManager.DATA_X] = x; pValues[SensorManager.DATA_Y] = y; }
Example 13
Source File: RestProtector.java From Huochexing12306 with Apache License 2.0 | 5 votes |
@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); } }
Example 14
Source File: Jzvd.java From imsdk-android with MIT License | 5 votes |
@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 < -12 || x > 12) { if ((System.currentTimeMillis() - lastAutoFullscreenTime) > 2000) { if (Jzvd.CURRENT_JZVD != null) Jzvd.CURRENT_JZVD.autoFullscreen(x); lastAutoFullscreenTime = System.currentTimeMillis(); } } }
Example 15
Source File: MyOrientationListener.java From BmapLite with Apache License 2.0 | 5 votes |
@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) { onOrientationListener.onOrientationChanged(x); } lastX = x; } }
Example 16
Source File: Orientation.java From WhereYouGo with GNU General Public License v3.0 | 4 votes |
public void onSensorChanged(SensorEvent event) { switch (event.sensor.getType()) { case Sensor.TYPE_MAGNETIC_FIELD: break; case Sensor.TYPE_ACCELEROMETER: float filter = getFilter(); aboveOrBelow = (float) ((event.values[SensorManager.DATA_Z] * filter) + (aboveOrBelow * (1.0 - filter))); break; case Sensor.TYPE_ORIENTATION: float valueOr = event.values[SensorManager.DATA_X]; // Logger.d(TAG, "sensorOrientation:" + valueOr + ", " + event.values[SensorManager.DATA_Y] // + ", " + event.values[SensorManager.DATA_Z] + ", " + getDeclination()); // fix to true bearing if (Preferences.SENSOR_BEARING_TRUE) { valueOr += getDeclination(); } orient = filterValue(valueOr, orient); pitch = filterValue(event.values[SensorManager.DATA_Y], pitch); roll = filterValue(event.values[SensorManager.DATA_Z], roll); float rollDef; if (aboveOrBelow < 0) { if (roll < 0) { rollDef = -180 - roll; } else { rollDef = 180 - roll; } } else { rollDef = roll; } this.mLastAziSensor = orient; // do some orientation change by settings int rotation = A.getMain().getWindowManager().getDefaultDisplay().getRotation(); switch (rotation) { case Surface.ROTATION_0: // no need for change break; case Surface.ROTATION_90: mLastAziSensor += 90; break; case Surface.ROTATION_180: mLastAziSensor -= 180; break; case Surface.ROTATION_270: mLastAziSensor -= 90; break; } sendOrientation(pitch, rollDef); break; } }
Example 17
Source File: AccelerationData.java From tilt-game-android with MIT License | 4 votes |
public float getX() { return this.mValues[SensorManager.DATA_X]; }
Example 18
Source File: AccelerationData.java From tilt-game-android with MIT License | 4 votes |
public void setX(final float pX) { this.mValues[SensorManager.DATA_X] = pX; }
Example 19
Source File: AccelerationData.java From 30-android-libraries-in-30-days with Apache License 2.0 | 4 votes |
public void setX(final float pX) { this.mValues[SensorManager.DATA_X] = pX; }
Example 20
Source File: OrientationData.java From 30-android-libraries-in-30-days with Apache License 2.0 | 4 votes |
public float getYaw() { return super.mValues[SensorManager.DATA_X]; }