Clover Coverage Report - RaspberryBusMalaysiaActivity Coverage Report
Coverage timestamp: mar dic 23 2014 15:39:35 EST
../../../img/srcFileCovDistChart10.png 0% of files have more coverage
43   119   9   10,75
10   80   0,21   2
4     2,25  
2    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  RouteOverlay       Line # 37 41 8 96,3% 0.962963
  RouteOverlay.GeoPointPair       Line # 43 2 1 100% 1.0
 
No Tests
 
1    /*
2    Copyright (C) 2012 Sweetie Piggy Apps <sweetiepiggyapps@gmail.com>
3   
4    This file is part of Raspberry Bus Malaysia.
5   
6    Raspberry Bus Malaysia is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10   
11    Raspberry Bus Malaysia is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14    GNU General Public License for more details.
15   
16    You should have received a copy of the GNU General Public License
17    along with Raspberry Bus Malaysia; if not, see <http://www.gnu.org/licenses/>.
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   
 
37    public class RouteOverlay extends Overlay
38    {
39    private Projection mProjection;
40    private Context mContext;
41    private ArrayList<GeoPointPair> mGpPairs = new ArrayList<GeoPointPair>();
42   
 
43    private class GeoPointPair
44    {
45    public GeoPoint from;
46    public GeoPoint to;
47   
 
48  33 toggle public GeoPointPair(GeoPoint f, GeoPoint t)
49    {
50  33 from = f;
51  33 to = t;
52    }
53    }
54   
 
55  1 toggle 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   
 
85  20 toggle 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   
 
104  660 toggle 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