AK2016 February 2016

PinView does not draw in Loop

I have extended SubsamplingScaleImageView to create PinView as recommend in documentation. I am able to draw Pint at proper location. But issue i am facing is : When i try to draw in loop it, Pin goes missing. I verified OnDraw is called on Main Thread.

Following is code i am using

public class PinView extends SubsamplingScaleImageView {

private PointF sPin;
private Bitmap pin;
private PointF sBlueDot;
private Bitmap blueDot;

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

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

public void setPin(PointF sPin) {
    this.sPin = sPin;
    initialise();
    invalidate();
}
public void setBlueDot(PointF sPin) {
    this.sBlueDot = sPin;
    initialiseBlueDot();
    invalidate();
}
public PointF getPin() {
    return sPin;
}

private void initialise() {
    float density = getResources().getDisplayMetrics().densityDpi;
    pin = BitmapFactory.decodeResource(this.getResources(), drawable.pushpin_blue);
    float w = (density/420f) * pin.getWidth();
    float h = (density/420f) * pin.getHeight();
    pin = Bitmap.createScaledBitmap(pin, (int)w, (int)h, true);
}
private void initialiseBlueDot() {
    float density = getResources().getDisplayMetrics().densityDpi;
    blueDot = BitmapFactory.decodeResource(this.getResources(), drawable.pushpin_blue);
    float w = (density/420f) * blueDot.getWidth();
    float h = (density/420f) * blueDot.getHeight();
    blueDot = Bitmap.createScaledBitmap(blueDot, (int)w, (int)h, true);
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // Don't draw pin before image is ready so it doesn't move around during setup.
    if (!isReady()) {
        return;
    }

    Paint paint = new Paint();
    paint.setAntiAlias(true);

    if (sPin != null && pin != null) {
        PointF vPin = sourceToViewCoord(sPin);
        float vX = vPin.x - (pin        

Answers


AK2016 February 2016

I got it fixed myself. Issue was with XY and source xy points. used viewToSourceCoord() to get proper location points.

Post Status

Asked in February 2016
Viewed 3,606 times
Voted 5
Answered 1 times

Search




Leave an answer