This repository has been archived by the owner on Nov 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from NicholasMata/custom-guide
Custom Guide Shape
- Loading branch information
Showing
5 changed files
with
172 additions
and
14 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
app/src/main/java/ir/smartdevelop/eram/showcaseview/CircleView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package ir.smartdevelop.eram.showcaseview; | ||
|
||
import android.content.Context; | ||
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.Paint; | ||
import android.graphics.Path; | ||
import android.graphics.RectF; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
|
||
import smartdevelop.ir.eram.showcaseviewlib.Targetable; | ||
|
||
public class CircleView extends View implements Targetable { | ||
|
||
private static final int DEFAULT_CIRCLE_COLOR = Color.RED; | ||
private int _circleColor = DEFAULT_CIRCLE_COLOR; | ||
private Paint _paint; | ||
private Path _guidePath = new Path(); | ||
private RectF _boundingRect = new RectF(); | ||
|
||
public CircleView(Context context) | ||
{ | ||
super(context); | ||
init(context, null); | ||
} | ||
|
||
public CircleView(Context context, AttributeSet attrs) | ||
{ | ||
super(context, attrs); | ||
init(context, attrs); | ||
} | ||
|
||
private void init(Context context, AttributeSet attrs) | ||
{ | ||
_paint = new Paint(); | ||
_paint.setAntiAlias(true); | ||
} | ||
|
||
public void setCircleColor(int circleColor) | ||
{ | ||
this._circleColor = circleColor; | ||
invalidate(); | ||
} | ||
|
||
public int getCircleColor() | ||
{ | ||
return _circleColor; | ||
} | ||
|
||
private int usableWidth() { | ||
int w = getWidth(); | ||
|
||
int pl = getPaddingLeft(); | ||
int pr = getPaddingRight(); | ||
|
||
return w - (pl + pr); | ||
} | ||
|
||
private int usableHeight() { | ||
int h = getHeight(); | ||
|
||
int pt = getPaddingTop(); | ||
int pb = getPaddingBottom(); | ||
|
||
return h - (pt + pb); | ||
} | ||
|
||
protected void onDraw(Canvas canvas) | ||
{ | ||
super.onDraw(canvas); | ||
|
||
int pl = getPaddingLeft(); | ||
int pt = getPaddingTop(); | ||
|
||
int usableWidth = this.usableWidth(); | ||
int usableHeight = this.usableHeight(); | ||
|
||
int halfUsableWidth = usableWidth / 2; | ||
int halfUsableHeight = usableHeight / 2; | ||
|
||
int radius = Math.min(usableWidth, usableHeight) / 2; | ||
int cx = pl + halfUsableWidth; | ||
int cy = pt + halfUsableHeight; | ||
|
||
_paint.setColor(_circleColor); | ||
|
||
canvas.drawCircle(cx, cy, radius, _paint); | ||
|
||
int[] locationTarget = new int[2]; | ||
getLocationOnScreen(locationTarget); | ||
int centerX = pl + halfUsableWidth + locationTarget[0]; | ||
int centerY = pt + halfUsableHeight + locationTarget[1]; | ||
_guidePath.reset(); | ||
_guidePath.addCircle(centerX, centerY, radius, Path.Direction.CW); | ||
|
||
_boundingRect.left = locationTarget[0]; | ||
_boundingRect.top = locationTarget[1]; | ||
_boundingRect.right = locationTarget[0] + getWidth(); | ||
_boundingRect.bottom = locationTarget[1] + getHeight(); | ||
|
||
} | ||
|
||
@Override | ||
public Path guidePath() { | ||
return _guidePath; | ||
} | ||
|
||
@Override | ||
public RectF boundingRect() { | ||
return _boundingRect; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
showcaseviewlib/src/main/java/smartdevelop/ir/eram/showcaseviewlib/Targetable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package smartdevelop.ir.eram.showcaseviewlib; | ||
|
||
import android.graphics.Path; | ||
import android.graphics.RectF; | ||
|
||
public interface Targetable { | ||
/** | ||
* This path will be used when drawing the guide. | ||
* @return The path that will be drawn. | ||
*/ | ||
Path guidePath(); | ||
|
||
/** | ||
* This rect is used when displaying the guide message. | ||
* If the guidePath is a circle then the bounding box should | ||
* be a square that contains the circle inside of it. | ||
* @return The rect that will used for positioning guide message. | ||
*/ | ||
RectF boundingRect(); | ||
} |