/
OverlayItem.java
166 lines (138 loc) · 5.61 KB
/
OverlayItem.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
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
// Created by plusminus on 00:02:58 - 03.10.2008
package org.osmdroid.views.overlay;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import org.osmdroid.api.IGeoPoint;
/**
* An Item that can be displayed in a {@link ItemizedOverlay} or {@link ItemizedIconOverlay}.
* <p>
* Immutable class describing a GeoPoint with a Title and a Description.
*
* @author Nicolas Gramlich
* @author Theodore Hong
* @author Fred Eisele
*/
public class OverlayItem {
// ===========================================================
// Constants
// ===========================================================
public static final int ITEM_STATE_FOCUSED_MASK = 4;
public static final int ITEM_STATE_PRESSED_MASK = 1;
public static final int ITEM_STATE_SELECTED_MASK = 2;
protected static final Point DEFAULT_MARKER_SIZE = new Point(26, 94);
/**
* Indicates a hotspot for an area. This is where the origin (0,0) of a point will be located
* relative to the area. In otherwords this acts as an offset. NONE indicates that no adjustment
* should be made.
*/
public enum HotspotPlace {
NONE, CENTER, BOTTOM_CENTER, TOP_CENTER, RIGHT_CENTER, LEFT_CENTER, UPPER_RIGHT_CORNER, LOWER_RIGHT_CORNER, UPPER_LEFT_CORNER, LOWER_LEFT_CORNER
}
// ===========================================================
// Fields
// ===========================================================
protected final String mUid;
protected final String mTitle;
protected final String mSnippet;
protected final IGeoPoint mGeoPoint;
protected Drawable mMarker;
protected HotspotPlace mHotspotPlace;
// ===========================================================
// Constructors
// ===========================================================
/**
* @param aTitle this should be <b>singleLine</b> (no <code>'\n'</code> )
* @param aSnippet a <b>multiLine</b> description ( <code>'\n'</code> possible)
* @param aGeoPoint
*/
public OverlayItem(final String aTitle, final String aSnippet, final IGeoPoint aGeoPoint) {
this(null, aTitle, aSnippet, aGeoPoint);
}
public OverlayItem(final String aUid, final String aTitle, final String aDescription,
final IGeoPoint aGeoPoint) {
this.mTitle = aTitle;
this.mSnippet = aDescription;
this.mGeoPoint = aGeoPoint;
this.mUid = aUid;
}
// ===========================================================
// Getter & Setter
// ===========================================================
public String getUid() {
return mUid;
}
public String getTitle() {
return mTitle;
}
public String getSnippet() {
return mSnippet;
}
public IGeoPoint getPoint() {
return mGeoPoint;
}
/*
* (copied from Google API docs) Returns the marker that should be used when drawing this item
* on the map. A null value means that the default marker should be drawn. Different markers can
* be returned for different states. The different markers can have different bounds. The
* default behavior is to call {@link setState(android.graphics.drawable.Drawable, int)} on the
* overlay item's marker, if it exists, and then return it.
*
* @param stateBitset The current state.
*
* @return The marker for the current state, or null if the default marker for the overlay
* should be used.
*/
public Drawable getMarker(final int stateBitset) {
// marker not specified
if (mMarker == null) {
return null;
}
// set marker state appropriately
setState(mMarker, stateBitset);
return mMarker;
}
public void setMarker(final Drawable marker) {
this.mMarker = marker;
}
public void setMarkerHotspot(final HotspotPlace place) {
this.mHotspotPlace = (place == null) ? HotspotPlace.BOTTOM_CENTER : place;
}
public HotspotPlace getMarkerHotspot() {
return this.mHotspotPlace;
}
// ===========================================================
// Methods from SuperClass/Interfaces
// ===========================================================
// ===========================================================
// Methods
// ===========================================================
/*
* (copied from the Google API docs) Sets the state of a drawable to match a given state bitset.
* This is done by converting the state bitset bits into a state set of R.attr.state_pressed,
* R.attr.state_selected and R.attr.state_focused attributes, and then calling {@link
* Drawable.setState(int[])}.
*/
public static void setState(final Drawable drawable, final int stateBitset) {
final int[] states = new int[3];
int index = 0;
if ((stateBitset & ITEM_STATE_PRESSED_MASK) > 0)
states[index++] = android.R.attr.state_pressed;
if ((stateBitset & ITEM_STATE_SELECTED_MASK) > 0)
states[index++] = android.R.attr.state_selected;
if ((stateBitset & ITEM_STATE_FOCUSED_MASK) > 0)
states[index++] = android.R.attr.state_focused;
drawable.setState(states);
}
public Drawable getDrawable() {
return this.mMarker;
}
public int getWidth() {
return this.mMarker.getIntrinsicWidth();
}
public int getHeight() {
return this.mMarker.getIntrinsicHeight();
}
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}