Skip to content

Instantly share code, notes, and snippets.

@iewnait
iewnait / gist:2038706
Created March 14, 2012 19:04
WIMM Accelerometer sample code
@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)+
@iewnait
iewnait / gist:2047273
Created March 15, 2012 22:02
WorkAround for WIMM Magnetometer bug.
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);
@iewnait
iewnait / gist:2126588
Created March 19, 2012 20:20
XML Manifest file for AccelerometerDemo code on WIMM One Developer kit
<?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" />
@iewnait
iewnait / gist:2126862
Created March 19, 2012 20:31
Activity Class for AccelerometerDemo App on WIMM ONE
/*
* 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;
@iewnait
iewnait / gist:2126869
Created March 19, 2012 20:32
Main Layout file for AccelerometerDemo App
<?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"/>
@iewnait
iewnait / gist:2138807
Created March 20, 2012 18:01
onSensorChanged() for accelerometer demo
@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]);
}
}
}
@iewnait
iewnait / gist:2138839
Created March 20, 2012 18:03
onResume and onPause for AccelerometerDemo
@Override
protected void onResume() {
super.onResume();
setAccelerometerUpdatesEnabled(true);
}
@Override
protected void onPause() {
super.onPause();
setAccelerometerUpdatesEnabled(false);
@iewnait
iewnait / gist:2151560
Created March 21, 2012 19:16
XML Manifest file for Magnetometer code on WIMM One Developer kit
<?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" />
@iewnait
iewnait / gist:2151740
Created March 21, 2012 19:30
Activity Class for MagnetometerDemo App on WIMM ONE
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;
/*
@iewnait
iewnait / gist:2154078
Created March 21, 2012 23:19
onSensorChanged() for MagnetometerDemo
@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