How to show a rectangle around an annotation?

This sample code shows how to draw a red rectangle around one of the annotations of each page.

put the followings in ToolManager.onDraw()

`

@Override
public void onDraw(Canvas canvas, Matrix tfm) {

// draw a red rectangle around the first annot in the page
Page page;
try {
int pageNum = mPdfViewCtrl.getCurrentPage();
page = mPdfViewCtrl.getDoc().getPage(pageNum);
int annotCnt = page.getNumAnnots();
if (annotCnt > 0) {
Paint mBackgroundPaint = new Paint();
mBackgroundPaint.setStyle(Paint.Style.STROKE);
mBackgroundPaint.setColor(Color.rgb(255, 0, 0));

Annot annot = page.getAnnot(0);
RectF rect = getAnnotRectInScreenPt(annot, pageNum);
if (mPdfViewCtrl.isMaintainZoomEnabled()) {
canvas.save();
try {
int dx = mPdfViewCtrl.getScrollXOffsetInTools(pageNum);
int dy = (mPdfViewCtrl.isCurrentSlidingCanvas(pageNum) ? 0
: mPdfViewCtrl.getSlidingScrollY()) - mPdfViewCtrl.getScrollYOffsetInTools(pageNum);
canvas.translate(dx, dy);
canvas.drawRect(rect, mBackgroundPaint);
} finally {
canvas.restore();
}
} else {
canvas.drawRect(rect, mBackgroundPaint);
}
}
} catch (PDFNetException e) {
e.printStackTrace();
}
}

`

and put the following method in ToolManager class

`

public RectF getAnnotRectInScreenPt(Annot annot, int pageNum) throws PDFNetException {
com.pdftron.pdf.Rect rect = mPdfViewCtrl.getPageRectForAnnot(annot, pageNum);
rect.normalize();
double[] point;
double x1, y1, x2, y2;
x1 = rect.getX1();
x2 = rect.getX2();
y1 = rect.getY1();
y2 = rect.getY2();

if (mPdfViewCtrl.isContinuousPagePresentationMode(mPdfViewCtrl.getPagePresentationMode())) {
point = mPdfViewCtrl.convPagePtToScreenPt(x1, y1, pageNum);
x1 = point[0] + mPdfViewCtrl.getScrollX();
y1 = point[1] + mPdfViewCtrl.getScrollY();
point = mPdfViewCtrl.convPagePtToScreenPt(x2, y2, pageNum);
x2 = point[0] + mPdfViewCtrl.getScrollX();
y2 = point[1] + mPdfViewCtrl.getScrollY();
} else {
point = mPdfViewCtrl.convPagePtToHorizontalScrollingPt(x1, y1, pageNum);
x1 = point[0];
y1 = point[1];
point = mPdfViewCtrl.convPagePtToHorizontalScrollingPt(x2, y2, pageNum);
x2 = point[0];
y2 = point[1];
}

return new RectF((float) x1, (float) y2, (float) x2, (float) y1);
}

`