/[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 282 - (hide annotations) (download)
Wed Aug 26 12:42:01 2009 UTC (14 years, 9 months ago) by torben
File size: 2895 byte(s)
Vibration feedback if user tries to go beyond zoom limits
1 torben 275 package dk.thoerup.droidradar;
2 torben 264
3     import java.util.List;
4    
5     import android.app.Activity;
6     import android.content.Context;
7     import android.hardware.Sensor;
8     import android.hardware.SensorEvent;
9     import android.hardware.SensorEventListener;
10     import android.hardware.SensorManager;
11     import android.location.Location;
12     import android.location.LocationListener;
13     import android.location.LocationManager;
14     import android.os.Bundle;
15 torben 282 import android.os.Vibrator;
16 torben 270 import android.telephony.TelephonyManager;
17 torben 264 import android.util.Log;
18    
19     public class RadarActivity extends Activity implements LocationListener {
20    
21     LocationManager locManager;
22     SensorManager sensorManager;
23    
24 torben 270 String deviceId;
25    
26 torben 264 RadarView radar;
27     @Override
28     public void onCreate(Bundle savedInstanceState) {
29     super.onCreate(savedInstanceState);
30     setContentView(R.layout.main);
31     radar = (RadarView) findViewById(R.id.radar);
32    
33     locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
34 torben 270 sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
35    
36    
37     TelephonyManager tlf = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
38     deviceId = tlf.getDeviceId(); //get IMEI number
39 torben 277 radar.setImei( Long.parseLong(deviceId) );
40 torben 282
41     Vibrator vibrator = (Vibrator) getSystemService( Context.VIBRATOR_SERVICE);
42     radar.setVibrator(vibrator);
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