diff --git a/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java b/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java index b2d22bd3..dd8cc860 100644 --- a/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java +++ b/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java @@ -60,6 +60,7 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis private int mContentBottomMargin; private int mContentTopMargin; private boolean mDismissOnTouch = false; + private boolean mDismissOnTarget = false; private boolean mShouldRender = false; // flag to decide when we should actually render private int mMaskColour; private AnimationFactory mAnimationFactory; @@ -95,7 +96,6 @@ public MaterialShowcaseView(Context context, AttributeSet attrs, int defStyleAtt init(context); } - private void init(Context context) { setWillNotDraw(false); @@ -200,6 +200,19 @@ public boolean onTouch(View v, MotionEvent event) { if (mDismissOnTouch) { hide(); } + + if (mDismissOnTarget) { + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + Rect bound = mTarget.getBounds(); + float x = event.getX(); + float y = event.getY(); + if (x >= bound.left && x <= bound.right && y >= bound.top && y <= bound.bottom) { + hide(); + } + break; + } + } return true; } @@ -373,6 +386,10 @@ private void setDismissOnTouch(boolean dismissOnTouch) { mDismissOnTouch = dismissOnTouch; } + private void setDismissOnTarget(boolean dissmissOnTarget) { + mDismissOnTarget = dissmissOnTarget; + } + private void setShouldRender(boolean shouldRender) { mShouldRender = shouldRender; } @@ -433,6 +450,10 @@ private void updateDismissButton() { } } + private void setCustomView(int layoutId) { + inflate(getContext(), layoutId, this); + } + public boolean hasFired() { return mPrefsManager.hasFired(); } @@ -512,6 +533,11 @@ public Builder setDismissOnTouch(boolean dismissOnTouch) { return this; } + public Builder setDismissOnTarget(boolean dismissOnTarget) { + showcaseView.setDismissOnTarget(dismissOnTarget); + return this; + } + public Builder setMaskColour(int maskColour) { showcaseView.setMaskColour(maskColour); return this; @@ -577,6 +603,11 @@ public Builder withRectangleShape(boolean fullWidth) { return this; } + public Builder setCustomView(int layoutId) { + showcaseView.setCustomView(layoutId); + return this; + } + public MaterialShowcaseView build() { if (showcaseView.mShape == null) { switch (shapeType) { @@ -700,13 +731,13 @@ public void fadeIn() { setVisibility(INVISIBLE); mAnimationFactory.fadeInView(this, mFadeDurationInMillis, - new IAnimationFactory.AnimationStartListener() { - @Override - public void onAnimationStart() { - setVisibility(View.VISIBLE); - notifyOnDisplayed(); - } + new IAnimationFactory.AnimationStartListener() { + @Override + public void onAnimationStart() { + setVisibility(View.VISIBLE); + notifyOnDisplayed(); } + } ); }