当前位置: 首页>>代码示例>>Java>>正文


Java SensorManager.GRAVITY_EARTH属性代码示例

本文整理汇总了Java中android.hardware.SensorManager.GRAVITY_EARTH属性的典型用法代码示例。如果您正苦于以下问题:Java SensorManager.GRAVITY_EARTH属性的具体用法?Java SensorManager.GRAVITY_EARTH怎么用?Java SensorManager.GRAVITY_EARTH使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.hardware.SensorManager的用法示例。


在下文中一共展示了SensorManager.GRAVITY_EARTH属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getGravityFromOrientation

public static float[] getGravityFromOrientation(float[] orientation) {
    // components[0]: azimuth, rotation around the Z axis.
    // components[1]: pitch, rotation around the X axis.
    // components[2]: roll, rotation around the Y axis.
    float[] components = new float[3];

    // Find the gravity component of the X-axis
    // = g*-cos(pitch)*sin(roll);
    components[0] = (float) (SensorManager.GRAVITY_EARTH
            * -Math.cos(orientation[1]) * Math
            .sin(orientation[2]));

    // Find the gravity component of the Y-axis
    // = g*-sin(pitch);
    components[1] = (float) (SensorManager.GRAVITY_EARTH * -Math
            .sin(orientation[1]));

    // Find the gravity component of the Z-axis
    // = g*cos(pitch)*cos(roll);
    components[2] = (float) (SensorManager.GRAVITY_EARTH
            * Math.cos(orientation[1]) * Math.cos(orientation[2]));

    return components;
}
 
开发者ID:KalebKE,项目名称:FSensor,代码行数:24,代码来源:Util.java

示例2: ShakeDetector

public ShakeDetector(Context context)
{
	try
	{
		shakeDetectorContext = context;
		
		sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
		
		previousAcceleration = SensorManager.GRAVITY_EARTH;
		currentAcceleration = SensorManager.GRAVITY_EARTH;
		acceleration = 0.00f;
	}
	catch (Exception e)
	{
		Log.e("ShakeDetector", "ShakeDetector : " + context.getString(R.string.log_shake_detector_error_create) + " : " + e);
		databaseManager.insertLog(context, "" + context.getString(R.string.log_shake_detector_error_create), new Date().getTime(), 1, false);
	}
}
 
开发者ID:vassela,项目名称:AC2RD,代码行数:18,代码来源:ShakeDetector.java

示例3: onSensorChanged

@Override
public void onSensorChanged(SensorEvent event) {
  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 close to 1 when there is no movement.
  float gForce = (float) Math.sqrt(gX * gX + gY * gY + gZ * gZ);

  if (gForce > SHAKE_THRESHOLD_GRAVITY) {
    final long now = System.currentTimeMillis();
    // ignore shake events too close to each other (500ms)
    if (mShakeTimestamp + SHAKE_SLOP_TIME_MS > now) {
      return;
    }
    mShakeTimestamp = now;
    this.onShakeListener.onShake();
  }
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:23,代码来源:ShakeDetector.java

示例4: getAccelerometer

private void getAccelerometer(SensorEvent event) {
    float[] values = event.values;
    // Movement
    final float x = values[0];
    float y = values[1];
    float z = values[2];
    float g = (float) Math.sqrt(x * x + y * y + z * z);
    float accelationSquareRoot = (x * x + y * y + z * z)
            / (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH);
    xSensorGraph.addSensorData(x);
    ySensorGraph.addSensorData(y);
    zSensorGraph.addSensorData(z);

    Random rand = new Random();
    int randomNumber = rand.nextInt(50);
    heartBeatGraph.drawHeartBeat(randomNumber < 2);

}
 
开发者ID:khoatd92,项目名称:sensor-graph-opengl-es-android,代码行数:18,代码来源:SensorDemoActivity.java

示例5: getAccelerometer

private void getAccelerometer(SensorEvent event) {
    float[] values = event.values;
    // Movement
    double x = values[0];
    double y = values[1];
    double z = values[2];

    double accelerationSquareRoot = (x * x + y * y + z * z) / (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH);
    double acceleration = Math.sqrt(accelerationSquareRoot);

    accelerationQueue.offer(acceleration);
}
 
开发者ID:Subarata-Talukder,项目名称:Android-Real-Time-Chart,代码行数:12,代码来源:MainActivity.java

示例6: onSensorChanged

@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 close to 1 when there is no movement.
        float sum = gX * gX + gY * gY + gZ * gZ;
        float gForce = (float)Math.sqrt(Double.parseDouble(new Float(sum).toString()));

        if (gForce > SHAKE_THRESHOLD_GRAVITY) {
            final long now = System.currentTimeMillis();
            // ignore shake events too 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);
        }
    }
}
 
开发者ID:Captwalloper,项目名称:NUI_Project,代码行数:35,代码来源:ShakeDetector.java

示例7: SplineOverScroller

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.618f; // look and feel tuning
    /*
    mIsPerfBoostEnabled = context.getResources().getBoolean(
            com.android.internal.R.bool.config_enableCpuBoostForOverScrollerFling);
    */
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}
 
开发者ID:anmingyu11,项目名称:OverScrollableRecyclerView-Method1,代码行数:14,代码来源:AScroller.java

示例8: onSensorChanged

@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 close to 1 when there is no movement.
        float gForce = (float) Math.sqrt(gX * gX + gY * gY + gZ * gZ);

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

            mShakeTimestamp = now;

            mListener.onShake();
        }
    }
}
 
开发者ID:jonathansautter,项目名称:AutoOff,代码行数:28,代码来源:ShakeDetector.java

示例9: SplineOverScroller

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
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:8,代码来源:OverScroller.java

示例10: detectShake

private void detectShake(SensorEvent event) {
    long now = System.currentTimeMillis();

    if((now - mShakeTime) > SHAKE_WAIT_TIME_MS) {
        mShakeTime = now;

        float gX = event.values[0] / SensorManager.GRAVITY_EARTH;
        float gY = event.values[1] / SensorManager.GRAVITY_EARTH;
        float gZ = event.values[2] / SensorManager.GRAVITY_EARTH;

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

        // Change background color if gForce exceeds threshold;
        // otherwise, reset the color

        if(LocalStoreUtils.getShakeIntensity(this).equals("1")) {
            SHAKE_THRESHOLD = 1.1f;
        } else {
            SHAKE_THRESHOLD = Float.parseFloat(LocalStoreUtils.getShakeIntensity(this));
        }

        Log.e("SHAKE_THRESHOLD", "->"+SHAKE_THRESHOLD);

        if(gForce > SHAKE_THRESHOLD) {
            sendShakeEventToPhone();
        }
    }
}
 
开发者ID:squareboat,项目名称:Excuser,代码行数:29,代码来源:AccelerometerSensorService.java

示例11: computeDeceleration

private float computeDeceleration(float friction) {
    return SensorManager.GRAVITY_EARTH   // g (m/s^2)
                  * 39.37f               // inch/meter
                  * mPpi                 // pixels per inch
                  * friction;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:6,代码来源:LauncherScroller.java

示例12: computeDeceleration

private float computeDeceleration(float friction) {
    return SensorManager.GRAVITY_EARTH   // g (m/s^2)
            * 39.37f               // inch/meter
            * mPpi                 // pixels per inch
            * friction;
}
 
开发者ID:h6ah4i,项目名称:android-numberpickercompat,代码行数:6,代码来源:Scroller.java


注:本文中的android.hardware.SensorManager.GRAVITY_EARTH属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。