Skip to content

Commit

Permalink
Added a check for fast clicks on spotlight while in sequence to avoid…
Browse files Browse the repository at this point in the history
… overlapping of spotlights. 29jitender#70
  • Loading branch information
dhavalwooplr committed Oct 25, 2017
1 parent 0d250a6 commit 18db962
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SpotlightSequence {
private static SpotlightSequence instance;
private final String TAG = "Tour Sequence";
private SpotlightSequenceListener spotlightSequenceListener;
private long lastClickTime = 0;

/**
* Creates an instance of SpotlightSequence
Expand Down Expand Up @@ -78,7 +79,8 @@ public SpotlightSequence addSpotlight(View target, String title, String subtitle
.setListener(new SpotlightListener() {
@Override
public void onUserClicked(String s) {
playNext();
if(!isFastDoubleClick())
playNext();
}
})
.enableDismissAfterShown(true);
Expand Down Expand Up @@ -106,7 +108,8 @@ public SpotlightSequence addSpotlight(@NonNull View target, int titleResId, int
.setListener(new SpotlightListener() {
@Override
public void onUserClicked(String s) {
playNext();
if(!isFastDoubleClick())
playNext();
}
})
.enableDismissAfterShown(true);
Expand Down Expand Up @@ -192,5 +195,20 @@ private void setConfig(@Nullable SpotlightConfig config) {
}
this.config = config;
}

/**
* Method to check if user has clicked withing 1 second or not.
* It will prevent showing spotlights overlapped on each other.
* @return
*/
private boolean isFastDoubleClick(){
long time = System.currentTimeMillis();
long timeD = time - lastClickTime;
if (timeD > 0 && timeD < 1000) {
return true;
}
lastClickTime = time;
return false;
}
}

10 changes: 5 additions & 5 deletions app/src/main/java/com/example/spotlight/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void onClick(View view) {

switch (view.getId()) {

case R.id.switchAnimation:
/*case R.id.switchAnimation:
if (isRevealEnabled) {
switchAnimation.setText("Switch to Reveal");
isRevealEnabled = false;
Expand All @@ -101,12 +101,12 @@ public void onClick(View view) {
isRevealEnabled = true;
}
mPreferencesManager.resetAll();
break;
break;*/

case R.id.reset:
mPreferencesManager.resetAll();
break;
case R.id.resetAndPlay:
/*case R.id.resetAndPlay:
mPreferencesManager.resetAll();
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
Expand All @@ -123,14 +123,14 @@ public void run() {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
params.setMargins(Utils.dpToPx(16), Utils.dpToPx(16), right, bottom);
fab.setLayoutParams(params);
break;
break;*/
case R.id.startSequence:
mPreferencesManager.resetAll();
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
SpotlightSequence.getInstance(MainActivity.this,null)
.addSpotlight(switchAnimation, "Switch Animation", "Click to swtich the animation", INTRO_SWITCH)
.addSpotlight(switchAnimation, "Switch Animation", "Click to switch the animation", INTRO_SWITCH)
.addSpotlight(reset, "Reset ", "Click here to reset preferences", INTRO_RESET)
.addSpotlight(resetAndPlay, "Play Again", "Click here to play again", INTRO_REPEAT)
.addSpotlight(changePosAndPlay, "Change Position", "Click here to change position and replay", INTRO_CHANGE_POSITION)
Expand Down

0 comments on commit 18db962

Please sign in to comment.