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

Diff of /android/DroidRadar/src/dk/thoerup/droidradar/RadarView.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 276 by torben, Mon Aug 24 18:32:10 2009 UTC revision 277 by torben, Mon Aug 24 21:48:00 2009 UTC
# Line 1  Line 1 
1  package dk.thoerup.droidradar;  package dk.thoerup.droidradar;
2    
3    
4    import java.util.Date;
5    import java.util.List;
6    
7  import android.content.Context;  import android.content.Context;
8  import android.graphics.Canvas;  import android.graphics.Canvas;
9  import android.graphics.Paint;  import android.graphics.Paint;
# Line 13  import android.view.SurfaceHolder; Line 16  import android.view.SurfaceHolder;
16  import android.view.SurfaceView;  import android.view.SurfaceView;
17    
18  //public class RadarView extends View {  //public class RadarView extends View {
19  public class RadarView extends SurfaceView implements SurfaceHolder.Callback, Runnable {  public class RadarView extends SurfaceView implements SurfaceHolder.Callback, Runnable, DroidLocator.DroidsLocatedListener {
20                    
21          int angle = 0;          int angle = 0;
22          Paint p = new Paint();          Paint p = new Paint();
# Line 48  public class RadarView extends SurfaceVi Line 51  public class RadarView extends SurfaceVi
51    
52          boolean mRun = true;          boolean mRun = true;
53                    
54            List<DroidBean> droidBeans;
55            
56            DroidLocator locator = new DroidLocator();
57    
58            long imei;
59            
60          Thread t;          Thread t;
61                    
62          public RadarView(Context context) {          public RadarView(Context context) {
# Line 157  public class RadarView extends SurfaceVi Line 166  public class RadarView extends SurfaceVi
166                  vcenter = hcenter + 20;                  vcenter = hcenter + 20;
167                                    
168                  t.start();                  t.start();
169                    locator.setDroidsLocatedListener(this);
170                    Thread locatorThread = new Thread(locator);
171                    locatorThread.start();
172          }          }
173    
174    
# Line 164  public class RadarView extends SurfaceVi Line 176  public class RadarView extends SurfaceVi
176          public void surfaceDestroyed(SurfaceHolder holder) { //surfaceholder.CallBack          public void surfaceDestroyed(SurfaceHolder holder) { //surfaceholder.CallBack
177                  Log.i("surfacDestroyed()","-");                  Log.i("surfacDestroyed()","-");
178          mRun = false;          mRun = false;
179            locator.stop();
180          }          }
181                    
182      public void run() {      public void run() {
# Line 250  public class RadarView extends SurfaceVi Line 263  public class RadarView extends SurfaceVi
263          void setCurrentLocation(Location loc) {          void setCurrentLocation(Location loc) {
264                  currentLocation = loc;                  currentLocation = loc;
265                  gpsText = formatLength( (int)loc.getAccuracy());                  gpsText = formatLength( (int)loc.getAccuracy());
266                    
267                    locator.setCurrentLocation(loc);
268                    
269          }          }
270                    
271          void setHeading(int head) {          void setHeading(int head) {
# Line 257  public class RadarView extends SurfaceVi Line 273  public class RadarView extends SurfaceVi
273                  headingText = "" + head;                  headingText = "" + head;
274          }          }
275                    
276            public void setImei(long imei) {
277                    this.imei = imei;
278                    locator.setImei(imei);
279            }
280            
281          void drawLocations(Canvas canvas) {          void drawLocations(Canvas canvas) {
282                  if (currentLocation != null) {                  if (currentLocation != null && droidBeans != null) {
                         Location loc = new Location("gps");  
                         loc.setLatitude(56.394908); //Hedemøllevej  
                         loc.setLongitude(9.666356);  
                           
         //              loc.setLatitude(56.298307); //Kongensbro  
         //              loc.setLongitude(9.669293);  
283                                                    
284                          loc.setLatitude(56.398577); //Langå                          for(DroidBean droid : droidBeans) {
285                          loc.setLongitude(9.899515);                                  drawLocation(canvas, droid);
286                                                    }
                           
                         drawLocation(canvas, loc);  
287                  }                  }
288          }          }
289                    
290          void drawLocation(Canvas canvas, Location location) {          void drawLocation(Canvas canvas, DroidBean droid) {
291                    
292                    Location location = droid.getLocation();
293                                    
294                  float bearing = currentLocation.bearingTo(location);                  float bearing = currentLocation.bearingTo(location);
295                  float distance = currentLocation.distanceTo(location);                  float distance = currentLocation.distanceTo(location);
# Line 299  public class RadarView extends SurfaceVi Line 314  public class RadarView extends SurfaceVi
314                          vertCathesis += vcenter;                          vertCathesis += vcenter;
315                          horzCathesis += hcenter;                          horzCathesis += hcenter;
316                                                    
317                            droid.setGuiX((int)horzCathesis);
318                            droid.setGuiY((int)vertCathesis);
319                            
320                          canvas.drawCircle( (float)horzCathesis, (float)vertCathesis, 3, p3);                          canvas.drawCircle( (float)horzCathesis, (float)vertCathesis, 3, p3);
321                                                    
322                  }                  }
323          }          }
324    
325    
326            @Override
327            public void onDroidsLocated() { //callback
328                    droidBeans = locator.getDroids();
329                    Log.i("RadarView", "OnDroidsLocated");
330            }
331                    
332  }  }

Legend:
Removed from v.276  
changed lines
  Added in v.277

  ViewVC Help
Powered by ViewVC 1.1.20