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

Commit

Permalink
added dismissType
Browse files Browse the repository at this point in the history
  • Loading branch information
mreram committed Feb 15, 2018
1 parent 541a0fd commit 059a93e
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 35 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Sample usage in your activity:
new GuideView.Builder(this)
.setTitle("Guide Title Text")
.setContentText("Guide Description Text\n .....Guide Description Text\n .....Guide Description Text .....")
.setGravity(GuideView.Gravity.AUTO)//optional
.setGravity(GuideView.Gravity.AUTO) //optional
.setDismissType(GuideView.DismissType.outSide) //optional - default dismissable by TargetView
.setTargetView(view)
.setContentTextSize(12)//optional
.setTitleTextSize(14)//optional
Expand All @@ -38,7 +39,7 @@ maven:
<dependency>
<groupId>com.github.mreram</groupId>
<artifactId>ShowCaseView</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</dependency>
```
gradle:
Expand Down Expand Up @@ -113,10 +114,24 @@ compile 'com.github.mreram:ShowCaseView:1.0.4'
})
.build()
.show();
## Contribution
Pull requests are welcome!


### DismissType Attribute

| Type | Description |
| ------ | ------ |
| outside | Dismissing with click on outside of MessageView |
| anywhere | Dismissing with click on anywhere |
| targetView | Dismissing with click on targetView(targetView is assigned with setTargetView method) |


## Contribution :collision:

Pull requests are welcome! :clap:

You can improve/fix some part of it .

Add Tests:

Assuming that the code in question already has automated (unit) tests, do add tests for the code you submit.
This isn't a hard rule. There are various cases where you may need to add code without test coverage (e.g. when adding a Object), but if it can be tested, it should be tested.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import smartdevelop.ir.eram.showcaseviewlib.GuideView;

Expand All @@ -27,7 +26,8 @@ protected void onCreate(Bundle savedInstanceState) {
builder = new GuideView.Builder(MainActivity.this)
.setTitle("Guide Title Text")
.setContentText("Guide Description Text\n .....Guide Description Text\n .....Guide Description Text .....")
.setGravity(GuideView.Gravity.CENTER)
.setGravity(GuideView.Gravity.center)
.setDismissType(GuideView.DismissType.outside)
.setTargetView(view1)
.setGuideListener(new GuideView.GuideListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public class GuideView extends FrameLayout {
private GuideMessageView mMessageView;
private boolean isTop;
private Gravity mGravity;
private DismissType dismissType;
int marginGuide;
private boolean mIsShowing;
private GuideListener mGuideListener;
int xMessageView = 0;
int yMessageView = 0;

final int ANIMATION_DURATION = 400;
final Paint emptyPaint = new Paint();
Expand All @@ -47,15 +52,18 @@ public class GuideView extends FrameLayout {
final Paint mPaint = new Paint();
final Paint targetPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
final Xfermode XFERMODE_CLEAR = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
private boolean mIsShowing;
private GuideListener mGuideListener;


public interface GuideListener {
void onDismiss(View view);
}

public enum Gravity {
AUTO, CENTER
auto, center
}

public enum DismissType {
outside, anywhere, targetView
}

private GuideView(Context context, View view) {
Expand Down Expand Up @@ -147,7 +155,7 @@ protected void onDraw(Canvas canvas) {
float startYLineAndCircle = (isTop ? rect.bottom : rect.top) + marginGuide;

float x = (rect.left / 2 + rect.right / 2);
float stopY = (y + INDICATOR_HEIGHT * density);
float stopY = (yMessageView + INDICATOR_HEIGHT * density);

tempCanvas.drawLine(x, startYLineAndCircle, x,
stopY
Expand Down Expand Up @@ -177,7 +185,7 @@ public void dismiss() {
this.startAnimation(startAnimation);
((ViewGroup) ((Activity) getContext()).getWindow().getDecorView()).removeView(this);
mIsShowing = false;
if(mGuideListener !=null){
if (mGuideListener != null) {
mGuideListener.onDismiss(target);
}
}
Expand All @@ -187,59 +195,83 @@ public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (rect.contains(x, y)) {
target.performClick();
if (event.getAction() == MotionEvent.ACTION_DOWN) {
switch (dismissType) {

case outside:
if (!isViewContains(mMessageView, x, y)) {
dismiss();
}
break;

case anywhere:
dismiss();
}
return true;
break;

case targetView:
if (rect.contains(x, y)) {
target.performClick();
dismiss();
}
break;

}
return true;
}
return false;
}

private boolean isViewContains(View view, float rx, float ry) {
int[] location = new int[2];
view.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
int w = view.getWidth();
int h = view.getHeight();

return !(rx < x || rx > x + w || ry < y || ry > y + h);
}

void setMessageLocation(Point p) {
mMessageView.setX(p.x);
mMessageView.setY(p.y);
requestLayout();
}

int x = 0;
int y = 0;

private Point resolveMessageViewLocation() {

if (mGravity == Gravity.CENTER) {
x = (int) (rect.left - mMessageView.getWidth() / 2 + target.getWidth() / 2);
if (mGravity == Gravity.center) {
xMessageView = (int) (rect.left - mMessageView.getWidth() / 2 + target.getWidth() / 2);
} else
x = (int) (rect.right) - mMessageView.getWidth();
xMessageView = (int) (rect.right) - mMessageView.getWidth();

if (isLandscape()) {
x -= getNavigationBarSize();
xMessageView -= getNavigationBarSize();
}

if (x + mMessageView.getWidth() > getWidth())
x = getWidth() - mMessageView.getWidth();
if (x < 0)
x = 0;
if (xMessageView + mMessageView.getWidth() > getWidth())
xMessageView = getWidth() - mMessageView.getWidth();
if (xMessageView < 0)
xMessageView = 0;


//set message view bottom
if (rect.top + (INDICATOR_HEIGHT * density) > getHeight() / 2) {
isTop = false;
y = (int) (rect.top - mMessageView.getHeight() - INDICATOR_HEIGHT * density);
yMessageView = (int) (rect.top - mMessageView.getHeight() - INDICATOR_HEIGHT * density);
}
//set message view top
else {
isTop = true;
y = (int) (rect.top + target.getHeight() + INDICATOR_HEIGHT * density);
yMessageView = (int) (rect.top + target.getHeight() + INDICATOR_HEIGHT * density);
}

if (y < 0)
y = 0;
if (yMessageView < 0)
yMessageView = 0;


return new Point(x, y);
return new Point(xMessageView, yMessageView);
}


Expand Down Expand Up @@ -289,11 +321,11 @@ public void setContentTextSize(int size) {
}



public static class Builder {
private View targetView;
private String title, contentText;
private Gravity gravity;
private DismissType dismissType;
private Context context;
private int titleTextSize;
private int contentTextSize;
Expand Down Expand Up @@ -367,9 +399,16 @@ public Builder setTitleTextSize(int size) {
return this;
}

public Builder setDismissType(DismissType dismissType) {
this.dismissType = dismissType;
return this;
}

public GuideView build() {
GuideView guideView = new GuideView(context, targetView);
guideView.mGravity = gravity != null ? gravity : Gravity.AUTO;
guideView.mGravity = gravity != null ? gravity : Gravity.auto;
guideView.dismissType = dismissType != null ? dismissType : DismissType.targetView;

guideView.setTitle(title);
if (contentText != null)
guideView.setContentText(contentText);
Expand All @@ -385,9 +424,10 @@ public GuideView build() {
if (contentTypeFace != null) {
guideView.setContentTypeFace(contentTypeFace);
}
if(guideListener !=null){
if (guideListener != null) {
guideView.mGuideListener = guideListener;
}

return guideView;
}

Expand Down

0 comments on commit 059a93e

Please sign in to comment.