Skip to content

Commit

Permalink
[FEATURE] Add the ability to set offsets to an overlay hole (issue wo…
Browse files Browse the repository at this point in the history
…rker8#6). Offset values (left and top, both can be either positive or negative integers, in pixels) are stored in a two-value array in a field of the Overlay class. Overlay.setHoleOffsets() is provided for setting those values to an overlay instance.
  • Loading branch information
svvorf committed May 22, 2016
1 parent 4bb172a commit d99c434
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions tourguide/src/main/java/tourguide/tourguide/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit d99c434

Please sign in to comment.