|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.android.maps.Overlay com.google.android.maps.ItemizedOverlay<Item>
public abstract class ItemizedOverlay<Item extends OverlayItem>
A base class for an Overlay
which consists of a list of
OverlayItems. This handles sorting north-to-south for drawing,
creating span bounds, drawing a marker for each point, and
maintaining a focused item. It also matches screen-taps to items,
and dispatches Focus-change events to an optional listener.
Nested Class Summary | |
---|---|
static interface |
ItemizedOverlay.OnFocusChangeListener
Interface for listeners interested in when the focused Item changes. |
Nested classes/interfaces inherited from class com.google.android.maps.Overlay |
---|
Overlay.Snappable |
Field Summary | |
---|---|
protected int |
mLastFocusedIndex
The index of the item that was most recently (or currently) focused, or -1 if none ever was. |
Fields inherited from class com.google.android.maps.Overlay |
---|
SHADOW_X_SKEW, SHADOW_Y_SCALE |
Constructor Summary | |
---|---|
ItemizedOverlay(android.graphics.drawable.Drawable defaultMarker)
Create a new ItemizedOverlay. |
Method Summary | |
---|---|
protected static android.graphics.drawable.Drawable |
boundCenter(android.graphics.drawable.Drawable balloon)
Adjusts a drawable's bounds so that (0,0) is the center center of the drawable. |
protected static android.graphics.drawable.Drawable |
boundCenterBottom(android.graphics.drawable.Drawable balloon)
Adjusts a drawable's bounds so that (0,0) is a pixel in the center of the bottom row of the drawable. |
protected abstract Item |
createItem(int i)
Method by which subclasses create the actual Items. |
void |
draw(android.graphics.Canvas canvas,
MapView mapView,
boolean shadow)
Draw a marker on each of our items. |
GeoPoint |
getCenter()
By default, returns the first-ranked item. |
Item |
getFocus()
|
protected int |
getIndexToDraw(int drawingOrder)
Returns the rank of the item with the given index. |
Item |
getItem(int position)
|
int |
getLastFocusedIndex()
|
int |
getLatSpanE6()
|
int |
getLonSpanE6()
|
protected boolean |
hitTest(Item item,
android.graphics.drawable.Drawable marker,
int hitX,
int hitY)
See if a given hit point is within the bounds of an item's marker. |
Item |
nextFocus(boolean forwards)
Returns the next Item to be focused in the given direction, or null if we're at the end of the line. |
boolean |
onKeyUp(int keyCode,
android.view.KeyEvent event,
MapView mapView)
Handle a key up event. |
boolean |
onSnapToItem(int x,
int y,
android.graphics.Point snapPoint,
MapView mapView)
Checks to see if the given x and y are close enough to an item resulting in snapping the current action (e.g. |
boolean |
onTap(GeoPoint p,
MapView mapView)
Handle a tap event. |
protected boolean |
onTap(int index)
Override this method to handle a "tap" on an item. |
boolean |
onTouchEvent(android.view.MotionEvent event,
MapView mapView)
Handle a touch event. |
boolean |
onTrackballEvent(android.view.MotionEvent event,
MapView mapView)
Handle a trackball event. |
protected void |
populate()
Utility method to perform all processing on a new ItemizedOverlay. |
void |
setDrawFocusedItem(boolean drawFocusedItem)
Set whether or not to draw the focused item. |
void |
setFocus(Item item)
If the given Item is found in the overlay, force it to be the current focus-bearer. |
protected void |
setLastFocusedIndex(int lastFocusedIndex)
Set the index of the item that was most recently (or currently) focused, or -1 if none ever was. |
void |
setOnFocusChangeListener(ItemizedOverlay.OnFocusChangeListener l)
|
abstract int |
size()
The number of items in this overlay. |
Methods inherited from class com.google.android.maps.Overlay |
---|
draw, drawAt, onKeyDown |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int mLastFocusedIndex
nextFocus(boolean)
can resume sequential browsing of an Overlay
even if the user pans away momentarily. Ordinarily subclasses
will not need to set this variable, since it will be
automatically updated when the focus is changed.
Constructor Detail |
---|
public ItemizedOverlay(android.graphics.drawable.Drawable defaultMarker)
defaultMarker
- A Drawable
to be drawn on the map for each
item in the overlay; see draw(android.graphics.Canvas, com.google.android.maps.MapView, boolean)
. An item may provide an
alternate marker via its OverlayItem.getMarker(int)
method. The marker
may be drawn in two states: null or
R.attr.state_focused
. In order
for hit-testing to work correctly, the two
states must have the same bounds. (A simple drawable will ignore its
state, which means that it will automatically have the same bounds.)
Note that you will need to add bounds to the marker in order
for it to draw correctly. Typically this is done with boundCenterBottom
, as in
super(boundCenterBottom(marker)).
Method Detail |
---|
protected static android.graphics.drawable.Drawable boundCenterBottom(android.graphics.drawable.Drawable balloon)
balloon
- the drawable to adjust
protected static android.graphics.drawable.Drawable boundCenter(android.graphics.drawable.Drawable balloon)
balloon
- the drawable to adjust
protected abstract Item createItem(int i)
populate()
; we'll cache them for
later use.
public abstract int size()
populate()
, and saved for all time.
public GeoPoint getCenter()
populate()
must have been called first.
protected int getIndexToDraw(int drawingOrder)
public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)
Draw a marker on each of our items. populate()
must have
been called first.
The marker will be drawn twice for each Item in the Overlay--once in the shadow phase, skewed and darkened, then again in the non-shadow phase. The bottom-center of the marker will be aligned with the geographical coordinates of the Item.
The order of drawing may be changed by overriding the
getIndexToDraw(int)
method. An item may provide an
alternate marker via its OverlayItem.getMarker(int)
method. If that method returns null, the default marker
is used.
The focused item is always drawn last, which puts it visually on top of the other items.
draw
in class Overlay
canvas
- The Canvas upon which to draw. Note that this
may already have a transformation applied, so be sure to leave
it the way you found it.mapView
- the MapView that requested the draw. Use MapView.getProjection()
to convert between on-screen pixels and
latitude/longitude pairs.shadow
- If true, draw the shadow layer. If false, draw the
overlay contents.public int getLatSpanE6()
populate()
as the difference between the northernmost
and southernmost Items.public int getLonSpanE6()
populate()
as the difference between the westernmost and
easternmost Items. Overlays that span the longitude
discontinuity at -180 degrees will report very large spans.protected final void populate()
createItem(int)
method. The subclass should call this as soon
as it has data, before anything else gets called.
protected void setLastFocusedIndex(int lastFocusedIndex)
nextFocus(boolean)
can resume sequential browsing of an Overlay
even if the user pans away momentarily. Ordinarily subclasses
will not need to set this variable, since it will be
automatically updated when the focus is changed.
public void setFocus(Item item)
ItemizedOverlay.OnFocusChangeListener
will be notified. This does not move
the map, so if the Item isn't already centered, the user may
get confused. If the Item is not found, this is a no-op. You
can also pass null to remove focus.
public Item getFocus()
public final int getLastFocusedIndex()
public final Item getItem(int position)
public Item nextFocus(boolean forwards)
public boolean onTap(GeoPoint p, MapView mapView)
onTap(int)
to return true.
onTap
in class Overlay
p
- the point that has been tappedmapView
- the MapView that generated the tap event
public boolean onSnapToItem(int x, int y, android.graphics.Point snapPoint, MapView mapView)
onSnapToItem
in interface Overlay.Snappable
x
- The x in screen coordinates.y
- The y in screen coordinates.snapPoint
- To be filled with the the interesting point (in
screen coordinates) that is closest to the given x and y. Can
be untouched if not snapping.mapView
- The MapView that is requesting the snap. Use
MapView.getProjection()
to convert between on-screen
pixels and latitude/longitude pairs.
public boolean onTrackballEvent(android.view.MotionEvent event, MapView mapView)
Overlay
onTrackballEvent
in class Overlay
event
- The motion event.mapView
- the MapView that generated the trackball event
public boolean onKeyUp(int keyCode, android.view.KeyEvent event, MapView mapView)
Overlay
onKeyUp
in class Overlay
keyCode
- The key codeevent
- The key eventmapView
- the MapView that generated the key event
public boolean onTouchEvent(android.view.MotionEvent event, MapView mapView)
Overlay
onTouchEvent
in class Overlay
event
- The motion event.mapView
- the MapView that generated the touch event
protected boolean hitTest(Item item, android.graphics.drawable.Drawable marker, int hitX, int hitY)
item
- the item to hit testmarker
- the item's markerhitX
- x coordinate of point to checkhitY
- y coordinate of point to check
public void setOnFocusChangeListener(ItemizedOverlay.OnFocusChangeListener l)
public void setDrawFocusedItem(boolean drawFocusedItem)
drawFocusedItem
- protected boolean onTap(int index)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |