1

I'm using this wonderful library to handle a Map in my Android application. I'm making a custom view named MapView that extends SubsamplingScaleImageView. I'm trying to use the base PinView extension of the library to set a Pin over the map but i don't want a static Pin image but a dinamic gif. I've read about the 3 scenarios of using "Movie", using GifDecoder and using WebView but none of them worked for me. I really can't figure out how to animate my Pin in the map. Help me please!

public class MapView extends SubsamplingScaleImageView{

    private PointF sPin;
    private Bitmap pin;


    public MapView(Context context) {
        this(context, null);
    }

    public MapView(Context context, AttributeSet attr) {
        super(context, attr);
        initialise();
    }

    private void initialise() {
         float density = getResources().getDisplayMetrics().densityDpi;
        pin = BitmapFactory.decodeResource(this.getResources(), R.drawable.pushpin_blue.gif); //<<<<<<<Here goes the GIF
        float w = (density/420f) * pin.getWidth();
        float h = (density/420f) * pin.getHeight();
        pin = Bitmap.createScaledBitmap(pin, (int)w, (int)h, true);
    }


    public PointF getPin() {
        return sPin;
    }

    public void setPin(PointF sPin) {
        this.sPin = sPin;
        initialise();
        invalidate();
    }

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (!isReady()) {
            return;
        }

        if (sPin != null && pin != null) {
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            PointF vPin = sourceToViewCoord(sPin);
            float vX = vPin.x - (pin.getWidth()/2);
            float vY = vPin.y - pin.getHeight();
            canvas.drawBitmap(pin, vX, vY, paint);
        }

    }

}
Floern
  • 33,559
  • 24
  • 104
  • 119

0 Answers0