Skip to content
This repository was archived by the owner on Nov 10, 2024. It is now read-only.

Commit bc408e5

Browse files
create parameter for making the shape filled or not
1 parent 2262c84 commit bc408e5

File tree

2 files changed

+61
-40
lines changed

2 files changed

+61
-40
lines changed

app/src/main/java/ir/smartdevelop/eram/showcaseview/MainActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ir.smartdevelop.eram.showcaseview;
22

3+
import android.annotation.SuppressLint;
34
import android.os.Bundle;
45
import android.support.v7.app.AppCompatActivity;
56
import android.view.View;
@@ -8,7 +9,6 @@
89
import smartdevelop.ir.eram.showcaseviewlib.config.DismissType;
910
import smartdevelop.ir.eram.showcaseviewlib.config.Gravity;
1011
import smartdevelop.ir.eram.showcaseviewlib.config.PointerType;
11-
import smartdevelop.ir.eram.showcaseviewlib.listener.GuideListener;
1212

1313
public class MainActivity extends AppCompatActivity {
1414

@@ -21,6 +21,7 @@ public class MainActivity extends AppCompatActivity {
2121
private GuideView mGuideView;
2222
private GuideView.Builder builder;
2323

24+
@SuppressLint("NonConstantResourceId")
2425
@Override
2526
protected void onCreate(Bundle savedInstanceState) {
2627
super.onCreate(savedInstanceState);
@@ -38,7 +39,8 @@ protected void onCreate(Bundle savedInstanceState) {
3839
.setContentText("Guide Description Text\n .....Guide Description Text\n .....Guide Description Text .....")
3940
.setGravity(Gravity.center)
4041
.setDismissType(DismissType.anywhere)
41-
.setPointerType(PointerType.circle)
42+
.setPointerType(PointerType.arrow)
43+
.isShapeSolid(true)
4244
.setTargetView(view1)
4345
.setGuideListener(view -> {
4446
switch (view.getId()) {

showcaseviewlib/src/main/java/smartdevelop/ir/eram/showcaseviewlib/GuideView.java

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public class GuideView extends FrameLayout {
8989
private DismissType dismissType;
9090
private PointerType pointerType;
9191
private final GuideMessageView mMessageView;
92+
private boolean isShapeSolid;
9293

9394
private GuideView(Context context, View view) {
9495
super(context);
@@ -100,19 +101,19 @@ private GuideView(Context context, View view) {
100101

101102
mMessageView = new GuideMessageView(getContext());
102103
mMessageView.setPadding(
103-
messageViewPadding,
104-
messageViewPadding,
105-
messageViewPadding,
106-
messageViewPadding
104+
messageViewPadding,
105+
messageViewPadding,
106+
messageViewPadding,
107+
messageViewPadding
107108
);
108109
mMessageView.setColor(Color.WHITE);
109110

110111
addView(
111-
mMessageView,
112-
new LayoutParams(
113-
ViewGroup.LayoutParams.WRAP_CONTENT,
114-
ViewGroup.LayoutParams.WRAP_CONTENT
115-
)
112+
mMessageView,
113+
new LayoutParams(
114+
ViewGroup.LayoutParams.WRAP_CONTENT,
115+
ViewGroup.LayoutParams.WRAP_CONTENT
116+
)
116117
);
117118

118119
ViewTreeObserver.OnGlobalLayoutListener layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@@ -130,21 +131,21 @@ public void onGlobalLayout() {
130131
int[] locationTarget = new int[2];
131132
target.getLocationOnScreen(locationTarget);
132133
targetRect = new RectF(
133-
locationTarget[0],
134-
locationTarget[1],
135-
locationTarget[0] + target.getWidth(),
136-
locationTarget[1] + target.getHeight()
134+
locationTarget[0],
135+
locationTarget[1],
136+
locationTarget[0] + target.getWidth(),
137+
locationTarget[1] + target.getHeight()
137138
);
138139
if (isLandscape()) {
139140
targetRect.offset(-getStatusBarHeight(), 0);
140141
}
141142
}
142143

143144
backgroundRect.set(
144-
getPaddingLeft(),
145-
getPaddingTop(),
146-
getWidth() - getPaddingRight(),
147-
getHeight() - getPaddingBottom()
145+
getPaddingLeft(),
146+
getPaddingTop(),
147+
getWidth() - getPaddingRight(),
148+
getHeight() - getPaddingBottom()
148149
);
149150
if (isLandscape()) {
150151
backgroundRect.offset(-getNavigationBarSize(), 0);
@@ -166,8 +167,8 @@ public void onGlobalLayout() {
166167
private void startAnimationSize() {
167168
if (!isPerformedAnimationSize) {
168169
final ValueAnimator circleSizeAnimator = ValueAnimator.ofFloat(
169-
0f,
170-
circleIndicatorSizeFinal
170+
0f,
171+
circleIndicatorSizeFinal
171172
);
172173
circleSizeAnimator.addUpdateListener(valueAnimator -> {
173174
circleIndicatorSize = (float) circleSizeAnimator.getAnimatedValue();
@@ -176,8 +177,8 @@ private void startAnimationSize() {
176177
});
177178

178179
final ValueAnimator linePositionAnimator = ValueAnimator.ofFloat(
179-
stopY,
180-
startYLineAndCircle
180+
stopY,
181+
startYLineAndCircle
181182
);
182183
linePositionAnimator.addUpdateListener(valueAnimator -> {
183184
startYLineAndCircle = (float) linePositionAnimator.getAnimatedValue();
@@ -259,28 +260,34 @@ protected void onDraw(final Canvas canvas) {
259260
paintLine.setStrokeWidth(lineIndicatorWidthSize);
260261
paintLine.setAntiAlias(true);
261262

262-
paintCircle.setStyle(Paint.Style.STROKE);
263+
if (isShapeSolid)
264+
paintCircle.setStyle(Paint.Style.FILL);
265+
else
266+
paintCircle.setStyle(Paint.Style.STROKE);
263267
paintCircle.setColor(CIRCLE_INDICATOR_COLOR);
264268
paintCircle.setStrokeCap(Paint.Cap.ROUND);
265269
paintCircle.setStrokeWidth(strokeCircleWidth);
266270
paintCircle.setAntiAlias(true);
267271

268-
paintCircleInner.setStyle(Paint.Style.FILL);
269-
paintCircleInner.setColor(CIRCLE_INNER_INDICATOR_COLOR);
270-
paintCircleInner.setAntiAlias(true);
271-
272+
if (!isShapeSolid) {
273+
paintCircleInner.setStyle(Paint.Style.FILL);
274+
paintCircleInner.setColor(CIRCLE_INNER_INDICATOR_COLOR);
275+
paintCircleInner.setAntiAlias(true);
276+
}
272277
final float x = (targetRect.left / 2 + targetRect.right / 2);
273278

274279
switch (pointerType) {
275280
case circle:
276281
canvas.drawLine(x, startYLineAndCircle, x, stopY, paintLine);
277282
canvas.drawCircle(x, startYLineAndCircle, circleIndicatorSize, paintCircle);
278-
canvas.drawCircle(
279-
x,
280-
startYLineAndCircle,
281-
circleInnerIndicatorSize,
282-
paintCircleInner
283-
);
283+
// to remove solid & inner circle drawing
284+
if (!isShapeSolid)
285+
canvas.drawCircle(
286+
x,
287+
startYLineAndCircle,
288+
circleInnerIndicatorSize,
289+
paintCircleInner
290+
);
284291
break;
285292
case arrow:
286293
canvas.drawLine(x, startYLineAndCircle, x, stopY, paintLine);
@@ -306,10 +313,10 @@ protected void onDraw(final Canvas canvas) {
306313
canvas.drawPath(((Targetable) target).guidePath(), targetPaint);
307314
} else {
308315
canvas.drawRoundRect(
309-
targetRect,
310-
RADIUS_SIZE_TARGET_RECT,
311-
RADIUS_SIZE_TARGET_RECT,
312-
targetPaint
316+
targetRect,
317+
RADIUS_SIZE_TARGET_RECT,
318+
RADIUS_SIZE_TARGET_RECT,
319+
targetPaint
313320
);
314321
}
315322
}
@@ -430,8 +437,8 @@ private Point resolveMessageViewLocation() {
430437

431438
public void show() {
432439
this.setLayoutParams(new ViewGroup.LayoutParams(
433-
ViewGroup.LayoutParams.MATCH_PARENT,
434-
ViewGroup.LayoutParams.MATCH_PARENT
440+
ViewGroup.LayoutParams.MATCH_PARENT,
441+
ViewGroup.LayoutParams.MATCH_PARENT
435442
));
436443
this.setClickable(false);
437444
((ViewGroup) ((Activity) getContext()).getWindow().getDecorView()).addView(this);
@@ -477,6 +484,7 @@ public static class Builder {
477484
private Gravity gravity;
478485
private DismissType dismissType;
479486
private PointerType pointerType;
487+
private boolean isShapeSolid;
480488
private final Context context;
481489
private Spannable contentSpan;
482490
private Typeface titleTypeFace, contentTypeFace;
@@ -660,11 +668,22 @@ public Builder setPointerType(PointerType pointerType) {
660668
return this;
661669
}
662670

671+
/**
672+
* this method defining the type of pointer
673+
*
674+
* @param isShapeSolid should be true/false to fill the shape arrow -> To be filled/solid you must set this parameter to true
675+
*/
676+
public Builder isShapeSolid(boolean isShapeSolid) {
677+
this.isShapeSolid = isShapeSolid;
678+
return this;
679+
}
680+
663681
public GuideView build() {
664682
GuideView guideView = new GuideView(context, targetView);
665683
guideView.mGravity = gravity != null ? gravity : Gravity.auto;
666684
guideView.dismissType = dismissType != null ? dismissType : DismissType.targetView;
667685
guideView.pointerType = pointerType != null ? pointerType : PointerType.circle;
686+
guideView.isShapeSolid = isShapeSolid;
668687
float density = context.getResources().getDisplayMetrics().density;
669688

670689
guideView.setTitle(title);

0 commit comments

Comments
 (0)