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

Commit

Permalink
Added new pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
Adw41t committed Jul 7, 2021
1 parent 766e115 commit 4867f21
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;

import smartdevelop.ir.eram.showcaseviewlib.GuideView;
import smartdevelop.ir.eram.showcaseviewlib.config.DismissType;
import smartdevelop.ir.eram.showcaseviewlib.config.Gravity;
import smartdevelop.ir.eram.showcaseviewlib.config.PointerType;
import smartdevelop.ir.eram.showcaseviewlib.listener.GuideListener;

public class MainActivity extends AppCompatActivity {
Expand Down Expand Up @@ -38,6 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
.setContentText("Guide Description Text\n .....Guide Description Text\n .....Guide Description Text .....")
.setGravity(Gravity.center)
.setDismissType(DismissType.anywhere)
.setPointerType(PointerType.arrow)
.setTargetView(view1)
.setGuideListener(new GuideListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
Expand All @@ -28,6 +29,7 @@

import smartdevelop.ir.eram.showcaseviewlib.config.DismissType;
import smartdevelop.ir.eram.showcaseviewlib.config.Gravity;
import smartdevelop.ir.eram.showcaseviewlib.config.PointerType;
import smartdevelop.ir.eram.showcaseviewlib.listener.GuideListener;

/**
Expand Down Expand Up @@ -84,6 +86,7 @@ public class GuideView extends FrameLayout {
private GuideListener mGuideListener;
private Gravity mGravity;
private DismissType dismissType;
private PointerType pointerType;
private final GuideMessageView mMessageView;

private GuideView(Context context, View view) {
Expand Down Expand Up @@ -271,17 +274,33 @@ protected void onDraw(final Canvas canvas) {
paintCircleInner.setAntiAlias(true);

final float x = (targetRect.left / 2 + targetRect.right / 2);
canvas.drawLine(
x,
startYLineAndCircle,
x,
stopY,
paintLine
);

canvas.drawCircle(x, startYLineAndCircle, circleIndicatorSize, paintCircle);
canvas.drawCircle(x, startYLineAndCircle, circleInnerIndicatorSize, paintCircleInner);

switch (pointerType) {
case circle:
canvas.drawLine(x,startYLineAndCircle,x,stopY,paintLine);
canvas.drawCircle(x, startYLineAndCircle, circleIndicatorSize, paintCircle);
canvas.drawCircle(x, startYLineAndCircle, circleInnerIndicatorSize, paintCircleInner);
break;
case arrow:
canvas.drawLine(x,startYLineAndCircle,x,stopY,paintLine);
Path path = new Path();
if (isTop) {
path.moveTo(x, startYLineAndCircle - (circleIndicatorSize * 2));
path.lineTo(x + circleIndicatorSize, startYLineAndCircle);
path.lineTo(x - circleIndicatorSize, startYLineAndCircle);
path.close();
} else {
path.moveTo(x, startYLineAndCircle + (circleIndicatorSize * 2));
path.lineTo(x + circleIndicatorSize, startYLineAndCircle);
path.lineTo(x - circleIndicatorSize, startYLineAndCircle);
path.close();
}
canvas.drawPath(path, paintCircle);
break;
case none:
//draw no line and no pointer
break;
}
targetPaint.setXfermode(X_FER_MODE_CLEAR);
targetPaint.setAntiAlias(true);

Expand Down Expand Up @@ -455,6 +474,7 @@ public static class Builder {
private String title, contentText;
private Gravity gravity;
private DismissType dismissType;
private PointerType pointerType;
private final Context context;
private Spannable contentSpan;
private Typeface titleTypeFace, contentTypeFace;
Expand Down Expand Up @@ -628,10 +648,20 @@ public Builder setCircleStrokeIndicatorSize(float size) {
return this;
}

/**
* this method defining the type of pointer
*
* @param pointerType should be one type of PointerType enum. for example: arrow -> To show arrow pointing to target view
*/
public Builder setPointerType(PointerType pointerType) {
this.pointerType = pointerType;
return this;
}
public GuideView build() {
GuideView guideView = new GuideView(context, targetView);
guideView.mGravity = gravity != null ? gravity : Gravity.auto;
guideView.dismissType = dismissType != null ? dismissType : DismissType.targetView;
guideView.pointerType = pointerType != null ? pointerType : PointerType.circle;
float density = context.getResources().getDisplayMetrics().density;

guideView.setTitle(title);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package smartdevelop.ir.eram.showcaseviewlib.config;

public enum PointerType {
circle, arrow, none
}

0 comments on commit 4867f21

Please sign in to comment.