Skip to content

Commit

Permalink
Merge pull request #11 from droidekas/master
Browse files Browse the repository at this point in the history
added activity backpress based dismiss,fixes #7
  • Loading branch information
29jitender authored Aug 2, 2016
2 parents 2f61b71 + 8528cf1 commit 7ba1dec
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class SpotlightConfig {
private long fadingTextDuration;
private int padding;
private boolean dismissOnTouch;
private boolean dismissOnBackpress;
private boolean isPerformClick;
private int headingTvSize;
private int headingTvColor;
Expand All @@ -35,6 +36,7 @@ public SpotlightConfig() {
this.fadingTextDuration = 400;
this.padding = 20;
this.dismissOnTouch = true;
this.dismissOnBackpress=true;
this.isPerformClick = true;
this.headingTvSize = 24;
this.headingTvColor = Color.parseColor("#eb273f");
Expand Down Expand Up @@ -182,4 +184,12 @@ public Typeface getmTypeface() {
public void setmTypeface(Typeface mTypeface) {
this.mTypeface = mTypeface;
}

public boolean isDismissOnBackpress() {
return dismissOnBackpress;
}

public void setDismissOnBackpress(boolean dismissOnBackpress) {
this.dismissOnBackpress = dismissOnBackpress;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewAnimationUtils;
Expand Down Expand Up @@ -116,6 +118,7 @@ public class SpotlightView extends FrameLayout {
* Dismiss layout on touch
*/
private boolean dismissOnTouch;
private boolean dismissOnBackPress;

private PreferencesManager preferencesManager;
private String usageId;
Expand Down Expand Up @@ -170,6 +173,7 @@ public class SpotlightView extends FrameLayout {

private Typeface mTypeface = null;


public SpotlightView(Context context) {
super(context);
init(context);
Expand Down Expand Up @@ -200,11 +204,9 @@ private void init(Context context) {
isRevealAnimationEnabled = true;
dismissOnTouch = false;
isPerformClick = false;

dismissOnBackPress = false;
handler = new Handler();

preferencesManager = new PreferencesManager(context);

eraser = new Paint();
eraser.setColor(0xFFFFFFFF);
eraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
Expand Down Expand Up @@ -596,6 +598,7 @@ public void onAnimationStart(Animation animation) {
@Override
public void onAnimationEnd(Animation animation) {
dismissOnTouch = true;
dismissOnBackPress = true;
}

@Override
Expand Down Expand Up @@ -796,6 +799,9 @@ public void setDismissOnTouch(boolean dismissOnTouch) {
this.dismissOnTouch = dismissOnTouch;
}

public void setDismissOnBackPress(boolean dismissOnBackPress) {
this.dismissOnBackPress = dismissOnBackPress;
}

public void setPerformClick(boolean performClick) {
isPerformClick = performClick;
Expand All @@ -809,6 +815,7 @@ public void setIntroAnimationDuration(long introAnimationDuration) {
this.introAnimationDuration = introAnimationDuration;
}


public void setRevealAnimationEnabled(boolean revealAnimationEnabled) {
isRevealAnimationEnabled = revealAnimationEnabled;
}
Expand Down Expand Up @@ -878,6 +885,7 @@ public void setConfiguration(SpotlightConfig configuration) {
this.fadingTextDuration = configuration.getFadingTextDuration();
this.padding = configuration.getPadding();
this.dismissOnTouch = configuration.isDismissOnTouch();
this.dismissOnBackPress = configuration.isDismissOnBackpress();
this.isPerformClick = configuration.isPerformClick();
this.headingTvSize = configuration.getHeadingTvSize();
this.headingTvColor = configuration.getHeadingTvColor();
Expand Down Expand Up @@ -938,6 +946,11 @@ public Builder dismissOnTouch(boolean dismissOnTouch) {
return this;
}

public Builder dismissOnBackPress(boolean dismissOnBackPress) {
spotlightView.setDismissOnBackPress(dismissOnBackPress);
return this;
}

public Builder usageId(String usageId) {
spotlightView.setUsageId(usageId);
return this;
Expand Down Expand Up @@ -1005,8 +1018,10 @@ public Builder lineAnimDuration(long duration) {
}

public Builder enableDismissAfterShown(boolean enable) {
if (enable)
if (enable) {
spotlightView.setDismissOnTouch(false);
spotlightView.setDismissOnBackPress(false);
}
return this;
}

Expand All @@ -1025,6 +1040,11 @@ public SpotlightView build() {
spotlightView.targetView,
spotlightView.padding);
spotlightView.setCircleShape(circle);
if (spotlightView.dismissOnBackPress) {
spotlightView.setFocusableInTouchMode(true);
spotlightView.setFocusable(true);
spotlightView.requestFocus();
}
return spotlightView;
}

Expand All @@ -1035,4 +1055,19 @@ public SpotlightView show() {

}


@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (dismissOnBackPress) {
if (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
dismiss();
return true;
}
}
return super.dispatchKeyEvent(event);
}

public void logger(String s) {
Log.d("Spotlight", s);
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/example/spotlight/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ private void showIntro(View view, String usageId) {
.lineAnimDuration(400)
.lineAndArcColor(Color.parseColor("#eb273f"))
.dismissOnTouch(true)
.enableDismissAfterShown(true)
.dismissOnBackPress(true)
//.enableDismissAfterShown(true)
.usageId(usageId) //UNIQUE ID
.show();
}
Expand Down

0 comments on commit 7ba1dec

Please sign in to comment.