diff --git a/tourguide/src/main/java/tourguide/tourguide/FrameLayoutWithHole.java b/tourguide/src/main/java/tourguide/tourguide/FrameLayoutWithHole.java index d9dbcbd..a8b1f82 100644 --- a/tourguide/src/main/java/tourguide/tourguide/FrameLayoutWithHole.java +++ b/tourguide/src/main/java/tourguide/tourguide/FrameLayoutWithHole.java @@ -258,16 +258,14 @@ protected void onDraw(Canvas canvas) { if (mOverlay!=null) { mEraserCanvas.drawColor(mOverlay.mBackgroundColor); int padding = (int) (10 * mDensity); + int[] holeOffsets = mOverlay.mHoleOffsets; if (mOverlay.mStyle == Overlay.Style.Rectangle) { - mEraserCanvas.drawRect(mPos[0] - padding, mPos[1] - padding, mPos[0] + mViewHole.getWidth() + padding, mPos[1] + mViewHole.getHeight() + padding, mEraser); + mEraserCanvas.drawRect(mPos[0] - padding + holeOffsets[0], mPos[1] - padding + holeOffsets[1], mPos[0] + mViewHole.getWidth() + padding + holeOffsets[0], mPos[1] + mViewHole.getHeight() + padding + holeOffsets[1], mEraser); } else if (mOverlay.mStyle == Overlay.Style.NoHole) { - mEraserCanvas.drawCircle(mPos[0] + mViewHole.getWidth() / 2, mPos[1] + mViewHole.getHeight() / 2, 0, mEraser); + mEraserCanvas.drawCircle(mPos[0] + mViewHole.getWidth() / 2 + holeOffsets[0], mPos[1] + mViewHole.getHeight() / 2 + holeOffsets[1], 0, mEraser); } else { - if (mOverlay != null && mOverlay.mHoleRadius != Overlay.NOT_SET){ - mEraserCanvas.drawCircle(mPos[0] + mViewHole.getWidth() / 2, mPos[1] + mViewHole.getHeight() / 2, mOverlay.mHoleRadius, mEraser); - } else { - mEraserCanvas.drawCircle(mPos[0] + mViewHole.getWidth() / 2, mPos[1] + mViewHole.getHeight() / 2, mRadius, mEraser); - } + int holeRadius = mOverlay.mHoleRadius != Overlay.NOT_SET ? mOverlay.mHoleRadius : mRadius; + mEraserCanvas.drawCircle(mPos[0] + mViewHole.getWidth() / 2 + holeOffsets[0], mPos[1] + mViewHole.getHeight() / 2 + holeOffsets[1], holeRadius, mEraser); } } canvas.drawBitmap(mEraserBitmap, 0, 0, null); diff --git a/tourguide/src/main/java/tourguide/tourguide/Overlay.java b/tourguide/src/main/java/tourguide/tourguide/Overlay.java index dfae6b3..4774df6 100644 --- a/tourguide/src/main/java/tourguide/tourguide/Overlay.java +++ b/tourguide/src/main/java/tourguide/tourguide/Overlay.java @@ -13,6 +13,7 @@ public class Overlay { public boolean mDisableClickThroughHole; public Style mStyle; public Animation mEnterAnimation, mExitAnimation; + public int[] mHoleOffsets = new int[] {0, 0}; public View.OnClickListener mOnClickListener; public int mHoleRadius = NOT_SET; public final static int NOT_SET = -1; @@ -108,4 +109,16 @@ public Overlay setHoleRadius(int holeRadius) { mHoleRadius = holeRadius; return this; } + + + /** + * This method sets offsets to the hole's position relative the position of the targeted view. + * @param offsetLeft left offset, in pixels + * @param offsetTop top offset, in pixels + * @return {@link Overlay} instance for chaining purpose + */ + public Overlay setHoleOffsets(int offsetLeft, int offsetTop) { + mHoleOffsets = new int[] {offsetLeft, offsetTop}; + return this; + } }