本文整理汇总了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;
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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();
}
示例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();
}
}
}
示例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
}
示例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();
}
}
}
示例11: computeDeceleration
private float computeDeceleration(float friction) {
return SensorManager.GRAVITY_EARTH // g (m/s^2)
* 39.37f // inch/meter
* mPpi // pixels per inch
* friction;
}
示例12: computeDeceleration
private float computeDeceleration(float friction) {
return SensorManager.GRAVITY_EARTH // g (m/s^2)
* 39.37f // inch/meter
* mPpi // pixels per inch
* friction;
}