/[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

android/FriendRadar/src/dk/thoerup/droidradar/RadarView.java revision 275 by torben, Mon Aug 24 18:30:30 2009 UTC android/DroidRadar/src/dk/thoerup/droidradar/RadarView.java revision 281 by torben, Tue Aug 25 19:00:58 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          Thread t;          List<DroidBean> droidBeans;
55            
56            DroidLocator locator = new DroidLocator();
57    
58            long imei;
59            
60            //Thread t;
61                    
62          public RadarView(Context context) {          public RadarView(Context context) {
63                  super(context);                  super(context);
# Line 87  public class RadarView extends SurfaceVi Line 96  public class RadarView extends SurfaceVi
96                  surfaceHolder = this.getHolder();                  surfaceHolder = this.getHolder();
97                  surfaceHolder.addCallback(this);                  surfaceHolder.addCallback(this);
98                                    
                 t = new Thread(this);  
99                                    
100                  updateDistanceTexts();                  updateDistanceTexts();
101          }          }
# Line 156  public class RadarView extends SurfaceVi Line 164  public class RadarView extends SurfaceVi
164                  hcenter = width / 2;                  hcenter = width / 2;
165                  vcenter = hcenter + 20;                  vcenter = hcenter + 20;
166                                    
167                  t.start();                  mRun = true;
168                    Thread drawThread = new Thread(this);
169                    
170                    drawThread.start();
171                    locator.setDroidsLocatedListener(this);
172                    locator.setContinue(true);
173                    Thread locatorThread = new Thread(locator);
174                    locatorThread.start();
175          }          }
176    
177    
# Line 164  public class RadarView extends SurfaceVi Line 179  public class RadarView extends SurfaceVi
179          public void surfaceDestroyed(SurfaceHolder holder) { //surfaceholder.CallBack          public void surfaceDestroyed(SurfaceHolder holder) { //surfaceholder.CallBack
180                  Log.i("surfacDestroyed()","-");                  Log.i("surfacDestroyed()","-");
181          mRun = false;          mRun = false;
182            locator.setContinue(false);
183          }          }
184                    
185      public void run() {      public void run() {
# Line 188  public class RadarView extends SurfaceVi Line 204  public class RadarView extends SurfaceVi
204                  Thread.sleep(20);                  Thread.sleep(20);
205              } catch (InterruptedException e) {}              } catch (InterruptedException e) {}
206          }          }
207            Log.i("RadarView", "Draw thread exiting");
208      }      }
209    
210            
# Line 250  public class RadarView extends SurfaceVi Line 267  public class RadarView extends SurfaceVi
267          void setCurrentLocation(Location loc) {          void setCurrentLocation(Location loc) {
268                  currentLocation = loc;                  currentLocation = loc;
269                  gpsText = formatLength( (int)loc.getAccuracy());                  gpsText = formatLength( (int)loc.getAccuracy());
270                    
271                    locator.setCurrentLocation(loc);
272                    
273          }          }
274                    
275          void setHeading(int head) {          void setHeading(int head) {
# Line 257  public class RadarView extends SurfaceVi Line 277  public class RadarView extends SurfaceVi
277                  headingText = "" + head;                  headingText = "" + head;
278          }          }
279                    
280            public void setImei(long imei) {
281                    this.imei = imei;
282                    locator.setImei(imei);
283            }
284            
285          void drawLocations(Canvas canvas) {          void drawLocations(Canvas canvas) {
286                  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);  
287                                                    
288                          loc.setLatitude(56.398577); //Langå                          for(DroidBean droid : droidBeans) {
289                          loc.setLongitude(9.899515);                                  drawLocation(canvas, droid);
290                                                    }
                           
                         drawLocation(canvas, loc);  
291                  }                  }
292          }          }
293                    
294          void drawLocation(Canvas canvas, Location location) {          void drawLocation(Canvas canvas, DroidBean droid) {
295                    
296                    Location location = droid.getLocation();
297                                    
298                  float bearing = currentLocation.bearingTo(location);                  float bearing = currentLocation.bearingTo(location);
299                  float distance = currentLocation.distanceTo(location);                  float distance = currentLocation.distanceTo(location);
# Line 299  public class RadarView extends SurfaceVi Line 318  public class RadarView extends SurfaceVi
318                          vertCathesis += vcenter;                          vertCathesis += vcenter;
319                          horzCathesis += hcenter;                          horzCathesis += hcenter;
320                                                    
321                            droid.setGuiX((int)horzCathesis);
322                            droid.setGuiY((int)vertCathesis);
323                            
324                          canvas.drawCircle( (float)horzCathesis, (float)vertCathesis, 3, p3);                          canvas.drawCircle( (float)horzCathesis, (float)vertCathesis, 3, p3);
325                                                    
326                  }                  }
327          }          }
328    
329    
330            @Override
331            public void onDroidsLocated() { //callback
332                    droidBeans = locator.getDroids();
333                    Log.i("RadarView", "OnDroidsLocated");
334            }
335                    
336  }  }

Legend:
Removed from v.275  
changed lines
  Added in v.281

  ViewVC Help
Powered by ViewVC 1.1.20