diff --git a/.idea/libraries/animated_vector_drawable_23_4_0.xml b/.idea/libraries/animated_vector_drawable_23_4_0.xml index f8bcc68..36b7174 100644 --- a/.idea/libraries/animated_vector_drawable_23_4_0.xml +++ b/.idea/libraries/animated_vector_drawable_23_4_0.xml @@ -1,13 +1,12 @@ - - + + - \ No newline at end of file diff --git a/.idea/libraries/appcompat_v7_23_4_0.xml b/.idea/libraries/appcompat_v7_23_4_0.xml index 6c6195f..95da926 100644 --- a/.idea/libraries/appcompat_v7_23_4_0.xml +++ b/.idea/libraries/appcompat_v7_23_4_0.xml @@ -1,17 +1,12 @@ - - - - - - + + - \ No newline at end of file diff --git a/.idea/libraries/design_23_4_0.xml b/.idea/libraries/design_23_4_0.xml index 88d8931..3e73e82 100644 --- a/.idea/libraries/design_23_4_0.xml +++ b/.idea/libraries/design_23_4_0.xml @@ -1,8 +1,5 @@ - - - diff --git a/.idea/libraries/espresso_core_2_2_2.xml b/.idea/libraries/espresso_core_2_2_2.xml index 64eafc2..4e9c2df 100644 --- a/.idea/libraries/espresso_core_2_2_2.xml +++ b/.idea/libraries/espresso_core_2_2_2.xml @@ -1,13 +1,12 @@ - - + + - \ No newline at end of file diff --git a/.idea/libraries/espresso_idling_resource_2_2_2.xml b/.idea/libraries/espresso_idling_resource_2_2_2.xml index eab8419..28e9d40 100644 --- a/.idea/libraries/espresso_idling_resource_2_2_2.xml +++ b/.idea/libraries/espresso_idling_resource_2_2_2.xml @@ -1,13 +1,12 @@ - - + + - \ No newline at end of file diff --git a/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml b/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml index 2b4c21f..bbda6ed 100644 --- a/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml +++ b/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml @@ -1,13 +1,12 @@ - - + + - \ No newline at end of file diff --git a/.idea/libraries/javax_inject_1.xml b/.idea/libraries/javax_inject_1.xml index 0d1d5fc..eebeedd 100644 --- a/.idea/libraries/javax_inject_1.xml +++ b/.idea/libraries/javax_inject_1.xml @@ -4,6 +4,8 @@ - + + + \ No newline at end of file diff --git a/.idea/libraries/recyclerview_v7_23_4_0.xml b/.idea/libraries/recyclerview_v7_23_4_0.xml index 67cedf1..230a1d2 100644 --- a/.idea/libraries/recyclerview_v7_23_4_0.xml +++ b/.idea/libraries/recyclerview_v7_23_4_0.xml @@ -1,11 +1,8 @@ - - - - + diff --git a/.idea/libraries/rules_0_5.xml b/.idea/libraries/rules_0_5.xml index d0051b5..219af33 100644 --- a/.idea/libraries/rules_0_5.xml +++ b/.idea/libraries/rules_0_5.xml @@ -1,17 +1,12 @@ - - - - - - + + - \ No newline at end of file diff --git a/.idea/libraries/runner_0_5.xml b/.idea/libraries/runner_0_5.xml index 760fdba..e8fe27f 100644 --- a/.idea/libraries/runner_0_5.xml +++ b/.idea/libraries/runner_0_5.xml @@ -1,17 +1,12 @@ - - - - - - + + - \ No newline at end of file diff --git a/.idea/libraries/support_v4_23_4_0.xml b/.idea/libraries/support_v4_23_4_0.xml index 2a4fdfb..f9d5520 100644 --- a/.idea/libraries/support_v4_23_4_0.xml +++ b/.idea/libraries/support_v4_23_4_0.xml @@ -1,18 +1,13 @@ - - - - - - - + + + - \ No newline at end of file diff --git a/.idea/libraries/support_vector_drawable_23_4_0.xml b/.idea/libraries/support_vector_drawable_23_4_0.xml index 04e0b2a..c7b9ca6 100644 --- a/.idea/libraries/support_vector_drawable_23_4_0.xml +++ b/.idea/libraries/support_vector_drawable_23_4_0.xml @@ -1,13 +1,12 @@ - - + + - \ No newline at end of file diff --git a/README.md b/README.md index 0125ddc..c3d6ea6 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,9 @@ Dismiss spotlight on touch outside ### enableDismissAfterShown(boolean) Dismiss spotlight on touch outside after spotlight is completely visible +### showAlways(boolean) +To show spotlight everytime when user opens the same screen. + # Configuration Method ```java //Create global config instance to reuse it diff --git a/Spotlight-library/src/main/java/com/wooplr/spotlight/SpotlightView.java b/Spotlight-library/src/main/java/com/wooplr/spotlight/SpotlightView.java index 7cda753..563e631 100755 --- a/Spotlight-library/src/main/java/com/wooplr/spotlight/SpotlightView.java +++ b/Spotlight-library/src/main/java/com/wooplr/spotlight/SpotlightView.java @@ -186,6 +186,11 @@ public class SpotlightView extends FrameLayout { private int softwareBtnHeight; + /** + * If true -> Do not store spotlight id into preferences so that it can show every time when a particular screen is opened. + */ + private boolean isShowAlways = false; + public SpotlightView(Context context) { super(context); @@ -217,6 +222,7 @@ private void init(Context context) { isRevealAnimationEnabled = true; dismissOnTouch = false; isPerformClick = false; + isShowAlways = false; enableDismissAfterShown = false; dismissOnBackPress = false; handler = new Handler(); @@ -320,34 +326,41 @@ private void show(final Activity activity) { setReady(true); - handler.postDelayed(new Runnable() { - @Override - public void run() { - try{ - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - - if (isRevealAnimationEnabled) - startRevealAnimation(activity); - else { - startFadinAnimation(activity); - } - } else { - startFadinAnimation(activity); - } - }catch(Exception e){ - e.printStackTrace(); - } - } - } - , 100); + SpotlightView.this.post(new Runnable() { + @Override + public void run() { + try{ + boolean isAttachedToWindow = true; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + isAttachedToWindow = SpotlightView.this.isAttachedToWindow(); + } + if(isAttachedToWindow) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + + if (isRevealAnimationEnabled) + startRevealAnimation(activity); + else { + startFadinAnimation(activity); + } + } else { + startFadinAnimation(activity); + } + } + }catch(Exception e){ + e.printStackTrace(); + } + } + }); } /** * Dissmiss view with reverse animation */ private void dismiss() { - preferencesManager.setDisplayed(usageId); + if(!isShowAlways) + preferencesManager.setDisplayed(usageId); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (isRevealAnimationEnabled) exitRevealAnimation(); @@ -892,6 +905,10 @@ public void setPerformClick(boolean performClick) { isPerformClick = performClick; } + public void setShowAlways(boolean showAlways){ + isShowAlways = showAlways; + } + public void setExtraPaddingForArc(int extraPaddingForArc) { this.extraPaddingForArc = extraPaddingForArc; } @@ -1086,6 +1103,13 @@ public Builder performClick(boolean isPerformClick) { return this; } + /** + * If true -> Do not store spotlight id into preferences so that it can show every time when a particular screen is opened. + */ + public Builder showAlways(boolean isShowAlways) { + spotlightView.setShowAlways(isShowAlways); + return this; + } public Builder fadeinTextDuration(long fadinTextDuration) { spotlightView.setFadingTextDuration(fadinTextDuration); 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 dd0627f..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 @@ -31,6 +31,8 @@ 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 @@ -77,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); @@ -105,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); @@ -147,9 +151,20 @@ private void playNext(){ }else { Log.d(TAG, "END OF QUEUE"); resetTour(); + + if (spotlightSequenceListener != null) + spotlightSequenceListener.onSequenceEnd(); } } + /** + * Set Spotlight sequence listener. (For now it is only for sequence end event.) + */ + public SpotlightSequence setListener(SpotlightSequenceListener listener){ + this.spotlightSequenceListener = listener; + return instance; + } + /** * Clear all Spotlights usageId from shared preferences. * @param context @@ -180,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/Spotlight-library/src/main/java/com/wooplr/spotlight/utils/SpotlightSequenceListener.java b/Spotlight-library/src/main/java/com/wooplr/spotlight/utils/SpotlightSequenceListener.java new file mode 100644 index 0000000..644c319 --- /dev/null +++ b/Spotlight-library/src/main/java/com/wooplr/spotlight/utils/SpotlightSequenceListener.java @@ -0,0 +1,12 @@ +package com.wooplr.spotlight.utils; + +/** + * Created by dhavalrupapara on 25/10/17. + * Spotlight sequence Events listener. + */ +public interface SpotlightSequenceListener { + /** + * Called when sequence is ended. + */ + void onSequenceEnd(); +} diff --git a/app/src/main/java/com/example/spotlight/MainActivity.java b/app/src/main/java/com/example/spotlight/MainActivity.java index c85cb7a..630a55c 100644 --- a/app/src/main/java/com/example/spotlight/MainActivity.java +++ b/app/src/main/java/com/example/spotlight/MainActivity.java @@ -17,6 +17,7 @@ import com.wooplr.spotlight.SpotlightView; import com.wooplr.spotlight.prefs.PreferencesManager; import com.wooplr.spotlight.utils.SpotlightSequence; +import com.wooplr.spotlight.utils.SpotlightSequenceListener; import com.wooplr.spotlight.utils.Utils; import java.util.Random; @@ -129,12 +130,19 @@ public void run() { @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) .addSpotlight(startSequence, "Start sequence", "Well.. you just clicked here", INTRO_SEQUENCE) .addSpotlight(fab,"Love", "Like the picture?\n" + "Let others know.", INTRO_CARD) + .setListener(new SpotlightSequenceListener() { + @Override + public void onSequenceEnd() { + Toast.makeText(MainActivity.this, "Spotlight sequence ended", Toast.LENGTH_SHORT).show(); + Log.d("MainActivity", "Spotlight sequence ended"); + } + }) .startSequence(); } },400); @@ -163,6 +171,7 @@ private void showIntro(View view, String usageId) { .dismissOnBackPress(true) .enableDismissAfterShown(true) .usageId(usageId) //UNIQUE ID +// .showAlways(true) .show(); }