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 |
|
|
24 |
|
import android.app.Activity; |
25 |
|
import android.app.AlertDialog; |
26 |
|
import android.content.Context; |
27 |
|
import android.content.DialogInterface; |
28 |
|
import android.content.DialogInterface.OnClickListener; |
29 |
|
import android.content.Intent; |
30 |
|
import android.graphics.drawable.Drawable; |
31 |
|
import android.os.Bundle; |
32 |
|
|
33 |
|
import com.google.android.maps.ItemizedOverlay; |
34 |
|
import com.google.android.maps.MapActivity; |
35 |
|
import com.google.android.maps.OverlayItem; |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 10 |
Complexity Density: 0,34 |
|
37 |
|
public class RbmItemizedOverlay extends ItemizedOverlay<OverlayItem> |
38 |
|
{ |
39 |
|
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); |
40 |
|
private Context mContext; |
41 |
|
private boolean mSetResult; |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
43 |
9
|
public RbmItemizedOverlay(Drawable defaultMarker, Context context, boolean set_result) {... |
44 |
9
|
super(boundCenterBottom(defaultMarker)); |
45 |
9
|
mContext = context; |
46 |
9
|
mSetResult = set_result; |
47 |
|
} |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
49 |
495
|
public void addOverlay(OverlayItem overlay) {... |
50 |
495
|
mOverlays.add(overlay); |
51 |
495
|
populate(); |
52 |
|
} |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
22043
|
@Override... |
55 |
|
protected OverlayItem createItem(int i) { |
56 |
22043
|
return mOverlays.get(i); |
57 |
|
} |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
583
|
@Override... |
60 |
|
public int size() { |
61 |
583
|
return mOverlays.size(); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
64 |
15
|
@Override... |
65 |
|
protected boolean onTap(int index) { |
66 |
15
|
OverlayItem item = mOverlays.get(index); |
67 |
15
|
String station = item.getTitle(); |
68 |
15
|
String city = item.getSnippet(); |
69 |
|
|
70 |
15
|
prompt_confirm(station, city, mSetResult); |
71 |
15
|
return true; |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0,25 |
|
74 |
15
|
private void prompt_confirm(final String station, final String city, final boolean set_result)... |
75 |
|
{ |
76 |
15
|
AlertDialog.Builder builder = new AlertDialog.Builder(mContext); |
77 |
15
|
if (station.equals(city)) { |
78 |
8
|
builder.setTitle(station); |
79 |
|
} else { |
80 |
7
|
builder.setTitle(station + ", " + city); |
81 |
|
} |
82 |
15
|
builder.setPositiveButton(android.R.string.ok, new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 2 |
Complexity Density: 0,22 |
|
83 |
10
|
@Override... |
84 |
|
public void onClick(DialogInterface dialog, int which) { |
85 |
10
|
if (set_result) { |
86 |
8
|
Bundle b = new Bundle(); |
87 |
8
|
b.putString("station", station); |
88 |
8
|
b.putString("city", city); |
89 |
|
|
90 |
8
|
Intent i = new Intent(); |
91 |
8
|
i.putExtras(b); |
92 |
|
|
93 |
8
|
MapActivity ma = (MapActivity) mContext; |
94 |
8
|
ma.setResult(Activity.RESULT_OK, i); |
95 |
8
|
ma.finish(); |
96 |
|
} |
97 |
|
} |
98 |
|
}); |
99 |
15
|
builder.setNegativeButton(android.R.string.cancel, new OnClickListener() { |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
100 |
5
|
@Override... |
101 |
|
public void onClick(DialogInterface dialog, int which) { |
102 |
|
} |
103 |
|
}); |
104 |
15
|
AlertDialog alert = builder.create(); |
105 |
15
|
alert.show(); |
106 |
|
} |
107 |
|
} |
108 |
|
|