List of usage examples for android.hardware SensorManager GRAVITY_EARTH
float GRAVITY_EARTH
To view the source code for android.hardware SensorManager GRAVITY_EARTH.
Click Source Link
From source file:Main.java
public static double[] magnititute(double accx[], double accy[], double accz[]) { if (!((accx.length == accy.length) && (accy.length == accz.length))) { return null; }//from www.j a v a 2 s. c o m double result[] = new double[accx.length]; for (int i = 0; i < accx.length; i++) { result[i] = 0.0; double grav = SensorManager.GRAVITY_EARTH; result[i] += Math.pow(accx[i] / grav, 2.0); result[i] += Math.pow(accy[i] / grav, 2.0); result[i] += Math.pow(accz[i] / grav, 2.0); result[i] = Math.sqrt(result[i]); result[i] *= 310; } return result; }
From source file:fi.hut.soberit.sensors.uploaders.PhysicalActivityUploader.java
public void updateWithAcceleration(float x, float y, float z) { accelerationSum += Math.sqrt(x * x + y * y + z * z) - SensorManager.GRAVITY_EARTH; accelerationCounter++;//from w ww . j a va 2 s.com }
From source file:com.etmay.brescrollpager.ui.MyScroller.java
private float computeDeceleration(float friction) { return SensorManager.GRAVITY_EARTH // g (m/s^2) * 39.37f // inch/meter * mPpi // pixels per inch * friction;//from w w w.j av a 2s . c om }
From source file:com.kircherelectronics.accelerationexplorer.filter.ImuLaCfQuaternion.java
public float[] getLinearAcceleration() { // values[0]: azimuth, rotation around the Z axis. // values[1]: pitch, rotation around the X axis. // values[2]: roll, rotation around the Y axis. // Find the gravity component of the X-axis // = g*-cos(pitch)*sin(roll); components[0] = (float) (SensorManager.GRAVITY_EARTH * -Math.cos(fusedOrientation[1]) * Math.sin(fusedOrientation[2])); // Find the gravity component of the Y-axis // = g*-sin(pitch); components[1] = (float) (SensorManager.GRAVITY_EARTH * -Math.sin(fusedOrientation[1])); // Find the gravity component of the Z-axis // = g*cos(pitch)*cos(roll); components[2] = (float) (SensorManager.GRAVITY_EARTH * Math.cos(fusedOrientation[1]) * Math.cos(fusedOrientation[2])); // Subtract the gravity component of the signal // from the input acceleration signal to get the // tilt compensated output. linearAcceleration[0] = (this.acceleration[0] - components[0]); linearAcceleration[1] = (this.acceleration[1] - components[1]); linearAcceleration[2] = (this.acceleration[2] - components[2]); return linearAcceleration; }
From source file:com.sir_m2x.messenger.activities.ChatWindowPager.java
@Override protected void onResume() { isActive = true;/*w w w. j a va2 s. co m*/ registerReceiver(this.listener, new IntentFilter(MessengerService.INTENT_IS_TYPING)); registerReceiver(this.listener, new IntentFilter(MessengerService.INTENT_NEW_IM)); registerReceiver(this.listener, new IntentFilter(MessengerService.INTENT_DESTROY)); registerReceiver(this.listener, new IntentFilter(MessengerService.INTENT_BUZZ)); this.sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE); this.mAccel = 0.00f; this.mAccelCurrent = SensorManager.GRAVITY_EARTH; this.mAccelLast = SensorManager.GRAVITY_EARTH; if (Preferences.shake2Buzz) this.sensorMgr.registerListener(this, this.sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_UI); super.onResume(); }
From source file:nl.vincentketelaars.mexen.activities.RollDice.java
private void getAccelerometer(SensorEvent event) { float[] values = event.values; // Movement/*from ww w . ja v a 2 s .c om*/ float x = values[0]; float y = values[1]; float z = values[2]; float accelationSquareRoot = (x * x + y * y + z * z) / (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH); if (accelationSquareRoot >= MINIMUM_ACCELARATION) { if (throwButton.isEnabled()) { throwButton.performClick(); } } }
From source file:mp.teardrop.PlaybackService.java
@Override public void onCreate() { HandlerThread thread = new HandlerThread("PlaybackService", Process.THREAD_PRIORITY_DEFAULT); thread.start();/*from w w w . j a v a2s . c o m*/ mTimeline = new SongTimeline(this); mTimeline.setCallback(this); int state = loadState(); mPlayCounts = new PlayCountsHelper(this); mMediaPlayer = getNewMediaPlayer(); mBastpUtil = new BastpUtil(); mReadahead = new ReadaheadThread(); mReadahead.start(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); SharedPreferences settings = getSettings(this); settings.registerOnSharedPreferenceChangeListener(this); mNotificationMode = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_MODE, "1")); mScrobble = settings.getBoolean(PrefKeys.SCROBBLE, false); mIdleTimeout = settings.getBoolean(PrefKeys.USE_IDLE_TIMEOUT, false) ? settings.getInt(PrefKeys.IDLE_TIMEOUT, 3600) : 0; Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_ANDROID, true) ? Song.mCoverLoadMode | Song.COVER_MODE_ANDROID : Song.mCoverLoadMode & ~(Song.COVER_MODE_ANDROID); Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_VANILLA, true) ? Song.mCoverLoadMode | Song.COVER_MODE_VANILLA : Song.mCoverLoadMode & ~(Song.COVER_MODE_VANILLA); Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_SHADOW, true) ? Song.mCoverLoadMode | Song.COVER_MODE_SHADOW : Song.mCoverLoadMode & ~(Song.COVER_MODE_SHADOW); mHeadsetOnly = settings.getBoolean(PrefKeys.HEADSET_ONLY, false); mStockBroadcast = settings.getBoolean(PrefKeys.STOCK_BROADCAST, false); mInvertNotification = settings.getBoolean(PrefKeys.NOTIFICATION_INVERTED_COLOR, false); mNotificationAction = createNotificationAction(settings); mHeadsetPause = getSettings(this).getBoolean(PrefKeys.HEADSET_PAUSE, true); mShakeAction = settings.getBoolean(PrefKeys.ENABLE_SHAKE, false) ? Action.getAction(settings, PrefKeys.SHAKE_ACTION, Action.NextSong) : Action.Nothing; mShakeThreshold = settings.getInt(PrefKeys.SHAKE_THRESHOLD, 80) / 10.0f; mReplayGainTrackEnabled = settings.getBoolean(PrefKeys.ENABLE_TRACK_REPLAYGAIN, false); mReplayGainAlbumEnabled = settings.getBoolean(PrefKeys.ENABLE_ALBUM_REPLAYGAIN, false); mReplayGainBump = settings.getInt(PrefKeys.REPLAYGAIN_BUMP, 75); /* seek bar is 150 -> 75 == middle == 0 */ mReplayGainUntaggedDeBump = settings.getInt(PrefKeys.REPLAYGAIN_UNTAGGED_DEBUMP, 150); /* seek bar is 150 -> == 0 */ mReadaheadEnabled = settings.getBoolean(PrefKeys.ENABLE_READAHEAD, false); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TeardropMusicLock"); mReceiver = new Receiver(); IntentFilter filter = new IntentFilter(); filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); filter.addAction(Intent.ACTION_SCREEN_ON); registerReceiver(mReceiver, filter); getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mObserver); CompatIcs.registerRemote(this, mAudioManager); mLooper = thread.getLooper(); mHandler = new Handler(mLooper, this); initWidgets(); updateState(state); setCurrentSong(0, false); sInstance = this; synchronized (sWait) { sWait.notifyAll(); } mAccelFiltered = 0.0f; mAccelLast = SensorManager.GRAVITY_EARTH; setupSensor(); }
From source file:io.v.moments.ux.MainActivity.java
@Override public void onSensorChanged(SensorEvent event) { float gX = event.values[0] / SensorManager.GRAVITY_EARTH; float gY = event.values[1] / SensorManager.GRAVITY_EARTH; float gZ = event.values[2] / SensorManager.GRAVITY_EARTH; double gForce = Math.sqrt(gX * gX + gY * gY + gZ * gZ); if (gForce < SHAKE_THRESHOLD) { return;/* w w w . j a v a 2 s.co m*/ } final long now = System.currentTimeMillis(); if (now - mShakeTimestamp < SHAKE_EVENT_MS) { return; } mShakeTimestamp = now; final EditText invitee = new EditText(this); invitee.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); AlertDialog.Builder builder = new AlertDialog.Builder(this) .setTitle(getString(R.string.invite_remote_inspector)).setView(invitee) .setPositiveButton(getString(R.string.invite_remote_inspector_positive_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_SEND); String to = invitee.getText().toString(); intent.setType("message/rfc822"); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { to }); intent.putExtra(Intent.EXTRA_SUBJECT, "Please help me debug"); try { intent.putExtra(Intent.EXTRA_TEXT, mV23Manager.inviteInspector(to, Duration.standardDays(1))); mRemoteInspectionEnabled = true; } catch (Exception e) { toast(e.toString()); return; } if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { toast(getString(R.string.invite_remote_inspector_failed)); } } }) .setNegativeButton(getString(R.string.invite_remote_inspector_negative_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); if (mRemoteInspectionEnabled) { builder.setNeutralButton(getString(R.string.invite_remote_inspector_neutral_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // This doesn't take effect till the next time the activity is created // (invited users will still be able to connect till then). mRemoteInspectionEnabled = false; } }); } builder.show(); }
From source file:info.alni.comete.android.Comete.java
private float tweakAileronValue(float aileron) { aileron /= SensorManager.GRAVITY_EARTH; // System.out.println("AILERON=" + aileron); // if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { // aileron = aileron - (25f/32f); //0.78125 // }/* ww w . ja v a 2 s .com*/ aileron *= aileronMoltDefault; return valToMinMax(aileron); /* * if (aileron > 1.0f) aileron = 1.0f; else if (aileron < -1.0f) aileron * = -1.0f; return aileron; */ }
From source file:info.alni.comete.android.Comete.java
private float tweakElevatorValue(float elevator) { elevator /= SensorManager.GRAVITY_EARTH; elevator -= elevatorSubDefault;/*from w ww. j a v a2 s. c o m*/ elevator *= elevatorMoltDefault; return valToMinMax(elevator); /* * if (elevator > 1.0f) elevator = 1.0f; else if (elevator < -1.0f) * elevator = -1.0f; return elevator; */ }