diff --git a/Spotlight-library/src/main/java/com/wooplr/spotlight/utils/SpotlightSequence.java b/Spotlight-library/src/main/java/com/wooplr/spotlight/utils/SpotlightSequence.java index 0a42689..e5f261a 100644 --- a/Spotlight-library/src/main/java/com/wooplr/spotlight/utils/SpotlightSequence.java +++ b/Spotlight-library/src/main/java/com/wooplr/spotlight/utils/SpotlightSequence.java @@ -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 @@ -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); @@ -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); @@ -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; + } } diff --git a/app/src/main/java/com/example/spotlight/MainActivity.java b/app/src/main/java/com/example/spotlight/MainActivity.java index 28f6ccb..34f0cc0 100644 --- a/app/src/main/java/com/example/spotlight/MainActivity.java +++ b/app/src/main/java/com/example/spotlight/MainActivity.java @@ -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; @@ -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 @@ -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)