source: other-projects/tipple-android/tipple-lib/src/org/mapsforge/android/maps/ArrayItemizedMarkerOverlay.java@ 26899

Last change on this file since 26899 was 26899, checked in by davidb, 11 years ago

Tipple reborn after Chris's Summer of Code 2013

File size: 2.5 KB
Line 
1package org.mapsforge.android.maps;
2
3
4import java.util.ArrayList;
5import java.util.Collection;
6
7import org.mapsforge.android.maps.overlay.OverlayItem;
8
9import android.app.AlertDialog;
10import android.content.Context;
11import 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 */
17public 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}
Note: See TracBrowser for help on using the repository browser.