This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onSensorChanged(SensorEvent event) { | |
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { | |
float[] values = event.values; | |
// Movement | |
float xAxisValue = values[0]; | |
float yAxisValue = values[1]; | |
float zAxisValue = values[2]; | |
float resultant = (float) Math.sqrt(Math.pow(xAxisValue, 2)+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); | |
//Power on Accelerometer Sensor | |
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) | |
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_UI); | |
//Power on mMagnetometer Sensor | |
mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); | |
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_UI); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!-- Copyright (C) 2012 WIMM Labs Incorporated --> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:wimm="http://schemas.wimm.com/android" | |
package="com.wimm.demo.accelerometerdemo" | |
android:versionCode="1" | |
android:versionName="1.0" > | |
<uses-sdk android:minSdkVersion="7" /> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2012 WIMM Labs Incorporated | |
*/ | |
package com.wimm.demo.accelerometerdemo; | |
import android.content.BroadcastReceiver; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.content.IntentFilter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!-- Copyright (C) 2012 WIMM Labs Incorporated --> | |
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/textView" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:textColor="#000" | |
android:gravity="center" | |
android:text="@string/prompt"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onSensorChanged(SensorEvent event) { | |
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { | |
if (isShakeDetected(event)) { | |
// If we detected a shake, update to the next background color. | |
mBackgroundColorIndex = (mBackgroundColorIndex + 1) % mBackgroundColorArray.length; | |
mTargetView.setBackgroundColor(mBackgroundColorArray[mBackgroundColorIndex]); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onResume() { | |
super.onResume(); | |
setAccelerometerUpdatesEnabled(true); | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
setAccelerometerUpdatesEnabled(false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!-- Copyright (C) 2012 WIMM Labs Incorporated --> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:wimm="http://schemas.wimm.com/android" | |
package="com.wimm.demo.magnetometerdemo" | |
android:versionCode="1" | |
android:versionName="1.0" > | |
<uses-sdk android:minSdkVersion="7" /> | |
<uses-permission android:name="android.permission.WAKE_LOCK" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MagnetometerDemoActivity extends LauncherActivity implements SensorEventListener { | |
public static final String TAG = MagnetometerDemoActivity.class.getSimpleName(); | |
/** | |
* We could use Math.toDegrees(), but we can take away division from | |
* calculations by just multiplying by this static value instead. | |
*/ | |
public static float TO_DEGREES = (1 / (float) Math.PI) * 180; | |
/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onSensorChanged(SensorEvent event) { | |
switch (event.sensor.getType()) { | |
case Sensor.TYPE_ACCELEROMETER: | |
// We need both the acceleration and magnetometer data to determine | |
// compass rotation. Save these values. | |
mAccelerationVals = event.values.clone(); | |
break; | |
case Sensor.TYPE_MAGNETIC_FIELD: | |
// We need both the acceleration and magnetometer data to determine |
OlderNewer