/[projects]/android/DroidRadar/src/dk/thoerup/droidradar/RadarActivity.java
ViewVC logotype

Annotation of /android/DroidRadar/src/dk/thoerup/droidradar/RadarActivity.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 277 - (hide annotations) (download)
Mon Aug 24 21:48:00 2009 UTC (14 years, 9 months ago) by torben
File size: 2835 byte(s)
Very ugly first implementation of backend enabled droidradar
1 torben 275 package dk.thoerup.droidradar;
2 torben 264
3     import java.util.List;
4    
5 torben 275 import dk.thoerup.droidradar.R;
6    
7 torben 264 import android.app.Activity;
8     import android.content.Context;
9     import android.hardware.Sensor;
10     import android.hardware.SensorEvent;
11     import android.hardware.SensorEventListener;
12     import android.hardware.SensorManager;
13     import android.location.Location;
14     import android.location.LocationListener;
15     import android.location.LocationManager;
16     import android.net.UrlQuerySanitizer.ValueSanitizer;
17     import android.os.Bundle;
18 torben 270 import android.telephony.TelephonyManager;
19 torben 264 import android.util.Log;
20    
21     public class RadarActivity extends Activity implements LocationListener {
22    
23     LocationManager locManager;
24     SensorManager sensorManager;
25    
26 torben 270 String deviceId;
27    
28 torben 264 RadarView radar;
29     @Override
30     public void onCreate(Bundle savedInstanceState) {
31     super.onCreate(savedInstanceState);
32     setContentView(R.layout.main);
33     radar = (RadarView) findViewById(R.id.radar);
34    
35     locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
36 torben 270 sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
37    
38    
39     TelephonyManager tlf = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
40     deviceId = tlf.getDeviceId(); //get IMEI number
41 torben 277 radar.setImei( Long.parseLong(deviceId) );
42 torben 270
43 torben 264 }
44    
45    
46    
47    
48     @Override
49     protected void onResume() {
50     super.onResume();
51    
52     if (locManager.isProviderEnabled("gps")) {
53     locManager.requestLocationUpdates("gps", 0, 0, this);
54     } else {
55     // ToDo: alert the user about missing gps provider
56     }
57    
58     List<Sensor> orientationSensors = sensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
59     Log.e("sensors1", "sensor count" + orientationSensors.size());
60     if (orientationSensors.size() > 0) {
61     sensorManager.registerListener(orientationListener, orientationSensors.get(0), SensorManager.SENSOR_DELAY_NORMAL);
62     } else {
63     // ToDo: alert the user about missing orientation sensor
64     Log.e("sensor", "no orientation sensor");
65     }
66 torben 266
67 torben 264 }
68    
69    
70    
71     @Override
72     protected void onPause() {
73     super.onPause();
74    
75     locManager.removeUpdates(this);
76     sensorManager.unregisterListener(orientationListener);
77     }
78    
79    
80    
81    
82     @Override
83     public void onLocationChanged(Location location) {
84     radar.setCurrentLocation(location);
85     }
86    
87    
88    
89    
90     @Override
91     public void onProviderDisabled(String provider) {
92     }
93    
94    
95    
96    
97     @Override
98     public void onProviderEnabled(String provider) {
99     }
100    
101    
102    
103    
104     @Override
105     public void onStatusChanged(String provider, int status, Bundle extras) {
106     }
107    
108     SensorEventListener orientationListener = new SensorEventListener() {
109    
110     @Override
111     public void onSensorChanged(SensorEvent event) {
112     radar.setHeading( (int)event.values[0]);
113     }
114    
115     @Override
116     public void onAccuracyChanged(Sensor sensor, int accuracy) {
117     }
118 torben 266 };
119 torben 264 }

  ViewVC Help
Powered by ViewVC 1.1.20