by Hylke1982 » Wed Apr 15, 2009 11:32 am
Example source code:
Using java Syntax Highlighting
public class SpotMap extends MapActivity {
private MapView mapView;
// SpotBalloon is a class that extends drawable
private static final Drawable yellowBalloon = new SpotBalloon(255,255,255,0);
private static final Drawable orangeBalloon = new SpotBalloon(255,255,140,0);
private static final Drawable whiteBalloon = new SpotBalloon(255,255,255,255);
// overlay with default drawable (yellowBalloon)
private static final SpotOverlay personalOverlay = new SpotOverlay(yellowBalloon);
public void addDifferentMarkersToMap(){
OverlayItem itemWhite = new OverlayItem(point, "white", "");
itemWhite.setMarker(whiteBalloon); // Another drawable is set here
OverlayItem itemOrange = new OverlayItem(point, "orange", "");
itemOrange.setMarker(whiteBalloon); // Another drawable is set here
// Add spot with different markers to overlay
personalOverlay.addOverlayItem(itemWhite);
personalOverlay.addOverlayItem(itemOrange);
mapView.getOverlays().add(personalOverlay);
}
}
Parsed in 0.034 seconds, using
GeSHi 1.0.8.4
SpotBalloon.java
Using java Syntax Highlighting
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
public class SpotBalloon extends Drawable {
private Paint spotBalloonPaint = new Paint();
private static final Paint blackTextPaint = new Paint();
private static final int HEIGHT = 20;
private static final int WIDTH = 100;
private String name;
public SpotBalloon(int alpha, int r, int g, int b) {
spotBalloonPaint.setARGB(alpha, r, g, b);
spotBalloonPaint.setAntiAlias(true);
blackTextPaint.setARGB(255, 0, 0, 0);
blackTextPaint.setAntiAlias(true);
}
@Override
public void draw(Canvas canvas) {
canvas.setViewport(WIDTH, HEIGHT);
canvas.drawCircle(0, 0, 5, blackTextPaint);
canvas.drawCircle(0, 0, 4, spotBalloonPaint);
// TODO Auto-generated method stub
}
@Override
public int getOpacity() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setAlpha(int alpha) {
// TODO Auto-generated method stub
}
@Override
public void setColorFilter(ColorFilter cf) {
// TODO Auto-generated method stub
}
public void setName(String name){
this.name = name;
}
}
Parsed in 0.039 seconds, using
GeSHi 1.0.8.4
Using java Syntax Highlighting
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
public class SpotOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> overLayList = new ArrayList<OverlayItem>();
public SpotOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
@Override
protected OverlayItem createItem(int i) {
return overLayList.get(i);
}
@Override
public int size() {
return overLayList.size();
}
public void addOverlayItem(OverlayItem overlayItem) {
if(!overLayList.contains(overlayItem)){
overLayList.add(overlayItem);
}
populate();
}
public void clear(){
overLayList.clear();
}
}
Parsed in 0.037 seconds, using
GeSHi 1.0.8.4
Last edited by
Hylke1982 on Thu Apr 16, 2009 8:24 am, edited 2 times in total.
An automaton that is created from biological materials and resembles a human. Also called humanoid.