Java Code Examples for android.hardware.SensorManager#GRAVITY_EARTH

The following examples show how to use android.hardware.SensorManager#GRAVITY_EARTH . 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: OverScroller.java    From Mupdf with Apache License 2.0 5 votes vote down vote up
SplineOverScroller(Context context) {
    mFinished = true;
    final float ppi = context.getResources().getDisplayMetrics().density * 160.0f;
    mPhysicalCoeff = SensorManager.GRAVITY_EARTH // g (m/s^2)
            * 39.37f // inch/meter
            * ppi
            * 0.84f; // look and feel tuning
}
 
Example 2
Source File: GestureManager.java    From XImageView with Apache License 2.0 5 votes vote down vote up
public XGestureDetector(Context context, GestureManager listener)
{
    super(context, listener);

    float density = context.getResources().getDisplayMetrics().density;
    float dpi = density * 160.0f;
    mPhysicalCoeff = SensorManager.GRAVITY_EARTH  * 39.37f * dpi * 0.84f;

    mScaleDetector = new ScaleGestureDetector(context, listener);
}
 
Example 3
Source File: BaseBehavior.java    From CollapsingRefresh with Apache License 2.0 5 votes vote down vote up
private void init(final AppBarLayout child) {
	this.mAppBarLayout = child;
	final float ppi = child.getResources().getDisplayMetrics().density * 160.0f;
	mPhysicalCoeff = SensorManager.GRAVITY_EARTH // g (m/s^2)
			* 39.37f // inch/meter
			* ppi
			* 0.84f; // look and feel tuning
}
 
Example 4
Source File: VelocityScroller.java    From VelocityViewPager with Apache License 2.0 5 votes vote down vote up
SplineOverScroller(Context context) {
    mFinished = true;
    final float ppi = context.getResources().getDisplayMetrics().density * 160.0f;
    mPhysicalCoeff = SensorManager.GRAVITY_EARTH // g (m/s^2)
            * 39.37f // inch/meter
            * ppi
            * 0.84f; // look and feel tuning
}
 
Example 5
Source File: SnappyLinearLayoutManager.java    From Ouroboros with GNU General Public License v3.0 5 votes vote down vote up
private void calculateDeceleration(Context context) {
    deceleration = SensorManager.GRAVITY_EARTH // g (m/s^2)
            * 39.3700787 // inches per meter
            // pixels per inch. 160 is the "default" dpi, i.e. one dip is one pixel on a 160 dpi
            // screen
            * context.getResources().getDisplayMetrics().density * 160.0f * FRICTION;
}
 
Example 6
Source File: ShakeDetector.java    From applivery-android-sdk with Apache License 2.0 5 votes vote down vote up
@Override public void onSensorChanged(SensorEvent event) {

    if (mListener != null) {
      float x = event.values[0];
      float y = event.values[1];
      float z = event.values[2];

      float gX = x / SensorManager.GRAVITY_EARTH;
      float gY = y / SensorManager.GRAVITY_EARTH;
      float gZ = z / SensorManager.GRAVITY_EARTH;

      // gForce will be applivery_close to 1 when there is no movement.
      double gForce = Math.sqrt(gX * gX + gY * gY + gZ * gZ);

      if (gForce > SHAKE_THRESHOLD_GRAVITY) {
        final long now = System.currentTimeMillis();
        // ignore shake events too applivery_close to each other (500ms)
        if (mShakeTimestamp + SHAKE_SLOP_TIME_MS > now) {
          return;
        }

        // reset the shake count after 3 seconds of no shakes
        if (mShakeTimestamp + SHAKE_COUNT_RESET_TIME_MS < now) {
          mShakeCount = 0;
        }

        mShakeTimestamp = now;
        mShakeCount++;

        mListener.onShake(mShakeCount);
      }
    }
  }
 
Example 7
Source File: MainActivity.java    From connectivity-samples with Apache License 2.0 5 votes vote down vote up
/** The device has moved. We need to decide if it was intentional or not. */
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
  float x = sensorEvent.values[0];
  float y = sensorEvent.values[1];
  float z = sensorEvent.values[2];

  float gX = x / SensorManager.GRAVITY_EARTH;
  float gY = y / SensorManager.GRAVITY_EARTH;
  float gZ = z / SensorManager.GRAVITY_EARTH;

  double gForce = Math.sqrt(gX * gX + gY * gY + gZ * gZ);

  if (gForce > SHAKE_THRESHOLD_GRAVITY && getState() == State.DISCOVERING) {
    logD("Device shaken");
    vibrate();
    setState(State.ADVERTISING);
    postDelayed(mDiscoverRunnable, ADVERTISING_DURATION);
  }
}
 
Example 8
Source File: StackScroller.java    From 365browser with Apache License 2.0 5 votes vote down vote up
SplineStackScroller(Context context) {
    mFinished = true;
    final float ppi = context.getResources().getDisplayMetrics().density * 160.0f;
    mPhysicalCoeff = SensorManager.GRAVITY_EARTH // g (m/s^2)
            * 39.37f // inch/meter
            * ppi * 0.84f; // look and feel tuning
}
 
Example 9
Source File: VelocityScroller.java    From Muzesto with GNU General Public License v3.0 5 votes vote down vote up
SplineOverScroller(Context context) {
    mFinished = true;
    final float ppi = context.getResources().getDisplayMetrics().density * 160.0f;
    mPhysicalCoeff = SensorManager.GRAVITY_EARTH // g (m/s^2)
            * 39.37f // inch/meter
            * ppi
            * 0.84f; // look and feel tuning
}
 
Example 10
Source File: LauncherScroller.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
private float computeDeceleration(float friction) {
    return SensorManager.GRAVITY_EARTH   // g (m/s^2)
                  * 39.37f               // inch/meter
                  * mPpi                 // pixels per inch
                  * friction;
}
 
Example 11
Source File: LauncherScroller.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
private float computeDeceleration(float friction) {
    return SensorManager.GRAVITY_EARTH   // g (m/s^2)
                  * 39.37f               // inch/meter
                  * mPpi                 // pixels per inch
                  * friction;
}
 
Example 12
Source File: GravityParticleInitializer.java    From tilt-game-android with MIT License 4 votes vote down vote up
public GravityParticleInitializer() {
	super(0, SensorManager.GRAVITY_EARTH);
}
 
Example 13
Source File: Scroller.java    From zen4android with MIT License 4 votes vote down vote up
private float computeDeceleration(float friction) {
    return SensorManager.GRAVITY_EARTH   // g (m/s^2)
                  * 39.37f               // inch/meter
                  * mPpi                 // pixels per inch
                  * friction;
}
 
Example 14
Source File: ScrollableScroller.java    From Scrollable with Apache License 2.0 4 votes vote down vote up
private float computeDeceleration(float friction) {
    return SensorManager.GRAVITY_EARTH   // g (m/s^2)
            * 39.37f               // inch/meter
            * mPpi                 // pixels per inch
            * friction;
}
 
Example 15
Source File: Scroller.java    From NumberPicker with MIT License 4 votes vote down vote up
private float computeDeceleration(float friction) {
    return SensorManager.GRAVITY_EARTH   // g (m/s^2)
            * 39.37f               // inch/meter
            * mPpi                 // pixels per inch
            * friction;
}
 
Example 16
Source File: Scroller.java    From WayHoo with Apache License 2.0 4 votes vote down vote up
private float computeDeceleration(float friction) {
    return SensorManager.GRAVITY_EARTH   // g (m/s^2)
                  * 39.37f               // inch/meter
                  * mPpi                 // pixels per inch
                  * friction;
}
 
Example 17
Source File: GravityParticleInitializer.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public GravityParticleInitializer() {
	super(0, SensorManager.GRAVITY_EARTH);
}
 
Example 18
Source File: Scroller.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
private float computeDeceleration(float friction) {
    return SensorManager.GRAVITY_EARTH   // g (m/s^2)
                  * 39.37f               // inch/meter
                  * mPpi                 // pixels per inch
                  * friction;
}
 
Example 19
Source File: Scroller.java    From SwipeBack with Apache License 2.0 4 votes vote down vote up
private float computeDeceleration(float friction) {
    return SensorManager.GRAVITY_EARTH   // g (m/s^2)
                  * 39.37f               // inch/meter
                  * mPpi                 // pixels per inch
                  * friction;
}
 
Example 20
Source File: LauncherScroller.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
private float computeDeceleration(float friction) {
    return SensorManager.GRAVITY_EARTH   // g (m/s^2)
                  * 39.37f               // inch/meter
                  * mPpi                 // pixels per inch
                  * friction;
}