Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to add custom layout. Added onDismiss for touch on target #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -95,7 +96,6 @@ public MaterialShowcaseView(Context context, AttributeSet attrs, int defStyleAtt
init(context);
}


private void init(Context context) {
setWillNotDraw(false);

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -433,6 +450,10 @@ private void updateDismissButton() {
}
}

private void setCustomView(int layoutId) {
inflate(getContext(), layoutId, this);
}

public boolean hasFired() {
return mPrefsManager.hasFired();
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
}
);
}

Expand Down