1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
package cgeo.geocaching.mapcommon;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Point;
import android.util.Log;
import cgeo.geocaching.R;
import cgeo.geocaching.cgSettings;
import cgeo.geocaching.cgUser;
import cgeo.geocaching.cgeodetail;
import cgeo.geocaching.mapinterfaces.ItemizedOverlayImpl;
import cgeo.geocaching.mapinterfaces.MapProjectionImpl;
import cgeo.geocaching.mapinterfaces.MapViewImpl;
import cgeo.geocaching.mapinterfaces.OverlayBase;
import cgeo.geocaching.mapinterfaces.UserOverlayItemImpl;
public class cgUsersOverlay extends ItemizedOverlayBase implements OverlayBase {
private ArrayList<UserOverlayItemImpl> items = new ArrayList<UserOverlayItemImpl>();
private Context context = null;
private final Pattern patternGeocode = Pattern.compile("^(GC[A-Z0-9]+)(\\: ?(.+))?$", Pattern.CASE_INSENSITIVE);
public cgUsersOverlay(ItemizedOverlayImpl ovlImplIn, Context contextIn) {
super(ovlImplIn);
populate();
context = contextIn;
}
protected void updateItems(UserOverlayItemImpl item) {
ArrayList<UserOverlayItemImpl> itemsPre = new ArrayList<UserOverlayItemImpl>();
itemsPre.add(item);
updateItems(itemsPre);
}
public void updateItems(ArrayList<UserOverlayItemImpl> itemsPre) {
if (itemsPre == null) {
return;
}
for (UserOverlayItemImpl item : itemsPre) {
item.setMarker(boundCenter(item.getMarker(0)));
}
items.clear();
if (itemsPre.size() > 0) {
items = new ArrayList<UserOverlayItemImpl>(itemsPre);
}
setLastFocusedItemIndex(-1); // to reset tap during data change
populate();
}
@Override
public boolean onTap(int index) {
try {
if (items.size() <= index) {
return false;
}
final UserOverlayItemImpl item = items.get(index);
final cgUser user = item.getUser();
// set action
String action = null;
String geocode = null;
final Matcher matcherGeocode = patternGeocode.matcher(user.action.trim());
if (user.action.length() == 0 || user.action.equalsIgnoreCase("pending")) {
action = "Looking around";
} else if (user.action.equalsIgnoreCase("tweeting")) {
action = "Tweeting";
} else if (matcherGeocode.find()) {
if (matcherGeocode.group(1) != null) {
geocode = matcherGeocode.group(1).trim().toUpperCase();
}
if (matcherGeocode.group(3) != null) {
action = "Heading to " + geocode + " (" + matcherGeocode.group(3).trim() + ")";
} else {
action = "Heading to " + geocode;
}
} else {
action = user.action;
}
// set icon
int icon = -1;
if (user.client.equalsIgnoreCase("c:geo")) {
icon = R.drawable.client_cgeo;
} else if (user.client.equalsIgnoreCase("preCaching")) {
icon = R.drawable.client_precaching;
} else if (user.client.equalsIgnoreCase("Handy Geocaching")) {
icon = R.drawable.client_handygeocaching;
}
final AlertDialog.Builder dialog = new AlertDialog.Builder(context);
if (icon > -1) {
dialog.setIcon(icon);
}
dialog.setTitle(user.username);
dialog.setMessage(action);
dialog.setCancelable(true);
if (geocode != null && geocode.length() > 0) {
dialog.setPositiveButton(geocode + "?", new cacheDetails(geocode));
}
dialog.setNeutralButton("Dismiss", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = dialog.create();
alert.show();
return true;
} catch (Exception e) {
Log.e(cgSettings.tag, "cgUsersOverlay.onTap: " + e.toString());
}
return false;
}
@Override
public void draw(Canvas canvas, MapViewImpl mapView, boolean shadow) {
super.draw(canvas, mapView, false);
}
@Override
public void drawOverlayBitmap(Canvas canvas, Point drawPosition,
MapProjectionImpl projection, byte drawZoomLevel) {
super.drawOverlayBitmap(canvas, drawPosition, projection, drawZoomLevel);
}
@Override
public UserOverlayItemImpl createItem(int index) {
try {
return items.get(index);
} catch (Exception e) {
Log.e(cgSettings.tag, "cgUsersOverlay.createItem: " + e.toString());
}
return null;
}
@Override
public int size() {
try {
return items.size();
} catch (Exception e) {
Log.e(cgSettings.tag, "cgUsersOverlay.size: " + e.toString());
}
return 0;
}
private class cacheDetails implements DialogInterface.OnClickListener {
private String geocode = null;
public cacheDetails(String geocodeIn) {
geocode = geocodeIn;
}
public void onClick(DialogInterface dialog, int id) {
if (geocode != null) {
Intent detailIntent = new Intent(context, cgeodetail.class);
detailIntent.putExtra("geocode", geocode);
context.startActivity(detailIntent);
}
dialog.cancel();
}
}
}
|