Here is a code which is actually working, but with manual draw, you
can imitate my workaround for now.
I hope an official answer will come up fast...
/** Map layer displaying contact locations */
public class LocationOverlay extends
ItemizedOverlay<LocationOverlayItem>
{
/** Contacts with known location */
private final List<Contact> mContacts;
/*
* FIXME fields to manually draw items, we don't know how to make
* ItemizedOverlay actually work
*/
private Bitmap mBubbleBitmap;
private Paint mInnerPaint;
private Paint mBorderPaint;
private TextPaint mTextPaint;
private static final int TEXT_OFFSET_X = 10;
private static final int TEXT_OFFSET_Y = 15;
private static final int INFO_WINDOW_HEIGHT = 25;
/** Create a new instance */
public LocationOverlay()
{
super(UbikIMApplication.getApplicationResources().getDrawable(
R.drawable.bubble));
/* Get contacts with location */
mContacts = new ArrayList<Contact>();
for (Contact contact : ContactManager.getInstance().getContacts())
if (contact.getLocation() != null)
mContacts.add(contact);
/* Populate */
populate();
/* FIXME manual draw managing relating code */
/* Decompress bubble bitmap */
mBubbleBitmap = BitmapFactory.decodeResource(UbikIMApplication
.getApplicationResources(), R.drawable.bubble);
/* Init painter used to draw the inner of the info window */
mInnerPaint = new Paint();
mInnerPaint.setARGB(225, 75, 75, 75);
mInnerPaint.setAntiAlias(true);
/* Init painter used to draw the border of the info window */
mBorderPaint = new Paint();
mBorderPaint.setARGB(255, 255, 255, 255);
mBorderPaint.setAntiAlias(true);
mBorderPaint.setStyle(Style.STROKE);
mBorderPaint.setStrokeWidth(2);
/* Init painter used to draw the text inside the info window */
mTextPaint = new TextPaint();
mTextPaint.setARGB(255, 255, 255, 255);
mTextPaint.setAntiAlias(true);
}
@Override
protected LocationOverlayItem createItem(int i)
{
return new LocationOverlayItem(mContacts.get(i));
}
@Override
public int size()
{
return mContacts.size();
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow)
{
/* FIXME manual draw because automatic doesn't seem to work */
/* Retrieve map view projection to compute coordinates */
Projection projection = mapView.getProjection();
/* For all contacts with location (including self) */
for (int index = size() - 1; index >= 0; index--)
{
OverlayItem item = getItem(index);
String title = item.getTitle();
Point point = projection.toPixels(item.getPoint(), null);
/* Draw bubble */
canvas.drawBitmap(mBubbleBitmap, point.x -
mBubbleBitmap.getWidth() / 2,
point.y - mBubbleBitmap.getHeight(), null);
/* Compute info window geometry */
int INFO_WINDOW_WIDTH = getTextWidth(title) + TEXT_OFFSET_X * 2;
RectF infoWindowRect = new RectF(0, 0, INFO_WINDOW_WIDTH,
INFO_WINDOW_HEIGHT);
int infoWindowOffsetX = point.x - INFO_WINDOW_WIDTH / 2;
int infoWindowOffsetY = point.y - INFO_WINDOW_HEIGHT
- mBubbleBitmap.getHeight() - 2;
infoWindowRect.offset(infoWindowOffsetX, infoWindowOffsetY);
/* Draw inner info window */
canvas.drawRoundRect(infoWindowRect, 5, 5, mInnerPaint);
/* Draw border for info window */
canvas.drawRoundRect(infoWindowRect, 5, 5, mBorderPaint);
/* Draw user name in the info window */
canvas.drawText(title, infoWindowOffsetX + TEXT_OFFSET_X,
infoWindowOffsetY + TEXT_OFFSET_Y, mTextPaint);
}
super.draw(canvas, mapView, shadow);
}
/* FIXME manual draw related function */
/** @return text width in pixels that the text paint will use to
draw text */
private int getTextWidth(String text)
{
int count = text.length();
float[] widths = new float[count];
mTextPaint.getTextWidths(text, widths);
int textWidth = 0;
for (int i = 0; i < count; i++)
textWidth += widths[i];
return textWidth;
}
@Override
protected boolean onTap(int index)
{
setFocus(getItem(index));
return true;
}
@Override
protected boolean hitTest(LocationOverlayItem item, Drawable marker,
int hitX, int hitY)
{
return super.hitTest(item, marker, hitX, hitY +
mBubbleBitmap.getHeight()
/ 2);