1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.sweetiepiggy.raspberrybusmalaysia; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Iterator; |
24 |
|
|
25 |
|
import android.content.Context; |
26 |
|
import android.database.Cursor; |
27 |
|
import android.graphics.Canvas; |
28 |
|
import android.graphics.Paint; |
29 |
|
import android.graphics.Path; |
30 |
|
import android.graphics.Point; |
31 |
|
|
32 |
|
import com.google.android.maps.GeoPoint; |
33 |
|
import com.google.android.maps.MapView; |
34 |
|
import com.google.android.maps.Overlay; |
35 |
|
import com.google.android.maps.Projection; |
36 |
|
|
|
|
| 96,3% |
Uncovered Elements: 2 (54) |
Complexity: 8 |
Complexity Density: 0,2 |
|
37 |
|
public class RouteOverlay extends Overlay |
38 |
|
{ |
39 |
|
private Projection mProjection; |
40 |
|
private Context mContext; |
41 |
|
private ArrayList<GeoPointPair> mGpPairs = new ArrayList<GeoPointPair>(); |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,5 |
|
43 |
|
private class GeoPointPair |
44 |
|
{ |
45 |
|
public GeoPoint from; |
46 |
|
public GeoPoint to; |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
48 |
33
|
public GeoPointPair(GeoPoint f, GeoPoint t)... |
49 |
|
{ |
50 |
33
|
from = f; |
51 |
33
|
to = t; |
52 |
|
} |
53 |
|
} |
54 |
|
|
|
|
| 93,1% |
Uncovered Elements: 2 (29) |
Complexity: 5 |
Complexity Density: 0,24 |
|
55 |
1
|
public RouteOverlay(Context context, Projection p)... |
56 |
|
{ |
57 |
1
|
mContext = context; |
58 |
1
|
mProjection = p; |
59 |
|
|
60 |
1
|
DbAdapter dbHelper = new DbAdapter(); |
61 |
1
|
dbHelper.open(mContext); |
62 |
1
|
Cursor c_from = dbHelper.fetch_from_stations(); |
63 |
1
|
if (c_from.moveToFirst()) do { |
64 |
13
|
int from_latitude = c_from.getInt(c_from.getColumnIndex(DbAdapter.KEY_LATITUDE)); |
65 |
13
|
int from_longitude = c_from.getInt(c_from.getColumnIndex(DbAdapter.KEY_LONGITUDE)); |
66 |
13
|
String from_station = c_from.getString(c_from.getColumnIndex(DbAdapter.KEY_STN)); |
67 |
|
|
68 |
13
|
GeoPoint from_gp = new GeoPoint(from_latitude, from_longitude); |
69 |
|
|
70 |
13
|
Cursor c_to = dbHelper.fetch_to_stations(from_station); |
71 |
13
|
if (c_to.moveToFirst()) do { |
72 |
33
|
int to_latitude = c_to.getInt(c_to.getColumnIndex(DbAdapter.KEY_LATITUDE)); |
73 |
33
|
int to_longitude = c_to.getInt(c_to.getColumnIndex(DbAdapter.KEY_LONGITUDE)); |
74 |
|
|
75 |
33
|
GeoPoint to_gp = new GeoPoint(to_latitude, to_longitude); |
76 |
|
|
77 |
33
|
mGpPairs.add(new GeoPointPair(from_gp, to_gp)); |
78 |
33
|
} while (c_to.moveToNext()); |
79 |
13
|
c_to.close(); |
80 |
13
|
} while (c_from.moveToNext()); |
81 |
1
|
c_from.close(); |
82 |
1
|
dbHelper.close(); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 2 |
Complexity Density: 0,17 |
|
85 |
20
|
public void draw(Canvas canvas, MapView mapv, boolean shadow)... |
86 |
|
{ |
87 |
20
|
super.draw(canvas, mapv, shadow); |
88 |
|
|
89 |
20
|
Paint paint = new Paint(); |
90 |
20
|
paint.setDither(true); |
91 |
20
|
paint.setStyle(Paint.Style.FILL_AND_STROKE); |
92 |
20
|
paint.setStrokeJoin(Paint.Join.ROUND); |
93 |
20
|
paint.setStrokeCap(Paint.Cap.ROUND); |
94 |
20
|
paint.setStrokeWidth(2); |
95 |
20
|
paint.setAlpha(50); |
96 |
|
|
97 |
20
|
Iterator<GeoPointPair> itr = mGpPairs.iterator(); |
98 |
680
|
while (itr.hasNext()) { |
99 |
660
|
GeoPointPair gpp = itr.next(); |
100 |
660
|
draw_line(canvas, paint, gpp.from, gpp.to); |
101 |
|
} |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
104 |
660
|
private void draw_line(Canvas canvas, Paint paint, GeoPoint gp1, GeoPoint gp2)... |
105 |
|
{ |
106 |
660
|
Point p1 = new Point(); |
107 |
660
|
Point p2 = new Point(); |
108 |
660
|
Path path = new Path(); |
109 |
|
|
110 |
660
|
mProjection.toPixels(gp1, p1); |
111 |
660
|
mProjection.toPixels(gp2, p2); |
112 |
|
|
113 |
660
|
path.moveTo(p2.x, p2.y); |
114 |
660
|
path.lineTo(p1.x,p1.y); |
115 |
|
|
116 |
660
|
canvas.drawPath(path, paint); |
117 |
|
} |
118 |
|
} |
119 |
|
|