Java Code Examples for android.hardware.Sensor#TYPE_ORIENTATION
The following examples show how to use
android.hardware.Sensor#TYPE_ORIENTATION .
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: SensorMyLocationOverlay.java From WhereYouGo with GNU General Public License v3.0 | 6 votes |
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) { boolean redraw = false; synchronized (this) { long timestamp = event.timestamp / 1000000; float azimuth = (event.values[0] + getRotationOffset() + 360) % 360; azimuth = filterValue(azimuth, this.currentCompassAzimuth); this.currentCompassAzimuth = azimuth; this.marker.setRotation(azimuth); if (Math.abs(timestamp - this.lastCompassTimestamp) >= UPDATE_INTERVAL && Math.abs(azimuth - this.lastCompassAzimuth) >= UPDATE_AZIMUTH) { this.lastCompassTimestamp = timestamp; this.lastCompassAzimuth = azimuth; redraw = true; } } if (redraw) this.mapView.getOverlayController().redrawOverlays(); } }
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: 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 4
Source File: GpsSectionFragment.java From satstat with GNU General Public License v3.0 | 6 votes |
/** * Called by {@link MainActivity} when a sensor's reading changes. * Rotates sky plot according to bearing. * * If {@code TYPE_ORIENTATION} data is available, preference is given to that value, which * appeared to be more accurate in tests. Otherwise orientation is obtained from the rotation * vector of the device, based on {@link TYPE_ACCELEROMETER} and {@code TYPE_MAGNETIC_FIELD} * sensor data. */ public void onSensorChanged(SensorEvent event) { switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: gravity = event.values.clone(); break; case Sensor.TYPE_MAGNETIC_FIELD: geomagnetic = event.values.clone(); break; case Sensor.TYPE_ORIENTATION: if (event.values[0] != 0) { hasOrientation = true; gpsStatusView.setYaw(event.values[0]); } break; } if ((gravity != null) && (geomagnetic != null) && !hasOrientation) { float[] ypr = new float[3]; float[] r = new float[16]; float[] i = new float[16]; SensorManager.getRotationMatrix(r, i, gravity, geomagnetic); ypr = SensorManager.getOrientation(r, ypr); gpsStatusView.setYaw((float) Math.toDegrees(ypr[0])); } }
Example 5
Source File: MyOrientationListener.java From BmapLite with GNU General Public License v3.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 6
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 7
Source File: InternalCompassOrientationProvider.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void onSensorChanged(final SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) { if (event.values != null) { mAzimuth = event.values[0]; if (mOrientationConsumer != null) mOrientationConsumer.onOrientationChanged(mAzimuth, this); } } }
Example 8
Source File: LocationLayerTestActivity.java From MapView with MIT License | 5 votes |
@Override public void onSensorChanged(SensorEvent event) { if (mapView.isMapLoadFinish() && openSensor) { float mapDegree = 0; // the rotate between reality map to northern float degree = 0; if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) { degree = event.values[0]; } locationLayer.setCompassIndicatorCircleRotateDegree(-degree); locationLayer.setCompassIndicatorArrowRotateDegree(mapDegree + mapView .getCurrentRotateDegrees() + degree); mapView.refresh(); } }
Example 9
Source File: SensorEventHelper.java From TraceByAmap with MIT License | 5 votes |
@Override public void onSensorChanged(SensorEvent event) { if (System.currentTimeMillis() - lastTime < TIME_SENSOR) { return; } switch (event.sensor.getType()) { case Sensor.TYPE_ORIENTATION: { float x = event.values[0]; x += getScreenRotationOnPhone(mContext); x %= 360.0F; if (x > 180.0F) x -= 360.0F; else if (x < -180.0F) x += 360.0F; if (Math.abs(mAngle - x) < 3.0f) { break; } mAngle = Float.isNaN(x) ? 0 : x; if (mMarker != null) { mMarker.setRotateAngle(360-mAngle); } lastTime = System.currentTimeMillis(); } } }
Example 10
Source File: SensorUtil.java From Sensor-Disabler with MIT License | 5 votes |
public static boolean isDangerousSensor(Sensor sensor) { switch (sensor.getType()) { case Sensor.TYPE_LIGHT: case Sensor.TYPE_ACCELEROMETER: case Sensor.TYPE_ORIENTATION: case Sensor.TYPE_GYROSCOPE: case Sensor.TYPE_GYROSCOPE_UNCALIBRATED: return true; default: //Don't have a human string type? Safer to say that it's possibly dangerous. return getHumanStringType(sensor) == null; } }
Example 11
Source File: AndroidSensorJoyInput.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Resumes the sensors. * Used to resume sensors when the activity comes to the top of the stack */ public void resumeSensors() { for (Entry entry: sensors) { if (entry.getKey() != Sensor.TYPE_ORIENTATION) { registerListener(entry.getKey()); } } }
Example 12
Source File: MainActivity.java From augmentedreality with Apache License 2.0 | 5 votes |
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) { tv_head.setText(String.valueOf(event.values[0])); tv_pitch.setText(String.valueOf(event.values[1])); tv_roll.setText(String.valueOf(event.values[2])); } else if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { tv_x.setText(String.valueOf(event.values[0])); tv_y.setText(String.valueOf(event.values[1])); tv_z.setText(String.valueOf(event.values[2])); } }
Example 13
Source File: Sensors.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
public void onSensorChanged(SensorEvent event) { //Log.d(TAG, "sensor: " + sensor + ", x: " + values[0] + ", y: " + values[1] + ", z: " + values[2]); synchronized (this) { if (mBitmap != null) { final Canvas canvas = mCanvas; final Paint paint = mPaint; if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) { for (int i=0 ; i<3 ; i++) { mOrientationValues[i] = event.values[i]; } } else { float deltaX = mSpeed; float newX = mLastX + deltaX; int j = (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) ? 1 : 0; for (int i=0 ; i<3 ; i++) { int k = i+j*3; final float v = mYOffset + event.values[i] * mScale[j]; paint.setColor(mColors[k]); canvas.drawLine(mLastX, mLastValues[k], newX, v, paint); mLastValues[k] = v; } if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) mLastX += mSpeed; } invalidate(); } } }
Example 14
Source File: XSensorManager.java From XPrivacy with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") private boolean isRestricted(XParam param, int type) throws Throwable { if (type == Sensor.TYPE_ALL) return false; else if (type == Sensor.TYPE_ACCELEROMETER || type == Sensor.TYPE_LINEAR_ACCELERATION) { if (isRestricted(param, "acceleration")) return true; } else if (type == Sensor.TYPE_GRAVITY) { if (isRestricted(param, "gravity")) return true; } else if (type == Sensor.TYPE_RELATIVE_HUMIDITY) { if (isRestricted(param, "humidity")) return true; } else if (type == Sensor.TYPE_LIGHT) { if (isRestricted(param, "light")) return true; } else if (type == Sensor.TYPE_MAGNETIC_FIELD || type == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) { if (isRestricted(param, "magnetic")) return true; } else if (type == Sensor.TYPE_SIGNIFICANT_MOTION) { if (isRestricted(param, "motion")) return true; } else if (type == Sensor.TYPE_ORIENTATION || type == Sensor.TYPE_GYROSCOPE || type == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) { if (isRestricted(param, "orientation")) return true; } else if (type == Sensor.TYPE_PRESSURE) { if (isRestricted(param, "pressure")) return true; } else if (type == Sensor.TYPE_PROXIMITY) { if (isRestricted(param, "proximity")) return true; } else if (type == Sensor.TYPE_GAME_ROTATION_VECTOR || type == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR || type == Sensor.TYPE_ROTATION_VECTOR) { if (isRestricted(param, "rotation")) return true; } else if (type == Sensor.TYPE_TEMPERATURE || type == Sensor.TYPE_AMBIENT_TEMPERATURE) { if (isRestricted(param, "temperature")) return true; } else if (type == Sensor.TYPE_STEP_COUNTER || type == Sensor.TYPE_STEP_DETECTOR) { if (isRestricted(param, "step")) return true; } else if (type == Sensor.TYPE_HEART_RATE) { if (isRestricted(param, "heartrate")) return true; } else if (type == 22) { // 22 = TYPE_TILT_DETECTOR // Do nothing } else if (type == 23 || type == 24 || type == 25) { // 23 = TYPE_WAKE_GESTURE // 24 = TYPE_GLANCE_GESTURE // 25 = TYPE_PICK_UP_GESTURE // 23/24 This sensor is expected to only be used by the system ui // 25 Expected to be used internally for always on display } else Util.log(this, Log.WARN, "Unknown sensor type=" + type); return false; }
Example 15
Source File: SensorSectionFragment.java From satstat with GNU General Public License v3.0 | 4 votes |
/** * Called by {@link MainActivity} when a sensor's reading changes. Updates sensor display. */ public void onSensorChanged(SensorEvent event) { switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: accX.setText(String.format("%." + mAccSensorRes + "f", event.values[0])); accY.setText(String.format("%." + mAccSensorRes + "f", event.values[1])); accZ.setText(String.format("%." + mAccSensorRes + "f", event.values[2])); accTotal.setText(String.format("%." + mAccSensorRes + "f", Math.sqrt(Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2)))); accStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_ORIENTATION: orAzimuth.setText(String.format("%.0f%s", event.values[0], getString(R.string.unit_degree))); orAziText.setText(MainActivity.formatOrientation(this.getContext(), event.values[0])); orPitch.setText(String.format("%.0f%s", event.values[1], getString(R.string.unit_degree))); orRoll.setText(String.format("%.0f%s", event.values[2], getString(R.string.unit_degree))); orStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_GYROSCOPE: rotX.setText(String.format("%." + mGyroSensorRes + "f", event.values[0])); rotY.setText(String.format("%." + mGyroSensorRes + "f", event.values[1])); rotZ.setText(String.format("%." + mGyroSensorRes + "f", event.values[2])); rotTotal.setText(String.format("%." + mGyroSensorRes + "f", Math.sqrt(Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2)))); rotStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_MAGNETIC_FIELD: magX.setText(String.format("%." + mMagSensorRes + "f", event.values[0])); magY.setText(String.format("%." + mMagSensorRes + "f", event.values[1])); magZ.setText(String.format("%." + mMagSensorRes + "f", event.values[2])); magTotal.setText(String.format("%." + mMagSensorRes + "f", Math.sqrt(Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2)))); magStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_LIGHT: light.setText(String.format("%." + mLightSensorRes + "f", event.values[0])); lightStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_PROXIMITY: proximity.setText(String.format("%." + mProximitySensorRes + "f", event.values[0])); proximityStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_PRESSURE: metPressure.setText(String.format("%." + mPressureSensorRes + "f", event.values[0])); pressureStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_RELATIVE_HUMIDITY: metHumid.setText(String.format("%." + mHumiditySensorRes + "f", event.values[0])); humidStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_AMBIENT_TEMPERATURE: metTemp.setText(String.format("%." + mTempSensorRes + "f", event.values[0])); tempStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; } }
Example 16
Source File: AndroidSensorJoyInput.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public Joystick loadJoystick(int joyId, InputManager inputManager) { SensorData sensorData; AndroidSensorJoystickAxis axis; AndroidSensorJoystick joystick = new AndroidSensorJoystick(inputManager, joyInput, joyId, "AndroidSensorsJoystick"); List<Sensor> availSensors = sensorManager.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor: availSensors) { logger.log(Level.FINE, "{0} Sensor is available, Type: {1}, Vendor: {2}, Version: {3}", new Object[]{sensor.getName(), sensor.getType(), sensor.getVendor(), sensor.getVersion()}); } // manually create orientation sensor data since orientation is not a physical sensor sensorData = new SensorData(Sensor.TYPE_ORIENTATION, null); sensorData.lastValues = new float[3]; sensors.put(Sensor.TYPE_ORIENTATION, sensorData); axis = joystick.addAxis(SensorJoystickAxis.ORIENTATION_X, SensorJoystickAxis.ORIENTATION_X, joystick.getAxisCount(), FastMath.HALF_PI); joystick.setYAxis(axis); // joystick y axis = rotation around device x axis sensorData.axes.add(axis); axis = joystick.addAxis(SensorJoystickAxis.ORIENTATION_Y, SensorJoystickAxis.ORIENTATION_Y, joystick.getAxisCount(), FastMath.HALF_PI); joystick.setXAxis(axis); // joystick x axis = rotation around device y axis sensorData.axes.add(axis); axis = joystick.addAxis(SensorJoystickAxis.ORIENTATION_Z, SensorJoystickAxis.ORIENTATION_Z, joystick.getAxisCount(), FastMath.HALF_PI); sensorData.axes.add(axis); // add axes for physical sensors sensorData = initSensor(Sensor.TYPE_MAGNETIC_FIELD); if (sensorData != null) { sensorData.lastValues = new float[3]; sensors.put(Sensor.TYPE_MAGNETIC_FIELD, sensorData); // axis = joystick.addAxis(SensorJoystickAxis.MAGNETIC_X, "MagneticField_X", joystick.getAxisCount(), 1f); // sensorData.axes.add(axis); // axis = joystick.addAxis(SensorJoystickAxis.MAGNETIC_Y, "MagneticField_Y", joystick.getAxisCount(), 1f); // sensorData.axes.add(axis); // axis = joystick.addAxis(SensorJoystickAxis.MAGNETIC_Z, "MagneticField_Z", joystick.getAxisCount(), 1f); // sensorData.axes.add(axis); } sensorData = initSensor(Sensor.TYPE_ACCELEROMETER); if (sensorData != null) { sensorData.lastValues = new float[3]; sensors.put(Sensor.TYPE_ACCELEROMETER, sensorData); // axis = joystick.addAxis(SensorJoystickAxis.ACCELEROMETER_X, "Accelerometer_X", joystick.getAxisCount(), 1f); // sensorData.axes.add(axis); // axis = joystick.addAxis(SensorJoystickAxis.ACCELEROMETER_Y, "Accelerometer_Y", joystick.getAxisCount(), 1f); // sensorData.axes.add(axis); // axis = joystick.addAxis(SensorJoystickAxis.ACCELEROMETER_Z, "Accelerometer_Z", joystick.getAxisCount(), 1f); // sensorData.axes.add(axis); } // sensorData = initSensor(Sensor.TYPE_GYROSCOPE); // if (sensorData != null) { // sensorData.lastValues = new float[3]; // } // // sensorData = initSensor(Sensor.TYPE_GRAVITY); // if (sensorData != null) { // sensorData.lastValues = new float[3]; // } // // sensorData = initSensor(Sensor.TYPE_LINEAR_ACCELERATION); // if (sensorData != null) { // sensorData.lastValues = new float[3]; // } // // sensorData = initSensor(Sensor.TYPE_ROTATION_VECTOR); // if (sensorData != null) { // sensorData.lastValues = new float[4]; // } // // sensorData = initSensor(Sensor.TYPE_PROXIMITY); // if (sensorData != null) { // sensorData.lastValues = new float[1]; // } // // sensorData = initSensor(Sensor.TYPE_LIGHT); // if (sensorData != null) { // sensorData.lastValues = new float[1]; // } // // sensorData = initSensor(Sensor.TYPE_PRESSURE); // if (sensorData != null) { // sensorData.lastValues = new float[1]; // } // // sensorData = initSensor(Sensor.TYPE_TEMPERATURE); // if (sensorData != null) { // sensorData.lastValues = new float[1]; // } loaded = true; return joystick; }
Example 17
Source File: MainActivity.java From satstat with GNU General Public License v3.0 | 4 votes |
/** * Called when a sensor's reading changes. Updates sensor display and rotates sky plot according * to bearing. */ public void onSensorChanged(SensorEvent event) { //to enforce sensor rate boolean isRateElapsed = false; switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: isRateElapsed = (event.timestamp / 1000) - mAccLast >= iSensorRate; // if Z acceleration is greater than X/Y combined, lock rotation, else unlock if (Math.pow(event.values[2], 2) > Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2)) { // workaround (SCREEN_ORIENTATION_LOCK is unsupported on API < 18) if (isWideScreen) setRequestedOrientation(OR_FROM_ROT_WIDE[this.getWindowManager().getDefaultDisplay().getRotation()]); else setRequestedOrientation(OR_FROM_ROT_TALL[this.getWindowManager().getDefaultDisplay().getRotation()]); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } break; case Sensor.TYPE_ORIENTATION: isRateElapsed = (event.timestamp / 1000) - mOrLast >= iSensorRate; break; case Sensor.TYPE_GYROSCOPE: isRateElapsed = (event.timestamp / 1000) - mGyroLast >= iSensorRate; break; case Sensor.TYPE_MAGNETIC_FIELD: isRateElapsed = (event.timestamp / 1000) - mMagLast >= iSensorRate; break; case Sensor.TYPE_LIGHT: isRateElapsed = (event.timestamp / 1000) - mLightLast >= iSensorRate; break; case Sensor.TYPE_PROXIMITY: isRateElapsed = (event.timestamp / 1000) - mProximityLast >= iSensorRate; break; case Sensor.TYPE_PRESSURE: isRateElapsed = (event.timestamp / 1000) - mPressureLast >= iSensorRate; break; case Sensor.TYPE_RELATIVE_HUMIDITY: isRateElapsed = (event.timestamp / 1000) - mHumidityLast >= iSensorRate; break; case Sensor.TYPE_AMBIENT_TEMPERATURE: isRateElapsed = (event.timestamp / 1000) - mTempLast >= iSensorRate; break; } if (!isRateElapsed) return; switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: mAccLast = event.timestamp / 1000; break; case Sensor.TYPE_ORIENTATION: mOrLast = event.timestamp / 1000; break; case Sensor.TYPE_GYROSCOPE: mGyroLast = event.timestamp / 1000; break; case Sensor.TYPE_MAGNETIC_FIELD: mMagLast = event.timestamp / 1000; break; case Sensor.TYPE_LIGHT: mLightLast = event.timestamp / 1000; break; case Sensor.TYPE_PROXIMITY: mProximityLast = event.timestamp / 1000; break; case Sensor.TYPE_PRESSURE: mPressureLast = event.timestamp / 1000; break; case Sensor.TYPE_RELATIVE_HUMIDITY: mHumidityLast = event.timestamp / 1000; break; case Sensor.TYPE_AMBIENT_TEMPERATURE: mTempLast = event.timestamp / 1000; break; } if (sensorSectionFragment != null) { sensorSectionFragment.onSensorChanged(event); } if (gpsSectionFragment != null) { gpsSectionFragment.onSensorChanged(event); } }
Example 18
Source File: OrientationDetector.java From edx-app-android with Apache License 2.0 | 4 votes |
@Override public void onSensorChanged(SensorEvent event) { Sensor sensor = event.sensor; if ((sensor.getType() == Sensor.TYPE_ORIENTATION)) { float[] eventValues = event.values; // current orientation of the phone float xAxis = eventValues[1]; float yAxis = eventValues[2]; if ((yAxis <= 25) && (yAxis >= -25) && (xAxis >= -160)) { if (previousOrientation != PORTRAIT) { previousOrientation = PORTRAIT; // CHANGED TO PORTRAIT onPortrait(); onChanged(); } } else if ((yAxis < -25) && (xAxis >= -20)) { if (previousOrientation != LANDSCAPE_RIGHT) { previousOrientation = LANDSCAPE_RIGHT; // CHANGED TO LANDSCAPE RIGHT onLandscapeRight(); if (previousOrientation != UNKNOWN) { onChanged(); } } } else if ((yAxis > 25) && (xAxis >= -20)) { if (previousOrientation != LANDSCAPE_LEFT) { previousOrientation = LANDSCAPE_LEFT; // CHANGED TO LANDSCAPE LEFT onLandscapeLeft(); if (previousOrientation != UNKNOWN) { onChanged(); } } } else { logger.debug("Orientation values unhandled: " + eventValues); } onUpdate(); } }
Example 19
Source File: POrientation.java From PHONK with GNU General Public License v3.0 | 4 votes |
public POrientation(AppRunner appRunner) { super(appRunner); type = Sensor.TYPE_ORIENTATION; }
Example 20
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; } }