Anonymous avatar Anonymous committed 192a0d5

Initial proof-of-concept retrieving sensor data.

Comments (0)

Files changed (2)

AndroidManifest.xml

+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+      package="to.rcpt.icarus"
+      android:versionCode="1"
+      android:versionName="1.0">
+    <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
+        <activity android:name=".IcarusMission"
+                  android:label="@string/app_name">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+    </application>
+    <uses-sdk android:minSdkVersion="4" />
+
+
+
+<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
+</manifest> 

src/to/rcpt/icarus/IcarusMission.java

+package to.rcpt.icarus;
+
+import java.util.List;
+
+import android.app.Activity;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.location.Criteria;
+import android.location.Location;
+import android.location.LocationListener;
+import android.location.LocationManager;
+import android.os.Bundle;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class IcarusMission extends Activity implements LocationListener {
+	private class SensorEventAdapter implements SensorEventListener {
+		private TextView tv;
+		
+		public SensorEventAdapter(TextView tv) {
+			this.tv = tv;
+		}
+		
+		public void onSensorChanged(SensorEvent event) {
+			String s = event.sensor.getName() + " " + event.timestamp;
+			for(float f: event.values) {
+				s += " " + f;
+			}
+			tv.setText(s);
+		}
+
+		public void onAccuracyChanged(Sensor sensor, int accuracy) {
+			// like, WTF cares?
+		}
+	}
+
+	LocationManager gps;
+	private TextView tv;
+	private LinearLayout ll;
+	private int index;
+	
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+    	index = 0;
+        super.onCreate(savedInstanceState);
+        ll = new LinearLayout(this);
+        ll.setOrientation(LinearLayout.VERTICAL);
+        tv = new TextView(this);
+        tv.setText("Hello, Icarus");
+        ll.addView(tv, index++);
+        setContentView(ll);
+        SensorManager sensors = (SensorManager) this.getSystemService(SENSOR_SERVICE);
+        List<Sensor> sensorList = sensors.getSensorList(Sensor.TYPE_ALL);
+        for(Sensor s: sensorList) {
+        	tv = new TextView(this);
+        	tv.setText(s.getName());
+        	ll.addView(tv, index++);
+        	sensors.registerListener(new SensorEventAdapter(tv), s, 
+        			SensorManager.SENSOR_DELAY_UI);
+        }
+		gps = (LocationManager) this.getSystemService(LOCATION_SERVICE);
+		Criteria c = new Criteria();
+		c.setAccuracy(Criteria.ACCURACY_FINE);
+		c.setAltitudeRequired(true);
+		c.setSpeedRequired(true);
+		String provider = gps.getBestProvider(c, true);
+		gps.requestLocationUpdates(provider, 0, 0, this);
+    }
+
+	public void onLocationChanged(Location l) {
+		TextView tv = (TextView) ll.getChildAt(0);
+		tv.setText(l.getTime() + " " + l.getLatitude() + "," + l.getLongitude() + " " + l.getAltitude());
+	}
+
+	public void onProviderDisabled(String provider) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	public void onProviderEnabled(String provider) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	public void onStatusChanged(String provider, int status, Bundle extras) {
+		// TODO Auto-generated method stub
+		
+	}
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.