1 | package org.mapsforge.android.maps;
|
---|
2 |
|
---|
3 |
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.Collection;
|
---|
6 |
|
---|
7 | import org.mapsforge.android.maps.overlay.OverlayItem;
|
---|
8 |
|
---|
9 | import android.app.AlertDialog;
|
---|
10 | import android.content.Context;
|
---|
11 | import android.graphics.drawable.Drawable;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Thread-safe implementation of the {@link ItemizedMarkerOverlay} class using an {@link ArrayList} as
|
---|
15 | * internal data structure.
|
---|
16 | */
|
---|
17 | public class ArrayItemizedMarkerOverlay extends ItemizedMarkerOverlay<OverlayMarkerItem> {
|
---|
18 | private static final int ARRAY_LIST_INITIAL_CAPACITY = 8;
|
---|
19 | private static final String THREAD_NAME = "ArrayItemizedMarkerOverlay";
|
---|
20 |
|
---|
21 | protected final Context context;
|
---|
22 | protected AlertDialog.Builder dialog;
|
---|
23 | protected OverlayItem item;
|
---|
24 | protected final ArrayList<OverlayMarkerItem> overlayMarkerItems;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Constructs a new ArrayItemizedOverlay.
|
---|
28 | *
|
---|
29 | * @param defaultMarker
|
---|
30 | * the default marker.
|
---|
31 | * @param context
|
---|
32 | * the reference to the application context.
|
---|
33 | */
|
---|
34 | public ArrayItemizedMarkerOverlay(Drawable defaultMarker, Context context) {
|
---|
35 | super(boundCenterBottom(defaultMarker));
|
---|
36 | this.context = context;
|
---|
37 | this.overlayMarkerItems = new ArrayList<OverlayMarkerItem>(ARRAY_LIST_INITIAL_CAPACITY);
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Adds the given item to the Overlay.
|
---|
42 | *
|
---|
43 | * @param overlayItem
|
---|
44 | * the item that should be added to the Overlay.
|
---|
45 | */
|
---|
46 | public synchronized void addOverlay(OverlayMarkerItem overlayItem) {
|
---|
47 | this.overlayMarkerItems.add(overlayItem);
|
---|
48 | populate();
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Adds all items of the given collection to the Overlay.
|
---|
53 | *
|
---|
54 | * @param c
|
---|
55 | * collection whose items should be added to the Overlay.
|
---|
56 | */
|
---|
57 | public synchronized void addOverlays(Collection<? extends OverlayMarkerItem> c) {
|
---|
58 | this.overlayMarkerItems.addAll(c);
|
---|
59 | populate();
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Removes all items from the Overlay.
|
---|
64 | */
|
---|
65 | public synchronized void clear() {
|
---|
66 | this.overlayMarkerItems.clear();
|
---|
67 | populate();
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public String getThreadName() {
|
---|
72 | return THREAD_NAME;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Removes the given item from the Overlay.
|
---|
77 | *
|
---|
78 | * @param overlayMarkerItem
|
---|
79 | * the item that should be removed from the Overlay.
|
---|
80 | */
|
---|
81 | public synchronized void removeOverlay(OverlayMarkerItem overlayMarkerItem) {
|
---|
82 | this.overlayMarkerItems.remove(overlayMarkerItem);
|
---|
83 | populate();
|
---|
84 | }
|
---|
85 |
|
---|
86 | @Override
|
---|
87 | public synchronized int size() {
|
---|
88 | return this.overlayMarkerItems.size();
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Override
|
---|
92 | public synchronized OverlayMarkerItem createItem(int i) {
|
---|
93 | return this.overlayMarkerItems.get(i);
|
---|
94 | }
|
---|
95 | } |
---|