13 |
import android.view.SurfaceView; |
import android.view.SurfaceView; |
14 |
|
|
15 |
//public class RadarView extends View { |
//public class RadarView extends View { |
16 |
public class RadarView extends SurfaceView implements SurfaceHolder.Callback, Runnable { |
public class RadarView extends SurfaceView implements SurfaceHolder.Callback, Runnable { |
17 |
|
|
18 |
|
static final float VERT_CORECTION = 5; |
19 |
|
|
20 |
int angle = 0; |
int angle = 0; |
21 |
Paint p = new Paint(); |
Paint p = new Paint(); |
22 |
Paint p2 = new Paint(); |
Paint p2 = new Paint(); |
41 |
int heading; |
int heading; |
42 |
String headingText = "-"; |
String headingText = "-"; |
43 |
|
|
44 |
|
|
45 |
|
int width; |
46 |
|
int height; |
47 |
|
int hcenter; |
48 |
|
int vcenter; |
49 |
|
|
50 |
|
|
51 |
boolean mRun = true; |
boolean mRun = true; |
95 |
} |
} |
96 |
|
|
97 |
protected void myDraw(Canvas canvas) { |
protected void myDraw(Canvas canvas) { |
|
int w = this.getWidth(); |
|
|
int h = this.getHeight(); |
|
|
int hcenter = w / 2; |
|
|
int vcenter = hcenter + 20; |
|
|
|
|
|
|
|
98 |
|
|
99 |
canvas.drawColor(0xff000000); |
canvas.drawColor(0xff000000); |
100 |
canvas.drawLine(hcenter-5, vcenter-5, hcenter+5, vcenter+5, p); |
canvas.drawLine(hcenter-5, vcenter-5, hcenter+5, vcenter+5, p); |
104 |
canvas.drawCircle(hcenter, vcenter+5, 115, p); |
canvas.drawCircle(hcenter, vcenter+5, 115, p); |
105 |
canvas.drawCircle(hcenter, vcenter+5, 150, p); |
canvas.drawCircle(hcenter, vcenter+5, 150, p); |
106 |
|
|
107 |
canvas.drawText(distanceText1, (w-textWidth1)/2, vcenter+40+6, p3); |
canvas.drawText(distanceText1, (width-textWidth1)/2, vcenter+40+6, p3); |
108 |
canvas.drawText(distanceText2, (w-textWidth2)/2, vcenter+80+6, p3); |
canvas.drawText(distanceText2, (width-textWidth2)/2, vcenter+80+6, p3); |
109 |
canvas.drawText(distanceText3, (w-textWidth3)/2, vcenter+115+6, p3); |
canvas.drawText(distanceText3, (width-textWidth3)/2, vcenter+115+6, p3); |
110 |
canvas.drawText(distanceText4, (w-textWidth4)/2, vcenter+150+6, p3); |
canvas.drawText(distanceText4, (width-textWidth4)/2, vcenter+150+6, p3); |
111 |
|
|
112 |
final float correction = 5; |
|
113 |
final float lineLength = 150; |
final float lineLength = 150; |
114 |
angle -= 6; |
angle -= 6; |
115 |
|
|
116 |
|
|
117 |
double base = (Math.sin(angle/360.0)*lineLength) + (float)hcenter; |
double base = (Math.sin(angle/360.0)*lineLength) + (float)hcenter; |
118 |
double height = (Math.cos(angle/360.0)*lineLength) + (float)vcenter; |
double height = (Math.cos(angle/360.0)*lineLength) + (float)vcenter; |
119 |
height += correction; |
height += VERT_CORECTION; |
120 |
|
|
121 |
|
|
122 |
canvas.drawLine(hcenter, vcenter, (float)base, (float)height, p2); |
canvas.drawLine(hcenter, vcenter, (float)base, (float)height, p2); |
153 |
@Override |
@Override |
154 |
public void surfaceCreated(SurfaceHolder holder) { //surfaceholder.CallBack |
public void surfaceCreated(SurfaceHolder holder) { //surfaceholder.CallBack |
155 |
Log.i("surfacCreated()","-"); |
Log.i("surfacCreated()","-"); |
156 |
|
|
157 |
|
width = this.getWidth(); |
158 |
|
height = this.getHeight(); |
159 |
|
hcenter = width / 2; |
160 |
|
vcenter = hcenter + 20; |
161 |
|
|
162 |
t.start(); |
t.start(); |
163 |
} |
} |
164 |
|
|
241 |
} |
} |
242 |
|
|
243 |
String formatLength(int meters) { |
String formatLength(int meters) { |
244 |
|
if (meters == 1500) //yuck, special cases !!! |
245 |
|
return "1.5 km"; |
246 |
|
|
247 |
if (meters>=1000) |
if (meters>=1000) |
248 |
return "" + (meters/1000) + " km"; |
return "" + (meters/1000) + " km"; |
249 |
else |
else |
278 |
} |
} |
279 |
|
|
280 |
void drawLocation(Canvas canvas, Location location) { |
void drawLocation(Canvas canvas, Location location) { |
|
int w = this.getWidth(); |
|
|
int h = this.getHeight(); |
|
|
int hcenter = w / 2; |
|
|
int vcenter = hcenter + 20; |
|
281 |
|
|
282 |
float bearing = currentLocation.bearingTo(location); |
float bearing = currentLocation.bearingTo(location); |
283 |
float distance = currentLocation.distanceTo(location); |
float distance = currentLocation.distanceTo(location); |
295 |
double hypotenuse = (distance / (distanceBase*4.0)) * 150.0; |
double hypotenuse = (distance / (distanceBase*4.0)) * 150.0; |
296 |
double vertCathesis = Math.sin(bearingRad)*hypotenuse; |
double vertCathesis = Math.sin(bearingRad)*hypotenuse; |
297 |
double horzCathesis = Math.cos(bearingRad)*hypotenuse; |
double horzCathesis = Math.cos(bearingRad)*hypotenuse; |
298 |
|
|
299 |
|
|
300 |
//vertCathesis *= -1.0; |
//vertCathesis *= -1.0; |
301 |
|
|
302 |
vertCathesis += vcenter; |
vertCathesis += vcenter; |
303 |
horzCathesis += hcenter; |
horzCathesis += hcenter; |
304 |
|
|
305 |
|
vertCathesis += VERT_CORECTION; |
306 |
|
|
307 |
canvas.drawCircle( (float)horzCathesis, (float)vertCathesis, 3, p3); |
canvas.drawCircle( (float)horzCathesis, (float)vertCathesis, 3, p3); |
308 |
|
|
309 |
} |
} |