List of usage examples for android.hardware Sensor TYPE_ACCELEROMETER
int TYPE_ACCELEROMETER
To view the source code for android.hardware Sensor TYPE_ACCELEROMETER.
Click Source Link
From source file:com.saulcintero.moveon.services.MoveOnService.java
private void registerDetector() { mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mSensorManager.registerListener(mStepDetector, mSensor, SensorManager.SENSOR_DELAY_FASTEST); stepDetectorSensitivity();/* w ww . j a v a2s . c om*/ }
From source file:com.example.lijingjiang.mobile_sensor_display.SimplePedometerActivity.java
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { simpleStepDetector.updateAccel(event.timestamp, event.values[0], event.values[1], event.values[2]); }/* w w w. j ava 2 s. c o m*/ }
From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java
@Override protected void onResume() { super.onResume(); try {//from ww w . j a v a 2s. c om this.mWakeLock.acquire(); // ?? ? killOnError(); // ? ? mixContext.mixView = this; // ?? dataView.doStart(); // ?? dataView.clearEvents(); // ? ? double angleX, angleY; // ? x, y /*? ? ? */ angleX = Math.toRadians(-90); m1.set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX), 0f, (float) Math.sin(angleX), (float) Math.cos(angleX)); angleX = Math.toRadians(-90); angleY = Math.toRadians(-90); m2.set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX), 0f, (float) Math.sin(angleX), (float) Math.cos(angleX)); m3.set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f, (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY)); m4.toIdentity(); for (int i = 0; i < histR.length; i++) { histR[i] = new Matrix(); } /* */ // ? sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE); // ? ? // ?? sensors = sensorMgr.getSensorList(Sensor.TYPE_ACCELEROMETER); if (sensors.size() > 0) { sensorGrav = sensors.get(0); } // ? sensors = sensorMgr.getSensorList(Sensor.TYPE_MAGNETIC_FIELD); if (sensors.size() > 0) { sensorMag = sensors.get(0); } //// TODO: 2016-06-01 if (sensors.size() > 0) { sensors = sensorMgr_ori.getSensorList(Sensor.TYPE_ORIENTATION); orientationSensor = sensors.get(0); } // ?? ? ? ? ? sensorMgr.registerListener(this, sensorGrav, SENSOR_DELAY_GAME); sensorMgr.registerListener(this, sensorMag, SENSOR_DELAY_GAME); if (orientationSensor != null) { sensorMgr_ori.registerListener(this, orientationSensor, sensorMgr_ori.SENSOR_DELAY_GAME); } try { // ?? (Criteria) // http://developer.android.com/reference/android/location/Criteria.html Criteria c = new Criteria(); // ? c.setAccuracy(Criteria.ACCURACY_FINE); //c.setBearingRequired(true); // ? locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // ?? ? ? ? . 2 , 3 locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 4, this); // ?? ? , String bestP = locationMgr.getBestProvider(c, true); isGpsEnabled = locationMgr.isProviderEnabled(bestP); // gps, ? ? ? Location hardFix = new Location("reverseGeocoded"); try { // ? gps, ?? Location gps = locationMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location network = locationMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); // ? ? // gps > ? > if (gps != null) mixContext.curLoc = gps; else if (network != null) mixContext.curLoc = network; else mixContext.curLoc = hardFix; } catch (Exception ex2) { // ? ex2.printStackTrace(); // mixContext.curLoc = hardFix; // } // ? ? ?? mixContext.setLocationAtLastDownload(mixContext.curLoc); // ?? . ? GeomagneticField gmf = new GeomagneticField((float) mixContext.curLoc.getLatitude(), (float) mixContext.curLoc.getLongitude(), (float) mixContext.curLoc.getAltitude(), System.currentTimeMillis()); // ?? angleY = Math.toRadians(-gmf.getDeclination()); m4.set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f, (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY)); mixContext.declination = gmf.getDeclination(); } catch (Exception ex) { Log.d("mixare", "GPS Initialize Error", ex); // ? } // ? downloadThread = new Thread(mixContext.downloadManager); downloadThread.start(); } catch (Exception ex) { doError(ex); // ? try { // ??? if (sensorMgr != null) { sensorMgr.unregisterListener(this, sensorGrav); sensorMgr.unregisterListener(this, sensorMag); sensorMgr = null; } // ?? if (locationMgr != null) { locationMgr.removeUpdates(this); locationMgr = null; } // ?? ?? if (mixContext != null) { if (mixContext.downloadManager != null) mixContext.downloadManager.stop(); } } catch (Exception ignore) { } } // ?? // ?? ? ( ?? ) ? if (dataView.isFrozen() && searchNotificationTxt == null) { searchNotificationTxt = new TextView(this); searchNotificationTxt.setWidth(dWindow.getWidth()); searchNotificationTxt.setPadding(10, 2, 0, 0); searchNotificationTxt.setBackgroundColor(Color.DKGRAY); searchNotificationTxt.setTextColor(Color.WHITE); searchNotificationTxt.setOnTouchListener(this); addContentView(searchNotificationTxt, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } else if (!dataView.isFrozen() && searchNotificationTxt != null) { searchNotificationTxt.setVisibility(View.GONE); searchNotificationTxt = null; } }
From source file:ibme.sleepap.recording.SignalsRecorder.java
/** * Called when the activity is first created. onStart() is called * immediately afterwards./*from www .j a v a2 s . co m*/ */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.signals_recorder); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Log both handled and unhandled issues. if (sharedPreferences.getBoolean(Constants.PREF_WRITE_LOG, Constants.DEFAULT_WRITE_LOG)) { String bugDirPath = Environment.getExternalStorageDirectory().toString() + "/" + getString(R.string.app_name) + "/" + Constants.FILENAME_LOG_DIRECTORY; File bugDir = new File(bugDirPath); if (!bugDir.exists()) { bugDir.mkdirs(); } String handledFileName = bugDirPath + "/logcat" + System.currentTimeMillis() + ".trace"; String unhandledFileName = bugDirPath + "/unhandled" + System.currentTimeMillis() + ".trace"; // Log any warning or higher, and write it to handledFileName. String[] cmd = new String[] { "logcat", "-f", handledFileName, "*:W" }; try { Runtime.getRuntime().exec(cmd); } catch (IOException e1) { Log.e(Constants.CODE_APP_TAG, "Error creating bug files", e1); } Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(unhandledFileName)); } bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); extras = getIntent().getBundleExtra(Constants.EXTRA_RECORDING_SETTINGS); actigraphyEnabled = extras.getBoolean(Constants.EXTRA_COLLECT_ACTIGRAPHY, false); audioEnabled = extras.getBoolean(Constants.EXTRA_COLLECT_AUDIO, false); ppgEnabled = extras.getBoolean(Constants.EXTRA_COLLECT_PPG, false); dateTimeString = DateFormat.format(Constants.PARAM_DATE_FORMAT, System.currentTimeMillis()).toString(); sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); magnetometer = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); String appDirPath = Environment.getExternalStorageDirectory().toString() + "/" + getString(R.string.app_name); filesDirPath = appDirPath + "/" + dateTimeString + "/"; lastAccelerometerRecordedTime = 0; lastPositionChangeTime = System.currentTimeMillis(); PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.CODE_APP_TAG); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); actigraphyQueue = new LinkedList<Double>(); positionDisplay = (TextView) findViewById(R.id.position); recordingSign = (ImageView) findViewById(R.id.recordingSign); for (int i = 0; i < 5; ++i) { totalPositionTime[i] = 0; } // Battery check receiver. registerReceiver(this.batteryLevelReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); // Button to stop the recording. Button stopButton = (Button) findViewById(R.id.buttonStop); stopButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View viewNext) { stopRecording(); } }); // Button to reconnect the bluetooth. reconnectButton = (Button) findViewById(R.id.reconnectButton); reconnectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View viewNext) { String macAddress = sharedPreferences.getString(Constants.PREF_MAC_ADDRESS, Constants.DEFAULT_MAC_ADDRESS); noninManager = null; noninManager = new NoninManager(getApplicationContext(), bluetoothAdapter, macAddress, new PpgHandler(SignalsRecorder.this)); noninManager.start(); reconnectButton.setEnabled(false); reconnectButton.setClickable(false); } }); // Create a folder for the recordings, and delete any extra recordings. File dir = new File(filesDirPath); if (!dir.exists()) { dir.mkdirs(); File appDir = new File(appDirPath); // Create a list of recordings in the app directory. These // are named by the date on which they were formed and so can be in // date order (earliest first). String[] recordingDirs = appDir.list(); Arrays.sort(recordingDirs); // How many more recordings do we have in the app directory than are // specified in the settings? Should account for questionnaires // file, // which must exist for the user to have gotten to this stage // (checklist). int numberRecordings = 0; for (String folderOrFileName : recordingDirs) { if (!folderOrFileName.equals(Constants.FILENAME_QUESTIONNAIRE) && !folderOrFileName.equals(Constants.FILENAME_LOG_DIRECTORY) && !folderOrFileName.equals(Constants.FILENAME_FEEDBACK_DIRECTORY)) { numberRecordings++; } } int extraFiles = numberRecordings - Integer.parseInt(sharedPreferences .getString(Constants.PREF_NUMBER_RECORDINGS, Constants.DEFAULT_NUMBER_RECORDINGS)); if (extraFiles > 0) { // Too many recordings. Delete the earliest n, where n is the // number of extra files. boolean success; int nDeleted = 0; for (String candidateFolderName : recordingDirs) { if (nDeleted >= extraFiles) { // We've deleted enough already. break; } if (candidateFolderName.equals(Constants.FILENAME_QUESTIONNAIRE) || candidateFolderName.equals(Constants.FILENAME_LOG_DIRECTORY) || candidateFolderName.equals(Constants.FILENAME_FEEDBACK_DIRECTORY)) { // Don't delete questionnaire file or log/feedback // directory. continue; } // See if the path is a directory, and skip it if it isn't. File candidateFolder = new File(appDir, candidateFolderName); if (!candidateFolder.isDirectory()) { continue; } // If we've got to this stage, the file is the earliest // recording and should be deleted. Delete files in // recording first. success = Utils.deleteDirectory(candidateFolder); if (success) { nDeleted++; } } } } // Copy latest questionnaire File try { File latestQuestionnaireFile = new File(appDirPath, Constants.FILENAME_QUESTIONNAIRE); InputStream in = new FileInputStream(latestQuestionnaireFile); OutputStream out = new FileOutputStream(new File(filesDirPath, Constants.FILENAME_QUESTIONNAIRE)); // Copy the bits from instream to outstream byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } catch (FileNotFoundException e) { Log.e(Constants.CODE_APP_TAG, "FileNotFoundException copying Questionnaire file."); } catch (IOException e) { Log.e(Constants.CODE_APP_TAG, "IOException copying Questionnaire file."); } // Create txt files. orientationFile = new File(filesDirPath, Constants.FILENAME_ORIENTATION); accelerationFile = new File(filesDirPath, Constants.FILENAME_ACCELERATION_RAW); actigraphyFile = new File(filesDirPath, Constants.FILENAME_ACCELERATION_PROCESSED); audioProcessedFile = new File(filesDirPath, Constants.FILENAME_AUDIO_PROCESSED); bodyPositionFile = new File(filesDirPath, Constants.FILENAME_POSITION); ppgFile = new File(filesDirPath, Constants.FILENAME_PPG); spo2File = new File(filesDirPath, Constants.FILENAME_SPO2); audioRawFile = new File(filesDirPath, Constants.FILENAME_AUDIO_RAW); /** Recording starts here. */ // Log start time so recording can begin in 30 minutes. startTime = Calendar.getInstance(Locale.getDefault()); finishRecordingFlag = false; recordingStartDelayMs = Constants.CONST_MILLIS_IN_MINUTE * Integer.parseInt(sharedPreferences .getString(Constants.PREF_RECORDING_START_DELAY, Constants.DEFAULT_RECORDING_START_DELAY)); recordingDurationMs = Constants.CONST_MILLIS_IN_MINUTE * Integer.parseInt(sharedPreferences .getString(Constants.PREF_RECORDING_DURATION, Constants.DEFAULT_RECORDING_DURATION)); if (recordingStartDelayMs > 0) { startRecordingFlag = false; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.setTitle(getString(R.string.delayAlertTitle)) .setMessage(getString(R.string.delayAlertMessage1) + " " + sharedPreferences.getString(Constants.PREF_RECORDING_START_DELAY, Constants.DEFAULT_RECORDING_START_DELAY) + " " + getString(R.string.delayAlertMessage2)) .setPositiveButton(getString(R.string.ok), null); delayAlertDialog = dialogBuilder.create(); delayAlertDialog.show(); } else { startRecordingFlag = true; // Notify user Intent notificationIntent = new Intent(SignalsRecorder.this, SignalsRecorder.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); if (sharedPreferences.getBoolean(Constants.PREF_NOTIFICATIONS, Constants.DEFAULT_NOTIFICATIONS)) { NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.notification_icon) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.deviceaccessmic)) .setContentTitle("SleepAp").setContentText(getString(R.string.startedRecordingNotification)) .setAutoCancel(false).setOngoing(true).setContentIntent(pendingIntent); notificationManager.notify(Constants.CODE_APP_NOTIFICATION_ID, builder.build()); recordingSign.setVisibility(View.VISIBLE); } } // Start audio recording. if (audioEnabled) { extAudioRecorder = new ExtAudioRecorder(this); extAudioRecorder.setOutputFile(audioRawFile); extAudioRecorder.setShouldWrite(startRecordingFlag); extAudioRecorder.setAudioProcessedFile(audioProcessedFile); extAudioRecorder.prepare(); extAudioRecorder.start(); } // Start PPG recording. if (ppgEnabled && bluetoothAdapter != null) { String macAddress = sharedPreferences.getString(Constants.PREF_MAC_ADDRESS, Constants.DEFAULT_MAC_ADDRESS); noninManager = new NoninManager(this, bluetoothAdapter, macAddress, new PpgHandler(SignalsRecorder.this)); noninManager.start(); } // Start actigraphy recording. if (actigraphyEnabled) { sensorManager.registerListener(this, accelerometer, 1000000 / (Constants.PARAM_SAMPLERATE_ACCELEROMETER * Constants.PARAM_UPSAMPLERATE_ACCELEROMETER)); sensorManager.registerListener(this, magnetometer, 1000000 / Constants.PARAM_SAMPLERATE_ACCELEROMETER); } wakeLock.acquire(); // Set up listener so that if Bluetooth connection is lost we set give // the user an option to reconnect. if (ppgEnabled) { IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED); filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED); filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); registerReceiver(bluetoothDisconnectReceiver, filter); } // Start graphs update. graphUpdateTask = new UserInterfaceUpdater(); graphUpdateTask.execute(); }
From source file:com.example.zoetablet.BasicFragmentActivity.java
@Override protected void onResume() { Log.i("Tablet", "Resume..."); //Compass Activity Sensor accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); Sensor magField = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); sensorManager.registerListener(sensorEventListener, accelerometer, SensorManager.SENSOR_DELAY_UI); sensorManager.registerListener(sensorEventListener, magField, SensorManager.SENSOR_DELAY_UI); super.onResume(); }
From source file:com.davidmascharka.lips.MainActivity.java
@Override public void onSensorChanged(SensorEvent event) { /*//w w w .j av a 2s . com * Because Android doesn't let us query a sensor reading whenever we want so * we have to keep track of the readings at all times. Here we just update * the class members with the values associated with each reading we're * interested in. */ switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: accelerometerX = event.values[0]; accelerometerY = event.values[1]; accelerometerZ = event.values[2]; break; case Sensor.TYPE_MAGNETIC_FIELD: magneticX = event.values[0]; magneticY = event.values[1]; magneticZ = event.values[2]; break; case Sensor.TYPE_LIGHT: light = event.values[0]; break; case Sensor.TYPE_ROTATION_VECTOR: rotationX = event.values[0]; rotationY = event.values[1]; rotationZ = event.values[2]; break; default: break; } SensorManager.getRotationMatrix(rotation, inclination, new float[] { accelerometerX, accelerometerY, accelerometerZ }, new float[] { magneticX, magneticY, magneticZ }); orientation = SensorManager.getOrientation(rotation, orientation); }
From source file:org.osm.keypadmapper2.KeypadMapper2Activity.java
@Override public void onSensorChanged(SensorEvent event) { synchronized (this) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) mGravity = event.values;/*from ww w . j ava2 s . c o m*/ if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) mGeomagnetic = event.values; if (mGravity != null && mGeomagnetic != null) { float R[] = new float[9]; float I[] = new float[9]; boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic); if (success) { float orientation[] = new float[3]; SensorManager.getOrientation(R, orientation); azimuth = orientation[0]; // orientation contains: azimuth, pitch and roll } } } }
From source file:com.vonglasow.michael.satstat.ui.MainActivity.java
/** * Called when a sensor's reading changes. Updates sensor display and rotates sky plot according * to bearing.//from w w w . j a v a 2s .co m */ 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); } }
From source file:radu.pidroid.Controller.java
@Override public void onSensorChanged(SensorEvent event) { // we received a sensor event. it is a good practice to check // that we received the proper event switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: mAccelerometerData = event.values; break;//from w ww. jav a 2 s .c o m case Sensor.TYPE_MAGNETIC_FIELD: mGeomagneticData = event.values; if (tiltControlsOn) { computeTiltAngle(); tiltControls(); } // if break; default: Log.e("onSensorChanged", "wut?!"); break; } // switch }
From source file:org.godotengine.godot.Godot.java
@Override public void onSensorChanged(SensorEvent event) { Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); int displayRotation = display.getRotation(); float[] adjustedValues = new float[3]; final int axisSwap[][] = { { 1, -1, 0, 1 }, // ROTATION_0 { -1, -1, 1, 0 }, // ROTATION_90 { -1, 1, 0, 1 }, // ROTATION_180 { 1, 1, 1, 0 } }; // ROTATION_270 final int[] as = axisSwap[displayRotation]; adjustedValues[0] = (float) as[0] * event.values[as[2]]; adjustedValues[1] = (float) as[1] * event.values[as[3]]; adjustedValues[2] = event.values[2]; final float x = adjustedValues[0]; final float y = adjustedValues[1]; final float z = adjustedValues[2]; final int typeOfSensor = event.sensor.getType(); if (mView != null) { mView.queueEvent(new Runnable() { @Override//from ww w . jav a 2 s . c om public void run() { if (typeOfSensor == Sensor.TYPE_ACCELEROMETER) { GodotLib.accelerometer(-x, y, -z); } if (typeOfSensor == Sensor.TYPE_GRAVITY) { GodotLib.gravity(-x, y, -z); } if (typeOfSensor == Sensor.TYPE_MAGNETIC_FIELD) { GodotLib.magnetometer(-x, y, -z); } if (typeOfSensor == Sensor.TYPE_GYROSCOPE) { GodotLib.gyroscope(x, -y, z); } } }); } }