-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyItemizedOverlay.java
86 lines (72 loc) · 2.71 KB
/
MyItemizedOverlay.java
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
package com.phonegap.plugin;
import java.util.ArrayList;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import io.cordova.R;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
private static String TAG = "MyItemizedOverlay";
public MyItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public MyItemizedOverlay(Drawable defaultMarker, Context context) {
this(defaultMarker);
mContext = context;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
@Override
protected boolean onTap(int index) {
// Weirdest thing ever! index is always 0 and mOverlays size is 1
Log.d(TAG, "Index " + index + " Overlay title " + mOverlays.get(index).getTitle());
final GMActivity ma = (GMActivity) mContext;
// // find geoname
final GeoName geoname = ma.getGeoName(mOverlays.get(index).getTitle());
if(geoname != null) {
final Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.geoname_dialog);
dialog.setTitle(geoname.getTitle());
TextView summary = (TextView) dialog.findViewById(R.id.summary);
summary.setText(geoname.getSummary());
ImageView gotoicon = (ImageView) dialog.findViewById(R.id.gotoicon);
gotoicon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
Intent i = new Intent();
Bundle b = new Bundle();
b.putString("wikipediaUrl", geoname.getUrl());
Log.d(TAG, "Overlay URL "+geoname.getUrl());
i.putExtras(b);
ma.setResult(GMPlugin.RESULT_OK, i);
ma.finish();
}
});
dialog.show();
} else {
Log.d(TAG, "Could not find geopoint");
}
return true;
}
}