1 |
package dk.thoerup.friendradar; |
package dk.thoerup.droidradar; |
2 |
|
|
3 |
|
|
4 |
import android.content.Context; |
import android.content.Context; |
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 |
|
|
|
static final float VERT_CORECTION = 5; |
|
|
|
|
18 |
int angle = 0; |
int angle = 0; |
19 |
Paint p = new Paint(); |
Paint p = new Paint(); |
20 |
Paint p2 = new Paint(); |
Paint p2 = new Paint(); |
97 |
canvas.drawColor(0xff000000); |
canvas.drawColor(0xff000000); |
98 |
canvas.drawLine(hcenter-5, vcenter-5, hcenter+5, vcenter+5, p); |
canvas.drawLine(hcenter-5, vcenter-5, hcenter+5, vcenter+5, p); |
99 |
canvas.drawLine(hcenter-5, vcenter+5, hcenter+5, vcenter-5, p); |
canvas.drawLine(hcenter-5, vcenter+5, hcenter+5, vcenter-5, p); |
100 |
canvas.drawCircle(hcenter, vcenter+5, 40, p); |
canvas.drawCircle(hcenter, vcenter, 40, p); |
101 |
canvas.drawCircle(hcenter, vcenter+5, 80, p); |
canvas.drawCircle(hcenter, vcenter, 80, p); |
102 |
canvas.drawCircle(hcenter, vcenter+5, 115, p); |
canvas.drawCircle(hcenter, vcenter, 115, p); |
103 |
canvas.drawCircle(hcenter, vcenter+5, 150, p); |
canvas.drawCircle(hcenter, vcenter, 150, p); |
104 |
|
|
105 |
canvas.drawText(distanceText1, (width-textWidth1)/2, vcenter+40+6, p3); |
canvas.drawText(distanceText1, (width-textWidth1)/2, vcenter+40+1, p3); |
106 |
canvas.drawText(distanceText2, (width-textWidth2)/2, vcenter+80+6, p3); |
canvas.drawText(distanceText2, (width-textWidth2)/2, vcenter+80+1, p3); |
107 |
canvas.drawText(distanceText3, (width-textWidth3)/2, vcenter+115+6, p3); |
canvas.drawText(distanceText3, (width-textWidth3)/2, vcenter+115+1, p3); |
108 |
canvas.drawText(distanceText4, (width-textWidth4)/2, vcenter+150+6, p3); |
canvas.drawText(distanceText4, (width-textWidth4)/2, vcenter+150+1, p3); |
109 |
|
|
110 |
|
|
111 |
final float lineLength = 150; |
final float lineLength = 150; |
114 |
|
|
115 |
double base = (Math.sin(angle/360.0)*lineLength) + (float)hcenter; |
double base = (Math.sin(angle/360.0)*lineLength) + (float)hcenter; |
116 |
double height = (Math.cos(angle/360.0)*lineLength) + (float)vcenter; |
double height = (Math.cos(angle/360.0)*lineLength) + (float)vcenter; |
|
height += VERT_CORECTION; |
|
117 |
|
|
118 |
|
|
119 |
canvas.drawLine(hcenter, vcenter, (float)base, (float)height, p2); |
canvas.drawLine(hcenter, vcenter, (float)base, (float)height, p2); |
299 |
vertCathesis += vcenter; |
vertCathesis += vcenter; |
300 |
horzCathesis += hcenter; |
horzCathesis += hcenter; |
301 |
|
|
|
vertCathesis += VERT_CORECTION; |
|
|
|
|
302 |
canvas.drawCircle( (float)horzCathesis, (float)vertCathesis, 3, p3); |
canvas.drawCircle( (float)horzCathesis, (float)vertCathesis, 3, p3); |
303 |
|
|
304 |
} |
} |