diff --git a/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java b/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java index 88571d6e..ae0cab2b 100644 --- a/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java +++ b/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java @@ -20,6 +20,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; +import android.widget.CheckBox; import android.widget.FrameLayout; import android.widget.TextView; @@ -46,6 +47,7 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis private boolean mUseAutoRadius = true; private View mContentBox; private TextView mContentTextView; + private CheckBox mContentCheckBox; private TextView mDismissButton; private int mGravity; private int mContentBottomMargin; @@ -60,10 +62,13 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis private long mDelayInMillis = ShowcaseConfig.DEFAULT_DELAY; private int mBottomMargin = 0; private boolean mSingleUse = false; // should display only once + private boolean mShowAgain = true; // should display once again private PrefsManager mPrefsManager; // used to store state doe single use mode List mListeners; // external listeners who want to observe when we show and dismiss private UpdateOnGlobalLayout mLayoutListener; private IDetachedListener mDetachedListener; + private String singleUseShowcaseID; + private String showAgainShowcaseID; public MaterialShowcaseView(Context context) { super(context); @@ -109,6 +114,7 @@ private void init(Context context) { View contentView = LayoutInflater.from(getContext()).inflate(R.layout.showcase_content, this, true); mContentBox = contentView.findViewById(R.id.content_box); mContentTextView = (TextView) contentView.findViewById(R.id.tv_content); + mContentCheckBox = (CheckBox) contentView.findViewById(R.id.tv_never_show); mDismissButton = (TextView) contentView.findViewById(R.id.tv_dismiss); mDismissButton.setOnClickListener(this); } @@ -176,7 +182,7 @@ protected void onDetachedFromWindow() { * Ensure we reset the flag so the showcase display again. */ if (!mWasDismissed && mSingleUse && mPrefsManager != null) { - mPrefsManager.resetShowcase(); + mPrefsManager.resetShowcase(singleUseShowcaseID); } @@ -246,7 +252,7 @@ public void setTarget(Target target) { mBottomMargin = getSoftButtonsBarSizePort((Activity) getContext()); FrameLayout.LayoutParams contentLP = (LayoutParams) getLayoutParams(); - if (contentLP!=null && contentLP.bottomMargin != mBottomMargin) + if (contentLP != null && contentLP.bottomMargin != mBottomMargin) contentLP.bottomMargin = mBottomMargin; } @@ -329,6 +335,12 @@ private void setContentText(CharSequence contentText) { } } + private void setCheckBoxText(CharSequence text, String showcaseID) { + if (mContentCheckBox != null) { + mContentCheckBox.setText(text); + } + } + private void setDismissText(CharSequence dismissText) { if (mDismissButton != null) { mDismissButton.setText(dismissText); @@ -466,6 +478,22 @@ public Builder setContentText(CharSequence text) { return this; } + /** + * This feature is intend to be used as a flag + * so the user can tell if he wants to be warned every time. + */ + public Builder showUntil(String showAgainShowcaseID) { + showcaseView.showUntil(showAgainShowcaseID); + return this; + } + + /** + * Set the text shown on the check box. + */ + public Builder setCheckBoxText(String showAgainShowcaseID) { + showcaseView.showUntil(showAgainShowcaseID); + return this; + } /** * Use auto radius, if true then the showcase circle will auto size based on the target view @@ -533,12 +561,22 @@ public MaterialShowcaseView show() { showcaseView.show(activity); return showcaseView; } + } + private void showUntil(String showcaseID) { + mShowAgain = true; + mContentCheckBox.setVisibility(VISIBLE); + showAgainShowcaseID = showcaseID; + + if (mPrefsManager == null) { + mPrefsManager = new PrefsManager(getContext()); + } } private void singleUse(String showcaseID) { mSingleUse = true; - mPrefsManager = new PrefsManager(getContext(), showcaseID); + singleUseShowcaseID = showcaseID; + mPrefsManager = new PrefsManager(getContext()); } public void removeFromWindow() { @@ -580,13 +618,17 @@ public boolean show(final Activity activity) { * if we're in single use mode and have already shot our bolt then do nothing */ if (mSingleUse) { - if (mPrefsManager.hasFired()) { + if (mPrefsManager.hasFired(singleUseShowcaseID)) { return false; } else { - mPrefsManager.setFired(); + mPrefsManager.setFired(singleUseShowcaseID); } } + if (mPrefsManager.hasFired(showAgainShowcaseID)) { + return false; + } + ((ViewGroup) activity.getWindow().getDecorView()).addView(this); setShouldRender(true); @@ -621,6 +663,10 @@ public void hide() { } else { removeFromWindow(); } + + if (mContentCheckBox.isChecked()) { + mPrefsManager.setFired(showAgainShowcaseID); + } } public void fadeIn() { @@ -649,7 +695,7 @@ public void onAnimationEnd() { } public void resetSingleUse() { - if (mSingleUse && mPrefsManager != null) mPrefsManager.resetShowcase(); + if (mSingleUse && mPrefsManager != null) mPrefsManager.resetShowcase(singleUseShowcaseID); } /** diff --git a/library/src/main/java/uk/co/deanwild/materialshowcaseview/PrefsManager.java b/library/src/main/java/uk/co/deanwild/materialshowcaseview/PrefsManager.java index 095b2763..fb840e31 100644 --- a/library/src/main/java/uk/co/deanwild/materialshowcaseview/PrefsManager.java +++ b/library/src/main/java/uk/co/deanwild/materialshowcaseview/PrefsManager.java @@ -17,6 +17,14 @@ public class PrefsManager { private String showcaseID = null; private Context context; + public PrefsManager(Context context) { + this.context = context; + } + + /*** + * @deprecated Pass the showcaseID when needed + */ + @Deprecated public PrefsManager(Context context, String showcaseID) { this.context = context; this.showcaseID = showcaseID; @@ -24,20 +32,35 @@ public PrefsManager(Context context, String showcaseID) { /*** - * METHODS FOR INDIVIDUAL SHOWCASE VIEWS + * @deprecated send the showcaseID via param */ + @Deprecated boolean hasFired() { int status = getSequenceStatus(); return (status == SEQUENCE_FINISHED); } + boolean hasFired(String showcaseID) { + int status = getSequenceStatus(showcaseID); + return (status == SEQUENCE_FINISHED); + } + + /*** + * @deprecated send the showcaseID via param + */ + @Deprecated void setFired() { setSequenceStatus(SEQUENCE_FINISHED); } + void setFired(String showcaseID) { + setSequenceStatus(SEQUENCE_FINISHED, showcaseID); + } + /*** - * METHODS FOR SHOWCASE SEQUENCES + * @deprecated send the showcaseID via param */ + @Deprecated int getSequenceStatus() { return context .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) @@ -45,16 +68,39 @@ int getSequenceStatus() { } + int getSequenceStatus(String showcaseID) { + return context + .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + .getInt(STATUS + showcaseID, SEQUENCE_NEVER_STARTED); + + } + + /*** + * @deprecated send the showcaseID via param + */ + @Deprecated void setSequenceStatus(int status) { SharedPreferences internal = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); internal.edit().putInt(STATUS + showcaseID, status).apply(); } + void setSequenceStatus(int status, String showcaseID) { + SharedPreferences internal = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); + internal.edit().putInt(STATUS + showcaseID, status).apply(); + } + /*** + * @deprecated send the showcaseID via param + */ + @Deprecated public void resetShowcase() { resetShowcase(context, showcaseID); } + public void resetShowcase(String showcaseID) { + resetShowcase(context, showcaseID); + } + static void resetShowcase(Context context, String showcaseID) { SharedPreferences internal = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); internal.edit().putInt(STATUS + showcaseID, SEQUENCE_NEVER_STARTED).apply(); diff --git a/library/src/main/java/uk/co/deanwild/materialshowcaseview/ShowcaseConfig.java b/library/src/main/java/uk/co/deanwild/materialshowcaseview/ShowcaseConfig.java index bc3c8aa4..23f02506 100644 --- a/library/src/main/java/uk/co/deanwild/materialshowcaseview/ShowcaseConfig.java +++ b/library/src/main/java/uk/co/deanwild/materialshowcaseview/ShowcaseConfig.java @@ -15,6 +15,7 @@ public class ShowcaseConfig { private long mDelay = DEFAULT_DELAY; private int mMaskColour; private int mContentTextColor; + private int mCheckBoxTextColor; private int mDismissTextColor; private long mFadeDuration = DEFAULT_FADE_TIME; @@ -22,6 +23,7 @@ public ShowcaseConfig() { mMaskColour = Color.parseColor(ShowcaseConfig.DEFAULT_MASK_COLOUR); mContentTextColor = Color.parseColor("#ffffff"); mDismissTextColor = Color.parseColor("#ffffff"); + mCheckBoxTextColor = Color.parseColor("#ffffff"); } public long getDelay() { @@ -63,4 +65,12 @@ public long getFadeDuration() { public void setFadeDuration(long fadeDuration) { this.mFadeDuration = fadeDuration; } + + public int getCheckBoxTextColor() { + return mCheckBoxTextColor; + } + + public void setCheckBoxTextColor(int mCheckBoxTextColor) { + this.mCheckBoxTextColor = mCheckBoxTextColor; + } } diff --git a/library/src/main/res/layout/showcase_content.xml b/library/src/main/res/layout/showcase_content.xml index ef7c9c74..aec9dbc8 100644 --- a/library/src/main/res/layout/showcase_content.xml +++ b/library/src/main/res/layout/showcase_content.xml @@ -1,5 +1,4 @@ - + + \ No newline at end of file diff --git a/library/src/main/res/values-pt/strings.xml b/library/src/main/res/values-pt/strings.xml new file mode 100644 index 00000000..9106eea9 --- /dev/null +++ b/library/src/main/res/values-pt/strings.xml @@ -0,0 +1,4 @@ + + + Não mostrar novamente + \ No newline at end of file diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml new file mode 100644 index 00000000..3fb5ea8d --- /dev/null +++ b/library/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + Don\'t show this again + \ No newline at end of file diff --git a/sample/src/main/java/uk/co/deanwild/materialshowcaseviewsample/SimpleSingleExample.java b/sample/src/main/java/uk/co/deanwild/materialshowcaseviewsample/SimpleSingleExample.java index bca95d71..96820515 100644 --- a/sample/src/main/java/uk/co/deanwild/materialshowcaseviewsample/SimpleSingleExample.java +++ b/sample/src/main/java/uk/co/deanwild/materialshowcaseviewsample/SimpleSingleExample.java @@ -51,7 +51,7 @@ private void presentShowcaseView(int withDelay) { .setDismissText("GOT IT") .setContentText("This is some amazing feature you should know about") .setDelay(withDelay) // optional but starting animations immediately in onCreate can make them choppy - .singleUse(SHOWCASE_ID) // provide a unique ID used to ensure it is only shown once + .showUntil(SHOWCASE_ID) .show(); }